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 ( |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 18 | "android/soong/bazel" |
| 19 | |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" |
| 21 | ) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 22 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 23 | // Phases: |
| 24 | // run Pre-arch mutators |
| 25 | // run archMutator |
| 26 | // run Pre-deps mutators |
| 27 | // run depsMutator |
| 28 | // run PostDeps mutators |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 29 | // run FinalDeps mutators (CreateVariations disallowed in this phase) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 30 | // continue on to GenerateAndroidBuildActions |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 31 | |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 32 | // RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing. |
Liz Kammer | be46fcc | 2021-11-01 15:32:43 -0400 | [diff] [blame] | 33 | func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators []RegisterMutatorFunc) { |
Spandan Das | 5af0bd3 | 2022-09-28 20:43:08 +0000 | [diff] [blame] | 34 | bp2buildMutators := append(preArchMutators, registerBp2buildConversionMutator) |
| 35 | registerMutatorsForBazelConversion(ctx, bp2buildMutators) |
| 36 | } |
| 37 | |
| 38 | // RegisterMutatorsForApiBazelConversion is an alternate registration pipeline for api_bp2build |
| 39 | // This pipeline restricts generation of Bazel targets to Soong modules that contribute APIs |
| 40 | func RegisterMutatorsForApiBazelConversion(ctx *Context, preArchMutators []RegisterMutatorFunc) { |
| 41 | bp2buildMutators := append(preArchMutators, registerApiBp2buildConversionMutator) |
| 42 | registerMutatorsForBazelConversion(ctx, bp2buildMutators) |
| 43 | } |
| 44 | |
| 45 | func registerMutatorsForBazelConversion(ctx *Context, bp2buildMutators []RegisterMutatorFunc) { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 46 | mctx := ®isterMutatorsContext{ |
| 47 | bazelConversionMode: true, |
Jingwen Chen | 041b184 | 2021-02-01 00:23:25 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Spandan Das | 5af0bd3 | 2022-09-28 20:43:08 +0000 | [diff] [blame] | 50 | allMutators := append([]RegisterMutatorFunc{ |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 51 | RegisterNamespaceMutator, |
| 52 | RegisterDefaultsPreArchMutators, |
| 53 | // TODO(b/165114590): this is required to resolve deps that are only prebuilts, but we should |
| 54 | // evaluate the impact on conversion. |
| 55 | RegisterPrebuiltsPreArchMutators, |
| 56 | }, |
Spandan Das | 5af0bd3 | 2022-09-28 20:43:08 +0000 | [diff] [blame] | 57 | bp2buildMutators...) |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 58 | |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 59 | // Register bp2build mutators |
Spandan Das | 5af0bd3 | 2022-09-28 20:43:08 +0000 | [diff] [blame] | 60 | for _, f := range allMutators { |
Jingwen Chen | 7385067 | 2020-12-14 08:25:34 -0500 | [diff] [blame] | 61 | f(mctx) |
| 62 | } |
| 63 | |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 64 | mctx.mutators.registerAll(ctx) |
Jingwen Chen | 4133ce6 | 2020-12-02 04:34:15 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 67 | // collateGloballyRegisteredMutators constructs the list of mutators that have been registered |
| 68 | // with the InitRegistrationContext and will be used at runtime. |
| 69 | func collateGloballyRegisteredMutators() sortableComponents { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame^] | 70 | // ensure mixed builds mutator is the last mutator |
| 71 | finalDeps = append(finalDeps, registerMixedBuildsMutator) |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 72 | return collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps) |
| 73 | } |
| 74 | |
| 75 | // collateRegisteredMutators constructs a single list of mutators from the separate lists. |
| 76 | func collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) sortableComponents { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 77 | mctx := ®isterMutatorsContext{} |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 78 | |
| 79 | register := func(funcs []RegisterMutatorFunc) { |
| 80 | for _, f := range funcs { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 81 | f(mctx) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 85 | register(preArch) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 86 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 87 | register(preDeps) |
| 88 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 89 | register([]RegisterMutatorFunc{registerDepsMutator}) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 90 | |
| 91 | register(postDeps) |
| 92 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 93 | mctx.finalPhase = true |
| 94 | register(finalDeps) |
| 95 | |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 96 | return mctx.mutators |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | type registerMutatorsContext struct { |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 100 | mutators sortableComponents |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 101 | finalPhase bool |
| 102 | bazelConversionMode bool |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 103 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 104 | |
| 105 | type RegisterMutatorsContext interface { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 106 | TopDown(name string, m TopDownMutator) MutatorHandle |
| 107 | BottomUp(name string, m BottomUpMutator) MutatorHandle |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 108 | BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 109 | Transition(name string, m TransitionMutator) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | type RegisterMutatorFunc func(RegisterMutatorsContext) |
| 113 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 114 | var preArch = []RegisterMutatorFunc{ |
Dan Willemsen | 6e72ef7 | 2018-01-26 18:27:02 -0800 | [diff] [blame] | 115 | RegisterNamespaceMutator, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 116 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 117 | // Check the visibility rules are valid. |
| 118 | // |
| 119 | // This must run after the package renamer mutators so that any issues found during |
| 120 | // validation of the package's default_visibility property are reported using the |
| 121 | // correct package name and not the synthetic name. |
| 122 | // |
| 123 | // This must also be run before defaults mutators as the rules for validation are |
| 124 | // different before checking the rules than they are afterwards. e.g. |
| 125 | // visibility: ["//visibility:private", "//visibility:public"] |
| 126 | // would be invalid if specified in a module definition but is valid if it results |
| 127 | // from something like this: |
| 128 | // |
| 129 | // defaults { |
| 130 | // name: "defaults", |
| 131 | // // Be inaccessible outside a package by default. |
| 132 | // visibility: ["//visibility:private"] |
| 133 | // } |
| 134 | // |
| 135 | // defaultable_module { |
| 136 | // name: "defaultable_module", |
| 137 | // defaults: ["defaults"], |
| 138 | // // Override the default. |
| 139 | // visibility: ["//visibility:public"] |
| 140 | // } |
| 141 | // |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 142 | RegisterVisibilityRuleChecker, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 143 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 144 | // Record the default_applicable_licenses for each package. |
| 145 | // |
| 146 | // This must run before the defaults so that defaults modules can pick up the package default. |
| 147 | RegisterLicensesPackageMapper, |
| 148 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 149 | // Apply properties from defaults modules to the referencing modules. |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 150 | // |
| 151 | // Any mutators that are added before this will not see any modules created by |
| 152 | // a DefaultableHook. |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 153 | RegisterDefaultsPreArchMutators, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 154 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 155 | // Add dependencies on any components so that any component references can be |
| 156 | // resolved within the deps mutator. |
| 157 | // |
| 158 | // Must be run after defaults so it can be used to create dependencies on the |
| 159 | // component modules that are creating in a DefaultableHook. |
| 160 | // |
| 161 | // Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are |
| 162 | // renamed. That is so that if a module creates components using a prebuilt module |
| 163 | // type that any dependencies (which must use prebuilt_ prefixes) are resolved to |
| 164 | // the prebuilt module and not the source module. |
| 165 | RegisterComponentsMutator, |
| 166 | |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 167 | // Create an association between prebuilt modules and their corresponding source |
| 168 | // modules (if any). |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 169 | // |
| 170 | // Must be run after defaults mutators to ensure that any modules created by |
| 171 | // a DefaultableHook can be either a prebuilt or a source module with a matching |
| 172 | // prebuilt. |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 173 | RegisterPrebuiltsPreArchMutators, |
| 174 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 175 | // Gather the licenses properties for all modules for use during expansion and enforcement. |
| 176 | // |
| 177 | // This must come after the defaults mutators to ensure that any licenses supplied |
| 178 | // in a defaults module has been successfully applied before the rules are gathered. |
| 179 | RegisterLicensesPropertyGatherer, |
| 180 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 181 | // Gather the visibility rules for all modules for us during visibility enforcement. |
| 182 | // |
| 183 | // This must come after the defaults mutators to ensure that any visibility supplied |
| 184 | // 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] | 185 | RegisterVisibilityRuleGatherer, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 188 | func registerArchMutator(ctx RegisterMutatorsContext) { |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 189 | ctx.BottomUpBlueprint("os", osMutator).Parallel() |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 190 | ctx.BottomUp("image", imageMutator).Parallel() |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 191 | ctx.BottomUpBlueprint("arch", archMutator).Parallel() |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 194 | var preDeps = []RegisterMutatorFunc{ |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 195 | registerArchMutator, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | var postDeps = []RegisterMutatorFunc{ |
Colin Cross | 1b48842 | 2019-03-04 22:33:56 -0800 | [diff] [blame] | 199 | registerPathDepsMutator, |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 200 | RegisterPrebuiltsPostDepsMutators, |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 201 | RegisterVisibilityRuleEnforcer, |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 202 | RegisterLicensesDependencyChecker, |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 203 | registerNeverallowMutator, |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 204 | RegisterOverridePostDepsMutators, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 205 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 206 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 207 | var finalDeps = []RegisterMutatorFunc{} |
| 208 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 209 | func PreArchMutators(f RegisterMutatorFunc) { |
| 210 | preArch = append(preArch, f) |
| 211 | } |
| 212 | |
| 213 | func PreDepsMutators(f RegisterMutatorFunc) { |
| 214 | preDeps = append(preDeps, f) |
| 215 | } |
| 216 | |
| 217 | func PostDepsMutators(f RegisterMutatorFunc) { |
| 218 | postDeps = append(postDeps, f) |
| 219 | } |
| 220 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 221 | func FinalDepsMutators(f RegisterMutatorFunc) { |
| 222 | finalDeps = append(finalDeps, f) |
| 223 | } |
| 224 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 225 | var bp2buildPreArchMutators = []RegisterMutatorFunc{} |
Rupert Shuttleworth | a9d76dd | 2021-07-02 07:17:16 -0400 | [diff] [blame] | 226 | |
Liz Kammer | 12615db | 2021-09-28 09:19:17 -0400 | [diff] [blame] | 227 | // A minimal context for Bp2build conversion |
| 228 | type Bp2buildMutatorContext interface { |
| 229 | BazelConversionPathContext |
| 230 | |
| 231 | CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}) |
| 232 | } |
| 233 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 234 | // PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules |
| 235 | // into Bazel BUILD targets that should run prior to deps and conversion. |
| 236 | func PreArchBp2BuildMutators(f RegisterMutatorFunc) { |
| 237 | bp2buildPreArchMutators = append(bp2buildPreArchMutators, f) |
| 238 | } |
| 239 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 240 | type BaseMutatorContext interface { |
| 241 | BaseModuleContext |
| 242 | |
| 243 | // MutatorName returns the name that this mutator was registered with. |
| 244 | MutatorName() string |
| 245 | |
| 246 | // Rename all variants of a module. The new name is not visible to calls to ModuleName, |
| 247 | // AddDependency or OtherModuleName until after this mutator pass is complete. |
| 248 | Rename(name string) |
| 249 | } |
| 250 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 251 | type TopDownMutator func(TopDownMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 252 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 253 | type TopDownMutatorContext interface { |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 254 | BaseMutatorContext |
Colin Cross | 3f68a13 | 2017-10-23 17:10:29 -0700 | [diff] [blame] | 255 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 256 | // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies |
| 257 | // 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] | 258 | CreateModule(ModuleFactory, ...interface{}) Module |
Jingwen Chen | 1fd1469 | 2021-02-05 03:01:50 -0500 | [diff] [blame] | 259 | |
| 260 | // CreateBazelTargetModule creates a BazelTargetModule by calling the |
| 261 | // factory method, just like in CreateModule, but also requires |
| 262 | // BazelTargetModuleProperties containing additional metadata for the |
| 263 | // bp2build codegenerator. |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 264 | CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}) |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 265 | |
| 266 | // CreateBazelTargetModuleWithRestrictions creates a BazelTargetModule by calling the |
| 267 | // factory method, just like in CreateModule, but also requires |
| 268 | // BazelTargetModuleProperties containing additional metadata for the |
| 269 | // bp2build codegenerator. The generated target is restricted to only be buildable for certain |
| 270 | // platforms, as dictated by a given bool attribute: the target will not be buildable in |
| 271 | // any platform for which this bool attribute is false. |
| 272 | CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}, bazel.BoolAttribute) |
Spandan Das | abedff0 | 2023-03-07 19:24:34 +0000 | [diff] [blame] | 273 | |
| 274 | // CreateBazelTargetAliasInDir creates an alias definition in `dir` directory. |
| 275 | // This function can be used to create alias definitions in a directory that is different |
| 276 | // from the directory of the visited Soong module. |
| 277 | CreateBazelTargetAliasInDir(dir string, name string, actual bazel.Label) |
Spandan Das | 6a448ec | 2023-04-19 17:36:12 +0000 | [diff] [blame] | 278 | |
| 279 | // CreateBazelConfigSetting creates a config_setting in <dir>/BUILD.bazel |
| 280 | // build/bazel has several static config_setting(s) that are used in Bazel builds. |
| 281 | // This function can be used to createa additional config_setting(s) based on the build graph |
| 282 | // (e.g. a config_setting specific to an apex variant) |
| 283 | CreateBazelConfigSetting(csa bazel.ConfigSettingAttributes, ca CommonAttributes, dir string) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 286 | type topDownMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 287 | bp blueprint.TopDownMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 288 | baseModuleContext |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 291 | type BottomUpMutator func(BottomUpMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 292 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 293 | type BottomUpMutatorContext interface { |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 294 | BaseMutatorContext |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 295 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 296 | // AddDependency adds a dependency to the given module. It returns a slice of modules for each |
| 297 | // dependency (some entries may be nil). |
| 298 | // |
| 299 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 300 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 301 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 302 | // be ordered correctly for all future mutator passes. |
| 303 | AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 304 | |
| 305 | // AddReverseDependency adds a dependency from the destination to the given module. |
| 306 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 307 | // correctly for all future mutator passes. All reverse dependencies for a destination module are |
| 308 | // collected until the end of the mutator pass, sorted by name, and then appended to the destination |
| 309 | // module's dependency list. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 310 | AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 311 | |
| 312 | // CreateVariations splits a module into multiple variants, one for each name in the variationNames |
| 313 | // parameter. It returns a list of new modules in the same order as the variationNames |
| 314 | // list. |
| 315 | // |
| 316 | // If any of the dependencies of the module being operated on were already split |
| 317 | // by calling CreateVariations with the same name, the dependency will automatically |
| 318 | // be updated to point the matching variant. |
| 319 | // |
| 320 | // If a module is split, and then a module depending on the first module is not split |
| 321 | // when the Mutator is later called on it, the dependency of the depending module will |
| 322 | // automatically be updated to point to the first variant. |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 323 | CreateVariations(...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 324 | |
| 325 | // CreateLocationVariations splits a module into multiple variants, one for each name in the variantNames |
| 326 | // parameter. It returns a list of new modules in the same order as the variantNames |
| 327 | // list. |
| 328 | // |
| 329 | // Local variations do not affect automatic dependency resolution - dependencies added |
| 330 | // to the split module via deps or DynamicDependerModule must exactly match a variant |
| 331 | // that contains all the non-local variations. |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 332 | CreateLocalVariations(...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 333 | |
| 334 | // SetDependencyVariation sets all dangling dependencies on the current module to point to the variation |
| 335 | // with given name. This function ignores the default variation set by SetDefaultDependencyVariation. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 336 | SetDependencyVariation(string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 337 | |
| 338 | // SetDefaultDependencyVariation sets the default variation when a dangling reference is detected |
| 339 | // 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] | 340 | SetDefaultDependencyVariation(*string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 341 | |
| 342 | // 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] | 343 | // argument to select which variant of the dependency to use. It returns a slice of modules for |
| 344 | // each dependency (some entries may be nil). A variant of the dependency must exist that matches |
Usta Shrestha | c725f47 | 2022-01-11 02:44:21 -0500 | [diff] [blame] | 345 | // all the non-local variations of the current module, plus the variations argument. |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 346 | // |
| 347 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 348 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 349 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 350 | // be ordered correctly for all future mutator passes. |
Usta Shrestha | c725f47 | 2022-01-11 02:44:21 -0500 | [diff] [blame] | 351 | AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 352 | |
| 353 | // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 354 | // variations argument to select which variant of the dependency to use. It returns a slice of |
| 355 | // modules for each dependency (some entries may be nil). A variant of the dependency must |
| 356 | // exist that matches the variations argument, but may also have other variations. |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 357 | // For any unspecified variation the first variant will be used. |
| 358 | // |
| 359 | // Unlike AddVariationDependencies, the variations of the current module are ignored - the |
| 360 | // dependency only needs to match the supplied variations. |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 361 | // |
| 362 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 363 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 364 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 365 | // be ordered correctly for all future mutator passes. |
| 366 | AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 367 | |
| 368 | // AddInterVariantDependency adds a dependency between two variants of the same module. Variants are always |
| 369 | // ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change |
| 370 | // that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps, |
| 371 | // WalkDeps, etc. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 372 | AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 373 | |
| 374 | // ReplaceDependencies replaces all dependencies on the identical variant of the module with the |
| 375 | // specified name with the current variant of this module. Replacements don't take effect until |
| 376 | // after the mutator pass is finished. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 377 | ReplaceDependencies(string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 378 | |
| 379 | // ReplaceDependencies replaces all dependencies on the identical variant of the module with the |
| 380 | // specified name with the current variant of this module as long as the supplied predicate returns |
| 381 | // true. |
| 382 | // |
| 383 | // Replacements don't take effect until after the mutator pass is finished. |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 384 | ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 385 | |
| 386 | // AliasVariation takes a variationName that was passed to CreateVariations for this module, |
| 387 | // and creates an alias from the current variant (before the mutator has run) to the new |
| 388 | // variant. The alias will be valid until the next time a mutator calls CreateVariations or |
| 389 | // CreateLocalVariations on this module without also calling AliasVariation. The alias can |
| 390 | // be used to add dependencies on the newly created variant using the variant map from |
| 391 | // before CreateVariations was run. |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 392 | AliasVariation(variationName string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 393 | |
| 394 | // CreateAliasVariation takes a toVariationName that was passed to CreateVariations for this |
| 395 | // module, and creates an alias from a new fromVariationName variant the toVariationName |
| 396 | // variant. The alias will be valid until the next time a mutator calls CreateVariations or |
| 397 | // CreateLocalVariations on this module without also calling AliasVariation. The alias can |
| 398 | // be used to add dependencies on the toVariationName variant using the fromVariationName |
| 399 | // variant. |
Colin Cross | 1b9604b | 2020-08-11 12:03:56 -0700 | [diff] [blame] | 400 | CreateAliasVariation(fromVariationName, toVariationName string) |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 401 | |
| 402 | // SetVariationProvider sets the value for a provider for the given newly created variant of |
| 403 | // the current module, i.e. one of the Modules returned by CreateVariations.. It panics if |
| 404 | // not called during the appropriate mutator or GenerateBuildActions pass for the provider, |
| 405 | // if the value is not of the appropriate type, or if the module is not a newly created |
| 406 | // variant of the current module. The value should not be modified after being passed to |
| 407 | // SetVariationProvider. |
| 408 | SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 411 | type bottomUpMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 412 | bp blueprint.BottomUpMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 413 | baseModuleContext |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 414 | finalPhase bool |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 417 | func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module, |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 418 | finalPhase, bazelConversionMode bool) BottomUpMutatorContext { |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 419 | |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 420 | moduleContext := a.base().baseModuleContextFactory(ctx) |
| 421 | moduleContext.bazelConversionMode = bazelConversionMode |
| 422 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 423 | return &bottomUpMutatorContext{ |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 424 | bp: ctx, |
Cole Faust | 0abd4b4 | 2023-01-10 10:49:18 -0800 | [diff] [blame] | 425 | baseModuleContext: moduleContext, |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 426 | finalPhase: finalPhase, |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 430 | func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 431 | finalPhase := x.finalPhase |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 432 | bazelConversionMode := x.bazelConversionMode |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 433 | f := func(ctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 434 | if a, ok := ctx.Module().(Module); ok { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 435 | m(bottomUpMutatorContextFactory(ctx, a, finalPhase, bazelConversionMode)) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 436 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 437 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 438 | mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 439 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 440 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 443 | func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle { |
| 444 | mutator := &mutator{name: name, bottomUpMutator: m} |
| 445 | x.mutators = append(x.mutators, mutator) |
| 446 | return mutator |
| 447 | } |
| 448 | |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 449 | type IncomingTransitionContext interface { |
| 450 | // Module returns the target of the dependency edge for which the transition |
| 451 | // is being computed |
| 452 | Module() Module |
| 453 | |
| 454 | // Config returns the configuration for the build. |
| 455 | Config() Config |
| 456 | } |
| 457 | |
| 458 | type OutgoingTransitionContext interface { |
| 459 | // Module returns the target of the dependency edge for which the transition |
| 460 | // is being computed |
| 461 | Module() Module |
| 462 | |
| 463 | // DepTag() Returns the dependency tag through which this dependency is |
| 464 | // reached |
| 465 | DepTag() blueprint.DependencyTag |
| 466 | } |
Lukacs T. Berki | 0e691c1 | 2022-06-24 10:15:55 +0200 | [diff] [blame] | 467 | |
| 468 | // Transition mutators implement a top-down mechanism where a module tells its |
| 469 | // direct dependencies what variation they should be built in but the dependency |
| 470 | // has the final say. |
| 471 | // |
| 472 | // When implementing a transition mutator, one needs to implement four methods: |
| 473 | // - Split() that tells what variations a module has by itself |
| 474 | // - OutgoingTransition() where a module tells what it wants from its |
| 475 | // dependency |
| 476 | // - IncomingTransition() where a module has the final say about its own |
| 477 | // variation |
| 478 | // - Mutate() that changes the state of a module depending on its variation |
| 479 | // |
| 480 | // That the effective variation of module B when depended on by module A is the |
| 481 | // composition the outgoing transition of module A and the incoming transition |
| 482 | // of module B. |
| 483 | // |
| 484 | // the outgoing transition should not take the properties of the dependency into |
| 485 | // account, only those of the module that depends on it. For this reason, the |
| 486 | // dependency is not even passed into it as an argument. Likewise, the incoming |
| 487 | // transition should not take the properties of the depending module into |
| 488 | // account and is thus not informed about it. This makes for a nice |
| 489 | // decomposition of the decision logic. |
| 490 | // |
| 491 | // A given transition mutator only affects its own variation; other variations |
| 492 | // stay unchanged along the dependency edges. |
| 493 | // |
| 494 | // Soong makes sure that all modules are created in the desired variations and |
| 495 | // that dependency edges are set up correctly. This ensures that "missing |
| 496 | // variation" errors do not happen and allows for more flexible changes in the |
| 497 | // value of the variation among dependency edges (as oppposed to bottom-up |
| 498 | // mutators where if module A in variation X depends on module B and module B |
| 499 | // has that variation X, A must depend on variation X of B) |
| 500 | // |
| 501 | // The limited power of the context objects passed to individual mutators |
| 502 | // methods also makes it more difficult to shoot oneself in the foot. Complete |
| 503 | // safety is not guaranteed because no one prevents individual transition |
| 504 | // mutators from mutating modules in illegal ways and for e.g. Split() or |
| 505 | // Mutate() to run their own visitations of the transitive dependency of the |
| 506 | // module and both of these are bad ideas, but it's better than no guardrails at |
| 507 | // all. |
| 508 | // |
| 509 | // This model is pretty close to Bazel's configuration transitions. The mapping |
| 510 | // between concepts in Soong and Bazel is as follows: |
| 511 | // - Module == configured target |
| 512 | // - Variant == configuration |
| 513 | // - Variation name == configuration flag |
| 514 | // - Variation == configuration flag value |
| 515 | // - Outgoing transition == attribute transition |
| 516 | // - Incoming transition == rule transition |
| 517 | // |
| 518 | // The Split() method does not have a Bazel equivalent and Bazel split |
| 519 | // transitions do not have a Soong equivalent. |
| 520 | // |
| 521 | // Mutate() does not make sense in Bazel due to the different models of the |
| 522 | // two systems: when creating new variations, Soong clones the old module and |
| 523 | // thus some way is needed to change it state whereas Bazel creates each |
| 524 | // configuration of a given configured target anew. |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 525 | type TransitionMutator interface { |
| 526 | // Split returns the set of variations that should be created for a module no |
| 527 | // matter who depends on it. Used when Make depends on a particular variation |
| 528 | // or when the module knows its variations just based on information given to |
| 529 | // it in the Blueprint file. This method should not mutate the module it is |
| 530 | // called on. |
| 531 | Split(ctx BaseModuleContext) []string |
| 532 | |
Lukacs T. Berki | 0e691c1 | 2022-06-24 10:15:55 +0200 | [diff] [blame] | 533 | // Called on a module to determine which variation it wants from its direct |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 534 | // dependencies. The dependency itself can override this decision. This method |
| 535 | // should not mutate the module itself. |
| 536 | OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string |
| 537 | |
| 538 | // Called on a module to determine which variation it should be in based on |
| 539 | // the variation modules that depend on it want. This gives the module a final |
| 540 | // say about its own variations. This method should not mutate the module |
| 541 | // itself. |
| 542 | IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string |
| 543 | |
| 544 | // Called after a module was split into multiple variations on each variation. |
| 545 | // It should not split the module any further but adding new dependencies is |
| 546 | // fine. Unlike all the other methods on TransitionMutator, this method is |
| 547 | // allowed to mutate the module. |
| 548 | Mutate(ctx BottomUpMutatorContext, variation string) |
| 549 | } |
| 550 | |
| 551 | type androidTransitionMutator struct { |
| 552 | finalPhase bool |
| 553 | bazelConversionMode bool |
| 554 | mutator TransitionMutator |
| 555 | } |
| 556 | |
| 557 | func (a *androidTransitionMutator) Split(ctx blueprint.BaseModuleContext) []string { |
| 558 | if m, ok := ctx.Module().(Module); ok { |
| 559 | moduleContext := m.base().baseModuleContextFactory(ctx) |
| 560 | moduleContext.bazelConversionMode = a.bazelConversionMode |
| 561 | return a.mutator.Split(&moduleContext) |
| 562 | } else { |
| 563 | return []string{""} |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | type outgoingTransitionContextImpl struct { |
| 568 | bp blueprint.OutgoingTransitionContext |
| 569 | } |
| 570 | |
| 571 | func (c *outgoingTransitionContextImpl) Module() Module { |
| 572 | return c.bp.Module().(Module) |
| 573 | } |
| 574 | |
| 575 | func (c *outgoingTransitionContextImpl) DepTag() blueprint.DependencyTag { |
| 576 | return c.bp.DepTag() |
| 577 | } |
| 578 | |
| 579 | func (a *androidTransitionMutator) OutgoingTransition(ctx blueprint.OutgoingTransitionContext, sourceVariation string) string { |
| 580 | if _, ok := ctx.Module().(Module); ok { |
| 581 | return a.mutator.OutgoingTransition(&outgoingTransitionContextImpl{bp: ctx}, sourceVariation) |
| 582 | } else { |
| 583 | return "" |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | type incomingTransitionContextImpl struct { |
| 588 | bp blueprint.IncomingTransitionContext |
| 589 | } |
| 590 | |
| 591 | func (c *incomingTransitionContextImpl) Module() Module { |
| 592 | return c.bp.Module().(Module) |
| 593 | } |
| 594 | |
| 595 | func (c *incomingTransitionContextImpl) Config() Config { |
| 596 | return c.bp.Config().(Config) |
| 597 | } |
| 598 | |
| 599 | func (a *androidTransitionMutator) IncomingTransition(ctx blueprint.IncomingTransitionContext, incomingVariation string) string { |
| 600 | if _, ok := ctx.Module().(Module); ok { |
| 601 | return a.mutator.IncomingTransition(&incomingTransitionContextImpl{bp: ctx}, incomingVariation) |
| 602 | } else { |
| 603 | return "" |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | func (a *androidTransitionMutator) Mutate(ctx blueprint.BottomUpMutatorContext, variation string) { |
| 608 | if am, ok := ctx.Module().(Module); ok { |
| 609 | a.mutator.Mutate(bottomUpMutatorContextFactory(ctx, am, a.finalPhase, a.bazelConversionMode), variation) |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | func (x *registerMutatorsContext) Transition(name string, m TransitionMutator) { |
| 614 | atm := &androidTransitionMutator{ |
| 615 | finalPhase: x.finalPhase, |
| 616 | bazelConversionMode: x.bazelConversionMode, |
| 617 | mutator: m, |
| 618 | } |
| 619 | mutator := &mutator{ |
| 620 | name: name, |
| 621 | transitionMutator: atm} |
| 622 | x.mutators = append(x.mutators, mutator) |
| 623 | } |
| 624 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 625 | func (x *registerMutatorsContext) mutatorName(name string) string { |
| 626 | if x.bazelConversionMode { |
| 627 | return name + "_bp2build" |
| 628 | } |
| 629 | return name |
| 630 | } |
| 631 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 632 | func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 633 | f := func(ctx blueprint.TopDownMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 634 | if a, ok := ctx.Module().(Module); ok { |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 635 | moduleContext := a.base().baseModuleContextFactory(ctx) |
| 636 | moduleContext.bazelConversionMode = x.bazelConversionMode |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 637 | actx := &topDownMutatorContext{ |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 638 | bp: ctx, |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 639 | baseModuleContext: moduleContext, |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 640 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 641 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 642 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 643 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 644 | mutator := &mutator{name: x.mutatorName(name), topDownMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 645 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 646 | return mutator |
| 647 | } |
| 648 | |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 649 | func (mutator *mutator) componentName() string { |
| 650 | return mutator.name |
| 651 | } |
| 652 | |
| 653 | func (mutator *mutator) register(ctx *Context) { |
| 654 | blueprintCtx := ctx.Context |
| 655 | var handle blueprint.MutatorHandle |
| 656 | if mutator.bottomUpMutator != nil { |
| 657 | handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator) |
| 658 | } else if mutator.topDownMutator != nil { |
| 659 | handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator) |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 660 | } else if mutator.transitionMutator != nil { |
| 661 | blueprintCtx.RegisterTransitionMutator(mutator.name, mutator.transitionMutator) |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 662 | } |
| 663 | if mutator.parallel { |
| 664 | handle.Parallel() |
| 665 | } |
| 666 | } |
| 667 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 668 | type MutatorHandle interface { |
| 669 | Parallel() MutatorHandle |
| 670 | } |
| 671 | |
| 672 | func (mutator *mutator) Parallel() MutatorHandle { |
| 673 | mutator.parallel = true |
| 674 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 675 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 676 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 677 | func RegisterComponentsMutator(ctx RegisterMutatorsContext) { |
| 678 | ctx.BottomUp("component-deps", componentDepsMutator).Parallel() |
| 679 | } |
| 680 | |
| 681 | // A special mutator that runs just prior to the deps mutator to allow the dependencies |
| 682 | // on component modules to be added so that they can depend directly on a prebuilt |
| 683 | // module. |
| 684 | func componentDepsMutator(ctx BottomUpMutatorContext) { |
| 685 | if m := ctx.Module(); m.Enabled() { |
| 686 | m.ComponentDepsMutator(ctx) |
| 687 | } |
| 688 | } |
| 689 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 690 | func depsMutator(ctx BottomUpMutatorContext) { |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 691 | if m := ctx.Module(); m.Enabled() { |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 692 | m.DepsMutator(ctx) |
| 693 | } |
| 694 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 695 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 696 | func registerDepsMutator(ctx RegisterMutatorsContext) { |
| 697 | ctx.BottomUp("deps", depsMutator).Parallel() |
| 698 | } |
| 699 | |
| 700 | func registerDepsMutatorBp2Build(ctx RegisterMutatorsContext) { |
| 701 | // TODO(b/179313531): Consider a separate mutator that only runs depsMutator for modules that are |
| 702 | // being converted to build targets. |
| 703 | ctx.BottomUp("deps", depsMutator).Parallel() |
| 704 | } |
| 705 | |
Jingwen Chen | 1fd1469 | 2021-02-05 03:01:50 -0500 | [diff] [blame] | 706 | func (t *topDownMutatorContext) CreateBazelTargetModule( |
Jingwen Chen | 1fd1469 | 2021-02-05 03:01:50 -0500 | [diff] [blame] | 707 | bazelProps bazel.BazelTargetModuleProperties, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 708 | commonAttrs CommonAttributes, |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 709 | attrs interface{}) { |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 710 | t.createBazelTargetModule(bazelProps, commonAttrs, attrs, bazel.BoolAttribute{}) |
| 711 | } |
| 712 | |
| 713 | func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions( |
| 714 | bazelProps bazel.BazelTargetModuleProperties, |
| 715 | commonAttrs CommonAttributes, |
| 716 | attrs interface{}, |
| 717 | enabledProperty bazel.BoolAttribute) { |
| 718 | t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty) |
| 719 | } |
| 720 | |
Spandan Das | abedff0 | 2023-03-07 19:24:34 +0000 | [diff] [blame] | 721 | var ( |
| 722 | bazelAliasModuleProperties = bazel.BazelTargetModuleProperties{ |
| 723 | Rule_class: "alias", |
| 724 | } |
| 725 | ) |
| 726 | |
| 727 | type bazelAliasAttributes struct { |
| 728 | Actual *bazel.LabelAttribute |
| 729 | } |
| 730 | |
| 731 | func (t *topDownMutatorContext) CreateBazelTargetAliasInDir( |
| 732 | dir string, |
| 733 | name string, |
| 734 | actual bazel.Label) { |
| 735 | mod := t.Module() |
| 736 | attrs := &bazelAliasAttributes{ |
| 737 | Actual: bazel.MakeLabelAttribute(actual.Label), |
| 738 | } |
| 739 | info := bp2buildInfo{ |
| 740 | Dir: dir, |
| 741 | BazelProps: bazelAliasModuleProperties, |
| 742 | CommonAttrs: CommonAttributes{Name: name}, |
| 743 | ConstraintAttrs: constraintAttributes{}, |
| 744 | Attrs: attrs, |
| 745 | } |
| 746 | mod.base().addBp2buildInfo(info) |
| 747 | } |
| 748 | |
Spandan Das | 6a448ec | 2023-04-19 17:36:12 +0000 | [diff] [blame] | 749 | func (t *topDownMutatorContext) CreateBazelConfigSetting( |
| 750 | csa bazel.ConfigSettingAttributes, |
| 751 | ca CommonAttributes, |
| 752 | dir string) { |
| 753 | mod := t.Module() |
| 754 | info := bp2buildInfo{ |
| 755 | Dir: dir, |
| 756 | BazelProps: bazel.BazelTargetModuleProperties{ |
| 757 | Rule_class: "config_setting", |
| 758 | }, |
| 759 | CommonAttrs: ca, |
| 760 | ConstraintAttrs: constraintAttributes{}, |
| 761 | Attrs: &csa, |
| 762 | } |
| 763 | mod.base().addBp2buildInfo(info) |
| 764 | } |
| 765 | |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 766 | // ApexAvailableTags converts the apex_available property value of an ApexModule |
| 767 | // module and returns it as a list of keyed tags. |
| 768 | func ApexAvailableTags(mod Module) bazel.StringListAttribute { |
| 769 | attr := bazel.StringListAttribute{} |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 770 | // Transform specific attributes into tags. |
| 771 | if am, ok := mod.(ApexModule); ok { |
| 772 | // TODO(b/218841706): hidl_interface has the apex_available prop, but it's |
| 773 | // defined directly as a prop and not via ApexModule, so this doesn't |
| 774 | // pick those props up. |
Spandan Das | 2dc6dfc | 2023-04-17 19:16:06 +0000 | [diff] [blame] | 775 | apexAvailable := am.apexModuleBase().ApexAvailable() |
| 776 | // If a user does not specify apex_available in Android.bp, then soong provides a default. |
| 777 | // To avoid verbosity of BUILD files, remove this default from user-facing BUILD files. |
| 778 | if len(am.apexModuleBase().ApexProperties.Apex_available) == 0 { |
| 779 | apexAvailable = []string{} |
| 780 | } |
| 781 | attr.Value = ConvertApexAvailableToTags(apexAvailable) |
Jingwen Chen | c4c34e1 | 2022-11-29 12:07:45 +0000 | [diff] [blame] | 782 | } |
| 783 | return attr |
| 784 | } |
| 785 | |
Spandan Das | f57a966 | 2023-04-12 19:05:49 +0000 | [diff] [blame] | 786 | func ApexAvailableTagsWithoutTestApexes(ctx BaseModuleContext, mod Module) bazel.StringListAttribute { |
| 787 | attr := bazel.StringListAttribute{} |
| 788 | if am, ok := mod.(ApexModule); ok { |
| 789 | apexAvailableWithoutTestApexes := removeTestApexes(ctx, am.apexModuleBase().ApexAvailable()) |
| 790 | // If a user does not specify apex_available in Android.bp, then soong provides a default. |
| 791 | // To avoid verbosity of BUILD files, remove this default from user-facing BUILD files. |
| 792 | if len(am.apexModuleBase().ApexProperties.Apex_available) == 0 { |
| 793 | apexAvailableWithoutTestApexes = []string{} |
| 794 | } |
| 795 | attr.Value = ConvertApexAvailableToTags(apexAvailableWithoutTestApexes) |
| 796 | } |
| 797 | return attr |
| 798 | } |
| 799 | |
| 800 | func removeTestApexes(ctx BaseModuleContext, apex_available []string) []string { |
| 801 | testApexes := []string{} |
| 802 | for _, aa := range apex_available { |
| 803 | // ignore the wildcards |
| 804 | if InList(aa, AvailableToRecognziedWildcards) { |
| 805 | continue |
| 806 | } |
| 807 | mod, _ := ctx.ModuleFromName(aa) |
| 808 | if apex, ok := mod.(ApexTestInterface); ok && apex.IsTestApex() { |
| 809 | testApexes = append(testApexes, aa) |
| 810 | } |
| 811 | } |
| 812 | return RemoveListFromList(CopyOf(apex_available), testApexes) |
| 813 | } |
| 814 | |
Cole Faust | fb11c1c | 2023-02-10 11:27:46 -0800 | [diff] [blame] | 815 | func ConvertApexAvailableToTags(apexAvailable []string) []string { |
| 816 | if len(apexAvailable) == 0 { |
| 817 | // We need nil specifically to make bp2build not add the tags property at all, |
| 818 | // instead of adding it with an empty list |
| 819 | return nil |
| 820 | } |
| 821 | result := make([]string, 0, len(apexAvailable)) |
| 822 | for _, a := range apexAvailable { |
| 823 | result = append(result, "apex_available="+a) |
| 824 | } |
| 825 | return result |
| 826 | } |
| 827 | |
Spandan Das | 39b6cc5 | 2023-04-12 19:05:49 +0000 | [diff] [blame] | 828 | // ConvertApexAvailableToTagsWithoutTestApexes converts a list of apex names to a list of bazel tags |
| 829 | // This function drops any test apexes from the input. |
| 830 | func ConvertApexAvailableToTagsWithoutTestApexes(ctx BaseModuleContext, apexAvailable []string) []string { |
| 831 | noTestApexes := removeTestApexes(ctx, apexAvailable) |
| 832 | return ConvertApexAvailableToTags(noTestApexes) |
| 833 | } |
| 834 | |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 835 | func (t *topDownMutatorContext) createBazelTargetModule( |
| 836 | bazelProps bazel.BazelTargetModuleProperties, |
| 837 | commonAttrs CommonAttributes, |
| 838 | attrs interface{}, |
| 839 | enabledProperty bazel.BoolAttribute) { |
| 840 | constraintAttributes := commonAttrs.fillCommonBp2BuildModuleAttrs(t, enabledProperty) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 841 | mod := t.Module() |
Liz Kammer | 2ada09a | 2021-08-11 00:17:36 -0400 | [diff] [blame] | 842 | info := bp2buildInfo{ |
Chris Parsons | 58852a0 | 2021-12-09 18:10:18 -0500 | [diff] [blame] | 843 | Dir: t.OtherModuleDir(mod), |
| 844 | BazelProps: bazelProps, |
| 845 | CommonAttrs: commonAttrs, |
| 846 | ConstraintAttrs: constraintAttributes, |
| 847 | Attrs: attrs, |
Jingwen Chen | fb4692a | 2021-02-07 10:05:16 -0500 | [diff] [blame] | 848 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 447f6c9 | 2021-08-31 20:30:36 +0000 | [diff] [blame] | 849 | mod.base().addBp2buildInfo(info) |
Jingwen Chen | 1fd1469 | 2021-02-05 03:01:50 -0500 | [diff] [blame] | 850 | } |
| 851 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 852 | // android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that |
| 853 | // has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid |
| 854 | // ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every |
| 855 | // non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following |
| 856 | // methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext. |
| 857 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 858 | func (t *topDownMutatorContext) MutatorName() string { |
| 859 | return t.bp.MutatorName() |
| 860 | } |
| 861 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 862 | func (t *topDownMutatorContext) Rename(name string) { |
| 863 | t.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 864 | t.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Liz Kammer | f31c900 | 2022-04-26 09:08:55 -0400 | [diff] [blame] | 867 | func (t *topDownMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module { |
| 868 | return t.bp.CreateModule(factory, name, props...) |
| 869 | } |
| 870 | |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 871 | func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { |
Liz Kammer | f31c900 | 2022-04-26 09:08:55 -0400 | [diff] [blame] | 872 | return createModule(t, factory, "_topDownMutatorModule", props...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 875 | func (t *topDownMutatorContext) createModuleWithoutInheritance(factory ModuleFactory, props ...interface{}) Module { |
Liz Kammer | f31c900 | 2022-04-26 09:08:55 -0400 | [diff] [blame] | 876 | module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), "", props...).(Module) |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 877 | return module |
| 878 | } |
| 879 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 880 | func (b *bottomUpMutatorContext) MutatorName() string { |
| 881 | return b.bp.MutatorName() |
| 882 | } |
| 883 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 884 | func (b *bottomUpMutatorContext) Rename(name string) { |
| 885 | b.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 886 | b.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 889 | func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame^] | 890 | if b.baseModuleContext.checkedMissingDeps() { |
| 891 | panic("Adding deps not allowed after checking for missing deps") |
| 892 | } |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 893 | return b.bp.AddDependency(module, tag, name...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame^] | 897 | if b.baseModuleContext.checkedMissingDeps() { |
| 898 | panic("Adding deps not allowed after checking for missing deps") |
| 899 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 900 | b.bp.AddReverseDependency(module, tag, name) |
| 901 | } |
| 902 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 903 | func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 904 | if b.finalPhase { |
| 905 | panic("CreateVariations not allowed in FinalDepsMutators") |
| 906 | } |
| 907 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 908 | modules := b.bp.CreateVariations(variations...) |
| 909 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 910 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 911 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 912 | aModules[i] = modules[i].(Module) |
| 913 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 914 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 915 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 916 | } |
| 917 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 918 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 921 | func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 922 | if b.finalPhase { |
| 923 | panic("CreateLocalVariations not allowed in FinalDepsMutators") |
| 924 | } |
| 925 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 926 | modules := b.bp.CreateLocalVariations(variations...) |
| 927 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 928 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 929 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 930 | aModules[i] = modules[i].(Module) |
| 931 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 932 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 933 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 934 | } |
| 935 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 936 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) { |
| 940 | b.bp.SetDependencyVariation(variation) |
| 941 | } |
| 942 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 943 | func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) { |
| 944 | b.bp.SetDefaultDependencyVariation(variation) |
| 945 | } |
| 946 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 947 | func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 948 | names ...string) []blueprint.Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame^] | 949 | if b.baseModuleContext.checkedMissingDeps() { |
| 950 | panic("Adding deps not allowed after checking for missing deps") |
| 951 | } |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 952 | return b.bp.AddVariationDependencies(variations, tag, names...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation, |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 956 | tag blueprint.DependencyTag, names ...string) []blueprint.Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame^] | 957 | if b.baseModuleContext.checkedMissingDeps() { |
| 958 | panic("Adding deps not allowed after checking for missing deps") |
| 959 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 960 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 961 | return b.bp.AddFarVariationDependencies(variations, tag, names...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) { |
| 965 | b.bp.AddInterVariantDependency(tag, from, to) |
| 966 | } |
| 967 | |
| 968 | func (b *bottomUpMutatorContext) ReplaceDependencies(name string) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame^] | 969 | if b.baseModuleContext.checkedMissingDeps() { |
| 970 | panic("Adding deps not allowed after checking for missing deps") |
| 971 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 972 | b.bp.ReplaceDependencies(name) |
| 973 | } |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 974 | |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 975 | func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame^] | 976 | if b.baseModuleContext.checkedMissingDeps() { |
| 977 | panic("Adding deps not allowed after checking for missing deps") |
| 978 | } |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 979 | b.bp.ReplaceDependenciesIf(name, predicate) |
| 980 | } |
| 981 | |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 982 | func (b *bottomUpMutatorContext) AliasVariation(variationName string) { |
| 983 | b.bp.AliasVariation(variationName) |
| 984 | } |
Colin Cross | 1b9604b | 2020-08-11 12:03:56 -0700 | [diff] [blame] | 985 | |
| 986 | func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) { |
| 987 | b.bp.CreateAliasVariation(fromVariationName, toVariationName) |
| 988 | } |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 989 | |
| 990 | func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) { |
| 991 | b.bp.SetVariationProvider(module, provider, value) |
| 992 | } |