bazel: Bazel throws exception if no local JDK is installed
It looks like this was caused by javabase refactorings in these versions, with two distinct breakages occurring in 0.18 -> 0.19 and 0.20 -> 0.21. Representative build logs from a build with Bazel 0.21:
$ bazel-0.21 build //src:bazel
[...]
ERROR: /Users/john/src/bazel/tools/jdk/BUILD:52:1: Executing genrule //tools/jdk:gen_include/darwin/jni_md.h failed (Exit 1) bash failed: error executing command /bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; cp external/local_jdk/include/darwin/jni_md.h bazel-out/darwin-fastbuild/genfiles/tools/jdk/include/darwin/jni_md.h'
Use --sandbox_debug to see verbose messages from the sandbox
cp: external/local_jdk/include/darwin/jni_md.h: No such file or directory
Target //src:bazel failed to build
The genrule comes from a macro:
def java_runtime_files(name, srcs):
"""Copies the given sources out of the current Java runtime."""
native.filegroup(
name = name,
srcs = srcs,
)
for src in srcs:
native.genrule(
name = "gen_%s" % src,
srcs = ["@bazel_tools//tools/jdk:current_java_runtime"],
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
cmd = "cp $(JAVABASE)/%s $@" % src,
outs = [src],
)
Editing that genrule to print out what files it sees indicates that $(JAVABASE)
has become decoupled from $(locations @bazel_tools//tools/jdk:current_java_runtime)
.
- v0.18
$(JAVABASE)
=external/local_jdk
- genrule srcs has
./external/local_jdk/include/jni.h
- v0.19
$(JAVABASE)
=external/local_jdk
- genrule srcs has
./external/embedded_jdk/include/jni.h
- v0.20
$(JAVABASE)
=external/local_jdk
- genrule srcs has
./external/embedded_jdk/include/jni.h
- v0.21
$(JAVABASE)
=external/local_jdk
- genrule srcs has
./external/remotejdk_macos/include/jni.h
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 22 (20 by maintainers)
Installing the default-jdk on Debian 9 fixed the problem for me. However, the gen_java target/test from an earlier comment still fails.