Skip to content

Commit 52b4de5

Browse files
ted-xiecopybara-github
authored andcommitted
Set the java toolchain source version based on --java_language_version
Fixes #354 PiperOrigin-RevId: 743225947 Change-Id: I6422d395b2654c7f621828b2060f342a9d5cc684
1 parent 71857f2 commit 52b4de5

1 file changed

Lines changed: 41 additions & 4 deletions

File tree

tools/jdk/BUILD

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@ load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
33
load("@rules_shell//shell:sh_test.bzl", "sh_test")
44
load("//tools/jdk:system.bzl", "android_system")
55

6+
# Java language versions
7+
# See https://bazel.build/docs/user-manual#java-language-version
8+
_SUPPORTED_JAVA_LANGUAGE_VERSIONS = [
9+
8,
10+
9,
11+
10,
12+
11,
13+
17,
14+
21,
15+
]
16+
17+
[
18+
config_setting(
19+
name = "java_language_version_%d" % ver,
20+
values = {"java_language_version": str(ver)},
21+
)
22+
for ver in _SUPPORTED_JAVA_LANGUAGE_VERSIONS
23+
]
24+
25+
java_language_version_select_dict = {
26+
":java_language_version_%d" % ver: ":toolchain_android_only_%d" % ver
27+
for ver in _SUPPORTED_JAVA_LANGUAGE_VERSIONS
28+
} | {
29+
"//conditions:default": ":toolchain_android_only_11",
30+
}
31+
632
sh_binary(
733
name = "create_system",
834
srcs = ["create_system.sh"],
@@ -49,11 +75,22 @@ android_system(
4975
],
5076
)
5177

52-
default_java_toolchain(
78+
[
79+
default_java_toolchain(
80+
name = "toolchain_android_only_%d" % ver,
81+
bootclasspath = [
82+
":bootclasspath_android_only",
83+
],
84+
source_version = str(ver),
85+
target_version = str(ver),
86+
visibility = ["//visibility:public"],
87+
)
88+
for ver in _SUPPORTED_JAVA_LANGUAGE_VERSIONS
89+
]
90+
91+
alias(
5392
name = "toolchain_android_only",
54-
bootclasspath = [
55-
":bootclasspath_android_only",
56-
],
93+
actual = select(java_language_version_select_dict),
5794
visibility = ["//visibility:public"],
5895
)
5996

0 commit comments

Comments
 (0)