blob: 1eac1f0f89ed572cb091a715573d75a4ee6fc3ff [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 (
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +000018 "android/soong/bazel"
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
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000029// run FinalDeps mutators (CreateVariations disallowed in this phase)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070030// continue on to GenerateAndroidBuildActions
Colin Cross1e676be2016-10-12 14:38:15 -070031
Jingwen Chen73850672020-12-14 08:25:34 -050032// RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing.
Liz Kammerbe46fcc2021-11-01 15:32:43 -040033func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators []RegisterMutatorFunc) {
Spandan Das5af0bd32022-09-28 20:43:08 +000034 bp2buildMutators := append(preArchMutators, registerBp2buildConversionMutator)
35 registerMutatorsForBazelConversion(ctx, bp2buildMutators)
36}
37
38// RegisterMutatorsForApiBazelConversion is an alternate registration pipeline for api_bp2build
39// This pipeline restricts generation of Bazel targets to Soong modules that contribute APIs
40func RegisterMutatorsForApiBazelConversion(ctx *Context, preArchMutators []RegisterMutatorFunc) {
41 bp2buildMutators := append(preArchMutators, registerApiBp2buildConversionMutator)
42 registerMutatorsForBazelConversion(ctx, bp2buildMutators)
43}
44
45func registerMutatorsForBazelConversion(ctx *Context, bp2buildMutators []RegisterMutatorFunc) {
Liz Kammer356f7d42021-01-26 09:18:53 -050046 mctx := &registerMutatorsContext{
47 bazelConversionMode: true,
Jingwen Chen041b1842021-02-01 00:23:25 -050048 }
49
Spandan Das5af0bd32022-09-28 20:43:08 +000050 allMutators := append([]RegisterMutatorFunc{
Liz Kammer356f7d42021-01-26 09:18:53 -050051 RegisterNamespaceMutator,
52 RegisterDefaultsPreArchMutators,
53 // TODO(b/165114590): this is required to resolve deps that are only prebuilts, but we should
54 // evaluate the impact on conversion.
55 RegisterPrebuiltsPreArchMutators,
56 },
Spandan Das5af0bd32022-09-28 20:43:08 +000057 bp2buildMutators...)
Liz Kammer356f7d42021-01-26 09:18:53 -050058
Jingwen Chen73850672020-12-14 08:25:34 -050059 // Register bp2build mutators
Spandan Das5af0bd32022-09-28 20:43:08 +000060 for _, f := range allMutators {
Jingwen Chen73850672020-12-14 08:25:34 -050061 f(mctx)
62 }
63
Paul Duffin1d2d42f2021-03-06 20:08:12 +000064 mctx.mutators.registerAll(ctx)
Jingwen Chen4133ce62020-12-02 04:34:15 -050065}
66
Paul Duffinc05b0342021-03-06 13:28:13 +000067// collateGloballyRegisteredMutators constructs the list of mutators that have been registered
68// with the InitRegistrationContext and will be used at runtime.
69func collateGloballyRegisteredMutators() sortableComponents {
70 return collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps)
71}
72
73// collateRegisteredMutators constructs a single list of mutators from the separate lists.
74func collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) sortableComponents {
Colin Crosscec81712017-07-13 14:43:27 -070075 mctx := &registerMutatorsContext{}
Nan Zhangdb0b9a32017-02-27 10:12:13 -080076
77 register := func(funcs []RegisterMutatorFunc) {
78 for _, f := range funcs {
Colin Crosscec81712017-07-13 14:43:27 -070079 f(mctx)
Nan Zhangdb0b9a32017-02-27 10:12:13 -080080 }
81 }
82
Colin Crosscec81712017-07-13 14:43:27 -070083 register(preArch)
Nan Zhangdb0b9a32017-02-27 10:12:13 -080084
Colin Crosscec81712017-07-13 14:43:27 -070085 register(preDeps)
86
Liz Kammer356f7d42021-01-26 09:18:53 -050087 register([]RegisterMutatorFunc{registerDepsMutator})
Colin Crosscec81712017-07-13 14:43:27 -070088
89 register(postDeps)
90
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000091 mctx.finalPhase = true
92 register(finalDeps)
93
Paul Duffinc05b0342021-03-06 13:28:13 +000094 return mctx.mutators
Colin Cross795c3772017-03-16 16:50:10 -070095}
96
97type registerMutatorsContext struct {
Paul Duffin1d2d42f2021-03-06 20:08:12 +000098 mutators sortableComponents
Liz Kammer356f7d42021-01-26 09:18:53 -050099 finalPhase bool
100 bazelConversionMode bool
Colin Cross795c3772017-03-16 16:50:10 -0700101}
Colin Cross1e676be2016-10-12 14:38:15 -0700102
103type RegisterMutatorsContext interface {
Colin Cross25de6c32019-06-06 14:29:25 -0700104 TopDown(name string, m TopDownMutator) MutatorHandle
105 BottomUp(name string, m BottomUpMutator) MutatorHandle
Colin Cross617b88a2020-08-24 18:04:09 -0700106 BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200107 Transition(name string, m TransitionMutator)
Colin Cross1e676be2016-10-12 14:38:15 -0700108}
109
110type RegisterMutatorFunc func(RegisterMutatorsContext)
111
Colin Crosscec81712017-07-13 14:43:27 -0700112var preArch = []RegisterMutatorFunc{
Dan Willemsen6e72ef72018-01-26 18:27:02 -0800113 RegisterNamespaceMutator,
Paul Duffinaa4162e2020-05-05 11:35:43 +0100114
Paul Duffinaa4162e2020-05-05 11:35:43 +0100115 // Check the visibility rules are valid.
116 //
117 // This must run after the package renamer mutators so that any issues found during
118 // validation of the package's default_visibility property are reported using the
119 // correct package name and not the synthetic name.
120 //
121 // This must also be run before defaults mutators as the rules for validation are
122 // different before checking the rules than they are afterwards. e.g.
123 // visibility: ["//visibility:private", "//visibility:public"]
124 // would be invalid if specified in a module definition but is valid if it results
125 // from something like this:
126 //
127 // defaults {
128 // name: "defaults",
129 // // Be inaccessible outside a package by default.
130 // visibility: ["//visibility:private"]
131 // }
132 //
133 // defaultable_module {
134 // name: "defaultable_module",
135 // defaults: ["defaults"],
136 // // Override the default.
137 // visibility: ["//visibility:public"]
138 // }
139 //
Paul Duffin593b3c92019-12-05 14:31:48 +0000140 RegisterVisibilityRuleChecker,
Paul Duffinaa4162e2020-05-05 11:35:43 +0100141
Bob Badour37af0462021-01-07 03:34:31 +0000142 // Record the default_applicable_licenses for each package.
143 //
144 // This must run before the defaults so that defaults modules can pick up the package default.
145 RegisterLicensesPackageMapper,
146
Paul Duffinaa4162e2020-05-05 11:35:43 +0100147 // Apply properties from defaults modules to the referencing modules.
Paul Duffinafa9fa12020-04-29 16:47:28 +0100148 //
149 // Any mutators that are added before this will not see any modules created by
150 // a DefaultableHook.
Colin Cross89536d42017-07-07 14:35:50 -0700151 RegisterDefaultsPreArchMutators,
Paul Duffinaa4162e2020-05-05 11:35:43 +0100152
Paul Duffin44f1d842020-06-26 20:17:02 +0100153 // Add dependencies on any components so that any component references can be
154 // resolved within the deps mutator.
155 //
156 // Must be run after defaults so it can be used to create dependencies on the
157 // component modules that are creating in a DefaultableHook.
158 //
159 // Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are
160 // renamed. That is so that if a module creates components using a prebuilt module
161 // type that any dependencies (which must use prebuilt_ prefixes) are resolved to
162 // the prebuilt module and not the source module.
163 RegisterComponentsMutator,
164
Paul Duffinc988c8e2020-04-29 18:27:14 +0100165 // Create an association between prebuilt modules and their corresponding source
166 // modules (if any).
Paul Duffinafa9fa12020-04-29 16:47:28 +0100167 //
168 // Must be run after defaults mutators to ensure that any modules created by
169 // a DefaultableHook can be either a prebuilt or a source module with a matching
170 // prebuilt.
Paul Duffinc988c8e2020-04-29 18:27:14 +0100171 RegisterPrebuiltsPreArchMutators,
172
Bob Badour37af0462021-01-07 03:34:31 +0000173 // Gather the licenses properties for all modules for use during expansion and enforcement.
174 //
175 // This must come after the defaults mutators to ensure that any licenses supplied
176 // in a defaults module has been successfully applied before the rules are gathered.
177 RegisterLicensesPropertyGatherer,
178
Paul Duffinaa4162e2020-05-05 11:35:43 +0100179 // Gather the visibility rules for all modules for us during visibility enforcement.
180 //
181 // This must come after the defaults mutators to ensure that any visibility supplied
182 // in a defaults module has been successfully applied before the rules are gathered.
Paul Duffin593b3c92019-12-05 14:31:48 +0000183 RegisterVisibilityRuleGatherer,
Colin Crosscec81712017-07-13 14:43:27 -0700184}
185
Colin Crossae4c6182017-09-15 17:33:55 -0700186func registerArchMutator(ctx RegisterMutatorsContext) {
Colin Cross617b88a2020-08-24 18:04:09 -0700187 ctx.BottomUpBlueprint("os", osMutator).Parallel()
Colin Crossfb0c16e2019-11-20 17:12:35 -0800188 ctx.BottomUp("image", imageMutator).Parallel()
Colin Cross617b88a2020-08-24 18:04:09 -0700189 ctx.BottomUpBlueprint("arch", archMutator).Parallel()
Colin Crossae4c6182017-09-15 17:33:55 -0700190}
191
Colin Crosscec81712017-07-13 14:43:27 -0700192var preDeps = []RegisterMutatorFunc{
Colin Crossae4c6182017-09-15 17:33:55 -0700193 registerArchMutator,
Colin Crosscec81712017-07-13 14:43:27 -0700194}
195
196var postDeps = []RegisterMutatorFunc{
Colin Cross1b488422019-03-04 22:33:56 -0800197 registerPathDepsMutator,
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700198 RegisterPrebuiltsPostDepsMutators,
Paul Duffin593b3c92019-12-05 14:31:48 +0000199 RegisterVisibilityRuleEnforcer,
Bob Badour37af0462021-01-07 03:34:31 +0000200 RegisterLicensesDependencyChecker,
Paul Duffin45338f02021-03-30 23:07:52 +0100201 registerNeverallowMutator,
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700202 RegisterOverridePostDepsMutators,
Colin Crosscec81712017-07-13 14:43:27 -0700203}
Colin Cross1e676be2016-10-12 14:38:15 -0700204
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000205var finalDeps = []RegisterMutatorFunc{}
206
Colin Cross1e676be2016-10-12 14:38:15 -0700207func PreArchMutators(f RegisterMutatorFunc) {
208 preArch = append(preArch, f)
209}
210
211func PreDepsMutators(f RegisterMutatorFunc) {
212 preDeps = append(preDeps, f)
213}
214
215func PostDepsMutators(f RegisterMutatorFunc) {
216 postDeps = append(postDeps, f)
217}
218
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000219func FinalDepsMutators(f RegisterMutatorFunc) {
220 finalDeps = append(finalDeps, f)
221}
222
Liz Kammer356f7d42021-01-26 09:18:53 -0500223var bp2buildPreArchMutators = []RegisterMutatorFunc{}
Rupert Shuttlewortha9d76dd2021-07-02 07:17:16 -0400224
Liz Kammer12615db2021-09-28 09:19:17 -0400225// A minimal context for Bp2build conversion
226type Bp2buildMutatorContext interface {
227 BazelConversionPathContext
228
229 CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
230}
231
Liz Kammer356f7d42021-01-26 09:18:53 -0500232// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
233// into Bazel BUILD targets that should run prior to deps and conversion.
234func PreArchBp2BuildMutators(f RegisterMutatorFunc) {
235 bp2buildPreArchMutators = append(bp2buildPreArchMutators, f)
236}
237
Colin Cross9f35c3d2020-09-16 19:04:41 -0700238type BaseMutatorContext interface {
239 BaseModuleContext
240
241 // MutatorName returns the name that this mutator was registered with.
242 MutatorName() string
243
244 // Rename all variants of a module. The new name is not visible to calls to ModuleName,
245 // AddDependency or OtherModuleName until after this mutator pass is complete.
246 Rename(name string)
247}
248
Colin Cross25de6c32019-06-06 14:29:25 -0700249type TopDownMutator func(TopDownMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -0700250
Colin Cross635c3b02016-05-18 15:37:25 -0700251type TopDownMutatorContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -0700252 BaseMutatorContext
Colin Cross3f68a132017-10-23 17:10:29 -0700253
Colin Cross9f35c3d2020-09-16 19:04:41 -0700254 // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
255 // the specified property structs to it as if the properties were set in a blueprint file.
Colin Crosse003c4a2019-09-25 12:58:36 -0700256 CreateModule(ModuleFactory, ...interface{}) Module
Jingwen Chen1fd14692021-02-05 03:01:50 -0500257
258 // CreateBazelTargetModule creates a BazelTargetModule by calling the
259 // factory method, just like in CreateModule, but also requires
260 // BazelTargetModuleProperties containing additional metadata for the
261 // bp2build codegenerator.
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000262 CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
Chris Parsons58852a02021-12-09 18:10:18 -0500263
264 // CreateBazelTargetModuleWithRestrictions creates a BazelTargetModule by calling the
265 // factory method, just like in CreateModule, but also requires
266 // BazelTargetModuleProperties containing additional metadata for the
267 // bp2build codegenerator. The generated target is restricted to only be buildable for certain
268 // platforms, as dictated by a given bool attribute: the target will not be buildable in
269 // any platform for which this bool attribute is false.
270 CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}, bazel.BoolAttribute)
Spandan Dasabedff02023-03-07 19:24:34 +0000271
272 // CreateBazelTargetAliasInDir creates an alias definition in `dir` directory.
273 // This function can be used to create alias definitions in a directory that is different
274 // from the directory of the visited Soong module.
275 CreateBazelTargetAliasInDir(dir string, name string, actual bazel.Label)
Spandan Das6a448ec2023-04-19 17:36:12 +0000276
277 // CreateBazelConfigSetting creates a config_setting in <dir>/BUILD.bazel
278 // build/bazel has several static config_setting(s) that are used in Bazel builds.
279 // This function can be used to createa additional config_setting(s) based on the build graph
280 // (e.g. a config_setting specific to an apex variant)
281 CreateBazelConfigSetting(csa bazel.ConfigSettingAttributes, ca CommonAttributes, dir string)
Colin Cross6362e272015-10-29 15:25:03 -0700282}
283
Colin Cross25de6c32019-06-06 14:29:25 -0700284type topDownMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700285 bp blueprint.TopDownMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700286 baseModuleContext
Colin Cross6362e272015-10-29 15:25:03 -0700287}
288
Colin Cross25de6c32019-06-06 14:29:25 -0700289type BottomUpMutator func(BottomUpMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -0700290
Colin Cross635c3b02016-05-18 15:37:25 -0700291type BottomUpMutatorContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -0700292 BaseMutatorContext
Colin Crossaabf6792017-11-29 00:27:14 -0800293
Colin Cross4f1dcb02020-09-16 18:45:04 -0700294 // AddDependency adds a dependency to the given module. It returns a slice of modules for each
295 // dependency (some entries may be nil).
296 //
297 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
298 // new dependencies have had the current mutator called on them. If the mutator is not
299 // parallel this method does not affect the ordering of the current mutator pass, but will
300 // be ordered correctly for all future mutator passes.
301 AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700302
303 // AddReverseDependency adds a dependency from the destination to the given module.
304 // Does not affect the ordering of the current mutator pass, but will be ordered
305 // correctly for all future mutator passes. All reverse dependencies for a destination module are
306 // collected until the end of the mutator pass, sorted by name, and then appended to the destination
307 // module's dependency list.
Colin Crossaabf6792017-11-29 00:27:14 -0800308 AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700309
310 // CreateVariations splits a module into multiple variants, one for each name in the variationNames
311 // parameter. It returns a list of new modules in the same order as the variationNames
312 // list.
313 //
314 // If any of the dependencies of the module being operated on were already split
315 // by calling CreateVariations with the same name, the dependency will automatically
316 // be updated to point the matching variant.
317 //
318 // If a module is split, and then a module depending on the first module is not split
319 // when the Mutator is later called on it, the dependency of the depending module will
320 // automatically be updated to point to the first variant.
Colin Cross43b92e02019-11-18 15:28:57 -0800321 CreateVariations(...string) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700322
323 // CreateLocationVariations splits a module into multiple variants, one for each name in the variantNames
324 // parameter. It returns a list of new modules in the same order as the variantNames
325 // list.
326 //
327 // Local variations do not affect automatic dependency resolution - dependencies added
328 // to the split module via deps or DynamicDependerModule must exactly match a variant
329 // that contains all the non-local variations.
Colin Cross43b92e02019-11-18 15:28:57 -0800330 CreateLocalVariations(...string) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700331
332 // SetDependencyVariation sets all dangling dependencies on the current module to point to the variation
333 // with given name. This function ignores the default variation set by SetDefaultDependencyVariation.
Colin Crossaabf6792017-11-29 00:27:14 -0800334 SetDependencyVariation(string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700335
336 // SetDefaultDependencyVariation sets the default variation when a dangling reference is detected
337 // during the subsequent calls on Create*Variations* functions. To reset, set it to nil.
Jiyong Park1d1119f2019-07-29 21:27:18 +0900338 SetDefaultDependencyVariation(*string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700339
340 // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
Colin Cross4f1dcb02020-09-16 18:45:04 -0700341 // argument to select which variant of the dependency to use. It returns a slice of modules for
342 // each dependency (some entries may be nil). A variant of the dependency must exist that matches
Usta Shresthac725f472022-01-11 02:44:21 -0500343 // all the non-local variations of the current module, plus the variations argument.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700344 //
345 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
346 // new dependencies have had the current mutator called on them. If the mutator is not
347 // parallel this method does not affect the ordering of the current mutator pass, but will
348 // be ordered correctly for all future mutator passes.
Usta Shresthac725f472022-01-11 02:44:21 -0500349 AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700350
351 // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the
Colin Cross4f1dcb02020-09-16 18:45:04 -0700352 // variations argument to select which variant of the dependency to use. It returns a slice of
353 // modules for each dependency (some entries may be nil). A variant of the dependency must
354 // exist that matches the variations argument, but may also have other variations.
Colin Cross9f35c3d2020-09-16 19:04:41 -0700355 // For any unspecified variation the first variant will be used.
356 //
357 // Unlike AddVariationDependencies, the variations of the current module are ignored - the
358 // dependency only needs to match the supplied variations.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700359 //
360 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
361 // new dependencies have had the current mutator called on them. If the mutator is not
362 // parallel this method does not affect the ordering of the current mutator pass, but will
363 // be ordered correctly for all future mutator passes.
364 AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700365
366 // AddInterVariantDependency adds a dependency between two variants of the same module. Variants are always
367 // ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change
368 // that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps,
369 // WalkDeps, etc.
Colin Crossaabf6792017-11-29 00:27:14 -0800370 AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700371
372 // ReplaceDependencies replaces all dependencies on the identical variant of the module with the
373 // specified name with the current variant of this module. Replacements don't take effect until
374 // after the mutator pass is finished.
Colin Crossaabf6792017-11-29 00:27:14 -0800375 ReplaceDependencies(string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700376
377 // ReplaceDependencies replaces all dependencies on the identical variant of the module with the
378 // specified name with the current variant of this module as long as the supplied predicate returns
379 // true.
380 //
381 // Replacements don't take effect until after the mutator pass is finished.
Paul Duffin80342d72020-06-26 22:08:43 +0100382 ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700383
384 // AliasVariation takes a variationName that was passed to CreateVariations for this module,
385 // and creates an alias from the current variant (before the mutator has run) to the new
386 // variant. The alias will be valid until the next time a mutator calls CreateVariations or
387 // CreateLocalVariations on this module without also calling AliasVariation. The alias can
388 // be used to add dependencies on the newly created variant using the variant map from
389 // before CreateVariations was run.
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800390 AliasVariation(variationName string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700391
392 // CreateAliasVariation takes a toVariationName that was passed to CreateVariations for this
393 // module, and creates an alias from a new fromVariationName variant the toVariationName
394 // variant. The alias will be valid until the next time a mutator calls CreateVariations or
395 // CreateLocalVariations on this module without also calling AliasVariation. The alias can
396 // be used to add dependencies on the toVariationName variant using the fromVariationName
397 // variant.
Colin Cross1b9604b2020-08-11 12:03:56 -0700398 CreateAliasVariation(fromVariationName, toVariationName string)
Colin Crossd27e7b82020-07-02 11:38:17 -0700399
400 // SetVariationProvider sets the value for a provider for the given newly created variant of
401 // the current module, i.e. one of the Modules returned by CreateVariations.. It panics if
402 // not called during the appropriate mutator or GenerateBuildActions pass for the provider,
403 // if the value is not of the appropriate type, or if the module is not a newly created
404 // variant of the current module. The value should not be modified after being passed to
405 // SetVariationProvider.
406 SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{})
Colin Cross6362e272015-10-29 15:25:03 -0700407}
408
Colin Cross25de6c32019-06-06 14:29:25 -0700409type bottomUpMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700410 bp blueprint.BottomUpMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700411 baseModuleContext
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400412 finalPhase bool
Colin Cross6362e272015-10-29 15:25:03 -0700413}
414
Colin Cross617b88a2020-08-24 18:04:09 -0700415func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module,
Liz Kammer356f7d42021-01-26 09:18:53 -0500416 finalPhase, bazelConversionMode bool) BottomUpMutatorContext {
Colin Cross617b88a2020-08-24 18:04:09 -0700417
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400418 moduleContext := a.base().baseModuleContextFactory(ctx)
419 moduleContext.bazelConversionMode = bazelConversionMode
420
Colin Cross617b88a2020-08-24 18:04:09 -0700421 return &bottomUpMutatorContext{
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400422 bp: ctx,
Cole Faust0abd4b42023-01-10 10:49:18 -0800423 baseModuleContext: moduleContext,
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400424 finalPhase: finalPhase,
Colin Cross617b88a2020-08-24 18:04:09 -0700425 }
426}
427
Colin Cross25de6c32019-06-06 14:29:25 -0700428func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000429 finalPhase := x.finalPhase
Liz Kammer356f7d42021-01-26 09:18:53 -0500430 bazelConversionMode := x.bazelConversionMode
Colin Cross798bfce2016-10-12 14:28:16 -0700431 f := func(ctx blueprint.BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700432 if a, ok := ctx.Module().(Module); ok {
Liz Kammer356f7d42021-01-26 09:18:53 -0500433 m(bottomUpMutatorContextFactory(ctx, a, finalPhase, bazelConversionMode))
Colin Cross6362e272015-10-29 15:25:03 -0700434 }
Colin Cross798bfce2016-10-12 14:28:16 -0700435 }
Liz Kammer356f7d42021-01-26 09:18:53 -0500436 mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700437 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700438 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700439}
440
Colin Cross617b88a2020-08-24 18:04:09 -0700441func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle {
442 mutator := &mutator{name: name, bottomUpMutator: m}
443 x.mutators = append(x.mutators, mutator)
444 return mutator
445}
446
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200447type IncomingTransitionContext interface {
448 // Module returns the target of the dependency edge for which the transition
449 // is being computed
450 Module() Module
451
452 // Config returns the configuration for the build.
453 Config() Config
454}
455
456type OutgoingTransitionContext interface {
457 // Module returns the target of the dependency edge for which the transition
458 // is being computed
459 Module() Module
460
461 // DepTag() Returns the dependency tag through which this dependency is
462 // reached
463 DepTag() blueprint.DependencyTag
464}
Lukacs T. Berki0e691c12022-06-24 10:15:55 +0200465
466// Transition mutators implement a top-down mechanism where a module tells its
467// direct dependencies what variation they should be built in but the dependency
468// has the final say.
469//
470// When implementing a transition mutator, one needs to implement four methods:
471// - Split() that tells what variations a module has by itself
472// - OutgoingTransition() where a module tells what it wants from its
473// dependency
474// - IncomingTransition() where a module has the final say about its own
475// variation
476// - Mutate() that changes the state of a module depending on its variation
477//
478// That the effective variation of module B when depended on by module A is the
479// composition the outgoing transition of module A and the incoming transition
480// of module B.
481//
482// the outgoing transition should not take the properties of the dependency into
483// account, only those of the module that depends on it. For this reason, the
484// dependency is not even passed into it as an argument. Likewise, the incoming
485// transition should not take the properties of the depending module into
486// account and is thus not informed about it. This makes for a nice
487// decomposition of the decision logic.
488//
489// A given transition mutator only affects its own variation; other variations
490// stay unchanged along the dependency edges.
491//
492// Soong makes sure that all modules are created in the desired variations and
493// that dependency edges are set up correctly. This ensures that "missing
494// variation" errors do not happen and allows for more flexible changes in the
495// value of the variation among dependency edges (as oppposed to bottom-up
496// mutators where if module A in variation X depends on module B and module B
497// has that variation X, A must depend on variation X of B)
498//
499// The limited power of the context objects passed to individual mutators
500// methods also makes it more difficult to shoot oneself in the foot. Complete
501// safety is not guaranteed because no one prevents individual transition
502// mutators from mutating modules in illegal ways and for e.g. Split() or
503// Mutate() to run their own visitations of the transitive dependency of the
504// module and both of these are bad ideas, but it's better than no guardrails at
505// all.
506//
507// This model is pretty close to Bazel's configuration transitions. The mapping
508// between concepts in Soong and Bazel is as follows:
509// - Module == configured target
510// - Variant == configuration
511// - Variation name == configuration flag
512// - Variation == configuration flag value
513// - Outgoing transition == attribute transition
514// - Incoming transition == rule transition
515//
516// The Split() method does not have a Bazel equivalent and Bazel split
517// transitions do not have a Soong equivalent.
518//
519// Mutate() does not make sense in Bazel due to the different models of the
520// two systems: when creating new variations, Soong clones the old module and
521// thus some way is needed to change it state whereas Bazel creates each
522// configuration of a given configured target anew.
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200523type TransitionMutator interface {
524 // Split returns the set of variations that should be created for a module no
525 // matter who depends on it. Used when Make depends on a particular variation
526 // or when the module knows its variations just based on information given to
527 // it in the Blueprint file. This method should not mutate the module it is
528 // called on.
529 Split(ctx BaseModuleContext) []string
530
Lukacs T. Berki0e691c12022-06-24 10:15:55 +0200531 // Called on a module to determine which variation it wants from its direct
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200532 // dependencies. The dependency itself can override this decision. This method
533 // should not mutate the module itself.
534 OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string
535
536 // Called on a module to determine which variation it should be in based on
537 // the variation modules that depend on it want. This gives the module a final
538 // say about its own variations. This method should not mutate the module
539 // itself.
540 IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string
541
542 // Called after a module was split into multiple variations on each variation.
543 // It should not split the module any further but adding new dependencies is
544 // fine. Unlike all the other methods on TransitionMutator, this method is
545 // allowed to mutate the module.
546 Mutate(ctx BottomUpMutatorContext, variation string)
547}
548
549type androidTransitionMutator struct {
550 finalPhase bool
551 bazelConversionMode bool
552 mutator TransitionMutator
553}
554
555func (a *androidTransitionMutator) Split(ctx blueprint.BaseModuleContext) []string {
556 if m, ok := ctx.Module().(Module); ok {
557 moduleContext := m.base().baseModuleContextFactory(ctx)
558 moduleContext.bazelConversionMode = a.bazelConversionMode
559 return a.mutator.Split(&moduleContext)
560 } else {
561 return []string{""}
562 }
563}
564
565type outgoingTransitionContextImpl struct {
566 bp blueprint.OutgoingTransitionContext
567}
568
569func (c *outgoingTransitionContextImpl) Module() Module {
570 return c.bp.Module().(Module)
571}
572
573func (c *outgoingTransitionContextImpl) DepTag() blueprint.DependencyTag {
574 return c.bp.DepTag()
575}
576
577func (a *androidTransitionMutator) OutgoingTransition(ctx blueprint.OutgoingTransitionContext, sourceVariation string) string {
578 if _, ok := ctx.Module().(Module); ok {
579 return a.mutator.OutgoingTransition(&outgoingTransitionContextImpl{bp: ctx}, sourceVariation)
580 } else {
581 return ""
582 }
583}
584
585type incomingTransitionContextImpl struct {
586 bp blueprint.IncomingTransitionContext
587}
588
589func (c *incomingTransitionContextImpl) Module() Module {
590 return c.bp.Module().(Module)
591}
592
593func (c *incomingTransitionContextImpl) Config() Config {
594 return c.bp.Config().(Config)
595}
596
597func (a *androidTransitionMutator) IncomingTransition(ctx blueprint.IncomingTransitionContext, incomingVariation string) string {
598 if _, ok := ctx.Module().(Module); ok {
599 return a.mutator.IncomingTransition(&incomingTransitionContextImpl{bp: ctx}, incomingVariation)
600 } else {
601 return ""
602 }
603}
604
605func (a *androidTransitionMutator) Mutate(ctx blueprint.BottomUpMutatorContext, variation string) {
606 if am, ok := ctx.Module().(Module); ok {
607 a.mutator.Mutate(bottomUpMutatorContextFactory(ctx, am, a.finalPhase, a.bazelConversionMode), variation)
608 }
609}
610
611func (x *registerMutatorsContext) Transition(name string, m TransitionMutator) {
612 atm := &androidTransitionMutator{
613 finalPhase: x.finalPhase,
614 bazelConversionMode: x.bazelConversionMode,
615 mutator: m,
616 }
617 mutator := &mutator{
618 name: name,
619 transitionMutator: atm}
620 x.mutators = append(x.mutators, mutator)
621}
622
Liz Kammer356f7d42021-01-26 09:18:53 -0500623func (x *registerMutatorsContext) mutatorName(name string) string {
624 if x.bazelConversionMode {
625 return name + "_bp2build"
626 }
627 return name
628}
629
Colin Cross25de6c32019-06-06 14:29:25 -0700630func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle {
Colin Cross798bfce2016-10-12 14:28:16 -0700631 f := func(ctx blueprint.TopDownMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700632 if a, ok := ctx.Module().(Module); ok {
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400633 moduleContext := a.base().baseModuleContextFactory(ctx)
634 moduleContext.bazelConversionMode = x.bazelConversionMode
Colin Cross25de6c32019-06-06 14:29:25 -0700635 actx := &topDownMutatorContext{
Colin Crossdc35e212019-06-06 16:13:11 -0700636 bp: ctx,
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400637 baseModuleContext: moduleContext,
Colin Cross6362e272015-10-29 15:25:03 -0700638 }
Colin Cross798bfce2016-10-12 14:28:16 -0700639 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -0700640 }
Colin Cross798bfce2016-10-12 14:28:16 -0700641 }
Liz Kammer356f7d42021-01-26 09:18:53 -0500642 mutator := &mutator{name: x.mutatorName(name), topDownMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700643 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700644 return mutator
645}
646
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000647func (mutator *mutator) componentName() string {
648 return mutator.name
649}
650
651func (mutator *mutator) register(ctx *Context) {
652 blueprintCtx := ctx.Context
653 var handle blueprint.MutatorHandle
654 if mutator.bottomUpMutator != nil {
655 handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator)
656 } else if mutator.topDownMutator != nil {
657 handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator)
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200658 } else if mutator.transitionMutator != nil {
659 blueprintCtx.RegisterTransitionMutator(mutator.name, mutator.transitionMutator)
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000660 }
661 if mutator.parallel {
662 handle.Parallel()
663 }
664}
665
Colin Cross798bfce2016-10-12 14:28:16 -0700666type MutatorHandle interface {
667 Parallel() MutatorHandle
668}
669
670func (mutator *mutator) Parallel() MutatorHandle {
671 mutator.parallel = true
672 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700673}
Colin Cross1e676be2016-10-12 14:38:15 -0700674
Paul Duffin44f1d842020-06-26 20:17:02 +0100675func RegisterComponentsMutator(ctx RegisterMutatorsContext) {
676 ctx.BottomUp("component-deps", componentDepsMutator).Parallel()
677}
678
679// A special mutator that runs just prior to the deps mutator to allow the dependencies
680// on component modules to be added so that they can depend directly on a prebuilt
681// module.
682func componentDepsMutator(ctx BottomUpMutatorContext) {
683 if m := ctx.Module(); m.Enabled() {
684 m.ComponentDepsMutator(ctx)
685 }
686}
687
Colin Cross1e676be2016-10-12 14:38:15 -0700688func depsMutator(ctx BottomUpMutatorContext) {
Paul Duffin44f1d842020-06-26 20:17:02 +0100689 if m := ctx.Module(); m.Enabled() {
Colin Cross1e676be2016-10-12 14:38:15 -0700690 m.DepsMutator(ctx)
691 }
692}
Colin Crossd11fcda2017-10-23 17:59:01 -0700693
Liz Kammer356f7d42021-01-26 09:18:53 -0500694func registerDepsMutator(ctx RegisterMutatorsContext) {
695 ctx.BottomUp("deps", depsMutator).Parallel()
696}
697
698func registerDepsMutatorBp2Build(ctx RegisterMutatorsContext) {
699 // TODO(b/179313531): Consider a separate mutator that only runs depsMutator for modules that are
700 // being converted to build targets.
701 ctx.BottomUp("deps", depsMutator).Parallel()
702}
703
Jingwen Chen1fd14692021-02-05 03:01:50 -0500704func (t *topDownMutatorContext) CreateBazelTargetModule(
Jingwen Chen1fd14692021-02-05 03:01:50 -0500705 bazelProps bazel.BazelTargetModuleProperties,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000706 commonAttrs CommonAttributes,
Liz Kammer2ada09a2021-08-11 00:17:36 -0400707 attrs interface{}) {
Chris Parsons58852a02021-12-09 18:10:18 -0500708 t.createBazelTargetModule(bazelProps, commonAttrs, attrs, bazel.BoolAttribute{})
709}
710
711func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions(
712 bazelProps bazel.BazelTargetModuleProperties,
713 commonAttrs CommonAttributes,
714 attrs interface{},
715 enabledProperty bazel.BoolAttribute) {
716 t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty)
717}
718
Spandan Dasabedff02023-03-07 19:24:34 +0000719var (
720 bazelAliasModuleProperties = bazel.BazelTargetModuleProperties{
721 Rule_class: "alias",
722 }
723)
724
725type bazelAliasAttributes struct {
726 Actual *bazel.LabelAttribute
727}
728
729func (t *topDownMutatorContext) CreateBazelTargetAliasInDir(
730 dir string,
731 name string,
732 actual bazel.Label) {
733 mod := t.Module()
734 attrs := &bazelAliasAttributes{
735 Actual: bazel.MakeLabelAttribute(actual.Label),
736 }
737 info := bp2buildInfo{
738 Dir: dir,
739 BazelProps: bazelAliasModuleProperties,
740 CommonAttrs: CommonAttributes{Name: name},
741 ConstraintAttrs: constraintAttributes{},
742 Attrs: attrs,
743 }
744 mod.base().addBp2buildInfo(info)
745}
746
Spandan Das6a448ec2023-04-19 17:36:12 +0000747func (t *topDownMutatorContext) CreateBazelConfigSetting(
748 csa bazel.ConfigSettingAttributes,
749 ca CommonAttributes,
750 dir string) {
751 mod := t.Module()
752 info := bp2buildInfo{
753 Dir: dir,
754 BazelProps: bazel.BazelTargetModuleProperties{
755 Rule_class: "config_setting",
756 },
757 CommonAttrs: ca,
758 ConstraintAttrs: constraintAttributes{},
759 Attrs: &csa,
760 }
761 mod.base().addBp2buildInfo(info)
762}
763
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000764// ApexAvailableTags converts the apex_available property value of an ApexModule
765// module and returns it as a list of keyed tags.
766func ApexAvailableTags(mod Module) bazel.StringListAttribute {
767 attr := bazel.StringListAttribute{}
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000768 // Transform specific attributes into tags.
769 if am, ok := mod.(ApexModule); ok {
770 // TODO(b/218841706): hidl_interface has the apex_available prop, but it's
771 // defined directly as a prop and not via ApexModule, so this doesn't
772 // pick those props up.
Spandan Das2dc6dfc2023-04-17 19:16:06 +0000773 apexAvailable := am.apexModuleBase().ApexAvailable()
774 // If a user does not specify apex_available in Android.bp, then soong provides a default.
775 // To avoid verbosity of BUILD files, remove this default from user-facing BUILD files.
776 if len(am.apexModuleBase().ApexProperties.Apex_available) == 0 {
777 apexAvailable = []string{}
778 }
779 attr.Value = ConvertApexAvailableToTags(apexAvailable)
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000780 }
781 return attr
782}
783
Cole Faustfb11c1c2023-02-10 11:27:46 -0800784func ConvertApexAvailableToTags(apexAvailable []string) []string {
785 if len(apexAvailable) == 0 {
786 // We need nil specifically to make bp2build not add the tags property at all,
787 // instead of adding it with an empty list
788 return nil
789 }
790 result := make([]string, 0, len(apexAvailable))
791 for _, a := range apexAvailable {
792 result = append(result, "apex_available="+a)
793 }
794 return result
795}
796
Chris Parsons58852a02021-12-09 18:10:18 -0500797func (t *topDownMutatorContext) createBazelTargetModule(
798 bazelProps bazel.BazelTargetModuleProperties,
799 commonAttrs CommonAttributes,
800 attrs interface{},
801 enabledProperty bazel.BoolAttribute) {
802 constraintAttributes := commonAttrs.fillCommonBp2BuildModuleAttrs(t, enabledProperty)
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000803 mod := t.Module()
Liz Kammer2ada09a2021-08-11 00:17:36 -0400804 info := bp2buildInfo{
Chris Parsons58852a02021-12-09 18:10:18 -0500805 Dir: t.OtherModuleDir(mod),
806 BazelProps: bazelProps,
807 CommonAttrs: commonAttrs,
808 ConstraintAttrs: constraintAttributes,
809 Attrs: attrs,
Jingwen Chenfb4692a2021-02-07 10:05:16 -0500810 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000811 mod.base().addBp2buildInfo(info)
Jingwen Chen1fd14692021-02-05 03:01:50 -0500812}
813
Colin Crossdc35e212019-06-06 16:13:11 -0700814// android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that
815// has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid
816// ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every
817// non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following
818// methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext.
819
Colin Crosscb55e082019-07-01 15:32:31 -0700820func (t *topDownMutatorContext) MutatorName() string {
821 return t.bp.MutatorName()
822}
823
Colin Crossdc35e212019-06-06 16:13:11 -0700824func (t *topDownMutatorContext) Rename(name string) {
825 t.bp.Rename(name)
Colin Cross9a362232019-07-01 15:32:45 -0700826 t.Module().base().commonProperties.DebugName = name
Colin Crossdc35e212019-06-06 16:13:11 -0700827}
828
Liz Kammerf31c9002022-04-26 09:08:55 -0400829func (t *topDownMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module {
830 return t.bp.CreateModule(factory, name, props...)
831}
832
Colin Crosse003c4a2019-09-25 12:58:36 -0700833func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
Liz Kammerf31c9002022-04-26 09:08:55 -0400834 return createModule(t, factory, "_topDownMutatorModule", props...)
Colin Crossdc35e212019-06-06 16:13:11 -0700835}
836
Liz Kammera060c452021-03-24 10:14:47 -0400837func (t *topDownMutatorContext) createModuleWithoutInheritance(factory ModuleFactory, props ...interface{}) Module {
Liz Kammerf31c9002022-04-26 09:08:55 -0400838 module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), "", props...).(Module)
Liz Kammera060c452021-03-24 10:14:47 -0400839 return module
840}
841
Colin Crosscb55e082019-07-01 15:32:31 -0700842func (b *bottomUpMutatorContext) MutatorName() string {
843 return b.bp.MutatorName()
844}
845
Colin Crossdc35e212019-06-06 16:13:11 -0700846func (b *bottomUpMutatorContext) Rename(name string) {
847 b.bp.Rename(name)
Colin Cross9a362232019-07-01 15:32:45 -0700848 b.Module().base().commonProperties.DebugName = name
Colin Crossdc35e212019-06-06 16:13:11 -0700849}
850
Colin Cross4f1dcb02020-09-16 18:45:04 -0700851func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module {
852 return b.bp.AddDependency(module, tag, name...)
Colin Crossdc35e212019-06-06 16:13:11 -0700853}
854
855func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) {
856 b.bp.AddReverseDependency(module, tag, name)
857}
858
Colin Cross43b92e02019-11-18 15:28:57 -0800859func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000860 if b.finalPhase {
861 panic("CreateVariations not allowed in FinalDepsMutators")
862 }
863
Colin Cross9a362232019-07-01 15:32:45 -0700864 modules := b.bp.CreateVariations(variations...)
865
Colin Cross43b92e02019-11-18 15:28:57 -0800866 aModules := make([]Module, len(modules))
Colin Cross9a362232019-07-01 15:32:45 -0700867 for i := range variations {
Colin Cross43b92e02019-11-18 15:28:57 -0800868 aModules[i] = modules[i].(Module)
869 base := aModules[i].base()
Colin Cross9a362232019-07-01 15:32:45 -0700870 base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
871 base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
872 }
873
Colin Cross43b92e02019-11-18 15:28:57 -0800874 return aModules
Colin Crossdc35e212019-06-06 16:13:11 -0700875}
876
Colin Cross43b92e02019-11-18 15:28:57 -0800877func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000878 if b.finalPhase {
879 panic("CreateLocalVariations not allowed in FinalDepsMutators")
880 }
881
Colin Cross9a362232019-07-01 15:32:45 -0700882 modules := b.bp.CreateLocalVariations(variations...)
883
Colin Cross43b92e02019-11-18 15:28:57 -0800884 aModules := make([]Module, len(modules))
Colin Cross9a362232019-07-01 15:32:45 -0700885 for i := range variations {
Colin Cross43b92e02019-11-18 15:28:57 -0800886 aModules[i] = modules[i].(Module)
887 base := aModules[i].base()
Colin Cross9a362232019-07-01 15:32:45 -0700888 base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
889 base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
890 }
891
Colin Cross43b92e02019-11-18 15:28:57 -0800892 return aModules
Colin Crossdc35e212019-06-06 16:13:11 -0700893}
894
895func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
896 b.bp.SetDependencyVariation(variation)
897}
898
Jiyong Park1d1119f2019-07-29 21:27:18 +0900899func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) {
900 b.bp.SetDefaultDependencyVariation(variation)
901}
902
Colin Crossdc35e212019-06-06 16:13:11 -0700903func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700904 names ...string) []blueprint.Module {
Colin Cross4f1dcb02020-09-16 18:45:04 -0700905 return b.bp.AddVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700906}
907
908func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700909 tag blueprint.DependencyTag, names ...string) []blueprint.Module {
Colin Crossdc35e212019-06-06 16:13:11 -0700910
Colin Cross4f1dcb02020-09-16 18:45:04 -0700911 return b.bp.AddFarVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700912}
913
914func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) {
915 b.bp.AddInterVariantDependency(tag, from, to)
916}
917
918func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
919 b.bp.ReplaceDependencies(name)
920}
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800921
Paul Duffin80342d72020-06-26 22:08:43 +0100922func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) {
923 b.bp.ReplaceDependenciesIf(name, predicate)
924}
925
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800926func (b *bottomUpMutatorContext) AliasVariation(variationName string) {
927 b.bp.AliasVariation(variationName)
928}
Colin Cross1b9604b2020-08-11 12:03:56 -0700929
930func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) {
931 b.bp.CreateAliasVariation(fromVariationName, toVariationName)
932}
Colin Crossd27e7b82020-07-02 11:38:17 -0700933
934func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) {
935 b.bp.SetVariationProvider(module, provider, value)
936}