Guy Coder
Guy Coder

Reputation: 24976

How do I get the commands executed by Bazel

I was wondering if there is a way to get Bazel to list, output, display, etc., all of the commands that can be executed from a command line that are run during a build after a clean. I do not care if the output is to the screen, in a file, etc. I will massage it into a usable form if necessary.

I have captured the screen output during a run of Bazel which gives me an idea of what is being done, however it does not give me a command I can execute on the command line. The command would have to include all of the command options and not display variables.

If this is not possible, since Bazel is open source, where in the code is/are the lines that represent the commands to be run so that I can modify Bazel to output the executable commands.

I am aware of the query command within Bazel, and used it generate the dependency diagram. If this could be done as a query command it would be even better.

TLDR;

My goal is to build TensorFlow using Bazel on Windows. Yes I know of all of the problems and reasons NOT to do it and have successfully installed TensorFlow on Windows via a Virtual Machine or Docker. I did take a shot at building Bazel on Windows starting with Cygwin, but that started to get out of hand as I am use to installing with packages and Cygwin doesn't play nice with packages, so then I started trying to build Bazel by hand and that was turning into a quagmire. So I am now trying to just build TensorFlow by hand on Windows by duplicating what Bazel would do to build TensorFlow on Linux.

Upvotes: 27

Views: 19144

Answers (2)

hagello
hagello

Reputation: 3255

(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.

Upvotes: 7

kris
kris

Reputation: 23592

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.

Upvotes: 29

Related Questions