Merge "Remove uses of buildDir from java/app_test.go"

This commit is contained in:
Paul Duffin 2021-03-24 07:58:28 +00:00 committed by Gerrit Code Review
commit 700185b1f8
1 changed files with 151 additions and 179 deletions

View File

@ -26,6 +26,7 @@ import (
"android/soong/android"
"android/soong/cc"
"android/soong/genrule"
)
// 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")
expectedOutputs := []string{
filepath.Join(buildDir, ".intermediates/foo/android_common/foo.apk"),
filepath.Join(buildDir, ".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.apk",
"out/soong/.intermediates/foo/android_common/foo_v4.apk",
"out/soong/.intermediates/foo/android_common/foo_v7_hdpi.apk",
}
for _, expectedOutput := range expectedOutputs {
foo.Output(expectedOutput)
@ -130,9 +131,7 @@ func TestAppSplits(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if g, w := outputFiles.Strings(), expectedOutputs; !reflect.DeepEqual(g, w) {
t.Errorf(`want OutputFiles("") = %q, got %q`, w, g)
}
android.AssertPathsRelativeToTopEquals(t, `OutputFiles("")`, expectedOutputs, outputFiles)
}
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,
}
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
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,
}
@ -561,11 +560,13 @@ func TestResourceDirs(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
config := testConfig(nil, fmt.Sprintf(bp, testCase.prop), fs)
ctx := testContext(config)
run(t, ctx, config)
result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
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")
var resources []string
@ -575,10 +576,7 @@ func TestResourceDirs(t *testing.T) {
}
}
if !reflect.DeepEqual(resources, testCase.resources) {
t.Errorf("expected resource files %q, got %q",
testCase.resources, resources)
}
android.AssertDeepEquals(t, "resource files", testCase.resources, resources)
})
}
}
@ -624,9 +622,9 @@ func TestLibraryAssets(t *testing.T) {
name: "foo",
// lib1 has its own asset. lib3 doesn't have any, but provides lib4's transitively.
assetPackages: []string{
buildDir + "/.intermediates/foo/android_common/aapt2/package-res.apk",
buildDir + "/.intermediates/lib1/android_common/assets.zip",
buildDir + "/.intermediates/lib3/android_common/assets.zip",
"out/soong/.intermediates/foo/android_common/aapt2/package-res.apk",
"out/soong/.intermediates/lib1/android_common/assets.zip",
"out/soong/.intermediates/lib3/android_common/assets.zip",
},
},
{
@ -639,8 +637,8 @@ func TestLibraryAssets(t *testing.T) {
{
name: "lib3",
assetPackages: []string{
buildDir + "/.intermediates/lib3/android_common/aapt2/package-res.apk",
buildDir + "/.intermediates/lib4/android_common/assets.zip",
"out/soong/.intermediates/lib3/android_common/aapt2/package-res.apk",
"out/soong/.intermediates/lib4/android_common/assets.zip",
},
},
{
@ -661,24 +659,18 @@ func TestLibraryAssets(t *testing.T) {
} else {
aapt2link = m.Output("package-res.apk")
}
aapt2link = aapt2link.RelativeToTop()
aapt2Flags := aapt2link.Args["flags"]
if test.assetFlag != "" {
if !strings.Contains(aapt2Flags, test.assetFlag) {
t.Errorf("Can't find asset flag %q in aapt2 link flags %q", test.assetFlag, aapt2Flags)
}
android.AssertStringDoesContain(t, "asset flag", aapt2Flags, test.assetFlag)
} else {
if strings.Contains(aapt2Flags, " -A ") {
t.Errorf("aapt2 link flags %q contain unexpected asset flag", aapt2Flags)
}
android.AssertStringDoesNotContain(t, "aapt2 link flags", aapt2Flags, " -A ")
}
// Check asset merge rule.
if len(test.assetPackages) > 0 {
mergeAssets := m.Output("package-res.apk")
if !reflect.DeepEqual(test.assetPackages, mergeAssets.Inputs.Strings()) {
t.Errorf("Unexpected mergeAssets inputs: %v, expected: %v",
mergeAssets.Inputs.Strings(), test.assetPackages)
}
android.AssertPathsRelativeToTopEquals(t, "mergeAssets inputs", test.assetPackages, mergeAssets.Inputs)
}
})
}
@ -750,9 +742,9 @@ func TestAndroidResources(t *testing.T) {
},
overlayFiles: map[string][]string{
"foo": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
buildDir + "/.intermediates/lib/android_common/package-res.apk",
buildDir + "/.intermediates/lib3/android_common/package-res.apk",
"out/soong/.intermediates/lib2/android_common/package-res.apk",
"out/soong/.intermediates/lib/android_common/package-res.apk",
"out/soong/.intermediates/lib3/android_common/package-res.apk",
"foo/res/res/values/strings.xml",
"device/vendor/blah/static_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",
},
"lib": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
"out/soong/.intermediates/lib2/android_common/package-res.apk",
"lib/res/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{
"foo": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
buildDir + "/.intermediates/lib/android_common/package-res.apk",
buildDir + "/.intermediates/lib3/android_common/package-res.apk",
"out/soong/.intermediates/lib2/android_common/package-res.apk",
"out/soong/.intermediates/lib/android_common/package-res.apk",
"out/soong/.intermediates/lib3/android_common/package-res.apk",
"foo/res/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",
},
"lib": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
"out/soong/.intermediates/lib2/android_common/package-res.apk",
"lib/res/res/values/strings.xml",
},
},
@ -827,15 +819,15 @@ func TestAndroidResources(t *testing.T) {
},
overlayFiles: map[string][]string{
"foo": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
buildDir + "/.intermediates/lib/android_common/package-res.apk",
buildDir + "/.intermediates/lib3/android_common/package-res.apk",
"out/soong/.intermediates/lib2/android_common/package-res.apk",
"out/soong/.intermediates/lib/android_common/package-res.apk",
"out/soong/.intermediates/lib3/android_common/package-res.apk",
"foo/res/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"},
"lib": {
buildDir + "/.intermediates/lib2/android_common/package-res.apk",
"out/soong/.intermediates/lib2/android_common/package-res.apk",
"lib/res/res/values/strings.xml",
},
},
@ -862,7 +854,7 @@ func TestAndroidResources(t *testing.T) {
"product/vendor/blah/overlay",
}
fs := map[string][]byte{
fs := android.MockFS{
"foo/res/res/values/strings.xml": nil,
"bar/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 {
t.Run(testCase.name, func(t *testing.T) {
config := testAppConfig(nil, bp, fs)
config.TestProductVariables.DeviceResourceOverlays = deviceResourceOverlays
config.TestProductVariables.ProductResourceOverlays = productResourceOverlays
if testCase.enforceRROTargets != nil {
config.TestProductVariables.EnforceRROTargets = testCase.enforceRROTargets
}
if testCase.enforceRROExcludedOverlays != nil {
config.TestProductVariables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
}
ctx := testContext(config)
run(t, ctx, config)
result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
PrepareForTestWithOverlayBuildComponents,
fs.AddToFixture(),
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.DeviceResourceOverlays = deviceResourceOverlays
variables.ProductResourceOverlays = productResourceOverlays
if testCase.enforceRROTargets != nil {
variables.EnforceRROTargets = testCase.enforceRROTargets
}
if testCase.enforceRROExcludedOverlays != nil {
variables.EnforceRROExcludedOverlays = testCase.enforceRROExcludedOverlays
}
}),
).RunTestWithBp(t, bp)
resourceListToFiles := func(module android.TestingModule, list []string) (files []string) {
for _, o := range list {
@ -942,14 +937,14 @@ func TestAndroidResources(t *testing.T) {
}
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")
if resourceList.Rule != nil {
resourceFiles = resourceListToFiles(module, resourceList.Inputs.Strings())
resourceFiles = resourceListToFiles(module, android.PathsRelativeToTop(resourceList.Inputs))
}
overlayList := module.MaybeOutput("aapt2/overlay.list")
if overlayList.Rule != nil {
overlayFiles = resourceListToFiles(module, overlayList.Inputs.Strings())
overlayFiles = resourceListToFiles(module, android.PathsRelativeToTop(overlayList.Inputs))
}
for _, d := range module.Module().(AndroidLibraryDependency).ExportedRRODirs() {
@ -961,7 +956,7 @@ func TestAndroidResources(t *testing.T) {
} else {
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
@ -1269,13 +1264,19 @@ func TestAppSdkVersionByPartition(t *testing.T) {
}
`
config := testAppConfig(nil, bp, nil)
config.TestProductVariables.EnforceProductPartitionInterface = proptools.BoolPtr(enforce)
errorHandler := android.FixtureExpectsNoErrors
if enforce {
testJavaErrorWithConfig(t, "sdk_version must have a value when the module is located at vendor or product", config)
} else {
testJavaWithConfig(t, config)
errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern("sdk_version must have a value when the module is located at vendor or product")
}
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 {
t.Run(test.name, func(t *testing.T) {
config := testAppConfig(nil, test.bp, nil)
if test.certificateOverride != "" {
config.TestProductVariables.CertificateOverrides = []string{test.certificateOverride}
}
ctx := testContext(config)
result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
if test.certificateOverride != "" {
variables.CertificateOverrides = []string{test.certificateOverride}
}
}),
).RunTestWithBp(t, test.bp)
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
foo := result.ModuleForTests("foo", "android_common")
signapk := foo.Output("foo.apk")
signCertificateFlags := signapk.Args["certificates"]
if test.expectedCertificate != signCertificateFlags {
t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expectedCertificate, signCertificateFlags)
}
android.AssertStringEquals(t, "certificates flags", test.expectedCertificate, signCertificateFlags)
signFlags := signapk.Args["flags"]
if test.expectedLineage != signFlags {
t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expectedLineage, signFlags)
}
android.AssertStringEquals(t, "signing flags", test.expectedLineage, signFlags)
})
}
}
@ -1677,17 +1676,15 @@ func TestRequestV4SigningFlag(t *testing.T) {
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
config := testAppConfig(nil, test.bp, nil)
ctx := testContext(config)
result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
).RunTestWithBp(t, test.bp)
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
foo := result.ModuleForTests("foo", "android_common")
signapk := foo.Output("foo.apk")
signFlags := signapk.Args["flags"]
if test.expected != signFlags {
t.Errorf("Incorrect signing flags, expected: %q, got: %q", test.expected, signFlags)
}
android.AssertStringEquals(t, "signing flags", test.expected, signFlags)
})
}
}
@ -1710,8 +1707,8 @@ func TestPackageNameOverride(t *testing.T) {
`,
packageNameOverride: "",
expected: []string{
buildDir + "/.intermediates/foo/android_common/foo.apk",
buildDir + "/target/product/test_device/system/app/foo/foo.apk",
"out/soong/.intermediates/foo/android_common/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",
expected: []string{
// The package apk should be still be the original name for test dependencies.
buildDir + "/.intermediates/foo/android_common/bar.apk",
buildDir + "/target/product/test_device/system/app/bar/bar.apk",
"out/soong/.intermediates/foo/android_common/bar.apk",
"out/soong/target/product/test_device/system/app/bar/bar.apk",
},
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
config := testAppConfig(nil, test.bp, nil)
if test.packageNameOverride != "" {
config.TestProductVariables.PackageNameOverrides = []string{test.packageNameOverride}
}
ctx := testContext(config)
result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
if test.packageNameOverride != "" {
variables.PackageNameOverrides = []string{test.packageNameOverride}
}
}),
).RunTestWithBp(t, test.bp)
run(t, ctx, config)
foo := ctx.ModuleForTests("foo", "android_common")
foo := result.ModuleForTests("foo", "android_common")
outSoongDir := result.Config.BuildDir()
outputs := foo.AllOutputs()
outputMap := make(map[string]bool)
for _, o := range outputs {
outputMap[o] = true
outputMap[android.StringPathRelativeToTop(outSoongDir, o)] = true
}
for _, e := range test.expected {
if _, exist := outputMap[e]; !exist {
@ -1771,13 +1772,15 @@ func TestInstrumentationTargetOverridden(t *testing.T) {
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")
aapt2Flags := res.Args["flags"]
e := "--rename-instrumentation-target-package org.dandroid.bp"
@ -1787,7 +1790,8 @@ func TestInstrumentationTargetOverridden(t *testing.T) {
}
func TestOverrideAndroidApp(t *testing.T) {
ctx, _ := testJava(t, `
result := PrepareForTestWithJavaDefaultModules.RunTestWithBp(
t, `
android_app {
name: "foo",
srcs: ["a.java"],
@ -1862,7 +1866,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo",
moduleName: "foo",
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",
lineageFlag: "",
overrides: []string{"qux"},
@ -1874,7 +1878,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo",
moduleName: "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",
lineageFlag: "--lineage lineage.bin",
overrides: []string{"qux", "foo"},
@ -1886,7 +1890,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo",
moduleName: "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",
lineageFlag: "",
overrides: []string{"qux", "foo"},
@ -1898,7 +1902,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo",
moduleName: "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",
lineageFlag: "",
overrides: []string{"qux", "foo"},
@ -1910,7 +1914,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo_no_rename_resources",
moduleName: "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",
lineageFlag: "",
overrides: []string{"qux", "foo_no_rename_resources"},
@ -1922,7 +1926,7 @@ func TestOverrideAndroidApp(t *testing.T) {
name: "foo_no_rename_resources",
moduleName: "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",
lineageFlag: "",
overrides: []string{"qux", "foo_no_rename_resources"},
@ -1932,48 +1936,27 @@ func TestOverrideAndroidApp(t *testing.T) {
},
}
for _, expected := range expectedVariants {
variant := ctx.ModuleForTests(expected.name, expected.variantName)
variant := result.ModuleForTests(expected.name, expected.variantName)
// Check the final apk name
outputs := variant.AllOutputs()
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)
}
variant.Output(expected.apkPath)
// Check the certificate paths
signapk := variant.Output(expected.moduleName + ".apk")
certFlag := signapk.Args["certificates"]
if expected.certFlag != certFlag {
t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected.certFlag, certFlag)
}
android.AssertStringEquals(t, "certificates flags", expected.certFlag, certFlag)
// Check the lineage flags
lineageFlag := signapk.Args["flags"]
if expected.lineageFlag != lineageFlag {
t.Errorf("Incorrect signing flags, expected: %q, got: %q", expected.lineageFlag, lineageFlag)
}
android.AssertStringEquals(t, "signing flags", expected.lineageFlag, lineageFlag)
// Check if the overrides field values are correctly aggregated.
mod := variant.Module().(*AndroidApp)
if !reflect.DeepEqual(expected.overrides, mod.appProperties.Overrides) {
t.Errorf("Incorrect overrides property value, expected: %q, got: %q",
expected.overrides, mod.appProperties.Overrides)
}
android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.appProperties.Overrides)
// Test Overridable property: Logging_parent
logging_parent := mod.aapt.LoggingParent
if expected.logging_parent != logging_parent {
t.Errorf("Incorrect overrides property value for logging parent, expected: %q, got: %q",
expected.logging_parent, logging_parent)
}
android.AssertStringEquals(t, "overrides property value for logging parent", expected.logging_parent, logging_parent)
// Check the package renaming flag, if exists.
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.
javac := ctx.ModuleForTests("baz", "android_common").Rule("javac")
fooTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common", "turbine-combined", "foo.jar")
javac := ctx.ModuleForTests("baz", "android_common").Rule("javac").RelativeToTop()
fooTurbine := "out/soong/.intermediates/foo/android_common/turbine-combined/foo.jar"
if !strings.Contains(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.
javac = ctx.ModuleForTests("qux", "android_common").Rule("javac")
barTurbine := filepath.Join(buildDir, ".intermediates", "foo", "android_common_bar", "turbine-combined", "foo.jar")
javac = ctx.ModuleForTests("qux", "android_common").Rule("javac").RelativeToTop()
barTurbine := "out/soong/.intermediates/foo/android_common_bar/turbine-combined/foo.jar"
if !strings.Contains(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)
// Check the final apk name
outputs := variant.AllOutputs()
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)
}
variant.Output("out/soong" + expected.apkPath)
// Check if the overrides field values are correctly aggregated.
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.
javac := variant.Rule("javac")
turbine := filepath.Join(buildDir, ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar")
javac := variant.Rule("javac").RelativeToTop()
turbine := filepath.Join("out", "soong", ".intermediates", "foo", expected.targetVariant, "turbine-combined", "foo.jar")
if !strings.Contains(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",
variantName: "android_common",
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",
},
},
@ -2175,8 +2147,7 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
moduleName: "foo_test",
variantName: "android_common_baz_test",
expectedFlags: []string{
"--manifest " + buildDir +
"/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
"--manifest out/soong/.intermediates/foo_test/android_common_baz_test/manifest_fixer/AndroidManifest.xml",
"--package-name com.android.baz.test",
"--test-file-name baz_test.apk",
},
@ -2185,7 +2156,7 @@ func TestAndroidTest_FixTestConfig(t *testing.T) {
for _, test := range testCases {
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 params.Rule == nil {
@ -2533,7 +2504,17 @@ func TestCodelessApp(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 {
name: "foo",
srcs: ["a.java"],
@ -2589,15 +2570,10 @@ func TestEmbedNotice(t *testing.T) {
srcs: ["b.java"],
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 := ctx.ModuleForTests("foo", "android_common")
foo := result.ModuleForTests("foo", "android_common")
// verify merge notices rule.
mergeNotices := foo.Rule("mergeNoticesRule")
noticeInputs := mergeNotices.Inputs.Strings()
@ -2615,27 +2591,23 @@ func TestEmbedNotice(t *testing.T) {
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.
res := foo.Output("package-res.apk")
res := foo.Output("package-res.apk").RelativeToTop()
aapt2Flags := res.Args["flags"]
e := "-A " + buildDir + "/.intermediates/foo/android_common/NOTICE"
if !strings.Contains(aapt2Flags, e) {
t.Errorf("asset dir flag for NOTICE, %q is missing in aapt2 link flags, %q", e, aapt2Flags)
}
e := "-A out/soong/.intermediates/foo/android_common/NOTICE"
android.AssertStringDoesContain(t, "expected.apkPath", aapt2Flags, e)
// bar has NOTICE files to process, but embed_notices is not set.
bar := ctx.ModuleForTests("bar", "android_common")
res = bar.Output("package-res.apk")
bar := result.ModuleForTests("bar", "android_common")
res = bar.Output("package-res.apk").RelativeToTop()
aapt2Flags = res.Args["flags"]
e = "-A " + buildDir + "/.intermediates/bar/android_common/NOTICE"
if strings.Contains(aapt2Flags, e) {
t.Errorf("bar shouldn't have the asset dir flag for NOTICE: %q", e)
}
e = "-A out/soong/.intermediates/bar/android_common/NOTICE"
android.AssertStringDoesNotContain(t, "bar shouldn't have the asset dir flag for NOTICE", aapt2Flags, e)
// 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")
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) {
t.Errorf("baz shouldn't have the asset dir flag for NOTICE: %q", e)
}