From 09cb6329a5723b0e4627d108b86340d9169537be Mon Sep 17 00:00:00 2001 From: Arunkumar Date: Mon, 15 Feb 2021 14:43:22 +0800 Subject: [PATCH] Remove databinding classInfos and setterStores duplicates from provider --- .../databinding/DataBindingV2Provider.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/databinding/DataBindingV2Provider.java b/src/main/java/com/google/devtools/build/lib/rules/android/databinding/DataBindingV2Provider.java index ebd06d03cb6223..3b52d8657c8061 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/databinding/DataBindingV2Provider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/databinding/DataBindingV2Provider.java @@ -26,6 +26,10 @@ import net.starlark.java.eval.EvalException; import net.starlark.java.eval.Sequence; +import java.util.Comparator; +import java.util.TreeSet; +import java.util.stream.Collectors; + /** * A provider that exposes this enables data binding @@ -53,8 +57,8 @@ public DataBindingV2Provider( NestedSet transitiveBRFiles, ImmutableList labelAndJavaPackages, NestedSet transitiveLabelAndJavaPackages) { - this.classInfos = classInfos; - this.setterStores = setterStores; + this.classInfos = removeDuplicates(classInfos); + this.setterStores = removeDuplicates(setterStores); this.transitiveBRFiles = transitiveBRFiles; this.labelAndJavaPackages = labelAndJavaPackages; this.transitiveLabelAndJavaPackages = transitiveLabelAndJavaPackages; @@ -164,6 +168,17 @@ public static DataBindingV2Provider createProvider( transitiveLabelAndJavaPackages.build()); } + /** + * Remove all duplicates from given artifact list. Needed until https://github.com/bazelbuild/bazel/issues/12780 is + * fixed + */ + private ImmutableList removeDuplicates(ImmutableList source) { + return source.stream() + .collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Artifact::getExecPath)))) + .stream() + .collect(ImmutableList.toImmutableList()); + } + /** The provider can construct the DataBindingV2Provider provider. */ public static class Provider extends BuiltinProvider implements DataBindingV2ProviderApi.Provider {