How do I get the commands executed by Bazel

You are correct, you can use the -s (--subcommands) option:

bazel build -s //foo

See https://docs.bazel.build/versions/master/user-manual.html#flag--subcommands.

For your use case, you'd probably want to redirect the output to a file and then global replace any library/binary paths to the Windows equivalents.

You might want to track https://github.com/bazelbuild/bazel/issues/276 (Windows support), although it'll probably be a while.


(Disclaimer: This solution does not print the commands that currently get executed but the commands that would get or got executed.)

I'd use aquery (action graph query) (forget about "graph"):

bazel aquery //foo

Advantages:

  • It's very fast, because it prints the actions without executing the build.
  • It's a query. It does not have side effects.
  • You don't have to do a bazel clean before in order to find out the build steps for a library that has already been built.
  • It prints information about the specific build step that you request. It does not print all the build commands required for the dependencies.

Tags:

Command

Bazel