Only include test data in flattened apex 1 time

Previously, if a data source was included in multiple APEX, it would
appear multiple times; however, this caused errors for overriding
commands for targets

Test: apex_test.go
Test: m nothing with change I54d92eca88fc04c949209d490e838d0a92ce8f87
Bug: 155820504
Change-Id: I98f04e0fd9fa3238f2bb0e5da3a86fc0797c38ba
This commit is contained in:
Liz Kammer 2020-05-27 15:15:11 -07:00
parent 43527e1f31
commit 5bd365f1e5
2 changed files with 37 additions and 5 deletions

View File

@ -78,6 +78,8 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
} }
} }
seenDataOutPaths := make(map[string]bool)
for _, fi := range a.filesInfo { for _, fi := range a.filesInfo {
if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake { if cc, ok := fi.module.(*cc.Module); ok && cc.Properties.HideFromMake {
continue continue
@ -112,16 +114,24 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexBundleName, apexName, mo
pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir) pathWhenActivated := filepath.Join("$(PRODUCT_OUT)", "apex", apexName, fi.installDir)
if apexType == flattenedApex { if apexType == flattenedApex {
// /system/apex/<name>/{lib|framework|...} // /system/apex/<name>/{lib|framework|...}
fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", filepath.Join(a.installDir.ToMakePath().String(), modulePath := filepath.Join(a.installDir.ToMakePath().String(), apexBundleName, fi.installDir)
apexBundleName, fi.installDir)) fmt.Fprintln(w, "LOCAL_MODULE_PATH :=", modulePath)
if a.primaryApexType && !symbolFilesNotNeeded { if a.primaryApexType && !symbolFilesNotNeeded {
fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated) fmt.Fprintln(w, "LOCAL_SOONG_SYMBOL_PATH :=", pathWhenActivated)
} }
if len(fi.symlinks) > 0 { if len(fi.symlinks) > 0 {
fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " ")) fmt.Fprintln(w, "LOCAL_MODULE_SYMLINKS :=", strings.Join(fi.symlinks, " "))
} }
if len(fi.dataPaths) > 0 { newDataPaths := []android.Path{}
fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(cc.AndroidMkDataPaths(fi.dataPaths), " ")) for _, path := range fi.dataPaths {
dataOutPath := modulePath + ":" + path.Rel()
if ok := seenDataOutPaths[dataOutPath]; !ok {
newDataPaths = append(newDataPaths, path)
seenDataOutPaths[dataOutPath] = true
}
}
if len(newDataPaths) > 0 {
fmt.Fprintln(w, "LOCAL_TEST_DATA :=", strings.Join(cc.AndroidMkDataPaths(newDataPaths), " "))
} }
if fi.module != nil && len(fi.module.NoticeFiles()) > 0 { if fi.module != nil && len(fi.module.NoticeFiles()) > 0 {

View File

@ -184,6 +184,7 @@ func testApexContext(t *testing.T, bp string, handlers ...testCustomizer) (*andr
"dummy.txt": nil, "dummy.txt": nil,
"baz": nil, "baz": nil,
"bar/baz": nil, "bar/baz": nil,
"testdata/baz": nil,
} }
cc.GatherRequiredFilesForTest(fs) cc.GatherRequiredFilesForTest(fs)
@ -274,6 +275,15 @@ func ensureContains(t *testing.T, result string, expected string) {
} }
} }
// ensure that 'result' contains 'expected' exactly one time
func ensureContainsOnce(t *testing.T, result string, expected string) {
t.Helper()
count := strings.Count(result, expected)
if count != 1 {
t.Errorf("%q is found %d times (expected 1 time) in %q", expected, count, result)
}
}
// ensures that 'result' does not contain 'notExpected' // ensures that 'result' does not contain 'notExpected'
func ensureNotContains(t *testing.T, result string, notExpected string) { func ensureNotContains(t *testing.T, result string, notExpected string) {
t.Helper() t.Helper()
@ -3423,6 +3433,13 @@ func TestApexWithTests(t *testing.T) {
stl: "none", stl: "none",
} }
filegroup {
name: "fg2",
srcs: [
"testdata/baz"
],
}
cc_test { cc_test {
name: "mytests", name: "mytests",
gtest: false, gtest: false,
@ -3436,6 +3453,10 @@ func TestApexWithTests(t *testing.T) {
system_shared_libs: [], system_shared_libs: [],
static_executable: true, static_executable: true,
stl: "none", stl: "none",
data: [
":fg",
":fg2",
],
} }
`) `)
@ -3475,7 +3496,8 @@ func TestApexWithTests(t *testing.T) {
data = android.AndroidMkDataForTest(t, config, "", flatBundle) data = android.AndroidMkDataForTest(t, config, "", flatBundle)
data.Custom(&builder, name, prefix, "", data) data.Custom(&builder, name, prefix, "", data)
flatAndroidMk := builder.String() flatAndroidMk := builder.String()
ensureContains(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n") ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :baz :bar/baz\n")
ensureContainsOnce(t, flatAndroidMk, "LOCAL_TEST_DATA := :testdata/baz\n")
} }
func TestInstallExtraFlattenedApexes(t *testing.T) { func TestInstallExtraFlattenedApexes(t *testing.T) {