blob: 4ec960472d4a6335b84d71571b24848fb85d7815 [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)
Colin Cross6362e272015-10-29 15:25:03 -0700276}
277
Colin Cross25de6c32019-06-06 14:29:25 -0700278type topDownMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700279 bp blueprint.TopDownMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700280 baseModuleContext
Colin Cross6362e272015-10-29 15:25:03 -0700281}
282
Colin Cross25de6c32019-06-06 14:29:25 -0700283type BottomUpMutator func(BottomUpMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -0700284
Colin Cross635c3b02016-05-18 15:37:25 -0700285type BottomUpMutatorContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -0700286 BaseMutatorContext
Colin Crossaabf6792017-11-29 00:27:14 -0800287
Colin Cross4f1dcb02020-09-16 18:45:04 -0700288 // AddDependency adds a dependency to the given module. It returns a slice of modules for each
289 // dependency (some entries may be nil).
290 //
291 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
292 // new dependencies have had the current mutator called on them. If the mutator is not
293 // parallel this method does not affect the ordering of the current mutator pass, but will
294 // be ordered correctly for all future mutator passes.
295 AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700296
297 // AddReverseDependency adds a dependency from the destination to the given module.
298 // Does not affect the ordering of the current mutator pass, but will be ordered
299 // correctly for all future mutator passes. All reverse dependencies for a destination module are
300 // collected until the end of the mutator pass, sorted by name, and then appended to the destination
301 // module's dependency list.
Colin Crossaabf6792017-11-29 00:27:14 -0800302 AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700303
304 // CreateVariations splits a module into multiple variants, one for each name in the variationNames
305 // parameter. It returns a list of new modules in the same order as the variationNames
306 // list.
307 //
308 // If any of the dependencies of the module being operated on were already split
309 // by calling CreateVariations with the same name, the dependency will automatically
310 // be updated to point the matching variant.
311 //
312 // If a module is split, and then a module depending on the first module is not split
313 // when the Mutator is later called on it, the dependency of the depending module will
314 // automatically be updated to point to the first variant.
Colin Cross43b92e02019-11-18 15:28:57 -0800315 CreateVariations(...string) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700316
317 // CreateLocationVariations splits a module into multiple variants, one for each name in the variantNames
318 // parameter. It returns a list of new modules in the same order as the variantNames
319 // list.
320 //
321 // Local variations do not affect automatic dependency resolution - dependencies added
322 // to the split module via deps or DynamicDependerModule must exactly match a variant
323 // that contains all the non-local variations.
Colin Cross43b92e02019-11-18 15:28:57 -0800324 CreateLocalVariations(...string) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700325
326 // SetDependencyVariation sets all dangling dependencies on the current module to point to the variation
327 // with given name. This function ignores the default variation set by SetDefaultDependencyVariation.
Colin Crossaabf6792017-11-29 00:27:14 -0800328 SetDependencyVariation(string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700329
330 // SetDefaultDependencyVariation sets the default variation when a dangling reference is detected
331 // during the subsequent calls on Create*Variations* functions. To reset, set it to nil.
Jiyong Park1d1119f2019-07-29 21:27:18 +0900332 SetDefaultDependencyVariation(*string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700333
334 // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
Colin Cross4f1dcb02020-09-16 18:45:04 -0700335 // argument to select which variant of the dependency to use. It returns a slice of modules for
336 // each dependency (some entries may be nil). A variant of the dependency must exist that matches
Usta Shresthac725f472022-01-11 02:44:21 -0500337 // all the non-local variations of the current module, plus the variations argument.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700338 //
339 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
340 // new dependencies have had the current mutator called on them. If the mutator is not
341 // parallel this method does not affect the ordering of the current mutator pass, but will
342 // be ordered correctly for all future mutator passes.
Usta Shresthac725f472022-01-11 02:44:21 -0500343 AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700344
345 // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the
Colin Cross4f1dcb02020-09-16 18:45:04 -0700346 // variations argument to select which variant of the dependency to use. It returns a slice of
347 // modules for each dependency (some entries may be nil). A variant of the dependency must
348 // exist that matches the variations argument, but may also have other variations.
Colin Cross9f35c3d2020-09-16 19:04:41 -0700349 // For any unspecified variation the first variant will be used.
350 //
351 // Unlike AddVariationDependencies, the variations of the current module are ignored - the
352 // dependency only needs to match the supplied variations.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700353 //
354 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
355 // new dependencies have had the current mutator called on them. If the mutator is not
356 // parallel this method does not affect the ordering of the current mutator pass, but will
357 // be ordered correctly for all future mutator passes.
358 AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700359
360 // AddInterVariantDependency adds a dependency between two variants of the same module. Variants are always
361 // ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change
362 // that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps,
363 // WalkDeps, etc.
Colin Crossaabf6792017-11-29 00:27:14 -0800364 AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700365
366 // ReplaceDependencies replaces all dependencies on the identical variant of the module with the
367 // specified name with the current variant of this module. Replacements don't take effect until
368 // after the mutator pass is finished.
Colin Crossaabf6792017-11-29 00:27:14 -0800369 ReplaceDependencies(string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700370
371 // ReplaceDependencies replaces all dependencies on the identical variant of the module with the
372 // specified name with the current variant of this module as long as the supplied predicate returns
373 // true.
374 //
375 // Replacements don't take effect until after the mutator pass is finished.
Paul Duffin80342d72020-06-26 22:08:43 +0100376 ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700377
378 // AliasVariation takes a variationName that was passed to CreateVariations for this module,
379 // and creates an alias from the current variant (before the mutator has run) to the new
380 // variant. The alias will be valid until the next time a mutator calls CreateVariations or
381 // CreateLocalVariations on this module without also calling AliasVariation. The alias can
382 // be used to add dependencies on the newly created variant using the variant map from
383 // before CreateVariations was run.
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800384 AliasVariation(variationName string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700385
386 // CreateAliasVariation takes a toVariationName that was passed to CreateVariations for this
387 // module, and creates an alias from a new fromVariationName variant the toVariationName
388 // variant. The alias will be valid until the next time a mutator calls CreateVariations or
389 // CreateLocalVariations on this module without also calling AliasVariation. The alias can
390 // be used to add dependencies on the toVariationName variant using the fromVariationName
391 // variant.
Colin Cross1b9604b2020-08-11 12:03:56 -0700392 CreateAliasVariation(fromVariationName, toVariationName string)
Colin Crossd27e7b82020-07-02 11:38:17 -0700393
394 // SetVariationProvider sets the value for a provider for the given newly created variant of
395 // the current module, i.e. one of the Modules returned by CreateVariations.. It panics if
396 // not called during the appropriate mutator or GenerateBuildActions pass for the provider,
397 // if the value is not of the appropriate type, or if the module is not a newly created
398 // variant of the current module. The value should not be modified after being passed to
399 // SetVariationProvider.
400 SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{})
Colin Cross6362e272015-10-29 15:25:03 -0700401}
402
Colin Cross25de6c32019-06-06 14:29:25 -0700403type bottomUpMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700404 bp blueprint.BottomUpMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700405 baseModuleContext
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400406 finalPhase bool
Colin Cross6362e272015-10-29 15:25:03 -0700407}
408
Colin Cross617b88a2020-08-24 18:04:09 -0700409func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module,
Liz Kammer356f7d42021-01-26 09:18:53 -0500410 finalPhase, bazelConversionMode bool) BottomUpMutatorContext {
Colin Cross617b88a2020-08-24 18:04:09 -0700411
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400412 moduleContext := a.base().baseModuleContextFactory(ctx)
413 moduleContext.bazelConversionMode = bazelConversionMode
414
Colin Cross617b88a2020-08-24 18:04:09 -0700415 return &bottomUpMutatorContext{
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400416 bp: ctx,
Cole Faust0abd4b42023-01-10 10:49:18 -0800417 baseModuleContext: moduleContext,
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400418 finalPhase: finalPhase,
Colin Cross617b88a2020-08-24 18:04:09 -0700419 }
420}
421
Colin Cross25de6c32019-06-06 14:29:25 -0700422func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000423 finalPhase := x.finalPhase
Liz Kammer356f7d42021-01-26 09:18:53 -0500424 bazelConversionMode := x.bazelConversionMode
Colin Cross798bfce2016-10-12 14:28:16 -0700425 f := func(ctx blueprint.BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700426 if a, ok := ctx.Module().(Module); ok {
Liz Kammer356f7d42021-01-26 09:18:53 -0500427 m(bottomUpMutatorContextFactory(ctx, a, finalPhase, bazelConversionMode))
Colin Cross6362e272015-10-29 15:25:03 -0700428 }
Colin Cross798bfce2016-10-12 14:28:16 -0700429 }
Liz Kammer356f7d42021-01-26 09:18:53 -0500430 mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700431 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700432 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700433}
434
Colin Cross617b88a2020-08-24 18:04:09 -0700435func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle {
436 mutator := &mutator{name: name, bottomUpMutator: m}
437 x.mutators = append(x.mutators, mutator)
438 return mutator
439}
440
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200441type IncomingTransitionContext interface {
442 // Module returns the target of the dependency edge for which the transition
443 // is being computed
444 Module() Module
445
446 // Config returns the configuration for the build.
447 Config() Config
448}
449
450type OutgoingTransitionContext interface {
451 // Module returns the target of the dependency edge for which the transition
452 // is being computed
453 Module() Module
454
455 // DepTag() Returns the dependency tag through which this dependency is
456 // reached
457 DepTag() blueprint.DependencyTag
458}
Lukacs T. Berki0e691c12022-06-24 10:15:55 +0200459
460// Transition mutators implement a top-down mechanism where a module tells its
461// direct dependencies what variation they should be built in but the dependency
462// has the final say.
463//
464// When implementing a transition mutator, one needs to implement four methods:
465// - Split() that tells what variations a module has by itself
466// - OutgoingTransition() where a module tells what it wants from its
467// dependency
468// - IncomingTransition() where a module has the final say about its own
469// variation
470// - Mutate() that changes the state of a module depending on its variation
471//
472// That the effective variation of module B when depended on by module A is the
473// composition the outgoing transition of module A and the incoming transition
474// of module B.
475//
476// the outgoing transition should not take the properties of the dependency into
477// account, only those of the module that depends on it. For this reason, the
478// dependency is not even passed into it as an argument. Likewise, the incoming
479// transition should not take the properties of the depending module into
480// account and is thus not informed about it. This makes for a nice
481// decomposition of the decision logic.
482//
483// A given transition mutator only affects its own variation; other variations
484// stay unchanged along the dependency edges.
485//
486// Soong makes sure that all modules are created in the desired variations and
487// that dependency edges are set up correctly. This ensures that "missing
488// variation" errors do not happen and allows for more flexible changes in the
489// value of the variation among dependency edges (as oppposed to bottom-up
490// mutators where if module A in variation X depends on module B and module B
491// has that variation X, A must depend on variation X of B)
492//
493// The limited power of the context objects passed to individual mutators
494// methods also makes it more difficult to shoot oneself in the foot. Complete
495// safety is not guaranteed because no one prevents individual transition
496// mutators from mutating modules in illegal ways and for e.g. Split() or
497// Mutate() to run their own visitations of the transitive dependency of the
498// module and both of these are bad ideas, but it's better than no guardrails at
499// all.
500//
501// This model is pretty close to Bazel's configuration transitions. The mapping
502// between concepts in Soong and Bazel is as follows:
503// - Module == configured target
504// - Variant == configuration
505// - Variation name == configuration flag
506// - Variation == configuration flag value
507// - Outgoing transition == attribute transition
508// - Incoming transition == rule transition
509//
510// The Split() method does not have a Bazel equivalent and Bazel split
511// transitions do not have a Soong equivalent.
512//
513// Mutate() does not make sense in Bazel due to the different models of the
514// two systems: when creating new variations, Soong clones the old module and
515// thus some way is needed to change it state whereas Bazel creates each
516// configuration of a given configured target anew.
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200517type TransitionMutator interface {
518 // Split returns the set of variations that should be created for a module no
519 // matter who depends on it. Used when Make depends on a particular variation
520 // or when the module knows its variations just based on information given to
521 // it in the Blueprint file. This method should not mutate the module it is
522 // called on.
523 Split(ctx BaseModuleContext) []string
524
Lukacs T. Berki0e691c12022-06-24 10:15:55 +0200525 // Called on a module to determine which variation it wants from its direct
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200526 // dependencies. The dependency itself can override this decision. This method
527 // should not mutate the module itself.
528 OutgoingTransition(ctx OutgoingTransitionContext, sourceVariation string) string
529
530 // Called on a module to determine which variation it should be in based on
531 // the variation modules that depend on it want. This gives the module a final
532 // say about its own variations. This method should not mutate the module
533 // itself.
534 IncomingTransition(ctx IncomingTransitionContext, incomingVariation string) string
535
536 // Called after a module was split into multiple variations on each variation.
537 // It should not split the module any further but adding new dependencies is
538 // fine. Unlike all the other methods on TransitionMutator, this method is
539 // allowed to mutate the module.
540 Mutate(ctx BottomUpMutatorContext, variation string)
541}
542
543type androidTransitionMutator struct {
544 finalPhase bool
545 bazelConversionMode bool
546 mutator TransitionMutator
547}
548
549func (a *androidTransitionMutator) Split(ctx blueprint.BaseModuleContext) []string {
550 if m, ok := ctx.Module().(Module); ok {
551 moduleContext := m.base().baseModuleContextFactory(ctx)
552 moduleContext.bazelConversionMode = a.bazelConversionMode
553 return a.mutator.Split(&moduleContext)
554 } else {
555 return []string{""}
556 }
557}
558
559type outgoingTransitionContextImpl struct {
560 bp blueprint.OutgoingTransitionContext
561}
562
563func (c *outgoingTransitionContextImpl) Module() Module {
564 return c.bp.Module().(Module)
565}
566
567func (c *outgoingTransitionContextImpl) DepTag() blueprint.DependencyTag {
568 return c.bp.DepTag()
569}
570
571func (a *androidTransitionMutator) OutgoingTransition(ctx blueprint.OutgoingTransitionContext, sourceVariation string) string {
572 if _, ok := ctx.Module().(Module); ok {
573 return a.mutator.OutgoingTransition(&outgoingTransitionContextImpl{bp: ctx}, sourceVariation)
574 } else {
575 return ""
576 }
577}
578
579type incomingTransitionContextImpl struct {
580 bp blueprint.IncomingTransitionContext
581}
582
583func (c *incomingTransitionContextImpl) Module() Module {
584 return c.bp.Module().(Module)
585}
586
587func (c *incomingTransitionContextImpl) Config() Config {
588 return c.bp.Config().(Config)
589}
590
591func (a *androidTransitionMutator) IncomingTransition(ctx blueprint.IncomingTransitionContext, incomingVariation string) string {
592 if _, ok := ctx.Module().(Module); ok {
593 return a.mutator.IncomingTransition(&incomingTransitionContextImpl{bp: ctx}, incomingVariation)
594 } else {
595 return ""
596 }
597}
598
599func (a *androidTransitionMutator) Mutate(ctx blueprint.BottomUpMutatorContext, variation string) {
600 if am, ok := ctx.Module().(Module); ok {
601 a.mutator.Mutate(bottomUpMutatorContextFactory(ctx, am, a.finalPhase, a.bazelConversionMode), variation)
602 }
603}
604
605func (x *registerMutatorsContext) Transition(name string, m TransitionMutator) {
606 atm := &androidTransitionMutator{
607 finalPhase: x.finalPhase,
608 bazelConversionMode: x.bazelConversionMode,
609 mutator: m,
610 }
611 mutator := &mutator{
612 name: name,
613 transitionMutator: atm}
614 x.mutators = append(x.mutators, mutator)
615}
616
Liz Kammer356f7d42021-01-26 09:18:53 -0500617func (x *registerMutatorsContext) mutatorName(name string) string {
618 if x.bazelConversionMode {
619 return name + "_bp2build"
620 }
621 return name
622}
623
Colin Cross25de6c32019-06-06 14:29:25 -0700624func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle {
Colin Cross798bfce2016-10-12 14:28:16 -0700625 f := func(ctx blueprint.TopDownMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700626 if a, ok := ctx.Module().(Module); ok {
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400627 moduleContext := a.base().baseModuleContextFactory(ctx)
628 moduleContext.bazelConversionMode = x.bazelConversionMode
Colin Cross25de6c32019-06-06 14:29:25 -0700629 actx := &topDownMutatorContext{
Colin Crossdc35e212019-06-06 16:13:11 -0700630 bp: ctx,
Chris Parsons5a34ffb2021-07-21 14:34:58 -0400631 baseModuleContext: moduleContext,
Colin Cross6362e272015-10-29 15:25:03 -0700632 }
Colin Cross798bfce2016-10-12 14:28:16 -0700633 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -0700634 }
Colin Cross798bfce2016-10-12 14:28:16 -0700635 }
Liz Kammer356f7d42021-01-26 09:18:53 -0500636 mutator := &mutator{name: x.mutatorName(name), topDownMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700637 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700638 return mutator
639}
640
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000641func (mutator *mutator) componentName() string {
642 return mutator.name
643}
644
645func (mutator *mutator) register(ctx *Context) {
646 blueprintCtx := ctx.Context
647 var handle blueprint.MutatorHandle
648 if mutator.bottomUpMutator != nil {
649 handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator)
650 } else if mutator.topDownMutator != nil {
651 handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator)
Lukacs T. Berki6c716762022-06-13 20:50:39 +0200652 } else if mutator.transitionMutator != nil {
653 blueprintCtx.RegisterTransitionMutator(mutator.name, mutator.transitionMutator)
Paul Duffin1d2d42f2021-03-06 20:08:12 +0000654 }
655 if mutator.parallel {
656 handle.Parallel()
657 }
658}
659
Colin Cross798bfce2016-10-12 14:28:16 -0700660type MutatorHandle interface {
661 Parallel() MutatorHandle
662}
663
664func (mutator *mutator) Parallel() MutatorHandle {
665 mutator.parallel = true
666 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700667}
Colin Cross1e676be2016-10-12 14:38:15 -0700668
Paul Duffin44f1d842020-06-26 20:17:02 +0100669func RegisterComponentsMutator(ctx RegisterMutatorsContext) {
670 ctx.BottomUp("component-deps", componentDepsMutator).Parallel()
671}
672
673// A special mutator that runs just prior to the deps mutator to allow the dependencies
674// on component modules to be added so that they can depend directly on a prebuilt
675// module.
676func componentDepsMutator(ctx BottomUpMutatorContext) {
677 if m := ctx.Module(); m.Enabled() {
678 m.ComponentDepsMutator(ctx)
679 }
680}
681
Colin Cross1e676be2016-10-12 14:38:15 -0700682func depsMutator(ctx BottomUpMutatorContext) {
Paul Duffin44f1d842020-06-26 20:17:02 +0100683 if m := ctx.Module(); m.Enabled() {
Colin Cross1e676be2016-10-12 14:38:15 -0700684 m.DepsMutator(ctx)
685 }
686}
Colin Crossd11fcda2017-10-23 17:59:01 -0700687
Liz Kammer356f7d42021-01-26 09:18:53 -0500688func registerDepsMutator(ctx RegisterMutatorsContext) {
689 ctx.BottomUp("deps", depsMutator).Parallel()
690}
691
692func registerDepsMutatorBp2Build(ctx RegisterMutatorsContext) {
693 // TODO(b/179313531): Consider a separate mutator that only runs depsMutator for modules that are
694 // being converted to build targets.
695 ctx.BottomUp("deps", depsMutator).Parallel()
696}
697
Jingwen Chen1fd14692021-02-05 03:01:50 -0500698func (t *topDownMutatorContext) CreateBazelTargetModule(
Jingwen Chen1fd14692021-02-05 03:01:50 -0500699 bazelProps bazel.BazelTargetModuleProperties,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000700 commonAttrs CommonAttributes,
Liz Kammer2ada09a2021-08-11 00:17:36 -0400701 attrs interface{}) {
Chris Parsons58852a02021-12-09 18:10:18 -0500702 t.createBazelTargetModule(bazelProps, commonAttrs, attrs, bazel.BoolAttribute{})
703}
704
705func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions(
706 bazelProps bazel.BazelTargetModuleProperties,
707 commonAttrs CommonAttributes,
708 attrs interface{},
709 enabledProperty bazel.BoolAttribute) {
710 t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty)
711}
712
Spandan Dasabedff02023-03-07 19:24:34 +0000713var (
714 bazelAliasModuleProperties = bazel.BazelTargetModuleProperties{
715 Rule_class: "alias",
716 }
717)
718
719type bazelAliasAttributes struct {
720 Actual *bazel.LabelAttribute
721}
722
723func (t *topDownMutatorContext) CreateBazelTargetAliasInDir(
724 dir string,
725 name string,
726 actual bazel.Label) {
727 mod := t.Module()
728 attrs := &bazelAliasAttributes{
729 Actual: bazel.MakeLabelAttribute(actual.Label),
730 }
731 info := bp2buildInfo{
732 Dir: dir,
733 BazelProps: bazelAliasModuleProperties,
734 CommonAttrs: CommonAttributes{Name: name},
735 ConstraintAttrs: constraintAttributes{},
736 Attrs: attrs,
737 }
738 mod.base().addBp2buildInfo(info)
739}
740
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000741// ApexAvailableTags converts the apex_available property value of an ApexModule
742// module and returns it as a list of keyed tags.
743func ApexAvailableTags(mod Module) bazel.StringListAttribute {
744 attr := bazel.StringListAttribute{}
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000745 // Transform specific attributes into tags.
746 if am, ok := mod.(ApexModule); ok {
747 // TODO(b/218841706): hidl_interface has the apex_available prop, but it's
748 // defined directly as a prop and not via ApexModule, so this doesn't
749 // pick those props up.
Spandan Das2dc6dfc2023-04-17 19:16:06 +0000750 apexAvailable := am.apexModuleBase().ApexAvailable()
751 // If a user does not specify apex_available in Android.bp, then soong provides a default.
752 // To avoid verbosity of BUILD files, remove this default from user-facing BUILD files.
753 if len(am.apexModuleBase().ApexProperties.Apex_available) == 0 {
754 apexAvailable = []string{}
755 }
756 attr.Value = ConvertApexAvailableToTags(apexAvailable)
Jingwen Chenc4c34e12022-11-29 12:07:45 +0000757 }
758 return attr
759}
760
Cole Faustfb11c1c2023-02-10 11:27:46 -0800761func ConvertApexAvailableToTags(apexAvailable []string) []string {
762 if len(apexAvailable) == 0 {
763 // We need nil specifically to make bp2build not add the tags property at all,
764 // instead of adding it with an empty list
765 return nil
766 }
767 result := make([]string, 0, len(apexAvailable))
768 for _, a := range apexAvailable {
769 result = append(result, "apex_available="+a)
770 }
771 return result
772}
773
Chris Parsons58852a02021-12-09 18:10:18 -0500774func (t *topDownMutatorContext) createBazelTargetModule(
775 bazelProps bazel.BazelTargetModuleProperties,
776 commonAttrs CommonAttributes,
777 attrs interface{},
778 enabledProperty bazel.BoolAttribute) {
779 constraintAttributes := commonAttrs.fillCommonBp2BuildModuleAttrs(t, enabledProperty)
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000780 mod := t.Module()
Liz Kammer2ada09a2021-08-11 00:17:36 -0400781 info := bp2buildInfo{
Chris Parsons58852a02021-12-09 18:10:18 -0500782 Dir: t.OtherModuleDir(mod),
783 BazelProps: bazelProps,
784 CommonAttrs: commonAttrs,
785 ConstraintAttrs: constraintAttributes,
786 Attrs: attrs,
Jingwen Chenfb4692a2021-02-07 10:05:16 -0500787 }
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux447f6c92021-08-31 20:30:36 +0000788 mod.base().addBp2buildInfo(info)
Jingwen Chen1fd14692021-02-05 03:01:50 -0500789}
790
Colin Crossdc35e212019-06-06 16:13:11 -0700791// android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that
792// has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid
793// ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every
794// non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following
795// methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext.
796
Colin Crosscb55e082019-07-01 15:32:31 -0700797func (t *topDownMutatorContext) MutatorName() string {
798 return t.bp.MutatorName()
799}
800
Colin Crossdc35e212019-06-06 16:13:11 -0700801func (t *topDownMutatorContext) Rename(name string) {
802 t.bp.Rename(name)
Colin Cross9a362232019-07-01 15:32:45 -0700803 t.Module().base().commonProperties.DebugName = name
Colin Crossdc35e212019-06-06 16:13:11 -0700804}
805
Liz Kammerf31c9002022-04-26 09:08:55 -0400806func (t *topDownMutatorContext) createModule(factory blueprint.ModuleFactory, name string, props ...interface{}) blueprint.Module {
807 return t.bp.CreateModule(factory, name, props...)
808}
809
Colin Crosse003c4a2019-09-25 12:58:36 -0700810func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
Liz Kammerf31c9002022-04-26 09:08:55 -0400811 return createModule(t, factory, "_topDownMutatorModule", props...)
Colin Crossdc35e212019-06-06 16:13:11 -0700812}
813
Liz Kammera060c452021-03-24 10:14:47 -0400814func (t *topDownMutatorContext) createModuleWithoutInheritance(factory ModuleFactory, props ...interface{}) Module {
Liz Kammerf31c9002022-04-26 09:08:55 -0400815 module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), "", props...).(Module)
Liz Kammera060c452021-03-24 10:14:47 -0400816 return module
817}
818
Colin Crosscb55e082019-07-01 15:32:31 -0700819func (b *bottomUpMutatorContext) MutatorName() string {
820 return b.bp.MutatorName()
821}
822
Colin Crossdc35e212019-06-06 16:13:11 -0700823func (b *bottomUpMutatorContext) Rename(name string) {
824 b.bp.Rename(name)
Colin Cross9a362232019-07-01 15:32:45 -0700825 b.Module().base().commonProperties.DebugName = name
Colin Crossdc35e212019-06-06 16:13:11 -0700826}
827
Colin Cross4f1dcb02020-09-16 18:45:04 -0700828func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module {
829 return b.bp.AddDependency(module, tag, name...)
Colin Crossdc35e212019-06-06 16:13:11 -0700830}
831
832func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) {
833 b.bp.AddReverseDependency(module, tag, name)
834}
835
Colin Cross43b92e02019-11-18 15:28:57 -0800836func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000837 if b.finalPhase {
838 panic("CreateVariations not allowed in FinalDepsMutators")
839 }
840
Colin Cross9a362232019-07-01 15:32:45 -0700841 modules := b.bp.CreateVariations(variations...)
842
Colin Cross43b92e02019-11-18 15:28:57 -0800843 aModules := make([]Module, len(modules))
Colin Cross9a362232019-07-01 15:32:45 -0700844 for i := range variations {
Colin Cross43b92e02019-11-18 15:28:57 -0800845 aModules[i] = modules[i].(Module)
846 base := aModules[i].base()
Colin Cross9a362232019-07-01 15:32:45 -0700847 base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
848 base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
849 }
850
Colin Cross43b92e02019-11-18 15:28:57 -0800851 return aModules
Colin Crossdc35e212019-06-06 16:13:11 -0700852}
853
Colin Cross43b92e02019-11-18 15:28:57 -0800854func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000855 if b.finalPhase {
856 panic("CreateLocalVariations not allowed in FinalDepsMutators")
857 }
858
Colin Cross9a362232019-07-01 15:32:45 -0700859 modules := b.bp.CreateLocalVariations(variations...)
860
Colin Cross43b92e02019-11-18 15:28:57 -0800861 aModules := make([]Module, len(modules))
Colin Cross9a362232019-07-01 15:32:45 -0700862 for i := range variations {
Colin Cross43b92e02019-11-18 15:28:57 -0800863 aModules[i] = modules[i].(Module)
864 base := aModules[i].base()
Colin Cross9a362232019-07-01 15:32:45 -0700865 base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
866 base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
867 }
868
Colin Cross43b92e02019-11-18 15:28:57 -0800869 return aModules
Colin Crossdc35e212019-06-06 16:13:11 -0700870}
871
872func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
873 b.bp.SetDependencyVariation(variation)
874}
875
Jiyong Park1d1119f2019-07-29 21:27:18 +0900876func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) {
877 b.bp.SetDefaultDependencyVariation(variation)
878}
879
Colin Crossdc35e212019-06-06 16:13:11 -0700880func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700881 names ...string) []blueprint.Module {
Colin Cross4f1dcb02020-09-16 18:45:04 -0700882 return b.bp.AddVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700883}
884
885func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700886 tag blueprint.DependencyTag, names ...string) []blueprint.Module {
Colin Crossdc35e212019-06-06 16:13:11 -0700887
Colin Cross4f1dcb02020-09-16 18:45:04 -0700888 return b.bp.AddFarVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700889}
890
891func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) {
892 b.bp.AddInterVariantDependency(tag, from, to)
893}
894
895func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
896 b.bp.ReplaceDependencies(name)
897}
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800898
Paul Duffin80342d72020-06-26 22:08:43 +0100899func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) {
900 b.bp.ReplaceDependenciesIf(name, predicate)
901}
902
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800903func (b *bottomUpMutatorContext) AliasVariation(variationName string) {
904 b.bp.AliasVariation(variationName)
905}
Colin Cross1b9604b2020-08-11 12:03:56 -0700906
907func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) {
908 b.bp.CreateAliasVariation(fromVariationName, toVariationName)
909}
Colin Crossd27e7b82020-07-02 11:38:17 -0700910
911func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) {
912 b.bp.SetVariationProvider(module, provider, value)
913}