diff options
author | 2016-10-27 19:53:11 +0000 | |
---|---|---|
committer | 2016-10-28 16:02:43 +0000 | |
commit | 578a5122cc4bf6239222226adfa2dafd32c4c220 (patch) | |
tree | 50d8a3136c15e7631c4afcc21208349f160ff08a /src/main/java/com/google/devtools/build/lib/packages | |
parent | e5788617934ee28ce1cdcd096e620ab9e7c2f37f (diff) |
bazel query:
- Extend https://github.com/bazelbuild/bazel/commit/83ffb5e7bc034ea2dd1e957249079b3884a9450d to --output=xml, --output=proto, too. This makes query much more resilient against freezing / OOMing from "select() + select() + select() + ..." patterns.
- Make the above logic accessible to any output type.
- Move AggregatingAttributeMapper.flattenAttributeValues to ProtoOutputFormatter, since this is really a utility method for ProtoOutputFormatter.
--
MOS_MIGRATED_REVID=137429116
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java | 94 |
1 files changed, 0 insertions, 94 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java index 2d9e4d491d..17f8dad21c 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java +++ b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java @@ -13,25 +13,6 @@ // limitations under the License. package com.google.devtools.build.lib.packages; -import static com.google.devtools.build.lib.packages.BuildType.DISTRIBUTIONS; -import static com.google.devtools.build.lib.packages.BuildType.FILESET_ENTRY_LIST; -import static com.google.devtools.build.lib.packages.BuildType.LABEL; -import static com.google.devtools.build.lib.packages.BuildType.LABEL_DICT_UNARY; -import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST; -import static com.google.devtools.build.lib.packages.BuildType.LICENSE; -import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL; -import static com.google.devtools.build.lib.packages.BuildType.NODEP_LABEL_LIST; -import static com.google.devtools.build.lib.packages.BuildType.OUTPUT; -import static com.google.devtools.build.lib.packages.BuildType.OUTPUT_LIST; -import static com.google.devtools.build.lib.packages.BuildType.TRISTATE; -import static com.google.devtools.build.lib.syntax.Type.BOOLEAN; -import static com.google.devtools.build.lib.syntax.Type.INTEGER; -import static com.google.devtools.build.lib.syntax.Type.INTEGER_LIST; -import static com.google.devtools.build.lib.syntax.Type.STRING; -import static com.google.devtools.build.lib.syntax.Type.STRING_DICT; -import static com.google.devtools.build.lib.syntax.Type.STRING_DICT_UNARY; -import static com.google.devtools.build.lib.syntax.Type.STRING_LIST; -import static com.google.devtools.build.lib.syntax.Type.STRING_LIST_DICT; import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; @@ -47,13 +28,11 @@ import com.google.devtools.build.lib.packages.BuildType.SelectorList; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.Preconditions; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nullable; @@ -63,11 +42,6 @@ import javax.annotation.Nullable; * values an attribute might take. */ public class AggregatingAttributeMapper extends AbstractAttributeMapper { - - @SuppressWarnings("unchecked") - private static final ImmutableSet<Type<?>> scalarTypes = - ImmutableSet.of(INTEGER, STRING, LABEL, NODEP_LABEL, OUTPUT, BOOLEAN, TRISTATE, LICENSE); - private final Rule rule; private AggregatingAttributeMapper(Rule rule) { @@ -250,74 +224,6 @@ public class AggregatingAttributeMapper extends AbstractAttributeMapper { } /** - * Coerces the list {@param possibleValues} of values of type {@param attrType} to a single - * value of that type, in the following way: - * - * <p>If the list contains a single value, return that value. - * - * <p>If the list contains zero or multiple values and the type is a scalar type, return {@code - * null}. - * - * <p>If the list contains zero or multiple values and the type is a collection or map type, - * merge the collections/maps in the list and return the merged collection/map. - */ - @Nullable - @SuppressWarnings("unchecked") - public static Object flattenAttributeValues(Type<?> attrType, Iterable<Object> possibleValues) { - // If there is only one possible value, return it. - if (Iterables.size(possibleValues) == 1) { - return Iterables.getOnlyElement(possibleValues); - } - - // Otherwise, there are multiple possible values. To conform to the message shape expected by - // query output's clients, we must transform the list of possible values. This transformation - // will be lossy, but this is the best we can do. - - // If the attribute's type is not a collection type, return null. Query output's clients do - // not support list values for scalar attributes. - if (scalarTypes.contains(attrType)) { - return null; - } - - // If the attribute's type is a collection type, merge the list of collections into a single - // collection. This is a sensible solution for query output's clients, which are happy to get - // the union of possible values. - if (attrType == STRING_LIST - || attrType == LABEL_LIST - || attrType == NODEP_LABEL_LIST - || attrType == OUTPUT_LIST - || attrType == DISTRIBUTIONS - || attrType == INTEGER_LIST - || attrType == FILESET_ENTRY_LIST) { - Builder<Object> builder = ImmutableList.builder(); - for (Object possibleValue : possibleValues) { - Collection<Object> collection = (Collection<Object>) possibleValue; - for (Object o : collection) { - builder.add(o); - } - } - return builder.build(); - } - - // Same for maps as for collections. - if (attrType == STRING_DICT - || attrType == STRING_DICT_UNARY - || attrType == STRING_LIST_DICT - || attrType == LABEL_DICT_UNARY) { - Map<Object, Object> mergedDict = new HashMap<>(); - for (Object possibleValue : possibleValues) { - Map<Object, Object> stringDict = (Map<Object, Object>) possibleValue; - for (Entry<Object, Object> entry : stringDict.entrySet()) { - mergedDict.put(entry.getKey(), entry.getValue()); - } - } - return mergedDict; - } - - throw new AssertionError("Unknown type: " + attrType); - } - - /** * Returns a list of all possible values an attribute can take for this rule. * * <p>Note that when an attribute uses multiple selects, or is a {@link Attribute.ComputedDefault} |