From d579b6eafd1d41a73c0dfce7b9ffcfdf1d607a97 Mon Sep 17 00:00:00 2001 From: lberki Date: Mon, 10 Jul 2017 14:28:56 +0200 Subject: Make jvm_runtime.java_home expand Make variables. RELNOTES: None. PiperOrigin-RevId: 161383469 --- .../java/com/google/devtools/build/lib/analysis/RuleContext.java | 9 +++++---- .../com/google/devtools/build/lib/rules/java/JavaRuntime.java | 7 +++++-- .../google/devtools/build/lib/rules/java/JavaRuntimeRule.java | 5 ++++- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/main/java/com') 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 b3d8940598..d2999d3098 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 @@ public final class RuleContext extends TargetContext } /** - * Return a context that maps Make variable names (string) to values (string). + * Expands the make variables in {@code expression}. * - *

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.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 0d15e60e9f..37fbab51da 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 @@ public class JavaRuntime implements RuleConfiguredTargetFactory { 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 ef526863f8..9d4ae426cf 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 @@ public final class JavaRuntimeRule implements RuleDefinition { */ .add(attr("srcs", LABEL_LIST).allowedFileTypes(FileTypeSet.ANY_FILE).mandatory()) /* - The relative path to the root of the runtime. + The path to the root of the runtime. + Subject to "Make" variable substitution. + If this path is absolute, the rule denotes a non-hermetic Java runtime with a well-known + path. In that case, the srcs attribute must be empty. */ .add(attr("java_home", STRING)) .add(attr("output_licenses", LICENSE)) -- cgit v1.2.3