aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar juliexxia <juliexxia@google.com>2018-02-28 14:54:14 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-28 14:55:43 -0800
commitcf568dbe0111135053b7c3b299860749a44512b0 (patch)
tree601adc63bb41ed914ae80b6523131a86e0f05b0d /src/main/java/com
parentc19869ea3c64c6b3db85eb34907688dc234a3222 (diff)
Prevent aspects with the same attributes but different names from outputting duplicates of those attributes in query's proto output format.
PiperOrigin-RevId: 187387578
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java33
1 files changed, 20 insertions, 13 deletions
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 c2fd4b0202..c052d3855d 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
@@ -57,6 +57,7 @@ import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.Type;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
@@ -64,6 +65,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.stream.Collectors;
import javax.annotation.Nullable;
/**
@@ -205,9 +207,10 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
attributeValue,
rule.isAttributeValueExplicitlySpecified(attr),
/*encodeBooleanAndTriStateAsIntegerAndString=*/ true);
- rulePb.addAttribute(serializedAttribute);
serializedAttributes.put(attr, serializedAttribute);
}
+ rulePb.addAllAttribute(
+ serializedAttributes.values().stream().distinct().collect(Collectors.toList()));
postProcess(rule, rulePb, serializedAttributes);
@@ -225,6 +228,7 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
ImmutableMultimap<Attribute, Label> aspectsDependencies =
aspectResolver.computeAspectDependencies(target, dependencyFilter);
// Add information about additional attributes from aspects.
+ List<Build.Attribute> attributes = new ArrayList<>(aspectsDependencies.asMap().size());
for (Entry<Attribute, Collection<Label>> entry : aspectsDependencies.asMap().entrySet()) {
Attribute attribute = entry.getKey();
Collection<Label> labels = entry.getValue();
@@ -238,25 +242,28 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter {
attributeValue,
/*explicitlySpecified=*/ false,
/*encodeBooleanAndTriStateAsIntegerAndString=*/ true);
- rulePb.addAttribute(serializedAttribute);
+ attributes.add(serializedAttribute);
}
+ rulePb.addAllAttribute(attributes.stream().distinct().collect(Collectors.toList()));
if (includeRuleInputsAndOutputs()) {
// Add all deps from aspects as rule inputs of current target.
- for (Label label : aspectsDependencies.values()) {
- rulePb.addRuleInput(label.toString());
- }
-
+ aspectsDependencies
+ .values()
+ .stream()
+ .distinct()
+ .forEach(dep -> rulePb.addRuleInput(dep.toString()));
// Include explicit elements for all direct inputs and outputs of a rule;
// this goes beyond what is available from the attributes above, since it
// may also (depending on options) include implicit outputs,
// host-configuration outputs, and default values.
- for (Label label : rule.getLabels(dependencyFilter)) {
- rulePb.addRuleInput(label.toString());
- }
- for (OutputFile outputFile : rule.getOutputFiles()) {
- Label fileLabel = outputFile.getLabel();
- rulePb.addRuleOutput(fileLabel.toString());
- }
+ rule.getLabels(dependencyFilter)
+ .stream()
+ .distinct()
+ .forEach(input -> rulePb.addRuleInput(input.toString()));
+ rule.getOutputFiles()
+ .stream()
+ .distinct()
+ .forEach(output -> rulePb.addRuleOutput(output.getLabel().toString()));
}
for (String feature : rule.getFeatures()) {
rulePb.addDefaultSetting(feature);