Merge "Add aconfig flag support for android_library" into main

This commit is contained in:
Treehugger Robot
2024-03-20 01:23:50 +00:00
committed by Gerrit Code Review
3 changed files with 75 additions and 20 deletions

View File

@@ -169,9 +169,6 @@ type overridableAppProperties struct {
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
// from PRODUCT_PACKAGES.
Overrides []string
// Names of aconfig_declarations modules that specify aconfig flags that the app depends on.
Flags_packages []string
}
type AndroidApp struct {
@@ -290,6 +287,10 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
}
a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
for _, aconfig_declaration := range a.aaptProperties.Flags_packages {
ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
}
}
func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutatorContext) {
@@ -317,10 +318,6 @@ func (a *AndroidApp) OverridablePropertiesDepsMutator(ctx android.BottomUpMutato
`must be names of android_app_certificate modules in the form ":module"`)
}
}
for _, aconfig_declaration := range a.overridableAppProperties.Flags_packages {
ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
}
}
func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -457,6 +454,21 @@ func (a *AndroidApp) renameResourcesPackage() bool {
return proptools.BoolDefault(a.overridableAppProperties.Rename_resources_package, true)
}
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(),
)
}
})
return aconfigTextFilePaths
}
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis)
if ctx.Module().(android.SdkContext).SdkVersion(ctx).Kind == android.SdkModule {
@@ -507,18 +519,6 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
a.aapt.defaultManifestVersion = android.DefaultUpdatableModuleVersion
}
var 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(),
)
}
})
a.aapt.buildActions(ctx,
aaptBuildActionOptions{
sdkContext: android.SdkContext(a),
@@ -526,7 +526,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
excludedLibs: a.usesLibraryProperties.Exclude_uses_libs,
enforceDefaultTargetSdkVersion: a.enforceDefaultTargetSdkVersion(),
extraLinkFlags: aaptLinkFlags,
aconfigTextFiles: aconfigTextFilePaths,
aconfigTextFiles: getAconfigFilePaths(ctx),
},
)