Find subdir aconfig_values from srcs

This change supports adding dependencies from the aconfig_value_set
module to the aconfig_values modules from `srcs`, which are the
paths to the Android.bp files where the aconfig_value modules are
defined.

Test: m nothing --no-skip-soong-tests
Bug: 365827715
Change-Id: Idd5f1d9c2625a6362dbaf3adba0a74406e3a9928
This commit is contained in:
Jihoon Kang
2024-09-12 22:28:32 +00:00
parent c379ea0fd4
commit 4fbee9af0b
2 changed files with 145 additions and 0 deletions

View File

@@ -16,6 +16,9 @@ package aconfig
import (
"android/soong/android"
"fmt"
"strings"
"github.com/google/blueprint"
)
@@ -27,6 +30,9 @@ type ValueSetModule struct {
properties struct {
// aconfig_values modules
Values []string
// Paths to the Android.bp files where the aconfig_values modules are defined.
Srcs []string
}
}
@@ -56,7 +62,35 @@ type valueSetProviderData struct {
var valueSetProviderKey = blueprint.NewProvider[valueSetProviderData]()
func (module *ValueSetModule) FindAconfigValuesFromSrc(ctx android.BottomUpMutatorContext) map[string]android.Path {
moduleDir := ctx.ModuleDir()
srcs := android.PathsForModuleSrcExcludes(ctx, module.properties.Srcs, []string{ctx.BlueprintsFile()})
aconfigValuesPrefix := strings.Replace(module.Name(), "aconfig_value_set", "aconfig-values", 1)
moduleNamesSrcMap := make(map[string]android.Path)
for _, src := range srcs {
subDir := strings.TrimPrefix(src.String(), moduleDir+"/")
packageName, _, found := strings.Cut(subDir, "/")
if found {
moduleName := fmt.Sprintf("%s-%s-all", aconfigValuesPrefix, packageName)
moduleNamesSrcMap[moduleName] = src
}
}
return moduleNamesSrcMap
}
func (module *ValueSetModule) DepsMutator(ctx android.BottomUpMutatorContext) {
// TODO: b/366285733 - Replace the file path based solution with more robust solution.
aconfigValuesMap := module.FindAconfigValuesFromSrc(ctx)
for _, moduleName := range android.SortedKeys(aconfigValuesMap) {
if ctx.OtherModuleExists(moduleName) {
ctx.AddDependency(ctx.Module(), valueSetTag, moduleName)
} else {
ctx.ModuleErrorf("module %q not found. Rename the aconfig_values module defined in %q to %q", moduleName, aconfigValuesMap[moduleName], moduleName)
}
}
deps := ctx.AddDependency(ctx.Module(), valueSetTag, module.properties.Values...)
for _, dep := range deps {
_, ok := dep.(*ValuesModule)