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" |
Colin Cross | c581620 | 2017-12-11 14:39:10 -0800 | [diff] [blame] | 19 | |
Colin Cross | b519a7e | 2017-02-01 13:21:35 -0800 | [diff] [blame] | 20 | "github.com/google/blueprint/pathtools" |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | type Singleton interface { |
| 24 | GenerateBuildActions(SingletonContext) |
| 25 | } |
| 26 | |
| 27 | type SingletonContext interface { |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 28 | // Config returns the config object that was passed to Context.PrepareBuildActions. |
Jamie Gennis | 6eb4d24 | 2014-06-11 18:31:16 -0700 | [diff] [blame] | 29 | Config() interface{} |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 30 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 31 | // Name returns the name of the current singleton passed to Context.RegisterSingletonType |
Colin Cross | 9226d6c | 2019-02-25 18:07:44 -0800 | [diff] [blame] | 32 | Name() string |
| 33 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 34 | // ModuleName returns the name of the given Module. See BaseModuleContext.ModuleName for more information. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 35 | ModuleName(module Module) string |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 36 | |
| 37 | // ModuleDir returns the directory of the given Module. See BaseModuleContext.ModuleDir for more information. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 38 | ModuleDir(module Module) string |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 39 | |
| 40 | // ModuleSubDir returns the unique subdirectory name of the given Module. See ModuleContext.ModuleSubDir for |
| 41 | // more information. |
Colin Cross | 8c602f7 | 2015-12-17 18:02:11 -0800 | [diff] [blame] | 42 | ModuleSubDir(module Module) string |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 43 | |
| 44 | // ModuleType returns the type of the given Module. See BaseModuleContext.ModuleType for more information. |
Dan Willemsen | c98e55b | 2016-07-25 15:51:50 -0700 | [diff] [blame] | 45 | ModuleType(module Module) string |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 46 | |
| 47 | // BlueprintFile returns the path of the Blueprint file that defined the given module. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 48 | BlueprintFile(module Module) string |
| 49 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 50 | // ModuleErrorf reports an error at the line number of the module type in the module definition. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 51 | ModuleErrorf(module Module, format string, args ...interface{}) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 52 | |
| 53 | // Errorf reports an error at the specified position of the module definition file. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 54 | Errorf(format string, args ...interface{}) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 55 | |
| 56 | // Failed returns true if any errors have been reported. In most cases the singleton can continue with generating |
| 57 | // build rules after an error, allowing it to report additional errors in a single run, but in cases where the error |
| 58 | // has prevented the singleton from creating necessary data it can return early when Failed returns true. |
Dan Willemsen | 265d92c | 2015-12-09 18:06:23 -0800 | [diff] [blame] | 59 | Failed() bool |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 60 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 61 | // Variable creates a new ninja variable scoped to the singleton. It can be referenced by calls to Rule and Build |
| 62 | // in the same singleton. |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 63 | Variable(pctx PackageContext, name, value string) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 64 | |
| 65 | // Rule creates a new ninja rule scoped to the singleton. It can be referenced by calls to Build in the same |
| 66 | // singleton. |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 67 | Rule(pctx PackageContext, name string, params RuleParams, argNames ...string) Rule |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 68 | |
| 69 | // Build creates a new ninja build statement. |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 70 | Build(pctx PackageContext, params BuildParams) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 71 | |
| 72 | // RequireNinjaVersion sets the generated ninja manifest to require at least the specified version of ninja. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 73 | RequireNinjaVersion(major, minor, micro int) |
| 74 | |
Colin Cross | a259945 | 2015-11-18 16:01:01 -0800 | [diff] [blame] | 75 | // SetNinjaBuildDir sets the value of the top-level "builddir" Ninja variable |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 76 | // that controls where Ninja stores its build log files. This value can be |
Colin Cross | a259945 | 2015-11-18 16:01:01 -0800 | [diff] [blame] | 77 | // set at most one time for a single build, later calls are ignored. |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 78 | SetNinjaBuildDir(pctx PackageContext, value string) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 79 | |
Dan Willemsen | ab223a5 | 2018-07-05 21:56:59 -0700 | [diff] [blame] | 80 | // AddSubninja adds a ninja file to include with subninja. This should likely |
| 81 | // only ever be used inside bootstrap to handle glob rules. |
| 82 | AddSubninja(file string) |
| 83 | |
Dan Willemsen | 4bb6276 | 2016-01-14 15:42:54 -0800 | [diff] [blame] | 84 | // Eval takes a string with embedded ninja variables, and returns a string |
| 85 | // with all of the variables recursively expanded. Any variables references |
| 86 | // are expanded in the scope of the PackageContext. |
| 87 | Eval(pctx PackageContext, ninjaStr string) (string, error) |
| 88 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 89 | // VisitAllModules calls visit for each defined variant of each module in an unspecified order. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 90 | VisitAllModules(visit func(Module)) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 91 | |
| 92 | // VisitAllModules calls pred for each defined variant of each module in an unspecified order, and if pred returns |
| 93 | // true calls visit. |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 94 | VisitAllModulesIf(pred func(Module) bool, visit func(Module)) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 95 | |
| 96 | // VisitDepsDepthFirst calls visit for each transitive dependency, traversing the dependency tree in depth first |
| 97 | // order. visit will only be called once for any given module, even if there are multiple paths through the |
| 98 | // dependency tree to the module or multiple direct dependencies with different tags. |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 99 | VisitDepsDepthFirst(module Module, visit func(Module)) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 100 | |
| 101 | // VisitDepsDepthFirst calls pred for each transitive dependency, and if pred returns true calls visit, traversing |
| 102 | // the dependency tree in depth first order. visit will only be called once for any given module, even if there are |
| 103 | // multiple paths through the dependency tree to the module or multiple direct dependencies with different tags. |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 104 | VisitDepsDepthFirstIf(module Module, pred func(Module) bool, |
| 105 | visit func(Module)) |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 106 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 107 | // VisitAllModuleVariants calls visit for each variant of the given module. |
Colin Cross | 24ad587 | 2015-11-17 16:22:29 -0800 | [diff] [blame] | 108 | VisitAllModuleVariants(module Module, visit func(Module)) |
| 109 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 110 | // PrimaryModule returns the first variant of the given module. This can be used to perform |
| 111 | // // singleton actions that are only done once for all variants of a module. |
Colin Cross | 24ad587 | 2015-11-17 16:22:29 -0800 | [diff] [blame] | 112 | PrimaryModule(module Module) Module |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 113 | |
| 114 | // FinalModule returns the last variant of the given module. This can be used to perform |
| 115 | // singleton actions that are only done once for all variants of a module. |
Colin Cross | 24ad587 | 2015-11-17 16:22:29 -0800 | [diff] [blame] | 116 | FinalModule(module Module) Module |
| 117 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 118 | // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The |
| 119 | // primary builder will be rerun whenever the specified files are modified. |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 120 | AddNinjaFileDeps(deps ...string) |
Colin Cross | 127d2ea | 2016-11-01 11:10:51 -0700 | [diff] [blame] | 121 | |
Dan Willemsen | b6c9023 | 2018-02-23 14:49:45 -0800 | [diff] [blame] | 122 | // GlobWithDeps returns a list of files and directories that match the |
| 123 | // specified pattern but do not match any of the patterns in excludes. |
| 124 | // Any directories will have a '/' suffix. It also adds efficient |
| 125 | // dependencies to rerun the primary builder whenever a file matching |
| 126 | // the pattern as added or removed, without rerunning if a file that |
| 127 | // does not match the pattern is added to a searched directory. |
Colin Cross | 127d2ea | 2016-11-01 11:10:51 -0700 | [diff] [blame] | 128 | GlobWithDeps(pattern string, excludes []string) ([]string, error) |
Colin Cross | b519a7e | 2017-02-01 13:21:35 -0800 | [diff] [blame] | 129 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 130 | // Fs returns a pathtools.Filesystem that can be used to interact with files. Using the Filesystem interface allows |
| 131 | // the singleton to be used in build system tests that run against a mock filesystem. |
Colin Cross | b519a7e | 2017-02-01 13:21:35 -0800 | [diff] [blame] | 132 | Fs() pathtools.FileSystem |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | var _ SingletonContext = (*singletonContext)(nil) |
| 136 | |
| 137 | type singletonContext struct { |
Colin Cross | 9226d6c | 2019-02-25 18:07:44 -0800 | [diff] [blame] | 138 | name string |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 139 | context *Context |
Jamie Gennis | 6eb4d24 | 2014-06-11 18:31:16 -0700 | [diff] [blame] | 140 | config interface{} |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 141 | scope *localScope |
Dan Willemsen | 4bb6276 | 2016-01-14 15:42:54 -0800 | [diff] [blame] | 142 | globals *liveTracker |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 143 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 144 | ninjaFileDeps []string |
| 145 | errs []error |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 146 | |
| 147 | actionDefs localBuildActions |
| 148 | } |
| 149 | |
Jamie Gennis | 6eb4d24 | 2014-06-11 18:31:16 -0700 | [diff] [blame] | 150 | func (s *singletonContext) Config() interface{} { |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 151 | return s.config |
| 152 | } |
| 153 | |
Colin Cross | 9226d6c | 2019-02-25 18:07:44 -0800 | [diff] [blame] | 154 | func (s *singletonContext) Name() string { |
| 155 | return s.name |
| 156 | } |
| 157 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 158 | func (s *singletonContext) ModuleName(logicModule Module) string { |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 159 | return s.context.ModuleName(logicModule) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 162 | func (s *singletonContext) ModuleDir(logicModule Module) string { |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 163 | return s.context.ModuleDir(logicModule) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Colin Cross | 8c602f7 | 2015-12-17 18:02:11 -0800 | [diff] [blame] | 166 | func (s *singletonContext) ModuleSubDir(logicModule Module) string { |
| 167 | return s.context.ModuleSubDir(logicModule) |
| 168 | } |
| 169 | |
Dan Willemsen | c98e55b | 2016-07-25 15:51:50 -0700 | [diff] [blame] | 170 | func (s *singletonContext) ModuleType(logicModule Module) string { |
| 171 | return s.context.ModuleType(logicModule) |
| 172 | } |
| 173 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 174 | func (s *singletonContext) BlueprintFile(logicModule Module) string { |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 175 | return s.context.BlueprintFile(logicModule) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 178 | func (s *singletonContext) error(err error) { |
| 179 | if err != nil { |
| 180 | s.errs = append(s.errs, err) |
| 181 | } |
| 182 | } |
| 183 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 184 | func (s *singletonContext) ModuleErrorf(logicModule Module, format string, |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 185 | args ...interface{}) { |
| 186 | |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 187 | s.error(s.context.ModuleErrorf(logicModule, format, args...)) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | func (s *singletonContext) Errorf(format string, args ...interface{}) { |
| 191 | // TODO: Make this not result in the error being printed as "internal error" |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 192 | s.error(fmt.Errorf(format, args...)) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Dan Willemsen | 265d92c | 2015-12-09 18:06:23 -0800 | [diff] [blame] | 195 | func (s *singletonContext) Failed() bool { |
| 196 | return len(s.errs) > 0 |
| 197 | } |
| 198 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 199 | func (s *singletonContext) Variable(pctx PackageContext, name, value string) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 200 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 201 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 202 | v, err := s.scope.AddLocalVariable(name, value) |
| 203 | if err != nil { |
| 204 | panic(err) |
| 205 | } |
| 206 | |
| 207 | s.actionDefs.variables = append(s.actionDefs.variables, v) |
| 208 | } |
| 209 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 210 | func (s *singletonContext) Rule(pctx PackageContext, name string, |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 211 | params RuleParams, argNames ...string) Rule { |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 212 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 213 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 214 | |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 215 | r, err := s.scope.AddLocalRule(name, ¶ms, argNames...) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 216 | if err != nil { |
| 217 | panic(err) |
| 218 | } |
| 219 | |
| 220 | s.actionDefs.rules = append(s.actionDefs.rules, r) |
| 221 | |
| 222 | return r |
| 223 | } |
| 224 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 225 | func (s *singletonContext) Build(pctx PackageContext, params BuildParams) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 226 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 227 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 228 | def, err := parseBuildParams(s.scope, ¶ms) |
| 229 | if err != nil { |
| 230 | panic(err) |
| 231 | } |
| 232 | |
| 233 | s.actionDefs.buildDefs = append(s.actionDefs.buildDefs, def) |
| 234 | } |
| 235 | |
Dan Willemsen | 4bb6276 | 2016-01-14 15:42:54 -0800 | [diff] [blame] | 236 | func (s *singletonContext) Eval(pctx PackageContext, str string) (string, error) { |
| 237 | s.scope.ReparentTo(pctx) |
| 238 | |
| 239 | ninjaStr, err := parseNinjaString(s.scope, str) |
| 240 | if err != nil { |
| 241 | return "", err |
| 242 | } |
| 243 | |
| 244 | err = s.globals.addNinjaStringDeps(ninjaStr) |
| 245 | if err != nil { |
| 246 | return "", err |
| 247 | } |
| 248 | |
| 249 | return ninjaStr.Eval(s.globals.variables) |
| 250 | } |
| 251 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 252 | func (s *singletonContext) RequireNinjaVersion(major, minor, micro int) { |
| 253 | s.context.requireNinjaVersion(major, minor, micro) |
| 254 | } |
| 255 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 256 | func (s *singletonContext) SetNinjaBuildDir(pctx PackageContext, value string) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 257 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 7d5b2f8 | 2014-09-24 17:51:52 -0700 | [diff] [blame] | 258 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 259 | ninjaValue, err := parseNinjaString(s.scope, value) |
| 260 | if err != nil { |
| 261 | panic(err) |
| 262 | } |
| 263 | |
Colin Cross | a259945 | 2015-11-18 16:01:01 -0800 | [diff] [blame] | 264 | s.context.setNinjaBuildDir(ninjaValue) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Dan Willemsen | ab223a5 | 2018-07-05 21:56:59 -0700 | [diff] [blame] | 267 | func (s *singletonContext) AddSubninja(file string) { |
| 268 | s.context.subninjas = append(s.context.subninjas, file) |
| 269 | } |
| 270 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 271 | func (s *singletonContext) VisitAllModules(visit func(Module)) { |
Colin Cross | 7f90d17 | 2018-09-19 13:37:29 -0700 | [diff] [blame] | 272 | var visitingModule Module |
| 273 | defer func() { |
| 274 | if r := recover(); r != nil { |
| 275 | panic(newPanicErrorf(r, "VisitAllModules(%s) for module %s", |
Colin Cross | 818af3b | 2019-03-25 15:04:09 -0700 | [diff] [blame] | 276 | funcName(visit), s.context.moduleInfo[visitingModule])) |
Colin Cross | 7f90d17 | 2018-09-19 13:37:29 -0700 | [diff] [blame] | 277 | } |
| 278 | }() |
| 279 | |
| 280 | s.context.VisitAllModules(func(m Module) { |
| 281 | visitingModule = m |
| 282 | visit(m) |
| 283 | }) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | func (s *singletonContext) VisitAllModulesIf(pred func(Module) bool, |
| 287 | visit func(Module)) { |
| 288 | |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 289 | s.context.VisitAllModulesIf(pred, visit) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 290 | } |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 291 | |
| 292 | func (s *singletonContext) VisitDepsDepthFirst(module Module, |
| 293 | visit func(Module)) { |
| 294 | |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 295 | s.context.VisitDepsDepthFirst(module, visit) |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | func (s *singletonContext) VisitDepsDepthFirstIf(module Module, |
| 299 | pred func(Module) bool, visit func(Module)) { |
| 300 | |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 301 | s.context.VisitDepsDepthFirstIf(module, pred, visit) |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 302 | } |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 303 | |
Colin Cross | 24ad587 | 2015-11-17 16:22:29 -0800 | [diff] [blame] | 304 | func (s *singletonContext) PrimaryModule(module Module) Module { |
| 305 | return s.context.PrimaryModule(module) |
| 306 | } |
| 307 | |
| 308 | func (s *singletonContext) FinalModule(module Module) Module { |
| 309 | return s.context.FinalModule(module) |
| 310 | } |
| 311 | |
| 312 | func (s *singletonContext) VisitAllModuleVariants(module Module, visit func(Module)) { |
| 313 | s.context.VisitAllModuleVariants(module, visit) |
| 314 | } |
| 315 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 316 | func (s *singletonContext) AddNinjaFileDeps(deps ...string) { |
| 317 | s.ninjaFileDeps = append(s.ninjaFileDeps, deps...) |
| 318 | } |
Colin Cross | 127d2ea | 2016-11-01 11:10:51 -0700 | [diff] [blame] | 319 | |
| 320 | func (s *singletonContext) GlobWithDeps(pattern string, |
| 321 | excludes []string) ([]string, error) { |
| 322 | return s.context.glob(pattern, excludes) |
| 323 | } |
Colin Cross | b519a7e | 2017-02-01 13:21:35 -0800 | [diff] [blame] | 324 | |
| 325 | func (s *singletonContext) Fs() pathtools.FileSystem { |
| 326 | return s.context.fs |
| 327 | } |