Skip to content

Commit

Permalink
Clean up Java toolchain configuration
Browse files Browse the repository at this point in the history
now that JDK 8 host_javabases are no longer supported.

PiperOrigin-RevId: 207687089
  • Loading branch information
cushon authored and Copybara-Service committed Aug 7, 2018
1 parent f203272 commit 808ec9f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,7 @@ public void init(ConfiguredRuleClassProvider.Builder builder) {

try {
builder.addWorkspaceFilePrefix(
ResourceFileLoader.loadResource(BazelRuleClassProvider.class, "tools.WORKSPACE")
// Hackily select the java_toolchain based on the host JDK version. JDK 8 and
// 9 host_javabases require different toolchains, e.g. to use --patch-module
// instead of -Xbootclasspath/p:.
.replace(
"%java_toolchain%",
isJdk8OrEarlier()
? "@bazel_tools//tools/jdk:toolchain_hostjdk8"
: "@bazel_tools//tools/jdk:toolchain_hostjdk10"));

ResourceFileLoader.loadResource(BazelRuleClassProvider.class, "tools.WORKSPACE"));
} catch (IOException e) {
throw new IllegalStateException(e);
}
Expand All @@ -65,8 +56,4 @@ public void init(ConfiguredRuleClassProvider.Builder builder) {
public ImmutableList<RuleSet> requires() {
return ImmutableList.of(CoreRules.INSTANCE);
}

private static boolean isJdk8OrEarlier() {
return Double.parseDouble(System.getProperty("java.class.version")) <= 52.0;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
local_repository(name = "bazel_tools", path = __embedded_dir__ + "/embedded_tools")
bind(name = "cc_toolchain", actual = "@bazel_tools//tools/cpp:default-toolchain")
bind(name = "java_toolchain", actual = "%java_toolchain%")
22 changes: 1 addition & 21 deletions tools/jdk/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package(default_visibility = ["//visibility:public"])
load(
"//tools/jdk:default_java_toolchain.bzl",
"default_java_toolchain",
"JDK8_JVM_OPTS",
"JDK10_JVM_OPTS",
"DEFAULT_JAVACOPTS",
)

Expand Down Expand Up @@ -195,27 +193,15 @@ genrule(
)

default_java_toolchain(
name = "toolchain_hostjdk8",
bootclasspath = [":bootclasspath"],
extclasspath = [":extclasspath"],
jvm_opts = JDK8_JVM_OPTS,
source_version = "8",
target_version = "8",
)

default_java_toolchain(
name = "toolchain_hostjdk10",
name = "toolchain",
bootclasspath = [":bootclasspath"],
extclasspath = [":extclasspath"],
jvm_opts = JDK10_JVM_OPTS,
source_version = "8",
target_version = "8",
)

default_java_toolchain(
name = "toolchain_java9",
# We use the same flags for JDK9 and 10
jvm_opts = JDK10_JVM_OPTS,
misc = DEFAULT_JAVACOPTS + [
"--release",
"9",
Expand All @@ -224,18 +210,12 @@ default_java_toolchain(

default_java_toolchain(
name = "toolchain_java10",
jvm_opts = JDK10_JVM_OPTS,
misc = DEFAULT_JAVACOPTS + [
"--release",
"10",
],
)

alias(
name = "toolchain",
actual = "//external:java_toolchain",
)

filegroup(
name = "srcs",
srcs = [
Expand Down
8 changes: 2 additions & 6 deletions tools/jdk/default_java_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@

"""Bazel rules for creating Java toolchains."""

JDK8_JVM_OPTS = [
"-Xbootclasspath/p:$(location @bazel_tools//third_party/java/jdk/langtools:javac_jar)",
]

JDK10_JVM_OPTS = [
JVM_OPTS = [
# In JDK9 we have seen a ~30% slow down in JavaBuilder performance when using
# G1 collector and having compact strings enabled.
"-XX:+UseParallelOldGC",
Expand Down Expand Up @@ -75,7 +71,7 @@ DEFAULT_TOOLCHAIN_CONFIGURATION = {
"@bazel_tools//third_party/java/jdk/langtools:jdk_compiler_jar",
],
"javac_supports_workers": 1,
"jvm_opts": JDK8_JVM_OPTS,
"jvm_opts": JVM_OPTS,
"misc": DEFAULT_JAVACOPTS,
"compatible_javacopts": COMPATIBLE_JAVACOPTS,
"singlejar": ["@bazel_tools//tools/jdk:singlejar"],
Expand Down

0 comments on commit 808ec9f

Please sign in to comment.