aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2015-02-09 21:38:59 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-09 21:38:59 +0000
commit9edc821c0b444411fb18c0ddb005988a983c645e (patch)
treeb81c44d5897f2abdfe220638baab6460542b81c8 /src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
parentfa720b3b4469ed8ce84c3e5c843df313e68cd814 (diff)
Configurable attributes: allow multiple matches so long as
one is a specialization of the other (e.g. {"foo=bar"} and {"foo=bar", "baz=bug"}. The most precise one wins. RELNOTES: When two configurable attribute conditions match and one is a specialization of the other, the most precise match is chosen. -- MOS_MIGRATED_REVID=85921611
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
index 84029b2046..67ff7a23c7 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapper.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.analysis;
import com.google.common.base.Preconditions;
+import com.google.common.base.Verify;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
@@ -102,25 +103,33 @@ public class ConfiguredAttributeMapper extends AbstractAttributeMapper {
return super.get(attributeName, type);
}
- // We expect exactly one of this attribute's conditions to match (including the default
- // condition, if specified). Throw an exception if our expectations aren't met.
- Label matchingCondition = null;
+ ConfigMatchingProvider matchingCondition = null;
T matchingValue = null;
// Find the matching condition and record its value (checking for duplicates).
for (Map.Entry<Label, T> entry : selector.getEntries().entrySet()) {
- Label curCondition = entry.getKey();
- if (Type.Selector.isReservedLabel(curCondition)) {
+ Label selectorKey = entry.getKey();
+ if (Type.Selector.isReservedLabel(selectorKey)) {
continue;
- } else if (Preconditions.checkNotNull(configConditions.get(curCondition)).matches()) {
- if (matchingCondition != null) {
+ }
+
+ ConfigMatchingProvider curCondition = Verify.verifyNotNull(configConditions.get(selectorKey));
+
+ if (curCondition.matches()) {
+ if (matchingCondition == null || curCondition.refines(matchingCondition)) {
+ // A match is valid if either this is the *only* condition that matches or this is a
+ // more "precise" specification of another matching condition (in which case we choose
+ // the most precise one).
+ matchingCondition = curCondition;
+ matchingValue = entry.getValue();
+ } else if (matchingCondition.refines(curCondition)) {
+ // The originally matching conditions is more precise, so keep that one.
+ } else {
throw new EvalException(rule.getAttributeLocation(attributeName),
- "Both " + matchingCondition.toString() + " and " + curCondition.toString()
+ "Both " + matchingCondition.label() + " and " + curCondition.label()
+ " match configurable attribute \"" + attributeName + "\" in " + getLabel()
- + ". At most one match is allowed");
+ + ". Multiple matches are not allowed unless one is a specialization of the other");
}
- matchingCondition = curCondition;
- matchingValue = entry.getValue();
}
}