Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 24de2b46 authored by Liana Kazanova's avatar Liana Kazanova Committed by Automerger Merge Worker
Browse files

Merge "Revert "Use soong built autogenerated RROs"" into main am: 53cee9d4 am: 8c9c0ab6

parents 5c4f46f7 8c9c0ab6
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -338,7 +338,6 @@ type commonProperties struct {
		}
		Android struct {
			Compile_multilib *string
			Enabled          *bool
		}
	}

+5 −7
Original line number Diff line number Diff line
@@ -588,16 +588,14 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
		}
	}

	var compiledRro, compiledRroOverlay android.Paths
	if opts.rroDirs != nil {
		compiledRro, compiledRroOverlay = a.compileResInDir(ctx, *opts.rroDirs, compileFlags, opts.aconfigTextFiles)
	} else {
		// RRO enforcement is done based on module name. Compile the overlayDirs only if rroDirs is nil.
		// This ensures that the autogenerated RROs do not compile the overlay dirs twice.
	for _, dir := range overlayDirs {
		compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files,
			compileFlags, a.filterProduct(), opts.aconfigTextFiles).Paths()...)
	}

	var compiledRro, compiledRroOverlay android.Paths
	if opts.rroDirs != nil {
		compiledRro, compiledRroOverlay = a.compileResInDir(ctx, *opts.rroDirs, compileFlags, opts.aconfigTextFiles)
	}

	var splitPackages android.WritablePaths
+30 −1
Original line number Diff line number Diff line
@@ -307,11 +307,15 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
			Disabled: true,
		}}
	}
	var required []string
	if proptools.Bool(app.appProperties.Generate_product_characteristics_rro) {
		required = []string{app.productCharacteristicsRROPackageName()}
	}
	return []android.AndroidMkEntries{android.AndroidMkEntries{
		Class:      "APPS",
		OutputFile: android.OptionalPathForPath(app.outputFile),
		Include:    "$(BUILD_SYSTEM)/soong_app_prebuilt.mk",
		Required:   app.requiredModuleNames,
		Required:   required,
		ExtraEntries: []android.AndroidMkExtraEntriesFunc{
			func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
				// App module names can be overridden.
@@ -346,6 +350,31 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries {
					entries.SetBoolIfTrue("LOCAL_NO_STANDARD_LIBRARIES", true)
				}

				filterRRO := func(filter overlayType) android.Paths {
					var paths android.Paths
					seen := make(map[android.Path]bool)
					for _, d := range app.rroDirsDepSet.ToList() {
						if d.overlayType == filter {
							if seen[d.path] {
								continue
							}
							seen[d.path] = true
							paths = append(paths, d.path)
						}
					}
					// Reverse the order, Soong stores rroDirs in aapt2 order (low to high priority), but Make
					// expects it in LOCAL_RESOURCE_DIRS order (high to low priority).
					return android.ReversePaths(paths)
				}
				deviceRRODirs := filterRRO(device)
				if len(deviceRRODirs) > 0 {
					entries.AddStrings("LOCAL_SOONG_DEVICE_RRO_DIRS", deviceRRODirs.Strings()...)
				}
				productRRODirs := filterRRO(product)
				if len(productRRODirs) > 0 {
					entries.AddStrings("LOCAL_SOONG_PRODUCT_RRO_DIRS", productRRODirs.Strings()...)
				}

				entries.SetBoolIfTrue("LOCAL_EXPORT_PACKAGE_RESOURCES", Bool(app.appProperties.Export_package_resources))

				entries.SetPath("LOCAL_FULL_MANIFEST_FILE", app.manifestPath)
+0 −91
Original line number Diff line number Diff line
@@ -223,8 +223,6 @@ type AndroidApp struct {
	javaApiUsedByOutputFile android.ModuleOutPath

	privAppAllowlist android.OptionalPath

	requiredModuleNames []string
}

func (a *AndroidApp) IsInstallable() bool {
@@ -423,24 +421,6 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		TestHelperApp:   false,
		EmbeddedJNILibs: embeddedJniLibs,
	})

	a.requiredModuleNames = a.getRequiredModuleNames(ctx)
}

func (a *AndroidApp) getRequiredModuleNames(ctx android.ModuleContext) []string {
	var required []string
	if proptools.Bool(a.appProperties.Generate_product_characteristics_rro) {
		required = []string{a.productCharacteristicsRROPackageName()}
	}
	// Install the vendor overlay variant if this app is installed.
	if len(filterRRO(a.rroDirsDepSet, device)) > 0 {
		required = append(required, AutogeneratedRroModuleName(ctx, ctx.Module().Name(), "vendor"))
	}
	// Install the product overlay variant if this app is installed.
	if len(filterRRO(a.rroDirsDepSet, product)) > 0 {
		required = append(required, AutogeneratedRroModuleName(ctx, ctx.Module().Name(), "product"))
	}
	return required
}

func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
@@ -1397,11 +1377,6 @@ func AndroidAppFactory() android.Module {
			}
		}
		ctx.CreateModule(RuntimeResourceOverlayFactory, &rroProperties)

	})

	module.SetDefaultableHook(func(ctx android.DefaultableHookContext) {
		createInternalRuntimeOverlays(ctx, module.ModuleBase)
	})

	return module
@@ -1411,68 +1386,6 @@ func AutogeneratedRroModuleName(ctx android.EarlyModuleContext, moduleName, part
	return fmt.Sprintf("%s__%s__auto_generated_rro_%s", moduleName, ctx.Config().DeviceProduct(), partition)
}

type createModuleContext interface {
	android.EarlyModuleContext
	CreateModule(android.ModuleFactory, ...interface{}) android.Module
}

func createInternalRuntimeOverlays(ctx createModuleContext, a android.ModuleBase) {
	if !ctx.Config().HasDeviceProduct() {
		return
	}
	// vendor
	vendorOverlayProps := struct {
		Name                *string
		Base                *string
		Vendor              *bool
		Product_specific    *bool
		System_ext_specific *bool
		Manifest            *string
		Sdk_version         *string
		Compile_multilib    *string
		Enabled             proptools.Configurable[bool]
	}{
		Name:                proptools.StringPtr(AutogeneratedRroModuleName(ctx, a.Name(), "vendor")),
		Base:                proptools.StringPtr(a.Name()),
		Vendor:              proptools.BoolPtr(true),
		Product_specific:    proptools.BoolPtr(false),
		System_ext_specific: proptools.BoolPtr(false),
		Manifest:            proptools.StringPtr(":" + a.Name() + "{.manifest.xml}"),
		Sdk_version:         proptools.StringPtr("current"),
		Compile_multilib:    proptools.StringPtr("first"),
		Enabled:             a.EnabledProperty().Clone(),
	}
	ctx.CreateModule(AutogenRuntimeResourceOverlayFactory, &vendorOverlayProps)

	// product
	productOverlayProps := struct {
		Name                *string
		Base                *string
		Vendor              *bool
		Proprietary         *bool
		Soc_specific        *bool
		Product_specific    *bool
		System_ext_specific *bool
		Manifest            *string
		Sdk_version         *string
		Compile_multilib    *string
		Enabled             proptools.Configurable[bool]
	}{
		Name:                proptools.StringPtr(AutogeneratedRroModuleName(ctx, a.Name(), "product")),
		Base:                proptools.StringPtr(a.Name()),
		Vendor:              proptools.BoolPtr(false),
		Proprietary:         proptools.BoolPtr(false),
		Soc_specific:        proptools.BoolPtr(false),
		Product_specific:    proptools.BoolPtr(true),
		System_ext_specific: proptools.BoolPtr(false),
		Manifest:            proptools.StringPtr(":" + a.Name() + "{.manifest.xml}"),
		Sdk_version:         proptools.StringPtr("current"),
		Compile_multilib:    proptools.StringPtr("first"),
		Enabled:             a.EnabledProperty().Clone(),
	}
	ctx.CreateModule(AutogenRuntimeResourceOverlayFactory, &productOverlayProps)
}

// A dictionary of values to be overridden in the manifest.
type Manifest_values struct {
	// Overrides the value of package_name in the manifest
@@ -1783,10 +1696,6 @@ func OverrideAndroidAppModuleFactory() android.Module {

	android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibCommon)
	android.InitOverrideModule(m)
	android.AddLoadHook(m, func(ctx android.LoadHookContext) {
		createInternalRuntimeOverlays(ctx, m.ModuleBase)
	})

	return m
}

+0 −71
Original line number Diff line number Diff line
@@ -4727,74 +4727,3 @@ func TestResourcesWithFlagDirectories(t *testing.T) {
		"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)
	}
}
Loading