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 | |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 47 | // RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing. |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 48 | func RegisterMutatorsForBazelConversion(ctx *blueprint.Context, preArchMutators, depsMutators, bp2buildMutators []RegisterMutatorFunc) { |
| 49 | mctx := ®isterMutatorsContext{ |
| 50 | bazelConversionMode: true, |
Jingwen Chen | 041b184 | 2021-02-01 00:23:25 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 53 | bp2buildPreArchMutators = append([]RegisterMutatorFunc{ |
| 54 | RegisterNamespaceMutator, |
| 55 | RegisterDefaultsPreArchMutators, |
| 56 | // TODO(b/165114590): this is required to resolve deps that are only prebuilts, but we should |
| 57 | // evaluate the impact on conversion. |
| 58 | RegisterPrebuiltsPreArchMutators, |
| 59 | }, |
| 60 | preArchMutators...) |
| 61 | |
| 62 | for _, f := range bp2buildPreArchMutators { |
| 63 | f(mctx) |
| 64 | } |
| 65 | |
| 66 | bp2buildDepsMutators = append([]RegisterMutatorFunc{ |
| 67 | registerDepsMutatorBp2Build, |
| 68 | registerPathDepsMutator, |
| 69 | }, depsMutators...) |
| 70 | |
| 71 | for _, f := range bp2buildDepsMutators { |
Jingwen Chen | 041b184 | 2021-02-01 00:23:25 -0500 | [diff] [blame] | 72 | f(mctx) |
| 73 | } |
| 74 | |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 75 | // Register bp2build mutators |
| 76 | for _, f := range bp2buildMutators { |
| 77 | f(mctx) |
| 78 | } |
| 79 | |
| 80 | registerMutatorsToContext(ctx, mctx.mutators) |
Jingwen Chen | 4133ce6 | 2020-12-02 04:34:15 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 83 | func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 84 | mctx := ®isterMutatorsContext{} |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 85 | |
| 86 | register := func(funcs []RegisterMutatorFunc) { |
| 87 | for _, f := range funcs { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 88 | f(mctx) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 92 | register(preArch) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 93 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 94 | register(preDeps) |
| 95 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 96 | register([]RegisterMutatorFunc{registerDepsMutator}) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 97 | |
| 98 | register(postDeps) |
| 99 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 100 | mctx.finalPhase = true |
| 101 | register(finalDeps) |
| 102 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 103 | registerMutatorsToContext(ctx, mctx.mutators) |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | type registerMutatorsContext struct { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 107 | mutators []*mutator |
| 108 | finalPhase bool |
| 109 | bazelConversionMode bool |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 110 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 111 | |
| 112 | type RegisterMutatorsContext interface { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 113 | TopDown(name string, m TopDownMutator) MutatorHandle |
| 114 | BottomUp(name string, m BottomUpMutator) MutatorHandle |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 115 | BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | type RegisterMutatorFunc func(RegisterMutatorsContext) |
| 119 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 120 | var preArch = []RegisterMutatorFunc{ |
Dan Willemsen | 6e72ef7 | 2018-01-26 18:27:02 -0800 | [diff] [blame] | 121 | RegisterNamespaceMutator, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 122 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 123 | // Check the visibility rules are valid. |
| 124 | // |
| 125 | // This must run after the package renamer mutators so that any issues found during |
| 126 | // validation of the package's default_visibility property are reported using the |
| 127 | // correct package name and not the synthetic name. |
| 128 | // |
| 129 | // This must also be run before defaults mutators as the rules for validation are |
| 130 | // different before checking the rules than they are afterwards. e.g. |
| 131 | // visibility: ["//visibility:private", "//visibility:public"] |
| 132 | // would be invalid if specified in a module definition but is valid if it results |
| 133 | // from something like this: |
| 134 | // |
| 135 | // defaults { |
| 136 | // name: "defaults", |
| 137 | // // Be inaccessible outside a package by default. |
| 138 | // visibility: ["//visibility:private"] |
| 139 | // } |
| 140 | // |
| 141 | // defaultable_module { |
| 142 | // name: "defaultable_module", |
| 143 | // defaults: ["defaults"], |
| 144 | // // Override the default. |
| 145 | // visibility: ["//visibility:public"] |
| 146 | // } |
| 147 | // |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 148 | RegisterVisibilityRuleChecker, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 149 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 150 | // Record the default_applicable_licenses for each package. |
| 151 | // |
| 152 | // This must run before the defaults so that defaults modules can pick up the package default. |
| 153 | RegisterLicensesPackageMapper, |
| 154 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 155 | // Apply properties from defaults modules to the referencing modules. |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 156 | // |
| 157 | // Any mutators that are added before this will not see any modules created by |
| 158 | // a DefaultableHook. |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 159 | RegisterDefaultsPreArchMutators, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 160 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 161 | // Add dependencies on any components so that any component references can be |
| 162 | // resolved within the deps mutator. |
| 163 | // |
| 164 | // Must be run after defaults so it can be used to create dependencies on the |
| 165 | // component modules that are creating in a DefaultableHook. |
| 166 | // |
| 167 | // Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are |
| 168 | // renamed. That is so that if a module creates components using a prebuilt module |
| 169 | // type that any dependencies (which must use prebuilt_ prefixes) are resolved to |
| 170 | // the prebuilt module and not the source module. |
| 171 | RegisterComponentsMutator, |
| 172 | |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 173 | // Create an association between prebuilt modules and their corresponding source |
| 174 | // modules (if any). |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 175 | // |
| 176 | // Must be run after defaults mutators to ensure that any modules created by |
| 177 | // a DefaultableHook can be either a prebuilt or a source module with a matching |
| 178 | // prebuilt. |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 179 | RegisterPrebuiltsPreArchMutators, |
| 180 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 181 | // Gather the licenses properties for all modules for use during expansion and enforcement. |
| 182 | // |
| 183 | // This must come after the defaults mutators to ensure that any licenses supplied |
| 184 | // in a defaults module has been successfully applied before the rules are gathered. |
| 185 | RegisterLicensesPropertyGatherer, |
| 186 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 187 | // Gather the visibility rules for all modules for us during visibility enforcement. |
| 188 | // |
| 189 | // This must come after the defaults mutators to ensure that any visibility supplied |
| 190 | // in a defaults module has been successfully applied before the rules are gathered. |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 191 | RegisterVisibilityRuleGatherer, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 194 | func registerArchMutator(ctx RegisterMutatorsContext) { |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 195 | ctx.BottomUpBlueprint("os", osMutator).Parallel() |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 196 | ctx.BottomUp("image", imageMutator).Parallel() |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 197 | ctx.BottomUpBlueprint("arch", archMutator).Parallel() |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 200 | var preDeps = []RegisterMutatorFunc{ |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 201 | registerArchMutator, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | var postDeps = []RegisterMutatorFunc{ |
Colin Cross | 1b48842 | 2019-03-04 22:33:56 -0800 | [diff] [blame] | 205 | registerPathDepsMutator, |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 206 | RegisterPrebuiltsPostDepsMutators, |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 207 | RegisterVisibilityRuleEnforcer, |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 208 | RegisterLicensesDependencyChecker, |
Artur Satayev | c5570ac | 2020-04-09 16:06:36 +0100 | [diff] [blame] | 209 | RegisterNeverallowMutator, |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 210 | RegisterOverridePostDepsMutators, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 211 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 212 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 213 | var finalDeps = []RegisterMutatorFunc{} |
| 214 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 215 | func PreArchMutators(f RegisterMutatorFunc) { |
| 216 | preArch = append(preArch, f) |
| 217 | } |
| 218 | |
| 219 | func PreDepsMutators(f RegisterMutatorFunc) { |
| 220 | preDeps = append(preDeps, f) |
| 221 | } |
| 222 | |
| 223 | func PostDepsMutators(f RegisterMutatorFunc) { |
| 224 | postDeps = append(postDeps, f) |
| 225 | } |
| 226 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 227 | func FinalDepsMutators(f RegisterMutatorFunc) { |
| 228 | finalDeps = append(finalDeps, f) |
| 229 | } |
| 230 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 231 | var bp2buildPreArchMutators = []RegisterMutatorFunc{} |
| 232 | var bp2buildDepsMutators = []RegisterMutatorFunc{} |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 233 | var bp2buildMutators = []RegisterMutatorFunc{} |
| 234 | |
| 235 | // RegisterBp2BuildMutator registers specially crafted mutators for |
| 236 | // converting Blueprint/Android modules into special modules that can |
| 237 | // be code-generated into Bazel BUILD targets. |
| 238 | // |
| 239 | // TODO(b/178068862): bring this into TestContext. |
| 240 | func RegisterBp2BuildMutator(moduleType string, m func(TopDownMutatorContext)) { |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 241 | f := func(ctx RegisterMutatorsContext) { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 242 | ctx.TopDown(moduleType, m) |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 243 | } |
| 244 | bp2buildMutators = append(bp2buildMutators, f) |
| 245 | } |
| 246 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 247 | // PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules |
| 248 | // into Bazel BUILD targets that should run prior to deps and conversion. |
| 249 | func PreArchBp2BuildMutators(f RegisterMutatorFunc) { |
| 250 | bp2buildPreArchMutators = append(bp2buildPreArchMutators, f) |
| 251 | } |
| 252 | |
| 253 | // DepsBp2BuildMutators adds mutators to be register for converting Android Blueprint modules into |
| 254 | // Bazel BUILD targets that should run prior to conversion to resolve dependencies. |
| 255 | func DepsBp2BuildMutators(f RegisterMutatorFunc) { |
| 256 | bp2buildDepsMutators = append(bp2buildDepsMutators, f) |
| 257 | } |
| 258 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 259 | type BaseMutatorContext interface { |
| 260 | BaseModuleContext |
| 261 | |
| 262 | // MutatorName returns the name that this mutator was registered with. |
| 263 | MutatorName() string |
| 264 | |
| 265 | // Rename all variants of a module. The new name is not visible to calls to ModuleName, |
| 266 | // AddDependency or OtherModuleName until after this mutator pass is complete. |
| 267 | Rename(name string) |
| 268 | } |
| 269 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 270 | type TopDownMutator func(TopDownMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 271 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 272 | type TopDownMutatorContext interface { |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 273 | BaseMutatorContext |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 274 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 275 | // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies |
| 276 | // the specified property structs to it as if the properties were set in a blueprint file. |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 277 | CreateModule(ModuleFactory, ...interface{}) Module |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 280 | type topDownMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 281 | bp blueprint.TopDownMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 282 | baseModuleContext |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 285 | type BottomUpMutator func(BottomUpMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 286 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 287 | type BottomUpMutatorContext interface { |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 288 | BaseMutatorContext |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 289 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 290 | // AddDependency adds a dependency to the given module. It returns a slice of modules for each |
| 291 | // dependency (some entries may be nil). |
| 292 | // |
| 293 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 294 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 295 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 296 | // be ordered correctly for all future mutator passes. |
| 297 | AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 298 | |
| 299 | // AddReverseDependency adds a dependency from the destination to the given module. |
| 300 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 301 | // correctly for all future mutator passes. All reverse dependencies for a destination module are |
| 302 | // collected until the end of the mutator pass, sorted by name, and then appended to the destination |
| 303 | // module's dependency list. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 304 | AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 305 | |
| 306 | // CreateVariations splits a module into multiple variants, one for each name in the variationNames |
| 307 | // parameter. It returns a list of new modules in the same order as the variationNames |
| 308 | // list. |
| 309 | // |
| 310 | // If any of the dependencies of the module being operated on were already split |
| 311 | // by calling CreateVariations with the same name, the dependency will automatically |
| 312 | // be updated to point the matching variant. |
| 313 | // |
| 314 | // If a module is split, and then a module depending on the first module is not split |
| 315 | // when the Mutator is later called on it, the dependency of the depending module will |
| 316 | // automatically be updated to point to the first variant. |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 317 | CreateVariations(...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 318 | |
| 319 | // CreateLocationVariations splits a module into multiple variants, one for each name in the variantNames |
| 320 | // parameter. It returns a list of new modules in the same order as the variantNames |
| 321 | // list. |
| 322 | // |
| 323 | // Local variations do not affect automatic dependency resolution - dependencies added |
| 324 | // to the split module via deps or DynamicDependerModule must exactly match a variant |
| 325 | // that contains all the non-local variations. |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 326 | CreateLocalVariations(...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 327 | |
| 328 | // SetDependencyVariation sets all dangling dependencies on the current module to point to the variation |
| 329 | // with given name. This function ignores the default variation set by SetDefaultDependencyVariation. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 330 | SetDependencyVariation(string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 331 | |
| 332 | // SetDefaultDependencyVariation sets the default variation when a dangling reference is detected |
| 333 | // during the subsequent calls on Create*Variations* functions. To reset, set it to nil. |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 334 | SetDefaultDependencyVariation(*string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 335 | |
| 336 | // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 337 | // argument to select which variant of the dependency to use. It returns a slice of modules for |
| 338 | // each dependency (some entries may be nil). A variant of the dependency must exist that matches |
| 339 | // the all of the non-local variations of the current module, plus the variations argument. |
| 340 | // |
| 341 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 342 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 343 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 344 | // be ordered correctly for all future mutator passes. |
| 345 | AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 346 | |
| 347 | // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 348 | // variations argument to select which variant of the dependency to use. It returns a slice of |
| 349 | // modules for each dependency (some entries may be nil). A variant of the dependency must |
| 350 | // exist that matches the variations argument, but may also have other variations. |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 351 | // For any unspecified variation the first variant will be used. |
| 352 | // |
| 353 | // Unlike AddVariationDependencies, the variations of the current module are ignored - the |
| 354 | // dependency only needs to match the supplied variations. |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 355 | // |
| 356 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 357 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 358 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 359 | // be ordered correctly for all future mutator passes. |
| 360 | AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 361 | |
| 362 | // AddInterVariantDependency adds a dependency between two variants of the same module. Variants are always |
| 363 | // ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change |
| 364 | // that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps, |
| 365 | // WalkDeps, etc. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 366 | AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 367 | |
| 368 | // ReplaceDependencies replaces all dependencies on the identical variant of the module with the |
| 369 | // specified name with the current variant of this module. Replacements don't take effect until |
| 370 | // after the mutator pass is finished. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 371 | ReplaceDependencies(string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 372 | |
| 373 | // ReplaceDependencies replaces all dependencies on the identical variant of the module with the |
| 374 | // specified name with the current variant of this module as long as the supplied predicate returns |
| 375 | // true. |
| 376 | // |
| 377 | // Replacements don't take effect until after the mutator pass is finished. |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 378 | ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 379 | |
| 380 | // AliasVariation takes a variationName that was passed to CreateVariations for this module, |
| 381 | // and creates an alias from the current variant (before the mutator has run) to the new |
| 382 | // variant. The alias will be valid until the next time a mutator calls CreateVariations or |
| 383 | // CreateLocalVariations on this module without also calling AliasVariation. The alias can |
| 384 | // be used to add dependencies on the newly created variant using the variant map from |
| 385 | // before CreateVariations was run. |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 386 | AliasVariation(variationName string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 387 | |
| 388 | // CreateAliasVariation takes a toVariationName that was passed to CreateVariations for this |
| 389 | // module, and creates an alias from a new fromVariationName variant the toVariationName |
| 390 | // variant. The alias will be valid until the next time a mutator calls CreateVariations or |
| 391 | // CreateLocalVariations on this module without also calling AliasVariation. The alias can |
| 392 | // be used to add dependencies on the toVariationName variant using the fromVariationName |
| 393 | // variant. |
Colin Cross | 1b9604b | 2020-08-11 12:03:56 -0700 | [diff] [blame] | 394 | CreateAliasVariation(fromVariationName, toVariationName string) |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 395 | |
| 396 | // SetVariationProvider sets the value for a provider for the given newly created variant of |
| 397 | // the current module, i.e. one of the Modules returned by CreateVariations.. It panics if |
| 398 | // not called during the appropriate mutator or GenerateBuildActions pass for the provider, |
| 399 | // if the value is not of the appropriate type, or if the module is not a newly created |
| 400 | // variant of the current module. The value should not be modified after being passed to |
| 401 | // SetVariationProvider. |
| 402 | SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 403 | |
| 404 | // BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion. |
| 405 | BazelConversionMode() bool |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 408 | type bottomUpMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 409 | bp blueprint.BottomUpMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 410 | baseModuleContext |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 411 | finalPhase bool |
| 412 | bazelConversionMode bool |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 413 | } |
| 414 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 415 | func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 416 | finalPhase, bazelConversionMode bool) BottomUpMutatorContext { |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 417 | |
| 418 | return &bottomUpMutatorContext{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 419 | bp: ctx, |
| 420 | baseModuleContext: a.base().baseModuleContextFactory(ctx), |
| 421 | finalPhase: finalPhase, |
| 422 | bazelConversionMode: bazelConversionMode, |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 426 | func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 427 | finalPhase := x.finalPhase |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 428 | bazelConversionMode := x.bazelConversionMode |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 429 | f := func(ctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 430 | if a, ok := ctx.Module().(Module); ok { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 431 | m(bottomUpMutatorContextFactory(ctx, a, finalPhase, bazelConversionMode)) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 432 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 433 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 434 | mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 435 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 436 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 439 | func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle { |
| 440 | mutator := &mutator{name: name, bottomUpMutator: m} |
| 441 | x.mutators = append(x.mutators, mutator) |
| 442 | return mutator |
| 443 | } |
| 444 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 445 | func (x *registerMutatorsContext) mutatorName(name string) string { |
| 446 | if x.bazelConversionMode { |
| 447 | return name + "_bp2build" |
| 448 | } |
| 449 | return name |
| 450 | } |
| 451 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 452 | func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 453 | f := func(ctx blueprint.TopDownMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 454 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 455 | actx := &topDownMutatorContext{ |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 456 | bp: ctx, |
| 457 | baseModuleContext: a.base().baseModuleContextFactory(ctx), |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 458 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 459 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 460 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 461 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 462 | mutator := &mutator{name: x.mutatorName(name), topDownMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 463 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 464 | return mutator |
| 465 | } |
| 466 | |
| 467 | type MutatorHandle interface { |
| 468 | Parallel() MutatorHandle |
| 469 | } |
| 470 | |
| 471 | func (mutator *mutator) Parallel() MutatorHandle { |
| 472 | mutator.parallel = true |
| 473 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 474 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 475 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 476 | func RegisterComponentsMutator(ctx RegisterMutatorsContext) { |
| 477 | ctx.BottomUp("component-deps", componentDepsMutator).Parallel() |
| 478 | } |
| 479 | |
| 480 | // A special mutator that runs just prior to the deps mutator to allow the dependencies |
| 481 | // on component modules to be added so that they can depend directly on a prebuilt |
| 482 | // module. |
| 483 | func componentDepsMutator(ctx BottomUpMutatorContext) { |
| 484 | if m := ctx.Module(); m.Enabled() { |
| 485 | m.ComponentDepsMutator(ctx) |
| 486 | } |
| 487 | } |
| 488 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 489 | func depsMutator(ctx BottomUpMutatorContext) { |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 490 | if m := ctx.Module(); m.Enabled() { |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 491 | m.DepsMutator(ctx) |
| 492 | } |
| 493 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 494 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 495 | func registerDepsMutator(ctx RegisterMutatorsContext) { |
| 496 | ctx.BottomUp("deps", depsMutator).Parallel() |
| 497 | } |
| 498 | |
| 499 | func registerDepsMutatorBp2Build(ctx RegisterMutatorsContext) { |
| 500 | // TODO(b/179313531): Consider a separate mutator that only runs depsMutator for modules that are |
| 501 | // being converted to build targets. |
| 502 | ctx.BottomUp("deps", depsMutator).Parallel() |
| 503 | } |
| 504 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 505 | func (t *topDownMutatorContext) AppendProperties(props ...interface{}) { |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 506 | for _, p := range props { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 507 | err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties, |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 508 | p, nil) |
| 509 | if err != nil { |
| 510 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 511 | t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 512 | } else { |
| 513 | panic(err) |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 519 | func (t *topDownMutatorContext) PrependProperties(props ...interface{}) { |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 520 | for _, p := range props { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 521 | err := proptools.PrependMatchingProperties(t.Module().base().customizableProperties, |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 522 | p, nil) |
| 523 | if err != nil { |
| 524 | if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 525 | t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) |
Colin Cross | 519917d | 2017-11-02 16:35:56 -0700 | [diff] [blame] | 526 | } else { |
| 527 | panic(err) |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 532 | |
| 533 | // android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that |
| 534 | // has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid |
| 535 | // ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every |
| 536 | // non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following |
| 537 | // methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext. |
| 538 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 539 | func (t *topDownMutatorContext) MutatorName() string { |
| 540 | return t.bp.MutatorName() |
| 541 | } |
| 542 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 543 | func (t *topDownMutatorContext) Rename(name string) { |
| 544 | t.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 545 | t.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 548 | func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 549 | inherited := []interface{}{&t.Module().base().commonProperties} |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 550 | module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...).(Module) |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 551 | |
| 552 | if t.Module().base().variableProperties != nil && module.base().variableProperties != nil { |
| 553 | src := t.Module().base().variableProperties |
| 554 | dst := []interface{}{ |
| 555 | module.base().variableProperties, |
| 556 | // Put an empty copy of the src properties into dst so that properties in src that are not in dst |
| 557 | // don't cause a "failed to find property to extend" error. |
Colin Cross | 43e789d | 2020-01-28 09:46:50 -0800 | [diff] [blame] | 558 | proptools.CloneEmptyProperties(reflect.ValueOf(src)).Interface(), |
Colin Cross | 18c4680 | 2019-09-24 22:19:02 -0700 | [diff] [blame] | 559 | } |
| 560 | err := proptools.AppendMatchingProperties(dst, src, nil) |
| 561 | if err != nil { |
| 562 | panic(err) |
| 563 | } |
| 564 | } |
| 565 | |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 566 | return module |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 569 | func (b *bottomUpMutatorContext) MutatorName() string { |
| 570 | return b.bp.MutatorName() |
| 571 | } |
| 572 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 573 | func (b *bottomUpMutatorContext) Rename(name string) { |
| 574 | b.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 575 | b.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 578 | func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module { |
| 579 | return b.bp.AddDependency(module, tag, name...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) { |
| 583 | b.bp.AddReverseDependency(module, tag, name) |
| 584 | } |
| 585 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 586 | func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 587 | if b.finalPhase { |
| 588 | panic("CreateVariations not allowed in FinalDepsMutators") |
| 589 | } |
| 590 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 591 | modules := b.bp.CreateVariations(variations...) |
| 592 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 593 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 594 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 595 | aModules[i] = modules[i].(Module) |
| 596 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 597 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 598 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 599 | } |
| 600 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 601 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 604 | func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 605 | if b.finalPhase { |
| 606 | panic("CreateLocalVariations not allowed in FinalDepsMutators") |
| 607 | } |
| 608 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 609 | modules := b.bp.CreateLocalVariations(variations...) |
| 610 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 611 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 612 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 613 | aModules[i] = modules[i].(Module) |
| 614 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 615 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 616 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 617 | } |
| 618 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 619 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) { |
| 623 | b.bp.SetDependencyVariation(variation) |
| 624 | } |
| 625 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 626 | func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) { |
| 627 | b.bp.SetDefaultDependencyVariation(variation) |
| 628 | } |
| 629 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 630 | func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 631 | names ...string) []blueprint.Module { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 632 | if b.bazelConversionMode { |
| 633 | _, noSelfDeps := RemoveFromList(b.ModuleName(), names) |
| 634 | if len(noSelfDeps) == 0 { |
| 635 | return []blueprint.Module(nil) |
| 636 | } |
| 637 | // In Bazel conversion mode, mutators should not have created any variants. So, when adding a |
| 638 | // dependency, the variations would not exist and the dependency could not be added, by |
| 639 | // specifying no variations, we will allow adding the dependency to succeed. |
| 640 | return b.bp.AddFarVariationDependencies(nil, tag, noSelfDeps...) |
| 641 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 642 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 643 | return b.bp.AddVariationDependencies(variations, tag, names...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation, |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 647 | tag blueprint.DependencyTag, names ...string) []blueprint.Module { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 648 | if b.bazelConversionMode { |
| 649 | // In Bazel conversion mode, mutators should not have created any variants. So, when adding a |
| 650 | // dependency, the variations would not exist and the dependency could not be added, by |
| 651 | // specifying no variations, we will allow adding the dependency to succeed. |
| 652 | return b.bp.AddFarVariationDependencies(nil, tag, names...) |
| 653 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 654 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 655 | return b.bp.AddFarVariationDependencies(variations, tag, names...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) { |
| 659 | b.bp.AddInterVariantDependency(tag, from, to) |
| 660 | } |
| 661 | |
| 662 | func (b *bottomUpMutatorContext) ReplaceDependencies(name string) { |
| 663 | b.bp.ReplaceDependencies(name) |
| 664 | } |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 665 | |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 666 | func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) { |
| 667 | b.bp.ReplaceDependenciesIf(name, predicate) |
| 668 | } |
| 669 | |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 670 | func (b *bottomUpMutatorContext) AliasVariation(variationName string) { |
| 671 | b.bp.AliasVariation(variationName) |
| 672 | } |
Colin Cross | 1b9604b | 2020-08-11 12:03:56 -0700 | [diff] [blame] | 673 | |
| 674 | func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) { |
| 675 | b.bp.CreateAliasVariation(fromVariationName, toVariationName) |
| 676 | } |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 677 | |
| 678 | func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) { |
| 679 | b.bp.SetVariationProvider(module, provider, value) |
| 680 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame^] | 681 | |
| 682 | func (b *bottomUpMutatorContext) BazelConversionMode() bool { |
| 683 | return b.bazelConversionMode |
| 684 | } |