aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2015-03-20 17:32:19 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-03-23 11:55:34 +0000
commit4aa1364794b7eef692f694aba7988169cfc3a946 (patch)
treeb8f33f3b71a3a17783b0b997f894fae12cffd708 /src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
parent2f95be37dacd79c85277946a3bbe8493d0fa0ae9 (diff)
Description redacted.
-- MOS_MIGRATED_REVID=89134834
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
index a174193226..a2ee1b13cb 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RawAttributeMapper.java
@@ -13,9 +13,16 @@
// limitations under the License.
package com.google.devtools.build.lib.packages;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import com.google.devtools.build.lib.syntax.Label;
+import java.util.Collection;
+import java.util.List;
+
+import javax.annotation.Nullable;
+
/**
* {@link AttributeMap} implementation that returns raw attribute information as contained
* within a {@link Rule}. In particular, configurable attributes of the form
@@ -40,6 +47,39 @@ public class RawAttributeMapper extends AbstractAttributeMapper {
}
/**
+ * Variation of {@link #get} that merges the values of configurable lists together (with
+ * duplicates removed).
+ *
+ * <p>For example, given:
+ * <pre>
+ * attr = select({
+ * ':condition1': [A, B, C],
+ * ':condition2': [C, D]
+ * }),
+ * </pre>
+ * this returns the value <code>[A, B, C, D]</code>.
+ *
+ * <p>If the attribute isn't configurable (e.g. <code>attr = [A, B]</code>), returns
+ * its raw value.
+ *
+ * <p>Throws an {@link IllegalStateException} if the attribute isn't a list type.
+ */
+ @Nullable
+ public <T> Collection<T> getMergedValues(String attributeName, Type<List<T>> type) {
+ Preconditions.checkState(type instanceof Type.ListType<?>);
+ if (!isConfigurable(attributeName, type)) {
+ return get(attributeName, type);
+ }
+
+ Type.Selector<List<T>> selector = getSelector(attributeName, type);
+ ImmutableSet.Builder<T> mergedValues = ImmutableSet.builder();
+ for (List<T> configuredList : selector.getEntries().values()) {
+ mergedValues.addAll(configuredList);
+ }
+ return mergedValues.build();
+ }
+
+ /**
* Returns true if the given attribute is configurable for this rule instance, false
* otherwise.
*/