1

I dug around option and source code but still unsure how to debug a bazel build, java specifically.

Also anyone know how I can change bazel, build it locally and use it on builds to verify. I found bazel invocation: exec -a "$0" "${BAZEL_REAL}" "$@"

where BAZEL_REAL is a binary: /usr/local/Cellar/bazel/0.15.2/libexec/bin/bazel-real

But this doesn't explain closely how it starts and how I can debug it...

Like is it possible to jump in and debug com.google.devtools.build.lib.bazel.rules.java.BazelJavaLibraryRule while building my code? Like if I build my code with Maven, I can do mvnDebug.

bazel build -s
➜  bazel git:(master) ✗ bazel build //examples/java-native/src/main/java/com/example/myproject:hello-world -s
BAZEL_REAL==/usr/local/Cellar/bazel/0.15.2/libexec/bin/bazel-real
INFO: Analysed target //examples/java-native/src/main/java/com/example/myproject:hello-world (15 packages loaded).
INFO: Found 1 target...
Target //examples/java-native/src/main/java/com/example/myproject:hello-world up-to-date:
  bazel-bin/examples/java-native/src/main/java/com/example/myproject/hello-world.jar
  bazel-bin/examples/java-native/src/main/java/com/example/myproject/hello-world
INFO: Elapsed time: 4.943s, Critical Path: 0.29s
INFO: 0 processes.
INFO: Build completed successfully, 2 total actions
HoaPhan
  • 1,714
  • 1
  • 13
  • 35
  • What do you mean by "debug bazel"? Do you mean debug the bazel binary, or debug how it handles the rule you have written? Are you looking for something like [`bazel build -s`](https://stackoverflow.com/a/34004688/3788176)? – Andy Turner Oct 13 '18 at 11:24
  • Like is it possible to jump in and debug com.google.devtools.build.lib.bazel.rules.java.BazelJavaLibraryRule while building my code? bazel build -s – HoaPhan Oct 13 '18 at 15:24
  • See also: https://stackoverflow.com/a/52836468/7778502 – László Oct 16 '18 at 14:16

1 Answers1

4

nevermind me, https://www.bazel.build/contributing.html#setting-up-your-coding-environment has the info I need.

Basically for starter

bazel --host_jvm_debug build //:*

the order of args are significant. For example below will NOT work

bazel build //:* --host_jvm_debug 

To debug worker's jvm, get the command with bazel build -s, then append the remote debug startup opts.

HoaPhan
  • 1,714
  • 1
  • 13
  • 35