Use Label (string) instead of Label (struct) to dedupe
Using Label struct as the map key causes issues because it contains
OriginalModuleName. The same module will have a different value for this
property when called from inside a soong namespace vs from outside.
If there are dups, we can just choose the first one. OriginalModuleName
is often used with ModuleFromName, and that function panics if there are
modules with the same name in two separate soong namespaces
Test: go test ./bp2build ./bazel
Change-Id: I2ee33efab03016a72f1eea99cb958b6198baeca2
diff --git a/bazel/properties.go b/bazel/properties.go
index 702c31c..bb0eafc 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -194,14 +194,7 @@
// UniqueSortedBazelLabels takes a []Label and deduplicates the labels, and returns
// the slice in a sorted order.
func UniqueSortedBazelLabels(originalLabels []Label) []Label {
- uniqueLabelsSet := make(map[Label]bool)
- for _, l := range originalLabels {
- uniqueLabelsSet[l] = true
- }
- var uniqueLabels []Label
- for l, _ := range uniqueLabelsSet {
- uniqueLabels = append(uniqueLabels, l)
- }
+ uniqueLabels := FirstUniqueBazelLabels(originalLabels)
sort.SliceStable(uniqueLabels, func(i, j int) bool {
return uniqueLabels[i].Label < uniqueLabels[j].Label
})
@@ -210,13 +203,13 @@
func FirstUniqueBazelLabels(originalLabels []Label) []Label {
var labels []Label
- found := make(map[Label]bool, len(originalLabels))
+ found := make(map[string]bool, len(originalLabels))
for _, l := range originalLabels {
- if _, ok := found[l]; ok {
+ if _, ok := found[l.Label]; ok {
continue
}
labels = append(labels, l)
- found[l] = true
+ found[l.Label] = true
}
return labels
}