aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2/output
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/output')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java24
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java46
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java3
3 files changed, 54 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java
index a6351d4df9..c6e79e1f14 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/output/OutputFormatter.java
@@ -24,8 +24,8 @@ import com.google.devtools.build.lib.collect.CompactHashSet;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.graph.Digraph;
import com.google.devtools.build.lib.graph.Node;
+import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
import com.google.devtools.build.lib.packages.Attribute;
-import com.google.devtools.build.lib.packages.AttributeSerializer;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.query2.engine.OutputFormatterCallback;
@@ -334,12 +334,13 @@ public abstract class OutputFormatter implements Serializable {
out.printf(" name = \"%s\",%n", rule.getName());
for (Attribute attr : rule.getAttributes()) {
- Pair<Iterable<Object>, AttributeValueSource> values = getAttributeValues(rule, attr);
+ Pair<Iterable<Object>, AttributeValueSource> values =
+ getPossibleAttributeValuesAndSources(rule, attr);
if (Iterables.size(values.first) != 1) {
- continue; // TODO(bazel-team): handle configurable attributes.
+ continue; // TODO(bazel-team): handle configurable attributes.
}
if (values.second != AttributeValueSource.RULE) {
- continue; // Don't print default values.
+ continue; // Don't print default values.
}
Object value = Iterables.getOnlyElement(values.first);
out.printf(" %s = ", attr.getPublicName());
@@ -538,17 +539,18 @@ public abstract class OutputFormatter implements Serializable {
}
/**
- * Returns the possible values of the specified attribute in the specified rule. For
- * non-configured attributes, this is a single value. For configurable attributes, this
- * may be multiple values.
+ * Returns the possible values of the specified attribute in the specified rule. For simple
+ * attributes, this is a single value. For configurable and computed attributes, this may be a
+ * list of values. See {@link AggregatingAttributeMapper#getPossibleAttributeValues} for how the
+ * value(s) is/are made.
*
* @return a pair, where the first value is the set of possible values and the
* second is an enum that tells where the values come from (declared on the
* rule, declared as a package level default or a
* global default)
*/
- protected static Pair<Iterable<Object>, AttributeValueSource> getAttributeValues(
- Rule rule, Attribute attr) {
+ protected static Pair<Iterable<Object>, AttributeValueSource>
+ getPossibleAttributeValuesAndSources(Rule rule, Attribute attr) {
AttributeValueSource source;
if (attr.getName().equals("visibility")) {
@@ -564,7 +566,9 @@ public abstract class OutputFormatter implements Serializable {
? AttributeValueSource.RULE : AttributeValueSource.DEFAULT;
}
- return Pair.of(AttributeSerializer.getAttributeValues(rule, attr), source);
+ Iterable<Object> possibleAttributeValues =
+ AggregatingAttributeMapper.of(rule).getPossibleAttributeValues(rule, attr);
+ return Pair.of(possibleAttributeValues, source);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
index 0fc1ffc582..e1f8ea78a5 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java
@@ -19,13 +19,15 @@ import static com.google.devtools.build.lib.query2.proto.proto2api.Build.Target.
import static com.google.devtools.build.lib.query2.proto.proto2api.Build.Target.Discriminator.RULE;
import static com.google.devtools.build.lib.query2.proto.proto2api.Build.Target.Discriminator.SOURCE_FILE;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.graph.Digraph;
+import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
import com.google.devtools.build.lib.packages.Attribute;
import com.google.devtools.build.lib.packages.AttributeSerializer;
+import com.google.devtools.build.lib.packages.BuildType;
import com.google.devtools.build.lib.packages.EnvironmentGroup;
import com.google.devtools.build.lib.packages.InputFile;
import com.google.devtools.build.lib.packages.OutputFile;
@@ -140,12 +142,19 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
|| !includeAttribute(attr)) {
continue;
}
- rulePb.addAttribute(
+ Iterable<Object> possibleAttributeValues =
+ AggregatingAttributeMapper.of(rule).getPossibleAttributeValues(rule, attr);
+ Object flattenedAttributeValue =
+ AggregatingAttributeMapper.flattenAttributeValues(
+ attr.getType(), possibleAttributeValues);
+ Build.Attribute serializedAttribute =
AttributeSerializer.getAttributeProto(
attr,
- AttributeSerializer.getAttributeValues(rule, attr),
+ flattenedAttributeValue,
rule.isAttributeValueExplicitlySpecified(attr),
- /*includeGlobs=*/ false));
+ /*includeGlobs=*/ false,
+ /*encodeBooleanAndTriStateAsIntegerAndString=*/ true);
+ rulePb.addAttribute(serializedAttribute);
}
postProcess(rule, rulePb);
@@ -166,12 +175,17 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
aspectResolver.computeAspectDependencies(target);
// Add information about additional attributes from aspects.
for (Entry<Attribute, Collection<Label>> entry : aspectsDependencies.asMap().entrySet()) {
- rulePb.addAttribute(
+ Attribute attribute = entry.getKey();
+ Collection<Label> labels = entry.getValue();
+ Object attributeValue = getAspectAttributeValue(attribute, labels);
+ Build.Attribute serializedAttribute =
AttributeSerializer.getAttributeProto(
- entry.getKey(),
- Lists.<Object>newArrayList(entry.getValue()),
+ attribute,
+ attributeValue,
/*explicitlySpecified=*/ false,
- /*includeGlobs=*/ false));
+ /*includeGlobs=*/ false,
+ /*encodeBooleanAndTriStateAsIntegerAndString=*/ true);
+ rulePb.addAttribute(serializedAttribute);
}
// Add all deps from aspects as rule inputs of current target.
for (Label label : aspectsDependencies.values()) {
@@ -291,6 +305,22 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
return targetPb.build();
}
+ private static Object getAspectAttributeValue(Attribute attribute, Collection<Label> labels) {
+ com.google.devtools.build.lib.syntax.Type<?> attributeType = attribute.getType();
+ if (attributeType.equals(BuildType.LABEL)) {
+ Preconditions.checkState(labels.size() == 1, "attribute=%s, labels=%s", attribute, labels);
+ return Iterables.getOnlyElement(labels);
+ } else {
+ Preconditions.checkState(
+ attributeType.equals(BuildType.LABEL_LIST),
+ "attribute=%s, type=%s, labels=%s",
+ attribute,
+ attributeType,
+ labels);
+ return labels;
+ }
+ }
+
/** Further customize the proto output */
protected void postProcess(Rule rule, Build.Rule.Builder rulePb) { }
diff --git a/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java b/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java
index 2af71b7414..14fdfa604d 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/output/XmlOutputFormatter.java
@@ -137,7 +137,8 @@ class XmlOutputFormatter extends AbstractUnorderedFormatter {
elem = doc.createElement("rule");
elem.setAttribute("class", rule.getRuleClass());
for (Attribute attr : rule.getAttributes()) {
- Pair<Iterable<Object>, AttributeValueSource> values = getAttributeValues(rule, attr);
+ Pair<Iterable<Object>, AttributeValueSource> values =
+ getPossibleAttributeValuesAndSources(rule, attr);
if (values.second == AttributeValueSource.RULE || options.xmlShowDefaultValues) {
Element attrElem = createValueElement(doc, attr.getType(), values.first);
attrElem.setAttribute("name", attr.getName());