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:
Jihoon Kang
2024-03-19 21:57:36 +00:00
parent f11f786571
commit 9049c2725a
3 changed files with 75 additions and 20 deletions

View File

@@ -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",
)
}