2

I know there is bazel info <...> bazel-bin but that is only giving the output path prefix. I am hoping for some fancy cquery or aquery to get the complete path for the outputs.

robsiemb
  • 6,157
  • 7
  • 32
  • 46
user7018565
  • 209
  • 2
  • 12

1 Answers1

3

As far as I know there's no an easy way to get that (see related discussions below), but if your target is runnable you can use this nice trick:

bazel run --run_under "echo" //path/to/folder:target

This will print the full path of the binary on disk (within the bazel cache folder).

A more general way to get output paths for a target would be through aquery, e.g.

bazel aquery "//path/to/folder:target" --noinclude_commandline --output=text

This will print the outputs for all the actions related to the given target (for a cc_binary these will include the object files, the binary, the stripped binary, etc...) - you can then grep for Outputs and extract the path.

This is an example output for a cc_binary:

> bazel aquery "//path/to/folder:target" --noinclude_commandline --output=text

action 'Compiling path/to/folder/main.cc'
  Mnemonic: CppCompile
  Target: //path/to/folder:target
  Configuration: k8-fastbuild
  ActionKey: ...
  Inputs: [..., path/to/folder/main.cc]
  Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/main.pic.d,
            bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/main.pic.o]

...

action 'Linking path/to/folder/target'
  Mnemonic: CppLink
  Target: //path/to/folder:target
  Configuration: k8-fastbuild
  ActionKey: ...
  Inputs: [..., bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/main.pic.o, ...]
  Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/target]

action 'Stripping path/to/folder/target.stripped for //path/to/folder:target'
  Mnemonic: CcStrip
  Target: //path/to/folder:target
  Configuration: k8-fastbuild
  ActionKey: ...
  Inputs: [..., bazel-out/k8-fastbuild/bin/path/to/folder/target]
  Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/target.stripped]

...
...
...

Paths are relative, but you can resolve them by getting the workspace folder with bazel info workspace.

If you're interested in the output(s) of a specific action, for example the final binary resulting from linking, you can filter by mnemonic type:

> bazel aquery "mnemonic(CppLink, //path/to/folder:target)" --noinclude_commandline --output=text

action 'Linking path/to/folder/target'
  Mnemonic: CppLink
  Target: //path/to/folder:target
  Configuration: k8-fastbuild
  ActionKey: ...
  Inputs: [..., bazel-out/k8-fastbuild/bin/path/to/folder/_objs/target/target.pic.o, ...]
  Outputs: [bazel-out/k8-fastbuild/bin/path/to/folder/target]

Not a full answer, but hope this helps.

Other related discussions:

dms
  • 1,260
  • 7
  • 12