cc_test: emit errors if there's duplicate in srcs
In general "srcs" property allows duplication in the list.
But when cc_test's "test_per_src" property is set "true",
there will be variants according to "srcs" list.
Therefore, it should fail if there is a duplicate entry
in srcs list.
Bug: 113629474
Test: mma
Change-Id: I543624459c30dd296494a3a80e28ce5503a3ea2f
diff --git a/cc/test.go b/cc/test.go
index 8e49fac..3ecc419 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -120,6 +120,10 @@
if m, ok := mctx.Module().(*Module); ok {
if test, ok := m.linker.(testPerSrc); ok {
if test.testPerSrc() && len(test.srcs()) > 0 {
+ if duplicate, found := checkDuplicate(test.srcs()); found {
+ mctx.PropertyErrorf("srcs", "found a duplicate entry %q", duplicate)
+ return
+ }
testNames := make([]string, len(test.srcs()))
for i, src := range test.srcs() {
testNames[i] = strings.TrimSuffix(filepath.Base(src), filepath.Ext(src))
@@ -133,6 +137,17 @@
}
}
+func checkDuplicate(values []string) (duplicate string, found bool) {
+ seen := make(map[string]string)
+ for _, v := range values {
+ if duplicate, found = seen[v]; found {
+ return
+ }
+ seen[v] = v
+ }
+ return
+}
+
type testDecorator struct {
Properties TestProperties
linker *baseLinker