Add aconfig flag support for android_app

This change adds an overrideable property flags_packages to android_app,
which is used to list the aconfig_declarations module names that the app
depends on. The build action of android_app is modified to pass all
flags text file provided by the aconfig_declarations to aapt2 link as
--feature-flags arguments.

Test: m nothing --no-skip-soong-tests
Bug: 306024510
Change-Id: I4924f88b9954950cc1936a472cd7ac70f41add5d
This commit is contained in:
Jihoon Kang
2023-12-01 22:01:06 +00:00
parent cca3e0c4b5
commit 84b2589e6d
6 changed files with 88 additions and 8 deletions

View File

@@ -4333,3 +4333,48 @@ func TestApexGlobalMinSdkVersionOverride(t *testing.T) {
)
}
func TestAppFlagsPackages(t *testing.T) {
ctx := testApp(t, `
android_app {
name: "foo",
srcs: ["a.java"],
sdk_version: "current",
flags_packages: [
"bar",
"baz",
],
}
aconfig_declarations {
name: "bar",
package: "com.example.package",
srcs: [
"bar.aconfig",
],
}
aconfig_declarations {
name: "baz",
package: "com.example.package",
srcs: [
"baz.aconfig",
],
}
`)
foo := ctx.ModuleForTests("foo", "android_common")
// android_app module depends on aconfig_declarations listed in flags_packages
android.AssertBoolEquals(t, "foo expected to depend on bar", true,
CheckModuleHasDependency(t, ctx, "foo", "android_common", "bar"))
android.AssertBoolEquals(t, "foo expected to depend on baz", true,
CheckModuleHasDependency(t, ctx, "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",
)
}