Make VisitAllModuleVariants, PrimaryModule and FinalModule available to mutators

Move the VisitAllModuleVariants, PrimaryModule and FinalModule methods to
baseModuleContext so they can be used by mutators.

Test: m checkbuild
Change-Id: I1827ce2fc75f017460a7f6a53b1dab6a81109435
This commit is contained in:
Colin Cross 2020-09-03 12:34:49 -07:00
parent bc973ffe1e
commit 18926521dc

View file

@ -246,6 +246,24 @@ type BaseModuleContext interface {
// invalidated by future mutators.
WalkDeps(visit func(Module, Module) bool)
// PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
// Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
// only done once for all variants of a module.
PrimaryModule() Module
// FinalModule returns the last variant of the current module. Variants of a module are always visited in
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
// variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
// singleton actions that are only done once for all variants of a module.
FinalModule() Module
// VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
// visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
// from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
// data modified by the current mutator.
VisitAllModuleVariants(visit func(Module))
// OtherModuleName returns the name of another Module. See BaseModuleContext.ModuleName for more information.
// It is intended for use inside the visit functions of Visit* and WalkDeps.
OtherModuleName(m Module) string
@ -309,24 +327,6 @@ type ModuleContext interface {
// Build creates a new ninja build statement.
Build(pctx PackageContext, params BuildParams)
// PrimaryModule returns the first variant of the current module. Variants of a module are always visited in
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from the
// Module returned by PrimaryModule without data races. This can be used to perform singleton actions that are
// only done once for all variants of a module.
PrimaryModule() Module
// FinalModule returns the last variant of the current module. Variants of a module are always visited in
// order by mutators and GenerateBuildActions, so the data created by the current mutator can be read from all
// variants using VisitAllModuleVariants if the current module == FinalModule(). This can be used to perform
// singleton actions that are only done once for all variants of a module.
FinalModule() Module
// VisitAllModuleVariants calls visit for each variant of the current module. Variants of a module are always
// visited in order by mutators and GenerateBuildActions, so the data created by the current mutator can be read
// from all variants if the current module == FinalModule(). Otherwise, care must be taken to not access any
// data modified by the current mutator.
VisitAllModuleVariants(visit func(Module))
// GetMissingDependencies returns the list of dependencies that were passed to AddDependencies or related methods,
// but do not exist. It can be used with Context.SetAllowMissingDependencies to allow the primary builder to
// handle missing dependencies on its own instead of having Blueprint treat them as an error.
@ -642,6 +642,18 @@ func (m *baseModuleContext) WalkDeps(visit func(child, parent Module) bool) {
m.visitingDep = depInfo{}
}
func (m *baseModuleContext) PrimaryModule() Module {
return m.module.group.modules[0].logicModule
}
func (m *baseModuleContext) FinalModule() Module {
return m.module.group.modules[len(m.module.group.modules)-1].logicModule
}
func (m *baseModuleContext) VisitAllModuleVariants(visit func(Module)) {
m.context.visitAllModuleVariants(m.module, visit)
}
func (m *baseModuleContext) AddNinjaFileDeps(deps ...string) {
m.ninjaFileDeps = append(m.ninjaFileDeps, deps...)
}
@ -695,18 +707,6 @@ func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
m.actionDefs.buildDefs = append(m.actionDefs.buildDefs, def)
}
func (m *moduleContext) PrimaryModule() Module {
return m.module.group.modules[0].logicModule
}
func (m *moduleContext) FinalModule() Module {
return m.module.group.modules[len(m.module.group.modules)-1].logicModule
}
func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
m.context.visitAllModuleVariants(m.module, visit)
}
func (m *moduleContext) GetMissingDependencies() []string {
m.handledMissingDeps = true
return m.module.missingDeps