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