Handle duplicate keys when merging BuildOutputs
Prefers nextOutputs on duplicates, which is defined as the more recent output.
package com.google.idea.blaze.base.sync.aspects;
import static com.google.common.collect.ImmutableList.toImmutableList;
+import static com.google.common.collect.ImmutableMap.toImmutableMap;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
@@ -29,6 +30,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
+import java.util.stream.Stream;
/** The result of a (potentially sharded) blaze build. */
public class BlazeBuildOutputs {
@@ -126,10 +128,12 @@ public class BlazeBuildOutputs {
return new BlazeBuildOutputs(
BuildResult.combine(buildResult, nextOutputs.buildResult),
combined,
- ImmutableMap.<String, BuildResult>builder()
- .putAll(buildShardResults)
- .putAll(nextOutputs.buildShardResults)
- .build(),
+ Stream.concat(
+ nextOutputs.buildShardResults.entrySet().stream(),
+ buildShardResults.entrySet().stream())
+ .collect(
+ // On duplicate buildIds, preserve most recent result
+ toImmutableMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1)),
bepBytesConsumed + nextOutputs.bepBytesConsumed);
}
