Make "overrides" attribute of Android_app overridable

Move overrides attribute from appProperties to overridableAppProperties

Bug: 220029162
Test: m
Change-Id: I6f527df3173f142311734333ad37018c83d5e279
Merged-In: I6f527df3173f142311734333ad37018c83d5e279
(cherry picked from commit a2ce78f80d)
This commit is contained in:
zhidou 2022-02-17 02:33:12 +00:00 committed by Colin Cross
parent f2d126b3d8
commit 198f589222
4 changed files with 118 additions and 14 deletions

View file

@ -424,8 +424,8 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
func (a *AndroidApp) getOverriddenPackages() []string {
var overridden []string
if len(a.appProperties.Overrides) > 0 {
overridden = append(overridden, a.appProperties.Overrides...)
if len(a.overridableAppProperties.Overrides) > 0 {
overridden = append(overridden, a.overridableAppProperties.Overrides...)
}
// When APK name is overridden via PRODUCT_PACKAGE_NAME_OVERRIDES
// ensure that the original name is overridden.

View file

@ -206,3 +206,49 @@ func TestAndroidTestHelperApp_LocalDisableTestConfig(t *testing.T) {
t.Errorf("Unexpected flag value - expected: %q, actual: %q", expected, actual)
}
}
func TestGetOverriddenPackages(t *testing.T) {
ctx, _ := testJava(
t, `
android_app {
name: "foo",
srcs: ["a.java"],
sdk_version: "current",
overrides: ["qux"]
}
override_android_app {
name: "foo_override",
base: "foo",
overrides: ["bar"]
}
`)
expectedVariants := []struct {
name string
moduleName string
variantName string
overrides []string
}{
{
name: "foo",
moduleName: "foo",
variantName: "android_common",
overrides: []string{"qux"},
},
{
name: "foo",
moduleName: "foo_override",
variantName: "android_common_foo_override",
overrides: []string{"bar", "foo"},
},
}
for _, expected := range expectedVariants {
mod := ctx.ModuleForTests(expected.name, expected.variantName).Module()
entries := android.AndroidMkEntriesForTest(t, ctx, mod)[0]
actual := entries.EntryMap["LOCAL_OVERRIDES_PACKAGES"]
android.AssertDeepEquals(t, "overrides property", expected.overrides, actual)
}
}

View file

@ -63,13 +63,6 @@ type appProperties struct {
// list of resource labels to generate individual resource packages
Package_splits []string
// Names of modules to be overridden. Listed modules can only be other binaries
// (in Make or Soong).
// This does not completely prevent installation of the overridden binaries, but if both
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES.
Overrides []string
// list of native libraries that will be provided in or alongside the resulting jar
Jni_libs []string `android:"arch_variant"`
@ -133,6 +126,13 @@ type overridableAppProperties struct {
// Whether to rename the package in resources to the override name rather than the base name. Defaults to true.
Rename_resources_package *bool
// Names of modules to be overridden. Listed modules can only be other binaries
// (in Make or Soong).
// This does not completely prevent installation of the overridden binaries, but if both
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES.
Overrides []string
}
type AndroidApp struct {
@ -913,7 +913,7 @@ func AndroidAppFactory() android.Module {
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
android.InitOverridableModule(module, &module.appProperties.Overrides)
android.InitOverridableModule(module, &module.overridableAppProperties.Overrides)
android.InitApexModule(module)
android.InitBazelModule(module)
@ -1037,7 +1037,7 @@ func AndroidTestFactory() android.Module {
android.InitAndroidMultiTargetsArchModule(module, android.DeviceSupported, android.MultilibCommon)
android.InitDefaultableModule(module)
android.InitOverridableModule(module, &module.appProperties.Overrides)
android.InitOverridableModule(module, &module.overridableAppProperties.Overrides)
return module
}

View file

@ -1962,7 +1962,7 @@ func TestOverrideAndroidApp(t *testing.T) {
// Check if the overrides field values are correctly aggregated.
mod := variant.Module().(*AndroidApp)
android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.appProperties.Overrides)
android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.overridableAppProperties.Overrides)
// Test Overridable property: Logging_parent
logging_parent := mod.aapt.LoggingParent
@ -1980,6 +1980,64 @@ func TestOverrideAndroidApp(t *testing.T) {
}
}
func TestOverrideAndroidAppOverrides(t *testing.T) {
ctx, _ := testJava(
t, `
android_app {
name: "foo",
srcs: ["a.java"],
sdk_version: "current",
overrides: ["qux"]
}
android_app {
name: "bar",
srcs: ["b.java"],
sdk_version: "current",
overrides: ["foo"]
}
override_android_app {
name: "foo_override",
base: "foo",
overrides: ["bar"]
}
`)
expectedVariants := []struct {
name string
moduleName string
variantName string
overrides []string
}{
{
name: "foo",
moduleName: "foo",
variantName: "android_common",
overrides: []string{"qux"},
},
{
name: "bar",
moduleName: "bar",
variantName: "android_common",
overrides: []string{"foo"},
},
{
name: "foo",
moduleName: "foo_override",
variantName: "android_common_foo_override",
overrides: []string{"bar", "foo"},
},
}
for _, expected := range expectedVariants {
variant := ctx.ModuleForTests(expected.name, expected.variantName)
// Check if the overrides field values are correctly aggregated.
mod := variant.Module().(*AndroidApp)
android.AssertDeepEquals(t, "overrides property", expected.overrides, mod.overridableAppProperties.Overrides)
}
}
func TestOverrideAndroidAppStem(t *testing.T) {
ctx, _ := testJava(t, `
android_app {
@ -2160,9 +2218,9 @@ func TestOverrideAndroidTest(t *testing.T) {
// Check if the overrides field values are correctly aggregated.
mod := variant.Module().(*AndroidTest)
if !reflect.DeepEqual(expected.overrides, mod.appProperties.Overrides) {
if !reflect.DeepEqual(expected.overrides, mod.overridableAppProperties.Overrides) {
t.Errorf("Incorrect overrides property value, expected: %q, got: %q",
expected.overrides, mod.appProperties.Overrides)
expected.overrides, mod.overridableAppProperties.Overrides)
}
// Check if javac classpath has the correct jar file path. This checks instrumentation_for overrides.