aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cc/cc.go20
-rw-r--r--cc/cc_test.go50
2 files changed, 70 insertions, 0 deletions
diff --git a/cc/cc.go b/cc/cc.go
index cff8d857..8069a900 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1054,6 +1054,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
})
+ // Dedup exported flags from dependencies
+ depPaths.Flags = firstUniqueElements(depPaths.Flags)
+
return depPaths
}
@@ -1175,6 +1178,23 @@ func vendorMutator(mctx android.BottomUpMutatorContext) {
}
}
+// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
+// modifies the slice contents in place, and returns a subslice of the original slice
+func firstUniqueElements(list []string) []string {
+ k := 0
+outer:
+ for i := 0; i < len(list); i++ {
+ for j := 0; j < k; j++ {
+ if list[i] == list[j] {
+ continue outer
+ }
+ }
+ list[k] = list[i]
+ k++
+ }
+ return list[:k]
+}
+
// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
// modifies the slice contents in place, and returns a subslice of the original slice
func lastUniqueElements(list []string) []string {
diff --git a/cc/cc_test.go b/cc/cc_test.go
index 6e779e75..92120a54 100644
--- a/cc/cc_test.go
+++ b/cc/cc_test.go
@@ -6,6 +6,56 @@ import (
"testing"
)
+var firstUniqueElementsTestCases = []struct {
+ in []string
+ out []string
+}{
+ {
+ in: []string{"a"},
+ out: []string{"a"},
+ },
+ {
+ in: []string{"a", "b"},
+ out: []string{"a", "b"},
+ },
+ {
+ in: []string{"a", "a"},
+ out: []string{"a"},
+ },
+ {
+ in: []string{"a", "b", "a"},
+ out: []string{"a", "b"},
+ },
+ {
+ in: []string{"b", "a", "a"},
+ out: []string{"b", "a"},
+ },
+ {
+ in: []string{"a", "a", "b"},
+ out: []string{"a", "b"},
+ },
+ {
+ in: []string{"a", "b", "a", "b"},
+ out: []string{"a", "b"},
+ },
+ {
+ in: []string{"liblog", "libdl", "libc++", "libdl", "libc", "libm"},
+ out: []string{"liblog", "libdl", "libc++", "libc", "libm"},
+ },
+}
+
+func TestFirstUniqueElements(t *testing.T) {
+ for _, testCase := range firstUniqueElementsTestCases {
+ out := firstUniqueElements(testCase.in)
+ if !reflect.DeepEqual(out, testCase.out) {
+ t.Errorf("incorrect output:")
+ t.Errorf(" input: %#v", testCase.in)
+ t.Errorf(" expected: %#v", testCase.out)
+ t.Errorf(" got: %#v", out)
+ }
+ }
+}
+
var lastUniqueElementsTestCases = []struct {
in []string
out []string