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