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