Skip to content

Commit

Permalink
Use a JDK version-specific toolchain in bazel_java_test.sh
Browse files Browse the repository at this point in the history
e.g. for ` //src/test/shell/bazel:bazel_java_test_jdk16_toolchain_head`,
this test was previously using `@bazel_tools//tools/jdk:toolchain`, which
was leaking the toolchain from the enclosing version of Bazel. It worked
anyways because turbine was always producing JDK 8 class files, but as of
google/turbine@006a74b
turbine uses the class file version corresponding to the `-target` or
`--release` flag.

This fixes e.g.

```
java/com/google/sandwich/B.java:3: error: cannot access C
  C myObject;
  ^
  bad class file: bazel-out/k8-fastbuild/bin/java/com/google/sandwich/libbottom-hjar.jar(/com/google/sandwich/C.class)
    class file has wrong version 59.0, should be 55.0
    Please remove or make sure it appears in the correct subdirectory of the classpath.
```

from #14059

PiperOrigin-RevId: 399738050
  • Loading branch information
cushon authored and copybara-github committed Sep 29, 2021
1 parent 08f3e93 commit 936196a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ if [[ $# -gt 0 ]]; then
JAVA_RUNTIME_VERSION="$1"; shift
add_to_bazelrc "build --java_runtime_version=${JAVA_RUNTIME_VERSION}"
add_to_bazelrc "build --tool_java_runtime_version=${JAVA_RUNTIME_VERSION}"
if [[ "${JAVA_RUNTIME_VERSION}" == 8 ]]; then
JAVA_TOOLCHAIN="@bazel_tools//tools/jdk:toolchain_java8"
elif [[ "${JAVA_RUNTIME_VERSION}" == 11 ]]; then
JAVA_TOOLCHAIN="@bazel_tools//tools/jdk:toolchain_java11"
else
JAVA_TOOLCHAIN="@bazel_tools//tools/jdk:toolchain_jdk_${JAVA_RUNTIME_VERSION}"
fi
fi

export TESTENV_DONT_BAZEL_CLEAN=1
Expand Down

0 comments on commit 936196a

Please sign in to comment.