| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 |  | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 16 |  | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 17 | import ( | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 18 | "github.com/google/blueprint" | 
| Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 19 | "github.com/google/blueprint/proptools" | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 20 | ) | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 21 |  | 
| Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 22 | // Phases: | 
|  | 23 | //   run Pre-arch mutators | 
|  | 24 | //   run archMutator | 
|  | 25 | //   run Pre-deps mutators | 
|  | 26 | //   run depsMutator | 
|  | 27 | //   run PostDeps mutators | 
|  | 28 | //   continue on to GenerateAndroidBuildActions | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 29 |  | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 30 | func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) { | 
|  | 31 | for _, t := range mutators { | 
|  | 32 | var handle blueprint.MutatorHandle | 
|  | 33 | if t.bottomUpMutator != nil { | 
|  | 34 | handle = ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator) | 
|  | 35 | } else if t.topDownMutator != nil { | 
|  | 36 | handle = ctx.RegisterTopDownMutator(t.name, t.topDownMutator) | 
|  | 37 | } | 
|  | 38 | if t.parallel { | 
|  | 39 | handle.Parallel() | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 40 | } | 
|  | 41 | } | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 42 | } | 
|  | 43 |  | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 44 | func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps []RegisterMutatorFunc) { | 
|  | 45 | mctx := ®isterMutatorsContext{} | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 46 |  | 
|  | 47 | register := func(funcs []RegisterMutatorFunc) { | 
|  | 48 | for _, f := range funcs { | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 49 | f(mctx) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 50 | } | 
|  | 51 | } | 
|  | 52 |  | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 53 | register(preArch) | 
| Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 54 |  | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 55 | register(preDeps) | 
|  | 56 |  | 
|  | 57 | mctx.BottomUp("deps", depsMutator).Parallel() | 
|  | 58 |  | 
|  | 59 | register(postDeps) | 
|  | 60 |  | 
|  | 61 | registerMutatorsToContext(ctx, mctx.mutators) | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 62 | } | 
|  | 63 |  | 
|  | 64 | type registerMutatorsContext struct { | 
|  | 65 | mutators []*mutator | 
|  | 66 | } | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 67 |  | 
|  | 68 | type RegisterMutatorsContext interface { | 
|  | 69 | TopDown(name string, m AndroidTopDownMutator) MutatorHandle | 
|  | 70 | BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | type RegisterMutatorFunc func(RegisterMutatorsContext) | 
|  | 74 |  | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 75 | var preArch = []RegisterMutatorFunc{ | 
| Colin Cross | f8b860a | 2019-04-16 14:43:28 -0700 | [diff] [blame] | 76 | registerLoadHookMutator, | 
| Dan Willemsen | 6e72ef7 | 2018-01-26 18:27:02 -0800 | [diff] [blame] | 77 | RegisterNamespaceMutator, | 
| Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 78 | RegisterPrebuiltsPreArchMutators, | 
| Martin Stjernholm | 226b20d | 2019-05-17 22:42:02 +0100 | [diff] [blame] | 79 | registerVisibilityRuleChecker, | 
| Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 80 | RegisterDefaultsPreArchMutators, | 
| Paul Duffin | 2e61fa6 | 2019-03-28 14:10:57 +0000 | [diff] [blame] | 81 | registerVisibilityRuleGatherer, | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 82 | } | 
|  | 83 |  | 
| Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 84 | func registerArchMutator(ctx RegisterMutatorsContext) { | 
|  | 85 | ctx.BottomUp("arch", archMutator).Parallel() | 
|  | 86 | ctx.TopDown("arch_hooks", archHookMutator).Parallel() | 
|  | 87 | } | 
|  | 88 |  | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 89 | var preDeps = []RegisterMutatorFunc{ | 
| Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 90 | registerArchMutator, | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
|  | 93 | var postDeps = []RegisterMutatorFunc{ | 
| Colin Cross | 1b48842 | 2019-03-04 22:33:56 -0800 | [diff] [blame] | 94 | registerPathDepsMutator, | 
| Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 95 | RegisterPrebuiltsPostDepsMutators, | 
| Paul Duffin | 2e61fa6 | 2019-03-28 14:10:57 +0000 | [diff] [blame] | 96 | registerVisibilityRuleEnforcer, | 
| Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 97 | registerNeverallowMutator, | 
| Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 98 | RegisterOverridePostDepsMutators, | 
| Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 99 | } | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 100 |  | 
|  | 101 | func PreArchMutators(f RegisterMutatorFunc) { | 
|  | 102 | preArch = append(preArch, f) | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | func PreDepsMutators(f RegisterMutatorFunc) { | 
|  | 106 | preDeps = append(preDeps, f) | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | func PostDepsMutators(f RegisterMutatorFunc) { | 
|  | 110 | postDeps = append(postDeps, f) | 
|  | 111 | } | 
|  | 112 |  | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 113 | type AndroidTopDownMutator func(TopDownMutatorContext) | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 114 |  | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 115 | type TopDownMutatorContext interface { | 
| Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 116 | BaseModuleContext | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 117 | androidBaseContext | 
| Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 118 |  | 
|  | 119 | OtherModuleExists(name string) bool | 
|  | 120 | Rename(name string) | 
| Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 121 | Module() Module | 
| Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 122 |  | 
|  | 123 | OtherModuleName(m blueprint.Module) string | 
| Paul Duffin | 2e61fa6 | 2019-03-28 14:10:57 +0000 | [diff] [blame] | 124 | OtherModuleDir(m blueprint.Module) string | 
| Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 125 | OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{}) | 
|  | 126 | OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag | 
|  | 127 |  | 
|  | 128 | CreateModule(blueprint.ModuleFactory, ...interface{}) | 
|  | 129 |  | 
|  | 130 | GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module | 
|  | 131 | GetDirectDep(name string) (blueprint.Module, blueprint.DependencyTag) | 
|  | 132 |  | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 133 | VisitDirectDeps(visit func(Module)) | 
| Colin Cross | ee6143c | 2017-12-30 17:54:27 -0800 | [diff] [blame] | 134 | VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 135 | VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) | 
|  | 136 | VisitDepsDepthFirst(visit func(Module)) | 
|  | 137 | VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) | 
|  | 138 | WalkDeps(visit func(Module, Module) bool) | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 139 | // GetWalkPath is supposed to be called in visit function passed in WalkDeps() | 
|  | 140 | // and returns a top-down dependency path from a start module to current child module. | 
|  | 141 | GetWalkPath() []Module | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 142 | } | 
|  | 143 |  | 
|  | 144 | type androidTopDownMutatorContext struct { | 
|  | 145 | blueprint.TopDownMutatorContext | 
|  | 146 | androidBaseContextImpl | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 147 | walkPath []Module | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 148 | } | 
|  | 149 |  | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 150 | type AndroidBottomUpMutator func(BottomUpMutatorContext) | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 151 |  | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 152 | type BottomUpMutatorContext interface { | 
| Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 153 | BaseModuleContext | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 154 | androidBaseContext | 
| Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 155 |  | 
|  | 156 | OtherModuleExists(name string) bool | 
|  | 157 | Rename(name string) | 
|  | 158 | Module() blueprint.Module | 
|  | 159 |  | 
|  | 160 | AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) | 
|  | 161 | AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) | 
|  | 162 | CreateVariations(...string) []blueprint.Module | 
|  | 163 | CreateLocalVariations(...string) []blueprint.Module | 
|  | 164 | SetDependencyVariation(string) | 
|  | 165 | AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) | 
|  | 166 | AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) | 
|  | 167 | AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) | 
|  | 168 | ReplaceDependencies(string) | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 169 | } | 
|  | 170 |  | 
|  | 171 | type androidBottomUpMutatorContext struct { | 
|  | 172 | blueprint.BottomUpMutatorContext | 
|  | 173 | androidBaseContextImpl | 
|  | 174 | } | 
|  | 175 |  | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 176 | func (x *registerMutatorsContext) BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle { | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 177 | f := func(ctx blueprint.BottomUpMutatorContext) { | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 178 | if a, ok := ctx.Module().(Module); ok { | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 179 | actx := &androidBottomUpMutatorContext{ | 
|  | 180 | BottomUpMutatorContext: ctx, | 
|  | 181 | androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), | 
|  | 182 | } | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 183 | m(actx) | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 184 | } | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 185 | } | 
|  | 186 | mutator := &mutator{name: name, bottomUpMutator: f} | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 187 | x.mutators = append(x.mutators, mutator) | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 188 | return mutator | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 189 | } | 
|  | 190 |  | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 191 | func (x *registerMutatorsContext) TopDown(name string, m AndroidTopDownMutator) MutatorHandle { | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 192 | f := func(ctx blueprint.TopDownMutatorContext) { | 
| Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 193 | if a, ok := ctx.Module().(Module); ok { | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 194 | actx := &androidTopDownMutatorContext{ | 
|  | 195 | TopDownMutatorContext:  ctx, | 
|  | 196 | androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), | 
|  | 197 | } | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 198 | m(actx) | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 199 | } | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 200 | } | 
|  | 201 | mutator := &mutator{name: name, topDownMutator: f} | 
| Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 202 | x.mutators = append(x.mutators, mutator) | 
| Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 203 | return mutator | 
|  | 204 | } | 
|  | 205 |  | 
|  | 206 | type MutatorHandle interface { | 
|  | 207 | Parallel() MutatorHandle | 
|  | 208 | } | 
|  | 209 |  | 
|  | 210 | func (mutator *mutator) Parallel() MutatorHandle { | 
|  | 211 | mutator.parallel = true | 
|  | 212 | return mutator | 
| Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 213 | } | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 214 |  | 
|  | 215 | func depsMutator(ctx BottomUpMutatorContext) { | 
| Colin Cross | 6db4a6a | 2018-08-30 12:52:41 -0700 | [diff] [blame] | 216 | if m, ok := ctx.Module().(Module); ok && m.Enabled() { | 
| Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 217 | m.DepsMutator(ctx) | 
|  | 218 | } | 
|  | 219 | } | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 220 |  | 
| Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 221 | func (a *androidTopDownMutatorContext) Config() Config { | 
|  | 222 | return a.config | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | func (a *androidBottomUpMutatorContext) Config() Config { | 
|  | 226 | return a.config | 
|  | 227 | } | 
|  | 228 |  | 
| Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 229 | func (a *androidTopDownMutatorContext) Module() Module { | 
|  | 230 | module, _ := a.TopDownMutatorContext.Module().(Module) | 
|  | 231 | return module | 
|  | 232 | } | 
|  | 233 |  | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 234 | func (a *androidTopDownMutatorContext) VisitDirectDeps(visit func(Module)) { | 
|  | 235 | a.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) { | 
|  | 236 | if aModule, _ := module.(Module); aModule != nil { | 
|  | 237 | visit(aModule) | 
|  | 238 | } | 
|  | 239 | }) | 
|  | 240 | } | 
|  | 241 |  | 
| Colin Cross | ee6143c | 2017-12-30 17:54:27 -0800 | [diff] [blame] | 242 | func (a *androidTopDownMutatorContext) VisitDirectDepsWithTag(tag blueprint.DependencyTag, visit func(Module)) { | 
|  | 243 | a.TopDownMutatorContext.VisitDirectDeps(func(module blueprint.Module) { | 
|  | 244 | if aModule, _ := module.(Module); aModule != nil { | 
|  | 245 | if a.TopDownMutatorContext.OtherModuleDependencyTag(aModule) == tag { | 
|  | 246 | visit(aModule) | 
|  | 247 | } | 
|  | 248 | } | 
|  | 249 | }) | 
|  | 250 | } | 
|  | 251 |  | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 252 | func (a *androidTopDownMutatorContext) VisitDirectDepsIf(pred func(Module) bool, visit func(Module)) { | 
|  | 253 | a.TopDownMutatorContext.VisitDirectDepsIf( | 
|  | 254 | // pred | 
|  | 255 | func(module blueprint.Module) bool { | 
|  | 256 | if aModule, _ := module.(Module); aModule != nil { | 
|  | 257 | return pred(aModule) | 
|  | 258 | } else { | 
|  | 259 | return false | 
|  | 260 | } | 
|  | 261 | }, | 
|  | 262 | // visit | 
|  | 263 | func(module blueprint.Module) { | 
|  | 264 | visit(module.(Module)) | 
|  | 265 | }) | 
|  | 266 | } | 
|  | 267 |  | 
|  | 268 | func (a *androidTopDownMutatorContext) VisitDepsDepthFirst(visit func(Module)) { | 
|  | 269 | a.TopDownMutatorContext.VisitDepsDepthFirst(func(module blueprint.Module) { | 
|  | 270 | if aModule, _ := module.(Module); aModule != nil { | 
|  | 271 | visit(aModule) | 
|  | 272 | } | 
|  | 273 | }) | 
|  | 274 | } | 
|  | 275 |  | 
|  | 276 | func (a *androidTopDownMutatorContext) VisitDepsDepthFirstIf(pred func(Module) bool, visit func(Module)) { | 
|  | 277 | a.TopDownMutatorContext.VisitDepsDepthFirstIf( | 
|  | 278 | // pred | 
|  | 279 | func(module blueprint.Module) bool { | 
|  | 280 | if aModule, _ := module.(Module); aModule != nil { | 
|  | 281 | return pred(aModule) | 
|  | 282 | } else { | 
|  | 283 | return false | 
|  | 284 | } | 
|  | 285 | }, | 
|  | 286 | // visit | 
|  | 287 | func(module blueprint.Module) { | 
|  | 288 | visit(module.(Module)) | 
|  | 289 | }) | 
|  | 290 | } | 
|  | 291 |  | 
|  | 292 | func (a *androidTopDownMutatorContext) WalkDeps(visit func(Module, Module) bool) { | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 293 | a.walkPath = []Module{a.Module()} | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 294 | a.TopDownMutatorContext.WalkDeps(func(child, parent blueprint.Module) bool { | 
|  | 295 | childAndroidModule, _ := child.(Module) | 
|  | 296 | parentAndroidModule, _ := parent.(Module) | 
|  | 297 | if childAndroidModule != nil && parentAndroidModule != nil { | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 298 | // record walkPath before visit | 
|  | 299 | for a.walkPath[len(a.walkPath)-1] != parentAndroidModule { | 
|  | 300 | a.walkPath = a.walkPath[0 : len(a.walkPath)-1] | 
|  | 301 | } | 
|  | 302 | a.walkPath = append(a.walkPath, childAndroidModule) | 
| Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 303 | return visit(childAndroidModule, parentAndroidModule) | 
|  | 304 | } else { | 
|  | 305 | return false | 
|  | 306 | } | 
|  | 307 | }) | 
|  | 308 | } | 
| Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 309 |  | 
| Jooyung Han | a70f067 | 2019-01-18 15:20:43 +0900 | [diff] [blame] | 310 | func (a *androidTopDownMutatorContext) GetWalkPath() []Module { | 
|  | 311 | return a.walkPath | 
|  | 312 | } | 
|  | 313 |  | 
| Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 314 | func (a *androidTopDownMutatorContext) AppendProperties(props ...interface{}) { | 
|  | 315 | for _, p := range props { | 
|  | 316 | err := proptools.AppendMatchingProperties(a.Module().base().customizableProperties, | 
|  | 317 | p, nil) | 
|  | 318 | if err != nil { | 
|  | 319 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { | 
|  | 320 | a.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) | 
|  | 321 | } else { | 
|  | 322 | panic(err) | 
|  | 323 | } | 
|  | 324 | } | 
|  | 325 | } | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | func (a *androidTopDownMutatorContext) PrependProperties(props ...interface{}) { | 
|  | 329 | for _, p := range props { | 
|  | 330 | err := proptools.PrependMatchingProperties(a.Module().base().customizableProperties, | 
|  | 331 | p, nil) | 
|  | 332 | if err != nil { | 
|  | 333 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { | 
|  | 334 | a.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) | 
|  | 335 | } else { | 
|  | 336 | panic(err) | 
|  | 337 | } | 
|  | 338 | } | 
|  | 339 | } | 
|  | 340 | } |