Skip to content

Instantly share code, notes, and snippets.

@kchodorow
Created April 3, 2017 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kchodorow/9555479d416087e4e867440e0f4c582d to your computer and use it in GitHub Desktop.
Save kchodorow/9555479d416087e4e867440e0f4c582d to your computer and use it in GitHub Desktop.
load("//:fun-with-outputs.bzl", "my_rule")
my_rule(
name = "foo",
many_results = [
"212",
"917",
"646",
],
one_result = "brooklyn",
)
$ bazel build :foo
INFO: Found 1 target...
>>>>> # //:foo [action 'Generating 212']
(cd home/kchodorow/.cache/bazel/_bazel_kchodorow/f454bcbe3fb58b7971b0951d116298e9/execroot/class-workspace && \
exec env - \
/bin/bash -c 'touch bazel-out/local-fastbuild/bin/212 bazel-out/local-fastbuild/bin/917 bazel-out/local-fastbuild/bin/646')
Target //:foo up-to-date:
bazel-bin/brooklyn
bazel-bin/212
bazel-bin/917
bazel-bin/646
INFO: Elapsed time: 1.744s, Critical Path: 0.09s
def _impl(ctx):
ctx.file_action(
output = ctx.outputs.one_result,
content = "I'm bespoke.",
)
ctx.action(
outputs = ctx.outputs.many_results,
command = "touch %s" % " ".join([p.path for p in ctx.outputs.many_results]),
)
my_rule = rule(
implementation = _impl,
attrs = {
'one_result' : attr.output(),
'many_results' : attr.output_list(),
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment