diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go index 14438c82f..b55d7bf5c 100644 --- a/aconfig/aconfig_declarations.go +++ b/aconfig/aconfig_declarations.go @@ -112,24 +112,6 @@ func optionalVariable(prefix string, value string) string { return sb.String() } -// Provider published by aconfig_value_set -type DeclarationsProviderData struct { - Package string - Container string - IntermediateCacheOutputPath android.WritablePath - IntermediateDumpOutputPath android.WritablePath -} - -var DeclarationsProviderKey = blueprint.NewProvider[DeclarationsProviderData]() - -// This is used to collect the aconfig declarations info on the transitive closure, -// the data is keyed on the container. -type TransitiveDeclarationsInfo struct { - AconfigFiles map[string]android.Paths -} - -var TransitiveDeclarationsInfoProvider = blueprint.NewProvider[TransitiveDeclarationsInfo]() - func (module *DeclarationsModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag valuesFiles := make([]android.Path, 0) @@ -174,7 +156,7 @@ func (module *DeclarationsModule) GenerateAndroidBuildActions(ctx android.Module Description: "aconfig_text", }) - android.SetProvider(ctx, DeclarationsProviderKey, DeclarationsProviderData{ + android.SetProvider(ctx, android.AconfigDeclarationsProviderKey, android.AconfigDeclarationsProviderData{ Package: module.properties.Package, Container: module.properties.Container, IntermediateCacheOutputPath: intermediateCacheFilePath, @@ -182,51 +164,6 @@ func (module *DeclarationsModule) GenerateAndroidBuildActions(ctx android.Module }) } -func CollectDependencyAconfigFiles(ctx android.ModuleContext, mergedAconfigFiles *map[string]android.Paths) { - if *mergedAconfigFiles == nil { - *mergedAconfigFiles = make(map[string]android.Paths) - } - ctx.VisitDirectDeps(func(module android.Module) { - if dep, _ := android.OtherModuleProvider(ctx, module, DeclarationsProviderKey); dep.IntermediateCacheOutputPath != nil { - (*mergedAconfigFiles)[dep.Container] = append((*mergedAconfigFiles)[dep.Container], dep.IntermediateCacheOutputPath) - return - } - if dep, _ := android.OtherModuleProvider(ctx, module, TransitiveDeclarationsInfoProvider); len(dep.AconfigFiles) > 0 { - for container, v := range dep.AconfigFiles { - (*mergedAconfigFiles)[container] = append((*mergedAconfigFiles)[container], v...) - } - } - }) - - for container, aconfigFiles := range *mergedAconfigFiles { - (*mergedAconfigFiles)[container] = mergeAconfigFiles(ctx, aconfigFiles) - } - - android.SetProvider(ctx, TransitiveDeclarationsInfoProvider, TransitiveDeclarationsInfo{ - AconfigFiles: *mergedAconfigFiles, - }) -} - -func mergeAconfigFiles(ctx android.ModuleContext, inputs android.Paths) android.Paths { - inputs = android.LastUniquePaths(inputs) - if len(inputs) == 1 { - return android.Paths{inputs[0]} - } - - output := android.PathForModuleOut(ctx, "aconfig_merged.pb") - - ctx.Build(pctx, android.BuildParams{ - Rule: mergeAconfigFilesRule, - Description: "merge aconfig files", - Inputs: inputs, - Output: output, - Args: map[string]string{ - "flags": android.JoinWithPrefix(inputs.Strings(), "--cache "), - }, - }) - - return android.Paths{output} -} func SetAconfigFileMkEntries(m *android.ModuleBase, entries *android.AndroidMkEntries, aconfigFiles map[string]android.Paths) { // TODO(b/311155208): The default container here should be system. diff --git a/aconfig/aconfig_declarations_test.go b/aconfig/aconfig_declarations_test.go index 1b4acabeb..d508af7a4 100644 --- a/aconfig/aconfig_declarations_test.go +++ b/aconfig/aconfig_declarations_test.go @@ -38,7 +38,7 @@ func TestAconfigDeclarations(t *testing.T) { module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule) // Check that the provider has the right contents - depData, _ := android.SingletonModuleProvider(result, module, DeclarationsProviderKey) + depData, _ := android.SingletonModuleProvider(result, module, android.AconfigDeclarationsProviderKey) android.AssertStringEquals(t, "package", depData.Package, "com.example.package") android.AssertStringEquals(t, "container", depData.Container, "com.android.foo") if !strings.HasSuffix(depData.IntermediateCacheOutputPath.String(), "/intermediate.pb") { diff --git a/aconfig/all_aconfig_declarations.go b/aconfig/all_aconfig_declarations.go index d8604985b..36bea0e3f 100644 --- a/aconfig/all_aconfig_declarations.go +++ b/aconfig/all_aconfig_declarations.go @@ -37,7 +37,7 @@ func (this *allAconfigDeclarationsSingleton) GenerateBuildActions(ctx android.Si // Find all of the aconfig_declarations modules var cacheFiles android.Paths ctx.VisitAllModules(func(module android.Module) { - decl, ok := android.SingletonModuleProvider(ctx, module, DeclarationsProviderKey) + decl, ok := android.SingletonModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey) if !ok { return } diff --git a/aconfig/codegen/cc_aconfig_library.go b/aconfig/codegen/cc_aconfig_library.go index 2c8369be0..12c2dea3a 100644 --- a/aconfig/codegen/cc_aconfig_library.go +++ b/aconfig/codegen/cc_aconfig_library.go @@ -15,7 +15,6 @@ package codegen import ( - "android/soong/aconfig" "android/soong/android" "android/soong/cc" @@ -92,7 +91,7 @@ func (this *CcAconfigLibraryCallbacks) GeneratorSources(ctx cc.ModuleContext) cc if len(declarationsModules) != 1 { panic(fmt.Errorf("Exactly one aconfig_declarations property required")) } - declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], aconfig.DeclarationsProviderKey) + declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], android.AconfigDeclarationsProviderKey) // Figure out the generated file paths. This has to match aconfig's codegen_cpp.rs. this.generatedDir = android.PathForModuleGen(ctx) @@ -122,7 +121,7 @@ func (this *CcAconfigLibraryCallbacks) GeneratorBuildActions(ctx cc.ModuleContex if len(declarationsModules) != 1 { panic(fmt.Errorf("Exactly one aconfig_declarations property required")) } - declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], aconfig.DeclarationsProviderKey) + declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], android.AconfigDeclarationsProviderKey) mode := proptools.StringDefault(this.properties.Mode, "production") if !isModeSupported(mode) { diff --git a/aconfig/codegen/java_aconfig_library.go b/aconfig/codegen/java_aconfig_library.go index a888957dc..c027815db 100644 --- a/aconfig/codegen/java_aconfig_library.go +++ b/aconfig/codegen/java_aconfig_library.go @@ -17,7 +17,6 @@ package codegen import ( "fmt" - "android/soong/aconfig" "android/soong/android" "android/soong/java" @@ -82,7 +81,7 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuild if len(declarationsModules) != 1 { panic(fmt.Errorf("Exactly one aconfig_declarations property required")) } - declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], aconfig.DeclarationsProviderKey) + declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], android.AconfigDeclarationsProviderKey) // Generate the action to build the srcjar srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar") diff --git a/aconfig/codegen/rust_aconfig_library.go b/aconfig/codegen/rust_aconfig_library.go index 88f5b452c..73b6fece2 100644 --- a/aconfig/codegen/rust_aconfig_library.go +++ b/aconfig/codegen/rust_aconfig_library.go @@ -3,7 +3,6 @@ package codegen import ( "fmt" - "android/soong/aconfig" "android/soong/android" "android/soong/rust" @@ -65,7 +64,7 @@ func (a *aconfigDecorator) GenerateSource(ctx rust.ModuleContext, deps rust.Path if len(declarationsModules) != 1 { panic(fmt.Errorf("Exactly one aconfig_declarations property required")) } - declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], aconfig.DeclarationsProviderKey) + declarations, _ := android.OtherModuleProvider(ctx, declarationsModules[0], android.AconfigDeclarationsProviderKey) mode := proptools.StringDefault(a.Properties.Mode, "production") if !isModeSupported(mode) { diff --git a/aconfig/exported_java_aconfig_library.go b/aconfig/exported_java_aconfig_library.go index 864481065..291938fa8 100644 --- a/aconfig/exported_java_aconfig_library.go +++ b/aconfig/exported_java_aconfig_library.go @@ -30,7 +30,7 @@ func (this *exportedJavaDeclarationsLibrarySingleton) GenerateBuildActions(ctx a // Find all of the aconfig_declarations modules var cacheFiles android.Paths ctx.VisitAllModules(func(module android.Module) { - decl, ok := android.SingletonModuleProvider(ctx, module, DeclarationsProviderKey) + decl, ok := android.SingletonModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey) if !ok { return } diff --git a/aconfig/init.go b/aconfig/init.go index c1b923b82..04176ec86 100644 --- a/aconfig/init.go +++ b/aconfig/init.go @@ -62,11 +62,6 @@ var ( }, }, "cache_files") - mergeAconfigFilesRule = pctx.AndroidStaticRule("mergeAconfigFilesRule", - blueprint.RuleParams{ - Command: `${aconfig} dump --dedup --format protobuf --out $out $flags`, - CommandDeps: []string{"${aconfig}"}, - }, "flags") // For exported_java_aconfig_library: Generate a JAR from all // java_aconfig_libraries to be consumed by apps built outside the // platform diff --git a/android/Android.bp b/android/Android.bp index 26317b8e4..b359df9dd 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -27,6 +27,7 @@ bootstrap_go_package { "androidmk-parser", ], srcs: [ + "aconfig_providers.go", "androidmk.go", "apex.go", "apex_contributions.go", diff --git a/android/aconfig_providers.go b/android/aconfig_providers.go new file mode 100644 index 000000000..ddebec343 --- /dev/null +++ b/android/aconfig_providers.go @@ -0,0 +1,92 @@ +// Copyright 2023 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package android + +import ( + "github.com/google/blueprint" +) + +var ( + mergeAconfigFilesRule = pctx.AndroidStaticRule("mergeAconfigFilesRule", + blueprint.RuleParams{ + Command: `${aconfig} dump --dedup --format protobuf --out $out $flags`, + CommandDeps: []string{"${aconfig}"}, + }, "flags") + _ = pctx.HostBinToolVariable("aconfig", "aconfig") +) + +// Provider published by aconfig_value_set +type AconfigDeclarationsProviderData struct { + Package string + Container string + IntermediateCacheOutputPath WritablePath + IntermediateDumpOutputPath WritablePath +} + +var AconfigDeclarationsProviderKey = blueprint.NewProvider[AconfigDeclarationsProviderData]() + +// This is used to collect the aconfig declarations info on the transitive closure, +// the data is keyed on the container. +type AconfigTransitiveDeclarationsInfo struct { + AconfigFiles map[string]Paths +} + +var AconfigTransitiveDeclarationsInfoProvider = blueprint.NewProvider[AconfigTransitiveDeclarationsInfo]() + +func CollectDependencyAconfigFiles(ctx ModuleContext, mergedAconfigFiles *map[string]Paths) { + if *mergedAconfigFiles == nil { + *mergedAconfigFiles = make(map[string]Paths) + } + ctx.VisitDirectDeps(func(module Module) { + if dep, _ := OtherModuleProvider(ctx, module, AconfigDeclarationsProviderKey); dep.IntermediateCacheOutputPath != nil { + (*mergedAconfigFiles)[dep.Container] = append((*mergedAconfigFiles)[dep.Container], dep.IntermediateCacheOutputPath) + return + } + if dep, _ := OtherModuleProvider(ctx, module, AconfigTransitiveDeclarationsInfoProvider); len(dep.AconfigFiles) > 0 { + for container, v := range dep.AconfigFiles { + (*mergedAconfigFiles)[container] = append((*mergedAconfigFiles)[container], v...) + } + } + }) + + for container, aconfigFiles := range *mergedAconfigFiles { + (*mergedAconfigFiles)[container] = mergeAconfigFiles(ctx, aconfigFiles) + } + + SetProvider(ctx, AconfigTransitiveDeclarationsInfoProvider, AconfigTransitiveDeclarationsInfo{ + AconfigFiles: *mergedAconfigFiles, + }) +} + +func mergeAconfigFiles(ctx ModuleContext, inputs Paths) Paths { + inputs = LastUniquePaths(inputs) + if len(inputs) == 1 { + return Paths{inputs[0]} + } + + output := PathForModuleOut(ctx, "aconfig_merged.pb") + + ctx.Build(pctx, BuildParams{ + Rule: mergeAconfigFilesRule, + Description: "merge aconfig files", + Inputs: inputs, + Output: output, + Args: map[string]string{ + "flags": JoinWithPrefix(inputs.Strings(), "--cache "), + }, + }) + + return Paths{output} +} diff --git a/apex/apex.go b/apex/apex.go index 56559b16b..fe3f5a8e1 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -24,7 +24,6 @@ import ( "sort" "strings" - "android/soong/aconfig" "github.com/google/blueprint" "github.com/google/blueprint/proptools" @@ -2272,7 +2271,7 @@ func (a *apexBundle) depVisitor(vctx *visitorContext, ctx android.ModuleContext, } func addAconfigFiles(vctx *visitorContext, ctx android.ModuleContext, module blueprint.Module) { - dep, _ := android.OtherModuleProvider(ctx, module, aconfig.TransitiveDeclarationsInfoProvider) + dep, _ := android.OtherModuleProvider(ctx, module, android.AconfigTransitiveDeclarationsInfoProvider) if len(dep.AconfigFiles) > 0 && dep.AconfigFiles[ctx.ModuleName()] != nil { vctx.aconfigFiles = append(vctx.aconfigFiles, dep.AconfigFiles[ctx.ModuleName()]...) } diff --git a/cc/cc.go b/cc/cc.go index e6b9d8b6a..9f32c4477 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -28,7 +28,6 @@ import ( "github.com/google/blueprint" "github.com/google/blueprint/proptools" - "android/soong/aconfig" "android/soong/aidl_library" "android/soong/android" "android/soong/cc/config" @@ -2137,7 +2136,7 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { } android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: deps.GeneratedSources.Strings()}) - aconfig.CollectDependencyAconfigFiles(ctx, &c.mergedAconfigFiles) + android.CollectDependencyAconfigFiles(ctx, &c.mergedAconfigFiles) c.maybeInstall(ctx, apexInfo) } diff --git a/java/app.go b/java/app.go index 7f0303a6b..8b28dac78 100755 --- a/java/app.go +++ b/java/app.go @@ -22,7 +22,6 @@ import ( "path/filepath" "strings" - "android/soong/aconfig" "android/soong/testing" "github.com/google/blueprint" @@ -509,7 +508,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) { var aconfigTextFilePaths android.Paths ctx.VisitDirectDepsWithTag(aconfigDeclarationTag, func(dep android.Module) { - if provider, ok := android.OtherModuleProvider(ctx, dep, aconfig.DeclarationsProviderKey); ok { + 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 "+ diff --git a/java/base.go b/java/base.go index 41f2fcc96..0d3e4dbe3 100644 --- a/java/base.go +++ b/java/base.go @@ -24,7 +24,6 @@ import ( "github.com/google/blueprint/pathtools" "github.com/google/blueprint/proptools" - "android/soong/aconfig" "android/soong/android" "android/soong/dexpreopt" "android/soong/java/config" @@ -1694,7 +1693,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath ctx.CheckbuildFile(outputFile) - aconfig.CollectDependencyAconfigFiles(ctx, &j.mergedAconfigFiles) + android.CollectDependencyAconfigFiles(ctx, &j.mergedAconfigFiles) android.SetProvider(ctx, JavaInfoProvider, JavaInfo{ HeaderJars: android.PathsIfNonNil(j.headerJarFile), diff --git a/rust/rust.go b/rust/rust.go index 521f624a2..6f4631de7 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -23,7 +23,6 @@ import ( "github.com/google/blueprint" "github.com/google/blueprint/proptools" - "android/soong/aconfig" "android/soong/android" "android/soong/cc" cc_config "android/soong/cc/config" @@ -1007,7 +1006,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{}) } - aconfig.CollectDependencyAconfigFiles(ctx, &mod.mergedAconfigFiles) + android.CollectDependencyAconfigFiles(ctx, &mod.mergedAconfigFiles) } func (mod *Module) deps(ctx DepsContext) Deps {