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 | 984223f | 2024-02-01 17:10:23 -0800 | [diff] [blame] | 18 | "sync" |
| 19 | |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" |
| 21 | ) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 22 | |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 23 | // Phases: |
| 24 | // run Pre-arch mutators |
| 25 | // run archMutator |
| 26 | // run Pre-deps mutators |
| 27 | // run depsMutator |
| 28 | // run PostDeps mutators |
Colin Cross | 1e954b6 | 2024-09-13 13:50:00 -0700 | [diff] [blame] | 29 | // run FinalDeps mutators (TransitionMutators disallowed in this phase) |
Jeff Gaston | af3cc2d | 2017-09-27 17:01:44 -0700 | [diff] [blame] | 30 | // continue on to GenerateAndroidBuildActions |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 31 | |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 32 | // collateGloballyRegisteredMutators constructs the list of mutators that have been registered |
| 33 | // with the InitRegistrationContext and will be used at runtime. |
| 34 | func collateGloballyRegisteredMutators() sortableComponents { |
Colin Cross | f22fe41 | 2024-10-01 14:02:12 -0700 | [diff] [blame] | 35 | return collateRegisteredMutators(preArch, preDeps, postDeps, postApex, finalDeps) |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // collateRegisteredMutators constructs a single list of mutators from the separate lists. |
Colin Cross | f22fe41 | 2024-10-01 14:02:12 -0700 | [diff] [blame] | 39 | func collateRegisteredMutators(preArch, preDeps, postDeps, postApex, finalDeps []RegisterMutatorFunc) sortableComponents { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 40 | mctx := ®isterMutatorsContext{} |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 41 | |
| 42 | register := func(funcs []RegisterMutatorFunc) { |
| 43 | for _, f := range funcs { |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 44 | f(mctx) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 48 | register(preArch) |
Nan Zhang | db0b9a3 | 2017-02-27 10:12:13 -0800 | [diff] [blame] | 49 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 50 | register(preDeps) |
| 51 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 52 | register([]RegisterMutatorFunc{registerDepsMutator}) |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 53 | |
| 54 | register(postDeps) |
| 55 | |
Colin Cross | f22fe41 | 2024-10-01 14:02:12 -0700 | [diff] [blame] | 56 | register(postApex) |
| 57 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 58 | mctx.finalPhase = true |
| 59 | register(finalDeps) |
| 60 | |
Paul Duffin | c05b034 | 2021-03-06 13:28:13 +0000 | [diff] [blame] | 61 | return mctx.mutators |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | type registerMutatorsContext struct { |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 65 | mutators sortableComponents |
| 66 | finalPhase bool |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 67 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 68 | |
| 69 | type RegisterMutatorsContext interface { |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 70 | TopDown(name string, m TopDownMutator) MutatorHandle |
| 71 | BottomUp(name string, m BottomUpMutator) MutatorHandle |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 72 | BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle |
Colin Cross | 90d7df9 | 2025-01-31 11:29:33 -0800 | [diff] [blame^] | 73 | Transition(name string, m VariationTransitionMutator) TransitionMutatorHandle |
| 74 | InfoBasedTransition(name string, m androidTransitionMutator) TransitionMutatorHandle |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | type RegisterMutatorFunc func(RegisterMutatorsContext) |
| 78 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 79 | var preArch = []RegisterMutatorFunc{ |
Dan Willemsen | 6e72ef7 | 2018-01-26 18:27:02 -0800 | [diff] [blame] | 80 | RegisterNamespaceMutator, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 81 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 82 | // Check the visibility rules are valid. |
| 83 | // |
| 84 | // This must run after the package renamer mutators so that any issues found during |
| 85 | // validation of the package's default_visibility property are reported using the |
| 86 | // correct package name and not the synthetic name. |
| 87 | // |
| 88 | // This must also be run before defaults mutators as the rules for validation are |
| 89 | // different before checking the rules than they are afterwards. e.g. |
| 90 | // visibility: ["//visibility:private", "//visibility:public"] |
| 91 | // would be invalid if specified in a module definition but is valid if it results |
| 92 | // from something like this: |
| 93 | // |
| 94 | // defaults { |
| 95 | // name: "defaults", |
| 96 | // // Be inaccessible outside a package by default. |
| 97 | // visibility: ["//visibility:private"] |
| 98 | // } |
| 99 | // |
| 100 | // defaultable_module { |
| 101 | // name: "defaultable_module", |
| 102 | // defaults: ["defaults"], |
| 103 | // // Override the default. |
| 104 | // visibility: ["//visibility:public"] |
| 105 | // } |
| 106 | // |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 107 | RegisterVisibilityRuleChecker, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 108 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 109 | // Record the default_applicable_licenses for each package. |
| 110 | // |
| 111 | // This must run before the defaults so that defaults modules can pick up the package default. |
| 112 | RegisterLicensesPackageMapper, |
| 113 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 114 | // Apply properties from defaults modules to the referencing modules. |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 115 | // |
| 116 | // Any mutators that are added before this will not see any modules created by |
| 117 | // a DefaultableHook. |
Colin Cross | 89536d4 | 2017-07-07 14:35:50 -0700 | [diff] [blame] | 118 | RegisterDefaultsPreArchMutators, |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 119 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 120 | // Add dependencies on any components so that any component references can be |
| 121 | // resolved within the deps mutator. |
| 122 | // |
| 123 | // Must be run after defaults so it can be used to create dependencies on the |
| 124 | // component modules that are creating in a DefaultableHook. |
| 125 | // |
| 126 | // Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are |
| 127 | // renamed. That is so that if a module creates components using a prebuilt module |
| 128 | // type that any dependencies (which must use prebuilt_ prefixes) are resolved to |
| 129 | // the prebuilt module and not the source module. |
| 130 | RegisterComponentsMutator, |
| 131 | |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 132 | // Create an association between prebuilt modules and their corresponding source |
| 133 | // modules (if any). |
Paul Duffin | afa9fa1 | 2020-04-29 16:47:28 +0100 | [diff] [blame] | 134 | // |
| 135 | // Must be run after defaults mutators to ensure that any modules created by |
| 136 | // a DefaultableHook can be either a prebuilt or a source module with a matching |
| 137 | // prebuilt. |
Paul Duffin | c988c8e | 2020-04-29 18:27:14 +0100 | [diff] [blame] | 138 | RegisterPrebuiltsPreArchMutators, |
| 139 | |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 140 | // Gather the licenses properties for all modules for use during expansion and enforcement. |
| 141 | // |
| 142 | // This must come after the defaults mutators to ensure that any licenses supplied |
| 143 | // in a defaults module has been successfully applied before the rules are gathered. |
| 144 | RegisterLicensesPropertyGatherer, |
| 145 | |
Paul Duffin | aa4162e | 2020-05-05 11:35:43 +0100 | [diff] [blame] | 146 | // Gather the visibility rules for all modules for us during visibility enforcement. |
| 147 | // |
| 148 | // This must come after the defaults mutators to ensure that any visibility supplied |
| 149 | // 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] | 150 | RegisterVisibilityRuleGatherer, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 153 | func registerArchMutator(ctx RegisterMutatorsContext) { |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 154 | ctx.Transition("os", &osTransitionMutator{}) |
Cole Faust | 5b7635d | 2024-10-28 13:01:12 -0700 | [diff] [blame] | 155 | ctx.BottomUp("image_begin", imageMutatorBeginMutator) |
Jihoon Kang | 5402bbd | 2024-07-31 18:37:49 +0000 | [diff] [blame] | 156 | ctx.Transition("image", &imageTransitionMutator{}) |
Colin Cross | 8bbc3d5 | 2024-09-11 15:33:54 -0700 | [diff] [blame] | 157 | ctx.Transition("arch", &archTransitionMutator{}) |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 160 | var preDeps = []RegisterMutatorFunc{ |
Colin Cross | ae4c618 | 2017-09-15 17:33:55 -0700 | [diff] [blame] | 161 | registerArchMutator, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | var postDeps = []RegisterMutatorFunc{ |
Colin Cross | 1b48842 | 2019-03-04 22:33:56 -0800 | [diff] [blame] | 165 | registerPathDepsMutator, |
Colin Cross | 5ea9bcc | 2017-07-27 15:41:32 -0700 | [diff] [blame] | 166 | RegisterPrebuiltsPostDepsMutators, |
Paul Duffin | 593b3c9 | 2019-12-05 14:31:48 +0000 | [diff] [blame] | 167 | RegisterVisibilityRuleEnforcer, |
Bob Badour | 37af046 | 2021-01-07 03:34:31 +0000 | [diff] [blame] | 168 | RegisterLicensesDependencyChecker, |
Paul Duffin | 45338f0 | 2021-03-30 23:07:52 +0100 | [diff] [blame] | 169 | registerNeverallowMutator, |
Jaewoong Jung | b639a6a | 2019-05-10 15:16:29 -0700 | [diff] [blame] | 170 | RegisterOverridePostDepsMutators, |
Colin Cross | cec8171 | 2017-07-13 14:43:27 -0700 | [diff] [blame] | 171 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 172 | |
Colin Cross | f22fe41 | 2024-10-01 14:02:12 -0700 | [diff] [blame] | 173 | var postApex = []RegisterMutatorFunc{} |
| 174 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 175 | var finalDeps = []RegisterMutatorFunc{} |
| 176 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 177 | func PreArchMutators(f RegisterMutatorFunc) { |
| 178 | preArch = append(preArch, f) |
| 179 | } |
| 180 | |
| 181 | func PreDepsMutators(f RegisterMutatorFunc) { |
| 182 | preDeps = append(preDeps, f) |
| 183 | } |
| 184 | |
| 185 | func PostDepsMutators(f RegisterMutatorFunc) { |
| 186 | postDeps = append(postDeps, f) |
| 187 | } |
| 188 | |
Colin Cross | f22fe41 | 2024-10-01 14:02:12 -0700 | [diff] [blame] | 189 | func PostApexMutators(f RegisterMutatorFunc) { |
| 190 | postApex = append(postApex, f) |
| 191 | } |
| 192 | |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 193 | func FinalDepsMutators(f RegisterMutatorFunc) { |
| 194 | finalDeps = append(finalDeps, f) |
| 195 | } |
| 196 | |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 197 | type TopDownMutator func(TopDownMutatorContext) |
| 198 | |
| 199 | type TopDownMutatorContext interface { |
Colin Cross | b2388e3 | 2024-10-07 15:05:23 -0700 | [diff] [blame] | 200 | BaseModuleContext |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 203 | type topDownMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 204 | bp blueprint.TopDownMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 205 | baseModuleContext |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 208 | type BottomUpMutator func(BottomUpMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 209 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 210 | type BottomUpMutatorContext interface { |
Colin Cross | b2388e3 | 2024-10-07 15:05:23 -0700 | [diff] [blame] | 211 | BaseModuleContext |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 212 | |
| 213 | // AddDependency adds a dependency to the given module. It returns a slice of modules for each |
| 214 | // dependency (some entries may be nil). |
| 215 | // |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 216 | // This method will pause until the new dependencies have had the current mutator called on them. |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 217 | AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []Module |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 218 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 219 | // AddReverseDependency adds a dependency from the destination to the given module. |
| 220 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 221 | // correctly for all future mutator passes. All reverse dependencies for a destination module are |
| 222 | // collected until the end of the mutator pass, sorted by name, and then appended to the destination |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 223 | // module's dependency list. May only be called by mutators that were marked with |
| 224 | // UsesReverseDependencies during registration. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 225 | AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 226 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 227 | // 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] | 228 | // argument to select which variant of the dependency to use. It returns a slice of modules for |
| 229 | // 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] | 230 | // 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] | 231 | // |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 232 | // This method will pause until the new dependencies have had the current mutator called on them. |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 233 | AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 234 | |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 235 | // AddReverseVariationDependency adds a dependency from the named module to the current |
Cole Faust | f4992e8 | 2024-09-30 15:16:18 -0700 | [diff] [blame] | 236 | // module. The given variations will be added to the current module's varations, and then the |
| 237 | // result will be used to find the correct variation of the depending module, which must exist. |
| 238 | // |
| 239 | // Does not affect the ordering of the current mutator pass, but will be ordered |
| 240 | // correctly for all future mutator passes. All reverse dependencies for a destination module are |
| 241 | // collected until the end of the mutator pass, sorted by name, and then appended to the destination |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 242 | // module's dependency list. May only be called by mutators that were marked with |
| 243 | // UsesReverseDependencies during registration. |
Cole Faust | f4992e8 | 2024-09-30 15:16:18 -0700 | [diff] [blame] | 244 | AddReverseVariationDependency([]blueprint.Variation, blueprint.DependencyTag, string) |
| 245 | |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 246 | // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 247 | // variations argument to select which variant of the dependency to use. It returns a slice of |
| 248 | // modules for each dependency (some entries may be nil). A variant of the dependency must |
| 249 | // exist that matches the variations argument, but may also have other variations. |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 250 | // For any unspecified variation the first variant will be used. |
| 251 | // |
| 252 | // Unlike AddVariationDependencies, the variations of the current module are ignored - the |
| 253 | // dependency only needs to match the supplied variations. |
Colin Cross | 4f1dcb0 | 2020-09-16 18:45:04 -0700 | [diff] [blame] | 254 | // |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 255 | // This method will pause until the new dependencies have had the current mutator called on them. |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 256 | AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []Module |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 257 | |
Colin Cross | 8677132 | 2024-05-01 14:19:51 -0700 | [diff] [blame] | 258 | // ReplaceDependencies finds all the variants of the module with the specified name, then |
| 259 | // replaces all dependencies onto those variants with the current variant of this module. |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 260 | // Replacements don't take effect until after the mutator pass is finished. May only |
| 261 | // be called by mutators that were marked with UsesReplaceDependencies during registration. |
Colin Cross | aabf679 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 262 | ReplaceDependencies(string) |
Colin Cross | 9f35c3d | 2020-09-16 19:04:41 -0700 | [diff] [blame] | 263 | |
Colin Cross | 8677132 | 2024-05-01 14:19:51 -0700 | [diff] [blame] | 264 | // ReplaceDependenciesIf finds all the variants of the module with the specified name, then |
| 265 | // replaces all dependencies onto those variants with the current variant of this module |
| 266 | // as long as the supplied predicate returns true. |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 267 | // Replacements don't take effect until after the mutator pass is finished. May only |
| 268 | // be called by mutators that were marked with UsesReplaceDependencies during registration. |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 269 | ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate) |
Colin Cross | b2388e3 | 2024-10-07 15:05:23 -0700 | [diff] [blame] | 270 | |
| 271 | // Rename all variants of a module. The new name is not visible to calls to ModuleName, |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 272 | // AddDependency or OtherModuleName until after this mutator pass is complete. May only be called |
| 273 | // by mutators that were marked with UsesRename during registration. |
Colin Cross | b2388e3 | 2024-10-07 15:05:23 -0700 | [diff] [blame] | 274 | Rename(name string) |
| 275 | |
| 276 | // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 277 | // the specified property structs to it as if the properties were set in a blueprint file. May only |
| 278 | // be called by mutators that were marked with UsesCreateModule during registration. |
Colin Cross | b2388e3 | 2024-10-07 15:05:23 -0700 | [diff] [blame] | 279 | CreateModule(ModuleFactory, ...interface{}) Module |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Colin Cross | 984223f | 2024-02-01 17:10:23 -0800 | [diff] [blame] | 282 | // An outgoingTransitionContextImpl and incomingTransitionContextImpl is created for every dependency of every module |
| 283 | // for each transition mutator. bottomUpMutatorContext and topDownMutatorContext are created once for every module |
| 284 | // for every BottomUp or TopDown mutator. Use a global pool for each to avoid reallocating every time. |
| 285 | var ( |
| 286 | outgoingTransitionContextPool = sync.Pool{ |
| 287 | New: func() any { return &outgoingTransitionContextImpl{} }, |
| 288 | } |
| 289 | incomingTransitionContextPool = sync.Pool{ |
| 290 | New: func() any { return &incomingTransitionContextImpl{} }, |
| 291 | } |
| 292 | bottomUpMutatorContextPool = sync.Pool{ |
| 293 | New: func() any { return &bottomUpMutatorContext{} }, |
| 294 | } |
| 295 | |
| 296 | topDownMutatorContextPool = sync.Pool{ |
| 297 | New: func() any { return &topDownMutatorContext{} }, |
| 298 | } |
| 299 | ) |
| 300 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 301 | type bottomUpMutatorContext struct { |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 302 | bp blueprint.BottomUpMutatorContext |
Colin Cross | 0ea8ba8 | 2019-06-06 14:33:29 -0700 | [diff] [blame] | 303 | baseModuleContext |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 304 | finalPhase bool |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Colin Cross | 984223f | 2024-02-01 17:10:23 -0800 | [diff] [blame] | 307 | // callers must immediately follow the call to this function with defer bottomUpMutatorContextPool.Put(mctx). |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 308 | func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module, |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 309 | finalPhase bool) BottomUpMutatorContext { |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 310 | |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 311 | moduleContext := a.base().baseModuleContextFactory(ctx) |
Colin Cross | 984223f | 2024-02-01 17:10:23 -0800 | [diff] [blame] | 312 | mctx := bottomUpMutatorContextPool.Get().(*bottomUpMutatorContext) |
| 313 | *mctx = bottomUpMutatorContext{ |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 314 | bp: ctx, |
Cole Faust | 0abd4b4 | 2023-01-10 10:49:18 -0800 | [diff] [blame] | 315 | baseModuleContext: moduleContext, |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 316 | finalPhase: finalPhase, |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 317 | } |
Colin Cross | 984223f | 2024-02-01 17:10:23 -0800 | [diff] [blame] | 318 | return mctx |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 321 | func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle { |
Martin Stjernholm | 710ec3a | 2020-01-16 15:12:04 +0000 | [diff] [blame] | 322 | finalPhase := x.finalPhase |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 323 | f := func(ctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 324 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 984223f | 2024-02-01 17:10:23 -0800 | [diff] [blame] | 325 | mctx := bottomUpMutatorContextFactory(ctx, a, finalPhase) |
| 326 | defer bottomUpMutatorContextPool.Put(mctx) |
| 327 | m(mctx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 328 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 329 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 330 | mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 331 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 332 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Colin Cross | 617b88a | 2020-08-24 18:04:09 -0700 | [diff] [blame] | 335 | func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle { |
| 336 | mutator := &mutator{name: name, bottomUpMutator: m} |
| 337 | x.mutators = append(x.mutators, mutator) |
| 338 | return mutator |
| 339 | } |
| 340 | |
Colin Cross | 90d7df9 | 2025-01-31 11:29:33 -0800 | [diff] [blame^] | 341 | func (x *registerMutatorsContext) Transition(name string, m VariationTransitionMutator) TransitionMutatorHandle { |
Colin Cross | c6f3f02 | 2025-01-31 11:16:26 -0800 | [diff] [blame] | 342 | atm := &androidTransitionMutatorAdapter{ |
Colin Cross | b63d7b3 | 2023-12-07 16:54:51 -0800 | [diff] [blame] | 343 | finalPhase: x.finalPhase, |
Colin Cross | c6f3f02 | 2025-01-31 11:16:26 -0800 | [diff] [blame] | 344 | mutator: variationTransitionMutatorAdapter{m}, |
Colin Cross | d67425d | 2024-04-15 15:17:05 -0700 | [diff] [blame] | 345 | name: name, |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 346 | } |
| 347 | mutator := &mutator{ |
| 348 | name: name, |
Cole Faust | fc7a411 | 2024-11-04 15:07:12 -0800 | [diff] [blame] | 349 | transitionMutator: atm, |
| 350 | } |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 351 | x.mutators = append(x.mutators, mutator) |
Cole Faust | fc7a411 | 2024-11-04 15:07:12 -0800 | [diff] [blame] | 352 | return mutator |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 353 | } |
| 354 | |
Colin Cross | 90d7df9 | 2025-01-31 11:29:33 -0800 | [diff] [blame^] | 355 | func (x *registerMutatorsContext) InfoBasedTransition(name string, m androidTransitionMutator) TransitionMutatorHandle { |
| 356 | atm := &androidTransitionMutatorAdapter{ |
| 357 | finalPhase: x.finalPhase, |
| 358 | mutator: m, |
| 359 | name: name, |
| 360 | } |
| 361 | mutator := &mutator{ |
| 362 | name: name, |
| 363 | transitionMutator: atm, |
| 364 | } |
| 365 | x.mutators = append(x.mutators, mutator) |
| 366 | return mutator |
| 367 | } |
| 368 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 369 | func (x *registerMutatorsContext) mutatorName(name string) string { |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 370 | return name |
| 371 | } |
| 372 | |
Colin Cross | 25de6c3 | 2019-06-06 14:29:25 -0700 | [diff] [blame] | 373 | func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 374 | f := func(ctx blueprint.TopDownMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 375 | if a, ok := ctx.Module().(Module); ok { |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 376 | moduleContext := a.base().baseModuleContextFactory(ctx) |
Colin Cross | 984223f | 2024-02-01 17:10:23 -0800 | [diff] [blame] | 377 | actx := topDownMutatorContextPool.Get().(*topDownMutatorContext) |
| 378 | defer topDownMutatorContextPool.Put(actx) |
| 379 | *actx = topDownMutatorContext{ |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 380 | bp: ctx, |
Chris Parsons | 5a34ffb | 2021-07-21 14:34:58 -0400 | [diff] [blame] | 381 | baseModuleContext: moduleContext, |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 382 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 383 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 384 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 385 | } |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 386 | mutator := &mutator{name: x.mutatorName(name), topDownMutator: f} |
Colin Cross | 795c377 | 2017-03-16 16:50:10 -0700 | [diff] [blame] | 387 | x.mutators = append(x.mutators, mutator) |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 388 | return mutator |
| 389 | } |
| 390 | |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 391 | func (mutator *mutator) componentName() string { |
| 392 | return mutator.name |
| 393 | } |
| 394 | |
| 395 | func (mutator *mutator) register(ctx *Context) { |
| 396 | blueprintCtx := ctx.Context |
| 397 | var handle blueprint.MutatorHandle |
| 398 | if mutator.bottomUpMutator != nil { |
| 399 | handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator) |
| 400 | } else if mutator.topDownMutator != nil { |
| 401 | handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator) |
Lukacs T. Berki | 6c71676 | 2022-06-13 20:50:39 +0200 | [diff] [blame] | 402 | } else if mutator.transitionMutator != nil { |
Cole Faust | fc7a411 | 2024-11-04 15:07:12 -0800 | [diff] [blame] | 403 | handle := blueprintCtx.RegisterTransitionMutator(mutator.name, mutator.transitionMutator) |
| 404 | if mutator.neverFar { |
| 405 | handle.NeverFar() |
| 406 | } |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 407 | } |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 408 | |
| 409 | // Forward booleans set on the MutatorHandle to the blueprint.MutatorHandle. |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 410 | if mutator.usesRename { |
| 411 | handle.UsesRename() |
| 412 | } |
| 413 | if mutator.usesReverseDependencies { |
| 414 | handle.UsesReverseDependencies() |
| 415 | } |
| 416 | if mutator.usesReplaceDependencies { |
| 417 | handle.UsesReplaceDependencies() |
| 418 | } |
| 419 | if mutator.usesCreateModule { |
| 420 | handle.UsesCreateModule() |
| 421 | } |
| 422 | if mutator.mutatesDependencies { |
| 423 | handle.MutatesDependencies() |
| 424 | } |
| 425 | if mutator.mutatesGlobalState { |
| 426 | handle.MutatesGlobalState() |
| 427 | } |
Paul Duffin | 1d2d42f | 2021-03-06 20:08:12 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 430 | type MutatorHandle interface { |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 431 | // Parallel sets the mutator to visit modules in parallel while maintaining ordering. Calling any |
| 432 | // method on the mutator context is thread-safe, but the mutator must handle synchronization |
| 433 | // for any modifications to global state or any modules outside the one it was invoked on. |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 434 | // Deprecated: all Mutators are parallel by default. |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 435 | Parallel() MutatorHandle |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 436 | |
| 437 | // UsesRename marks the mutator as using the BottomUpMutatorContext.Rename method, which prevents |
| 438 | // coalescing adjacent mutators into a single mutator pass. |
| 439 | UsesRename() MutatorHandle |
| 440 | |
| 441 | // UsesReverseDependencies marks the mutator as using the BottomUpMutatorContext.AddReverseDependency |
| 442 | // method, which prevents coalescing adjacent mutators into a single mutator pass. |
| 443 | UsesReverseDependencies() MutatorHandle |
| 444 | |
| 445 | // UsesReplaceDependencies marks the mutator as using the BottomUpMutatorContext.ReplaceDependencies |
| 446 | // method, which prevents coalescing adjacent mutators into a single mutator pass. |
| 447 | UsesReplaceDependencies() MutatorHandle |
| 448 | |
| 449 | // UsesCreateModule marks the mutator as using the BottomUpMutatorContext.CreateModule method, |
| 450 | // which prevents coalescing adjacent mutators into a single mutator pass. |
| 451 | UsesCreateModule() MutatorHandle |
| 452 | |
| 453 | // MutatesDependencies marks the mutator as modifying properties in dependencies, which prevents |
| 454 | // coalescing adjacent mutators into a single mutator pass. |
| 455 | MutatesDependencies() MutatorHandle |
| 456 | |
| 457 | // MutatesGlobalState marks the mutator as modifying global state, which prevents coalescing |
| 458 | // adjacent mutators into a single mutator pass. |
| 459 | MutatesGlobalState() MutatorHandle |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Cole Faust | fc7a411 | 2024-11-04 15:07:12 -0800 | [diff] [blame] | 462 | type TransitionMutatorHandle interface { |
| 463 | // NeverFar causes the variations created by this mutator to never be ignored when adding |
| 464 | // far variation dependencies. Normally, far variation dependencies ignore all the variants |
| 465 | // of the source module, and only use the variants explicitly requested by the |
| 466 | // AddFarVariationDependencies call. |
| 467 | NeverFar() MutatorHandle |
| 468 | } |
| 469 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 470 | func (mutator *mutator) Parallel() MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 471 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 472 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 473 | |
Colin Cross | b8533a8 | 2024-10-05 15:25:09 -0700 | [diff] [blame] | 474 | func (mutator *mutator) UsesRename() MutatorHandle { |
| 475 | mutator.usesRename = true |
| 476 | return mutator |
| 477 | } |
| 478 | |
| 479 | func (mutator *mutator) UsesReverseDependencies() MutatorHandle { |
| 480 | mutator.usesReverseDependencies = true |
| 481 | return mutator |
| 482 | } |
| 483 | |
| 484 | func (mutator *mutator) UsesReplaceDependencies() MutatorHandle { |
| 485 | mutator.usesReplaceDependencies = true |
| 486 | return mutator |
| 487 | } |
| 488 | |
| 489 | func (mutator *mutator) UsesCreateModule() MutatorHandle { |
| 490 | mutator.usesCreateModule = true |
| 491 | return mutator |
| 492 | } |
| 493 | |
| 494 | func (mutator *mutator) MutatesDependencies() MutatorHandle { |
| 495 | mutator.mutatesDependencies = true |
| 496 | return mutator |
| 497 | } |
| 498 | |
| 499 | func (mutator *mutator) MutatesGlobalState() MutatorHandle { |
| 500 | mutator.mutatesGlobalState = true |
| 501 | return mutator |
| 502 | } |
| 503 | |
Cole Faust | fc7a411 | 2024-11-04 15:07:12 -0800 | [diff] [blame] | 504 | func (mutator *mutator) NeverFar() MutatorHandle { |
| 505 | mutator.neverFar = true |
| 506 | return mutator |
| 507 | } |
| 508 | |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 509 | func RegisterComponentsMutator(ctx RegisterMutatorsContext) { |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 510 | ctx.BottomUp("component-deps", componentDepsMutator) |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | // A special mutator that runs just prior to the deps mutator to allow the dependencies |
| 514 | // on component modules to be added so that they can depend directly on a prebuilt |
| 515 | // module. |
| 516 | func componentDepsMutator(ctx BottomUpMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 517 | ctx.Module().ComponentDepsMutator(ctx) |
Paul Duffin | 44f1d84 | 2020-06-26 20:17:02 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 520 | func depsMutator(ctx BottomUpMutatorContext) { |
Cole Faust | a963b94 | 2024-04-11 17:43:00 -0700 | [diff] [blame] | 521 | if m := ctx.Module(); m.Enabled(ctx) { |
Ronald Braunstein | 73b08ff | 2023-12-19 10:24:47 -0800 | [diff] [blame] | 522 | m.base().baseDepsMutator(ctx) |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame] | 523 | m.DepsMutator(ctx) |
| 524 | } |
| 525 | } |
Colin Cross | d11fcda | 2017-10-23 17:59:01 -0700 | [diff] [blame] | 526 | |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 527 | func registerDepsMutator(ctx RegisterMutatorsContext) { |
Colin Cross | 8a96280 | 2024-10-09 15:29:27 -0700 | [diff] [blame] | 528 | ctx.BottomUp("deps", depsMutator).UsesReverseDependencies() |
Liz Kammer | 356f7d4 | 2021-01-26 09:18:53 -0500 | [diff] [blame] | 529 | } |
| 530 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 531 | // android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that |
| 532 | // has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid |
| 533 | // ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every |
| 534 | // non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following |
| 535 | // methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext. |
| 536 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 537 | func (b *bottomUpMutatorContext) Rename(name string) { |
| 538 | b.bp.Rename(name) |
Colin Cross | 9a36223 | 2019-07-01 15:32:45 -0700 | [diff] [blame] | 539 | b.Module().base().commonProperties.DebugName = name |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 542 | func (b *bottomUpMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) Module { |
| 543 | return bpModuleToModule(b.bp.CreateModule(factory, name, props...)) |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 544 | } |
| 545 | |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 546 | func (b *bottomUpMutatorContext) createModuleInDirectory(factory blueprint.ModuleFactory, name string, _ string, props ...interface{}) Module { |
Jihoon Kang | 222874d | 2024-10-23 23:38:05 +0000 | [diff] [blame] | 547 | panic("createModuleInDirectory is not implemented for bottomUpMutatorContext") |
| 548 | } |
| 549 | |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 550 | func (b *bottomUpMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { |
Jihoon Kang | 222874d | 2024-10-23 23:38:05 +0000 | [diff] [blame] | 551 | return createModule(b, factory, "_bottomUpMutatorModule", doesNotSpecifyDirectory(), props...) |
Colin Cross | da279cf | 2024-09-17 14:25:45 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 554 | func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 555 | if b.baseModuleContext.checkedMissingDeps() { |
| 556 | panic("Adding deps not allowed after checking for missing deps") |
| 557 | } |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 558 | return bpModulesToModules(b.bp.AddDependency(module, tag, name...)) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 562 | if b.baseModuleContext.checkedMissingDeps() { |
| 563 | panic("Adding deps not allowed after checking for missing deps") |
| 564 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 565 | b.bp.AddReverseDependency(module, tag, name) |
| 566 | } |
Cole Faust | f4992e8 | 2024-09-30 15:16:18 -0700 | [diff] [blame] | 567 | |
| 568 | func (b *bottomUpMutatorContext) AddReverseVariationDependency(variations []blueprint.Variation, tag blueprint.DependencyTag, name string) { |
| 569 | if b.baseModuleContext.checkedMissingDeps() { |
| 570 | panic("Adding deps not allowed after checking for missing deps") |
| 571 | } |
| 572 | b.bp.AddReverseVariationDependency(variations, tag, name) |
| 573 | } |
| 574 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 575 | func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 576 | names ...string) []Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 577 | if b.baseModuleContext.checkedMissingDeps() { |
| 578 | panic("Adding deps not allowed after checking for missing deps") |
| 579 | } |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 580 | return bpModulesToModules(b.bp.AddVariationDependencies(variations, tag, names...)) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation, |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 584 | tag blueprint.DependencyTag, names ...string) []Module { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 585 | if b.baseModuleContext.checkedMissingDeps() { |
| 586 | panic("Adding deps not allowed after checking for missing deps") |
| 587 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 588 | |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 589 | return bpModulesToModules(b.bp.AddFarVariationDependencies(variations, tag, names...)) |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 592 | func (b *bottomUpMutatorContext) ReplaceDependencies(name string) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 593 | if b.baseModuleContext.checkedMissingDeps() { |
| 594 | panic("Adding deps not allowed after checking for missing deps") |
| 595 | } |
Colin Cross | dc35e21 | 2019-06-06 16:13:11 -0700 | [diff] [blame] | 596 | b.bp.ReplaceDependencies(name) |
| 597 | } |
Jaewoong Jung | 9f88ce2 | 2019-11-15 10:57:34 -0800 | [diff] [blame] | 598 | |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 599 | func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) { |
Liz Kammer | c13f785 | 2023-05-17 13:01:48 -0400 | [diff] [blame] | 600 | if b.baseModuleContext.checkedMissingDeps() { |
| 601 | panic("Adding deps not allowed after checking for missing deps") |
| 602 | } |
Paul Duffin | 80342d7 | 2020-06-26 22:08:43 +0100 | [diff] [blame] | 603 | b.bp.ReplaceDependenciesIf(name, predicate) |
| 604 | } |
Colin Cross | d5c6431 | 2024-12-18 16:04:52 -0800 | [diff] [blame] | 605 | |
| 606 | func bpModulesToModules(bpModules []blueprint.Module) []Module { |
| 607 | modules := make([]Module, len(bpModules)) |
| 608 | for i, bpModule := range bpModules { |
| 609 | modules[i] = bpModuleToModule(bpModule) |
| 610 | } |
| 611 | return modules |
| 612 | } |
| 613 | |
| 614 | func bpModuleToModule(bpModule blueprint.Module) Module { |
| 615 | if bpModule != nil { |
| 616 | return bpModule.(Module) |
| 617 | } |
| 618 | return nil |
| 619 | } |