From 2b25a2a85a7b4d743eb3f38138bb350a19295077 Mon Sep 17 00:00:00 2001 From: lberki Date: Thu, 17 Aug 2017 11:24:19 +0200 Subject: Fetch the Java-specific Make variables from the :host_jdk dependency instead of the configuration in genrules. This is necessary because if one uses a java_runtime rule that has java_home="$(VAR") and VAR is set to an absolute path, BuildConfiguration won't be able to resolve VAR (since it's a Make variable and thus can't affect other Make variables), Blaze won't be able to tell that it's an absolute value and thus will prepend the package name of the java_runtime rule to it, e.g. resulting in a//foo/bar instead of /foo/bar if the java_runtime rule is in package a. RELNOTES: None. PiperOrigin-RevId: 165555251 --- .../java/com/google/devtools/build/lib/analysis/RuleContext.java | 4 ++-- .../com/google/devtools/build/lib/rules/genrule/GenRuleBase.java | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib') 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 2274a3dfb9..eaa634d34b 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 @@ -1086,8 +1086,8 @@ public final class RuleContext extends TargetContext if (!attributes().has(attributeName)) { continue; } - Iterables.addAll(makeVariableProviders, - getPrerequisites(attributeName, Mode.TARGET, MakeVariableProvider.SKYLARK_CONSTRUCTOR)); + Iterables.addAll(makeVariableProviders, getPrerequisites( + attributeName, Mode.DONT_CHECK, MakeVariableProvider.SKYLARK_CONSTRUCTOR)); } LinkedHashMap makeVariables = new LinkedHashMap<>(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java index 7ea6743a05..e2b14a62ce 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java +++ b/src/main/java/com/google/devtools/build/lib/rules/genrule/GenRuleBase.java @@ -46,6 +46,7 @@ import com.google.devtools.build.lib.rules.java.JavaHelper; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.LazyString; import com.google.devtools.build.lib.vfs.PathFragment; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -354,9 +355,11 @@ public abstract class GenRuleBase implements RuleConfiguredTargetFactory { return dir.getRelative(relPath).getPathString(); } } else if (JDK_MAKE_VARIABLE.matcher("$(" + variableName + ")").find()) { + List attributes = new ArrayList<>(); + attributes.addAll(ConfigurationMakeVariableContext.DEFAULT_MAKE_VARIABLE_ATTRIBUTES); + attributes.add(":host_jdk"); return new ConfigurationMakeVariableContext( - ruleContext.getMakeVariables( - ConfigurationMakeVariableContext.DEFAULT_MAKE_VARIABLE_ATTRIBUTES), + ruleContext.getMakeVariables(attributes), ruleContext.getTarget().getPackage(), ruleContext.getHostConfiguration()) .lookupMakeVariable(variableName); -- cgit v1.2.3