Skip to content

Instantly share code, notes, and snippets.

@kchodorow
Created April 3, 2017 14:24
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/587a906989abcc9d0d07aa14aa1f241d to your computer and use it in GitHub Desktop.
Save kchodorow/587a906989abcc9d0d07aa14aa1f241d to your computer and use it in GitHub Desktop.
load('//:dark-underbelly.bzl', 'du')
du(name = "whatever")
load('//:very-dark-underbelly.bzl', 'vdu')
vdu(
name = "dark-whatever",
one_result = "foo"
)
def my_output():
return {'txt' : '%{name}.txt'}
def _impl(ctx):
ctx.file_action(
output = ctx.outputs.txt,
content = "I'm bespoke.",
)
du = rule(
implementation = _impl,
outputs = my_output
)
def my_output(one_result):
# One result is a label.
first_char = one_result.name[0:1]
return {'txt' : '%s.txt' % first_char}
def _impl(ctx):
ctx.file_action(
output = ctx.outputs.one_result,
content = "I'm bespoke.",
)
ctx.file_action(
output = ctx.outputs.txt,
content = "I'm also bespoke.",
)
vdu = rule(
implementation = _impl,
attrs = {'one_result' : attr.output()},
outputs = my_output,
)
@abergmeier-dsfishlabs
Copy link

You do realize that I will immediately start using that now, right.

@abergmeier-dsfishlabs
Copy link

@kchodorow does something similar (attribute functions) work for attrs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment