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 | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 196 | d.error(&Error{ |
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 | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 205 | d.error(&Error{ |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 206 | Err: fmt.Errorf(format, args...), |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 207 | Pos: d.module.pos, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 208 | }) |
| 209 | } |
| 210 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 211 | func (d *baseModuleContext) PropertyErrorf(property, format string, |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 212 | args ...interface{}) { |
| 213 | |
Colin Cross | a2ca92c | 2015-11-02 16:10:23 -0800 | [diff] [blame] | 214 | pos := d.module.propertyPos[property] |
| 215 | |
| 216 | if !pos.IsValid() { |
| 217 | pos = d.module.pos |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Colin Cross | a2ca92c | 2015-11-02 16:10:23 -0800 | [diff] [blame] | 220 | format = property + ": " + format |
| 221 | |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 222 | d.error(&Error{ |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 223 | Err: fmt.Errorf(format, args...), |
| 224 | Pos: pos, |
| 225 | }) |
| 226 | } |
| 227 | |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 228 | func (d *baseModuleContext) Failed() bool { |
Jamie Gennis | b9e87f6 | 2014-09-24 20:28:11 -0700 | [diff] [blame] | 229 | return len(d.errs) > 0 |
| 230 | } |
| 231 | |
Colin Cross | 1455a0f | 2014-12-17 13:23:56 -0800 | [diff] [blame] | 232 | var _ ModuleContext = (*moduleContext)(nil) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 233 | |
Colin Cross | 1455a0f | 2014-12-17 13:23:56 -0800 | [diff] [blame] | 234 | type moduleContext struct { |
Colin Cross | be1a9a1 | 2014-12-18 11:05:45 -0800 | [diff] [blame] | 235 | baseModuleContext |
Colin Cross | 036a1df | 2015-12-17 15:49:30 -0800 | [diff] [blame] | 236 | scope *localScope |
| 237 | ninjaFileDeps []string |
| 238 | actionDefs localBuildActions |
| 239 | handledMissingDeps bool |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 242 | func (m *baseModuleContext) OtherModuleName(logicModule Module) string { |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 243 | module := m.context.moduleInfo[logicModule] |
| 244 | return module.properties.Name |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 247 | func (m *baseModuleContext) OtherModuleErrorf(logicModule Module, format string, |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 248 | args ...interface{}) { |
| 249 | |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 250 | module := m.context.moduleInfo[logicModule] |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 251 | m.errs = append(m.errs, &Error{ |
| 252 | Err: fmt.Errorf(format, args...), |
Colin Cross | ed342d9 | 2015-03-11 00:57:25 -0700 | [diff] [blame] | 253 | Pos: module.pos, |
Jamie Gennis | d4c53d8 | 2014-06-22 17:02:55 -0700 | [diff] [blame] | 254 | }) |
| 255 | } |
| 256 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 257 | func (m *baseModuleContext) OtherModuleDependencyTag(logicModule Module) DependencyTag { |
| 258 | // fast path for calling OtherModuleDependencyTag from inside VisitDirectDeps |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 259 | if logicModule == m.visitingDep.module.logicModule { |
| 260 | return m.visitingDep.tag |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 263 | for _, dep := range m.visitingParent.directDeps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 264 | if dep.module.logicModule == logicModule { |
| 265 | return dep.tag |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | return nil |
Colin Cross | c7ffa30 | 2015-02-10 11:24:52 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 272 | func (m *baseModuleContext) VisitDirectDeps(visit func(Module)) { |
| 273 | defer func() { |
| 274 | if r := recover(); r != nil { |
| 275 | panic(newPanicErrorf(r, "VisitDirectDeps(%s, %s) for dependency %s", |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 276 | m.module, funcName(visit), m.visitingDep.module)) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 277 | } |
| 278 | }() |
| 279 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 280 | m.visitingParent = m.module |
| 281 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 282 | for _, dep := range m.module.directDeps { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 283 | m.visitingDep = dep |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 284 | visit(dep.module.logicModule) |
| 285 | } |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 286 | |
| 287 | m.visitingParent = nil |
| 288 | m.visitingDep = depInfo{} |
Colin Cross | c7ffa30 | 2015-02-10 11:24:52 -0800 | [diff] [blame] | 289 | } |
| 290 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 291 | func (m *baseModuleContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { |
| 292 | defer func() { |
| 293 | if r := recover(); r != nil { |
| 294 | panic(newPanicErrorf(r, "VisitDirectDepsIf(%s, %s, %s) for dependency %s", |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 295 | m.module, funcName(pred), funcName(visit), m.visitingDep.module)) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 296 | } |
| 297 | }() |
| 298 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 299 | m.visitingParent = m.module |
| 300 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 301 | for _, dep := range m.module.directDeps { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 302 | m.visitingDep = dep |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 303 | if pred(dep.module.logicModule) { |
| 304 | visit(dep.module.logicModule) |
| 305 | } |
| 306 | } |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 307 | |
| 308 | m.visitingParent = nil |
| 309 | m.visitingDep = depInfo{} |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | func (m *baseModuleContext) VisitDepsDepthFirst(visit func(Module)) { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 313 | defer func() { |
| 314 | if r := recover(); r != nil { |
| 315 | panic(newPanicErrorf(r, "VisitDepsDepthFirst(%s, %s) for dependency %s", |
| 316 | m.module, funcName(visit), m.visitingDep.module)) |
| 317 | } |
| 318 | }() |
| 319 | |
| 320 | m.context.walkDeps(m.module, nil, func(dep depInfo, parent *moduleInfo) { |
| 321 | m.visitingParent = parent |
| 322 | m.visitingDep = dep |
| 323 | visit(dep.module.logicModule) |
| 324 | }) |
| 325 | |
| 326 | m.visitingParent = nil |
| 327 | m.visitingDep = depInfo{} |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 328 | } |
| 329 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 330 | func (m *baseModuleContext) VisitDepsDepthFirstIf(pred func(Module) bool, |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 331 | visit func(Module)) { |
| 332 | |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 333 | defer func() { |
| 334 | if r := recover(); r != nil { |
| 335 | panic(newPanicErrorf(r, "VisitDepsDepthFirstIf(%s, %s, %s) for dependency %s", |
| 336 | m.module, funcName(pred), funcName(visit), m.visitingDep.module)) |
| 337 | } |
| 338 | }() |
| 339 | |
| 340 | m.context.walkDeps(m.module, nil, func(dep depInfo, parent *moduleInfo) { |
| 341 | if pred(dep.module.logicModule) { |
| 342 | m.visitingParent = parent |
| 343 | m.visitingDep = dep |
| 344 | visit(dep.module.logicModule) |
| 345 | } |
| 346 | }) |
| 347 | |
| 348 | m.visitingParent = nil |
| 349 | m.visitingDep = depInfo{} |
Colin Cross | b2e7b5d | 2014-11-11 14:18:53 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 352 | func (m *baseModuleContext) WalkDeps(visit func(Module, Module) bool) { |
Colin Cross | bafd5f5 | 2016-08-06 22:52:01 -0700 | [diff] [blame] | 353 | m.context.walkDeps(m.module, func(dep depInfo, parent *moduleInfo) bool { |
| 354 | m.visitingParent = parent |
| 355 | m.visitingDep = dep |
| 356 | return visit(dep.module.logicModule, parent.logicModule) |
| 357 | }, nil) |
| 358 | |
| 359 | m.visitingParent = nil |
| 360 | m.visitingDep = depInfo{} |
Yuchen Wu | 222e245 | 2015-10-06 14:03:27 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 363 | func (m *moduleContext) ModuleSubDir() string { |
Colin Cross | e7daa22 | 2015-03-11 14:35:41 -0700 | [diff] [blame] | 364 | return m.module.variantName |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 367 | func (m *moduleContext) Variable(pctx PackageContext, name, value string) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 368 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 369 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 370 | v, err := m.scope.AddLocalVariable(name, value) |
| 371 | if err != nil { |
| 372 | panic(err) |
| 373 | } |
| 374 | |
| 375 | m.actionDefs.variables = append(m.actionDefs.variables, v) |
| 376 | } |
| 377 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 378 | func (m *moduleContext) Rule(pctx PackageContext, name string, |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 379 | params RuleParams, argNames ...string) Rule { |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 380 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 381 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 382 | |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 383 | r, err := m.scope.AddLocalRule(name, ¶ms, argNames...) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 384 | if err != nil { |
| 385 | panic(err) |
| 386 | } |
| 387 | |
| 388 | m.actionDefs.rules = append(m.actionDefs.rules, r) |
| 389 | |
| 390 | return r |
| 391 | } |
| 392 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 393 | func (m *moduleContext) Build(pctx PackageContext, params BuildParams) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 394 | m.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 395 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 396 | def, err := parseBuildParams(m.scope, ¶ms) |
| 397 | if err != nil { |
| 398 | panic(err) |
| 399 | } |
| 400 | |
| 401 | m.actionDefs.buildDefs = append(m.actionDefs.buildDefs, def) |
| 402 | } |
| 403 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 404 | func (m *moduleContext) AddNinjaFileDeps(deps ...string) { |
| 405 | m.ninjaFileDeps = append(m.ninjaFileDeps, deps...) |
| 406 | } |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 407 | |
| 408 | func (m *moduleContext) PrimaryModule() Module { |
Colin Cross | 80ad04d | 2015-01-06 16:19:59 -0800 | [diff] [blame] | 409 | return m.module.group.modules[0].logicModule |
| 410 | } |
| 411 | |
| 412 | func (m *moduleContext) FinalModule() Module { |
| 413 | return m.module.group.modules[len(m.module.group.modules)-1].logicModule |
| 414 | } |
| 415 | |
| 416 | func (m *moduleContext) VisitAllModuleVariants(visit func(Module)) { |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 417 | m.context.visitAllModuleVariants(m.module, visit) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Colin Cross | 036a1df | 2015-12-17 15:49:30 -0800 | [diff] [blame] | 420 | func (m *moduleContext) GetMissingDependencies() []string { |
| 421 | m.handledMissingDeps = true |
| 422 | return m.module.missingDeps |
| 423 | } |
| 424 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 425 | // |
| 426 | // MutatorContext |
| 427 | // |
| 428 | |
| 429 | type mutatorContext struct { |
| 430 | baseModuleContext |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 431 | name string |
Colin Cross | 49c279a | 2016-08-05 22:30:44 -0700 | [diff] [blame^] | 432 | reverseDeps []reverseDep |
| 433 | newModules []*moduleInfo |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | type baseMutatorContext interface { |
| 437 | BaseModuleContext |
| 438 | |
| 439 | Module() Module |
| 440 | } |
| 441 | |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 442 | type EarlyMutatorContext interface { |
| 443 | baseMutatorContext |
| 444 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 445 | CreateVariations(...string) []Module |
| 446 | CreateLocalVariations(...string) []Module |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 449 | type TopDownMutatorContext interface { |
| 450 | baseMutatorContext |
| 451 | |
Colin Cross | 8d22233 | 2015-11-02 16:11:32 -0800 | [diff] [blame] | 452 | OtherModuleName(m Module) string |
| 453 | OtherModuleErrorf(m Module, fmt string, args ...interface{}) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 454 | OtherModuleDependencyTag(m Module) DependencyTag |
Colin Cross | 8d22233 | 2015-11-02 16:11:32 -0800 | [diff] [blame] | 455 | |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 456 | VisitDirectDeps(visit func(Module)) |
| 457 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) |
| 458 | VisitDepsDepthFirst(visit func(Module)) |
| 459 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) |
Yuchen Wu | 222e245 | 2015-10-06 14:03:27 -0700 | [diff] [blame] | 460 | WalkDeps(visit func(Module, Module) bool) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | type BottomUpMutatorContext interface { |
Colin Cross | 93c4cf6 | 2016-08-06 22:54:17 -0700 | [diff] [blame] | 464 | baseMutatorContext |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 465 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 466 | AddDependency(module Module, tag DependencyTag, name ...string) |
| 467 | AddReverseDependency(module Module, tag DependencyTag, name string) |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 468 | CreateVariations(...string) []Module |
Jamie Gennis | 6a5825e | 2015-05-19 11:26:11 -0700 | [diff] [blame] | 469 | CreateLocalVariations(...string) []Module |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 470 | SetDependencyVariation(string) |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 471 | AddVariationDependencies([]Variation, DependencyTag, ...string) |
| 472 | AddFarVariationDependencies([]Variation, DependencyTag, ...string) |
Colin Cross | f187546 | 2016-04-11 17:33:13 -0700 | [diff] [blame] | 473 | AddInterVariantDependency(tag DependencyTag, from, to Module) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | // A Mutator function is called for each Module, and can use |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 477 | // MutatorContext.CreateVariations to split a Module into multiple Modules, |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 478 | // modifying properties on the new modules to differentiate them. It is called |
| 479 | // after parsing all Blueprint files, but before generating any build rules, |
| 480 | // and is always called on dependencies before being called on the depending module. |
| 481 | // |
| 482 | // The Mutator function should only modify members of properties structs, and not |
| 483 | // members of the module struct itself, to ensure the modified values are copied |
| 484 | // if a second Mutator chooses to split the module a second time. |
| 485 | type TopDownMutator func(mctx TopDownMutatorContext) |
| 486 | type BottomUpMutator func(mctx BottomUpMutatorContext) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 487 | type EarlyMutator func(mctx EarlyMutatorContext) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 488 | |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 489 | // DependencyTag is an interface to an arbitrary object that embeds BaseDependencyTag. It can be |
| 490 | // used to transfer information on a dependency between the mutator that called AddDependency |
| 491 | // and the GenerateBuildActions method. Variants created by CreateVariations have a copy of the |
| 492 | // interface (pointing to the same concrete object) from their original module. |
| 493 | type DependencyTag interface { |
| 494 | dependencyTag(DependencyTag) |
| 495 | } |
| 496 | |
| 497 | type BaseDependencyTag struct { |
| 498 | } |
| 499 | |
| 500 | func (BaseDependencyTag) dependencyTag(DependencyTag) { |
| 501 | } |
| 502 | |
| 503 | var _ DependencyTag = BaseDependencyTag{} |
| 504 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 505 | // Split a module into mulitple variants, one for each name in the variationNames |
| 506 | // 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] | 507 | // list. |
| 508 | // |
| 509 | // 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] | 510 | // by calling CreateVariations with the same name, the dependency will automatically |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 511 | // be updated to point the matching variant. |
| 512 | // |
| 513 | // If a module is split, and then a module depending on the first module is not split |
| 514 | // when the Mutator is later called on it, the dependency of the depending module will |
| 515 | // automatically be updated to point to the first variant. |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 516 | func (mctx *mutatorContext) CreateVariations(variationNames ...string) []Module { |
| 517 | return mctx.createVariations(variationNames, false) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | // Split a module into mulitple variants, one for each name in the variantNames |
| 521 | // parameter. It returns a list of new modules in the same order as the variantNames |
| 522 | // list. |
| 523 | // |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 524 | // Local variations do not affect automatic dependency resolution - dependencies added |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 525 | // 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] | 526 | // that contains all the non-local variations. |
| 527 | func (mctx *mutatorContext) CreateLocalVariations(variationNames ...string) []Module { |
| 528 | return mctx.createVariations(variationNames, true) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 531 | func (mctx *mutatorContext) createVariations(variationNames []string, local bool) []Module { |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 532 | ret := []Module{} |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 533 | modules, errs := mctx.context.createVariations(mctx.module, mctx.name, variationNames) |
Colin Cross | 174ae05 | 2015-03-03 17:37:03 -0800 | [diff] [blame] | 534 | if len(errs) > 0 { |
| 535 | mctx.errs = append(mctx.errs, errs...) |
| 536 | } |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 537 | |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 538 | for i, module := range modules { |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 539 | ret = append(ret, module.logicModule) |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 540 | if !local { |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 541 | module.dependencyVariant[mctx.name] = variationNames[i] |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 542 | } |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 543 | } |
| 544 | |
Colin Cross | 49c279a | 2016-08-05 22:30:44 -0700 | [diff] [blame^] | 545 | if mctx.newModules != nil { |
| 546 | panic("module already has variations from this mutator") |
| 547 | } |
| 548 | mctx.newModules = modules |
| 549 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 550 | if len(ret) != len(variationNames) { |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 551 | panic("oops!") |
| 552 | } |
| 553 | |
| 554 | return ret |
| 555 | } |
| 556 | |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 557 | // 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] | 558 | // with given name. |
Colin Cross | f5e34b9 | 2015-03-13 16:02:36 -0700 | [diff] [blame] | 559 | func (mctx *mutatorContext) SetDependencyVariation(variationName string) { |
| 560 | mctx.context.convertDepsToVariation(mctx.module, mctx.name, variationName) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | func (mctx *mutatorContext) Module() Module { |
| 564 | return mctx.module.logicModule |
| 565 | } |
| 566 | |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 567 | // Add a dependency to the given module. |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 568 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 569 | // correctly for all future mutator passes. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 570 | func (mctx *mutatorContext) AddDependency(module Module, tag DependencyTag, deps ...string) { |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 571 | for _, dep := range deps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 572 | errs := mctx.context.addDependency(mctx.context.moduleInfo[module], tag, dep) |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 573 | if len(errs) > 0 { |
| 574 | mctx.errs = append(mctx.errs, errs...) |
| 575 | } |
Colin Cross | 65569e4 | 2015-03-10 20:08:19 -0700 | [diff] [blame] | 576 | } |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | // Add a dependency from the destination to the given module. |
| 580 | // 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] | 581 | // correctly for all future mutator passes. All reverse dependencies for a destination module are |
| 582 | // collected until the end of the mutator pass, sorted by name, and then appended to the destination |
| 583 | // module's dependency list. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 584 | func (mctx *mutatorContext) AddReverseDependency(module Module, tag DependencyTag, destName string) { |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 585 | destModule, errs := mctx.context.findReverseDependency(mctx.context.moduleInfo[module], destName) |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 586 | if len(errs) > 0 { |
| 587 | mctx.errs = append(mctx.errs, errs...) |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 588 | return |
Dan Willemsen | fdeb724 | 2015-07-24 16:53:27 -0700 | [diff] [blame] | 589 | } |
Colin Cross | 8d8a7af | 2015-11-03 16:41:29 -0800 | [diff] [blame] | 590 | |
Colin Cross | 49c279a | 2016-08-05 22:30:44 -0700 | [diff] [blame^] | 591 | mctx.reverseDeps = append(mctx.reverseDeps, reverseDep{ |
| 592 | destModule, |
| 593 | depInfo{mctx.context.moduleInfo[module], tag}, |
| 594 | }) |
Colin Cross | c902848 | 2014-12-18 16:28:54 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 597 | // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations |
| 598 | // argument to select which variant of the dependency to use. A variant of the dependency must |
| 599 | // exist that matches the all of the non-local variations of the current module, plus the variations |
| 600 | // argument. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 601 | func (mctx *mutatorContext) AddVariationDependencies(variations []Variation, tag DependencyTag, |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 602 | deps ...string) { |
| 603 | |
| 604 | for _, dep := range deps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 605 | errs := mctx.context.addVariationDependency(mctx.module, variations, tag, dep, false) |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 606 | if len(errs) > 0 { |
| 607 | mctx.errs = append(mctx.errs, errs...) |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the |
| 613 | // variations argument to select which variant of the dependency to use. A variant of the |
| 614 | // dependency must exist that matches the variations argument, but may also have other variations. |
| 615 | // For any unspecified variation the first variant will be used. |
| 616 | // |
| 617 | // Unlike AddVariationDependencies, the variations of the current module are ignored - the |
| 618 | // depdendency only needs to match the supplied variations. |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 619 | func (mctx *mutatorContext) AddFarVariationDependencies(variations []Variation, tag DependencyTag, |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 620 | deps ...string) { |
| 621 | |
| 622 | for _, dep := range deps { |
Colin Cross | 2c1f3d1 | 2016-04-11 15:47:28 -0700 | [diff] [blame] | 623 | errs := mctx.context.addVariationDependency(mctx.module, variations, tag, dep, true) |
Colin Cross | 763b6f1 | 2015-10-29 15:32:56 -0700 | [diff] [blame] | 624 | if len(errs) > 0 { |
| 625 | mctx.errs = append(mctx.errs, errs...) |
| 626 | } |
| 627 | } |
| 628 | } |
Colin Cross | f187546 | 2016-04-11 17:33:13 -0700 | [diff] [blame] | 629 | |
| 630 | func (mctx *mutatorContext) AddInterVariantDependency(tag DependencyTag, from, to Module) { |
| 631 | mctx.context.addInterVariantDependency(mctx.module, tag, from, to) |
| 632 | } |