From aee1f800ad2f8d701ae1ce763b412303472f78eb Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sun, 22 Sep 2019 21:40:54 +0200 Subject: [PATCH] Bazel: Fix toolchain vanilla to not hard code java 8 The main feature of toolchain_vanilla definition is to support newer Java language versions that the embedded JDK, e.g.: at the time of this change, toolchain_java could be used to support building with JDK 13 and produce byte code major version 57, using the combination of absolute javabase and toolchain_vanilla: $ bazel build --define=ABSOLUTE_JAVABASE=/use/local/bin/jdk-13 \ --javabase=@bazel_tools//tools/jdk:absolute_javabase \ --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \ --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ :gerrit Unfortunately, [1] sets source and target language levels to Java 8 to restore backwards compatibility, to fix a regression, that was introduced during upgrade of remote JDK version to Java 11, in: [2]. This change restores the neutrality of toolchain_vanilla declaration by unsetting source and target language level versions. So that the bazel invocation in the example above produces byte code major version 57 (Java 13), and not 52 (Java 8) as it is the case before this change. Also add a TODO, to remove the workaround, when this issue is fixed: [3]. [1] https://github.com/bazelbuild/bazel/commit/6ef6d879ab69225d54ecab3db847fb4eff33bbeb [2] https://github.com/bazelbuild/bazel/commit/bad5a2beb9f8441d97b88d5c4323055e710f72e8 [3] https://github.com/bazelbuild/bazel/issues/9415 Bug: Issue 11571 Change-Id: I721067202de744883bc8c74bb4106ad08f19c66d --- Documentation/dev-bazel.txt | 12 ++++++------ tools/BUILD | 13 +++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Documentation/dev-bazel.txt b/Documentation/dev-bazel.txt index 1a4a75d286..158e528e99 100644 --- a/Documentation/dev-bazel.txt +++ b/Documentation/dev-bazel.txt @@ -43,8 +43,8 @@ provide the path to JDK home: $ bazel build \ --define=ABSOLUTE_JAVABASE= \ --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \ - --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ - --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ + --host_java_toolchain=//tools:toolchain_vanilla \ + --java_toolchain=//tools:toolchain_vanilla \ :release ``` @@ -56,8 +56,8 @@ bazel test runs the test using the target javabase: --define=ABSOLUTE_JAVABASE= \ --javabase=@bazel_tools//tools/jdk:absolute_javabase \ --host_javabase=@bazel_tools//tools/jdk:absolute_javabase \ - --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ - --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla \ + --host_java_toolchain=//tools:toolchain_vanilla \ + --java_toolchain=//tools:toolchain_vanilla \ //... ``` @@ -69,8 +69,8 @@ $ cat << EOF > ~/.bazelrc > build --define=ABSOLUTE_JAVABASE= > build --javabase=@bazel_tools//tools/jdk:absolute_javabase > build --host_javabase=@bazel_tools//tools/jdk:absolute_javabase -> build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla -> build --java_toolchain=@bazel_tools//tools/jdk:toolchain_vanilla +> build --host_java_toolchain=//tools:toolchain_vanilla +> build --java_toolchain=//tools:toolchain_vanilla > EOF ``` diff --git a/tools/BUILD b/tools/BUILD index 5531c3ef78..208a7fcbc0 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -15,6 +15,19 @@ py_binary( visibility = ["//visibility:public"], ) +# TODO(davido): Remove this workaround and switch to using toolchain_vanilla +# from this Bazel package again: @bazel_tools//tools/jdk:toolchain_vanilla, +# when this issue is fixed: https://github.com/bazelbuild/bazel/issues/9415. +default_java_toolchain( + name = "toolchain_vanilla", + forcibly_disable_header_compilation = True, + javabuilder = ["@bazel_tools//tools/jdk:vanillajavabuilder"], + jvm_opts = [], + source_version = "", + target_version = "", + visibility = ["//visibility:public"], +) + default_java_toolchain( name = "error_prone_warnings_toolchain", bootclasspath = ["@bazel_tools//tools/jdk:platformclasspath.jar"],