Let mutators use ctx.AddNinjaFileDeps
Propagate extra ninja file deps through mutators so that they can use ctx.AddNinjaFileDeps. Test: blueprint tests Change-Id: I299a0665c3f63b020ae345889fd78b91b91b215a
This commit is contained in:
parent
af4fd215eb
commit
874a346904
5 changed files with 40 additions and 33 deletions
|
@ -128,10 +128,11 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri
|
|||
// Add extra ninja file dependencies
|
||||
deps = append(deps, extraNinjaFileDeps...)
|
||||
|
||||
errs = ctx.ResolveDependencies(config)
|
||||
extraDeps, errs := ctx.ResolveDependencies(config)
|
||||
if len(errs) > 0 {
|
||||
fatalErrors(errs)
|
||||
}
|
||||
deps = append(deps, extraDeps...)
|
||||
|
||||
if docFile != "" {
|
||||
err := writeDocs(ctx, filepath.Dir(bootstrapConfig.topLevelBlueprintsFile), docFile)
|
||||
|
@ -141,7 +142,7 @@ func Main(ctx *blueprint.Context, config interface{}, extraNinjaFileDeps ...stri
|
|||
return
|
||||
}
|
||||
|
||||
extraDeps, errs := ctx.PrepareBuildActions(config)
|
||||
extraDeps, errs = ctx.PrepareBuildActions(config)
|
||||
if len(errs) > 0 {
|
||||
fatalErrors(errs)
|
||||
}
|
||||
|
|
47
context.go
47
context.go
|
@ -1152,21 +1152,21 @@ func (c *Context) addModule(module *moduleInfo) []error {
|
|||
// modules defined in the parsed Blueprints files are valid. This means that
|
||||
// the modules depended upon are defined and that no circular dependencies
|
||||
// exist.
|
||||
func (c *Context) ResolveDependencies(config interface{}) []error {
|
||||
errs := c.updateDependencies()
|
||||
func (c *Context) ResolveDependencies(config interface{}) (deps []string, errs []error) {
|
||||
errs = c.updateDependencies()
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
errs = c.runMutators(config)
|
||||
deps, errs = c.runMutators(config)
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
c.cloneModules()
|
||||
|
||||
c.dependenciesReady = true
|
||||
return nil
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
// Default dependencies handling. If the module implements the (deprecated)
|
||||
|
@ -1633,10 +1633,11 @@ func (c *Context) PrepareBuildActions(config interface{}) (deps []string, errs [
|
|||
c.buildActionsReady = false
|
||||
|
||||
if !c.dependenciesReady {
|
||||
errs := c.ResolveDependencies(config)
|
||||
extraDeps, errs := c.ResolveDependencies(config)
|
||||
if len(errs) > 0 {
|
||||
return nil, errs
|
||||
}
|
||||
deps = append(deps, extraDeps...)
|
||||
}
|
||||
|
||||
liveGlobals := newLiveTracker(config)
|
||||
|
@ -1653,7 +1654,8 @@ func (c *Context) PrepareBuildActions(config interface{}) (deps []string, errs [
|
|||
return nil, errs
|
||||
}
|
||||
|
||||
deps = append(depsModules, depsSingletons...)
|
||||
deps = append(deps, depsModules...)
|
||||
deps = append(deps, depsSingletons...)
|
||||
|
||||
if c.ninjaBuildDir != nil {
|
||||
liveGlobals.addNinjaStringDeps(c.ninjaBuildDir)
|
||||
|
@ -1676,26 +1678,28 @@ func (c *Context) PrepareBuildActions(config interface{}) (deps []string, errs [
|
|||
return deps, nil
|
||||
}
|
||||
|
||||
func (c *Context) runMutators(config interface{}) (errs []error) {
|
||||
func (c *Context) runMutators(config interface{}) (deps []string, errs []error) {
|
||||
var mutators []*mutatorInfo
|
||||
|
||||
mutators = append(mutators, c.earlyMutatorInfo...)
|
||||
mutators = append(mutators, c.mutatorInfo...)
|
||||
|
||||
for _, mutator := range mutators {
|
||||
var newDeps []string
|
||||
if mutator.topDownMutator != nil {
|
||||
errs = c.runMutator(config, mutator, topDownMutator)
|
||||
newDeps, errs = c.runMutator(config, mutator, topDownMutator)
|
||||
} else if mutator.bottomUpMutator != nil {
|
||||
errs = c.runMutator(config, mutator, bottomUpMutator)
|
||||
newDeps, errs = c.runMutator(config, mutator, bottomUpMutator)
|
||||
} else {
|
||||
panic("no mutator set on " + mutator.name)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
deps = append(deps, newDeps...)
|
||||
}
|
||||
|
||||
return nil
|
||||
return deps, nil
|
||||
}
|
||||
|
||||
type mutatorDirection interface {
|
||||
|
@ -1743,7 +1747,7 @@ type reverseDep struct {
|
|||
}
|
||||
|
||||
func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
|
||||
direction mutatorDirection) (errs []error) {
|
||||
direction mutatorDirection) (deps []string, errs []error) {
|
||||
|
||||
newModuleInfo := make(map[Module]*moduleInfo)
|
||||
for k, v := range c.moduleInfo {
|
||||
|
@ -1755,6 +1759,7 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
|
|||
rename []rename
|
||||
replace []replace
|
||||
newModules []*moduleInfo
|
||||
deps []string
|
||||
}
|
||||
|
||||
reverseDeps := make(map[*moduleInfo][]depInfo)
|
||||
|
@ -1813,6 +1818,7 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
|
|||
replace: mctx.replace,
|
||||
rename: mctx.rename,
|
||||
newModules: mctx.newModules,
|
||||
deps: mctx.ninjaFileDeps,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1832,6 +1838,7 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
|
|||
replace = append(replace, globalStateChange.replace...)
|
||||
rename = append(rename, globalStateChange.rename...)
|
||||
newModules = append(newModules, globalStateChange.newModules...)
|
||||
deps = append(deps, globalStateChange.deps...)
|
||||
case newVariations := <-newVariationsCh:
|
||||
for _, m := range newVariations {
|
||||
newModuleInfo[m.logicModule] = m
|
||||
|
@ -1851,7 +1858,7 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
|
|||
done <- true
|
||||
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
c.moduleInfo = newModuleInfo
|
||||
|
@ -1884,29 +1891,29 @@ func (c *Context) runMutator(config interface{}, mutator *mutatorInfo,
|
|||
for _, module := range newModules {
|
||||
errs = c.addModule(module)
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
atomic.AddUint32(&c.depsModified, 1)
|
||||
}
|
||||
|
||||
errs = c.handleRenames(rename)
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
errs = c.handleReplacements(replace)
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
|
||||
if c.depsModified > 0 {
|
||||
errs = c.updateDependencies()
|
||||
if len(errs) > 0 {
|
||||
return errs
|
||||
return nil, errs
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
return deps, errs
|
||||
}
|
||||
|
||||
// Replaces every build logic module with a clone of itself. Prevents introducing problems where
|
||||
|
|
|
@ -105,7 +105,7 @@ func TestContextParse(t *testing.T) {
|
|||
t.FailNow()
|
||||
}
|
||||
|
||||
errs = ctx.ResolveDependencies(nil)
|
||||
_, errs = ctx.ResolveDependencies(nil)
|
||||
if len(errs) > 0 {
|
||||
t.Errorf("unexpected dep errors:")
|
||||
for _, err := range errs {
|
||||
|
@ -170,7 +170,7 @@ func TestWalkDeps(t *testing.T) {
|
|||
t.FailNow()
|
||||
}
|
||||
|
||||
errs = ctx.ResolveDependencies(nil)
|
||||
_, errs = ctx.ResolveDependencies(nil)
|
||||
if len(errs) > 0 {
|
||||
t.Errorf("unexpected dep errors:")
|
||||
for _, err := range errs {
|
||||
|
@ -228,7 +228,7 @@ func TestCreateModule(t *testing.T) {
|
|||
t.FailNow()
|
||||
}
|
||||
|
||||
errs = ctx.ResolveDependencies(nil)
|
||||
_, errs = ctx.ResolveDependencies(nil)
|
||||
if len(errs) > 0 {
|
||||
t.Errorf("unexpected dep errors:")
|
||||
for _, err := range errs {
|
||||
|
|
|
@ -138,6 +138,7 @@ type BaseModuleContext interface {
|
|||
GlobWithDeps(pattern string, excludes []string) ([]string, error)
|
||||
|
||||
Fs() pathtools.FileSystem
|
||||
AddNinjaFileDeps(deps ...string)
|
||||
|
||||
moduleInfo() *moduleInfo
|
||||
error(err error)
|
||||
|
@ -167,8 +168,6 @@ type ModuleContext interface {
|
|||
Rule(pctx PackageContext, name string, params RuleParams, argNames ...string) Rule
|
||||
Build(pctx PackageContext, params BuildParams)
|
||||
|
||||
AddNinjaFileDeps(deps ...string)
|
||||
|
||||
PrimaryModule() Module
|
||||
FinalModule() Module
|
||||
VisitAllModuleVariants(visit func(Module))
|
||||
|
@ -185,6 +184,7 @@ type baseModuleContext struct {
|
|||
errs []error
|
||||
visitingParent *moduleInfo
|
||||
visitingDep depInfo
|
||||
ninjaFileDeps []string
|
||||
}
|
||||
|
||||
func (d *baseModuleContext) moduleInfo() *moduleInfo {
|
||||
|
@ -274,7 +274,6 @@ var _ ModuleContext = (*moduleContext)(nil)
|
|||
type moduleContext struct {
|
||||
baseModuleContext
|
||||
scope *localScope
|
||||
ninjaFileDeps []string
|
||||
actionDefs localBuildActions
|
||||
handledMissingDeps bool
|
||||
}
|
||||
|
@ -431,6 +430,10 @@ func (m *baseModuleContext) WalkDeps(visit func(Module, Module) bool) {
|
|||
m.visitingDep = depInfo{}
|
||||
}
|
||||
|
||||
func (m *baseModuleContext) AddNinjaFileDeps(deps ...string) {
|
||||
m.ninjaFileDeps = append(m.ninjaFileDeps, deps...)
|
||||
}
|
||||
|
||||
func (m *moduleContext) ModuleSubDir() string {
|
||||
return m.module.variantName
|
||||
}
|
||||
|
@ -472,10 +475,6 @@ func (m *moduleContext) Build(pctx PackageContext, params BuildParams) {
|
|||
m.actionDefs.buildDefs = append(m.actionDefs.buildDefs, def)
|
||||
}
|
||||
|
||||
func (m *moduleContext) AddNinjaFileDeps(deps ...string) {
|
||||
m.ninjaFileDeps = append(m.ninjaFileDeps, deps...)
|
||||
}
|
||||
|
||||
func (m *moduleContext) PrimaryModule() Module {
|
||||
return m.module.group.modules[0].logicModule
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ func setupVisitTest(t *testing.T) *Context {
|
|||
t.FailNow()
|
||||
}
|
||||
|
||||
errs = ctx.ResolveDependencies(nil)
|
||||
_, errs = ctx.ResolveDependencies(nil)
|
||||
if len(errs) > 0 {
|
||||
t.Errorf("unexpected dep errors:")
|
||||
for _, err := range errs {
|
||||
|
|
Loading…
Reference in a new issue