aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/android
diff options
context:
space:
mode:
authorGravatar mstaib <mstaib@google.com>2017-05-31 18:17:06 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-06-01 14:07:41 +0200
commitfd2c682a6a6bb0759f92476e533bffd2883b9c27 (patch)
tree10fe94488353823aea7d0872995e65823d8f632e /src/main/java/com/google/devtools/build/lib/rules/android
parent65ceda9c9f686bc27f7319817985a4df07b60f9d (diff)
Fix aliases for users of label-keyed string dicts.
Aliases mess with the assumption that attributeValue.containsKey(target.getLabel()) for every target in the prerequisites of a LABEL_KEYED_STRING_DICT attribute. The solution is to use AliasProvider.getDependencyLabel(target) instead. This fixes it for all current users, including SkylarkRuleContext. This also adjusts config_setting flag_values and Android feature_flags to do intelligent things with aliases in their respective attributes. RELNOTES: None. PiperOrigin-RevId: 157594095
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/android')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidFeatureFlagSetProvider.java18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidFeatureFlagSetProvider.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidFeatureFlagSetProvider.java
index 315aea19c6..29375a9ead 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidFeatureFlagSetProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidFeatureFlagSetProvider.java
@@ -25,6 +25,7 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException;
+import com.google.devtools.build.lib.rules.AliasProvider;
import com.google.devtools.build.lib.rules.config.ConfigFeatureFlagProvider;
import java.util.Map;
@@ -53,7 +54,7 @@ public abstract class AndroidFeatureFlagSetProvider implements TransitiveInfoPro
/**
* Builds a map which can be used with create, confirming that the desired flag values were
* actually received, and producing an error if they were not (because dynamic configurations are
- * not enabled).
+ * not enabled, or because aliases were used).
*/
public static ImmutableMap<Label, String> getAndValidateFlagMapFromRuleContext(
RuleContext ruleContext) throws RuleErrorException {
@@ -62,8 +63,18 @@ public abstract class AndroidFeatureFlagSetProvider implements TransitiveInfoPro
.get(FEATURE_FLAG_ATTR, BuildType.LABEL_KEYED_STRING_DICT);
Iterable<? extends TransitiveInfoCollection> actualTargets =
ruleContext.getPrerequisites(FEATURE_FLAG_ATTR, Mode.TARGET);
+ boolean aliasFound = false;
for (TransitiveInfoCollection target : actualTargets) {
- Label label = target.getLabel();
+ Label label = AliasProvider.getDependencyLabel(target);
+ if (!label.equals(target.getLabel())) {
+ ruleContext.attributeError(
+ FEATURE_FLAG_ATTR,
+ String.format(
+ "Feature flags must be named directly, not through aliases; use '%s', not '%s'",
+ target.getLabel(), label));
+ aliasFound = true;
+ }
+
String expectedValue = expectedValues.get(label);
String actualValue = ConfigFeatureFlagProvider.fromTarget(target).getValue();
@@ -75,6 +86,9 @@ public abstract class AndroidFeatureFlagSetProvider implements TransitiveInfoPro
throw new RuleErrorException();
}
}
+ if (aliasFound) {
+ throw new RuleErrorException();
+ }
return ImmutableMap.copyOf(expectedValues);
}