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 | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 18 | "reflect" |
| 19 | |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 21 | "github.com/google/blueprint/proptools" |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 22 | ) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 23 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 24 | // Phases: |
| 25 | // run Pre-arch mutators |
| 26 | // run archMutator |
| 27 | // run Pre-deps mutators |
| 28 | // run depsMutator |
| 29 | // run PostDeps mutators |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 30 | // run FinalDeps mutators (CreateVariations disallowed in this phase) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 31 | // continue on to GenerateAndroidBuildActions |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 32 | |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 33 | func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) { |
| 34 | for _, t := range mutators { |
| 35 | var handle blueprint.MutatorHandle |
| 36 | if t.bottomUpMutator != nil { |
| 37 | handle = ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator) |
| 38 | } else if t.topDownMutator != nil { |
| 39 | handle = ctx.RegisterTopDownMutator(t.name, t.topDownMutator) |
| 40 | } |
| 41 | if t.parallel { |
| 42 | handle.Parallel() |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 43 | } |
| 44 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 47 | func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 48 | mctx := ®isterMutatorsContext{} |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 49 | |
| 50 | register := func(funcs []RegisterMutatorFunc) { |
| 51 | for _, f := range funcs { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 52 | f(mctx) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 56 | register(preArch) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 57 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 58 | register(preDeps) |
| 59 | |
| 60 | mctx.BottomUp("deps", depsMutator).Parallel() |
| 61 | |
| 62 | register(postDeps) |
| 63 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 64 | mctx.finalPhase = true |
| 65 | register(finalDeps) |
| 66 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 67 | registerMutatorsToContext(ctx, mctx.mutators) |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | type registerMutatorsContext struct { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 71 | mutators []*mutator |
| 72 | finalPhase bool |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 73 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 74 | |
| 75 | type RegisterMutatorsContext interface { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 76 | TopDown(name string, m TopDownMutator) MutatorHandle |
| 77 | BottomUp(name string, m BottomUpMutator) MutatorHandle |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | type RegisterMutatorFunc func(RegisterMutatorsContext) |
| 81 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 82 | var preArch = []RegisterMutatorFunc{ |
Dan Willemsen | 6e72ef7 | 2018-01-26 18:27:02 -0800 | [diff] [blame] | 83 | RegisterNamespaceMutator, |
Paul Duffin | e2453c7 | 2019-05-31 14:00:04 +0100 | [diff] [blame] | 84 | // Rename package module types. |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 85 | RegisterPackageRenamer, |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 86 | RegisterPrebuiltsPreArchMutators, |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 87 | RegisterVisibilityRuleChecker, |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 88 | RegisterDefaultsPreArchMutators, |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 89 | RegisterVisibilityRuleGatherer, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 92 | func registerArchMutator(ctx RegisterMutatorsContext) { |
Colin Cross | a195f91 | 2019-10-16 11:07:20 -0700 | [diff] [blame] | 93 | ctx.BottomUp("os", osMutator).Parallel() |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 94 | ctx.BottomUp("image", imageMutator).Parallel() |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 95 | ctx.BottomUp("arch", archMutator).Parallel() |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 98 | var preDeps = []RegisterMutatorFunc{ |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 99 | registerArchMutator, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | var postDeps = []RegisterMutatorFunc{ |
Colin Cross | 1b48842 | 2019-03-04 22:33:56 -0800 | [diff] [blame] | 103 | registerPathDepsMutator, |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 104 | RegisterPrebuiltsPostDepsMutators, |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 105 | RegisterVisibilityRuleEnforcer, |
Steven Moreland | 65b3fd9 | 2017-12-06 14:18:35 -0800 | [diff] [blame] | 106 | registerNeverallowMutator, |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 107 | RegisterOverridePostDepsMutators, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 108 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 109 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 110 | var finalDeps = []RegisterMutatorFunc{} |
| 111 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 112 | func PreArchMutators(f RegisterMutatorFunc) { |
| 113 | preArch = append(preArch, f) |
| 114 | } |
| 115 | |
| 116 | func PreDepsMutators(f RegisterMutatorFunc) { |
| 117 | preDeps = append(preDeps, f) |
| 118 | } |
| 119 | |
| 120 | func PostDepsMutators(f RegisterMutatorFunc) { |
| 121 | postDeps = append(postDeps, f) |
| 122 | } |
| 123 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 124 | func FinalDepsMutators(f RegisterMutatorFunc) { |
| 125 | finalDeps = append(finalDeps, f) |
| 126 | } |
| 127 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 128 | type TopDownMutator func(TopDownMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 129 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 130 | type TopDownMutatorContext interface { |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 131 | BaseModuleContext |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 132 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 133 | MutatorName() string |
| 134 | |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 135 | Rename(name string) |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 136 | |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 137 | CreateModule(ModuleFactory, ...interface{}) Module |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 140 | type topDownMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 141 | bp blueprint.TopDownMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 142 | baseModuleContext |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 145 | type BottomUpMutator func(BottomUpMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 146 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 147 | type BottomUpMutatorContext interface { |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 148 | BaseModuleContext |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 149 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 150 | MutatorName() string |
| 151 | |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 152 | Rename(name string) |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 153 | |
| 154 | AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) |
| 155 | AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 156 | CreateVariations(...string) []Module |
| 157 | CreateLocalVariations(...string) []Module |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 158 | SetDependencyVariation(string) |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 159 | SetDefaultDependencyVariation(*string) |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 160 | AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) |
| 161 | AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) |
| 162 | AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) |
| 163 | ReplaceDependencies(string) |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 164 | AliasVariation(variationName string) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 167 | type bottomUpMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 168 | bp blueprint.BottomUpMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 169 | baseModuleContext |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 170 | finalPhase bool |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 173 | func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 174 | finalPhase := x.finalPhase |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 175 | f := func(ctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 176 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 177 | actx := &bottomUpMutatorContext{ |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 178 | bp: ctx, |
| 179 | baseModuleContext: a.base().baseModuleContextFactory(ctx), |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 180 | finalPhase: finalPhase, |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 181 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 182 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 183 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 184 | } |
| 185 | mutator := &mutator{name: name, bottomUpMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 186 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 187 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 190 | func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 191 | f := func(ctx blueprint.TopDownMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 192 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 193 | actx := &topDownMutatorContext{ |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 194 | bp: ctx, |
| 195 | baseModuleContext: a.base().baseModuleContextFactory(ctx), |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 196 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 197 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 198 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 199 | } |
| 200 | mutator := &mutator{name: name, topDownMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 201 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 202 | return mutator |
| 203 | } |
| 204 | |
| 205 | type MutatorHandle interface { |
| 206 | Parallel() MutatorHandle |
| 207 | } |
| 208 | |
| 209 | func (mutator *mutator) Parallel() MutatorHandle { |
| 210 | mutator.parallel = true |
| 211 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 212 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 213 | |
| 214 | func depsMutator(ctx BottomUpMutatorContext) { |
Colin Cross | 6db4a6a | 2018-08-30 12:52:41 -0700 | [diff] [blame] | 215 | if m, ok := ctx.Module().(Module); ok && m.Enabled() { |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 216 | m.DepsMutator(ctx) |
| 217 | } |
| 218 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 219 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 220 | func (t *topDownMutatorContext) AppendProperties(props ...interface{}) { |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 221 | for _, p := range props { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 222 | err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties, |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 223 | p, nil) |
| 224 | if err != nil { |
| 225 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 226 | t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 227 | } else { |
| 228 | panic(err) |
| 229 | } |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 234 | func (t *topDownMutatorContext) PrependProperties(props ...interface{}) { |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 235 | for _, p := range props { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 236 | err := proptools.PrependMatchingProperties(t.Module().base().customizableProperties, |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 237 | p, nil) |
| 238 | if err != nil { |
| 239 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 240 | t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 241 | } else { |
| 242 | panic(err) |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 247 | |
| 248 | // android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that |
| 249 | // has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid |
| 250 | // ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every |
| 251 | // non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following |
| 252 | // methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext. |
| 253 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 254 | func (t *topDownMutatorContext) MutatorName() string { |
| 255 | return t.bp.MutatorName() |
| 256 | } |
| 257 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 258 | func (t *topDownMutatorContext) Rename(name string) { |
| 259 | t.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 260 | t.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 263 | func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 264 | inherited := []interface{}{&t.Module().base().commonProperties} |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 265 | module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...).(Module) |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 266 | |
| 267 | if t.Module().base().variableProperties != nil && module.base().variableProperties != nil { |
| 268 | src := t.Module().base().variableProperties |
| 269 | dst := []interface{}{ |
| 270 | module.base().variableProperties, |
| 271 | // Put an empty copy of the src properties into dst so that properties in src that are not in dst |
| 272 | // don't cause a "failed to find property to extend" error. |
| 273 | proptools.CloneEmptyProperties(reflect.ValueOf(src).Elem()).Interface(), |
| 274 | } |
| 275 | err := proptools.AppendMatchingProperties(dst, src, nil) |
| 276 | if err != nil { |
| 277 | panic(err) |
| 278 | } |
| 279 | } |
| 280 | |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 281 | return module |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 284 | func (b *bottomUpMutatorContext) MutatorName() string { |
| 285 | return b.bp.MutatorName() |
| 286 | } |
| 287 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 288 | func (b *bottomUpMutatorContext) Rename(name string) { |
| 289 | b.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 290 | b.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) { |
| 294 | b.bp.AddDependency(module, tag, name...) |
| 295 | } |
| 296 | |
| 297 | func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) { |
| 298 | b.bp.AddReverseDependency(module, tag, name) |
| 299 | } |
| 300 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 301 | func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 302 | if b.finalPhase { |
| 303 | panic("CreateVariations not allowed in FinalDepsMutators") |
| 304 | } |
| 305 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 306 | modules := b.bp.CreateVariations(variations...) |
| 307 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 308 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 309 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 310 | aModules[i] = modules[i].(Module) |
| 311 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 312 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 313 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 314 | } |
| 315 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 316 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 319 | func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame^] | 320 | if b.finalPhase { |
| 321 | panic("CreateLocalVariations not allowed in FinalDepsMutators") |
| 322 | } |
| 323 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 324 | modules := b.bp.CreateLocalVariations(variations...) |
| 325 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 326 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 327 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 328 | aModules[i] = modules[i].(Module) |
| 329 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 330 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 331 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 332 | } |
| 333 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 334 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) { |
| 338 | b.bp.SetDependencyVariation(variation) |
| 339 | } |
| 340 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 341 | func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) { |
| 342 | b.bp.SetDefaultDependencyVariation(variation) |
| 343 | } |
| 344 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 345 | func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, |
| 346 | names ...string) { |
| 347 | |
| 348 | b.bp.AddVariationDependencies(variations, tag, names...) |
| 349 | } |
| 350 | |
| 351 | func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation, |
| 352 | tag blueprint.DependencyTag, names ...string) { |
| 353 | |
| 354 | b.bp.AddFarVariationDependencies(variations, tag, names...) |
| 355 | } |
| 356 | |
| 357 | func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) { |
| 358 | b.bp.AddInterVariantDependency(tag, from, to) |
| 359 | } |
| 360 | |
| 361 | func (b *bottomUpMutatorContext) ReplaceDependencies(name string) { |
| 362 | b.bp.ReplaceDependencies(name) |
| 363 | } |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 364 | |
| 365 | func (b *bottomUpMutatorContext) AliasVariation(variationName string) { |
| 366 | b.bp.AliasVariation(variationName) |
| 367 | } |