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 ( |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 18 | "github.com/google/blueprint" |
| 19 | ) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 20 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 21 | // Phases: |
| 22 | // run Pre-arch mutators |
| 23 | // run archMutator |
| 24 | // run Pre-deps mutators |
| 25 | // run depsMutator |
| 26 | // run PostDeps mutators |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 27 | // run FinalDeps mutators (CreateVariations disallowed in this phase) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 28 | // continue on to GenerateAndroidBuildActions |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 29 | |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 30 | // collateGloballyRegisteredMutators constructs the list of mutators that have been registered |
| 31 | // with the InitRegistrationContext and will be used at runtime. |
| 32 | func collateGloballyRegisteredMutators() sortableComponents { |
| 33 | return collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps) |
| 34 | } |
| 35 | |
| 36 | // collateRegisteredMutators constructs a single list of mutators from the separate lists. |
| 37 | func collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) sortableComponents { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 38 | mctx := ®isterMutatorsContext{} |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 39 | |
| 40 | register := func(funcs []RegisterMutatorFunc) { |
| 41 | for _, f := range funcs { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 42 | f(mctx) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 46 | register(preArch) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 47 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 48 | register(preDeps) |
| 49 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 50 | register([]RegisterMutatorFunc{registerDepsMutator}) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 51 | |
| 52 | register(postDeps) |
| 53 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 54 | mctx.finalPhase = true |
| 55 | register(finalDeps) |
| 56 | |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 57 | return mctx.mutators |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | type registerMutatorsContext struct { |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 61 | mutators sortableComponents |
| 62 | finalPhase bool |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 63 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 64 | |
| 65 | type RegisterMutatorsContext interface { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 66 | TopDown(name string, m TopDownMutator) MutatorHandle |
| 67 | BottomUp(name string, m BottomUpMutator) MutatorHandle |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 68 | BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 69 | Transition(name string, m TransitionMutator) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | type RegisterMutatorFunc func(RegisterMutatorsContext) |
| 73 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 74 | var preArch = []RegisterMutatorFunc{ |
Dan Willemsen | 6e72ef7 | 2018-01-26 18:27:02 -0800 | [diff] [blame] | 75 | RegisterNamespaceMutator, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 76 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 77 | // Check the visibility rules are valid. |
| 78 | // |
| 79 | // This must run after the package renamer mutators so that any issues found during |
| 80 | // validation of the package's default_visibility property are reported using the |
| 81 | // correct package name and not the synthetic name. |
| 82 | // |
| 83 | // This must also be run before defaults mutators as the rules for validation are |
| 84 | // different before checking the rules than they are afterwards. e.g. |
| 85 | // visibility: ["//visibility:private", "//visibility:public"] |
| 86 | // would be invalid if specified in a module definition but is valid if it results |
| 87 | // from something like this: |
| 88 | // |
| 89 | // defaults { |
| 90 | // name: "defaults", |
| 91 | // // Be inaccessible outside a package by default. |
| 92 | // visibility: ["//visibility:private"] |
| 93 | // } |
| 94 | // |
| 95 | // defaultable_module { |
| 96 | // name: "defaultable_module", |
| 97 | // defaults: ["defaults"], |
| 98 | // // Override the default. |
| 99 | // visibility: ["//visibility:public"] |
| 100 | // } |
| 101 | // |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 102 | RegisterVisibilityRuleChecker, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 103 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 104 | // Record the default_applicable_licenses for each package. |
| 105 | // |
| 106 | // This must run before the defaults so that defaults modules can pick up the package default. |
| 107 | RegisterLicensesPackageMapper, |
| 108 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 109 | // Apply properties from defaults modules to the referencing modules. |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 110 | // |
| 111 | // Any mutators that are added before this will not see any modules created by |
| 112 | // a DefaultableHook. |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 113 | RegisterDefaultsPreArchMutators, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 114 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 115 | // Add dependencies on any components so that any component references can be |
| 116 | // resolved within the deps mutator. |
| 117 | // |
| 118 | // Must be run after defaults so it can be used to create dependencies on the |
| 119 | // component modules that are creating in a DefaultableHook. |
| 120 | // |
| 121 | // Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are |
| 122 | // renamed. That is so that if a module creates components using a prebuilt module |
| 123 | // type that any dependencies (which must use prebuilt_ prefixes) are resolved to |
| 124 | // the prebuilt module and not the source module. |
| 125 | RegisterComponentsMutator, |
| 126 | |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 127 | // Create an association between prebuilt modules and their corresponding source |
| 128 | // modules (if any). |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 129 | // |
| 130 | // Must be run after defaults mutators to ensure that any modules created by |
| 131 | // a DefaultableHook can be either a prebuilt or a source module with a matching |
| 132 | // prebuilt. |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 133 | RegisterPrebuiltsPreArchMutators, |
| 134 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 135 | // Gather the licenses properties for all modules for use during expansion and enforcement. |
| 136 | // |
| 137 | // This must come after the defaults mutators to ensure that any licenses supplied |
| 138 | // in a defaults module has been successfully applied before the rules are gathered. |
| 139 | RegisterLicensesPropertyGatherer, |
| 140 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 141 | // Gather the visibility rules for all modules for us during visibility enforcement. |
| 142 | // |
| 143 | // This must come after the defaults mutators to ensure that any visibility supplied |
| 144 | // 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] | 145 | RegisterVisibilityRuleGatherer, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 148 | func registerArchMutator(ctx RegisterMutatorsContext) { |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 149 | ctx.BottomUpBlueprint("os", osMutator).Parallel() |
Colin Cross | fb0c16e | 2019-11-20 17:12:35 -0800 | [diff] [blame] | 150 | ctx.BottomUp("image", imageMutator).Parallel() |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 151 | ctx.BottomUpBlueprint("arch", archMutator).Parallel() |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 154 | var preDeps = []RegisterMutatorFunc{ |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 155 | registerArchMutator, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | var postDeps = []RegisterMutatorFunc{ |
Colin Cross | 1b48842 | 2019-03-04 22:33:56 -0800 | [diff] [blame] | 159 | registerPathDepsMutator, |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 160 | RegisterPrebuiltsPostDepsMutators, |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 161 | RegisterVisibilityRuleEnforcer, |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 162 | RegisterLicensesDependencyChecker, |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 163 | registerNeverallowMutator, |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 164 | RegisterOverridePostDepsMutators, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 165 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 166 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 167 | var finalDeps = []RegisterMutatorFunc{} |
| 168 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 169 | func PreArchMutators(f RegisterMutatorFunc) { |
| 170 | preArch = append(preArch, f) |
| 171 | } |
| 172 | |
| 173 | func PreDepsMutators(f RegisterMutatorFunc) { |
| 174 | preDeps = append(preDeps, f) |
| 175 | } |
| 176 | |
| 177 | func PostDepsMutators(f RegisterMutatorFunc) { |
| 178 | postDeps = append(postDeps, f) |
| 179 | } |
| 180 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 181 | func FinalDepsMutators(f RegisterMutatorFunc) { |
| 182 | finalDeps = append(finalDeps, f) |
| 183 | } |
| 184 | |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 185 | type BaseMutatorContext interface { |
| 186 | BaseModuleContext |
| 187 | |
| 188 | // MutatorName returns the name that this mutator was registered with. |
| 189 | MutatorName() string |
| 190 | |
| 191 | // Rename all variants of a module. The new name is not visible to calls to ModuleName, |
| 192 | // AddDependency or OtherModuleName until after this mutator pass is complete. |
| 193 | Rename(name string) |
| 194 | } |
| 195 | |
| 196 | type TopDownMutator func(TopDownMutatorContext) |
| 197 | |
| 198 | type TopDownMutatorContext interface { |
| 199 | BaseMutatorContext |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 200 | |
| 201 | // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies |
| 202 | // the specified property structs to it as if the properties were set in a blueprint file. |
| 203 | CreateModule(ModuleFactory, ...interface{}) Module |
| 204 | } |
| 205 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 206 | type topDownMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 207 | bp blueprint.TopDownMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 208 | baseModuleContext |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 211 | type BottomUpMutator func(BottomUpMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 212 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 213 | type BottomUpMutatorContext interface { |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 214 | BaseMutatorContext |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 215 | |
| 216 | // AddDependency adds a dependency to the given module. It returns a slice of modules for each |
| 217 | // dependency (some entries may be nil). |
| 218 | // |
| 219 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 220 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 221 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 222 | // be ordered correctly for all future mutator passes. |
| 223 | AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 224 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 225 | // AddReverseDependency adds a dependency from the destination to the given module. |
| 226 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 227 | // correctly for all future mutator passes. All reverse dependencies for a destination module are |
| 228 | // collected until the end of the mutator pass, sorted by name, and then appended to the destination |
| 229 | // module's dependency list. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 230 | AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 231 | |
| 232 | // CreateVariations splits a module into multiple variants, one for each name in the variationNames |
| 233 | // parameter. It returns a list of new modules in the same order as the variationNames |
| 234 | // list. |
| 235 | // |
| 236 | // If any of the dependencies of the module being operated on were already split |
| 237 | // by calling CreateVariations with the same name, the dependency will automatically |
| 238 | // be updated to point the matching variant. |
| 239 | // |
| 240 | // If a module is split, and then a module depending on the first module is not split |
| 241 | // when the Mutator is later called on it, the dependency of the depending module will |
| 242 | // automatically be updated to point to the first variant. |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 243 | CreateVariations(...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 244 | |
| 245 | // CreateLocationVariations splits a module into multiple variants, one for each name in the variantNames |
| 246 | // parameter. It returns a list of new modules in the same order as the variantNames |
| 247 | // list. |
| 248 | // |
| 249 | // Local variations do not affect automatic dependency resolution - dependencies added |
| 250 | // to the split module via deps or DynamicDependerModule must exactly match a variant |
| 251 | // that contains all the non-local variations. |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 252 | CreateLocalVariations(...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 253 | |
| 254 | // SetDependencyVariation sets all dangling dependencies on the current module to point to the variation |
| 255 | // with given name. This function ignores the default variation set by SetDefaultDependencyVariation. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 256 | SetDependencyVariation(string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 257 | |
| 258 | // SetDefaultDependencyVariation sets the default variation when a dangling reference is detected |
| 259 | // 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] | 260 | SetDefaultDependencyVariation(*string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 261 | |
| 262 | // 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] | 263 | // argument to select which variant of the dependency to use. It returns a slice of modules for |
| 264 | // 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] | 265 | // 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] | 266 | // |
| 267 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 268 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 269 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 270 | // be ordered correctly for all future mutator passes. |
Usta Shrestha | c725f47 | 2022-01-11 02:44:21 -0500 | [diff] [blame] | 271 | AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 272 | |
| 273 | // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 274 | // variations argument to select which variant of the dependency to use. It returns a slice of |
| 275 | // modules for each dependency (some entries may be nil). A variant of the dependency must |
| 276 | // exist that matches the variations argument, but may also have other variations. |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 277 | // For any unspecified variation the first variant will be used. |
| 278 | // |
| 279 | // Unlike AddVariationDependencies, the variations of the current module are ignored - the |
| 280 | // dependency only needs to match the supplied variations. |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 281 | // |
| 282 | // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the |
| 283 | // new dependencies have had the current mutator called on them. If the mutator is not |
| 284 | // parallel this method does not affect the ordering of the current mutator pass, but will |
| 285 | // be ordered correctly for all future mutator passes. |
| 286 | AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 287 | |
| 288 | // AddInterVariantDependency adds a dependency between two variants of the same module. Variants are always |
| 289 | // ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change |
| 290 | // that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps, |
| 291 | // WalkDeps, etc. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 292 | AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 293 | |
| 294 | // ReplaceDependencies replaces all dependencies on the identical variant of the module with the |
| 295 | // specified name with the current variant of this module. Replacements don't take effect until |
| 296 | // after the mutator pass is finished. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 297 | ReplaceDependencies(string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 298 | |
| 299 | // ReplaceDependencies replaces all dependencies on the identical variant of the module with the |
| 300 | // specified name with the current variant of this module as long as the supplied predicate returns |
| 301 | // true. |
| 302 | // |
| 303 | // Replacements don't take effect until after the mutator pass is finished. |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 304 | ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 305 | |
| 306 | // AliasVariation takes a variationName that was passed to CreateVariations for this module, |
| 307 | // and creates an alias from the current variant (before the mutator has run) to the new |
| 308 | // variant. The alias will be valid until the next time a mutator calls CreateVariations or |
| 309 | // CreateLocalVariations on this module without also calling AliasVariation. The alias can |
| 310 | // be used to add dependencies on the newly created variant using the variant map from |
| 311 | // before CreateVariations was run. |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 312 | AliasVariation(variationName string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 313 | |
| 314 | // CreateAliasVariation takes a toVariationName that was passed to CreateVariations for this |
| 315 | // module, and creates an alias from a new fromVariationName variant the toVariationName |
| 316 | // variant. The alias will be valid until the next time a mutator calls CreateVariations or |
| 317 | // CreateLocalVariations on this module without also calling AliasVariation. The alias can |
| 318 | // be used to add dependencies on the toVariationName variant using the fromVariationName |
| 319 | // variant. |
Colin Cross | 1b9604b | 2020-08-11 12:03:56 -0700 | [diff] [blame] | 320 | CreateAliasVariation(fromVariationName, toVariationName string) |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 321 | |
| 322 | // SetVariationProvider sets the value for a provider for the given newly created variant of |
| 323 | // the current module, i.e. one of the Modules returned by CreateVariations.. It panics if |
| 324 | // not called during the appropriate mutator or GenerateBuildActions pass for the provider, |
| 325 | // if the value is not of the appropriate type, or if the module is not a newly created |
| 326 | // variant of the current module. The value should not be modified after being passed to |
| 327 | // SetVariationProvider. |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 328 | SetVariationProvider(module blueprint.Module, provider blueprint.AnyProviderKey, value interface{}) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 331 | type bottomUpMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 332 | bp blueprint.BottomUpMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 333 | baseModuleContext |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 334 | finalPhase bool |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 337 | func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module, |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 338 | finalPhase bool) BottomUpMutatorContext { |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 339 | |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 340 | moduleContext := a.base().baseModuleContextFactory(ctx) |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 341 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 342 | return &bottomUpMutatorContext{ |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 343 | bp: ctx, |
Cole Faust | 0abd4b4 | 2023-01-10 10:49:18 -0800 | [diff] [blame] | 344 | baseModuleContext: moduleContext, |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 345 | finalPhase: finalPhase, |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 349 | func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 350 | finalPhase := x.finalPhase |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 351 | f := func(ctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 352 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 353 | m(bottomUpMutatorContextFactory(ctx, a, finalPhase)) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 354 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 355 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 356 | mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 357 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 358 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 361 | func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle { |
| 362 | mutator := &mutator{name: name, bottomUpMutator: m} |
| 363 | x.mutators = append(x.mutators, mutator) |
| 364 | return mutator |
| 365 | } |
| 366 | |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 367 | type IncomingTransitionContext interface { |
| 368 | // Module returns the target of the dependency edge for which the transition |
| 369 | // is being computed |
| 370 | Module() Module |
| 371 | |
| 372 | // Config returns the configuration for the build. |
| 373 | Config() Config |
| 374 | } |
| 375 | |
| 376 | type OutgoingTransitionContext interface { |
| 377 | // Module returns the target of the dependency edge for which the transition |
| 378 | // is being computed |
| 379 | Module() Module |
| 380 | |
| 381 | // DepTag() Returns the dependency tag through which this dependency is |
| 382 | // reached |
| 383 | DepTag() blueprint.DependencyTag |
| 384 | } |
Lukacs T. Berki | 0e691c1 | 2022-06-24 10:15:55 +0200 | [diff] [blame] | 385 | |
| 386 | // Transition mutators implement a top-down mechanism where a module tells its |
| 387 | // direct dependencies what variation they should be built in but the dependency |
| 388 | // has the final say. |
| 389 | // |
| 390 | // When implementing a transition mutator, one needs to implement four methods: |
| 391 | // - Split() that tells what variations a module has by itself |
| 392 | // - OutgoingTransition() where a module tells what it wants from its |
| 393 | // dependency |
| 394 | // - IncomingTransition() where a module has the final say about its own |
| 395 | // variation |
| 396 | // - Mutate() that changes the state of a module depending on its variation |
| 397 | // |
| 398 | // That the effective variation of module B when depended on by module A is the |
| 399 | // composition the outgoing transition of module A and the incoming transition |
| 400 | // of module B. |
| 401 | // |
| 402 | // the outgoing transition should not take the properties of the dependency into |
| 403 | // account, only those of the module that depends on it. For this reason, the |
| 404 | // dependency is not even passed into it as an argument. Likewise, the incoming |
| 405 | // transition should not take the properties of the depending module into |
| 406 | // account and is thus not informed about it. This makes for a nice |
| 407 | // decomposition of the decision logic. |
| 408 | // |
| 409 | // A given transition mutator only affects its own variation; other variations |
| 410 | // stay unchanged along the dependency edges. |
| 411 | // |
| 412 | // Soong makes sure that all modules are created in the desired variations and |
| 413 | // that dependency edges are set up correctly. This ensures that "missing |
| 414 | // variation" errors do not happen and allows for more flexible changes in the |
| 415 | // value of the variation among dependency edges (as oppposed to bottom-up |
| 416 | // mutators where if module A in variation X depends on module B and module B |
| 417 | // has that variation X, A must depend on variation X of B) |
| 418 | // |
| 419 | // The limited power of the context objects passed to individual mutators |
| 420 | // methods also makes it more difficult to shoot oneself in the foot. Complete |
| 421 | // safety is not guaranteed because no one prevents individual transition |
| 422 | // mutators from mutating modules in illegal ways and for e.g. Split() or |
| 423 | // Mutate() to run their own visitations of the transitive dependency of the |
| 424 | // module and both of these are bad ideas, but it's better than no guardrails at |
| 425 | // all. |
| 426 | // |
| 427 | // This model is pretty close to Bazel's configuration transitions. The mapping |
| 428 | // between concepts in Soong and Bazel is as follows: |
| 429 | // - Module == configured target |
| 430 | // - Variant == configuration |
| 431 | // - Variation name == configuration flag |
| 432 | // - Variation == configuration flag value |
| 433 | // - Outgoing transition == attribute transition |
| 434 | // - Incoming transition == rule transition |
| 435 | // |
| 436 | // The Split() method does not have a Bazel equivalent and Bazel split |
| 437 | // transitions do not have a Soong equivalent. |
| 438 | // |
| 439 | // Mutate() does not make sense in Bazel due to the different models of the |
| 440 | // two systems: when creating new variations, Soong clones the old module and |
| 441 | // thus some way is needed to change it state whereas Bazel creates each |
| 442 | // configuration of a given configured target anew. |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 443 | type TransitionMutator interface { |
| 444 | // Split returns the set of variations that should be created for a module no |
| 445 | // matter who depends on it. Used when Make depends on a particular variation |
| 446 | // or when the module knows its variations just based on information given to |
| 447 | // it in the Blueprint file. This method should not mutate the module it is |
| 448 | // called on. |
| 449 | Split(ctx BaseModuleContext) []string |
| 450 | |
Lukacs T. Berki | 0e691c1 | 2022-06-24 10:15:55 +0200 | [diff] [blame] | 451 | // 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] | 452 | // dependencies. The dependency itself can override this decision. This method |
| 453 | // should not mutate the module itself. |
| 454 | OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string |
| 455 | |
| 456 | // Called on a module to determine which variation it should be in based on |
| 457 | // the variation modules that depend on it want. This gives the module a final |
| 458 | // say about its own variations. This method should not mutate the module |
| 459 | // itself. |
| 460 | IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string |
| 461 | |
| 462 | // Called after a module was split into multiple variations on each variation. |
| 463 | // It should not split the module any further but adding new dependencies is |
| 464 | // fine. Unlike all the other methods on TransitionMutator, this method is |
| 465 | // allowed to mutate the module. |
| 466 | Mutate(ctx BottomUpMutatorContext, variation string) |
| 467 | } |
| 468 | |
| 469 | type androidTransitionMutator struct { |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 470 | finalPhase bool |
| 471 | mutator TransitionMutator |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | func (a *androidTransitionMutator) Split(ctx blueprint.BaseModuleContext) []string { |
| 475 | if m, ok := ctx.Module().(Module); ok { |
| 476 | moduleContext := m.base().baseModuleContextFactory(ctx) |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 477 | return a.mutator.Split(&moduleContext) |
| 478 | } else { |
| 479 | return []string{""} |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | type outgoingTransitionContextImpl struct { |
| 484 | bp blueprint.OutgoingTransitionContext |
| 485 | } |
| 486 | |
| 487 | func (c *outgoingTransitionContextImpl) Module() Module { |
| 488 | return c.bp.Module().(Module) |
| 489 | } |
| 490 | |
| 491 | func (c *outgoingTransitionContextImpl) DepTag() blueprint.DependencyTag { |
| 492 | return c.bp.DepTag() |
| 493 | } |
| 494 | |
| 495 | func (a *androidTransitionMutator) OutgoingTransition(ctx blueprint.OutgoingTransitionContext, sourceVariation string) string { |
| 496 | if _, ok := ctx.Module().(Module); ok { |
| 497 | return a.mutator.OutgoingTransition(&outgoingTransitionContextImpl{bp: ctx}, sourceVariation) |
| 498 | } else { |
| 499 | return "" |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | type incomingTransitionContextImpl struct { |
| 504 | bp blueprint.IncomingTransitionContext |
| 505 | } |
| 506 | |
| 507 | func (c *incomingTransitionContextImpl) Module() Module { |
| 508 | return c.bp.Module().(Module) |
| 509 | } |
| 510 | |
| 511 | func (c *incomingTransitionContextImpl) Config() Config { |
| 512 | return c.bp.Config().(Config) |
| 513 | } |
| 514 | |
| 515 | func (a *androidTransitionMutator) IncomingTransition(ctx blueprint.IncomingTransitionContext, incomingVariation string) string { |
| 516 | if _, ok := ctx.Module().(Module); ok { |
| 517 | return a.mutator.IncomingTransition(&incomingTransitionContextImpl{bp: ctx}, incomingVariation) |
| 518 | } else { |
| 519 | return "" |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | func (a *androidTransitionMutator) Mutate(ctx blueprint.BottomUpMutatorContext, variation string) { |
| 524 | if am, ok := ctx.Module().(Module); ok { |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 525 | a.mutator.Mutate(bottomUpMutatorContextFactory(ctx, am, a.finalPhase), variation) |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| 529 | func (x *registerMutatorsContext) Transition(name string, m TransitionMutator) { |
| 530 | atm := &androidTransitionMutator{ |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 531 | finalPhase: x.finalPhase, |
| 532 | mutator: m, |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 533 | } |
| 534 | mutator := &mutator{ |
| 535 | name: name, |
| 536 | transitionMutator: atm} |
| 537 | x.mutators = append(x.mutators, mutator) |
| 538 | } |
| 539 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 540 | func (x *registerMutatorsContext) mutatorName(name string) string { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 541 | return name |
| 542 | } |
| 543 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 544 | func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 545 | f := func(ctx blueprint.TopDownMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 546 | if a, ok := ctx.Module().(Module); ok { |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 547 | moduleContext := a.base().baseModuleContextFactory(ctx) |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 548 | actx := &topDownMutatorContext{ |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 549 | bp: ctx, |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 550 | baseModuleContext: moduleContext, |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 551 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 552 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 553 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 554 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 555 | mutator := &mutator{name: x.mutatorName(name), topDownMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 556 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 557 | return mutator |
| 558 | } |
| 559 | |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 560 | func (mutator *mutator) componentName() string { |
| 561 | return mutator.name |
| 562 | } |
| 563 | |
| 564 | func (mutator *mutator) register(ctx *Context) { |
| 565 | blueprintCtx := ctx.Context |
| 566 | var handle blueprint.MutatorHandle |
| 567 | if mutator.bottomUpMutator != nil { |
| 568 | handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator) |
| 569 | } else if mutator.topDownMutator != nil { |
| 570 | handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator) |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 571 | } else if mutator.transitionMutator != nil { |
| 572 | blueprintCtx.RegisterTransitionMutator(mutator.name, mutator.transitionMutator) |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 573 | } |
| 574 | if mutator.parallel { |
| 575 | handle.Parallel() |
| 576 | } |
| 577 | } |
| 578 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 579 | type MutatorHandle interface { |
| 580 | Parallel() MutatorHandle |
| 581 | } |
| 582 | |
| 583 | func (mutator *mutator) Parallel() MutatorHandle { |
| 584 | mutator.parallel = true |
| 585 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 586 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 587 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 588 | func RegisterComponentsMutator(ctx RegisterMutatorsContext) { |
| 589 | ctx.BottomUp("component-deps", componentDepsMutator).Parallel() |
| 590 | } |
| 591 | |
| 592 | // A special mutator that runs just prior to the deps mutator to allow the dependencies |
| 593 | // on component modules to be added so that they can depend directly on a prebuilt |
| 594 | // module. |
| 595 | func componentDepsMutator(ctx BottomUpMutatorContext) { |
| 596 | if m := ctx.Module(); m.Enabled() { |
| 597 | m.ComponentDepsMutator(ctx) |
| 598 | } |
| 599 | } |
| 600 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 601 | func depsMutator(ctx BottomUpMutatorContext) { |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 602 | if m := ctx.Module(); m.Enabled() { |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame^] | 603 | m.base().baseDepsMutator(ctx) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 604 | m.DepsMutator(ctx) |
| 605 | } |
| 606 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 607 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 608 | func registerDepsMutator(ctx RegisterMutatorsContext) { |
| 609 | ctx.BottomUp("deps", depsMutator).Parallel() |
| 610 | } |
| 611 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 612 | // android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that |
| 613 | // has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid |
| 614 | // ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every |
| 615 | // non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following |
| 616 | // methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext. |
| 617 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 618 | func (t *topDownMutatorContext) MutatorName() string { |
| 619 | return t.bp.MutatorName() |
| 620 | } |
| 621 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 622 | func (t *topDownMutatorContext) Rename(name string) { |
| 623 | t.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 624 | t.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 625 | } |
| 626 | |
Liz Kammer | f31c900 | 2022-04-26 09:08:55 -0400 | [diff] [blame] | 627 | func (t *topDownMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module { |
| 628 | return t.bp.CreateModule(factory, name, props...) |
| 629 | } |
| 630 | |
Colin Cross | e003c4a | 2019-09-25 12:58:36 -0700 | [diff] [blame] | 631 | func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { |
Liz Kammer | f31c900 | 2022-04-26 09:08:55 -0400 | [diff] [blame] | 632 | return createModule(t, factory, "_topDownMutatorModule", props...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 635 | func (t *topDownMutatorContext) createModuleWithoutInheritance(factory ModuleFactory, props ...interface{}) Module { |
Liz Kammer | f31c900 | 2022-04-26 09:08:55 -0400 | [diff] [blame] | 636 | module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), "", props...).(Module) |
Liz Kammer | a060c45 | 2021-03-24 10:14:47 -0400 | [diff] [blame] | 637 | return module |
| 638 | } |
| 639 | |
Colin Cross | cb55e08 | 2019-07-01 15:32:31 -0700 | [diff] [blame] | 640 | func (b *bottomUpMutatorContext) MutatorName() string { |
| 641 | return b.bp.MutatorName() |
| 642 | } |
| 643 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 644 | func (b *bottomUpMutatorContext) Rename(name string) { |
| 645 | b.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 646 | b.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 649 | 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] | 650 | if b.baseModuleContext.checkedMissingDeps() { |
| 651 | panic("Adding deps not allowed after checking for missing deps") |
| 652 | } |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 653 | return b.bp.AddDependency(module, tag, name...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 657 | if b.baseModuleContext.checkedMissingDeps() { |
| 658 | panic("Adding deps not allowed after checking for missing deps") |
| 659 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 660 | b.bp.AddReverseDependency(module, tag, name) |
| 661 | } |
| 662 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 663 | func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 664 | if b.finalPhase { |
| 665 | panic("CreateVariations not allowed in FinalDepsMutators") |
| 666 | } |
| 667 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 668 | modules := b.bp.CreateVariations(variations...) |
| 669 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 670 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 671 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 672 | aModules[i] = modules[i].(Module) |
| 673 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 674 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 675 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 676 | } |
| 677 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 678 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 681 | func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 682 | if b.finalPhase { |
| 683 | panic("CreateLocalVariations not allowed in FinalDepsMutators") |
| 684 | } |
| 685 | |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 686 | modules := b.bp.CreateLocalVariations(variations...) |
| 687 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 688 | aModules := make([]Module, len(modules)) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 689 | for i := range variations { |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 690 | aModules[i] = modules[i].(Module) |
| 691 | base := aModules[i].base() |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 692 | base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName()) |
| 693 | base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i]) |
| 694 | } |
| 695 | |
Colin Cross | 43b92e0 | 2019-11-18 15:28:57 -0800 | [diff] [blame] | 696 | return aModules |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) { |
| 700 | b.bp.SetDependencyVariation(variation) |
| 701 | } |
| 702 | |
Jiyong Park | 1d1119f | 2019-07-29 21:27:18 +0900 | [diff] [blame] | 703 | func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) { |
| 704 | b.bp.SetDefaultDependencyVariation(variation) |
| 705 | } |
| 706 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 707 | func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 708 | names ...string) []blueprint.Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 709 | if b.baseModuleContext.checkedMissingDeps() { |
| 710 | panic("Adding deps not allowed after checking for missing deps") |
| 711 | } |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 712 | return b.bp.AddVariationDependencies(variations, tag, names...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation, |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 716 | tag blueprint.DependencyTag, names ...string) []blueprint.Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 717 | if b.baseModuleContext.checkedMissingDeps() { |
| 718 | panic("Adding deps not allowed after checking for missing deps") |
| 719 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 720 | |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 721 | return b.bp.AddFarVariationDependencies(variations, tag, names...) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) { |
| 725 | b.bp.AddInterVariantDependency(tag, from, to) |
| 726 | } |
| 727 | |
| 728 | func (b *bottomUpMutatorContext) ReplaceDependencies(name string) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 729 | if b.baseModuleContext.checkedMissingDeps() { |
| 730 | panic("Adding deps not allowed after checking for missing deps") |
| 731 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 732 | b.bp.ReplaceDependencies(name) |
| 733 | } |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 734 | |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 735 | func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 736 | if b.baseModuleContext.checkedMissingDeps() { |
| 737 | panic("Adding deps not allowed after checking for missing deps") |
| 738 | } |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 739 | b.bp.ReplaceDependenciesIf(name, predicate) |
| 740 | } |
| 741 | |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 742 | func (b *bottomUpMutatorContext) AliasVariation(variationName string) { |
| 743 | b.bp.AliasVariation(variationName) |
| 744 | } |
Colin Cross | 1b9604b | 2020-08-11 12:03:56 -0700 | [diff] [blame] | 745 | |
| 746 | func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) { |
| 747 | b.bp.CreateAliasVariation(fromVariationName, toVariationName) |
| 748 | } |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 749 | |
Colin Cross | 3c0a83d | 2023-12-12 14:13:26 -0800 | [diff] [blame] | 750 | func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.AnyProviderKey, value interface{}) { |
Colin Cross | d27e7b8 | 2020-07-02 11:38:17 -0700 | [diff] [blame] | 751 | b.bp.SetVariationProvider(module, provider, value) |
| 752 | } |