Reputation: 1865
From https://stackoverflow.com/a/59455700/6162120:
cc_library
produces several outputs, which are separated by output groups. If you want to get only .so outputs, you can usefilegroup
withdynamic_library
output group.
Where can I find the list of all the output groups produced by cc_library
? And more generally, how can I list all the output groups of a bazel rule?
Upvotes: 4
Views: 5057
Reputation: 13503
In the next Bazel release (after 3.7), or using Bazel@HEAD as of today, you can use cquery --output=starlark
and the providers()
function to do this:
$ bazel-dev cquery //:java-maven \
--output=starlark \
--starlark:expr="[p for p in providers(target)]"
["InstrumentedFilesInfo", "JavaGenJarsProvider", "JavaInfo", "JavaRuntimeClasspathProvider", "FileProvider", "FilesToRunProvider", "OutputGroupInfo"]
Upvotes: 4
Reputation: 5006
This isn't a replacement for documentation, but it's possible to get the output groups of targets using an aspect:
defs.bzl
:
def _output_group_query_aspect_impl(target, ctx):
for og in target.output_groups:
print("output group " + str(og) + ": " + str(getattr(target.output_groups, og)))
return []
output_group_query_aspect = aspect(
implementation = _output_group_query_aspect_impl,
)
Then on the command line:
bazel build --nobuild Foo --aspects=//:defs.bzl%output_group_query_aspect
(--nobuild
runs just the analysis phase and avoids running the execution phase if you don't need it)
For a java_binary
this returns e.g.:
DEBUG: defs.bzl:3:5: output group _hidden_top_level_INTERNAL_: depset([<generated file _middlemen/Foo-runfiles>])
DEBUG: defs.bzl:3:5: output group _source_jars: depset([<generated file Foo-src.jar>])
DEBUG: defs.bzl:3:5: output group compilation_outputs: depset([<generated file Foo.jar>])
Upvotes: 3