45

How can I increase the verbosity of the build process? Bazel seems to print compiler commands only if something goes wrong during the build.

I would like to see which compiler comands the cc_library rule fires, even if everything seems to be fine, to debug linking problems. I already tried various bazel command line parameters but nothing gives me the compiler commands :(

Jan
  • 1,281
  • 1
  • 13
  • 18
  • Possible duplicate of [How do I get the commands executed by Bazel](https://stackoverflow.com/questions/33983711/how-do-i-get-the-commands-executed-by-bazel) – 200_success Apr 13 '18 at 21:42
  • 3
    Which is 2 months younger than this question. So why do you mark my question as a duplicate? – Jan Apr 16 '18 at 05:47
  • Because the other question presents the challenge in more detail, and has an answer with a citation. – 200_success Apr 16 '18 at 06:31

3 Answers3

65

This is probably what you are looking for:

bazel build --subcommands //my:target

The --subcommands option causes Bazel's execution phase to print the full command line for each command prior to executing it.

John
  • 27,926
  • 10
  • 75
  • 78
  • 1
    You also have to change something in the code base to make it rebuild--even if that just means deleting a parenthesis somewhere to make the build break. – Gabriel Staples Feb 27 '20 at 23:58
  • Where is the official documentation for the `-s` option? Is there a long form of this short option which is more easy to Google? – Gabriel Staples Jun 24 '20 at 23:46
  • 2
    https://docs.bazel.build/versions/master/user-manual.html#flag--subcommands `bazel help build` prints: `--[no]subcommands [-s] (true, pretty_print or false; default: "false")` – hnakamur Nov 26 '20 at 14:03
  • +1 to hnakamur's comment. I think people should usually use the verbose version of flags in stackoverflow answers because they are more explanatory. `bazel build --subcommands //my:target` is clear and easy to search for compared to `-s`. – gonzojive Jul 27 '21 at 15:53
13

Useful information taken from Envoy's bazel readme (https://github.com/envoyproxy/envoy/blob/master/bazel/README.md)

When trying to understand what Bazel is doing, the -s and --explain options are useful. To have Bazel provide verbose output on which commands it is executing:

bazel build -s //source/...

To have Bazel emit to a text file the rationale for rebuilding a target:

bazel build --explain=file.txt //source/...

To get more verbose explanations:

bazel build --explain=file.txt --verbose_explanations //source/...
mancini0
  • 3,683
  • 1
  • 26
  • 28
1

Maybe you can generate the compile_commands.json file. I have created Shell scripts (under Linux) to automate that: https://github.com/vincent-picaud/Bazel_and_CompileCommands.

Picaud Vincent
  • 9,660
  • 4
  • 27
  • 62