blob: 9182c2dd98d8daa0fc9183d3bd12dd802be55589 [file] [log] [blame]
Colin Cross8e0c5112015-01-23 14:15:10 -08001// Copyright 2014 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Jamie Gennis1bc967e2014-05-27 16:34:41 -070015package blueprint
16
17import (
18 "fmt"
19 "path/filepath"
Jamie Gennis6a40c192014-07-02 16:40:31 -070020 "text/scanner"
Jamie Gennis1bc967e2014-05-27 16:34:41 -070021)
22
Jamie Gennisb9e87f62014-09-24 20:28:11 -070023// A Module handles generating all of the Ninja build actions needed to build a
Colin Crossc9028482014-12-18 16:28:54 -080024// single module based on properties defined in a Blueprints file. Module
25// objects are initially created during the parse phase of a Context using one
26// of the registered module types (and the associated ModuleFactory function).
27// The Module's properties struct is automatically filled in with the property
28// values specified in the Blueprints file (see Context.RegisterModuleType for more
Jamie Gennisb9e87f62014-09-24 20:28:11 -070029// information on this).
30//
Colin Crossc9028482014-12-18 16:28:54 -080031// A Module can be split into multiple Modules by a Mutator. All existing
32// properties set on the module will be duplicated to the new Module, and then
33// modified as necessary by the Mutator.
34//
Jamie Gennisb9e87f62014-09-24 20:28:11 -070035// The Module implementation can access the build configuration as well as any
36// modules on which on which it depends (as defined by the "deps" property
37// specified in the Blueprints file or dynamically added by implementing the
38// DynamicDependerModule interface) using the ModuleContext passed to
39// GenerateBuildActions. This ModuleContext is also used to create Ninja build
40// actions and to report errors to the user.
41//
42// In addition to implementing the GenerateBuildActions method, a Module should
43// implement methods that provide dependant modules and singletons information
44// they need to generate their build actions. These methods will only be called
45// after GenerateBuildActions is called because the Context calls
46// GenerateBuildActions in dependency-order (and singletons are invoked after
47// all the Modules). The set of methods a Module supports will determine how
48// dependant Modules interact with it.
49//
50// For example, consider a Module that is responsible for generating a library
51// that other modules can link against. The library Module might implement the
52// following interface:
53//
54// type LibraryProducer interface {
55// LibraryFileName() string
56// }
57//
58// func IsLibraryProducer(module blueprint.Module) {
59// _, ok := module.(LibraryProducer)
60// return ok
61// }
62//
63// A binary-producing Module that depends on the library Module could then do:
64//
65// func (m *myBinaryModule) GenerateBuildActions(ctx blueprint.ModuleContext) {
66// ...
67// var libraryFiles []string
68// ctx.VisitDepsDepthFirstIf(IsLibraryProducer,
69// func(module blueprint.Module) {
70// libProducer := module.(LibraryProducer)
71// libraryFiles = append(libraryFiles, libProducer.LibraryFileName())
72// })
73// ...
74// }
75//
76// to build the list of library file names that should be included in its link
77// command.
Colin Cross691a60d2015-01-07 18:08:56 -080078//
79// GenerateBuildActions may be called from multiple threads. It is guaranteed to
80// be called after it has finished being called on all dependencies and on all
81// variants of that appear earlier in the ModuleContext.VisitAllModuleVariants list.
82// Any accesses to global variables or to Module objects that are not dependencies
83// or variants of the current Module must be synchronized by the implementation of
84// GenerateBuildActions.
Jamie Gennis1bc967e2014-05-27 16:34:41 -070085type Module interface {
Jamie Gennisb9e87f62014-09-24 20:28:11 -070086 // GenerateBuildActions is called by the Context that created the Module
87 // during its generate phase. This call should generate all Ninja build
88 // actions (rules, pools, and build statements) needed to build the module.
Jamie Gennis1bc967e2014-05-27 16:34:41 -070089 GenerateBuildActions(ModuleContext)
90}
91
Jamie Gennisb9e87f62014-09-24 20:28:11 -070092// A DynamicDependerModule is a Module that may add dependencies that do not
93// appear in its "deps" property. Any Module that implements this interface
94// will have its DynamicDependencies method called by the Context that created
95// it during generate phase.
96type DynamicDependerModule interface {
97 Module
98
99 // DynamicDependencies is called by the Context that created the
100 // DynamicDependerModule during its generate phase. This call should return
101 // the list of module names that the DynamicDependerModule depends on
102 // dynamically. Module names that already appear in the "deps" property may
103 // but do not need to be included in the returned list.
104 DynamicDependencies(DynamicDependerModuleContext) []string
105}
106
Colin Crossbe1a9a12014-12-18 11:05:45 -0800107type BaseModuleContext interface {
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700108 ModuleName() string
109 ModuleDir() string
Jamie Gennis6eb4d242014-06-11 18:31:16 -0700110 Config() interface{}
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700111
David Allison701fbad2014-10-29 14:51:13 -0700112 ContainsProperty(name string) bool
Jamie Gennis6a40c192014-07-02 16:40:31 -0700113 Errorf(pos scanner.Position, fmt string, args ...interface{})
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700114 ModuleErrorf(fmt string, args ...interface{})
115 PropertyErrorf(property, fmt string, args ...interface{})
Jamie Gennis6a40c192014-07-02 16:40:31 -0700116 Failed() bool
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700117}
118
Colin Crossbe1a9a12014-12-18 11:05:45 -0800119type DynamicDependerModuleContext interface {
120 BaseModuleContext
Colin Cross65569e42015-03-10 20:08:19 -0700121
Colin Crossf5e34b92015-03-13 16:02:36 -0700122 AddVariationDependencies([]Variation, ...string)
Colin Crossbe1a9a12014-12-18 11:05:45 -0800123}
124
Colin Cross1455a0f2014-12-17 13:23:56 -0800125type ModuleContext interface {
Colin Crossbe1a9a12014-12-18 11:05:45 -0800126 BaseModuleContext
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700127
128 OtherModuleName(m Module) string
129 OtherModuleErrorf(m Module, fmt string, args ...interface{})
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700130
Colin Crossc7ffa302015-02-10 11:24:52 -0800131 VisitDirectDeps(visit func(Module))
132 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
Colin Crossb2e7b5d2014-11-11 14:18:53 -0800133 VisitDepsDepthFirst(visit func(Module))
134 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
Colin Crossb2e7b5d2014-11-11 14:18:53 -0800135
Colin Crossc9028482014-12-18 16:28:54 -0800136 ModuleSubDir() string
137
Jamie Gennis2fb20952014-10-03 02:49:58 -0700138 Variable(pctx *PackageContext, name, value string)
139 Rule(pctx *PackageContext, name string, params RuleParams, argNames ...string) Rule
140 Build(pctx *PackageContext, params BuildParams)
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700141
Mathias Agopian5b8477d2014-06-25 17:21:54 -0700142 AddNinjaFileDeps(deps ...string)
Colin Crossc9028482014-12-18 16:28:54 -0800143
144 PrimaryModule() Module
Colin Cross80ad04d2015-01-06 16:19:59 -0800145 FinalModule() Module
146 VisitAllModuleVariants(visit func(Module))
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700147}
148
Colin Crossbe1a9a12014-12-18 11:05:45 -0800149var _ BaseModuleContext = (*baseModuleContext)(nil)
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700150
Colin Crossbe1a9a12014-12-18 11:05:45 -0800151type baseModuleContext struct {
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700152 context *Context
153 config interface{}
Colin Crossed342d92015-03-11 00:57:25 -0700154 module *moduleInfo
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700155 errs []error
156}
157
Colin Crossbe1a9a12014-12-18 11:05:45 -0800158func (d *baseModuleContext) ModuleName() string {
Colin Crossed342d92015-03-11 00:57:25 -0700159 return d.module.properties.Name
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700160}
161
Colin Crossbe1a9a12014-12-18 11:05:45 -0800162func (d *baseModuleContext) ContainsProperty(name string) bool {
Colin Crossed342d92015-03-11 00:57:25 -0700163 _, ok := d.module.propertyPos[name]
David Allison701fbad2014-10-29 14:51:13 -0700164 return ok
165}
166
Colin Crossbe1a9a12014-12-18 11:05:45 -0800167func (d *baseModuleContext) ModuleDir() string {
Colin Crossed342d92015-03-11 00:57:25 -0700168 return filepath.Dir(d.module.relBlueprintsFile)
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700169}
170
Colin Crossbe1a9a12014-12-18 11:05:45 -0800171func (d *baseModuleContext) Config() interface{} {
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700172 return d.config
173}
174
Colin Crossbe1a9a12014-12-18 11:05:45 -0800175func (d *baseModuleContext) Errorf(pos scanner.Position,
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700176 format string, args ...interface{}) {
177
178 d.errs = append(d.errs, &Error{
179 Err: fmt.Errorf(format, args...),
180 Pos: pos,
181 })
182}
183
Colin Crossbe1a9a12014-12-18 11:05:45 -0800184func (d *baseModuleContext) ModuleErrorf(format string,
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700185 args ...interface{}) {
186
187 d.errs = append(d.errs, &Error{
188 Err: fmt.Errorf(format, args...),
Colin Crossed342d92015-03-11 00:57:25 -0700189 Pos: d.module.pos,
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700190 })
191}
192
Colin Crossbe1a9a12014-12-18 11:05:45 -0800193func (d *baseModuleContext) PropertyErrorf(property, format string,
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700194 args ...interface{}) {
195
Colin Crossed342d92015-03-11 00:57:25 -0700196 pos, ok := d.module.propertyPos[property]
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700197 if !ok {
198 panic(fmt.Errorf("property %q was not set for this module", property))
199 }
200
201 d.errs = append(d.errs, &Error{
202 Err: fmt.Errorf(format, args...),
203 Pos: pos,
204 })
205}
206
Colin Crossbe1a9a12014-12-18 11:05:45 -0800207func (d *baseModuleContext) Failed() bool {
Jamie Gennisb9e87f62014-09-24 20:28:11 -0700208 return len(d.errs) > 0
209}
210
Colin Cross1455a0f2014-12-17 13:23:56 -0800211var _ ModuleContext = (*moduleContext)(nil)
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700212
Colin Cross1455a0f2014-12-17 13:23:56 -0800213type moduleContext struct {
Colin Crossbe1a9a12014-12-18 11:05:45 -0800214 baseModuleContext
Colin Cross1455a0f2014-12-17 13:23:56 -0800215 scope *localScope
216 ninjaFileDeps []string
217 actionDefs localBuildActions
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700218}
219
Colin Crossed342d92015-03-11 00:57:25 -0700220func (m *moduleContext) OtherModuleName(logicModule Module) string {
221 module := m.context.moduleInfo[logicModule]
222 return module.properties.Name
Jamie Gennisd4c53d82014-06-22 17:02:55 -0700223}
224
Colin Crossed342d92015-03-11 00:57:25 -0700225func (m *moduleContext) OtherModuleErrorf(logicModule Module, format string,
Jamie Gennisd4c53d82014-06-22 17:02:55 -0700226 args ...interface{}) {
227
Colin Crossed342d92015-03-11 00:57:25 -0700228 module := m.context.moduleInfo[logicModule]
Jamie Gennisd4c53d82014-06-22 17:02:55 -0700229 m.errs = append(m.errs, &Error{
230 Err: fmt.Errorf(format, args...),
Colin Crossed342d92015-03-11 00:57:25 -0700231 Pos: module.pos,
Jamie Gennisd4c53d82014-06-22 17:02:55 -0700232 })
233}
234
Colin Crossc7ffa302015-02-10 11:24:52 -0800235func (m *moduleContext) VisitDirectDeps(visit func(Module)) {
236 m.context.visitDirectDeps(m.module, visit)
237}
238
239func (m *moduleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
240 m.context.visitDirectDepsIf(m.module, pred, visit)
241}
242
Colin Cross1455a0f2014-12-17 13:23:56 -0800243func (m *moduleContext) VisitDepsDepthFirst(visit func(Module)) {
Colin Crossb2e7b5d2014-11-11 14:18:53 -0800244 m.context.visitDepsDepthFirst(m.module, visit)
245}
246
Colin Cross1455a0f2014-12-17 13:23:56 -0800247func (m *moduleContext) VisitDepsDepthFirstIf(pred func(Module) bool,
Colin Crossb2e7b5d2014-11-11 14:18:53 -0800248 visit func(Module)) {
249
250 m.context.visitDepsDepthFirstIf(m.module, pred, visit)
251}
252
Colin Crossc9028482014-12-18 16:28:54 -0800253func (m *moduleContext) ModuleSubDir() string {
Colin Crosse7daa222015-03-11 14:35:41 -0700254 return m.module.variantName
Colin Crossc9028482014-12-18 16:28:54 -0800255}
256
Jamie Gennis2fb20952014-10-03 02:49:58 -0700257func (m *moduleContext) Variable(pctx *PackageContext, name, value string) {
258 m.scope.ReparentTo(pctx)
Jamie Gennis0ed63ef2014-06-30 18:07:17 -0700259
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700260 v, err := m.scope.AddLocalVariable(name, value)
261 if err != nil {
262 panic(err)
263 }
264
265 m.actionDefs.variables = append(m.actionDefs.variables, v)
266}
267
Jamie Gennis2fb20952014-10-03 02:49:58 -0700268func (m *moduleContext) Rule(pctx *PackageContext, name string,
269 params RuleParams, argNames ...string) Rule {
Jamie Genniscbc6f862014-06-05 20:00:22 -0700270
Jamie Gennis2fb20952014-10-03 02:49:58 -0700271 m.scope.ReparentTo(pctx)
Jamie Gennis0ed63ef2014-06-30 18:07:17 -0700272
Jamie Genniscbc6f862014-06-05 20:00:22 -0700273 r, err := m.scope.AddLocalRule(name, &params, argNames...)
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700274 if err != nil {
275 panic(err)
276 }
277
278 m.actionDefs.rules = append(m.actionDefs.rules, r)
279
280 return r
281}
282
Jamie Gennis2fb20952014-10-03 02:49:58 -0700283func (m *moduleContext) Build(pctx *PackageContext, params BuildParams) {
284 m.scope.ReparentTo(pctx)
Jamie Gennis0ed63ef2014-06-30 18:07:17 -0700285
Jamie Gennis1bc967e2014-05-27 16:34:41 -0700286 def, err := parseBuildParams(m.scope, &params)
287 if err != nil {
288 panic(err)
289 }
290
291 m.actionDefs.buildDefs = append(m.actionDefs.buildDefs, def)
292}
293
Mathias Agopian5b8477d2014-06-25 17:21:54 -0700294func (m *moduleContext) AddNinjaFileDeps(deps ...string) {
295 m.ninjaFileDeps = append(m.ninjaFileDeps, deps...)
296}
Colin Crossc9028482014-12-18 16:28:54 -0800297
298func (m *moduleContext) PrimaryModule() Module {
Colin Cross80ad04d2015-01-06 16:19:59 -0800299 return m.module.group.modules[0].logicModule
300}
301
302func (m *moduleContext) FinalModule() Module {
303 return m.module.group.modules[len(m.module.group.modules)-1].logicModule
304}
305
306func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) {
307 for _, module := range m.module.group.modules {
308 visit(module.logicModule)
309 }
Colin Crossc9028482014-12-18 16:28:54 -0800310}
311
312//
Colin Cross65569e42015-03-10 20:08:19 -0700313// DynamicDependerModuleContext
314//
315
316type dynamicDependerModuleContext struct {
317 baseModuleContext
318
319 module *moduleInfo
320}
321
Colin Crossf5e34b92015-03-13 16:02:36 -0700322// AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
323// argument to select which variant of the dependency to use. A variant of the dependency must
324// exist that matches the all of the non-local variations of the current module, plus the variations
325// argument.
326func (mctx *dynamicDependerModuleContext) AddVariationDependencies(variations []Variation,
327 deps ...string) {
328
Colin Cross65569e42015-03-10 20:08:19 -0700329 for _, dep := range deps {
Colin Crossf5e34b92015-03-13 16:02:36 -0700330 errs := mctx.context.addVariationDependency(mctx.module, variations, dep)
Colin Cross65569e42015-03-10 20:08:19 -0700331 if len(errs) > 0 {
332 mctx.errs = append(mctx.errs, errs...)
333 }
334 }
335}
336
337//
Colin Crossc9028482014-12-18 16:28:54 -0800338// MutatorContext
339//
340
341type mutatorContext struct {
342 baseModuleContext
Colin Crossc9028482014-12-18 16:28:54 -0800343 name string
344 dependenciesModified bool
345}
346
347type baseMutatorContext interface {
348 BaseModuleContext
349
350 Module() Module
351}
352
Colin Cross65569e42015-03-10 20:08:19 -0700353type EarlyMutatorContext interface {
354 baseMutatorContext
355
Colin Crossf5e34b92015-03-13 16:02:36 -0700356 CreateVariations(...string) []Module
357 CreateLocalVariations(...string) []Module
Colin Cross65569e42015-03-10 20:08:19 -0700358}
359
Colin Crossc9028482014-12-18 16:28:54 -0800360type TopDownMutatorContext interface {
361 baseMutatorContext
362
363 VisitDirectDeps(visit func(Module))
364 VisitDirectDepsIf(pred func(Module) bool, visit func(Module))
365 VisitDepsDepthFirst(visit func(Module))
366 VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module))
367}
368
369type BottomUpMutatorContext interface {
370 baseMutatorContext
371
372 AddDependency(module Module, name string)
Colin Crossf5e34b92015-03-13 16:02:36 -0700373 CreateVariations(...string) []Module
374 SetDependencyVariation(string)
Colin Crossc9028482014-12-18 16:28:54 -0800375}
376
377// A Mutator function is called for each Module, and can use
Colin Crossf5e34b92015-03-13 16:02:36 -0700378// MutatorContext.CreateVariations to split a Module into multiple Modules,
Colin Crossc9028482014-12-18 16:28:54 -0800379// modifying properties on the new modules to differentiate them. It is called
380// after parsing all Blueprint files, but before generating any build rules,
381// and is always called on dependencies before being called on the depending module.
382//
383// The Mutator function should only modify members of properties structs, and not
384// members of the module struct itself, to ensure the modified values are copied
385// if a second Mutator chooses to split the module a second time.
386type TopDownMutator func(mctx TopDownMutatorContext)
387type BottomUpMutator func(mctx BottomUpMutatorContext)
Colin Cross65569e42015-03-10 20:08:19 -0700388type EarlyMutator func(mctx EarlyMutatorContext)
Colin Crossc9028482014-12-18 16:28:54 -0800389
Colin Crossf5e34b92015-03-13 16:02:36 -0700390// Split a module into mulitple variants, one for each name in the variationNames
391// parameter. It returns a list of new modules in the same order as the variationNames
Colin Crossc9028482014-12-18 16:28:54 -0800392// list.
393//
394// If any of the dependencies of the module being operated on were already split
Colin Crossf5e34b92015-03-13 16:02:36 -0700395// by calling CreateVariations with the same name, the dependency will automatically
Colin Crossc9028482014-12-18 16:28:54 -0800396// be updated to point the matching variant.
397//
398// If a module is split, and then a module depending on the first module is not split
399// when the Mutator is later called on it, the dependency of the depending module will
400// automatically be updated to point to the first variant.
Colin Crossf5e34b92015-03-13 16:02:36 -0700401func (mctx *mutatorContext) CreateVariations(variationNames ...string) []Module {
402 return mctx.createVariations(variationNames, false)
Colin Cross65569e42015-03-10 20:08:19 -0700403}
404
405// Split a module into mulitple variants, one for each name in the variantNames
406// parameter. It returns a list of new modules in the same order as the variantNames
407// list.
408//
Colin Crossf5e34b92015-03-13 16:02:36 -0700409// Local variations do not affect automatic dependency resolution - dependencies added
Colin Cross65569e42015-03-10 20:08:19 -0700410// to the split module via deps or DynamicDependerModule must exactly match a variant
Colin Crossf5e34b92015-03-13 16:02:36 -0700411// that contains all the non-local variations.
412func (mctx *mutatorContext) CreateLocalVariations(variationNames ...string) []Module {
413 return mctx.createVariations(variationNames, true)
Colin Cross65569e42015-03-10 20:08:19 -0700414}
415
Colin Crossf5e34b92015-03-13 16:02:36 -0700416func (mctx *mutatorContext) createVariations(variationNames []string, local bool) []Module {
Colin Crossc9028482014-12-18 16:28:54 -0800417 ret := []Module{}
Colin Crossf5e34b92015-03-13 16:02:36 -0700418 modules, errs := mctx.context.createVariations(mctx.module, mctx.name, variationNames)
Colin Cross174ae052015-03-03 17:37:03 -0800419 if len(errs) > 0 {
420 mctx.errs = append(mctx.errs, errs...)
421 }
Colin Crossc9028482014-12-18 16:28:54 -0800422
Colin Cross65569e42015-03-10 20:08:19 -0700423 for i, module := range modules {
Colin Crossc9028482014-12-18 16:28:54 -0800424 ret = append(ret, module.logicModule)
Colin Cross65569e42015-03-10 20:08:19 -0700425 if !local {
Colin Crossf5e34b92015-03-13 16:02:36 -0700426 module.dependencyVariant[mctx.name] = variationNames[i]
Colin Cross65569e42015-03-10 20:08:19 -0700427 }
Colin Crossc9028482014-12-18 16:28:54 -0800428 }
429
Colin Crossf5e34b92015-03-13 16:02:36 -0700430 if len(ret) != len(variationNames) {
Colin Crossc9028482014-12-18 16:28:54 -0800431 panic("oops!")
432 }
433
434 return ret
435}
436
Colin Crossf5e34b92015-03-13 16:02:36 -0700437// Set all dangling dependencies on the current module to point to the variation
Colin Crossc9028482014-12-18 16:28:54 -0800438// with given name.
Colin Crossf5e34b92015-03-13 16:02:36 -0700439func (mctx *mutatorContext) SetDependencyVariation(variationName string) {
440 mctx.context.convertDepsToVariation(mctx.module, mctx.name, variationName)
Colin Crossc9028482014-12-18 16:28:54 -0800441}
442
443func (mctx *mutatorContext) Module() Module {
444 return mctx.module.logicModule
445}
446
447// Add a dependency to the given module. The depender can be a specific variant
Colin Crossf5e34b92015-03-13 16:02:36 -0700448// of a module, but the dependee must be a module that has no variations.
Colin Crossc9028482014-12-18 16:28:54 -0800449// Does not affect the ordering of the current mutator pass, but will be ordered
450// correctly for all future mutator passes.
451func (mctx *mutatorContext) AddDependency(module Module, depName string) {
Colin Cross65569e42015-03-10 20:08:19 -0700452 errs := mctx.context.addDependency(mctx.context.moduleInfo[module], depName)
453 if len(errs) > 0 {
454 mctx.errs = append(mctx.errs, errs...)
455 }
Colin Crossc9028482014-12-18 16:28:54 -0800456 mctx.dependenciesModified = true
457}
458
459func (mctx *mutatorContext) VisitDirectDeps(visit func(Module)) {
460 mctx.context.visitDirectDeps(mctx.module, visit)
461}
462
463func (mctx *mutatorContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) {
464 mctx.context.visitDirectDepsIf(mctx.module, pred, visit)
465}
466
467func (mctx *mutatorContext) VisitDepsDepthFirst(visit func(Module)) {
468 mctx.context.visitDepsDepthFirst(mctx.module, visit)
469}
470
471func (mctx *mutatorContext) VisitDepsDepthFirstIf(pred func(Module) bool,
472 visit func(Module)) {
473
474 mctx.context.visitDepsDepthFirstIf(mctx.module, pred, visit)
475}