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