From 5b8477d42376052df28847d3df6b5caf4af1e044 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 25 Jun 2014 17:21:54 -0700 Subject: [PATCH] add support for module generated ninja-file dependencies Change-Id: I54b6d240adc89591fbe41ed1f9d63db9a791999a --- blueprint/bootstrap/command.go | 4 +++- blueprint/context.go | 35 +++++++++++++++++++++++----------- blueprint/module_ctx.go | 9 ++++++++- blueprint/singleton_ctx.go | 9 ++++++++- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/blueprint/bootstrap/command.go b/blueprint/bootstrap/command.go index 87fed70..3ec6d98 100644 --- a/blueprint/bootstrap/command.go +++ b/blueprint/bootstrap/command.go @@ -46,11 +46,13 @@ func Main(ctx *blueprint.Context, config interface{}) { fatalErrors(errs) } - errs = ctx.PrepareBuildActions(config) + extraDeps, errs := ctx.PrepareBuildActions(config) if len(errs) > 0 { fatalErrors(errs) } + deps = append(deps, extraDeps...) + buf := bytes.NewBuffer(nil) err := ctx.WriteBuildFile(buf) if err != nil { diff --git a/blueprint/context.go b/blueprint/context.go index 9159f8f..03e9214 100644 --- a/blueprint/context.go +++ b/blueprint/context.go @@ -654,13 +654,17 @@ func (c *Context) checkForDependencyCycles() (errs []error) { // objects passed to GenerateBuildActions. It is also passed to the functions // specified via PoolFunc, RuleFunc, and VariableFunc so that they can compute // config-specific values. -func (c *Context) PrepareBuildActions(config interface{}) []error { +// +// The returned deps is a list of the ninja files dependencies that were added +// by the modules and singletons via the ModuleContext.AddNinjaFileDeps() and +// SingletonContext.AddNinjaFileDeps() methods. +func (c *Context) PrepareBuildActions(config interface{}) (deps []string, errs []error) { c.buildActionsReady = false if !c.dependenciesReady { errs := c.ResolveDependencies() if len(errs) > 0 { - return errs + return nil, errs } } @@ -668,16 +672,18 @@ func (c *Context) PrepareBuildActions(config interface{}) []error { c.initSpecialVariables() - errs := c.generateModuleBuildActions(config, liveGlobals) + depsModules, errs := c.generateModuleBuildActions(config, liveGlobals) if len(errs) > 0 { - return errs + return nil, errs } - errs = c.generateSingletonBuildActions(config, liveGlobals) + depsSingletons, errs := c.generateSingletonBuildActions(config, liveGlobals) if len(errs) > 0 { - return errs + return nil, errs } + deps = append(depsModules, depsSingletons...) + if c.buildDir != nil { liveGlobals.addNinjaStringDeps(c.buildDir) } @@ -694,7 +700,7 @@ func (c *Context) PrepareBuildActions(config interface{}) []error { c.buildActionsReady = true - return nil + return deps, nil } func (c *Context) initSpecialVariables() { @@ -705,10 +711,11 @@ func (c *Context) initSpecialVariables() { } func (c *Context) generateModuleBuildActions(config interface{}, - liveGlobals *liveTracker) []error { + liveGlobals *liveTracker) ([]string, []error) { visited := make(map[Module]bool) + var deps []string var errs []error var walk func(module Module) @@ -738,6 +745,8 @@ func (c *Context) generateModuleBuildActions(config interface{}, return } + deps = append(deps, mctx.ninjaFileDeps...) + newErrs := c.processLocalBuildActions(&info.actionDefs, &mctx.actionDefs, liveGlobals) errs = append(errs, newErrs...) @@ -749,13 +758,15 @@ func (c *Context) generateModuleBuildActions(config interface{}, } } - return errs + return deps, errs } func (c *Context) generateSingletonBuildActions(config interface{}, - liveGlobals *liveTracker) []error { + liveGlobals *liveTracker) ([]string, []error) { + var deps []string var errs []error + for name, info := range c.singletonInfo { // If the package to which the singleton type belongs has not defined // any Ninja globals and has not called Import() then we won't have an @@ -783,6 +794,8 @@ func (c *Context) generateSingletonBuildActions(config interface{}, continue } + deps = append(deps, sctx.ninjaFileDeps...) + newErrs := c.processLocalBuildActions(&info.actionDefs, &sctx.actionDefs, liveGlobals) errs = append(errs, newErrs...) @@ -791,7 +804,7 @@ func (c *Context) generateSingletonBuildActions(config interface{}, } } - return errs + return deps, errs } func (c *Context) processLocalBuildActions(out, in *localBuildActions, diff --git a/blueprint/module_ctx.go b/blueprint/module_ctx.go index f664c93..0029d11 100644 --- a/blueprint/module_ctx.go +++ b/blueprint/module_ctx.go @@ -25,6 +25,8 @@ type ModuleContext interface { VisitDepsDepthFirst(visit func(Module)) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) + + AddNinjaFileDeps(deps ...string) } var _ ModuleContext = (*moduleContext)(nil) @@ -36,7 +38,8 @@ type moduleContext struct { scope *localScope info *moduleInfo - errs []error + ninjaFileDeps []string + errs []error actionDefs localBuildActions } @@ -129,3 +132,7 @@ func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool, m.context.visitDepsDepthFirstIf(m.module, pred, visit) } + +func (m *moduleContext) AddNinjaFileDeps(deps ...string) { + m.ninjaFileDeps = append(m.ninjaFileDeps, deps...) +} diff --git a/blueprint/singleton_ctx.go b/blueprint/singleton_ctx.go index 343f97b..aa1626a 100644 --- a/blueprint/singleton_ctx.go +++ b/blueprint/singleton_ctx.go @@ -35,6 +35,8 @@ type SingletonContext interface { VisitDepsDepthFirst(module Module, visit func(Module)) VisitDepsDepthFirstIf(module Module, pred func(Module) bool, visit func(Module)) + + AddNinjaFileDeps(deps ...string) } var _ SingletonContext = (*singletonContext)(nil) @@ -44,7 +46,8 @@ type singletonContext struct { config interface{} scope *localScope - errs []error + ninjaFileDeps []string + errs []error actionDefs localBuildActions } @@ -148,3 +151,7 @@ func (s *singletonContext) VisitDepsDepthFirstIf(module Module, s.context.visitDepsDepthFirstIf(module, pred, visit) } + +func (s *singletonContext) AddNinjaFileDeps(deps ...string) { + s.ninjaFileDeps = append(s.ninjaFileDeps, deps...) +}