Colin Cross | 8e0c511 | 2015-01-23 14:15:10 -0800 | [diff] [blame] | 1 | // 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 Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 15 | package blueprint |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "path/filepath" |
Jamie Gennis | 6a40c19 | 2014-07-02 16:40:31 -0700 | [diff] [blame] | 20 | "text/scanner" |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 21 | ) |
| 22 | |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 23 | // 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] | 24 | // 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 Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 29 | // information on this). |
| 30 | // |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 31 | // 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 Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 35 | // 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 |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 37 | // specified in the Blueprints file, dynamically added by implementing the |
| 38 | // (deprecated) DynamicDependerModule interface, or dynamically added by a |
| 39 | // BottomUpMutator) using the ModuleContext passed to GenerateBuildActions. |
| 40 | // This ModuleContext is also used to create Ninja build actions and to report |
| 41 | // errors to the user. |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 42 | // |
| 43 | // In addition to implementing the GenerateBuildActions method, a Module should |
| 44 | // implement methods that provide dependant modules and singletons information |
| 45 | // they need to generate their build actions. These methods will only be called |
| 46 | // after GenerateBuildActions is called because the Context calls |
| 47 | // GenerateBuildActions in dependency-order (and singletons are invoked after |
| 48 | // all the Modules). The set of methods a Module supports will determine how |
| 49 | // dependant Modules interact with it. |
| 50 | // |
| 51 | // For example, consider a Module that is responsible for generating a library |
| 52 | // that other modules can link against. The library Module might implement the |
| 53 | // following interface: |
| 54 | // |
| 55 | // type LibraryProducer interface { |
| 56 | // LibraryFileName() string |
| 57 | // } |
| 58 | // |
| 59 | // func IsLibraryProducer(module blueprint.Module) { |
| 60 | // _, ok := module.(LibraryProducer) |
| 61 | // return ok |
| 62 | // } |
| 63 | // |
| 64 | // A binary-producing Module that depends on the library Module could then do: |
| 65 | // |
| 66 | // func (m *myBinaryModule) GenerateBuildActions(ctx blueprint.ModuleContext) { |
| 67 | // ... |
| 68 | // var libraryFiles []string |
| 69 | // ctx.VisitDepsDepthFirstIf(IsLibraryProducer, |
| 70 | // func(module blueprint.Module) { |
| 71 | // libProducer := module.(LibraryProducer) |
| 72 | // libraryFiles = append(libraryFiles, libProducer.LibraryFileName()) |
| 73 | // }) |
| 74 | // ... |
| 75 | // } |
| 76 | // |
| 77 | // to build the list of library file names that should be included in its link |
| 78 | // command. |
Colin Cross | 691a60d | 2015-01-07 18:08:56 -0800 | [diff] [blame] | 79 | // |
| 80 | // GenerateBuildActions may be called from multiple threads. It is guaranteed to |
| 81 | // be called after it has finished being called on all dependencies and on all |
| 82 | // variants of that appear earlier in the ModuleContext.VisitAllModuleVariants list. |
| 83 | // Any accesses to global variables or to Module objects that are not dependencies |
| 84 | // or variants of the current Module must be synchronized by the implementation of |
| 85 | // GenerateBuildActions. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 86 | type Module interface { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 87 | // GenerateBuildActions is called by the Context that created the Module |
| 88 | // during its generate phase. This call should generate all Ninja build |
| 89 | // actions (rules, pools, and build statements) needed to build the module. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 90 | GenerateBuildActions(ModuleContext) |
| 91 | } |
| 92 | |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 93 | // A DynamicDependerModule is a Module that may add dependencies that do not |
| 94 | // appear in its "deps" property. Any Module that implements this interface |
| 95 | // will have its DynamicDependencies method called by the Context that created |
| 96 | // it during generate phase. |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 97 | // |
| 98 | // Deprecated, use a BottomUpMutator instead |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 99 | type DynamicDependerModule interface { |
| 100 | Module |
| 101 | |
| 102 | // DynamicDependencies is called by the Context that created the |
| 103 | // DynamicDependerModule during its generate phase. This call should return |
| 104 | // the list of module names that the DynamicDependerModule depends on |
| 105 | // dynamically. Module names that already appear in the "deps" property may |
| 106 | // but do not need to be included in the returned list. |
| 107 | DynamicDependencies(DynamicDependerModuleContext) []string |
| 108 | } |
| 109 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 110 | type BaseModuleContext interface { |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 111 | ModuleName() string |
| 112 | ModuleDir() string |
Jamie Gennis | 6eb4d24 | 2014-06-11 18:31:16 -0700 | [diff] [blame] | 113 | Config() interface{} |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 114 | |
David Allison | 701fbad | 2014-10-29 14:51:13 -0700 | [diff] [blame] | 115 | ContainsProperty(name string) bool |
Jamie Gennis | 6a40c19 | 2014-07-02 16:40:31 -0700 | [diff] [blame] | 116 | Errorf(pos scanner.Position, fmt string, args ...interface{}) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 117 | ModuleErrorf(fmt string, args ...interface{}) |
| 118 | PropertyErrorf(property, fmt string, args ...interface{}) |
Jamie Gennis | 6a40c19 | 2014-07-02 16:40:31 -0700 | [diff] [blame] | 119 | Failed() bool |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 120 | |
| 121 | moduleInfo() *moduleInfo |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 122 | error(err error) |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 125 | type DynamicDependerModuleContext BottomUpMutatorContext |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 126 | |
Colin Cross | 1455a0f | 2014-12-17 13:23:56 -0800 | [diff] [blame] | 127 | type ModuleContext interface { |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 128 | BaseModuleContext |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 129 | |
| 130 | OtherModuleName(m Module) string |
| 131 | OtherModuleErrorf(m Module, fmt string, args ...interface{}) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 132 | OtherModuleDependencyTag(m Module) DependencyTag |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 133 | |
Colin Cross | c7ffa30 | 2015-02-10 11:24:52 -0800 | [diff] [blame] | 134 | VisitDirectDeps(visit func(Module)) |
| 135 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 136 | VisitDepsDepthFirst(visit func(Module)) |
| 137 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
Yuchen Wu | 222e245 | 2015-10-06 14:03:27 -0700 | [diff] [blame] | 138 | WalkDeps(visit func(Module, Module) bool) |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 139 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 140 | ModuleSubDir() string |
| 141 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 142 | Variable(pctx PackageContext, name, value string) |
| 143 | Rule(pctx PackageContext, name string, params RuleParams, argNames ...string) Rule |
| 144 | Build(pctx PackageContext, params BuildParams) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 145 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 146 | AddNinjaFileDeps(deps ...string) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 147 | |
| 148 | PrimaryModule() Module |
Colin Cross | 80ad04d | 2015-01-06 16:19:59 -0800 | [diff] [blame] | 149 | FinalModule() Module |
| 150 | VisitAllModuleVariants(visit func(Module)) |
Colin Cross | 036a1df | 2015-12-17 15:49:30 -0800 | [diff] [blame] | 151 | |
| 152 | GetMissingDependencies() []string |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 155 | var _ BaseModuleContext = (*baseModuleContext)(nil) |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 156 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 157 | type baseModuleContext struct { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 158 | context *Context |
| 159 | config interface{} |
| 160 | module *moduleInfo |
| 161 | errs []error |
| 162 | visitingParent *moduleInfo |
| 163 | visitingDep depInfo |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 166 | func (d *baseModuleContext) moduleInfo() *moduleInfo { |
| 167 | return d.module |
| 168 | } |
| 169 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 170 | func (d *baseModuleContext) ModuleName() string { |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 171 | return d.module.properties.Name |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 174 | func (d *baseModuleContext) ContainsProperty(name string) bool { |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 175 | _, ok := d.module.propertyPos[name] |
David Allison | 701fbad | 2014-10-29 14:51:13 -0700 | [diff] [blame] | 176 | return ok |
| 177 | } |
| 178 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 179 | func (d *baseModuleContext) ModuleDir() string { |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 180 | return filepath.Dir(d.module.relBlueprintsFile) |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 183 | func (d *baseModuleContext) Config() interface{} { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 184 | return d.config |
| 185 | } |
| 186 | |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 187 | func (d *baseModuleContext) error(err error) { |
| 188 | if err != nil { |
| 189 | d.errs = append(d.errs, err) |
| 190 | } |
| 191 | } |
| 192 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 193 | func (d *baseModuleContext) Errorf(pos scanner.Position, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 194 | format string, args ...interface{}) { |
| 195 | |
Colin Cross | 2c62844 | 2016-10-07 17:13:10 -0700 | [diff] [blame^] | 196 | d.error(&BlueprintError{ |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 197 | Err: fmt.Errorf(format, args...), |
| 198 | Pos: pos, |
| 199 | }) |
| 200 | } |
| 201 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 202 | func (d *baseModuleContext) ModuleErrorf(format string, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 203 | args ...interface{}) { |
| 204 | |
Colin Cross | 2c62844 | 2016-10-07 17:13:10 -0700 | [diff] [blame^] | 205 | d.error(&ModuleError{ |
| 206 | BlueprintError: BlueprintError{ |
| 207 | Err: fmt.Errorf(format, args...), |
| 208 | Pos: d.module.pos, |
| 209 | }, |
| 210 | module: d.module, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 211 | }) |
| 212 | } |
| 213 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 214 | func (d *baseModuleContext) PropertyErrorf(property, format string, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 215 | args ...interface{}) { |
| 216 | |
Colin Cross | a2ca92c | 2015-11-02 16:10:23 -0800 | [diff] [blame] | 217 | pos := d.module.propertyPos[property] |
| 218 | |
| 219 | if !pos.IsValid() { |
| 220 | pos = d.module.pos |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Colin Cross | 2c62844 | 2016-10-07 17:13:10 -0700 | [diff] [blame^] | 223 | d.error(&PropertyError{ |
| 224 | ModuleError: ModuleError{ |
| 225 | BlueprintError: BlueprintError{ |
| 226 | Err: fmt.Errorf(format, args...), |
| 227 | Pos: pos, |
| 228 | }, |
| 229 | module: d.module, |
| 230 | }, |
| 231 | property: property, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 232 | }) |
| 233 | } |
| 234 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 235 | func (d *baseModuleContext) Failed() bool { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 236 | return len(d.errs) > 0 |
| 237 | } |
| 238 | |
Colin Cross | 1455a0f | 2014-12-17 13:23:56 -0800 | [diff] [blame] | 239 | var _ ModuleContext = (*moduleContext)(nil) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 240 | |
Colin Cross | 1455a0f | 2014-12-17 13:23:56 -0800 | [diff] [blame] | 241 | type moduleContext struct { |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 242 | baseModuleContext |
Colin Cross | 036a1df | 2015-12-17 15:49:30 -0800 | [diff] [blame] | 243 | scope *localScope |
| 244 | ninjaFileDeps []string |
| 245 | actionDefs localBuildActions |
| 246 | handledMissingDeps bool |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 249 | func (m *baseModuleContext) OtherModuleName(logicModule Module) string { |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 250 | module := m.context.moduleInfo[logicModule] |
| 251 | return module.properties.Name |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 254 | func (m *baseModuleContext) OtherModuleErrorf(logicModule Module, format string, |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 255 | args ...interface{}) { |
| 256 | |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 257 | module := m.context.moduleInfo[logicModule] |
Colin Cross | 2c62844 | 2016-10-07 17:13:10 -0700 | [diff] [blame^] | 258 | m.errs = append(m.errs, &ModuleError{ |
| 259 | BlueprintError: BlueprintError{ |
| 260 | Err: fmt.Errorf(format, args...), |
| 261 | Pos: module.pos, |
| 262 | }, |
| 263 | module: module, |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 264 | }) |
| 265 | } |
| 266 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 267 | func (m *baseModuleContext) OtherModuleDependencyTag(logicModule Module) DependencyTag { |
| 268 | // fast path for calling OtherModuleDependencyTag from inside VisitDirectDeps |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 269 | if logicModule == m.visitingDep.module.logicModule { |
| 270 | return m.visitingDep.tag |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 273 | for _, dep := range m.visitingParent.directDeps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 274 | if dep.module.logicModule == logicModule { |
| 275 | return dep.tag |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | return nil |
Colin Cross | c7ffa30 | 2015-02-10 11:24:52 -0800 | [diff] [blame] | 280 | } |
| 281 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 282 | func (m *baseModuleContext) VisitDirectDeps(visit func(Module)) { |
| 283 | defer func() { |
| 284 | if r := recover(); r != nil { |
| 285 | panic(newPanicErrorf(r, "VisitDirectDeps(%s, %s) for dependency %s", |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 286 | m.module, funcName(visit), m.visitingDep.module)) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 287 | } |
| 288 | }() |
| 289 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 290 | m.visitingParent = m.module |
| 291 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 292 | for _, dep := range m.module.directDeps { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 293 | m.visitingDep = dep |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 294 | visit(dep.module.logicModule) |
| 295 | } |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 296 | |
| 297 | m.visitingParent = nil |
| 298 | m.visitingDep = depInfo{} |
Colin Cross | c7ffa30 | 2015-02-10 11:24:52 -0800 | [diff] [blame] | 299 | } |
| 300 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 301 | func (m *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { |
| 302 | defer func() { |
| 303 | if r := recover(); r != nil { |
| 304 | panic(newPanicErrorf(r, "VisitDirectDepsIf(%s, %s, %s) for dependency %s", |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 305 | m.module, funcName(pred), funcName(visit), m.visitingDep.module)) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 306 | } |
| 307 | }() |
| 308 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 309 | m.visitingParent = m.module |
| 310 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 311 | for _, dep := range m.module.directDeps { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 312 | m.visitingDep = dep |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 313 | if pred(dep.module.logicModule) { |
| 314 | visit(dep.module.logicModule) |
| 315 | } |
| 316 | } |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 317 | |
| 318 | m.visitingParent = nil |
| 319 | m.visitingDep = depInfo{} |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | func (m *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 323 | defer func() { |
| 324 | if r := recover(); r != nil { |
| 325 | panic(newPanicErrorf(r, "VisitDepsDepthFirst(%s, %s) for dependency %s", |
| 326 | m.module, funcName(visit), m.visitingDep.module)) |
| 327 | } |
| 328 | }() |
| 329 | |
| 330 | m.context.walkDeps(m.module, nil, func(dep depInfo, parent *moduleInfo) { |
| 331 | m.visitingParent = parent |
| 332 | m.visitingDep = dep |
| 333 | visit(dep.module.logicModule) |
| 334 | }) |
| 335 | |
| 336 | m.visitingParent = nil |
| 337 | m.visitingDep = depInfo{} |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 338 | } |
| 339 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 340 | func (m *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 341 | visit func(Module)) { |
| 342 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 343 | defer func() { |
| 344 | if r := recover(); r != nil { |
| 345 | panic(newPanicErrorf(r, "VisitDepsDepthFirstIf(%s, %s, %s) for dependency %s", |
| 346 | m.module, funcName(pred), funcName(visit), m.visitingDep.module)) |
| 347 | } |
| 348 | }() |
| 349 | |
| 350 | m.context.walkDeps(m.module, nil, func(dep depInfo, parent *moduleInfo) { |
| 351 | if pred(dep.module.logicModule) { |
| 352 | m.visitingParent = parent |
| 353 | m.visitingDep = dep |
| 354 | visit(dep.module.logicModule) |
| 355 | } |
| 356 | }) |
| 357 | |
| 358 | m.visitingParent = nil |
| 359 | m.visitingDep = depInfo{} |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 362 | func (m *baseModuleContext) WalkDeps(visit func(Module, Module) bool) { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 363 | m.context.walkDeps(m.module, func(dep depInfo, parent *moduleInfo) bool { |
| 364 | m.visitingParent = parent |
| 365 | m.visitingDep = dep |
| 366 | return visit(dep.module.logicModule, parent.logicModule) |
| 367 | }, nil) |
| 368 | |
| 369 | m.visitingParent = nil |
| 370 | m.visitingDep = depInfo{} |
Yuchen Wu | 222e245 | 2015-10-06 14:03:27 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 373 | func (m *moduleContext) ModuleSubDir() string { |
Colin Cross | e7daa22 | 2015-03-11 14:35:41 -0700 | [diff] [blame] | 374 | return m.module.variantName |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 375 | } |
| 376 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 377 | func (m *moduleContext) Variable(pctx PackageContext, name, value string) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 378 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 379 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 380 | v, err := m.scope.AddLocalVariable(name, value) |
| 381 | if err != nil { |
| 382 | panic(err) |
| 383 | } |
| 384 | |
| 385 | m.actionDefs.variables = append(m.actionDefs.variables, v) |
| 386 | } |
| 387 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 388 | func (m *moduleContext) Rule(pctx PackageContext, name string, |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 389 | params RuleParams, argNames ...string) Rule { |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 390 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 391 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 392 | |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 393 | r, err := m.scope.AddLocalRule(name, ¶ms, argNames...) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 394 | if err != nil { |
| 395 | panic(err) |
| 396 | } |
| 397 | |
| 398 | m.actionDefs.rules = append(m.actionDefs.rules, r) |
| 399 | |
| 400 | return r |
| 401 | } |
| 402 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 403 | func (m *moduleContext) Build(pctx PackageContext, params BuildParams) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 404 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 405 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 406 | def, err := parseBuildParams(m.scope, ¶ms) |
| 407 | if err != nil { |
| 408 | panic(err) |
| 409 | } |
| 410 | |
| 411 | m.actionDefs.buildDefs = append(m.actionDefs.buildDefs, def) |
| 412 | } |
| 413 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 414 | func (m *moduleContext) AddNinjaFileDeps(deps ...string) { |
| 415 | m.ninjaFileDeps = append(m.ninjaFileDeps, deps...) |
| 416 | } |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 417 | |
| 418 | func (m *moduleContext) PrimaryModule() Module { |
Colin Cross | 80ad04d | 2015-01-06 16:19:59 -0800 | [diff] [blame] | 419 | return m.module.group.modules[0].logicModule |
| 420 | } |
| 421 | |
| 422 | func (m *moduleContext) FinalModule() Module { |
| 423 | return m.module.group.modules[len(m.module.group.modules)-1].logicModule |
| 424 | } |
| 425 | |
| 426 | func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) { |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 427 | m.context.visitAllModuleVariants(m.module, visit) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Colin Cross | 036a1df | 2015-12-17 15:49:30 -0800 | [diff] [blame] | 430 | func (m *moduleContext) GetMissingDependencies() []string { |
| 431 | m.handledMissingDeps = true |
| 432 | return m.module.missingDeps |
| 433 | } |
| 434 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 435 | // |
| 436 | // MutatorContext |
| 437 | // |
| 438 | |
| 439 | type mutatorContext struct { |
| 440 | baseModuleContext |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 441 | name string |
Colin Cross | 49c279a | 2016-08-05 22:30:44 -0700 | [diff] [blame] | 442 | reverseDeps []reverseDep |
| 443 | newModules []*moduleInfo |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | type baseMutatorContext interface { |
| 447 | BaseModuleContext |
| 448 | |
| 449 | Module() Module |
| 450 | } |
| 451 | |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 452 | type EarlyMutatorContext interface { |
| 453 | baseMutatorContext |
| 454 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 455 | CreateVariations(...string) []Module |
| 456 | CreateLocalVariations(...string) []Module |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 459 | type TopDownMutatorContext interface { |
| 460 | baseMutatorContext |
| 461 | |
Colin Cross | 8d22233 | 2015-11-02 16:11:32 -0800 | [diff] [blame] | 462 | OtherModuleName(m Module) string |
| 463 | OtherModuleErrorf(m Module, fmt string, args ...interface{}) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 464 | OtherModuleDependencyTag(m Module) DependencyTag |
Colin Cross | 8d22233 | 2015-11-02 16:11:32 -0800 | [diff] [blame] | 465 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 466 | VisitDirectDeps(visit func(Module)) |
| 467 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
| 468 | VisitDepsDepthFirst(visit func(Module)) |
| 469 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
Yuchen Wu | 222e245 | 2015-10-06 14:03:27 -0700 | [diff] [blame] | 470 | WalkDeps(visit func(Module, Module) bool) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | type BottomUpMutatorContext interface { |
Colin Cross | 93c4cf6 | 2016-08-06 22:54:17 -0700 | [diff] [blame] | 474 | baseMutatorContext |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 475 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 476 | AddDependency(module Module, tag DependencyTag, name ...string) |
| 477 | AddReverseDependency(module Module, tag DependencyTag, name string) |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 478 | CreateVariations(...string) []Module |
Jamie Gennis | 6a5825e | 2015-05-19 11:26:11 -0700 | [diff] [blame] | 479 | CreateLocalVariations(...string) []Module |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 480 | SetDependencyVariation(string) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 481 | AddVariationDependencies([]Variation, DependencyTag, ...string) |
| 482 | AddFarVariationDependencies([]Variation, DependencyTag, ...string) |
Colin Cross | f187546 | 2016-04-11 17:33:13 -0700 | [diff] [blame] | 483 | AddInterVariantDependency(tag DependencyTag, from, to Module) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | // A Mutator function is called for each Module, and can use |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 487 | // MutatorContext.CreateVariations to split a Module into multiple Modules, |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 488 | // modifying properties on the new modules to differentiate them. It is called |
| 489 | // after parsing all Blueprint files, but before generating any build rules, |
| 490 | // and is always called on dependencies before being called on the depending module. |
| 491 | // |
| 492 | // The Mutator function should only modify members of properties structs, and not |
| 493 | // members of the module struct itself, to ensure the modified values are copied |
| 494 | // if a second Mutator chooses to split the module a second time. |
| 495 | type TopDownMutator func(mctx TopDownMutatorContext) |
| 496 | type BottomUpMutator func(mctx BottomUpMutatorContext) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 497 | type EarlyMutator func(mctx EarlyMutatorContext) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 498 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 499 | // DependencyTag is an interface to an arbitrary object that embeds BaseDependencyTag. It can be |
| 500 | // used to transfer information on a dependency between the mutator that called AddDependency |
| 501 | // and the GenerateBuildActions method. Variants created by CreateVariations have a copy of the |
| 502 | // interface (pointing to the same concrete object) from their original module. |
| 503 | type DependencyTag interface { |
| 504 | dependencyTag(DependencyTag) |
| 505 | } |
| 506 | |
| 507 | type BaseDependencyTag struct { |
| 508 | } |
| 509 | |
| 510 | func (BaseDependencyTag) dependencyTag(DependencyTag) { |
| 511 | } |
| 512 | |
| 513 | var _ DependencyTag = BaseDependencyTag{} |
| 514 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 515 | // Split a module into mulitple variants, one for each name in the variationNames |
| 516 | // parameter. It returns a list of new modules in the same order as the variationNames |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 517 | // list. |
| 518 | // |
| 519 | // If any of the dependencies of the module being operated on were already split |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 520 | // by calling CreateVariations with the same name, the dependency will automatically |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 521 | // be updated to point the matching variant. |
| 522 | // |
| 523 | // If a module is split, and then a module depending on the first module is not split |
| 524 | // when the Mutator is later called on it, the dependency of the depending module will |
| 525 | // automatically be updated to point to the first variant. |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 526 | func (mctx *mutatorContext) CreateVariations(variationNames ...string) []Module { |
| 527 | return mctx.createVariations(variationNames, false) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | // Split a module into mulitple variants, one for each name in the variantNames |
| 531 | // parameter. It returns a list of new modules in the same order as the variantNames |
| 532 | // list. |
| 533 | // |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 534 | // Local variations do not affect automatic dependency resolution - dependencies added |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 535 | // to the split module via deps or DynamicDependerModule must exactly match a variant |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 536 | // that contains all the non-local variations. |
| 537 | func (mctx *mutatorContext) CreateLocalVariations(variationNames ...string) []Module { |
| 538 | return mctx.createVariations(variationNames, true) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 541 | func (mctx *mutatorContext) createVariations(variationNames []string, local bool) []Module { |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 542 | ret := []Module{} |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 543 | modules, errs := mctx.context.createVariations(mctx.module, mctx.name, variationNames) |
Colin Cross | 174ae05 | 2015-03-03 17:37:03 -0800 | [diff] [blame] | 544 | if len(errs) > 0 { |
| 545 | mctx.errs = append(mctx.errs, errs...) |
| 546 | } |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 547 | |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 548 | for i, module := range modules { |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 549 | ret = append(ret, module.logicModule) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 550 | if !local { |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 551 | module.dependencyVariant[mctx.name] = variationNames[i] |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 552 | } |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Colin Cross | 49c279a | 2016-08-05 22:30:44 -0700 | [diff] [blame] | 555 | if mctx.newModules != nil { |
| 556 | panic("module already has variations from this mutator") |
| 557 | } |
| 558 | mctx.newModules = modules |
| 559 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 560 | if len(ret) != len(variationNames) { |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 561 | panic("oops!") |
| 562 | } |
| 563 | |
| 564 | return ret |
| 565 | } |
| 566 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 567 | // Set all dangling dependencies on the current module to point to the variation |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 568 | // with given name. |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 569 | func (mctx *mutatorContext) SetDependencyVariation(variationName string) { |
| 570 | mctx.context.convertDepsToVariation(mctx.module, mctx.name, variationName) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | func (mctx *mutatorContext) Module() Module { |
| 574 | return mctx.module.logicModule |
| 575 | } |
| 576 | |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 577 | // Add a dependency to the given module. |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 578 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 579 | // correctly for all future mutator passes. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 580 | func (mctx *mutatorContext) AddDependency(module Module, tag DependencyTag, deps ...string) { |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 581 | for _, dep := range deps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 582 | errs := mctx.context.addDependency(mctx.context.moduleInfo[module], tag, dep) |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 583 | if len(errs) > 0 { |
| 584 | mctx.errs = append(mctx.errs, errs...) |
| 585 | } |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 586 | } |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | // Add a dependency from the destination to the given module. |
| 590 | // Does not affect the ordering of the current mutator pass, but will be ordered |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 591 | // correctly for all future mutator passes. All reverse dependencies for a destination module are |
| 592 | // collected until the end of the mutator pass, sorted by name, and then appended to the destination |
| 593 | // module's dependency list. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 594 | func (mctx *mutatorContext) AddReverseDependency(module Module, tag DependencyTag, destName string) { |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 595 | destModule, errs := mctx.context.findReverseDependency(mctx.context.moduleInfo[module], destName) |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 596 | if len(errs) > 0 { |
| 597 | mctx.errs = append(mctx.errs, errs...) |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 598 | return |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 599 | } |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 600 | |
Colin Cross | 49c279a | 2016-08-05 22:30:44 -0700 | [diff] [blame] | 601 | mctx.reverseDeps = append(mctx.reverseDeps, reverseDep{ |
| 602 | destModule, |
| 603 | depInfo{mctx.context.moduleInfo[module], tag}, |
| 604 | }) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 605 | } |
| 606 | |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 607 | // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations |
| 608 | // argument to select which variant of the dependency to use. A variant of the dependency must |
| 609 | // exist that matches the all of the non-local variations of the current module, plus the variations |
| 610 | // argument. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 611 | func (mctx *mutatorContext) AddVariationDependencies(variations []Variation, tag DependencyTag, |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 612 | deps ...string) { |
| 613 | |
| 614 | for _, dep := range deps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 615 | errs := mctx.context.addVariationDependency(mctx.module, variations, tag, dep, false) |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 616 | if len(errs) > 0 { |
| 617 | mctx.errs = append(mctx.errs, errs...) |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the |
| 623 | // variations argument to select which variant of the dependency to use. A variant of the |
| 624 | // dependency must exist that matches the variations argument, but may also have other variations. |
| 625 | // For any unspecified variation the first variant will be used. |
| 626 | // |
| 627 | // Unlike AddVariationDependencies, the variations of the current module are ignored - the |
| 628 | // depdendency only needs to match the supplied variations. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 629 | func (mctx *mutatorContext) AddFarVariationDependencies(variations []Variation, tag DependencyTag, |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 630 | deps ...string) { |
| 631 | |
| 632 | for _, dep := range deps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 633 | errs := mctx.context.addVariationDependency(mctx.module, variations, tag, dep, true) |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 634 | if len(errs) > 0 { |
| 635 | mctx.errs = append(mctx.errs, errs...) |
| 636 | } |
| 637 | } |
| 638 | } |
Colin Cross | f187546 | 2016-04-11 17:33:13 -0700 | [diff] [blame] | 639 | |
| 640 | func (mctx *mutatorContext) AddInterVariantDependency(tag DependencyTag, from, to Module) { |
| 641 | mctx.context.addInterVariantDependency(mctx.module, tag, from, to) |
| 642 | } |