aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2017-12-20 14:36:40 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-20 14:38:04 -0800
commit56ef727987c05df2953a4a53935b4f9b899f9d81 (patch)
tree555138a3c2ebf5b175952c1e37f7cc51041810ec /src
parentd25f9534dfd106c32f14e84e0a339965aeed3e2e (diff)
Allow --javabase to accept java_runtime (not just java_runtime_suite)
Fixes bazelbuild/bazel#3407 PiperOrigin-RevId: 179735489
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java b/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
index 10367cf631..51f6778fd8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java
@@ -83,13 +83,17 @@ public final class JvmConfigurationLoader implements ConfigurationFragmentFactor
}
Target javaHomeTarget = lookup.getTarget(javaBase);
if (javaHomeTarget instanceof Rule) {
- if (!((Rule) javaHomeTarget).getRuleClass().equals("java_runtime_suite")) {
- throw new InvalidConfigurationException(
- "Unexpected javabase rule kind '"
- + ((Rule) javaHomeTarget).getRuleClass()
- + "'. Expected java_runtime_suite");
+ switch (((Rule) javaHomeTarget).getRuleClass()) {
+ case "java_runtime_suite":
+ return createFromRuntimeSuite(lookup, (Rule) javaHomeTarget, cpu);
+ case "java_runtime":
+ return createFromRuntime(lookup, javaHomeTarget.getLabel());
+ default:
+ throw new InvalidConfigurationException(
+ "Unexpected javabase rule kind '"
+ + ((Rule) javaHomeTarget).getRuleClass()
+ + "'. Expected java_runtime_suite");
}
- return createFromRuntimeSuite(lookup, (Rule) javaHomeTarget, cpu);
}
throw new InvalidConfigurationException(
"No JVM target found under " + javaBase + " that would work for " + cpu);
@@ -101,11 +105,25 @@ public final class JvmConfigurationLoader implements ConfigurationFragmentFactor
// TODO(b/34175492): eventually the Jvm fragement will containg only the label of a java_runtime
// rule, and all of the configuration will be accessed using JavaRuntimeInfo.
- private static Jvm createFromRuntimeSuite(ConfigurationEnvironment lookup, Rule javaRuntimeSuite,
- String cpu)
+
+ private static Jvm createFromRuntimeSuite(
+ ConfigurationEnvironment lookup, Rule javaRuntimeSuite, String cpu)
throws InvalidConfigurationException, InterruptedException, NoSuchTargetException,
NoSuchPackageException {
Label javaRuntimeLabel = selectRuntime(javaRuntimeSuite, cpu);
+ PathFragment javaHome = getJavaHome(lookup, javaRuntimeLabel);
+ return new Jvm(javaHome, javaRuntimeSuite.getLabel());
+ }
+
+ private static Jvm createFromRuntime(ConfigurationEnvironment lookup, Label javaRuntimeLabel)
+ throws InvalidConfigurationException, InterruptedException, NoSuchTargetException,
+ NoSuchPackageException {
+ return new Jvm(getJavaHome(lookup, javaRuntimeLabel), javaRuntimeLabel);
+ }
+
+ private static PathFragment getJavaHome(ConfigurationEnvironment lookup, Label javaRuntimeLabel)
+ throws NoSuchPackageException, NoSuchTargetException, InterruptedException,
+ InvalidConfigurationException {
Target javaRuntimeTarget = lookup.getTarget(javaRuntimeLabel);
if (javaRuntimeTarget == null) {
return null;
@@ -132,7 +150,7 @@ public final class JvmConfigurationLoader implements ConfigurationFragmentFactor
javaHomePath, srcs.toString()));
}
}
- return new Jvm(javaHomePath, javaRuntimeSuite.getLabel());
+ return javaHomePath;
}
private static Label selectRuntime(Rule javaRuntimeSuite, String cpu)