blob: b73679641e55aeb15b032719266eec5df5b43dd2 [file] [log] [blame]
Colin Cross6362e272015-10-29 15:25:03 -07001// 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 Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross6362e272015-10-29 15:25:03 -070016
Colin Cross795c3772017-03-16 16:50:10 -070017import (
Colin Cross984223f2024-02-01 17:10:23 -080018 "sync"
19
Colin Cross795c3772017-03-16 16:50:10 -070020 "github.com/google/blueprint"
21)
Colin Cross6362e272015-10-29 15:25:03 -070022
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070023// Phases:
24// run Pre-arch mutators
25// run archMutator
26// run Pre-deps mutators
27// run depsMutator
28// run PostDeps mutators
Colin Cross1e954b62024-09-13 13:50:00 -070029// run FinalDeps mutators (TransitionMutators disallowed in this phase)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070030// continue on to GenerateAndroidBuildActions
Colin Cross1e676be2016-10-12 14:38:15 -070031
Paul Duffinc05b0342021-03-06 13:28:13 +000032// collateGloballyRegisteredMutators constructs the list of mutators that have been registered
33// with the InitRegistrationContext and will be used at runtime.
34func collateGloballyRegisteredMutators() sortableComponents {
Colin Crossf22fe412024-10-01 14:02:12 -070035 return collateRegisteredMutators(preArch, preDeps, postDeps, postApex, finalDeps)
Paul Duffinc05b0342021-03-06 13:28:13 +000036}
37
38// collateRegisteredMutators constructs a single list of mutators from the separate lists.
Colin Crossf22fe412024-10-01 14:02:12 -070039func collateRegisteredMutators(preArch, preDeps, postDeps, postApex, finalDeps []RegisterMutatorFunc) sortableComponents {
Colin Crosscec81712017-07-13 14:43:27 -070040 mctx := &registerMutatorsContext{}
Nan Zhangdb0b9a32017-02-27 10:12:13 -080041
42 register := func(funcs []RegisterMutatorFunc) {
43 for _, f := range funcs {
Colin Crosscec81712017-07-13 14:43:27 -070044 f(mctx)
Nan Zhangdb0b9a32017-02-27 10:12:13 -080045 }
46 }
47
Colin Crosscec81712017-07-13 14:43:27 -070048 register(preArch)
Nan Zhangdb0b9a32017-02-27 10:12:13 -080049
Colin Crosscec81712017-07-13 14:43:27 -070050 register(preDeps)
51
Liz Kammer356f7d42021-01-26 09:18:53 -050052 register([]RegisterMutatorFunc{registerDepsMutator})
Colin Crosscec81712017-07-13 14:43:27 -070053
54 register(postDeps)
55
Colin Crossf22fe412024-10-01 14:02:12 -070056 register(postApex)
57
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000058 mctx.finalPhase = true
59 register(finalDeps)
60
Paul Duffinc05b0342021-03-06 13:28:13 +000061 return mctx.mutators
Colin Cross795c3772017-03-16 16:50:10 -070062}
63
64type registerMutatorsContext struct {
Colin Crossb63d7b32023-12-07 16:54:51 -080065 mutators sortableComponents
66 finalPhase bool
Colin Cross795c3772017-03-16 16:50:10 -070067}
Colin Cross1e676be2016-10-12 14:38:15 -070068
69type RegisterMutatorsContext interface {
Colin Cross25de6c32019-06-06 14:29:25 -070070 TopDown(name string, m TopDownMutator) MutatorHandle
71 BottomUp(name string, m BottomUpMutator) MutatorHandle
Colin Cross617b88a2020-08-24 18:04:09 -070072 BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle
Lukacs T. Berki6c716762022-06-13 20:50:39 +020073 Transition(name string, m TransitionMutator)
Colin Cross1e676be2016-10-12 14:38:15 -070074}
75
76type RegisterMutatorFunc func(RegisterMutatorsContext)
77
Colin Crosscec81712017-07-13 14:43:27 -070078var preArch = []RegisterMutatorFunc{
Dan Willemsen6e72ef72018-01-26 18:27:02 -080079 RegisterNamespaceMutator,
Paul Duffinaa4162e2020-05-05 11:35:43 +010080
Paul Duffinaa4162e2020-05-05 11:35:43 +010081 // Check the visibility rules are valid.
82 //
83 // This must run after the package renamer mutators so that any issues found during
84 // validation of the package's default_visibility property are reported using the
85 // correct package name and not the synthetic name.
86 //
87 // This must also be run before defaults mutators as the rules for validation are
88 // different before checking the rules than they are afterwards. e.g.
89 // visibility: ["//visibility:private", "//visibility:public"]
90 // would be invalid if specified in a module definition but is valid if it results
91 // from something like this:
92 //
93 // defaults {
94 // name: "defaults",
95 // // Be inaccessible outside a package by default.
96 // visibility: ["//visibility:private"]
97 // }
98 //
99 // defaultable_module {
100 // name: "defaultable_module",
101 // defaults: ["defaults"],
102 // // Override the default.
103 // visibility: ["//visibility:public"]
104 // }
105 //
Paul Duffin593b3c92019-12-05 14:31:48 +0000106 RegisterVisibilityRuleChecker,
Paul Duffinaa4162e2020-05-05 11:35:43 +0100107
Bob Badour37af0462021-01-07 03:34:31 +0000108 // Record the default_applicable_licenses for each package.
109 //
110 // This must run before the defaults so that defaults modules can pick up the package default.
111 RegisterLicensesPackageMapper,
112
Paul Duffinaa4162e2020-05-05 11:35:43 +0100113 // Apply properties from defaults modules to the referencing modules.
Paul Duffinafa9fa12020-04-29 16:47:28 +0100114 //
115 // Any mutators that are added before this will not see any modules created by
116 // a DefaultableHook.
Colin Cross89536d42017-07-07 14:35:50 -0700117 RegisterDefaultsPreArchMutators,
Paul Duffinaa4162e2020-05-05 11:35:43 +0100118
Paul Duffin44f1d842020-06-26 20:17:02 +0100119 // Add dependencies on any components so that any component references can be
120 // resolved within the deps mutator.
121 //
122 // Must be run after defaults so it can be used to create dependencies on the
123 // component modules that are creating in a DefaultableHook.
124 //
125 // Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are
126 // renamed. That is so that if a module creates components using a prebuilt module
127 // type that any dependencies (which must use prebuilt_ prefixes) are resolved to
128 // the prebuilt module and not the source module.
129 RegisterComponentsMutator,
130
Paul Duffinc988c8e2020-04-29 18:27:14 +0100131 // Create an association between prebuilt modules and their corresponding source
132 // modules (if any).
Paul Duffinafa9fa12020-04-29 16:47:28 +0100133 //
134 // Must be run after defaults mutators to ensure that any modules created by
135 // a DefaultableHook can be either a prebuilt or a source module with a matching
136 // prebuilt.
Paul Duffinc988c8e2020-04-29 18:27:14 +0100137 RegisterPrebuiltsPreArchMutators,
138
Bob Badour37af0462021-01-07 03:34:31 +0000139 // Gather the licenses properties for all modules for use during expansion and enforcement.
140 //
141 // This must come after the defaults mutators to ensure that any licenses supplied
142 // in a defaults module has been successfully applied before the rules are gathered.
143 RegisterLicensesPropertyGatherer,
144
Paul Duffinaa4162e2020-05-05 11:35:43 +0100145 // Gather the visibility rules for all modules for us during visibility enforcement.
146 //
147 // This must come after the defaults mutators to ensure that any visibility supplied
148 // in a defaults module has been successfully applied before the rules are gathered.
Paul Duffin593b3c92019-12-05 14:31:48 +0000149 RegisterVisibilityRuleGatherer,
Colin Crosscec81712017-07-13 14:43:27 -0700150}
151
Colin Crossae4c6182017-09-15 17:33:55 -0700152func registerArchMutator(ctx RegisterMutatorsContext) {
Colin Cross8bbc3d52024-09-11 15:33:54 -0700153 ctx.Transition("os", &osTransitionMutator{})
Jihoon Kang5402bbd2024-07-31 18:37:49 +0000154 ctx.Transition("image", &imageTransitionMutator{})
Colin Cross8bbc3d52024-09-11 15:33:54 -0700155 ctx.Transition("arch", &archTransitionMutator{})
Colin Crossae4c6182017-09-15 17:33:55 -0700156}
157
Colin Crosscec81712017-07-13 14:43:27 -0700158var preDeps = []RegisterMutatorFunc{
Colin Crossae4c6182017-09-15 17:33:55 -0700159 registerArchMutator,
Colin Crosscec81712017-07-13 14:43:27 -0700160}
161
162var postDeps = []RegisterMutatorFunc{
Colin Cross1b488422019-03-04 22:33:56 -0800163 registerPathDepsMutator,
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700164 RegisterPrebuiltsPostDepsMutators,
Paul Duffin593b3c92019-12-05 14:31:48 +0000165 RegisterVisibilityRuleEnforcer,
Bob Badour37af0462021-01-07 03:34:31 +0000166 RegisterLicensesDependencyChecker,
Paul Duffin45338f02021-03-30 23:07:52 +0100167 registerNeverallowMutator,
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700168 RegisterOverridePostDepsMutators,
Colin Crosscec81712017-07-13 14:43:27 -0700169}
Colin Cross1e676be2016-10-12 14:38:15 -0700170
Colin Crossf22fe412024-10-01 14:02:12 -0700171var postApex = []RegisterMutatorFunc{}
172
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000173var finalDeps = []RegisterMutatorFunc{}
174
Colin Cross1e676be2016-10-12 14:38:15 -0700175func PreArchMutators(f RegisterMutatorFunc) {
176 preArch = append(preArch, f)
177}
178
179func PreDepsMutators(f RegisterMutatorFunc) {
180 preDeps = append(preDeps, f)
181}
182
183func PostDepsMutators(f RegisterMutatorFunc) {
184 postDeps = append(postDeps, f)
185}
186
Colin Crossf22fe412024-10-01 14:02:12 -0700187func PostApexMutators(f RegisterMutatorFunc) {
188 postApex = append(postApex, f)
189}
190
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000191func FinalDepsMutators(f RegisterMutatorFunc) {
192 finalDeps = append(finalDeps, f)
193}
194
Chris Parsons637458d2023-09-19 20:09:00 +0000195type TopDownMutator func(TopDownMutatorContext)
196
197type TopDownMutatorContext interface {
Colin Crossb2388e32024-10-07 15:05:23 -0700198 BaseModuleContext
Chris Parsons637458d2023-09-19 20:09:00 +0000199}
200
Colin Cross25de6c32019-06-06 14:29:25 -0700201type topDownMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700202 bp blueprint.TopDownMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700203 baseModuleContext
Colin Cross6362e272015-10-29 15:25:03 -0700204}
205
Colin Cross25de6c32019-06-06 14:29:25 -0700206type BottomUpMutator func(BottomUpMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -0700207
Colin Cross635c3b02016-05-18 15:37:25 -0700208type BottomUpMutatorContext interface {
Colin Crossb2388e32024-10-07 15:05:23 -0700209 BaseModuleContext
Colin Crossb63d7b32023-12-07 16:54:51 -0800210
211 // AddDependency adds a dependency to the given module. It returns a slice of modules for each
212 // dependency (some entries may be nil).
213 //
Colin Cross8a962802024-10-09 15:29:27 -0700214 // This method will pause until the new dependencies have had the current mutator called on them.
Colin Crossb63d7b32023-12-07 16:54:51 -0800215 AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module
Colin Crossaabf6792017-11-29 00:27:14 -0800216
Colin Cross9f35c3d2020-09-16 19:04:41 -0700217 // AddReverseDependency adds a dependency from the destination to the given module.
218 // Does not affect the ordering of the current mutator pass, but will be ordered
219 // correctly for all future mutator passes. All reverse dependencies for a destination module are
220 // collected until the end of the mutator pass, sorted by name, and then appended to the destination
Colin Crossb8533a82024-10-05 15:25:09 -0700221 // module's dependency list. May only be called by mutators that were marked with
222 // UsesReverseDependencies during registration.
Colin Crossaabf6792017-11-29 00:27:14 -0800223 AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700224
Colin Cross9f35c3d2020-09-16 19:04:41 -0700225 // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
Colin Cross4f1dcb02020-09-16 18:45:04 -0700226 // argument to select which variant of the dependency to use. It returns a slice of modules for
227 // each dependency (some entries may be nil). A variant of the dependency must exist that matches
Usta Shresthac725f472022-01-11 02:44:21 -0500228 // all the non-local variations of the current module, plus the variations argument.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700229 //
Colin Cross8a962802024-10-09 15:29:27 -0700230 // This method will pause until the new dependencies have had the current mutator called on them.
Usta Shresthac725f472022-01-11 02:44:21 -0500231 AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700232
Colin Crossb8533a82024-10-05 15:25:09 -0700233 // AddReverseVariationDependency adds a dependency from the named module to the current
Cole Faustf4992e82024-09-30 15:16:18 -0700234 // module. The given variations will be added to the current module's varations, and then the
235 // result will be used to find the correct variation of the depending module, which must exist.
236 //
237 // Does not affect the ordering of the current mutator pass, but will be ordered
238 // correctly for all future mutator passes. All reverse dependencies for a destination module are
239 // collected until the end of the mutator pass, sorted by name, and then appended to the destination
Colin Crossb8533a82024-10-05 15:25:09 -0700240 // module's dependency list. May only be called by mutators that were marked with
241 // UsesReverseDependencies during registration.
Cole Faustf4992e82024-09-30 15:16:18 -0700242 AddReverseVariationDependency([]blueprint.Variation, blueprint.DependencyTag, string)
243
Colin Cross9f35c3d2020-09-16 19:04:41 -0700244 // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the
Colin Cross4f1dcb02020-09-16 18:45:04 -0700245 // variations argument to select which variant of the dependency to use. It returns a slice of
246 // modules for each dependency (some entries may be nil). A variant of the dependency must
247 // exist that matches the variations argument, but may also have other variations.
Colin Cross9f35c3d2020-09-16 19:04:41 -0700248 // For any unspecified variation the first variant will be used.
249 //
250 // Unlike AddVariationDependencies, the variations of the current module are ignored - the
251 // dependency only needs to match the supplied variations.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700252 //
Colin Cross8a962802024-10-09 15:29:27 -0700253 // This method will pause until the new dependencies have had the current mutator called on them.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700254 AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700255
Colin Cross86771322024-05-01 14:19:51 -0700256 // ReplaceDependencies finds all the variants of the module with the specified name, then
257 // replaces all dependencies onto those variants with the current variant of this module.
Colin Crossb8533a82024-10-05 15:25:09 -0700258 // Replacements don't take effect until after the mutator pass is finished. May only
259 // be called by mutators that were marked with UsesReplaceDependencies during registration.
Colin Crossaabf6792017-11-29 00:27:14 -0800260 ReplaceDependencies(string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700261
Colin Cross86771322024-05-01 14:19:51 -0700262 // ReplaceDependenciesIf finds all the variants of the module with the specified name, then
263 // replaces all dependencies onto those variants with the current variant of this module
264 // as long as the supplied predicate returns true.
Colin Crossb8533a82024-10-05 15:25:09 -0700265 // Replacements don't take effect until after the mutator pass is finished. May only
266 // be called by mutators that were marked with UsesReplaceDependencies during registration.
Paul Duffin80342d72020-06-26 22:08:43 +0100267 ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate)
Colin Crossb2388e32024-10-07 15:05:23 -0700268
269 // Rename all variants of a module. The new name is not visible to calls to ModuleName,
Colin Crossb8533a82024-10-05 15:25:09 -0700270 // AddDependency or OtherModuleName until after this mutator pass is complete. May only be called
271 // by mutators that were marked with UsesRename during registration.
Colin Crossb2388e32024-10-07 15:05:23 -0700272 Rename(name string)
273
274 // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
Colin Crossb8533a82024-10-05 15:25:09 -0700275 // the specified property structs to it as if the properties were set in a blueprint file. May only
276 // be called by mutators that were marked with UsesCreateModule during registration.
Colin Crossb2388e32024-10-07 15:05:23 -0700277 CreateModule(ModuleFactory, ...interface{}) Module
Colin Cross6362e272015-10-29 15:25:03 -0700278}
279
Colin Cross984223f2024-02-01 17:10:23 -0800280// An outgoingTransitionContextImpl and incomingTransitionContextImpl is created for every dependency of every module
281// for each transition mutator. bottomUpMutatorContext and topDownMutatorContext are created once for every module
282// for every BottomUp or TopDown mutator. Use a global pool for each to avoid reallocating every time.
283var (
284 outgoingTransitionContextPool = sync.Pool{
285 New: func() any { return &outgoingTransitionContextImpl{} },
286 }
287 incomingTransitionContextPool = sync.Pool{
288 New: func() any { return &incomingTransitionContextImpl{} },
289 }
290 bottomUpMutatorContextPool = sync.Pool{
291 New: func() any { return &bottomUpMutatorContext{} },
292 }
293
294 topDownMutatorContextPool = sync.Pool{
295 New: func() any { return &topDownMutatorContext{} },
296 }
297)
298
Colin Cross25de6c32019-06-06 14:29:25 -0700299type bottomUpMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700300 bp blueprint.BottomUpMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700301 baseModuleContext
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400302 finalPhase bool
Colin Cross6362e272015-10-29 15:25:03 -0700303}
304
Colin Cross984223f2024-02-01 17:10:23 -0800305// callers must immediately follow the call to this function with defer bottomUpMutatorContextPool.Put(mctx).
Colin Cross617b88a2020-08-24 18:04:09 -0700306func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module,
Colin Crossb63d7b32023-12-07 16:54:51 -0800307 finalPhase bool) BottomUpMutatorContext {
Colin Cross617b88a2020-08-24 18:04:09 -0700308
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400309 moduleContext := a.base().baseModuleContextFactory(ctx)
Colin Cross984223f2024-02-01 17:10:23 -0800310 mctx := bottomUpMutatorContextPool.Get().(*bottomUpMutatorContext)
311 *mctx = bottomUpMutatorContext{
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400312 bp: ctx,
Cole Faust0abd4b42023-01-10 10:49:18 -0800313 baseModuleContext: moduleContext,
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400314 finalPhase: finalPhase,
Colin Cross617b88a2020-08-24 18:04:09 -0700315 }
Colin Cross984223f2024-02-01 17:10:23 -0800316 return mctx
Colin Cross617b88a2020-08-24 18:04:09 -0700317}
318
Colin Cross25de6c32019-06-06 14:29:25 -0700319func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000320 finalPhase := x.finalPhase
Colin Cross798bfce2016-10-12 14:28:16 -0700321 f := func(ctx blueprint.BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700322 if a, ok := ctx.Module().(Module); ok {
Colin Cross984223f2024-02-01 17:10:23 -0800323 mctx := bottomUpMutatorContextFactory(ctx, a, finalPhase)
324 defer bottomUpMutatorContextPool.Put(mctx)
325 m(mctx)
Colin Cross6362e272015-10-29 15:25:03 -0700326 }
Colin Cross798bfce2016-10-12 14:28:16 -0700327 }
Liz Kammer356f7d42021-01-26 09:18:53 -0500328 mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700329 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700330 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700331}
332
Colin Cross617b88a2020-08-24 18:04:09 -0700333func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle {
334 mutator := &mutator{name: name, bottomUpMutator: m}
335 x.mutators = append(x.mutators, mutator)
336 return mutator
337}
338
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200339type IncomingTransitionContext interface {
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800340 ArchModuleContext
Colin Crossaf333f52024-04-15 15:20:23 -0700341 ModuleProviderContext
Cole Faustbda18162024-10-15 15:01:14 -0700342 ModuleErrorContext
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800343
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200344 // Module returns the target of the dependency edge for which the transition
345 // is being computed
346 Module() Module
347
348 // Config returns the configuration for the build.
349 Config() Config
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800350
351 DeviceConfig() DeviceConfig
Colin Crosse1a85552024-06-14 12:17:37 -0700352
353 // IsAddingDependency returns true if the transition is being called while adding a dependency
354 // after the transition mutator has already run, or false if it is being called when the transition
355 // mutator is running. This should be used sparingly, all uses will have to be removed in order
356 // to support creating variants on demand.
357 IsAddingDependency() bool
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200358}
359
360type OutgoingTransitionContext interface {
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800361 ArchModuleContext
Colin Crossaf333f52024-04-15 15:20:23 -0700362 ModuleProviderContext
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800363
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200364 // Module returns the target of the dependency edge for which the transition
365 // is being computed
366 Module() Module
367
368 // DepTag() Returns the dependency tag through which this dependency is
369 // reached
370 DepTag() blueprint.DependencyTag
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800371
372 // Config returns the configuration for the build.
373 Config() Config
374
375 DeviceConfig() DeviceConfig
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200376}
Lukacs T. Berki0e691c12022-06-24 10:15:55 +0200377
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800378// TransitionMutator implements a top-down mechanism where a module tells its
Lukacs T. Berki0e691c12022-06-24 10:15:55 +0200379// direct dependencies what variation they should be built in but the dependency
380// has the final say.
381//
382// When implementing a transition mutator, one needs to implement four methods:
383// - Split() that tells what variations a module has by itself
384// - OutgoingTransition() where a module tells what it wants from its
385// dependency
386// - IncomingTransition() where a module has the final say about its own
387// variation
388// - Mutate() that changes the state of a module depending on its variation
389//
390// That the effective variation of module B when depended on by module A is the
391// composition the outgoing transition of module A and the incoming transition
392// of module B.
393//
394// the outgoing transition should not take the properties of the dependency into
395// account, only those of the module that depends on it. For this reason, the
396// dependency is not even passed into it as an argument. Likewise, the incoming
397// transition should not take the properties of the depending module into
398// account and is thus not informed about it. This makes for a nice
399// decomposition of the decision logic.
400//
401// A given transition mutator only affects its own variation; other variations
402// stay unchanged along the dependency edges.
403//
404// Soong makes sure that all modules are created in the desired variations and
405// that dependency edges are set up correctly. This ensures that "missing
406// variation" errors do not happen and allows for more flexible changes in the
407// value of the variation among dependency edges (as oppposed to bottom-up
408// mutators where if module A in variation X depends on module B and module B
409// has that variation X, A must depend on variation X of B)
410//
411// The limited power of the context objects passed to individual mutators
412// methods also makes it more difficult to shoot oneself in the foot. Complete
413// safety is not guaranteed because no one prevents individual transition
414// mutators from mutating modules in illegal ways and for e.g. Split() or
415// Mutate() to run their own visitations of the transitive dependency of the
416// module and both of these are bad ideas, but it's better than no guardrails at
417// all.
418//
419// This model is pretty close to Bazel's configuration transitions. The mapping
420// between concepts in Soong and Bazel is as follows:
421// - Module == configured target
422// - Variant == configuration
423// - Variation name == configuration flag
424// - Variation == configuration flag value
425// - Outgoing transition == attribute transition
426// - Incoming transition == rule transition
427//
428// The Split() method does not have a Bazel equivalent and Bazel split
429// transitions do not have a Soong equivalent.
430//
431// Mutate() does not make sense in Bazel due to the different models of the
432// two systems: when creating new variations, Soong clones the old module and
433// thus some way is needed to change it state whereas Bazel creates each
434// configuration of a given configured target anew.
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200435type TransitionMutator interface {
436 // Split returns the set of variations that should be created for a module no
437 // matter who depends on it. Used when Make depends on a particular variation
438 // or when the module knows its variations just based on information given to
439 // it in the Blueprint file. This method should not mutate the module it is
440 // called on.
441 Split(ctx BaseModuleContext) []string
442
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800443 // OutgoingTransition is called on a module to determine which variation it wants
444 // from its direct dependencies. The dependency itself can override this decision.
445 // This method should not mutate the module itself.
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200446 OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string
447
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800448 // IncomingTransition is called on a module to determine which variation it should
449 // be in based on the variation modules that depend on it want. This gives the module
450 // a final say about its own variations. This method should not mutate the module
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200451 // itself.
452 IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string
453
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800454 // Mutate is called after a module was split into multiple variations on each variation.
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200455 // It should not split the module any further but adding new dependencies is
456 // fine. Unlike all the other methods on TransitionMutator, this method is
457 // allowed to mutate the module.
458 Mutate(ctx BottomUpMutatorContext, variation string)
459}
460
461type androidTransitionMutator struct {
Colin Crossb63d7b32023-12-07 16:54:51 -0800462 finalPhase bool
463 mutator TransitionMutator
Colin Crossd67425d2024-04-15 15:17:05 -0700464 name string
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200465}
466
467func (a *androidTransitionMutator) Split(ctx blueprint.BaseModuleContext) []string {
Colin Crossd27205e2024-09-12 22:41:37 -0700468 if a.finalPhase {
469 panic("TransitionMutator not allowed in FinalDepsMutators")
470 }
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200471 if m, ok := ctx.Module().(Module); ok {
472 moduleContext := m.base().baseModuleContextFactory(ctx)
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200473 return a.mutator.Split(&moduleContext)
474 } else {
475 return []string{""}
476 }
477}
478
479type outgoingTransitionContextImpl struct {
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800480 archModuleContext
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200481 bp blueprint.OutgoingTransitionContext
482}
483
484func (c *outgoingTransitionContextImpl) Module() Module {
485 return c.bp.Module().(Module)
486}
487
488func (c *outgoingTransitionContextImpl) DepTag() blueprint.DependencyTag {
489 return c.bp.DepTag()
490}
491
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800492func (c *outgoingTransitionContextImpl) Config() Config {
493 return c.bp.Config().(Config)
494}
495
496func (c *outgoingTransitionContextImpl) DeviceConfig() DeviceConfig {
497 return DeviceConfig{c.bp.Config().(Config).deviceConfig}
498}
499
Colin Crossaf333f52024-04-15 15:20:23 -0700500func (c *outgoingTransitionContextImpl) provider(provider blueprint.AnyProviderKey) (any, bool) {
501 return c.bp.Provider(provider)
502}
503
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800504func (a *androidTransitionMutator) OutgoingTransition(bpctx blueprint.OutgoingTransitionContext, sourceVariation string) string {
505 if m, ok := bpctx.Module().(Module); ok {
Colin Cross984223f2024-02-01 17:10:23 -0800506 ctx := outgoingTransitionContextPool.Get().(*outgoingTransitionContextImpl)
507 defer outgoingTransitionContextPool.Put(ctx)
508 *ctx = outgoingTransitionContextImpl{
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800509 archModuleContext: m.base().archModuleContextFactory(bpctx),
510 bp: bpctx,
511 }
512 return a.mutator.OutgoingTransition(ctx, sourceVariation)
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200513 } else {
514 return ""
515 }
516}
517
518type incomingTransitionContextImpl struct {
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800519 archModuleContext
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200520 bp blueprint.IncomingTransitionContext
521}
522
523func (c *incomingTransitionContextImpl) Module() Module {
524 return c.bp.Module().(Module)
525}
526
527func (c *incomingTransitionContextImpl) Config() Config {
528 return c.bp.Config().(Config)
529}
530
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800531func (c *incomingTransitionContextImpl) DeviceConfig() DeviceConfig {
532 return DeviceConfig{c.bp.Config().(Config).deviceConfig}
533}
534
Colin Crosse1a85552024-06-14 12:17:37 -0700535func (c *incomingTransitionContextImpl) IsAddingDependency() bool {
536 return c.bp.IsAddingDependency()
537}
538
Colin Crossaf333f52024-04-15 15:20:23 -0700539func (c *incomingTransitionContextImpl) provider(provider blueprint.AnyProviderKey) (any, bool) {
540 return c.bp.Provider(provider)
541}
542
Cole Faustbda18162024-10-15 15:01:14 -0700543func (c *incomingTransitionContextImpl) ModuleErrorf(fmt string, args ...interface{}) {
544 c.bp.ModuleErrorf(fmt, args)
545}
546
547func (c *incomingTransitionContextImpl) PropertyErrorf(property, fmt string, args ...interface{}) {
548 c.bp.PropertyErrorf(property, fmt, args)
549}
550
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800551func (a *androidTransitionMutator) IncomingTransition(bpctx blueprint.IncomingTransitionContext, incomingVariation string) string {
552 if m, ok := bpctx.Module().(Module); ok {
Colin Cross984223f2024-02-01 17:10:23 -0800553 ctx := incomingTransitionContextPool.Get().(*incomingTransitionContextImpl)
554 defer incomingTransitionContextPool.Put(ctx)
555 *ctx = incomingTransitionContextImpl{
Colin Cross4aa3e0a2024-01-18 17:22:58 -0800556 archModuleContext: m.base().archModuleContextFactory(bpctx),
557 bp: bpctx,
558 }
559 return a.mutator.IncomingTransition(ctx, incomingVariation)
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200560 } else {
561 return ""
562 }
563}
564
565func (a *androidTransitionMutator) Mutate(ctx blueprint.BottomUpMutatorContext, variation string) {
566 if am, ok := ctx.Module().(Module); ok {
Colin Cross888046f2024-05-01 14:20:31 -0700567 if variation != "" {
568 // TODO: this should really be checking whether the TransitionMutator affected this module, not
569 // the empty variant, but TransitionMutator has no concept of skipping a module.
570 base := am.base()
571 base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, a.name)
572 base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variation)
573 }
574
Colin Cross984223f2024-02-01 17:10:23 -0800575 mctx := bottomUpMutatorContextFactory(ctx, am, a.finalPhase)
576 defer bottomUpMutatorContextPool.Put(mctx)
577 a.mutator.Mutate(mctx, variation)
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200578 }
579}
580
581func (x *registerMutatorsContext) Transition(name string, m TransitionMutator) {
582 atm := &androidTransitionMutator{
Colin Crossb63d7b32023-12-07 16:54:51 -0800583 finalPhase: x.finalPhase,
584 mutator: m,
Colin Crossd67425d2024-04-15 15:17:05 -0700585 name: name,
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200586 }
587 mutator := &mutator{
588 name: name,
589 transitionMutator: atm}
590 x.mutators = append(x.mutators, mutator)
591}
592
Liz Kammer356f7d42021-01-26 09:18:53 -0500593func (x *registerMutatorsContext) mutatorName(name string) string {
Liz Kammer356f7d42021-01-26 09:18:53 -0500594 return name
595}
596
Colin Cross25de6c32019-06-06 14:29:25 -0700597func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle {
Colin Cross798bfce2016-10-12 14:28:16 -0700598 f := func(ctx blueprint.TopDownMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700599 if a, ok := ctx.Module().(Module); ok {
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400600 moduleContext := a.base().baseModuleContextFactory(ctx)
Colin Cross984223f2024-02-01 17:10:23 -0800601 actx := topDownMutatorContextPool.Get().(*topDownMutatorContext)
602 defer topDownMutatorContextPool.Put(actx)
603 *actx = topDownMutatorContext{
Colin Crossdc35e212019-06-06 16:13:11 -0700604 bp: ctx,
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400605 baseModuleContext: moduleContext,
Colin Cross6362e272015-10-29 15:25:03 -0700606 }
Colin Cross798bfce2016-10-12 14:28:16 -0700607 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -0700608 }
Colin Cross798bfce2016-10-12 14:28:16 -0700609 }
Liz Kammer356f7d42021-01-26 09:18:53 -0500610 mutator := &mutator{name: x.mutatorName(name), topDownMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700611 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700612 return mutator
613}
614
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000615func (mutator *mutator) componentName() string {
616 return mutator.name
617}
618
619func (mutator *mutator) register(ctx *Context) {
620 blueprintCtx := ctx.Context
621 var handle blueprint.MutatorHandle
622 if mutator.bottomUpMutator != nil {
623 handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator)
624 } else if mutator.topDownMutator != nil {
625 handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator)
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200626 } else if mutator.transitionMutator != nil {
627 blueprintCtx.RegisterTransitionMutator(mutator.name, mutator.transitionMutator)
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000628 }
Colin Crossb8533a82024-10-05 15:25:09 -0700629
630 // Forward booleans set on the MutatorHandle to the blueprint.MutatorHandle.
Colin Crossb8533a82024-10-05 15:25:09 -0700631 if mutator.usesRename {
632 handle.UsesRename()
633 }
634 if mutator.usesReverseDependencies {
635 handle.UsesReverseDependencies()
636 }
637 if mutator.usesReplaceDependencies {
638 handle.UsesReplaceDependencies()
639 }
640 if mutator.usesCreateModule {
641 handle.UsesCreateModule()
642 }
643 if mutator.mutatesDependencies {
644 handle.MutatesDependencies()
645 }
646 if mutator.mutatesGlobalState {
647 handle.MutatesGlobalState()
648 }
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000649}
650
Colin Cross798bfce2016-10-12 14:28:16 -0700651type MutatorHandle interface {
Colin Crossb8533a82024-10-05 15:25:09 -0700652 // Parallel sets the mutator to visit modules in parallel while maintaining ordering. Calling any
653 // method on the mutator context is thread-safe, but the mutator must handle synchronization
654 // for any modifications to global state or any modules outside the one it was invoked on.
Colin Cross8a962802024-10-09 15:29:27 -0700655 // Deprecated: all Mutators are parallel by default.
Colin Cross798bfce2016-10-12 14:28:16 -0700656 Parallel() MutatorHandle
Colin Crossb8533a82024-10-05 15:25:09 -0700657
658 // UsesRename marks the mutator as using the BottomUpMutatorContext.Rename method, which prevents
659 // coalescing adjacent mutators into a single mutator pass.
660 UsesRename() MutatorHandle
661
662 // UsesReverseDependencies marks the mutator as using the BottomUpMutatorContext.AddReverseDependency
663 // method, which prevents coalescing adjacent mutators into a single mutator pass.
664 UsesReverseDependencies() MutatorHandle
665
666 // UsesReplaceDependencies marks the mutator as using the BottomUpMutatorContext.ReplaceDependencies
667 // method, which prevents coalescing adjacent mutators into a single mutator pass.
668 UsesReplaceDependencies() MutatorHandle
669
670 // UsesCreateModule marks the mutator as using the BottomUpMutatorContext.CreateModule method,
671 // which prevents coalescing adjacent mutators into a single mutator pass.
672 UsesCreateModule() MutatorHandle
673
674 // MutatesDependencies marks the mutator as modifying properties in dependencies, which prevents
675 // coalescing adjacent mutators into a single mutator pass.
676 MutatesDependencies() MutatorHandle
677
678 // MutatesGlobalState marks the mutator as modifying global state, which prevents coalescing
679 // adjacent mutators into a single mutator pass.
680 MutatesGlobalState() MutatorHandle
Colin Cross798bfce2016-10-12 14:28:16 -0700681}
682
683func (mutator *mutator) Parallel() MutatorHandle {
Colin Cross798bfce2016-10-12 14:28:16 -0700684 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700685}
Colin Cross1e676be2016-10-12 14:38:15 -0700686
Colin Crossb8533a82024-10-05 15:25:09 -0700687func (mutator *mutator) UsesRename() MutatorHandle {
688 mutator.usesRename = true
689 return mutator
690}
691
692func (mutator *mutator) UsesReverseDependencies() MutatorHandle {
693 mutator.usesReverseDependencies = true
694 return mutator
695}
696
697func (mutator *mutator) UsesReplaceDependencies() MutatorHandle {
698 mutator.usesReplaceDependencies = true
699 return mutator
700}
701
702func (mutator *mutator) UsesCreateModule() MutatorHandle {
703 mutator.usesCreateModule = true
704 return mutator
705}
706
707func (mutator *mutator) MutatesDependencies() MutatorHandle {
708 mutator.mutatesDependencies = true
709 return mutator
710}
711
712func (mutator *mutator) MutatesGlobalState() MutatorHandle {
713 mutator.mutatesGlobalState = true
714 return mutator
715}
716
Paul Duffin44f1d842020-06-26 20:17:02 +0100717func RegisterComponentsMutator(ctx RegisterMutatorsContext) {
Colin Cross8a962802024-10-09 15:29:27 -0700718 ctx.BottomUp("component-deps", componentDepsMutator)
Paul Duffin44f1d842020-06-26 20:17:02 +0100719}
720
721// A special mutator that runs just prior to the deps mutator to allow the dependencies
722// on component modules to be added so that they can depend directly on a prebuilt
723// module.
724func componentDepsMutator(ctx BottomUpMutatorContext) {
Cole Fausta963b942024-04-11 17:43:00 -0700725 ctx.Module().ComponentDepsMutator(ctx)
Paul Duffin44f1d842020-06-26 20:17:02 +0100726}
727
Colin Cross1e676be2016-10-12 14:38:15 -0700728func depsMutator(ctx BottomUpMutatorContext) {
Cole Fausta963b942024-04-11 17:43:00 -0700729 if m := ctx.Module(); m.Enabled(ctx) {
Ronald Braunstein73b08ff2023-12-19 10:24:47 -0800730 m.base().baseDepsMutator(ctx)
Colin Cross1e676be2016-10-12 14:38:15 -0700731 m.DepsMutator(ctx)
732 }
733}
Colin Crossd11fcda2017-10-23 17:59:01 -0700734
Liz Kammer356f7d42021-01-26 09:18:53 -0500735func registerDepsMutator(ctx RegisterMutatorsContext) {
Colin Cross8a962802024-10-09 15:29:27 -0700736 ctx.BottomUp("deps", depsMutator).UsesReverseDependencies()
Liz Kammer356f7d42021-01-26 09:18:53 -0500737}
738
Colin Crossdc35e212019-06-06 16:13:11 -0700739// android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that
740// has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid
741// ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every
742// non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following
743// methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext.
744
Colin Crossdc35e212019-06-06 16:13:11 -0700745func (b *bottomUpMutatorContext) Rename(name string) {
746 b.bp.Rename(name)
Colin Cross9a362232019-07-01 15:32:45 -0700747 b.Module().base().commonProperties.DebugName = name
Colin Crossdc35e212019-06-06 16:13:11 -0700748}
749
Colin Crossda279cf2024-09-17 14:25:45 -0700750func (b *bottomUpMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module {
751 return b.bp.CreateModule(factory, name, props...)
752}
753
Jihoon Kang222874d2024-10-23 23:38:05 +0000754func (b *bottomUpMutatorContext) createModuleInDirectory(factory blueprint.ModuleFactory, name string, _ string, props ...interface{}) blueprint.Module {
755 panic("createModuleInDirectory is not implemented for bottomUpMutatorContext")
756}
757
Colin Crossda279cf2024-09-17 14:25:45 -0700758func (b *bottomUpMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
Jihoon Kang222874d2024-10-23 23:38:05 +0000759 return createModule(b, factory, "_bottomUpMutatorModule", doesNotSpecifyDirectory(), props...)
Colin Crossda279cf2024-09-17 14:25:45 -0700760}
761
Colin Cross4f1dcb02020-09-16 18:45:04 -0700762func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module {
Liz Kammerc13f7852023-05-17 13:01:48 -0400763 if b.baseModuleContext.checkedMissingDeps() {
764 panic("Adding deps not allowed after checking for missing deps")
765 }
Colin Cross4f1dcb02020-09-16 18:45:04 -0700766 return b.bp.AddDependency(module, tag, name...)
Colin Crossdc35e212019-06-06 16:13:11 -0700767}
768
769func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) {
Liz Kammerc13f7852023-05-17 13:01:48 -0400770 if b.baseModuleContext.checkedMissingDeps() {
771 panic("Adding deps not allowed after checking for missing deps")
772 }
Colin Crossdc35e212019-06-06 16:13:11 -0700773 b.bp.AddReverseDependency(module, tag, name)
774}
Cole Faustf4992e82024-09-30 15:16:18 -0700775
776func (b *bottomUpMutatorContext) AddReverseVariationDependency(variations []blueprint.Variation, tag blueprint.DependencyTag, name string) {
777 if b.baseModuleContext.checkedMissingDeps() {
778 panic("Adding deps not allowed after checking for missing deps")
779 }
780 b.bp.AddReverseVariationDependency(variations, tag, name)
781}
782
Colin Crossdc35e212019-06-06 16:13:11 -0700783func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700784 names ...string) []blueprint.Module {
Liz Kammerc13f7852023-05-17 13:01:48 -0400785 if b.baseModuleContext.checkedMissingDeps() {
786 panic("Adding deps not allowed after checking for missing deps")
787 }
Colin Cross4f1dcb02020-09-16 18:45:04 -0700788 return b.bp.AddVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700789}
790
791func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700792 tag blueprint.DependencyTag, names ...string) []blueprint.Module {
Liz Kammerc13f7852023-05-17 13:01:48 -0400793 if b.baseModuleContext.checkedMissingDeps() {
794 panic("Adding deps not allowed after checking for missing deps")
795 }
Colin Crossdc35e212019-06-06 16:13:11 -0700796
Colin Cross4f1dcb02020-09-16 18:45:04 -0700797 return b.bp.AddFarVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700798}
799
Colin Crossdc35e212019-06-06 16:13:11 -0700800func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
Liz Kammerc13f7852023-05-17 13:01:48 -0400801 if b.baseModuleContext.checkedMissingDeps() {
802 panic("Adding deps not allowed after checking for missing deps")
803 }
Colin Crossdc35e212019-06-06 16:13:11 -0700804 b.bp.ReplaceDependencies(name)
805}
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800806
Paul Duffin80342d72020-06-26 22:08:43 +0100807func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) {
Liz Kammerc13f7852023-05-17 13:01:48 -0400808 if b.baseModuleContext.checkedMissingDeps() {
809 panic("Adding deps not allowed after checking for missing deps")
810 }
Paul Duffin80342d72020-06-26 22:08:43 +0100811 b.bp.ReplaceDependenciesIf(name, predicate)
812}