Remove uses of buildDir from java/app_test.go

Remove any uses, either direct (or indirect via testJavaConfig or
similar methods), of the package level buildDir variable from this
file.

Bug: 182885307
Test: m nothing
Change-Id: Ia8f835a8250934ef328cad02b272e6b94b13c459
This commit is contained in:
Paul Duffin
2021-03-22 17:31:52 +00:00
parent f71e4ed326
commit fb0fe9f5cb

View File

@@ -26,6 +26,7 @@ import (
"android/soong/android" "android/soong/android"
"android/soong/cc" "android/soong/cc"
"android/soong/genrule"
) )
// testAppConfig is a legacy way of creating a test Config for testing java app modules. // testAppConfig is a legacy way of creating a test Config for testing java app modules.
@@ -118,9 +119,9 @@ func TestAppSplits(t *testing.T) {
foo := ctx.ModuleForTests("foo", "android_common") foo := ctx.ModuleForTests("foo", "android_common")
expectedOutputs := []string{ expectedOutputs := []string{
filepath.Join(buildDir, ".intermediates/foo/android_common/foo.apk"), "out/soong/.intermediates/foo/android_common/foo.apk",
filepath.Join(buildDir, ".intermediates/foo/android_common/foo_v4.apk"), "out/soong/.intermediates/foo/android_common/foo_v4.apk",
filepath.Join(buildDir, ".intermediates/foo/android_common/foo_v7_hdpi.apk"), "out/soong/.intermediates/foo/android_common/foo_v7_hdpi.apk",
} }
for _, expectedOutput := range expectedOutputs { for _, expectedOutput := range expectedOutputs {
foo.Output(expectedOutput) foo.Output(expectedOutput)
@@ -130,9 +131,7 @@ func TestAppSplits(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if g, w := outputFiles.Strings(), expectedOutputs; !reflect.DeepEqual(g, w) { android.AssertPathsRelativeToTopEquals(t, `OutputFiles("")`, expectedOutputs, outputFiles)
t.Errorf(`want OutputFiles("") = %q, got %q`, w, g)
}
} }
func TestPlatformAPIs(t *testing.T) { func TestPlatformAPIs(t *testing.T) {
@@ -446,7 +445,7 @@ func TestUpdatableApps_JniLibShouldBeBuiltAgainstMinSdkVersion(t *testing.T) {
"prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtend_so.o": nil, "prebuilts/ndk/current/platforms/android-29/arch-arm/usr/lib/crtend_so.o": nil,
} }
ctx, _ := testJavaWithConfig(t, testConfig(nil, bp, fs)) ctx, _ := testJavaWithFS(t, bp, fs)
inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits inputs := ctx.ModuleForTests("libjni", "android_arm64_armv8-a_sdk_shared").Description("link").Implicits
var crtbeginFound, crtendFound bool var crtbeginFound, crtendFound bool
@@ -547,7 +546,7 @@ func TestResourceDirs(t *testing.T) {
}, },
} }
fs := map[string][]byte{ fs := android.MockFS{
"res/res/values/strings.xml": nil, "res/res/values/strings.xml": nil,
} }
@@ -561,11 +560,13 @@ func TestResourceDirs(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) { t.Run(testCase.name, func(t *testing.T) {
config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs) result := android.GroupFixturePreparers(
ctx := testContext(config) PrepareForTestWithJavaDefaultModules,
run(t, ctx, config) PrepareForTestWithOverlayBuildComponents,
fs.AddToFixture(),
).RunTestWithBp(t, fmt.Sprintf(bp, testCase.prop))
module := ctx.ModuleForTests("foo", "android_common") module := result.ModuleForTests("foo", "android_common")
resourceList := module.MaybeOutput("aapt2/res.list") resourceList := module.MaybeOutput("aapt2/res.list")
var resources []string var resources []string
@@ -575,10 +576,7 @@ func TestResourceDirs(t *testing.T) {
} }
} }
if !reflect.DeepEqual(resources, testCase.resources) { android.AssertDeepEquals(t, "resource files", testCase.resources, resources)
t.Errorf("expected resource files %q, got %q",
testCase.resources, resources)
}
}) })
} }
} }
@@ -624,9 +622,9 @@ func TestLibraryAssets(t *testing.T) {
name: "foo", name: "foo",
// lib1 has its own asset. lib3 doesn't have any, but provides lib4's transitively. // lib1 has its own asset. lib3 doesn't have any, but provides lib4's transitively.
assetPackages: []string{ assetPackages: []string{
buildDir + "/.intermediates/foo/android_common/aapt2/package-res.apk", "out/soong/.intermediates/foo/android_common/aapt2/package-res.apk",
buildDir + "/.intermediates/lib1/android_common/assets.zip", "out/soong/.intermediates/lib1/android_common/assets.zip",
buildDir + "/.intermediates/lib3/android_common/assets.zip", "out/soong/.intermediates/lib3/android_common/assets.zip",
}, },
}, },
{ {
@@ -639,8 +637,8 @@ func TestLibraryAssets(t *testing.T) {
{ {
name: "lib3", name: "lib3",
assetPackages: []string{ assetPackages: []string{
buildDir + "/.intermediates/lib3/android_common/aapt2/package-res.apk", "out/soong/.intermediates/lib3/android_common/aapt2/package-res.apk",
buildDir + "/.intermediates/lib4/android_common/assets.zip", "out/soong/.intermediates/lib4/android_common/assets.zip",
}, },
}, },
{ {
@@ -661,24 +659,18 @@ func TestLibraryAssets(t *testing.T) {
} else { } else {
aapt2link = m.Output("package-res.apk") aapt2link = m.Output("package-res.apk")
} }
aapt2link = aapt2link.RelativeToTop()
aapt2Flags := aapt2link.Args["flags"] aapt2Flags := aapt2link.Args["flags"]
if test.assetFlag != "" { if test.assetFlag != "" {
if !strings.Contains(aapt2Flags, test.assetFlag) { android.AssertStringDoesContain(t, "asset flag", aapt2Flags, test.assetFlag)
t.Errorf("Can't find asset flag %q in aapt2 link flags %q", test.assetFlag, aapt2Flags)
}
} else { } else {
if strings.Contains(aapt2Flags, " -A ") { android.AssertStringDoesNotContain(t, "aapt2 link flags", aapt2Flags, " -A ")
t.Errorf("aapt2 link flags %q contain unexpected asset flag", aapt2Flags)
}
} }
// Check asset merge rule. // Check asset merge rule.
if len(test.assetPackages) > 0 { if len(test.assetPackages) > 0 {
mergeAssets := m.Output("package-res.apk") mergeAssets := m.Output("package-res.apk")
if !reflect.DeepEqual(test.assetPackages, mergeAssets.Inputs.Strings()) { android.AssertPathsRelativeToTopEquals(t, "mergeAssets inputs", test.assetPackages, mergeAssets.Inputs)
t.Errorf("Unexpected mergeAssets inputs: %v, expected: %v",
mergeAssets.Inputs.Strings(), test.assetPackages)
}
} }
}) })
} }
@@ -750,9 +742,9 @@ func TestAndroidResources(t *testing.T) {
}, },
overlayFiles: map[string][]string{ overlayFiles: map[string][]string{
"foo": { "foo": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk", "out/soong/.intermediates/lib2/android_common/package-res.apk",
buildDir + "/.intermediates/lib/android_common/package-res.apk", "out/soong/.intermediates/lib/android_common/package-res.apk",
buildDir + "/.intermediates/lib3/android_common/package-res.apk", "out/soong/.intermediates/lib3/android_common/package-res.apk",
"foo/res/res/values/strings.xml", "foo/res/res/values/strings.xml",
"device/vendor/blah/static_overlay/foo/res/values/strings.xml", "device/vendor/blah/static_overlay/foo/res/values/strings.xml",
"device/vendor/blah/overlay/foo/res/values/strings.xml", "device/vendor/blah/overlay/foo/res/values/strings.xml",
@@ -763,7 +755,7 @@ func TestAndroidResources(t *testing.T) {
"device/vendor/blah/overlay/bar/res/values/strings.xml", "device/vendor/blah/overlay/bar/res/values/strings.xml",
}, },
"lib": { "lib": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk", "out/soong/.intermediates/lib2/android_common/package-res.apk",
"lib/res/res/values/strings.xml", "lib/res/res/values/strings.xml",
"device/vendor/blah/overlay/lib/res/values/strings.xml", "device/vendor/blah/overlay/lib/res/values/strings.xml",
}, },
@@ -785,9 +777,9 @@ func TestAndroidResources(t *testing.T) {
}, },
overlayFiles: map[string][]string{ overlayFiles: map[string][]string{
"foo": { "foo": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk", "out/soong/.intermediates/lib2/android_common/package-res.apk",
buildDir + "/.intermediates/lib/android_common/package-res.apk", "out/soong/.intermediates/lib/android_common/package-res.apk",
buildDir + "/.intermediates/lib3/android_common/package-res.apk", "out/soong/.intermediates/lib3/android_common/package-res.apk",
"foo/res/res/values/strings.xml", "foo/res/res/values/strings.xml",
"device/vendor/blah/static_overlay/foo/res/values/strings.xml", "device/vendor/blah/static_overlay/foo/res/values/strings.xml",
}, },
@@ -796,7 +788,7 @@ func TestAndroidResources(t *testing.T) {
"device/vendor/blah/overlay/bar/res/values/strings.xml", "device/vendor/blah/overlay/bar/res/values/strings.xml",
}, },
"lib": { "lib": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk", "out/soong/.intermediates/lib2/android_common/package-res.apk",
"lib/res/res/values/strings.xml", "lib/res/res/values/strings.xml",
}, },
}, },
@@ -827,15 +819,15 @@ func TestAndroidResources(t *testing.T) {
}, },
overlayFiles: map[string][]string{ overlayFiles: map[string][]string{
"foo": { "foo": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk", "out/soong/.intermediates/lib2/android_common/package-res.apk",
buildDir + "/.intermediates/lib/android_common/package-res.apk", "out/soong/.intermediates/lib/android_common/package-res.apk",
buildDir + "/.intermediates/lib3/android_common/package-res.apk", "out/soong/.intermediates/lib3/android_common/package-res.apk",
"foo/res/res/values/strings.xml", "foo/res/res/values/strings.xml",
"device/vendor/blah/static_overlay/foo/res/values/strings.xml", "device/vendor/blah/static_overlay/foo/res/values/strings.xml",
}, },
"bar": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"}, "bar": {"device/vendor/blah/static_overlay/bar/res/values/strings.xml"},
"lib": { "lib": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk", "out/soong/.intermediates/lib2/android_common/package-res.apk",
"lib/res/res/values/strings.xml", "lib/res/res/values/strings.xml",
}, },
}, },
@@ -862,7 +854,7 @@ func TestAndroidResources(t *testing.T) {
"product/vendor/blah/overlay", "product/vendor/blah/overlay",
} }
fs := map[string][]byte{ fs := android.MockFS{
"foo/res/res/values/strings.xml": nil, "foo/res/res/values/strings.xml": nil,
"bar/res/res/values/strings.xml": nil, "bar/res/res/values/strings.xml": nil,
"lib/res/res/values/strings.xml": nil, "lib/res/res/values/strings.xml": nil,
@@ -913,18 +905,21 @@ func TestAndroidResources(t *testing.T) {
for _, testCase := range testCases { for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) { t.Run(testCase.name, func(t *testing.T) {
config := testAppConfig(nil, bp, fs) result := android.GroupFixturePreparers(
config.TestProductVariables.DeviceResourceOverlays = deviceResourceOverlays PrepareForTestWithJavaDefaultModules,
config.TestProductVariables.ProductResourceOverlays = productResourceOverlays PrepareForTestWithOverlayBuildComponents,
fs.AddToFixture(),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.DeviceResourceOverlays = deviceResourceOverlays
variables.ProductResourceOverlays = productResourceOverlays
if testCase.enforceRROTargets != nil { if testCase.enforceRROTargets != nil {
config.TestProductVariables.EnforceRROTargets = testCase.enforceRROTargets variables.EnforceRROTargets = testCase.enforceRROTargets
} }
if testCase.enforceRROExcludedOverlays != nil { if testCase.enforceRROExcludedOverlays != nil {
config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays variables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
} }
}),
ctx := testContext(config) ).RunTestWithBp(t, bp)
run(t, ctx, config)
resourceListToFiles := func(module android.TestingModule, list []string) (files []string) { resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
for _, o := range list { for _, o := range list {
@@ -942,14 +937,14 @@ func TestAndroidResources(t *testing.T) {
} }
getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) { getResources := func(moduleName string) (resourceFiles, overlayFiles, rroDirs []string) {
module := ctx.ModuleForTests(moduleName, "android_common") module := result.ModuleForTests(moduleName, "android_common")
resourceList := module.MaybeOutput("aapt2/res.list") resourceList := module.MaybeOutput("aapt2/res.list")
if resourceList.Rule != nil { if resourceList.Rule != nil {
resourceFiles = resourceListToFiles(module, resourceList.Inputs.Strings()) resourceFiles = resourceListToFiles(module, android.PathsRelativeToTop(resourceList.Inputs))
} }
overlayList := module.MaybeOutput("aapt2/overlay.list") overlayList := module.MaybeOutput("aapt2/overlay.list")
if overlayList.Rule != nil { if overlayList.Rule != nil {
overlayFiles = resourceListToFiles(module, overlayList.Inputs.Strings()) overlayFiles = resourceListToFiles(module, android.PathsRelativeToTop(overlayList.Inputs))
} }
for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() { for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() {
@@ -961,7 +956,7 @@ func TestAndroidResources(t *testing.T) {
} else { } else {
t.Fatalf("Unexpected overlayType %d", d.overlayType) t.Fatalf("Unexpected overlayType %d", d.overlayType)
} }
rroDirs = append(rroDirs, prefix+d.path.String()) rroDirs = append(rroDirs, prefix+android.PathRelativeToTop(d.path))
} }
return resourceFiles, overlayFiles, rroDirs return resourceFiles, overlayFiles, rroDirs
@@ -1269,13 +1264,19 @@ func TestAppSdkVersionByPartition(t *testing.T) {
} }
` `
config := testAppConfig(nil, bp, nil) errorHandler := android.FixtureExpectsNoErrors
config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
if enforce { if enforce {
testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config) errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern("sdk_version must have a value when the module is located at vendor or product")
} else {
testJavaWithConfig(t, config)
} }
android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
}),
).
ExtendWithErrorHandler(errorHandler).
RunTestWithBp(t, bp)
} }
} }
@@ -1609,25 +1610,23 @@ func TestCertificates(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
config := testAppConfig(nil, test.bp, nil) result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
if test.certificateOverride != "" { if test.certificateOverride != "" {
config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride} variables.CertificateOverrides = []string{test.certificateOverride}
} }
ctx := testContext(config) }),
).RunTestWithBp(t, test.bp)
run(t, ctx, config) foo := result.ModuleForTests("foo", "android_common")
foo := ctx.ModuleForTests("foo", "android_common")
signapk := foo.Output("foo.apk") signapk := foo.Output("foo.apk")
signCertificateFlags := signapk.Args["certificates"] signCertificateFlags := signapk.Args["certificates"]
if test.expectedCertificate != signCertificateFlags { android.AssertStringEquals(t, "certificates flags", test.expectedCertificate, signCertificateFlags)
t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expectedCertificate, signCertificateFlags)
}
signFlags := signapk.Args["flags"] signFlags := signapk.Args["flags"]
if test.expectedLineage != signFlags { android.AssertStringEquals(t, "signing flags", test.expectedLineage, signFlags)
t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expectedLineage, signFlags)
}
}) })
} }
} }
@@ -1677,17 +1676,15 @@ func TestRequestV4SigningFlag(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
config := testAppConfig(nil, test.bp, nil) result := android.GroupFixturePreparers(
ctx := testContext(config) PrepareForTestWithJavaDefaultModules,
).RunTestWithBp(t, test.bp)
run(t, ctx, config) foo := result.ModuleForTests("foo", "android_common")
foo := ctx.ModuleForTests("foo", "android_common")
signapk := foo.Output("foo.apk") signapk := foo.Output("foo.apk")
signFlags := signapk.Args["flags"] signFlags := signapk.Args["flags"]
if test.expected != signFlags { android.AssertStringEquals(t, "signing flags", test.expected, signFlags)
t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expected, signFlags)
}
}) })
} }
} }
@@ -1710,8 +1707,8 @@ func TestPackageNameOverride(t *testing.T) {
`, `,
packageNameOverride: "", packageNameOverride: "",
expected: []string{ expected: []string{
buildDir + "/.intermediates/foo/android_common/foo.apk", "out/soong/.intermediates/foo/android_common/foo.apk",
buildDir + "/target/product/test_device/system/app/foo/foo.apk", "out/soong/target/product/test_device/system/app/foo/foo.apk",
}, },
}, },
{ {
@@ -1726,27 +1723,31 @@ func TestPackageNameOverride(t *testing.T) {
packageNameOverride: "foo:bar", packageNameOverride: "foo:bar",
expected: []string{ expected: []string{
// The package apk should be still be the original name for test dependencies. // The package apk should be still be the original name for test dependencies.
buildDir + "/.intermediates/foo/android_common/bar.apk", "out/soong/.intermediates/foo/android_common/bar.apk",
buildDir + "/target/product/test_device/system/app/bar/bar.apk", "out/soong/target/product/test_device/system/app/bar/bar.apk",
}, },
}, },
} }
for _, test := range testCases { for _, test := range testCases {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
config := testAppConfig(nil, test.bp, nil) result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
if test.packageNameOverride != "" { if test.packageNameOverride != "" {
config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride} variables.PackageNameOverrides = []string{test.packageNameOverride}
} }
ctx := testContext(config) }),
).RunTestWithBp(t, test.bp)
run(t, ctx, config) foo := result.ModuleForTests("foo", "android_common")
foo := ctx.ModuleForTests("foo", "android_common")
outSoongDir := result.Config.BuildDir()
outputs := foo.AllOutputs() outputs := foo.AllOutputs()
outputMap := make(map[string]bool) outputMap := make(map[string]bool)
for _, o := range outputs { for _, o := range outputs {
outputMap[o] = true outputMap[android.StringPathRelativeToTop(outSoongDir, o)] = true
} }
for _, e := range test.expected { for _, e := range test.expected {
if _, exist := outputMap[e]; !exist { if _, exist := outputMap[e]; !exist {
@@ -1771,13 +1772,15 @@ func TestInstrumentationTargetOverridden(t *testing.T) {
sdk_version: "current", sdk_version: "current",
} }
` `
config := testAppConfig(nil, bp, nil)
config.TestProductVariables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
ctx := testContext(config)
run(t, ctx, config) result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.ManifestPackageNameOverrides = []string{"foo:org.dandroid.bp"}
}),
).RunTestWithBp(t, bp)
bar := ctx.ModuleForTests("bar", "android_common") bar := result.ModuleForTests("bar", "android_common")
res := bar.Output("package-res.apk") res := bar.Output("package-res.apk")
aapt2Flags := res.Args["flags"] aapt2Flags := res.Args["flags"]
e := "--rename-instrumentation-target-package org.dandroid.bp" e := "--rename-instrumentation-target-package org.dandroid.bp"
@@ -1787,7 +1790,8 @@ func TestInstrumentationTargetOverridden(t *testing.T) {
} }
func TestOverrideAndroidApp(t *testing.T) { func TestOverrideAndroidApp(t *testing.T) {
ctx, _ := testJava(t, ` result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(
t, `
android_app { android_app {
name: "foo", name: "foo",
srcs: ["a.java"], srcs: ["a.java"],
@@ -1862,7 +1866,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo", name: "foo",
moduleName: "foo", moduleName: "foo",
variantName: "android_common", variantName: "android_common",
apkPath: "/target/product/test_device/system/app/foo/foo.apk", apkPath: "out/soong/target/product/test_device/system/app/foo/foo.apk",
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
lineageFlag: "", lineageFlag: "",
overrides: []string{"qux"}, overrides: []string{"qux"},
@@ -1874,7 +1878,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo", name: "foo",
moduleName: "bar", moduleName: "bar",
variantName: "android_common_bar", variantName: "android_common_bar",
apkPath: "/target/product/test_device/system/app/bar/bar.apk", apkPath: "out/soong/target/product/test_device/system/app/bar/bar.apk",
certFlag: "cert/new_cert.x509.pem cert/new_cert.pk8", certFlag: "cert/new_cert.x509.pem cert/new_cert.pk8",
lineageFlag: "--lineage lineage.bin", lineageFlag: "--lineage lineage.bin",
overrides: []string{"qux", "foo"}, overrides: []string{"qux", "foo"},
@@ -1886,7 +1890,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo", name: "foo",
moduleName: "baz", moduleName: "baz",
variantName: "android_common_baz", variantName: "android_common_baz",
apkPath: "/target/product/test_device/system/app/baz/baz.apk", apkPath: "out/soong/target/product/test_device/system/app/baz/baz.apk",
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
lineageFlag: "", lineageFlag: "",
overrides: []string{"qux", "foo"}, overrides: []string{"qux", "foo"},
@@ -1898,7 +1902,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo", name: "foo",
moduleName: "baz_no_rename_resources", moduleName: "baz_no_rename_resources",
variantName: "android_common_baz_no_rename_resources", variantName: "android_common_baz_no_rename_resources",
apkPath: "/target/product/test_device/system/app/baz_no_rename_resources/baz_no_rename_resources.apk", apkPath: "out/soong/target/product/test_device/system/app/baz_no_rename_resources/baz_no_rename_resources.apk",
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
lineageFlag: "", lineageFlag: "",
overrides: []string{"qux", "foo"}, overrides: []string{"qux", "foo"},
@@ -1910,7 +1914,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo_no_rename_resources", name: "foo_no_rename_resources",
moduleName: "baz_base_no_rename_resources", moduleName: "baz_base_no_rename_resources",
variantName: "android_common_baz_base_no_rename_resources", variantName: "android_common_baz_base_no_rename_resources",
apkPath: "/target/product/test_device/system/app/baz_base_no_rename_resources/baz_base_no_rename_resources.apk", apkPath: "out/soong/target/product/test_device/system/app/baz_base_no_rename_resources/baz_base_no_rename_resources.apk",
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
lineageFlag: "", lineageFlag: "",
overrides: []string{"qux", "foo_no_rename_resources"}, overrides: []string{"qux", "foo_no_rename_resources"},
@@ -1922,7 +1926,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo_no_rename_resources", name: "foo_no_rename_resources",
moduleName: "baz_override_base_rename_resources", moduleName: "baz_override_base_rename_resources",
variantName: "android_common_baz_override_base_rename_resources", variantName: "android_common_baz_override_base_rename_resources",
apkPath: "/target/product/test_device/system/app/baz_override_base_rename_resources/baz_override_base_rename_resources.apk", apkPath: "out/soong/target/product/test_device/system/app/baz_override_base_rename_resources/baz_override_base_rename_resources.apk",
certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8", certFlag: "build/make/target/product/security/expiredkey.x509.pem build/make/target/product/security/expiredkey.pk8",
lineageFlag: "", lineageFlag: "",
overrides: []string{"qux", "foo_no_rename_resources"}, overrides: []string{"qux", "foo_no_rename_resources"},
@@ -1932,48 +1936,27 @@ func TestOverrideAndroidApp(t *testing.T) {
}, },
} }
for _, expected := range expectedVariants { for _, expected := range expectedVariants {
variant := ctx.ModuleForTests(expected.name, expected.variantName) variant := result.ModuleForTests(expected.name, expected.variantName)
// Check the final apk name // Check the final apk name
outputs := variant.AllOutputs() variant.Output(expected.apkPath)
expectedApkPath := buildDir + expected.apkPath
found := false
for _, o := range outputs {
if o == expectedApkPath {
found = true
break
}
}
if !found {
t.Errorf("Can't find %q in output files.\nAll outputs:%v", expectedApkPath, outputs)
}
// Check the certificate paths // Check the certificate paths
signapk := variant.Output(expected.moduleName + ".apk") signapk := variant.Output(expected.moduleName + ".apk")
certFlag := signapk.Args["certificates"] certFlag := signapk.Args["certificates"]
if expected.certFlag != certFlag { android.AssertStringEquals(t, "certificates flags", expected.certFlag, certFlag)
t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected.certFlag, certFlag)
}
// Check the lineage flags // Check the lineage flags
lineageFlag := signapk.Args["flags"] lineageFlag := signapk.Args["flags"]
if expected.lineageFlag != lineageFlag { android.AssertStringEquals(t, "signing flags", expected.lineageFlag, lineageFlag)
t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected.lineageFlag, lineageFlag)
}
// Check if the overrides field values are correctly aggregated. // Check if the overrides field values are correctly aggregated.
mod := variant.Module().(*AndroidApp) mod := variant.Module().(*AndroidApp)
if !reflect.DeepEqual(expected.overrides, mod.appProperties.Overrides) { android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.appProperties.Overrides)
t.Errorf("Incorrect overrides property value, expected: %q, got: %q",
expected.overrides, mod.appProperties.Overrides)
}
// Test Overridable property: Logging_parent // Test Overridable property: Logging_parent
logging_parent := mod.aapt.LoggingParent logging_parent := mod.aapt.LoggingParent
if expected.logging_parent != logging_parent { android.AssertStringEquals(t, "overrides property value for logging parent", expected.logging_parent, logging_parent)
t.Errorf("Incorrect overrides property value for logging parent, expected: %q, got: %q",
expected.logging_parent, logging_parent)
}
// Check the package renaming flag, if exists. // Check the package renaming flag, if exists.
res := variant.Output("package-res.apk") res := variant.Output("package-res.apk")
@@ -2015,15 +1998,15 @@ func TestOverrideAndroidAppDependency(t *testing.T) {
`) `)
// Verify baz, which depends on the overridden module foo, has the correct classpath javac arg. // Verify baz, which depends on the overridden module foo, has the correct classpath javac arg.
javac := ctx.ModuleForTests("baz", "android_common").Rule("javac") javac := ctx.ModuleForTests("baz", "android_common").Rule("javac").RelativeToTop()
fooTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar") fooTurbine := "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar"
if !strings.Contains(javac.Args["classpath"], fooTurbine) { if !strings.Contains(javac.Args["classpath"], fooTurbine) {
t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine) t.Errorf("baz classpath %v does not contain %q", javac.Args["classpath"], fooTurbine)
} }
// Verify qux, which depends on the overriding module bar, has the correct classpath javac arg. // Verify qux, which depends on the overriding module bar, has the correct classpath javac arg.
javac = ctx.ModuleForTests("qux", "android_common").Rule("javac") javac = ctx.ModuleForTests("qux", "android_common").Rule("javac").RelativeToTop()
barTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common_bar", "turbine-combined", "foo.jar") barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine-combined/foo.jar"
if !strings.Contains(javac.Args["classpath"], barTurbine) { if !strings.Contains(javac.Args["classpath"], barTurbine) {
t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine) t.Errorf("qux classpath %v does not contain %q", javac.Args["classpath"], barTurbine)
} }
@@ -2089,18 +2072,7 @@ func TestOverrideAndroidTest(t *testing.T) {
variant := ctx.ModuleForTests("foo_test", expected.variantName) variant := ctx.ModuleForTests("foo_test", expected.variantName)
// Check the final apk name // Check the final apk name
outputs := variant.AllOutputs() variant.Output("out/soong" + expected.apkPath)
expectedApkPath := buildDir + expected.apkPath
found := false
for _, o := range outputs {
if o == expectedApkPath {
found = true
break
}
}
if !found {
t.Errorf("Can't find %q in output files.\nAll outputs:%v", expectedApkPath, outputs)
}
// Check if the overrides field values are correctly aggregated. // Check if the overrides field values are correctly aggregated.
mod := variant.Module().(*AndroidTest) mod := variant.Module().(*AndroidTest)
@@ -2110,8 +2082,8 @@ func TestOverrideAndroidTest(t *testing.T) {
} }
// Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides. // Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides.
javac := variant.Rule("javac") javac := variant.Rule("javac").RelativeToTop()
turbine := filepath.Join(buildDir, ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar") turbine := filepath.Join("out", "soong", ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar")
if !strings.Contains(javac.Args["classpath"], turbine) { if !strings.Contains(javac.Args["classpath"], turbine) {
t.Errorf("classpath %q does not contain %q", javac.Args["classpath"], turbine) t.Errorf("classpath %q does not contain %q", javac.Args["classpath"], turbine)
} }
@@ -2167,7 +2139,7 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
moduleName: "bar_test", moduleName: "bar_test",
variantName: "android_common", variantName: "android_common",
expectedFlags: []string{ expectedFlags: []string{
"--manifest " + buildDir + "/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml", "--manifest out/soong/.intermediates/bar_test/android_common/manifest_fixer/AndroidManifest.xml",
"--package-name com.android.bar.test", "--package-name com.android.bar.test",
}, },
}, },
@@ -2175,8 +2147,7 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
moduleName: "foo_test", moduleName: "foo_test",
variantName: "android_common_baz_test", variantName: "android_common_baz_test",
expectedFlags: []string{ expectedFlags: []string{
"--manifest " + buildDir + "--manifest out/soong/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
"/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
"--package-name com.android.baz.test", "--package-name com.android.baz.test",
"--test-file-name baz_test.apk", "--test-file-name baz_test.apk",
}, },
@@ -2185,7 +2156,7 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
for _, test := range testCases { for _, test := range testCases {
variant := ctx.ModuleForTests(test.moduleName, test.variantName) variant := ctx.ModuleForTests(test.moduleName, test.variantName)
params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml") params := variant.MaybeOutput("test_config_fixer/AndroidTest.xml").RelativeToTop()
if len(test.expectedFlags) > 0 { if len(test.expectedFlags) > 0 {
if params.Rule == nil { if params.Rule == nil {
@@ -2533,7 +2504,17 @@ func TestCodelessApp(t *testing.T) {
} }
func TestEmbedNotice(t *testing.T) { func TestEmbedNotice(t *testing.T) {
ctx, _ := testJavaWithFS(t, cc.GatherRequiredDepsForTest(android.Android)+` result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
cc.PrepareForTestWithCcDefaultModules,
genrule.PrepareForTestWithGenRuleBuildComponents,
android.MockFS{
"APP_NOTICE": nil,
"GENRULE_NOTICE": nil,
"LIB_NOTICE": nil,
"TOOL_NOTICE": nil,
}.AddToFixture(),
).RunTestWithBp(t, `
android_app { android_app {
name: "foo", name: "foo",
srcs: ["a.java"], srcs: ["a.java"],
@@ -2589,15 +2570,10 @@ func TestEmbedNotice(t *testing.T) {
srcs: ["b.java"], srcs: ["b.java"],
notice: "TOOL_NOTICE", notice: "TOOL_NOTICE",
} }
`, map[string][]byte{ `)
"APP_NOTICE": nil,
"GENRULE_NOTICE": nil,
"LIB_NOTICE": nil,
"TOOL_NOTICE": nil,
})
// foo has NOTICE files to process, and embed_notices is true. // foo has NOTICE files to process, and embed_notices is true.
foo := ctx.ModuleForTests("foo", "android_common") foo := result.ModuleForTests("foo", "android_common")
// verify merge notices rule. // verify merge notices rule.
mergeNotices := foo.Rule("mergeNoticesRule") mergeNotices := foo.Rule("mergeNoticesRule")
noticeInputs := mergeNotices.Inputs.Strings() noticeInputs := mergeNotices.Inputs.Strings()
@@ -2615,27 +2591,23 @@ func TestEmbedNotice(t *testing.T) {
t.Errorf("GENRULE_NOTICE is missing from notice files, %q", noticeInputs) t.Errorf("GENRULE_NOTICE is missing from notice files, %q", noticeInputs)
} }
// aapt2 flags should include -A <NOTICE dir> so that its contents are put in the APK's /assets. // aapt2 flags should include -A <NOTICE dir> so that its contents are put in the APK's /assets.
res := foo.Output("package-res.apk") res := foo.Output("package-res.apk").RelativeToTop()
aapt2Flags := res.Args["flags"] aapt2Flags := res.Args["flags"]
e := "-A " + buildDir + "/.intermediates/foo/android_common/NOTICE" e := "-A out/soong/.intermediates/foo/android_common/NOTICE"
if !strings.Contains(aapt2Flags, e) { android.AssertStringDoesContain(t, "expected.apkPath", aapt2Flags, e)
t.Errorf("asset dir flag for NOTICE, %q is missing in aapt2 link flags, %q", e, aapt2Flags)
}
// bar has NOTICE files to process, but embed_notices is not set. // bar has NOTICE files to process, but embed_notices is not set.
bar := ctx.ModuleForTests("bar", "android_common") bar := result.ModuleForTests("bar", "android_common")
res = bar.Output("package-res.apk") res = bar.Output("package-res.apk").RelativeToTop()
aapt2Flags = res.Args["flags"] aapt2Flags = res.Args["flags"]
e = "-A " + buildDir + "/.intermediates/bar/android_common/NOTICE" e = "-A out/soong/.intermediates/bar/android_common/NOTICE"
if strings.Contains(aapt2Flags, e) { android.AssertStringDoesNotContain(t, "bar shouldn't have the asset dir flag for NOTICE", aapt2Flags, e)
t.Errorf("bar shouldn't have the asset dir flag for NOTICE: %q", e)
}
// baz's embed_notice is true, but it doesn't have any NOTICE files. // baz's embed_notice is true, but it doesn't have any NOTICE files.
baz := ctx.ModuleForTests("baz", "android_common") baz := result.ModuleForTests("baz", "android_common")
res = baz.Output("package-res.apk") res = baz.Output("package-res.apk")
aapt2Flags = res.Args["flags"] aapt2Flags = res.Args["flags"]
e = "-A " + buildDir + "/.intermediates/baz/android_common/NOTICE" e = "-A out/soong/.intermediates/baz/android_common/NOTICE"
if strings.Contains(aapt2Flags, e) { if strings.Contains(aapt2Flags, e) {
t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e) t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e)
} }