Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 1 | package blueprint |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "path/filepath" |
Jamie Gennis | 6a40c19 | 2014-07-02 16:40:31 -0700 | [diff] [blame] | 6 | "text/scanner" |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 7 | ) |
| 8 | |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 9 | // A Module handles generating all of the Ninja build actions needed to build a |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame^] | 10 | // single module based on properties defined in a Blueprints file. Module |
| 11 | // objects are initially created during the parse phase of a Context using one |
| 12 | // of the registered module types (and the associated ModuleFactory function). |
| 13 | // The Module's properties struct is automatically filled in with the property |
| 14 | // values specified in the Blueprints file (see Context.RegisterModuleType for more |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 15 | // information on this). |
| 16 | // |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame^] | 17 | // A Module can be split into multiple Modules by a Mutator. All existing |
| 18 | // properties set on the module will be duplicated to the new Module, and then |
| 19 | // modified as necessary by the Mutator. |
| 20 | // |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 21 | // The Module implementation can access the build configuration as well as any |
| 22 | // modules on which on which it depends (as defined by the "deps" property |
| 23 | // specified in the Blueprints file or dynamically added by implementing the |
| 24 | // DynamicDependerModule interface) using the ModuleContext passed to |
| 25 | // GenerateBuildActions. This ModuleContext is also used to create Ninja build |
| 26 | // actions and to report errors to the user. |
| 27 | // |
| 28 | // In addition to implementing the GenerateBuildActions method, a Module should |
| 29 | // implement methods that provide dependant modules and singletons information |
| 30 | // they need to generate their build actions. These methods will only be called |
| 31 | // after GenerateBuildActions is called because the Context calls |
| 32 | // GenerateBuildActions in dependency-order (and singletons are invoked after |
| 33 | // all the Modules). The set of methods a Module supports will determine how |
| 34 | // dependant Modules interact with it. |
| 35 | // |
| 36 | // For example, consider a Module that is responsible for generating a library |
| 37 | // that other modules can link against. The library Module might implement the |
| 38 | // following interface: |
| 39 | // |
| 40 | // type LibraryProducer interface { |
| 41 | // LibraryFileName() string |
| 42 | // } |
| 43 | // |
| 44 | // func IsLibraryProducer(module blueprint.Module) { |
| 45 | // _, ok := module.(LibraryProducer) |
| 46 | // return ok |
| 47 | // } |
| 48 | // |
| 49 | // A binary-producing Module that depends on the library Module could then do: |
| 50 | // |
| 51 | // func (m *myBinaryModule) GenerateBuildActions(ctx blueprint.ModuleContext) { |
| 52 | // ... |
| 53 | // var libraryFiles []string |
| 54 | // ctx.VisitDepsDepthFirstIf(IsLibraryProducer, |
| 55 | // func(module blueprint.Module) { |
| 56 | // libProducer := module.(LibraryProducer) |
| 57 | // libraryFiles = append(libraryFiles, libProducer.LibraryFileName()) |
| 58 | // }) |
| 59 | // ... |
| 60 | // } |
| 61 | // |
| 62 | // to build the list of library file names that should be included in its link |
| 63 | // command. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 64 | type Module interface { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 65 | // GenerateBuildActions is called by the Context that created the Module |
| 66 | // during its generate phase. This call should generate all Ninja build |
| 67 | // actions (rules, pools, and build statements) needed to build the module. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 68 | GenerateBuildActions(ModuleContext) |
| 69 | } |
| 70 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 71 | type preGenerateModule interface { |
| 72 | // PreGenerateBuildActions is called by the Context that created the Module |
| 73 | // during its generate phase, before calling GenerateBuildActions on |
| 74 | // any module. It should not touch any Ninja build actions. |
| 75 | PreGenerateBuildActions(PreModuleContext) |
| 76 | } |
| 77 | |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 78 | // A DynamicDependerModule is a Module that may add dependencies that do not |
| 79 | // appear in its "deps" property. Any Module that implements this interface |
| 80 | // will have its DynamicDependencies method called by the Context that created |
| 81 | // it during generate phase. |
| 82 | type DynamicDependerModule interface { |
| 83 | Module |
| 84 | |
| 85 | // DynamicDependencies is called by the Context that created the |
| 86 | // DynamicDependerModule during its generate phase. This call should return |
| 87 | // the list of module names that the DynamicDependerModule depends on |
| 88 | // dynamically. Module names that already appear in the "deps" property may |
| 89 | // but do not need to be included in the returned list. |
| 90 | DynamicDependencies(DynamicDependerModuleContext) []string |
| 91 | } |
| 92 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 93 | type BaseModuleContext interface { |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 94 | ModuleName() string |
| 95 | ModuleDir() string |
Jamie Gennis | 6eb4d24 | 2014-06-11 18:31:16 -0700 | [diff] [blame] | 96 | Config() interface{} |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 97 | |
David Allison | 701fbad | 2014-10-29 14:51:13 -0700 | [diff] [blame] | 98 | ContainsProperty(name string) bool |
Jamie Gennis | 6a40c19 | 2014-07-02 16:40:31 -0700 | [diff] [blame] | 99 | Errorf(pos scanner.Position, fmt string, args ...interface{}) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 100 | ModuleErrorf(fmt string, args ...interface{}) |
| 101 | PropertyErrorf(property, fmt string, args ...interface{}) |
Jamie Gennis | 6a40c19 | 2014-07-02 16:40:31 -0700 | [diff] [blame] | 102 | Failed() bool |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 105 | type DynamicDependerModuleContext interface { |
| 106 | BaseModuleContext |
| 107 | } |
| 108 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 109 | type PreModuleContext interface { |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 110 | BaseModuleContext |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 111 | |
| 112 | OtherModuleName(m Module) string |
| 113 | OtherModuleErrorf(m Module, fmt string, args ...interface{}) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 114 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 115 | VisitDepsDepthFirst(visit func(Module)) |
| 116 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
| 117 | } |
| 118 | |
| 119 | type ModuleContext interface { |
| 120 | PreModuleContext |
| 121 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame^] | 122 | ModuleSubDir() string |
| 123 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 124 | Variable(pctx *PackageContext, name, value string) |
| 125 | Rule(pctx *PackageContext, name string, params RuleParams, argNames ...string) Rule |
| 126 | Build(pctx *PackageContext, params BuildParams) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 127 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 128 | AddNinjaFileDeps(deps ...string) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame^] | 129 | |
| 130 | PrimaryModule() Module |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 133 | var _ BaseModuleContext = (*baseModuleContext)(nil) |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 134 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 135 | type baseModuleContext struct { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 136 | context *Context |
| 137 | config interface{} |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 138 | group *moduleGroup |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 139 | errs []error |
| 140 | } |
| 141 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 142 | func (d *baseModuleContext) ModuleName() string { |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 143 | return d.group.properties.Name |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 146 | func (d *baseModuleContext) ContainsProperty(name string) bool { |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 147 | _, ok := d.group.propertyPos[name] |
David Allison | 701fbad | 2014-10-29 14:51:13 -0700 | [diff] [blame] | 148 | return ok |
| 149 | } |
| 150 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 151 | func (d *baseModuleContext) ModuleDir() string { |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 152 | return filepath.Dir(d.group.relBlueprintsFile) |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 155 | func (d *baseModuleContext) Config() interface{} { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 156 | return d.config |
| 157 | } |
| 158 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 159 | func (d *baseModuleContext) Errorf(pos scanner.Position, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 160 | format string, args ...interface{}) { |
| 161 | |
| 162 | d.errs = append(d.errs, &Error{ |
| 163 | Err: fmt.Errorf(format, args...), |
| 164 | Pos: pos, |
| 165 | }) |
| 166 | } |
| 167 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 168 | func (d *baseModuleContext) ModuleErrorf(format string, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 169 | args ...interface{}) { |
| 170 | |
| 171 | d.errs = append(d.errs, &Error{ |
| 172 | Err: fmt.Errorf(format, args...), |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 173 | Pos: d.group.pos, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 174 | }) |
| 175 | } |
| 176 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 177 | func (d *baseModuleContext) PropertyErrorf(property, format string, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 178 | args ...interface{}) { |
| 179 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 180 | pos, ok := d.group.propertyPos[property] |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 181 | if !ok { |
| 182 | panic(fmt.Errorf("property %q was not set for this module", property)) |
| 183 | } |
| 184 | |
| 185 | d.errs = append(d.errs, &Error{ |
| 186 | Err: fmt.Errorf(format, args...), |
| 187 | Pos: pos, |
| 188 | }) |
| 189 | } |
| 190 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 191 | func (d *baseModuleContext) Failed() bool { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 192 | return len(d.errs) > 0 |
| 193 | } |
| 194 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 195 | var _ PreModuleContext = (*preModuleContext)(nil) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 196 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 197 | type preModuleContext struct { |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 198 | baseModuleContext |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame^] | 199 | module *moduleInfo |
| 200 | primaryModule *moduleInfo |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 203 | func (m *preModuleContext) OtherModuleName(module Module) string { |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 204 | info := m.context.moduleInfo[module] |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 205 | return info.group.properties.Name |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 208 | func (m *preModuleContext) OtherModuleErrorf(module Module, format string, |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 209 | args ...interface{}) { |
| 210 | |
| 211 | info := m.context.moduleInfo[module] |
| 212 | m.errs = append(m.errs, &Error{ |
| 213 | Err: fmt.Errorf(format, args...), |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 214 | Pos: info.group.pos, |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 215 | }) |
| 216 | } |
| 217 | |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 218 | func (m *preModuleContext) VisitDepsDepthFirst(visit func(Module)) { |
| 219 | m.context.visitDepsDepthFirst(m.module, visit) |
| 220 | } |
| 221 | |
| 222 | func (m *preModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, |
| 223 | visit func(Module)) { |
| 224 | |
| 225 | m.context.visitDepsDepthFirstIf(m.module, pred, visit) |
| 226 | } |
| 227 | |
| 228 | var _ ModuleContext = (*moduleContext)(nil) |
| 229 | |
| 230 | type moduleContext struct { |
| 231 | preModuleContext |
| 232 | scope *localScope |
| 233 | ninjaFileDeps []string |
| 234 | actionDefs localBuildActions |
| 235 | } |
| 236 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame^] | 237 | func (m *moduleContext) ModuleSubDir() string { |
| 238 | return m.module.subName() |
| 239 | } |
| 240 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 241 | func (m *moduleContext) Variable(pctx *PackageContext, name, value string) { |
| 242 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 243 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 244 | v, err := m.scope.AddLocalVariable(name, value) |
| 245 | if err != nil { |
| 246 | panic(err) |
| 247 | } |
| 248 | |
| 249 | m.actionDefs.variables = append(m.actionDefs.variables, v) |
| 250 | } |
| 251 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 252 | func (m *moduleContext) Rule(pctx *PackageContext, name string, |
| 253 | params RuleParams, argNames ...string) Rule { |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 254 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 255 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 256 | |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 257 | r, err := m.scope.AddLocalRule(name, ¶ms, argNames...) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 258 | if err != nil { |
| 259 | panic(err) |
| 260 | } |
| 261 | |
| 262 | m.actionDefs.rules = append(m.actionDefs.rules, r) |
| 263 | |
| 264 | return r |
| 265 | } |
| 266 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 267 | func (m *moduleContext) Build(pctx *PackageContext, params BuildParams) { |
| 268 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 269 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 270 | def, err := parseBuildParams(m.scope, ¶ms) |
| 271 | if err != nil { |
| 272 | panic(err) |
| 273 | } |
| 274 | |
| 275 | m.actionDefs.buildDefs = append(m.actionDefs.buildDefs, def) |
| 276 | } |
| 277 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 278 | func (m *moduleContext) AddNinjaFileDeps(deps ...string) { |
| 279 | m.ninjaFileDeps = append(m.ninjaFileDeps, deps...) |
| 280 | } |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame^] | 281 | |
| 282 | func (m *moduleContext) PrimaryModule() Module { |
| 283 | return m.primaryModule.logicModule |
| 284 | } |
| 285 | |
| 286 | // |
| 287 | // MutatorContext |
| 288 | // |
| 289 | |
| 290 | type mutatorContext struct { |
| 291 | baseModuleContext |
| 292 | module *moduleInfo |
| 293 | name string |
| 294 | dependenciesModified bool |
| 295 | } |
| 296 | |
| 297 | type baseMutatorContext interface { |
| 298 | BaseModuleContext |
| 299 | |
| 300 | Module() Module |
| 301 | } |
| 302 | |
| 303 | type TopDownMutatorContext interface { |
| 304 | baseMutatorContext |
| 305 | |
| 306 | VisitDirectDeps(visit func(Module)) |
| 307 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
| 308 | VisitDepsDepthFirst(visit func(Module)) |
| 309 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
| 310 | } |
| 311 | |
| 312 | type BottomUpMutatorContext interface { |
| 313 | baseMutatorContext |
| 314 | |
| 315 | AddDependency(module Module, name string) |
| 316 | CreateVariants(...string) []Module |
| 317 | SetDependencyVariant(string) |
| 318 | } |
| 319 | |
| 320 | // A Mutator function is called for each Module, and can use |
| 321 | // MutatorContext.CreateSubVariants to split a Module into multiple Modules, |
| 322 | // modifying properties on the new modules to differentiate them. It is called |
| 323 | // after parsing all Blueprint files, but before generating any build rules, |
| 324 | // and is always called on dependencies before being called on the depending module. |
| 325 | // |
| 326 | // The Mutator function should only modify members of properties structs, and not |
| 327 | // members of the module struct itself, to ensure the modified values are copied |
| 328 | // if a second Mutator chooses to split the module a second time. |
| 329 | type TopDownMutator func(mctx TopDownMutatorContext) |
| 330 | type BottomUpMutator func(mctx BottomUpMutatorContext) |
| 331 | |
| 332 | // Split a module into mulitple variants, one for each name in the variantNames |
| 333 | // parameter. It returns a list of new modules in the same order as the variantNames |
| 334 | // list. |
| 335 | // |
| 336 | // If any of the dependencies of the module being operated on were already split |
| 337 | // by calling CreateVariants with the same name, the dependency will automatically |
| 338 | // be updated to point the matching variant. |
| 339 | // |
| 340 | // If a module is split, and then a module depending on the first module is not split |
| 341 | // when the Mutator is later called on it, the dependency of the depending module will |
| 342 | // automatically be updated to point to the first variant. |
| 343 | func (mctx *mutatorContext) CreateVariants(variantNames ...string) []Module { |
| 344 | ret := []Module{} |
| 345 | modules := mctx.context.createVariants(mctx.module, mctx.name, variantNames) |
| 346 | |
| 347 | for _, module := range modules { |
| 348 | ret = append(ret, module.logicModule) |
| 349 | } |
| 350 | |
| 351 | if len(ret) != len(variantNames) { |
| 352 | panic("oops!") |
| 353 | } |
| 354 | |
| 355 | return ret |
| 356 | } |
| 357 | |
| 358 | // Set all dangling dependencies on the current module to point to the variant |
| 359 | // with given name. |
| 360 | func (mctx *mutatorContext) SetDependencyVariant(variantName string) { |
| 361 | subName := subName{ |
| 362 | mutatorName: mctx.name, |
| 363 | variantName: variantName, |
| 364 | } |
| 365 | mctx.context.convertDepsToVariant(mctx.module, subName) |
| 366 | } |
| 367 | |
| 368 | func (mctx *mutatorContext) Module() Module { |
| 369 | return mctx.module.logicModule |
| 370 | } |
| 371 | |
| 372 | // Add a dependency to the given module. The depender can be a specific variant |
| 373 | // of a module, but the dependee must be a module that only has a single variant. |
| 374 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 375 | // correctly for all future mutator passes. |
| 376 | func (mctx *mutatorContext) AddDependency(module Module, depName string) { |
| 377 | mctx.context.addDependency(mctx.context.moduleInfo[module], depName) |
| 378 | mctx.dependenciesModified = true |
| 379 | } |
| 380 | |
| 381 | func (mctx *mutatorContext) VisitDirectDeps(visit func(Module)) { |
| 382 | mctx.context.visitDirectDeps(mctx.module, visit) |
| 383 | } |
| 384 | |
| 385 | func (mctx *mutatorContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { |
| 386 | mctx.context.visitDirectDepsIf(mctx.module, pred, visit) |
| 387 | } |
| 388 | |
| 389 | func (mctx *mutatorContext) VisitDepsDepthFirst(visit func(Module)) { |
| 390 | mctx.context.visitDepsDepthFirst(mctx.module, visit) |
| 391 | } |
| 392 | |
| 393 | func (mctx *mutatorContext) VisitDepsDepthFirstIf(pred func(Module) bool, |
| 394 | visit func(Module)) { |
| 395 | |
| 396 | mctx.context.visitDepsDepthFirstIf(mctx.module, pred, visit) |
| 397 | } |