diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/JvmConfigurationLoader.java | 43 |
1 files changed, 34 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..3323e75e9d 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,32 @@ 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); + if (javaHome == null) { + return null; + } + return new Jvm(javaHome, javaRuntimeSuite.getLabel()); + } + + private static Jvm createFromRuntime(ConfigurationEnvironment lookup, Label javaRuntimeLabel) + throws InvalidConfigurationException, InterruptedException, NoSuchTargetException, + NoSuchPackageException { + PathFragment javaHome = getJavaHome(lookup, javaRuntimeLabel); + if (javaHome == null) { + return null; + } + return new Jvm(javaHome, 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 +157,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) |