From fa22b8fffc3fc7c5a1f88dd9f64ab12bac638e24 Mon Sep 17 00:00:00 2001 From: Marc Redemske Date: Sat, 30 Dec 2023 01:23:04 +0100 Subject: [PATCH] examples: add example and test --- examples/BUILD.bazel | 13 +++++++++++++ examples/generate.bzl | 10 ++++++++++ examples/generate_message.txt | 1 + 3 files changed, 24 insertions(+) create mode 100644 examples/generate.bzl create mode 100644 examples/generate_message.txt diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel index 8e55a45..f5d9a04 100644 --- a/examples/BUILD.bazel +++ b/examples/BUILD.bazel @@ -1,6 +1,19 @@ +load("@bazel_skylib//rules:diff_test.bzl", "diff_test") load("//quickjs:qjs.bzl", "qjs_binary") +load(":generate.bzl", "generate_message") qjs_binary( name = "hello_world", entry_point = ":hello_world.js", ) + +generate_message( + name = "msg", + message = "Hello, World", +) + +diff_test( + name = "generate_message_test", + file1 = ":msg", + file2 = ":generate_message.txt", +) diff --git a/examples/generate.bzl b/examples/generate.bzl new file mode 100644 index 0000000..31446bd --- /dev/null +++ b/examples/generate.bzl @@ -0,0 +1,10 @@ +"Example using @bzlparty_quickjs//:qjs in `genrule`" + +def generate_message(name, message): + "Generate a file with a given message" + native.genrule( + name = name, + outs = ["%s.out" % name], + cmd = "$(locations @bzlparty_quickjs//:qjs) --eval 'console.log(\"%s\")' > $(OUTS)" % message, + tools = ["@bzlparty_quickjs//:qjs"], + ) diff --git a/examples/generate_message.txt b/examples/generate_message.txt new file mode 100644 index 0000000..3fa0d4b --- /dev/null +++ b/examples/generate_message.txt @@ -0,0 +1 @@ +Hello, World