Propagate flags_packages to static reverse dependencies
flags_packages property was added to supports flagging the manifest files. The listed names of `aconfig_declarations` modules are passed to aapt2. However, this is currently scoped to the module level, and is not propagated to the reverse dependencies. In other words, if the manifest is flagged with `featureFlag` property, all of the reverse dependency of the android_app/android_library should specify `flags_packages` property in the bp module definition, leading to huge toil for the users. In order to resolve such inconvenience, this change modifies the build rules of android_app,android_library and runtime_resource_overlay such that flags_packages of the static dependencies are collected. Test: Patch ag/27816261 && m Settings --no-skip-soong-tests Bug: 347289274 Change-Id: I4c3855541dd09cb72293515eb2626eaf4ae8c0df
This commit is contained in:
43
java/app.go
43
java/app.go
@@ -47,6 +47,13 @@ var (
|
||||
}, "packageName")
|
||||
)
|
||||
|
||||
type FlagsPackages struct {
|
||||
// Paths to the aconfig dump output text files that are consumed by aapt2
|
||||
AconfigTextFiles android.Paths
|
||||
}
|
||||
|
||||
var FlagsPackagesProvider = blueprint.NewProvider[FlagsPackages]()
|
||||
|
||||
func RegisterAppBuildComponents(ctx android.RegistrationContext) {
|
||||
ctx.RegisterModuleType("android_app", AndroidAppFactory)
|
||||
ctx.RegisterModuleType("android_test", AndroidTestFactory)
|
||||
@@ -478,18 +485,27 @@ func (a *AndroidApp) renameResourcesPackage() bool {
|
||||
}
|
||||
|
||||
func getAconfigFilePaths(ctx android.ModuleContext) (aconfigTextFilePaths android.Paths) {
|
||||
ctx.VisitDirectDepsWithTag(aconfigDeclarationTag, func(dep android.Module) {
|
||||
if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok {
|
||||
aconfigTextFilePaths = append(aconfigTextFilePaths, provider.IntermediateDumpOutputPath)
|
||||
} else {
|
||||
ctx.ModuleErrorf("Only aconfig_declarations module type is allowed for "+
|
||||
"flags_packages property, but %s is not aconfig_declarations module type",
|
||||
dep.Name(),
|
||||
)
|
||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||
tag := ctx.OtherModuleDependencyTag(dep)
|
||||
switch tag {
|
||||
case staticLibTag:
|
||||
if flagPackages, ok := android.OtherModuleProvider(ctx, dep, FlagsPackagesProvider); ok {
|
||||
aconfigTextFilePaths = append(aconfigTextFilePaths, flagPackages.AconfigTextFiles...)
|
||||
}
|
||||
|
||||
case aconfigDeclarationTag:
|
||||
if provider, ok := android.OtherModuleProvider(ctx, dep, android.AconfigDeclarationsProviderKey); ok {
|
||||
aconfigTextFilePaths = append(aconfigTextFilePaths, provider.IntermediateDumpOutputPath)
|
||||
} else {
|
||||
ctx.ModuleErrorf("Only aconfig_declarations module type is allowed for "+
|
||||
"flags_packages property, but %s is not aconfig_declarations module type",
|
||||
dep.Name(),
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return aconfigTextFilePaths
|
||||
return android.FirstUniquePaths(aconfigTextFilePaths)
|
||||
}
|
||||
|
||||
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
||||
@@ -544,6 +560,9 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
||||
|
||||
// Use non final ids if we are doing optimized shrinking and are using R8.
|
||||
nonFinalIds := a.dexProperties.optimizedResourceShrinkingEnabled(ctx) && a.dexer.effectiveOptimizeEnabled()
|
||||
|
||||
aconfigTextFilePaths := getAconfigFilePaths(ctx)
|
||||
|
||||
a.aapt.buildActions(ctx,
|
||||
aaptBuildActionOptions{
|
||||
sdkContext: android.SdkContext(a),
|
||||
@@ -552,13 +571,17 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
||||
enforceDefaultTargetSdkVersion: a.enforceDefaultTargetSdkVersion(),
|
||||
forceNonFinalResourceIDs: nonFinalIds,
|
||||
extraLinkFlags: aaptLinkFlags,
|
||||
aconfigTextFiles: getAconfigFilePaths(ctx),
|
||||
aconfigTextFiles: aconfigTextFilePaths,
|
||||
usesLibrary: &a.usesLibrary,
|
||||
},
|
||||
)
|
||||
|
||||
// apps manifests are handled by aapt, don't let Module see them
|
||||
a.properties.Manifest = nil
|
||||
|
||||
android.SetProvider(ctx, FlagsPackagesProvider, FlagsPackages{
|
||||
AconfigTextFiles: aconfigTextFilePaths,
|
||||
})
|
||||
}
|
||||
|
||||
func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) {
|
||||
|
Reference in New Issue
Block a user