• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package android
16
17import (
18	"reflect"
19
20	"android/soong/bazel"
21
22	"github.com/google/blueprint"
23	"github.com/google/blueprint/proptools"
24)
25
26// Phases:
27//   run Pre-arch mutators
28//   run archMutator
29//   run Pre-deps mutators
30//   run depsMutator
31//   run PostDeps mutators
32//   run FinalDeps mutators (CreateVariations disallowed in this phase)
33//   continue on to GenerateAndroidBuildActions
34
35// RegisterMutatorsForBazelConversion is a alternate registration pipeline for bp2build. Exported for testing.
36func RegisterMutatorsForBazelConversion(ctx *Context, preArchMutators []RegisterMutatorFunc) {
37	mctx := &registerMutatorsContext{
38		bazelConversionMode: true,
39	}
40
41	bp2buildMutators := append([]RegisterMutatorFunc{
42		RegisterNamespaceMutator,
43		RegisterDefaultsPreArchMutators,
44		// TODO(b/165114590): this is required to resolve deps that are only prebuilts, but we should
45		// evaluate the impact on conversion.
46		RegisterPrebuiltsPreArchMutators,
47	},
48		preArchMutators...)
49	bp2buildMutators = append(bp2buildMutators, registerBp2buildConversionMutator)
50
51	// Register bp2build mutators
52	for _, f := range bp2buildMutators {
53		f(mctx)
54	}
55
56	mctx.mutators.registerAll(ctx)
57}
58
59// collateGloballyRegisteredMutators constructs the list of mutators that have been registered
60// with the InitRegistrationContext and will be used at runtime.
61func collateGloballyRegisteredMutators() sortableComponents {
62	return collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps)
63}
64
65// collateRegisteredMutators constructs a single list of mutators from the separate lists.
66func collateRegisteredMutators(preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) sortableComponents {
67	mctx := &registerMutatorsContext{}
68
69	register := func(funcs []RegisterMutatorFunc) {
70		for _, f := range funcs {
71			f(mctx)
72		}
73	}
74
75	register(preArch)
76
77	register(preDeps)
78
79	register([]RegisterMutatorFunc{registerDepsMutator})
80
81	register(postDeps)
82
83	mctx.finalPhase = true
84	register(finalDeps)
85
86	return mctx.mutators
87}
88
89type registerMutatorsContext struct {
90	mutators            sortableComponents
91	finalPhase          bool
92	bazelConversionMode bool
93}
94
95type RegisterMutatorsContext interface {
96	TopDown(name string, m TopDownMutator) MutatorHandle
97	BottomUp(name string, m BottomUpMutator) MutatorHandle
98	BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle
99}
100
101type RegisterMutatorFunc func(RegisterMutatorsContext)
102
103var preArch = []RegisterMutatorFunc{
104	RegisterNamespaceMutator,
105
106	// Check the visibility rules are valid.
107	//
108	// This must run after the package renamer mutators so that any issues found during
109	// validation of the package's default_visibility property are reported using the
110	// correct package name and not the synthetic name.
111	//
112	// This must also be run before defaults mutators as the rules for validation are
113	// different before checking the rules than they are afterwards. e.g.
114	//    visibility: ["//visibility:private", "//visibility:public"]
115	// would be invalid if specified in a module definition but is valid if it results
116	// from something like this:
117	//
118	//    defaults {
119	//        name: "defaults",
120	//        // Be inaccessible outside a package by default.
121	//        visibility: ["//visibility:private"]
122	//    }
123	//
124	//    defaultable_module {
125	//        name: "defaultable_module",
126	//        defaults: ["defaults"],
127	//        // Override the default.
128	//        visibility: ["//visibility:public"]
129	//    }
130	//
131	RegisterVisibilityRuleChecker,
132
133	// Record the default_applicable_licenses for each package.
134	//
135	// This must run before the defaults so that defaults modules can pick up the package default.
136	RegisterLicensesPackageMapper,
137
138	// Apply properties from defaults modules to the referencing modules.
139	//
140	// Any mutators that are added before this will not see any modules created by
141	// a DefaultableHook.
142	RegisterDefaultsPreArchMutators,
143
144	// Add dependencies on any components so that any component references can be
145	// resolved within the deps mutator.
146	//
147	// Must be run after defaults so it can be used to create dependencies on the
148	// component modules that are creating in a DefaultableHook.
149	//
150	// Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are
151	// renamed. That is so that if a module creates components using a prebuilt module
152	// type that any dependencies (which must use prebuilt_ prefixes) are resolved to
153	// the prebuilt module and not the source module.
154	RegisterComponentsMutator,
155
156	// Create an association between prebuilt modules and their corresponding source
157	// modules (if any).
158	//
159	// Must be run after defaults mutators to ensure that any modules created by
160	// a DefaultableHook can be either a prebuilt or a source module with a matching
161	// prebuilt.
162	RegisterPrebuiltsPreArchMutators,
163
164	// Gather the licenses properties for all modules for use during expansion and enforcement.
165	//
166	// This must come after the defaults mutators to ensure that any licenses supplied
167	// in a defaults module has been successfully applied before the rules are gathered.
168	RegisterLicensesPropertyGatherer,
169
170	// Gather the visibility rules for all modules for us during visibility enforcement.
171	//
172	// This must come after the defaults mutators to ensure that any visibility supplied
173	// in a defaults module has been successfully applied before the rules are gathered.
174	RegisterVisibilityRuleGatherer,
175}
176
177func registerArchMutator(ctx RegisterMutatorsContext) {
178	ctx.BottomUpBlueprint("os", osMutator).Parallel()
179	ctx.BottomUp("image", imageMutator).Parallel()
180	ctx.BottomUpBlueprint("arch", archMutator).Parallel()
181}
182
183var preDeps = []RegisterMutatorFunc{
184	registerArchMutator,
185}
186
187var postDeps = []RegisterMutatorFunc{
188	registerPathDepsMutator,
189	RegisterPrebuiltsPostDepsMutators,
190	RegisterVisibilityRuleEnforcer,
191	RegisterLicensesDependencyChecker,
192	registerNeverallowMutator,
193	RegisterOverridePostDepsMutators,
194}
195
196var finalDeps = []RegisterMutatorFunc{}
197
198func PreArchMutators(f RegisterMutatorFunc) {
199	preArch = append(preArch, f)
200}
201
202func PreDepsMutators(f RegisterMutatorFunc) {
203	preDeps = append(preDeps, f)
204}
205
206func PostDepsMutators(f RegisterMutatorFunc) {
207	postDeps = append(postDeps, f)
208}
209
210func FinalDepsMutators(f RegisterMutatorFunc) {
211	finalDeps = append(finalDeps, f)
212}
213
214var bp2buildPreArchMutators = []RegisterMutatorFunc{}
215
216// A minimal context for Bp2build conversion
217type Bp2buildMutatorContext interface {
218	BazelConversionPathContext
219
220	CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
221}
222
223// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
224// into Bazel BUILD targets that should run prior to deps and conversion.
225func PreArchBp2BuildMutators(f RegisterMutatorFunc) {
226	bp2buildPreArchMutators = append(bp2buildPreArchMutators, f)
227}
228
229type BaseMutatorContext interface {
230	BaseModuleContext
231
232	// MutatorName returns the name that this mutator was registered with.
233	MutatorName() string
234
235	// Rename all variants of a module.  The new name is not visible to calls to ModuleName,
236	// AddDependency or OtherModuleName until after this mutator pass is complete.
237	Rename(name string)
238
239	// BazelConversionMode returns whether this mutator is being run as part of Bazel Conversion.
240	BazelConversionMode() bool
241}
242
243type TopDownMutator func(TopDownMutatorContext)
244
245type TopDownMutatorContext interface {
246	BaseMutatorContext
247
248	// CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
249	// the specified property structs to it as if the properties were set in a blueprint file.
250	CreateModule(ModuleFactory, ...interface{}) Module
251
252	// CreateBazelTargetModule creates a BazelTargetModule by calling the
253	// factory method, just like in CreateModule, but also requires
254	// BazelTargetModuleProperties containing additional metadata for the
255	// bp2build codegenerator.
256	CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
257
258	// CreateBazelTargetModuleWithRestrictions 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. The generated target is restricted to only be buildable for certain
262	// platforms, as dictated by a given bool attribute: the target will not be buildable in
263	// any platform for which this bool attribute is false.
264	CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}, bazel.BoolAttribute)
265}
266
267type topDownMutatorContext struct {
268	bp blueprint.TopDownMutatorContext
269	baseModuleContext
270}
271
272type BottomUpMutator func(BottomUpMutatorContext)
273
274type BottomUpMutatorContext interface {
275	BaseMutatorContext
276
277	// AddDependency adds a dependency to the given module.  It returns a slice of modules for each
278	// dependency (some entries may be nil).
279	//
280	// If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
281	// new dependencies have had the current mutator called on them.  If the mutator is not
282	// parallel this method does not affect the ordering of the current mutator pass, but will
283	// be ordered correctly for all future mutator passes.
284	AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module
285
286	// AddReverseDependency adds a dependency from the destination to the given module.
287	// Does not affect the ordering of the current mutator pass, but will be ordered
288	// correctly for all future mutator passes.  All reverse dependencies for a destination module are
289	// collected until the end of the mutator pass, sorted by name, and then appended to the destination
290	// module's dependency list.
291	AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
292
293	// CreateVariations splits  a module into multiple variants, one for each name in the variationNames
294	// parameter.  It returns a list of new modules in the same order as the variationNames
295	// list.
296	//
297	// If any of the dependencies of the module being operated on were already split
298	// by calling CreateVariations with the same name, the dependency will automatically
299	// be updated to point the matching variant.
300	//
301	// If a module is split, and then a module depending on the first module is not split
302	// when the Mutator is later called on it, the dependency of the depending module will
303	// automatically be updated to point to the first variant.
304	CreateVariations(...string) []Module
305
306	// CreateLocationVariations splits a module into multiple variants, one for each name in the variantNames
307	// parameter.  It returns a list of new modules in the same order as the variantNames
308	// list.
309	//
310	// Local variations do not affect automatic dependency resolution - dependencies added
311	// to the split module via deps or DynamicDependerModule must exactly match a variant
312	// that contains all the non-local variations.
313	CreateLocalVariations(...string) []Module
314
315	// SetDependencyVariation sets all dangling dependencies on the current module to point to the variation
316	// with given name. This function ignores the default variation set by SetDefaultDependencyVariation.
317	SetDependencyVariation(string)
318
319	// SetDefaultDependencyVariation sets the default variation when a dangling reference is detected
320	// during the subsequent calls on Create*Variations* functions. To reset, set it to nil.
321	SetDefaultDependencyVariation(*string)
322
323	// AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
324	// argument to select which variant of the dependency to use.  It returns a slice of modules for
325	// each dependency (some entries may be nil).  A variant of the dependency must exist that matches
326	// all the non-local variations of the current module, plus the variations argument.
327	//
328	// If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
329	// new dependencies have had the current mutator called on them.  If the mutator is not
330	// parallel this method does not affect the ordering of the current mutator pass, but will
331	// be ordered correctly for all future mutator passes.
332	AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag, names ...string) []blueprint.Module
333
334	// AddFarVariationDependencies adds deps as dependencies of the current module, but uses the
335	// variations argument to select which variant of the dependency to use.  It returns a slice of
336	// modules for each dependency (some entries may be nil).  A variant of the dependency must
337	// exist that matches the variations argument, but may also have other variations.
338	// For any unspecified variation the first variant will be used.
339	//
340	// Unlike AddVariationDependencies, the variations of the current module are ignored - the
341	// dependency only needs to match the supplied variations.
342	//
343	// If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
344	// new dependencies have had the current mutator called on them.  If the mutator is not
345	// parallel this method does not affect the ordering of the current mutator pass, but will
346	// be ordered correctly for all future mutator passes.
347	AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module
348
349	// AddInterVariantDependency adds a dependency between two variants of the same module.  Variants are always
350	// ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change
351	// that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps,
352	// WalkDeps, etc.
353	AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
354
355	// ReplaceDependencies replaces all dependencies on the identical variant of the module with the
356	// specified name with the current variant of this module.  Replacements don't take effect until
357	// after the mutator pass is finished.
358	ReplaceDependencies(string)
359
360	// ReplaceDependencies replaces all dependencies on the identical variant of the module with the
361	// specified name with the current variant of this module as long as the supplied predicate returns
362	// true.
363	//
364	// Replacements don't take effect until after the mutator pass is finished.
365	ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate)
366
367	// AliasVariation takes a variationName that was passed to CreateVariations for this module,
368	// and creates an alias from the current variant (before the mutator has run) to the new
369	// variant.  The alias will be valid until the next time a mutator calls CreateVariations or
370	// CreateLocalVariations on this module without also calling AliasVariation.  The alias can
371	// be used to add dependencies on the newly created variant using the variant map from
372	// before CreateVariations was run.
373	AliasVariation(variationName string)
374
375	// CreateAliasVariation takes a toVariationName that was passed to CreateVariations for this
376	// module, and creates an alias from a new fromVariationName variant the toVariationName
377	// variant.  The alias will be valid until the next time a mutator calls CreateVariations or
378	// CreateLocalVariations on this module without also calling AliasVariation.  The alias can
379	// be used to add dependencies on the toVariationName variant using the fromVariationName
380	// variant.
381	CreateAliasVariation(fromVariationName, toVariationName string)
382
383	// SetVariationProvider sets the value for a provider for the given newly created variant of
384	// the current module, i.e. one of the Modules returned by CreateVariations..  It panics if
385	// not called during the appropriate mutator or GenerateBuildActions pass for the provider,
386	// if the value is not of the appropriate type, or if the module is not a newly created
387	// variant of the current module.  The value should not be modified after being passed to
388	// SetVariationProvider.
389	SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{})
390}
391
392type bottomUpMutatorContext struct {
393	bp blueprint.BottomUpMutatorContext
394	baseModuleContext
395	finalPhase bool
396}
397
398func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module,
399	finalPhase, bazelConversionMode bool) BottomUpMutatorContext {
400
401	moduleContext := a.base().baseModuleContextFactory(ctx)
402	moduleContext.bazelConversionMode = bazelConversionMode
403
404	return &bottomUpMutatorContext{
405		bp:                ctx,
406		baseModuleContext: a.base().baseModuleContextFactory(ctx),
407		finalPhase:        finalPhase,
408	}
409}
410
411func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle {
412	finalPhase := x.finalPhase
413	bazelConversionMode := x.bazelConversionMode
414	f := func(ctx blueprint.BottomUpMutatorContext) {
415		if a, ok := ctx.Module().(Module); ok {
416			m(bottomUpMutatorContextFactory(ctx, a, finalPhase, bazelConversionMode))
417		}
418	}
419	mutator := &mutator{name: x.mutatorName(name), bottomUpMutator: f}
420	x.mutators = append(x.mutators, mutator)
421	return mutator
422}
423
424func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle {
425	mutator := &mutator{name: name, bottomUpMutator: m}
426	x.mutators = append(x.mutators, mutator)
427	return mutator
428}
429
430func (x *registerMutatorsContext) mutatorName(name string) string {
431	if x.bazelConversionMode {
432		return name + "_bp2build"
433	}
434	return name
435}
436
437func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle {
438	f := func(ctx blueprint.TopDownMutatorContext) {
439		if a, ok := ctx.Module().(Module); ok {
440			moduleContext := a.base().baseModuleContextFactory(ctx)
441			moduleContext.bazelConversionMode = x.bazelConversionMode
442			actx := &topDownMutatorContext{
443				bp:                ctx,
444				baseModuleContext: moduleContext,
445			}
446			m(actx)
447		}
448	}
449	mutator := &mutator{name: x.mutatorName(name), topDownMutator: f}
450	x.mutators = append(x.mutators, mutator)
451	return mutator
452}
453
454func (mutator *mutator) componentName() string {
455	return mutator.name
456}
457
458func (mutator *mutator) register(ctx *Context) {
459	blueprintCtx := ctx.Context
460	var handle blueprint.MutatorHandle
461	if mutator.bottomUpMutator != nil {
462		handle = blueprintCtx.RegisterBottomUpMutator(mutator.name, mutator.bottomUpMutator)
463	} else if mutator.topDownMutator != nil {
464		handle = blueprintCtx.RegisterTopDownMutator(mutator.name, mutator.topDownMutator)
465	}
466	if mutator.parallel {
467		handle.Parallel()
468	}
469}
470
471type MutatorHandle interface {
472	Parallel() MutatorHandle
473}
474
475func (mutator *mutator) Parallel() MutatorHandle {
476	mutator.parallel = true
477	return mutator
478}
479
480func RegisterComponentsMutator(ctx RegisterMutatorsContext) {
481	ctx.BottomUp("component-deps", componentDepsMutator).Parallel()
482}
483
484// A special mutator that runs just prior to the deps mutator to allow the dependencies
485// on component modules to be added so that they can depend directly on a prebuilt
486// module.
487func componentDepsMutator(ctx BottomUpMutatorContext) {
488	if m := ctx.Module(); m.Enabled() {
489		m.ComponentDepsMutator(ctx)
490	}
491}
492
493func depsMutator(ctx BottomUpMutatorContext) {
494	if m := ctx.Module(); m.Enabled() {
495		m.DepsMutator(ctx)
496	}
497}
498
499func registerDepsMutator(ctx RegisterMutatorsContext) {
500	ctx.BottomUp("deps", depsMutator).Parallel()
501}
502
503func registerDepsMutatorBp2Build(ctx RegisterMutatorsContext) {
504	// TODO(b/179313531): Consider a separate mutator that only runs depsMutator for modules that are
505	// being converted to build targets.
506	ctx.BottomUp("deps", depsMutator).Parallel()
507}
508
509func (t *topDownMutatorContext) CreateBazelTargetModule(
510	bazelProps bazel.BazelTargetModuleProperties,
511	commonAttrs CommonAttributes,
512	attrs interface{}) {
513	t.createBazelTargetModule(bazelProps, commonAttrs, attrs, bazel.BoolAttribute{})
514}
515
516func (t *topDownMutatorContext) CreateBazelTargetModuleWithRestrictions(
517	bazelProps bazel.BazelTargetModuleProperties,
518	commonAttrs CommonAttributes,
519	attrs interface{},
520	enabledProperty bazel.BoolAttribute) {
521	t.createBazelTargetModule(bazelProps, commonAttrs, attrs, enabledProperty)
522}
523
524func (t *topDownMutatorContext) createBazelTargetModule(
525	bazelProps bazel.BazelTargetModuleProperties,
526	commonAttrs CommonAttributes,
527	attrs interface{},
528	enabledProperty bazel.BoolAttribute) {
529	constraintAttributes := commonAttrs.fillCommonBp2BuildModuleAttrs(t, enabledProperty)
530	mod := t.Module()
531	info := bp2buildInfo{
532		Dir:             t.OtherModuleDir(mod),
533		BazelProps:      bazelProps,
534		CommonAttrs:     commonAttrs,
535		ConstraintAttrs: constraintAttributes,
536		Attrs:           attrs,
537	}
538	mod.base().addBp2buildInfo(info)
539}
540
541// android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that
542// has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid
543// ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every
544// non-overridden method has to be forwarded.  There are fewer non-overridden methods, so use the latter.  The following
545// methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext.
546
547func (t *topDownMutatorContext) MutatorName() string {
548	return t.bp.MutatorName()
549}
550
551func (t *topDownMutatorContext) Rename(name string) {
552	t.bp.Rename(name)
553	t.Module().base().commonProperties.DebugName = name
554}
555
556func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
557	inherited := []interface{}{&t.Module().base().commonProperties}
558	module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...).(Module)
559
560	if t.Module().base().variableProperties != nil && module.base().variableProperties != nil {
561		src := t.Module().base().variableProperties
562		dst := []interface{}{
563			module.base().variableProperties,
564			// Put an empty copy of the src properties into dst so that properties in src that are not in dst
565			// don't cause a "failed to find property to extend" error.
566			proptools.CloneEmptyProperties(reflect.ValueOf(src)).Interface(),
567		}
568		err := proptools.AppendMatchingProperties(dst, src, nil)
569		if err != nil {
570			panic(err)
571		}
572	}
573
574	return module
575}
576
577func (t *topDownMutatorContext) createModuleWithoutInheritance(factory ModuleFactory, props ...interface{}) Module {
578	module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), props...).(Module)
579	return module
580}
581
582func (b *bottomUpMutatorContext) MutatorName() string {
583	return b.bp.MutatorName()
584}
585
586func (b *bottomUpMutatorContext) Rename(name string) {
587	b.bp.Rename(name)
588	b.Module().base().commonProperties.DebugName = name
589}
590
591func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module {
592	return b.bp.AddDependency(module, tag, name...)
593}
594
595func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) {
596	b.bp.AddReverseDependency(module, tag, name)
597}
598
599func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module {
600	if b.finalPhase {
601		panic("CreateVariations not allowed in FinalDepsMutators")
602	}
603
604	modules := b.bp.CreateVariations(variations...)
605
606	aModules := make([]Module, len(modules))
607	for i := range variations {
608		aModules[i] = modules[i].(Module)
609		base := aModules[i].base()
610		base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
611		base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
612	}
613
614	return aModules
615}
616
617func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module {
618	if b.finalPhase {
619		panic("CreateLocalVariations not allowed in FinalDepsMutators")
620	}
621
622	modules := b.bp.CreateLocalVariations(variations...)
623
624	aModules := make([]Module, len(modules))
625	for i := range variations {
626		aModules[i] = modules[i].(Module)
627		base := aModules[i].base()
628		base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
629		base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
630	}
631
632	return aModules
633}
634
635func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
636	b.bp.SetDependencyVariation(variation)
637}
638
639func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) {
640	b.bp.SetDefaultDependencyVariation(variation)
641}
642
643func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
644	names ...string) []blueprint.Module {
645	if b.bazelConversionMode {
646		_, noSelfDeps := RemoveFromList(b.ModuleName(), names)
647		if len(noSelfDeps) == 0 {
648			return []blueprint.Module(nil)
649		}
650		// In Bazel conversion mode, mutators should not have created any variants. So, when adding a
651		// dependency, the variations would not exist and the dependency could not be added, by
652		// specifying no variations, we will allow adding the dependency to succeed.
653		return b.bp.AddFarVariationDependencies(nil, tag, noSelfDeps...)
654	}
655
656	return b.bp.AddVariationDependencies(variations, tag, names...)
657}
658
659func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
660	tag blueprint.DependencyTag, names ...string) []blueprint.Module {
661	if b.bazelConversionMode {
662		// In Bazel conversion mode, mutators should not have created any variants. So, when adding a
663		// dependency, the variations would not exist and the dependency could not be added, by
664		// specifying no variations, we will allow adding the dependency to succeed.
665		return b.bp.AddFarVariationDependencies(nil, tag, names...)
666	}
667
668	return b.bp.AddFarVariationDependencies(variations, tag, names...)
669}
670
671func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) {
672	b.bp.AddInterVariantDependency(tag, from, to)
673}
674
675func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
676	b.bp.ReplaceDependencies(name)
677}
678
679func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) {
680	b.bp.ReplaceDependenciesIf(name, predicate)
681}
682
683func (b *bottomUpMutatorContext) AliasVariation(variationName string) {
684	b.bp.AliasVariation(variationName)
685}
686
687func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) {
688	b.bp.CreateAliasVariation(fromVariationName, toVariationName)
689}
690
691func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) {
692	b.bp.SetVariationProvider(module, provider, value)
693}
694