Add FinalModule and VisitAllModuleVariants to ModuleContext

Allows modules to determine if they are the last of their variants
to build, and to visit each variant to collect shared information.

Change-Id: I396f0c9d43e0e9b1901822d6dd9c6ad6380ad582
This commit is contained in:
Colin Cross 2015-01-06 16:19:59 -08:00
parent 82b7d51dfd
commit 80ad04d5f8
2 changed files with 15 additions and 5 deletions

View file

@ -1204,8 +1204,7 @@ func (c *Context) generateModuleBuildActions(config interface{},
config: config, config: config,
group: group, group: group,
}, },
module: module, module: module,
primaryModule: group.modules[0],
}, },
scope: scope, scope: scope,
} }

View file

@ -128,6 +128,8 @@ type ModuleContext interface {
AddNinjaFileDeps(deps ...string) AddNinjaFileDeps(deps ...string)
PrimaryModule() Module PrimaryModule() Module
FinalModule() Module
VisitAllModuleVariants(visit func(Module))
} }
var _ BaseModuleContext = (*baseModuleContext)(nil) var _ BaseModuleContext = (*baseModuleContext)(nil)
@ -196,8 +198,7 @@ var _ PreModuleContext = (*preModuleContext)(nil)
type preModuleContext struct { type preModuleContext struct {
baseModuleContext baseModuleContext
module *moduleInfo module *moduleInfo
primaryModule *moduleInfo
} }
func (m *preModuleContext) OtherModuleName(module Module) string { func (m *preModuleContext) OtherModuleName(module Module) string {
@ -280,7 +281,17 @@ func (m *moduleContext) AddNinjaFileDeps(deps ...string) {
} }
func (m *moduleContext) PrimaryModule() Module { func (m *moduleContext) PrimaryModule() Module {
return m.primaryModule.logicModule 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)) {
for _, module := range m.module.group.modules {
visit(module.logicModule)
}
} }
// //