2

Consider somepath/BUILD file:

load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")

proto_library(
    name = "bar_proto",
    srcs = ["bar.proto"],
)

java_proto_library(
    name = "bar_java_proto",
    deps = [":bar_proto"],
)

By inspecting bazel-bin folder, I find bazel-bin/somepath/libbar_proto-speed.jar.

How do I get bazel-bin/somepath/libbar_proto-speed.jar from //somepath:bar_java_proto using bazel query?

Igor Gatis
  • 4,648
  • 10
  • 43
  • 66

3 Answers3

5

You don't.

Knowing output paths requires executing Bazel's loading and analysis phases, i.e. (1) loading the BUILD files and (2) analyzing dependencies to come up with the execution plan and concrete build actions (called the "action graph").

Bazel query only runs the loading phase, not the analysis phase, therefore it doesn't know about output paths.

Bazel cquery ("configured query") runs after the analysis phase [1], but as far as I understand it also cannot return output paths.

[1] https://docs.bazel.build/versions/master/cquery.html

László
  • 3,973
  • 1
  • 13
  • 26
0

You can do this using action query; e.g.

bazel aquery 'outputs("lib.*proto.*\.jar", //somepath:bar_java_proto)'

By default, you'll get an output looking something like;

action 'Some action name'
  Mnemonic: ...
  Target: ...
  Configuration: ...
  ActionKey: ...
  Inputs: [...]
  Outputs: [...]

But you can change this using the --output flag (overloaded terminology here). From the bazel docs;

--output=(text|summary|proto|jsonproto|textproto), default=text The text (default) and summary output formats are human-readable, select proto, textproto, or jsonproto for a machine-readable format. The proto message for the machine-readable formats is analysis.ActionGraphContainer.

You can of course broaden or narrow the output glob to suite your needs e.g. List all .jar file outputs from //somepath:bar_java_proto.

bazel aquery 'outputs(".*\.jar", //somepath:bar_java_proto)'

silvergasp
  • 1,517
  • 12
  • 23
0

You can use cquery's --output=starlark option:

bazel cquery //somepath:bar_java_proto --output=starlark --starlark:expr="target.files.to_list()[0].path"
darkdragon
  • 392
  • 5
  • 13