Make jvm_runtime.java_home expand Make variables. RELNOTES: None. PiperOrigin-RevId: 161383469
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java index b3d8940..d2999d3 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java
@@ -1108,11 +1108,12 @@ } /** - * Return a context that maps Make variable names (string) to values (string). + * Expands the make variables in {@code expression}. * - * <p>Uses {@NoopExpansionInterceptor}. - * - * @return a ConfigurationMakeVariableContext. + * @param attributeName the name of the attribute from which "expression" comes; used for error + * reporting. + * @param expression the string to expand. + * @return the expanded string. */ public String expandMakeVariables(String attributeName, String expression) { return expandMakeVariables(attributeName, expression, ImmutableList.<MakeVariableSupplier>of());
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntime.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntime.java index 0d15e60..37fbab5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntime.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntime.java
@@ -45,10 +45,13 @@ PrerequisiteArtifacts.nestedSet(ruleContext, "srcs", Mode.TARGET); PathFragment javaHome = defaultJavaHome(ruleContext.getLabel()); if (ruleContext.attributes().isAttributeValueExplicitlySpecified("java_home")) { - PathFragment javaHomeAttribute = PathFragment.create( - ruleContext.attributes().get("java_home", Type.STRING)); + PathFragment javaHomeAttribute = PathFragment.create(ruleContext.expandMakeVariables( + "java_home", ruleContext.attributes().get("java_home", Type.STRING))); if (!filesToBuild.isEmpty() && javaHomeAttribute.isAbsolute()) { ruleContext.ruleError("'java_home' with an absolute path requires 'srcs' to be empty."); + } + + if (ruleContext.hasErrors()) { return null; }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeRule.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeRule.java index ef52686..9d4ae42 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaRuntimeRule.java
@@ -36,7 +36,10 @@ <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ .add(attr("srcs", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE).mandatory()) /* <!-- #BLAZE_RULE(java_runtime).ATTRIBUTE(java_home) --> - The relative path to the root of the runtime. + The path to the root of the runtime. + Subject to <a href="${link make-variables}">"Make" variable</a> substitution. + If this path is absolute, the rule denotes a non-hermetic Java runtime with a well-known + path. In that case, the <code>srcs</code> attribute must be empty. <!-- #END_BLAZE_RULE.ATTRIBUTE --> */ .add(attr("java_home", STRING)) .add(attr("output_licenses", LICENSE))