Support aapt2 resources flagging
This change modifies the aconfig and aapt2 build rules to support resources flagging in aapt2. Implementation details: - Modify the aconfig text rule to include flag permission in the output text file - Pass the `--flags-packages` argument to `aapt2 compile` command, similar to what is currently being done in the `aapt2 link` command Bug: 344979955 Test: m nothing --no-skip-soong-tests Change-Id: I3b0b1fd6dcd691b7cc50ba3d081ecafd82c2c904
This commit is contained in:
@@ -47,7 +47,7 @@ var (
|
|||||||
// For create-device-config-sysprops: Generate aconfig flag value map text file
|
// For create-device-config-sysprops: Generate aconfig flag value map text file
|
||||||
aconfigTextRule = pctx.AndroidStaticRule("aconfig_text",
|
aconfigTextRule = pctx.AndroidStaticRule("aconfig_text",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `${aconfig} dump-cache --dedup --format='{fully_qualified_name}={state:bool}'` +
|
Command: `${aconfig} dump-cache --dedup --format='{fully_qualified_name}:{permission}={state:bool}'` +
|
||||||
` --cache ${in}` +
|
` --cache ${in}` +
|
||||||
` --out ${out}.tmp` +
|
` --out ${out}.tmp` +
|
||||||
` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
|
` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
|
||||||
|
@@ -69,7 +69,7 @@ var aapt2CompileRule = pctx.AndroidStaticRule("aapt2Compile",
|
|||||||
|
|
||||||
// aapt2Compile compiles resources and puts the results in the requested directory.
|
// aapt2Compile compiles resources and puts the results in the requested directory.
|
||||||
func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Paths,
|
func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Paths,
|
||||||
flags []string, productToFilter string) android.WritablePaths {
|
flags []string, productToFilter string, featureFlagsPaths android.Paths) android.WritablePaths {
|
||||||
if productToFilter != "" && productToFilter != "default" {
|
if productToFilter != "" && productToFilter != "default" {
|
||||||
// --filter-product leaves only product-specific resources. Product-specific resources only exist
|
// --filter-product leaves only product-specific resources. Product-specific resources only exist
|
||||||
// in value resources (values/*.xml), so filter value resource files only. Ignore other types of
|
// in value resources (values/*.xml), so filter value resource files only. Ignore other types of
|
||||||
@@ -85,6 +85,10 @@ func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Pat
|
|||||||
flags = append([]string{"--filter-product " + productToFilter}, flags...)
|
flags = append([]string{"--filter-product " + productToFilter}, flags...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, featureFlagsPath := range android.SortedUniquePaths(featureFlagsPaths) {
|
||||||
|
flags = append(flags, "--feature-flags", "@"+featureFlagsPath.String())
|
||||||
|
}
|
||||||
|
|
||||||
// Shard the input paths so that they can be processed in parallel. If we shard them into too
|
// Shard the input paths so that they can be processed in parallel. If we shard them into too
|
||||||
// small chunks, the additional cost of spinning up aapt2 outweighs the performance gain. The
|
// small chunks, the additional cost of spinning up aapt2 outweighs the performance gain. The
|
||||||
// current shard size, 100, seems to be a good balance between the added cost and the gain.
|
// current shard size, 100, seems to be a good balance between the added cost and the gain.
|
||||||
@@ -112,6 +116,7 @@ func aapt2Compile(ctx android.ModuleContext, dir android.Path, paths android.Pat
|
|||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: aapt2CompileRule,
|
Rule: aapt2CompileRule,
|
||||||
Description: "aapt2 compile " + dir.String() + shardDesc,
|
Description: "aapt2 compile " + dir.String() + shardDesc,
|
||||||
|
Implicits: featureFlagsPaths,
|
||||||
Inputs: shard,
|
Inputs: shard,
|
||||||
Outputs: outPaths,
|
Outputs: outPaths,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
|
@@ -440,7 +440,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
|
|||||||
var compiledResDirs []android.Paths
|
var compiledResDirs []android.Paths
|
||||||
for _, dir := range resDirs {
|
for _, dir := range resDirs {
|
||||||
a.resourceFiles = append(a.resourceFiles, dir.files...)
|
a.resourceFiles = append(a.resourceFiles, dir.files...)
|
||||||
compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths())
|
compiledResDirs = append(compiledResDirs, aapt2Compile(ctx, dir.dir, dir.files,
|
||||||
|
compileFlags, a.filterProduct(), opts.aconfigTextFiles).Paths())
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, zip := range resZips {
|
for i, zip := range resZips {
|
||||||
@@ -499,7 +500,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, dir := range overlayDirs {
|
for _, dir := range overlayDirs {
|
||||||
compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files, compileFlags, a.filterProduct()).Paths()...)
|
compiledOverlay = append(compiledOverlay, aapt2Compile(ctx, dir.dir, dir.files,
|
||||||
|
compileFlags, a.filterProduct(), opts.aconfigTextFiles).Paths()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
var splitPackages android.WritablePaths
|
var splitPackages android.WritablePaths
|
||||||
|
@@ -4364,7 +4364,16 @@ func TestPrivappAllowlistAndroidMk(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppFlagsPackages(t *testing.T) {
|
func TestAppFlagsPackages(t *testing.T) {
|
||||||
ctx := testApp(t, `
|
ctx := android.GroupFixturePreparers(
|
||||||
|
prepareForJavaTest,
|
||||||
|
android.FixtureMergeMockFs(
|
||||||
|
map[string][]byte{
|
||||||
|
"res/layout/layout.xml": nil,
|
||||||
|
"res/values/strings.xml": nil,
|
||||||
|
"res/values-en-rUS/strings.xml": nil,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
).RunTestWithBp(t, `
|
||||||
android_app {
|
android_app {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
@@ -4396,10 +4405,10 @@ func TestAppFlagsPackages(t *testing.T) {
|
|||||||
|
|
||||||
// android_app module depends on aconfig_declarations listed in flags_packages
|
// android_app module depends on aconfig_declarations listed in flags_packages
|
||||||
android.AssertBoolEquals(t, "foo expected to depend on bar", true,
|
android.AssertBoolEquals(t, "foo expected to depend on bar", true,
|
||||||
CheckModuleHasDependency(t, ctx, "foo", "android_common", "bar"))
|
CheckModuleHasDependency(t, ctx.TestContext, "foo", "android_common", "bar"))
|
||||||
|
|
||||||
android.AssertBoolEquals(t, "foo expected to depend on baz", true,
|
android.AssertBoolEquals(t, "foo expected to depend on baz", true,
|
||||||
CheckModuleHasDependency(t, ctx, "foo", "android_common", "baz"))
|
CheckModuleHasDependency(t, ctx.TestContext, "foo", "android_common", "baz"))
|
||||||
|
|
||||||
aapt2LinkRule := foo.Rule("android/soong/java.aapt2Link")
|
aapt2LinkRule := foo.Rule("android/soong/java.aapt2Link")
|
||||||
linkInFlags := aapt2LinkRule.Args["inFlags"]
|
linkInFlags := aapt2LinkRule.Args["inFlags"]
|
||||||
@@ -4408,6 +4417,14 @@ func TestAppFlagsPackages(t *testing.T) {
|
|||||||
linkInFlags,
|
linkInFlags,
|
||||||
"--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt",
|
"--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
aapt2CompileRule := foo.Rule("android/soong/java.aapt2Compile")
|
||||||
|
compileFlags := aapt2CompileRule.Args["cFlags"]
|
||||||
|
android.AssertStringDoesContain(t,
|
||||||
|
"aapt2 compile command expected to pass feature flags arguments",
|
||||||
|
compileFlags,
|
||||||
|
"--feature-flags @out/soong/.intermediates/bar/intermediate.txt --feature-flags @out/soong/.intermediates/baz/intermediate.txt",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppFlagsPackagesPropagation(t *testing.T) {
|
func TestAppFlagsPackagesPropagation(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user