Bazel: Consume toolchain_java from @bazel_tools//tools/jdk package

Starting from Bazel 0.19.x toolchain_java and absolute_javabase are
exposed in Bazel's @bazel_tools//tools/jdk package. Remove our own
definition of those rules and adapt the documentation.

Test Plan:

To build with Java 11 and newer Java versions:

* To build:

  $ bazel build \
    --define=ABSOLUTE_JAVABASE=/usr/lib64/jvm/java-11 \
    --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 \
    :release

* To run the tests --javabase option must be passed as well:

  $ bazel test \
    --define=ABSOLUTE_JAVABASE=/usr/lib64/jvm/java-11 \
    --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 \
    //...

Alternatively, JAVA_HOME should be set to the new Java version:

  $ JAVA_HOME=/usr/lib64/jvm/java-11 bazel test \
    --define=ABSOLUTE_JAVABASE=/usr/lib64/jvm/java-11 \
    --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 \
    //...

Change-Id: I7fc4499fcd52f5b0d95ffcb177b89767000b43ce
This commit is contained in:
David Ostrovsky
2018-11-03 08:48:47 +01:00
parent f27ec617e1
commit 7e1fcd9d44
2 changed files with 14 additions and 48 deletions

36
BUILD
View File

@@ -2,10 +2,6 @@ package(default_visibility = ["//visibility:public"])
load("//tools/bzl:genrule2.bzl", "genrule2")
load("//tools/bzl:pkg_war.bzl", "pkg_war")
load(
"@bazel_tools//tools/jdk:default_java_toolchain.bzl",
"default_java_toolchain",
)
config_setting(
name = "java9",
@@ -17,40 +13,10 @@ config_setting(
config_setting(
name = "java_next",
values = {
"java_toolchain": ":toolchain_vanilla",
"java_toolchain": "@bazel_tools//tools/jdk:toolchain_vanilla",
},
)
# TODO(davido): Switch to consuming it from @bazel_tool//tools/jdk:absolute_javabase
# when new Bazel version is released with this change included:
# https://github.com/bazelbuild/bazel/issues/6012
# https://github.com/bazelbuild/bazel/commit/0173bdbf7bdd1874379d4dd3eb70d5321e0f1816
# As the interim use a hack that works around it by putting the variable reference
# behind a select
config_setting(
name = "use_absolute_javabase",
values = {"define": "USE_ABSOLUTE_JAVABASE=true"},
)
java_runtime(
name = "absolute_javabase",
java_home = select({
":use_absolute_javabase": "$(ABSOLUTE_JAVABASE)",
"//conditions:default": "",
}),
visibility = ["//visibility:public"],
)
# TODO(davido): Switch to consuming it from @bazel_tool//tools/jdk:toolchain_vanilla
# when my change is included in released Bazel version:
# https://github.com/bazelbuild/bazel/commit/0bef68e054eccecd690e5d9f46db8a0c4b2d887a
default_java_toolchain(
name = "toolchain_vanilla",
forcibly_disable_header_compilation = True,
javabuilder = ["@bazel_tools//tools/jdk:VanillaJavaBuilder_deploy.jar"],
jvm_opts = [],
)
genrule(
name = "gen_version",
outs = ["version.txt"],