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 | |
Ulya Trafimovich | 811381a | 2019-09-20 12:01:01 +0100 | [diff] [blame] | 96 | // VisitDirectDeps calls visit for each direct dependency of the Module. If there are |
| 97 | // multiple direct dependencies on the same module visit will be called multiple times on |
| 98 | // that module and OtherModuleDependencyTag will return a different tag for each. |
| 99 | // |
| 100 | // The Module passed to the visit function should not be retained outside of the visit |
| 101 | // function, it may be invalidated by future mutators. |
| 102 | VisitDirectDeps(module Module, visit func(Module)) |
| 103 | |
| 104 | // VisitDirectDepsIf calls pred for each direct dependency of the Module, and if pred |
| 105 | // returns true calls visit. If there are multiple direct dependencies on the same module |
| 106 | // pred and visit will be called multiple times on that module and OtherModuleDependencyTag |
| 107 | // will return a different tag for each. |
| 108 | // |
| 109 | // The Module passed to the visit function should not be retained outside of the visit |
| 110 | // function, it may be invalidated by future mutators. |
| 111 | VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module)) |
| 112 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 113 | // VisitDepsDepthFirst calls visit for each transitive dependency, traversing the dependency tree in depth first |
| 114 | // order. visit will only be called once for any given module, even if there are multiple paths through the |
| 115 | // dependency tree to the module or multiple direct dependencies with different tags. |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 116 | VisitDepsDepthFirst(module Module, visit func(Module)) |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 117 | |
| 118 | // VisitDepsDepthFirst calls pred for each transitive dependency, and if pred returns true calls visit, traversing |
| 119 | // the dependency tree in depth first order. visit will only be called once for any given module, even if there are |
| 120 | // 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] | 121 | VisitDepsDepthFirstIf(module Module, pred func(Module) bool, |
| 122 | visit func(Module)) |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 123 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 124 | // VisitAllModuleVariants calls visit for each variant of the given module. |
Colin Cross | 24ad587 | 2015-11-17 16:22:29 -0800 | [diff] [blame] | 125 | VisitAllModuleVariants(module Module, visit func(Module)) |
| 126 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 127 | // PrimaryModule returns the first variant of the given module. This can be used to perform |
| 128 | // // 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] | 129 | PrimaryModule(module Module) Module |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 130 | |
| 131 | // FinalModule returns the last variant of the given module. This can be used to perform |
| 132 | // 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] | 133 | FinalModule(module Module) Module |
| 134 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 135 | // AddNinjaFileDeps adds dependencies on the specified files to the rule that creates the ninja manifest. The |
| 136 | // primary builder will be rerun whenever the specified files are modified. |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 137 | AddNinjaFileDeps(deps ...string) |
Colin Cross | 127d2ea | 2016-11-01 11:10:51 -0700 | [diff] [blame] | 138 | |
Dan Willemsen | b6c9023 | 2018-02-23 14:49:45 -0800 | [diff] [blame] | 139 | // GlobWithDeps returns a list of files and directories that match the |
| 140 | // specified pattern but do not match any of the patterns in excludes. |
| 141 | // Any directories will have a '/' suffix. It also adds efficient |
| 142 | // dependencies to rerun the primary builder whenever a file matching |
| 143 | // the pattern as added or removed, without rerunning if a file that |
| 144 | // does not match the pattern is added to a searched directory. |
Colin Cross | 127d2ea | 2016-11-01 11:10:51 -0700 | [diff] [blame] | 145 | GlobWithDeps(pattern string, excludes []string) ([]string, error) |
Colin Cross | b519a7e | 2017-02-01 13:21:35 -0800 | [diff] [blame] | 146 | |
Colin Cross | 7bcc256 | 2019-05-20 14:51:55 -0700 | [diff] [blame] | 147 | // Fs returns a pathtools.Filesystem that can be used to interact with files. Using the Filesystem interface allows |
| 148 | // 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] | 149 | Fs() pathtools.FileSystem |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | var _ SingletonContext = (*singletonContext)(nil) |
| 153 | |
| 154 | type singletonContext struct { |
Colin Cross | 9226d6c | 2019-02-25 18:07:44 -0800 | [diff] [blame] | 155 | name string |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 156 | context *Context |
Jamie Gennis | 6eb4d24 | 2014-06-11 18:31:16 -0700 | [diff] [blame] | 157 | config interface{} |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 158 | scope *localScope |
Dan Willemsen | 4bb6276 | 2016-01-14 15:42:54 -0800 | [diff] [blame] | 159 | globals *liveTracker |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 160 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 161 | ninjaFileDeps []string |
| 162 | errs []error |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 163 | |
| 164 | actionDefs localBuildActions |
| 165 | } |
| 166 | |
Jamie Gennis | 6eb4d24 | 2014-06-11 18:31:16 -0700 | [diff] [blame] | 167 | func (s *singletonContext) Config() interface{} { |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 168 | return s.config |
| 169 | } |
| 170 | |
Colin Cross | 9226d6c | 2019-02-25 18:07:44 -0800 | [diff] [blame] | 171 | func (s *singletonContext) Name() string { |
| 172 | return s.name |
| 173 | } |
| 174 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 175 | func (s *singletonContext) ModuleName(logicModule Module) string { |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 176 | return s.context.ModuleName(logicModule) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 179 | func (s *singletonContext) ModuleDir(logicModule Module) string { |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 180 | return s.context.ModuleDir(logicModule) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Colin Cross | 8c602f7 | 2015-12-17 18:02:11 -0800 | [diff] [blame] | 183 | func (s *singletonContext) ModuleSubDir(logicModule Module) string { |
| 184 | return s.context.ModuleSubDir(logicModule) |
| 185 | } |
| 186 | |
Dan Willemsen | c98e55b | 2016-07-25 15:51:50 -0700 | [diff] [blame] | 187 | func (s *singletonContext) ModuleType(logicModule Module) string { |
| 188 | return s.context.ModuleType(logicModule) |
| 189 | } |
| 190 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 191 | func (s *singletonContext) BlueprintFile(logicModule Module) string { |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 192 | return s.context.BlueprintFile(logicModule) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 195 | func (s *singletonContext) error(err error) { |
| 196 | if err != nil { |
| 197 | s.errs = append(s.errs, err) |
| 198 | } |
| 199 | } |
| 200 | |
Colin Cross | bbfa51a | 2014-12-17 16:12:41 -0800 | [diff] [blame] | 201 | func (s *singletonContext) ModuleErrorf(logicModule Module, format string, |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 202 | args ...interface{}) { |
| 203 | |
Colin Cross | 0aa6a5f | 2016-01-07 13:43:09 -0800 | [diff] [blame] | 204 | s.error(s.context.ModuleErrorf(logicModule, format, args...)) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | func (s *singletonContext) Errorf(format string, args ...interface{}) { |
| 208 | // 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] | 209 | s.error(fmt.Errorf(format, args...)) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Dan Willemsen | 265d92c | 2015-12-09 18:06:23 -0800 | [diff] [blame] | 212 | func (s *singletonContext) Failed() bool { |
| 213 | return len(s.errs) > 0 |
| 214 | } |
| 215 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 216 | func (s *singletonContext) Variable(pctx PackageContext, name, value string) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 217 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 218 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 219 | v, err := s.scope.AddLocalVariable(name, value) |
| 220 | if err != nil { |
| 221 | panic(err) |
| 222 | } |
| 223 | |
| 224 | s.actionDefs.variables = append(s.actionDefs.variables, v) |
| 225 | } |
| 226 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 227 | func (s *singletonContext) Rule(pctx PackageContext, name string, |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 228 | params RuleParams, argNames ...string) Rule { |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 229 | |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 230 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 231 | |
Jamie Gennis | cbc6f86 | 2014-06-05 20:00:22 -0700 | [diff] [blame] | 232 | r, err := s.scope.AddLocalRule(name, ¶ms, argNames...) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 233 | if err != nil { |
| 234 | panic(err) |
| 235 | } |
| 236 | |
| 237 | s.actionDefs.rules = append(s.actionDefs.rules, r) |
| 238 | |
| 239 | return r |
| 240 | } |
| 241 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 242 | func (s *singletonContext) Build(pctx PackageContext, params BuildParams) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 243 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 0ed63ef | 2014-06-30 18:07:17 -0700 | [diff] [blame] | 244 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 245 | def, err := parseBuildParams(s.scope, ¶ms) |
| 246 | if err != nil { |
| 247 | panic(err) |
| 248 | } |
| 249 | |
| 250 | s.actionDefs.buildDefs = append(s.actionDefs.buildDefs, def) |
| 251 | } |
| 252 | |
Dan Willemsen | 4bb6276 | 2016-01-14 15:42:54 -0800 | [diff] [blame] | 253 | func (s *singletonContext) Eval(pctx PackageContext, str string) (string, error) { |
| 254 | s.scope.ReparentTo(pctx) |
| 255 | |
| 256 | ninjaStr, err := parseNinjaString(s.scope, str) |
| 257 | if err != nil { |
| 258 | return "", err |
| 259 | } |
| 260 | |
| 261 | err = s.globals.addNinjaStringDeps(ninjaStr) |
| 262 | if err != nil { |
| 263 | return "", err |
| 264 | } |
| 265 | |
| 266 | return ninjaStr.Eval(s.globals.variables) |
| 267 | } |
| 268 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 269 | func (s *singletonContext) RequireNinjaVersion(major, minor, micro int) { |
| 270 | s.context.requireNinjaVersion(major, minor, micro) |
| 271 | } |
| 272 | |
Dan Willemsen | aeffbf7 | 2015-11-25 15:29:32 -0800 | [diff] [blame] | 273 | func (s *singletonContext) SetNinjaBuildDir(pctx PackageContext, value string) { |
Jamie Gennis | 2fb2095 | 2014-10-03 02:49:58 -0700 | [diff] [blame] | 274 | s.scope.ReparentTo(pctx) |
Jamie Gennis | 7d5b2f8 | 2014-09-24 17:51:52 -0700 | [diff] [blame] | 275 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 276 | ninjaValue, err := parseNinjaString(s.scope, value) |
| 277 | if err != nil { |
| 278 | panic(err) |
| 279 | } |
| 280 | |
Colin Cross | a259945 | 2015-11-18 16:01:01 -0800 | [diff] [blame] | 281 | s.context.setNinjaBuildDir(ninjaValue) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Dan Willemsen | ab223a5 | 2018-07-05 21:56:59 -0700 | [diff] [blame] | 284 | func (s *singletonContext) AddSubninja(file string) { |
| 285 | s.context.subninjas = append(s.context.subninjas, file) |
| 286 | } |
| 287 | |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 288 | func (s *singletonContext) VisitAllModules(visit func(Module)) { |
Colin Cross | 7f90d17 | 2018-09-19 13:37:29 -0700 | [diff] [blame] | 289 | var visitingModule Module |
| 290 | defer func() { |
| 291 | if r := recover(); r != nil { |
| 292 | panic(newPanicErrorf(r, "VisitAllModules(%s) for module %s", |
Colin Cross | 818af3b | 2019-03-25 15:04:09 -0700 | [diff] [blame] | 293 | funcName(visit), s.context.moduleInfo[visitingModule])) |
Colin Cross | 7f90d17 | 2018-09-19 13:37:29 -0700 | [diff] [blame] | 294 | } |
| 295 | }() |
| 296 | |
| 297 | s.context.VisitAllModules(func(m Module) { |
| 298 | visitingModule = m |
| 299 | visit(m) |
| 300 | }) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | func (s *singletonContext) VisitAllModulesIf(pred func(Module) bool, |
| 304 | visit func(Module)) { |
| 305 | |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 306 | s.context.VisitAllModulesIf(pred, visit) |
Jamie Gennis | 1bc967e | 2014-05-27 16:34:41 -0700 | [diff] [blame] | 307 | } |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 308 | |
Ulya Trafimovich | 811381a | 2019-09-20 12:01:01 +0100 | [diff] [blame] | 309 | func (s *singletonContext) VisitDirectDeps(module Module, visit func(Module)) { |
| 310 | s.context.VisitDirectDeps(module, visit) |
| 311 | } |
| 312 | |
| 313 | func (s *singletonContext) VisitDirectDepsIf(module Module, pred func(Module) bool, visit func(Module)) { |
| 314 | s.context.VisitDirectDepsIf(module, pred, visit) |
| 315 | } |
| 316 | |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 317 | func (s *singletonContext) VisitDepsDepthFirst(module Module, |
| 318 | visit func(Module)) { |
| 319 | |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 320 | s.context.VisitDepsDepthFirst(module, visit) |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | func (s *singletonContext) VisitDepsDepthFirstIf(module Module, |
| 324 | pred func(Module) bool, visit func(Module)) { |
| 325 | |
Colin Cross | 4572edd | 2015-05-13 14:36:24 -0700 | [diff] [blame] | 326 | s.context.VisitDepsDepthFirstIf(module, pred, visit) |
Jamie Gennis | e98b8a9 | 2014-06-17 10:24:24 -0700 | [diff] [blame] | 327 | } |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 328 | |
Colin Cross | 24ad587 | 2015-11-17 16:22:29 -0800 | [diff] [blame] | 329 | func (s *singletonContext) PrimaryModule(module Module) Module { |
| 330 | return s.context.PrimaryModule(module) |
| 331 | } |
| 332 | |
| 333 | func (s *singletonContext) FinalModule(module Module) Module { |
| 334 | return s.context.FinalModule(module) |
| 335 | } |
| 336 | |
| 337 | func (s *singletonContext) VisitAllModuleVariants(module Module, visit func(Module)) { |
| 338 | s.context.VisitAllModuleVariants(module, visit) |
| 339 | } |
| 340 | |
Mathias Agopian | 5b8477d | 2014-06-25 17:21:54 -0700 | [diff] [blame] | 341 | func (s *singletonContext) AddNinjaFileDeps(deps ...string) { |
| 342 | s.ninjaFileDeps = append(s.ninjaFileDeps, deps...) |
| 343 | } |
Colin Cross | 127d2ea | 2016-11-01 11:10:51 -0700 | [diff] [blame] | 344 | |
| 345 | func (s *singletonContext) GlobWithDeps(pattern string, |
| 346 | excludes []string) ([]string, error) { |
| 347 | return s.context.glob(pattern, excludes) |
| 348 | } |
Colin Cross | b519a7e | 2017-02-01 13:21:35 -0800 | [diff] [blame] | 349 | |
| 350 | func (s *singletonContext) Fs() pathtools.FileSystem { |
| 351 | return s.context.fs |
| 352 | } |