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