25

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.

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
  • Did you consider or try using WSL instead of Cygwin or Docker or a VM? – Brian Bulkowski Aug 25 '20 at 21:08
  • 1
    @BrianBulkowski When the question was posed in 2015, I don't believe that WSL was public. I did use WSL early on in the beta releases, and even then it did not access the GPU, so no I would not have considered WSL 1 at the time of the question. While I still keep tabs on using TensorFlow, currently I do not actively use TensorFlow but do keep it in my toolbox. :) Luckily the details of what I was doing back then were made public in this answer, but also it was done many years ago. While I have not installed TensorFlow lately I would try the standard install first now. – Guy Coder Aug 26 '20 at 10:07
  • Luckily the details of what I was doing back then were made public in this [answer](https://stackoverflow.com/a/34788819/1243762), but also it was done many years ago. While I have not installed TensorFlow lately I would try the standard install first now. – Guy Coder Aug 26 '20 at 10:11

2 Answers2

26

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.

kris
  • 23,024
  • 10
  • 70
  • 79
4

(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.
hagello
  • 2,843
  • 2
  • 27
  • 37