Reputation: 360
I am writing a custom rule that takes inputs from cc_library
, cc_binary
, apple_static_library
, and a few other platform-specific rules. I'd like to view each API given to me via referencing ctx.attr.foo
inside the custom rule's implementation function.
There is a list of providers here https://docs.bazel.build/versions/master/skylark/lib/skylark-provider.html but it doesn't say which rules are using them.
Is there a best practice for viewing what these rules are providing me, or does it require going through the source for each one?
Upvotes: 1
Views: 2173
Reputation: 601
This is how you get all providers and output groups from a target:
bazel cquery my_target --output=starlark --starlark:expr="providers(target)"
Upvotes: 4
Reputation: 3848
You can get a list of providers for a given target with dir. Something like this is helpful for debugging:
def _print_attrs_impl(ctx):
for target in ctx.attr.targets:
print('%s: %s' % (target.label, dir(target)))
Printing from inside a rule you're developing is often helpful too, to verify targets are actually what you expect them to be.
You can also apply dir
to the providers themselves, to see what fields they have.
Upvotes: 2