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
This commit is contained in:
Jooyung Han
2019-02-28 18:06:34 +09:00
parent 7aa5a56bbc
commit a61ff2cec3

View File

@@ -120,6 +120,10 @@ func testPerSrcMutator(mctx android.BottomUpMutatorContext) {
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 testPerSrcMutator(mctx android.BottomUpMutatorContext) {
}
}
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