move CollectDependencyAconfigFiles to android

This needs to be called by some modules in android.

Bug: 308625757
Test: manual
Change-Id: I389fcfd88a3f4bd85a9218fdd4dd66d8a239bb67
This commit is contained in:
LaMont Jones
2023-12-19 19:01:57 +00:00
parent 349ef87505
commit aa005ae080
15 changed files with 106 additions and 89 deletions

View File

@@ -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.

View File

@@ -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") {

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -17,7 +17,6 @@ package codegen
import (
"fmt"
"android/soong/aconfig"
"android/soong/android"
"android/soong/java"
@@ -74,7 +73,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")

View File

@@ -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) {

View File

@@ -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
}

View File

@@ -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