Reputation: 28178
In my codebase it's often a mistake to include the same source file in multiple targets (cc_binary
, cc_library
, etc). I'd like to detect this.
I can do
bazel query labels(srcs, //target:name)
to get a list of sources for a single target. This is enough to figure out which sources are part of multiple targets, by doing this for every target and detecting which source files are in multiple targets. But I'd still need a query to get me a list of every target.
It would be a lot easier/cleaner if I could just query which targets a source file belongs to and see if it's a source of multiple targets. Is that possible?
Also, I have a lot of source files, optimalness of the query is a concern too.
Upvotes: 4
Views: 3299
Reputation: 337
A few clarifying questions:
foo/bar/src.c
is only visible to targets defined in foo/bar/BUILD
, and then ensure that foo/bar/BUILD
contains only one cc_library
target.Consider using aspects to obtain a list of all transitive source files of a given target.
If you're truly attached to using bazel query
, you can get a comprehensive list of every target under your project by invoking, for example,
bazel query //...
Upvotes: 2