Add aconfig flag support for android_library
This change adds the support that was added to android_app in https://r.android.com/2854663 for android_library modules. Implementation details: - Move `Flags_packages` to aaptProperties, so that it can be utilized for both android_app and android_library. - Wrap `VisitDirectDeps` of aconfig_declarations to a function that takes a ModuleContext as an input, so that it can be utilized in the `GenerateAndroidBuildActions` of both android_app and android_library. Test: m nothing --no-skip-soong-tests Bug: 330222981 Change-Id: I8a755f5ca615c8a1651afcd2ec441fc9fbd82c61
This commit is contained in:
@@ -104,6 +104,9 @@ type aaptProperties struct {
|
|||||||
|
|
||||||
// Filter only specified product and ignore other products
|
// Filter only specified product and ignore other products
|
||||||
Filter_product *string `blueprint:"mutated"`
|
Filter_product *string `blueprint:"mutated"`
|
||||||
|
|
||||||
|
// Names of aconfig_declarations modules that specify aconfig flags that the module depends on.
|
||||||
|
Flags_packages []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type aapt struct {
|
type aapt struct {
|
||||||
@@ -804,6 +807,10 @@ func (a *AndroidLibrary) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
a.aapt.deps(ctx, sdkDep)
|
a.aapt.deps(ctx, sdkDep)
|
||||||
}
|
}
|
||||||
a.usesLibrary.deps(ctx, false)
|
a.usesLibrary.deps(ctx, false)
|
||||||
|
|
||||||
|
for _, aconfig_declaration := range a.aaptProperties.Flags_packages {
|
||||||
|
ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||||
@@ -817,6 +824,7 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
|
|||||||
sdkContext: android.SdkContext(a),
|
sdkContext: android.SdkContext(a),
|
||||||
classLoaderContexts: a.classLoaderContexts,
|
classLoaderContexts: a.classLoaderContexts,
|
||||||
enforceDefaultTargetSdkVersion: false,
|
enforceDefaultTargetSdkVersion: false,
|
||||||
|
aconfigTextFiles: getAconfigFilePaths(ctx),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -81,3 +81,50 @@ func TestAarImportProducesJniPackages(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLibraryFlagsPackages(t *testing.T) {
|
||||||
|
result := android.GroupFixturePreparers(
|
||||||
|
prepareForJavaTest,
|
||||||
|
).RunTestWithBp(t, `
|
||||||
|
android_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
sdk_version: "current",
|
||||||
|
flags_packages: [
|
||||||
|
"bar",
|
||||||
|
"baz",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
aconfig_declarations {
|
||||||
|
name: "bar",
|
||||||
|
package: "com.example.package.bar",
|
||||||
|
srcs: [
|
||||||
|
"bar.aconfig",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
aconfig_declarations {
|
||||||
|
name: "baz",
|
||||||
|
package: "com.example.package.baz",
|
||||||
|
srcs: [
|
||||||
|
"baz.aconfig",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
|
||||||
|
foo := result.ModuleForTests("foo", "android_common")
|
||||||
|
|
||||||
|
// android_library module depends on aconfig_declarations listed in flags_packages
|
||||||
|
android.AssertBoolEquals(t, "foo expected to depend on bar", true,
|
||||||
|
CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "bar"))
|
||||||
|
|
||||||
|
android.AssertBoolEquals(t, "foo expected to depend on baz", true,
|
||||||
|
CheckModuleHasDependency(t, result.TestContext, "foo", "android_common", "baz"))
|
||||||
|
|
||||||
|
aapt2LinkRule := foo.Rule("android/soong/java.aapt2Link")
|
||||||
|
linkInFlags := aapt2LinkRule.Args["inFlags"]
|
||||||
|
android.AssertStringDoesContain(t,
|
||||||
|
"aapt2 link command expected to pass feature flags arguments",
|
||||||
|
linkInFlags,
|
||||||
|
"--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
40
java/app.go
40
java/app.go
@@ -169,9 +169,6 @@ type overridableAppProperties struct {
|
|||||||
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
|
// binaries would be installed by default (in PRODUCT_PACKAGES) the other binary will be removed
|
||||||
// from PRODUCT_PACKAGES.
|
// from PRODUCT_PACKAGES.
|
||||||
Overrides []string
|
Overrides []string
|
||||||
|
|
||||||
// Names of aconfig_declarations modules that specify aconfig flags that the app depends on.
|
|
||||||
Flags_packages []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AndroidApp struct {
|
type AndroidApp struct {
|
||||||
@@ -290,6 +287,10 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
|
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) {
|
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"`)
|
`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) {
|
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)
|
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) {
|
func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
||||||
usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis)
|
usePlatformAPI := proptools.Bool(a.Module.deviceProperties.Platform_apis)
|
||||||
if ctx.Module().(android.SdkContext).SdkVersion(ctx).Kind == android.SdkModule {
|
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
|
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,
|
a.aapt.buildActions(ctx,
|
||||||
aaptBuildActionOptions{
|
aaptBuildActionOptions{
|
||||||
sdkContext: android.SdkContext(a),
|
sdkContext: android.SdkContext(a),
|
||||||
@@ -526,7 +526,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
|||||||
excludedLibs: a.usesLibraryProperties.Exclude_uses_libs,
|
excludedLibs: a.usesLibraryProperties.Exclude_uses_libs,
|
||||||
enforceDefaultTargetSdkVersion: a.enforceDefaultTargetSdkVersion(),
|
enforceDefaultTargetSdkVersion: a.enforceDefaultTargetSdkVersion(),
|
||||||
extraLinkFlags: aaptLinkFlags,
|
extraLinkFlags: aaptLinkFlags,
|
||||||
aconfigTextFiles: aconfigTextFilePaths,
|
aconfigTextFiles: getAconfigFilePaths(ctx),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user