From 80ad04d5f82c08ce297767d15ab1378c1262226f Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 6 Jan 2015 16:19:59 -0800 Subject: [PATCH] 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 --- blueprint/context.go | 3 +-- blueprint/module_ctx.go | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/blueprint/context.go b/blueprint/context.go index d43c3af..7a508cb 100644 --- a/blueprint/context.go +++ b/blueprint/context.go @@ -1204,8 +1204,7 @@ func (c *Context) generateModuleBuildActions(config interface{}, config: config, group: group, }, - module: module, - primaryModule: group.modules[0], + module: module, }, scope: scope, } diff --git a/blueprint/module_ctx.go b/blueprint/module_ctx.go index fd89a86..6faff01 100644 --- a/blueprint/module_ctx.go +++ b/blueprint/module_ctx.go @@ -128,6 +128,8 @@ type ModuleContext interface { AddNinjaFileDeps(deps ...string) PrimaryModule() Module + FinalModule() Module + VisitAllModuleVariants(visit func(Module)) } var _ BaseModuleContext = (*baseModuleContext)(nil) @@ -196,8 +198,7 @@ var _ PreModuleContext = (*preModuleContext)(nil) type preModuleContext struct { baseModuleContext - module *moduleInfo - primaryModule *moduleInfo + module *moduleInfo } func (m *preModuleContext) OtherModuleName(module Module) string { @@ -280,7 +281,17 @@ func (m *moduleContext) AddNinjaFileDeps(deps ...string) { } 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) + } } //