Use soong built autogenerated RROs
At ToT, soong emits metadata to make (LOCAL_SOONG_PRODUCT_RRO_DIRS and
LOCAL_SOONG_DEVICE_RRO_DIRS), and make uses this metadata to build and
install apks that are intalled in /vendor or /product. This CL ports
this logic to soong.
This CL autogenerates these modules in a load hook for android_app and
override_android_app, and adds them to the `LOCAL_REQUIRED_MODULES` of
the base app. The autogenerated modules will inherit the enabled
property of the apps. This required me to add `Target.Android.Enabled`
to commonProperties in ModuleBase.
Since autogeneration happens in soong now,
`LOCAL_SOONG_(DEVICE|PRODUCT)_RRO_DIRS` no longer needs to be exported.
Followup work
- Installing the overlay variants for soong built filesystems.
Test: lunch aosp_cf_x86_64_phone-trunk_staging-userdebug
Test: no diff in system, vendor, product file_list.txt
Test: m out/target/product/vsoc_x86_64/vendor/overlay/SystemUI__aosp_cf_x86_64_phone__auto_generated_rro_vendor.apk
the apk is not bit-identical, but this is likely due to different
aapt link flags between make and soong (e.g. `--enable-compact-entries`
is added as default in soong but not in make
Test: aapt2 diff
SystemUI__aosp_cf_x86_64_phone__auto_generated_rro_vendor.apk.before
SystemUI__aosp_cf_x86_64_phone__auto_generated_rro_vendor.apk.after
reports no diffs
Change-Id: I9b212a4ed443250a63dbe27cb955c6f133cff9af
diff --git a/java/app_test.go b/java/app_test.go
index 3d83ea1..61b718d 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -4727,3 +4727,74 @@
"out/soong/.intermediates/foo/android_common/aapt2/res/values_strings.(test.package.flag1).arsc.flat",
)
}
+
+func TestAutogeneratedStaticRro(t *testing.T) {
+ t.Parallel()
+ bp := `
+android_app {
+ name: "foo",
+ srcs: ["foo.java"],
+ platform_apis: true,
+}
+override_android_app {
+ name: "override_foo",
+ base: "foo",
+}
+`
+ testCases := []struct {
+ desc string
+ preparer android.FixturePreparer
+ overlayApkExpected bool
+ }{
+ {
+ desc: "No DEVICE_PACKAGE_OVERLAYS, no overlay .apk file",
+ overlayApkExpected: false,
+ },
+ {
+ desc: "DEVICE_PACKAGE_OVERLAYS exists, but the directory is empty",
+ overlayApkExpected: false,
+ preparer: android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.DeviceResourceOverlays = []string{"device/company/test_product"}
+ }),
+ },
+ {
+ desc: "DEVICE_PACKAGE_OVERLAYS exists, directory is non-empty, but does not contain a matching resource dir",
+ overlayApkExpected: false,
+ preparer: android.GroupFixturePreparers(
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.DeviceResourceOverlays = []string{"device/company/test_product"}
+ }),
+ android.MockFS{
+ "res/foo.xml": nil,
+ "device/company/test_product/different_res/foo.xml": nil, // different dir
+ }.AddToFixture(),
+ ),
+ },
+ {
+ desc: "DEVICE_PACKAGE_OVERLAYS and the directory contain a matching resource dir",
+ overlayApkExpected: true,
+ preparer: android.GroupFixturePreparers(
+ 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(),
+ ),
+ },
+ }
+ for _, tc := range testCases {
+ result := android.GroupFixturePreparers(
+ PrepareForTestWithJavaDefaultModules,
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.EnforceRROTargets = []string{"*"}
+ }),
+ android.OptionalFixturePreparer(tc.preparer),
+ ).RunTestWithBp(t, bp)
+ vendorOverlayApk := result.ModuleForTests("foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").MaybeOutput("foo__test_product__auto_generated_rro_vendor.apk")
+ android.AssertBoolEquals(t, tc.desc, tc.overlayApkExpected, vendorOverlayApk.Rule != nil)
+ overrideVendorOverlayApk := result.ModuleForTests("override_foo__test_product__auto_generated_rro_vendor", "android_arm64_armv8-a").MaybeOutput("override_foo__test_product__auto_generated_rro_vendor.apk")
+ android.AssertBoolEquals(t, tc.desc, tc.overlayApkExpected, overrideVendorOverlayApk.Rule != nil)
+ }
+}