diff options
author | Googler <noreply@google.com> | 2018-08-07 10:56:10 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-08-07 10:58:10 -0700 |
commit | 66133e7cfb17de11264b144ce04a64bb6fb57a39 (patch) | |
tree | a09d90067ed2c8eb18e36af73e2bcf56363120ab /src/main | |
parent | c1705f0cf03255404e8967b962d60f6053900c5f (diff) |
Sort the rule attribute list in ProtoOutputFormatter by name to cure some query
and genquery non-determinism.
This approach relies on there never being two attributes with the same name.
I added the inOrder() to the test without my change commented and observed flaky failures. I then uncommented my change and saw consistent passes.
RELNOTES: Sort attribute lists in proto-form query output to fix non-deterministic genquery output.
PiperOrigin-RevId: 207743773
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/query2/output/ProtoOutputFormatter.java | 15 |
1 files changed, 12 insertions, 3 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 43addea672..4eb877b29f 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 @@ -58,6 +58,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -71,12 +72,14 @@ import javax.annotation.Nullable; * {@code Build.QueryResult} object the full result can be reconstructed. */ public class ProtoOutputFormatter extends AbstractUnorderedFormatter { - /** * A special attribute name for the rule implementation hash code. */ public static final String RULE_IMPLEMENTATION_HASH_ATTR_NAME = "$rule_implementation_hash"; + private static final Comparator<Build.Attribute> ATTRIBUTE_NAME = + Comparator.comparing(Build.Attribute::getName); + @SuppressWarnings("unchecked") private static final ImmutableSet<Type<?>> SCALAR_TYPES = ImmutableSet.<Type<?>>of( @@ -214,7 +217,8 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter { /*encodeBooleanAndTriStateAsIntegerAndString=*/ true); attributes.add(serializedAttribute); } - rulePb.addAllAttribute(attributes.stream().distinct().collect(Collectors.toList())); + rulePb.addAllAttribute( + attributes.stream().distinct().sorted(ATTRIBUTE_NAME).collect(Collectors.toList())); if (includeRuleInputsAndOutputs()) { // Add all deps from aspects as rule inputs of current target. aspectsDependencies @@ -360,7 +364,12 @@ public class ProtoOutputFormatter extends AbstractUnorderedFormatter { serializedAttributes.put(attr, serializedAttribute); } rulePb.addAllAttribute( - serializedAttributes.values().stream().distinct().collect(Collectors.toList())); + serializedAttributes + .values() + .stream() + .distinct() + .sorted(ATTRIBUTE_NAME) + .collect(Collectors.toList())); postProcess(rule, rulePb, serializedAttributes); } |