Merge "Add phonies as provider instead of updaing a global map." into main am: ee5b92fd6c

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/3229623

Change-Id: I3a075db80ad7c45067b080a2df8c50fc56b40b64
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yu Liu
2024-08-20 16:02:36 +00:00
committed by Automerger Merge Worker
4 changed files with 26 additions and 6 deletions

View File

@@ -1797,6 +1797,7 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
bp: blueprintCtx,
baseModuleContext: m.baseModuleContextFactory(blueprintCtx),
variables: make(map[string]string),
phonies: make(map[string]Paths),
}
setContainerInfo(ctx)
@@ -2052,6 +2053,11 @@ func (m *ModuleBase) GenerateBuildActions(blueprintCtx blueprint.ModuleContext)
SetProvider(ctx, OutputFilesProvider, m.outputFiles)
}
if len(ctx.phonies) > 0 {
SetProvider(ctx, ModulePhonyProvider, ModulePhonyInfo{
Phonies: ctx.phonies,
})
}
buildComplianceMetadataProvider(ctx, m)
}

View File

@@ -361,7 +361,7 @@ func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
}
func (m *moduleContext) Phony(name string, deps ...Path) {
addPhony(m.config, name, deps...)
m.phonies[name] = append(m.phonies[name], deps...)
}
func (m *moduleContext) GetMissingDependencies() []string {

View File

@@ -26,14 +26,20 @@ type phonyMap map[string]Paths
var phonyMapLock sync.Mutex
func getPhonyMap(config Config) phonyMap {
type ModulePhonyInfo struct {
Phonies map[string]Paths
}
var ModulePhonyProvider = blueprint.NewProvider[ModulePhonyInfo]()
func getSingletonPhonyMap(config Config) phonyMap {
return config.Once(phonyMapOnceKey, func() interface{} {
return make(phonyMap)
}).(phonyMap)
}
func addPhony(config Config, name string, deps ...Path) {
phonyMap := getPhonyMap(config)
func addSingletonPhony(config Config, name string, deps ...Path) {
phonyMap := getSingletonPhonyMap(config)
phonyMapLock.Lock()
defer phonyMapLock.Unlock()
phonyMap[name] = append(phonyMap[name], deps...)
@@ -47,7 +53,15 @@ type phonySingleton struct {
var _ SingletonMakeVarsProvider = (*phonySingleton)(nil)
func (p *phonySingleton) GenerateBuildActions(ctx SingletonContext) {
p.phonyMap = getPhonyMap(ctx.Config())
p.phonyMap = getSingletonPhonyMap(ctx.Config())
ctx.VisitAllModules(func(m Module) {
if info, ok := OtherModuleProvider(ctx, m, ModulePhonyProvider); ok {
for k, v := range info.Phonies {
p.phonyMap[k] = append(p.phonyMap[k], v...)
}
}
})
p.phonyList = SortedKeys(p.phonyMap)
for _, phony := range p.phonyList {
p.phonyMap[phony] = SortedUniquePaths(p.phonyMap[phony])

View File

@@ -177,7 +177,7 @@ func (s *singletonContextAdaptor) Build(pctx PackageContext, params BuildParams)
}
func (s *singletonContextAdaptor) Phony(name string, deps ...Path) {
addPhony(s.Config(), name, deps...)
addSingletonPhony(s.Config(), name, deps...)
}
func (s *singletonContextAdaptor) SetOutDir(pctx PackageContext, value string) {