9

I dig around Bazel source code, there aren't much logging it seems. Is there a way to enable some kind of verbose mode so I can see what bazel is doing?

Also there seems to be various kind of debug options but I cant seem to comprehend yet, if I want to debug say java_library how should I do it?

HoaPhan
  • 1,714
  • 1
  • 13
  • 35

1 Answers1

8

To debug what Bazel does and why:

To debug programs you built with Bazel:

  • You cannot debug java_library rules
  • You can debug java_binary rules. Build with "-c dbg" (see the "--compilation_mode" flag), then run the binary with bazel-bin/path/to/java/program --debug=<port>

EDIT: added info about --verbose_failures and --verbose_explanations

László
  • 3,973
  • 1
  • 13
  • 26
  • "To debug programs you built with Bazel" Nah I actually meant debugging Bazel build itself, like when it is running https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaLibraryRule.java – HoaPhan Oct 23 '18 at 09:38
  • FYI, you don't need to add these flags to `.bazelrc`, all that does is letting you use the `--config=debug` flag in the future. You can instead just pass the flags directly to Bazel to build a debuggable Bazel binary: `bazel build //src:bazel -c dbg --javacopt="-g" --copt="-g" --strip="never"` – László Oct 23 '18 at 09:54
  • It will yield bazel build //src:bazel -c dbg --javacopt="-g" --copt="-g" --strip="never" Starting local Bazel server and connecting to it... ERROR: bazel should not be called from a bazel output directory. The pertinent workspace directory is: '/Users/hoaphan/dev/AlexCal/bazel' INFO: Invocation ID: f5fa1836-9182-445e-bb7d-8b7839bb9002 This works for me: bazel --host_jvm_debug build //src/main/java/com/example/cmdline:runner_deploy.jar Not sure if --jobs=1 will make it better. – HoaPhan Oct 23 '18 at 11:12
  • 1
    Copy the file (`bazel-bin/src/bazel`) out of the output tree, e.g. to `$HOME/devbazel`, and run from there. – László Oct 23 '18 at 12:11
  • 1
    Alas, but all of those flags still do not show me what bazel is actually _putting_ onto the command line to build and (fail to) link my program. If I were to make a build system (I have), this would be close to the first feature I'd make. – Zendel Jul 19 '22 at 21:10