|
|
|
|
|
MyInfo = provider(fields = {}) |
|
|
|
def _example_implementation(ctx): |
|
out = ctx.actions.declare_file(ctx.label.name) |
|
ctx.actions.write(out, "") |
|
|
|
return [MyInfo(), DefaultInfo(files = depset([out]))] |
|
|
|
example = rule( |
|
implementation = _example_implementation, |
|
attrs = { |
|
"deps": attr.label_list( |
|
providers = [MyInfo], |
|
), |
|
}, |
|
provides = [MyInfo], |
|
) |
|
|
|
################################################################################ |
|
|
|
ExampleInfo = provider(fields = dict(original = "depset[File]", markers = "depset[File]")) |
|
|
|
def _aspect_implementation(target, actx): |
|
print(target) |
|
print(actx.label) |
|
|
|
marker = actx.actions.declare_file(actx.label.name + ".marker") |
|
actx.actions.write(marker, actx.label.name) |
|
|
|
original = depset( |
|
direct = [target[DefaultInfo].files.to_list()[0]], |
|
transitive = [ |
|
d[ExampleInfo].original |
|
for d in actx.rule.attr.deps |
|
], |
|
) |
|
markers = depset( |
|
direct = [marker], |
|
transitive = [ |
|
d[ExampleInfo].markers |
|
for d in actx.rule.attr.deps |
|
], |
|
) |
|
|
|
return [ExampleInfo(original = original, markers = markers)] |
|
|
|
example_aspect = aspect( |
|
implementation = _aspect_implementation, |
|
attr_aspects = ["deps"], |
|
attrs = {}, |
|
required_providers = [[MyInfo]], |
|
# required_aspect_providers, |
|
provides = [ExampleInfo], |
|
# requires, |
|
) |
|
|
|
################################################################################ |
|
|
|
frob = rule( |
|
implementation = lambda ctx: [DefaultInfo( |
|
files = ctx.attr.inner[ExampleInfo].markers |
|
)], |
|
attrs = { |
|
"inner": attr.label(providers = [MyInfo], aspects = [example_aspect]), |
|
}, |
|
) |
|
|
|
flub = rule( |
|
implementation = lambda ctx: [DefaultInfo( |
|
files = ctx.attr.inner[ExampleInfo].markers |
|
)], |
|
attrs = { |
|
"inner": attr.label(providers = [MyInfo], aspects = [example_aspect]), |
|
}, |
|
) |