Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 54513622 authored by Yu Liu's avatar Yu Liu
Browse files

Add phonies as provider instead of updaing a global map.

Bug: 358425833
Test: Manually compare the generated mk and ninja files.
Change-Id: Ie74b620fc680ca2fc0d7836e88361ab3bdb87c49
parent 67478b34
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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)
}

+1 −1
Original line number Diff line number Diff line
@@ -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 {
+18 −4
Original line number Diff line number Diff line
@@ -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])
+1 −1
Original line number Diff line number Diff line
@@ -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) {