diff options
author | 2024-12-04 01:34:34 +0000 | |
---|---|---|
committer | 2024-12-04 03:40:01 +0000 | |
commit | ef8b3b27391d2027097d5ffd918ad5aed5075dd1 (patch) | |
tree | 68f780ed833396e469b07b25cfa71be6ccd84d23 | |
parent | de588a30ac15d786c349c9a651bedb5207e1e07e (diff) |
Move autogenerated rro creation to a higher priority load hook
This prevents issues where the autogenerated rro module depends on a
module that has been disabled using soong config variables
Test: Added a unit test
Change-Id: Iaaa9803d136dd720a67b6f87c25913d82c723214
-rw-r--r-- | java/app.go | 4 | ||||
-rw-r--r-- | java/app_test.go | 73 |
2 files changed, 75 insertions, 2 deletions
diff --git a/java/app.go b/java/app.go index 34884d75c..7bb51e428 100644 --- a/java/app.go +++ b/java/app.go @@ -1783,9 +1783,9 @@ func OverrideAndroidAppModuleFactory() android.Module { android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon) android.InitOverrideModule(m) - android.AddLoadHook(m, func(ctx android.LoadHookContext) { + android.AddLoadHookWithPriority(m, func(ctx android.LoadHookContext) { createInternalRuntimeOverlays(ctx, m.ModuleBase) - }) + }, 1) // Run after soong config load hoook return m } diff --git a/java/app_test.go b/java/app_test.go index 61b718d00..11556b05c 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -4798,3 +4798,76 @@ override_android_app { android.AssertBoolEquals(t, tc.desc, tc.overlayApkExpected, overrideVendorOverlayApk.Rule != nil) } } + +func TestNoAutogeneratedStaticRroForDisabledOverrideApps(t *testing.T) { + t.Parallel() + bp := ` +soong_config_module_type { + name: "my_custom_override_android_app", + module_type: "override_android_app", + config_namespace: "my_namespace", + value_variables: ["my_app_enabled"], + properties: ["enabled"], +} +soong_config_bool_variable { + name: "my_app_enabled", +} +android_app { + name: "foo", + srcs: ["foo.java"], + platform_apis: true, +} +my_custom_override_android_app { + name: "override_foo", + base: "foo", + soong_config_variables: { + my_app_enabled: { + enabled: true, + conditions_default: { + enabled: false + }, + }, + } +} +` + testCases := []struct { + desc string + preparer android.FixturePreparer + overlayApkExpected bool + }{ + { + desc: "my_app_enabled is empty", + overlayApkExpected: false, + }, + { + desc: "my_app_enabled is true", + overlayApkExpected: true, + preparer: android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.VendorVars = map[string]map[string]string{ + "my_namespace": { + "my_app_enabled": "true", + }, + } + }), + }, + } + for _, tc := range testCases { + result := android.GroupFixturePreparers( + PrepareForTestWithJavaDefaultModules, + android.PrepareForTestWithSoongConfigModuleBuildComponents, + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.EnforceRROTargets = []string{"*"} + }), + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.DeviceResourceOverlays = []string{"device/company/test_product"} + }), + android.MockFS{ + "res/foo.xml": nil, + "device/company/test_product/res/foo.xml": nil, + }.AddToFixture(), + android.OptionalFixturePreparer(tc.preparer), + ).RunTestWithBp(t, bp) + overrideVendorOverlayApk := result.ModuleForTests("override_foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").Module().(*AutogenRuntimeResourceOverlay) + android.AssertBoolEquals(t, tc.desc, tc.overlayApkExpected, overrideVendorOverlayApk.exportPackage != nil) + } +} |