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:
parent
987abc7c83
commit
17188224b7
40
BUILD
40
BUILD
@ -1,7 +1,5 @@
|
||||
load(
|
||||
"@bazel_tools//tools/jdk:default_java_toolchain.bzl",
|
||||
"default_java_toolchain",
|
||||
)
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load("//tools/bzl:genrule2.bzl", "genrule2")
|
||||
load("//tools/bzl:pkg_war.bzl", "pkg_war")
|
||||
|
||||
@ -15,42 +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({
|
||||
"//conditions:default": "",
|
||||
":use_absolute_javabase": "$(ABSOLUTE_JAVABASE)",
|
||||
}),
|
||||
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 = [],
|
||||
)
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
genrule(
|
||||
name = "gen_version",
|
||||
outs = ["version.txt"],
|
||||
|
@ -26,11 +26,11 @@ To build Gerrit with Java 10 and newer, specify vanilla java toolchain and
|
||||
provide the path to JDK home:
|
||||
|
||||
```
|
||||
$ bazel build --host_javabase=:absolute_javabase \
|
||||
$ bazel build \
|
||||
--define=ABSOLUTE_JAVABASE=<path-to-java-10> \
|
||||
--define=USE_ABSOLUTE_JAVABASE=true \
|
||||
--host_java_toolchain=//:toolchain_vanilla \
|
||||
--java_toolchain=//:toolchain_vanilla \
|
||||
--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
|
||||
```
|
||||
|
||||
@ -38,12 +38,12 @@ To run the tests, `--javabase` option must be passed as well, because
|
||||
bazel test runs the test using the target javabase:
|
||||
|
||||
```
|
||||
$ bazel test --host_javabase=:absolute_javabase \
|
||||
--javabase=:absolute_javabase \
|
||||
$ bazel test \
|
||||
--define=ABSOLUTE_JAVABASE=<path-to-java-10> \
|
||||
--define=USE_ABSOLUTE_JAVABASE=true \
|
||||
--host_java_toolchain=//:toolchain_vanilla \
|
||||
--java_toolchain=//:toolchain_vanilla \
|
||||
--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 \
|
||||
//...
|
||||
```
|
||||
|
||||
@ -53,10 +53,10 @@ they could be added to ~/.bazelrc resource file:
|
||||
```
|
||||
$ cat << EOF > ~/.bazelrc
|
||||
> build --define=ABSOLUTE_JAVABASE=<path-to-java-10>
|
||||
> build --javabase=:absolute_javabase
|
||||
> build --host_javabase=:absolute_javabase
|
||||
> build --host_java_toolchain=//:toolchain_vanilla
|
||||
> build --java_toolchain=//:toolchain_vanilla
|
||||
> 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
|
||||
> EOF
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user