blob: 7a104772ffb46de6e435d238afedf96f78db16ad [file] [log] [blame]
Colin Cross6362e272015-10-29 15:25:03 -07001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Colin Cross635c3b02016-05-18 15:37:25 -070015package android
Colin Cross6362e272015-10-29 15:25:03 -070016
Colin Cross795c3772017-03-16 16:50:10 -070017import (
Colin Cross18c46802019-09-24 22:19:02 -070018 "reflect"
19
Colin Cross795c3772017-03-16 16:50:10 -070020 "github.com/google/blueprint"
Colin Cross519917d2017-11-02 16:35:56 -070021 "github.com/google/blueprint/proptools"
Colin Cross795c3772017-03-16 16:50:10 -070022)
Colin Cross6362e272015-10-29 15:25:03 -070023
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070024// Phases:
25// run Pre-arch mutators
26// run archMutator
27// run Pre-deps mutators
28// run depsMutator
29// run PostDeps mutators
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000030// run FinalDeps mutators (CreateVariations disallowed in this phase)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -070031// continue on to GenerateAndroidBuildActions
Colin Cross1e676be2016-10-12 14:38:15 -070032
Colin Cross795c3772017-03-16 16:50:10 -070033func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
34 for _, t := range mutators {
35 var handle blueprint.MutatorHandle
36 if t.bottomUpMutator != nil {
37 handle = ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator)
38 } else if t.topDownMutator != nil {
39 handle = ctx.RegisterTopDownMutator(t.name, t.topDownMutator)
40 }
41 if t.parallel {
42 handle.Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070043 }
44 }
Colin Cross1e676be2016-10-12 14:38:15 -070045}
46
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000047func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps, finalDeps []RegisterMutatorFunc) {
Colin Crosscec81712017-07-13 14:43:27 -070048 mctx := &registerMutatorsContext{}
Nan Zhangdb0b9a32017-02-27 10:12:13 -080049
50 register := func(funcs []RegisterMutatorFunc) {
51 for _, f := range funcs {
Colin Crosscec81712017-07-13 14:43:27 -070052 f(mctx)
Nan Zhangdb0b9a32017-02-27 10:12:13 -080053 }
54 }
55
Colin Crosscec81712017-07-13 14:43:27 -070056 register(preArch)
Nan Zhangdb0b9a32017-02-27 10:12:13 -080057
Colin Crosscec81712017-07-13 14:43:27 -070058 register(preDeps)
59
60 mctx.BottomUp("deps", depsMutator).Parallel()
61
62 register(postDeps)
63
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000064 mctx.finalPhase = true
65 register(finalDeps)
66
Colin Crosscec81712017-07-13 14:43:27 -070067 registerMutatorsToContext(ctx, mctx.mutators)
Colin Cross795c3772017-03-16 16:50:10 -070068}
69
70type registerMutatorsContext struct {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +000071 mutators []*mutator
72 finalPhase bool
Colin Cross795c3772017-03-16 16:50:10 -070073}
Colin Cross1e676be2016-10-12 14:38:15 -070074
75type RegisterMutatorsContext interface {
Colin Cross25de6c32019-06-06 14:29:25 -070076 TopDown(name string, m TopDownMutator) MutatorHandle
77 BottomUp(name string, m BottomUpMutator) MutatorHandle
Colin Cross617b88a2020-08-24 18:04:09 -070078 BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle
Colin Cross1e676be2016-10-12 14:38:15 -070079}
80
81type RegisterMutatorFunc func(RegisterMutatorsContext)
82
Colin Crosscec81712017-07-13 14:43:27 -070083var preArch = []RegisterMutatorFunc{
Dan Willemsen6e72ef72018-01-26 18:27:02 -080084 RegisterNamespaceMutator,
Paul Duffinaa4162e2020-05-05 11:35:43 +010085
Paul Duffinaa4162e2020-05-05 11:35:43 +010086 // Check the visibility rules are valid.
87 //
88 // This must run after the package renamer mutators so that any issues found during
89 // validation of the package's default_visibility property are reported using the
90 // correct package name and not the synthetic name.
91 //
92 // This must also be run before defaults mutators as the rules for validation are
93 // different before checking the rules than they are afterwards. e.g.
94 // visibility: ["//visibility:private", "//visibility:public"]
95 // would be invalid if specified in a module definition but is valid if it results
96 // from something like this:
97 //
98 // defaults {
99 // name: "defaults",
100 // // Be inaccessible outside a package by default.
101 // visibility: ["//visibility:private"]
102 // }
103 //
104 // defaultable_module {
105 // name: "defaultable_module",
106 // defaults: ["defaults"],
107 // // Override the default.
108 // visibility: ["//visibility:public"]
109 // }
110 //
Paul Duffin593b3c92019-12-05 14:31:48 +0000111 RegisterVisibilityRuleChecker,
Paul Duffinaa4162e2020-05-05 11:35:43 +0100112
113 // Apply properties from defaults modules to the referencing modules.
Paul Duffinafa9fa12020-04-29 16:47:28 +0100114 //
115 // Any mutators that are added before this will not see any modules created by
116 // a DefaultableHook.
Colin Cross89536d42017-07-07 14:35:50 -0700117 RegisterDefaultsPreArchMutators,
Paul Duffinaa4162e2020-05-05 11:35:43 +0100118
Paul Duffin44f1d842020-06-26 20:17:02 +0100119 // Add dependencies on any components so that any component references can be
120 // resolved within the deps mutator.
121 //
122 // Must be run after defaults so it can be used to create dependencies on the
123 // component modules that are creating in a DefaultableHook.
124 //
125 // Must be run before RegisterPrebuiltsPreArchMutators, i.e. before prebuilts are
126 // renamed. That is so that if a module creates components using a prebuilt module
127 // type that any dependencies (which must use prebuilt_ prefixes) are resolved to
128 // the prebuilt module and not the source module.
129 RegisterComponentsMutator,
130
Paul Duffinc988c8e2020-04-29 18:27:14 +0100131 // Create an association between prebuilt modules and their corresponding source
132 // modules (if any).
Paul Duffinafa9fa12020-04-29 16:47:28 +0100133 //
134 // Must be run after defaults mutators to ensure that any modules created by
135 // a DefaultableHook can be either a prebuilt or a source module with a matching
136 // prebuilt.
Paul Duffinc988c8e2020-04-29 18:27:14 +0100137 RegisterPrebuiltsPreArchMutators,
138
Paul Duffinaa4162e2020-05-05 11:35:43 +0100139 // Gather the visibility rules for all modules for us during visibility enforcement.
140 //
141 // This must come after the defaults mutators to ensure that any visibility supplied
142 // in a defaults module has been successfully applied before the rules are gathered.
Paul Duffin593b3c92019-12-05 14:31:48 +0000143 RegisterVisibilityRuleGatherer,
Colin Crosscec81712017-07-13 14:43:27 -0700144}
145
Colin Crossae4c6182017-09-15 17:33:55 -0700146func registerArchMutator(ctx RegisterMutatorsContext) {
Colin Cross617b88a2020-08-24 18:04:09 -0700147 ctx.BottomUpBlueprint("os", osMutator).Parallel()
Colin Crossfb0c16e2019-11-20 17:12:35 -0800148 ctx.BottomUp("image", imageMutator).Parallel()
Colin Cross617b88a2020-08-24 18:04:09 -0700149 ctx.BottomUpBlueprint("arch", archMutator).Parallel()
Colin Crossae4c6182017-09-15 17:33:55 -0700150}
151
Colin Crosscec81712017-07-13 14:43:27 -0700152var preDeps = []RegisterMutatorFunc{
Colin Crossae4c6182017-09-15 17:33:55 -0700153 registerArchMutator,
Colin Crosscec81712017-07-13 14:43:27 -0700154}
155
156var postDeps = []RegisterMutatorFunc{
Colin Cross1b488422019-03-04 22:33:56 -0800157 registerPathDepsMutator,
Colin Cross5ea9bcc2017-07-27 15:41:32 -0700158 RegisterPrebuiltsPostDepsMutators,
Paul Duffin593b3c92019-12-05 14:31:48 +0000159 RegisterVisibilityRuleEnforcer,
Artur Satayevc5570ac2020-04-09 16:06:36 +0100160 RegisterNeverallowMutator,
Jaewoong Jungb639a6a2019-05-10 15:16:29 -0700161 RegisterOverridePostDepsMutators,
Colin Crosscec81712017-07-13 14:43:27 -0700162}
Colin Cross1e676be2016-10-12 14:38:15 -0700163
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000164var finalDeps = []RegisterMutatorFunc{}
165
Colin Cross1e676be2016-10-12 14:38:15 -0700166func PreArchMutators(f RegisterMutatorFunc) {
167 preArch = append(preArch, f)
168}
169
170func PreDepsMutators(f RegisterMutatorFunc) {
171 preDeps = append(preDeps, f)
172}
173
174func PostDepsMutators(f RegisterMutatorFunc) {
175 postDeps = append(postDeps, f)
176}
177
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000178func FinalDepsMutators(f RegisterMutatorFunc) {
179 finalDeps = append(finalDeps, f)
180}
181
Colin Cross9f35c3d2020-09-16 19:04:41 -0700182type BaseMutatorContext interface {
183 BaseModuleContext
184
185 // MutatorName returns the name that this mutator was registered with.
186 MutatorName() string
187
188 // Rename all variants of a module. The new name is not visible to calls to ModuleName,
189 // AddDependency or OtherModuleName until after this mutator pass is complete.
190 Rename(name string)
191}
192
Colin Cross25de6c32019-06-06 14:29:25 -0700193type TopDownMutator func(TopDownMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -0700194
Colin Cross635c3b02016-05-18 15:37:25 -0700195type TopDownMutatorContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -0700196 BaseMutatorContext
Colin Cross3f68a132017-10-23 17:10:29 -0700197
Colin Cross9f35c3d2020-09-16 19:04:41 -0700198 // CreateModule creates a new module by calling the factory method for the specified moduleType, and applies
199 // the specified property structs to it as if the properties were set in a blueprint file.
Colin Crosse003c4a2019-09-25 12:58:36 -0700200 CreateModule(ModuleFactory, ...interface{}) Module
Colin Cross6362e272015-10-29 15:25:03 -0700201}
202
Colin Cross25de6c32019-06-06 14:29:25 -0700203type topDownMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700204 bp blueprint.TopDownMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700205 baseModuleContext
Colin Cross6362e272015-10-29 15:25:03 -0700206}
207
Colin Cross25de6c32019-06-06 14:29:25 -0700208type BottomUpMutator func(BottomUpMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -0700209
Colin Cross635c3b02016-05-18 15:37:25 -0700210type BottomUpMutatorContext interface {
Colin Cross9f35c3d2020-09-16 19:04:41 -0700211 BaseMutatorContext
Colin Crossaabf6792017-11-29 00:27:14 -0800212
Colin Cross4f1dcb02020-09-16 18:45:04 -0700213 // AddDependency adds a dependency to the given module. It returns a slice of modules for each
214 // dependency (some entries may be nil).
215 //
216 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
217 // new dependencies have had the current mutator called on them. If the mutator is not
218 // parallel this method does not affect the ordering of the current mutator pass, but will
219 // be ordered correctly for all future mutator passes.
220 AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700221
222 // AddReverseDependency adds a dependency from the destination to the given module.
223 // Does not affect the ordering of the current mutator pass, but will be ordered
224 // correctly for all future mutator passes. All reverse dependencies for a destination module are
225 // collected until the end of the mutator pass, sorted by name, and then appended to the destination
226 // module's dependency list.
Colin Crossaabf6792017-11-29 00:27:14 -0800227 AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700228
229 // CreateVariations splits a module into multiple variants, one for each name in the variationNames
230 // parameter. It returns a list of new modules in the same order as the variationNames
231 // list.
232 //
233 // If any of the dependencies of the module being operated on were already split
234 // by calling CreateVariations with the same name, the dependency will automatically
235 // be updated to point the matching variant.
236 //
237 // If a module is split, and then a module depending on the first module is not split
238 // when the Mutator is later called on it, the dependency of the depending module will
239 // automatically be updated to point to the first variant.
Colin Cross43b92e02019-11-18 15:28:57 -0800240 CreateVariations(...string) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700241
242 // CreateLocationVariations splits a module into multiple variants, one for each name in the variantNames
243 // parameter. It returns a list of new modules in the same order as the variantNames
244 // list.
245 //
246 // Local variations do not affect automatic dependency resolution - dependencies added
247 // to the split module via deps or DynamicDependerModule must exactly match a variant
248 // that contains all the non-local variations.
Colin Cross43b92e02019-11-18 15:28:57 -0800249 CreateLocalVariations(...string) []Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700250
251 // SetDependencyVariation sets all dangling dependencies on the current module to point to the variation
252 // with given name. This function ignores the default variation set by SetDefaultDependencyVariation.
Colin Crossaabf6792017-11-29 00:27:14 -0800253 SetDependencyVariation(string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700254
255 // SetDefaultDependencyVariation sets the default variation when a dangling reference is detected
256 // during the subsequent calls on Create*Variations* functions. To reset, set it to nil.
Jiyong Park1d1119f2019-07-29 21:27:18 +0900257 SetDefaultDependencyVariation(*string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700258
259 // AddVariationDependencies adds deps as dependencies of the current module, but uses the variations
Colin Cross4f1dcb02020-09-16 18:45:04 -0700260 // argument to select which variant of the dependency to use. It returns a slice of modules for
261 // each dependency (some entries may be nil). A variant of the dependency must exist that matches
262 // the all of the non-local variations of the current module, plus the variations argument.
263 //
264 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
265 // new dependencies have had the current mutator called on them. If the mutator is not
266 // parallel this method does not affect the ordering of the current mutator pass, but will
267 // be ordered correctly for all future mutator passes.
268 AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700269
270 // AddFarVariationDependencies adds deps as dependencies of the current module, but uses the
Colin Cross4f1dcb02020-09-16 18:45:04 -0700271 // variations argument to select which variant of the dependency to use. It returns a slice of
272 // modules for each dependency (some entries may be nil). A variant of the dependency must
273 // exist that matches the variations argument, but may also have other variations.
Colin Cross9f35c3d2020-09-16 19:04:41 -0700274 // For any unspecified variation the first variant will be used.
275 //
276 // Unlike AddVariationDependencies, the variations of the current module are ignored - the
277 // dependency only needs to match the supplied variations.
Colin Cross4f1dcb02020-09-16 18:45:04 -0700278 //
279 // If the mutator is parallel (see MutatorHandle.Parallel), this method will pause until the
280 // new dependencies have had the current mutator called on them. If the mutator is not
281 // parallel this method does not affect the ordering of the current mutator pass, but will
282 // be ordered correctly for all future mutator passes.
283 AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string) []blueprint.Module
Colin Cross9f35c3d2020-09-16 19:04:41 -0700284
285 // AddInterVariantDependency adds a dependency between two variants of the same module. Variants are always
286 // ordered in the same orderas they were listed in CreateVariations, and AddInterVariantDependency does not change
287 // that ordering, but it associates a DependencyTag with the dependency and makes it visible to VisitDirectDeps,
288 // WalkDeps, etc.
Colin Crossaabf6792017-11-29 00:27:14 -0800289 AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700290
291 // ReplaceDependencies replaces all dependencies on the identical variant of the module with the
292 // specified name with the current variant of this module. Replacements don't take effect until
293 // after the mutator pass is finished.
Colin Crossaabf6792017-11-29 00:27:14 -0800294 ReplaceDependencies(string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700295
296 // ReplaceDependencies replaces all dependencies on the identical variant of the module with the
297 // specified name with the current variant of this module as long as the supplied predicate returns
298 // true.
299 //
300 // Replacements don't take effect until after the mutator pass is finished.
Paul Duffin80342d72020-06-26 22:08:43 +0100301 ReplaceDependenciesIf(string, blueprint.ReplaceDependencyPredicate)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700302
303 // AliasVariation takes a variationName that was passed to CreateVariations for this module,
304 // and creates an alias from the current variant (before the mutator has run) to the new
305 // variant. The alias will be valid until the next time a mutator calls CreateVariations or
306 // CreateLocalVariations on this module without also calling AliasVariation. The alias can
307 // be used to add dependencies on the newly created variant using the variant map from
308 // before CreateVariations was run.
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800309 AliasVariation(variationName string)
Colin Cross9f35c3d2020-09-16 19:04:41 -0700310
311 // CreateAliasVariation takes a toVariationName that was passed to CreateVariations for this
312 // module, and creates an alias from a new fromVariationName variant the toVariationName
313 // variant. The alias will be valid until the next time a mutator calls CreateVariations or
314 // CreateLocalVariations on this module without also calling AliasVariation. The alias can
315 // be used to add dependencies on the toVariationName variant using the fromVariationName
316 // variant.
Colin Cross1b9604b2020-08-11 12:03:56 -0700317 CreateAliasVariation(fromVariationName, toVariationName string)
Colin Crossd27e7b82020-07-02 11:38:17 -0700318
319 // SetVariationProvider sets the value for a provider for the given newly created variant of
320 // the current module, i.e. one of the Modules returned by CreateVariations.. It panics if
321 // not called during the appropriate mutator or GenerateBuildActions pass for the provider,
322 // if the value is not of the appropriate type, or if the module is not a newly created
323 // variant of the current module. The value should not be modified after being passed to
324 // SetVariationProvider.
325 SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{})
Colin Cross6362e272015-10-29 15:25:03 -0700326}
327
Colin Cross25de6c32019-06-06 14:29:25 -0700328type bottomUpMutatorContext struct {
Colin Crossdc35e212019-06-06 16:13:11 -0700329 bp blueprint.BottomUpMutatorContext
Colin Cross0ea8ba82019-06-06 14:33:29 -0700330 baseModuleContext
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000331 finalPhase bool
Colin Cross6362e272015-10-29 15:25:03 -0700332}
333
Colin Cross617b88a2020-08-24 18:04:09 -0700334func bottomUpMutatorContextFactory(ctx blueprint.BottomUpMutatorContext, a Module,
335 finalPhase bool) BottomUpMutatorContext {
336
337 return &bottomUpMutatorContext{
338 bp: ctx,
339 baseModuleContext: a.base().baseModuleContextFactory(ctx),
340 finalPhase: finalPhase,
341 }
342}
343
Colin Cross25de6c32019-06-06 14:29:25 -0700344func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000345 finalPhase := x.finalPhase
Colin Cross798bfce2016-10-12 14:28:16 -0700346 f := func(ctx blueprint.BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700347 if a, ok := ctx.Module().(Module); ok {
Colin Cross617b88a2020-08-24 18:04:09 -0700348 m(bottomUpMutatorContextFactory(ctx, a, finalPhase))
Colin Cross6362e272015-10-29 15:25:03 -0700349 }
Colin Cross798bfce2016-10-12 14:28:16 -0700350 }
351 mutator := &mutator{name: name, bottomUpMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700352 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700353 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700354}
355
Colin Cross617b88a2020-08-24 18:04:09 -0700356func (x *registerMutatorsContext) BottomUpBlueprint(name string, m blueprint.BottomUpMutator) MutatorHandle {
357 mutator := &mutator{name: name, bottomUpMutator: m}
358 x.mutators = append(x.mutators, mutator)
359 return mutator
360}
361
Colin Cross25de6c32019-06-06 14:29:25 -0700362func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle {
Colin Cross798bfce2016-10-12 14:28:16 -0700363 f := func(ctx blueprint.TopDownMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700364 if a, ok := ctx.Module().(Module); ok {
Colin Cross25de6c32019-06-06 14:29:25 -0700365 actx := &topDownMutatorContext{
Colin Crossdc35e212019-06-06 16:13:11 -0700366 bp: ctx,
367 baseModuleContext: a.base().baseModuleContextFactory(ctx),
Colin Cross6362e272015-10-29 15:25:03 -0700368 }
Colin Cross798bfce2016-10-12 14:28:16 -0700369 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -0700370 }
Colin Cross798bfce2016-10-12 14:28:16 -0700371 }
372 mutator := &mutator{name: name, topDownMutator: f}
Colin Cross795c3772017-03-16 16:50:10 -0700373 x.mutators = append(x.mutators, mutator)
Colin Cross798bfce2016-10-12 14:28:16 -0700374 return mutator
375}
376
377type MutatorHandle interface {
378 Parallel() MutatorHandle
379}
380
381func (mutator *mutator) Parallel() MutatorHandle {
382 mutator.parallel = true
383 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700384}
Colin Cross1e676be2016-10-12 14:38:15 -0700385
Paul Duffin44f1d842020-06-26 20:17:02 +0100386func RegisterComponentsMutator(ctx RegisterMutatorsContext) {
387 ctx.BottomUp("component-deps", componentDepsMutator).Parallel()
388}
389
390// A special mutator that runs just prior to the deps mutator to allow the dependencies
391// on component modules to be added so that they can depend directly on a prebuilt
392// module.
393func componentDepsMutator(ctx BottomUpMutatorContext) {
394 if m := ctx.Module(); m.Enabled() {
395 m.ComponentDepsMutator(ctx)
396 }
397}
398
Colin Cross1e676be2016-10-12 14:38:15 -0700399func depsMutator(ctx BottomUpMutatorContext) {
Paul Duffin44f1d842020-06-26 20:17:02 +0100400 if m := ctx.Module(); m.Enabled() {
Colin Cross1e676be2016-10-12 14:38:15 -0700401 m.DepsMutator(ctx)
402 }
403}
Colin Crossd11fcda2017-10-23 17:59:01 -0700404
Colin Cross25de6c32019-06-06 14:29:25 -0700405func (t *topDownMutatorContext) AppendProperties(props ...interface{}) {
Colin Cross519917d2017-11-02 16:35:56 -0700406 for _, p := range props {
Colin Cross25de6c32019-06-06 14:29:25 -0700407 err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties,
Colin Cross519917d2017-11-02 16:35:56 -0700408 p, nil)
409 if err != nil {
410 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
Colin Cross25de6c32019-06-06 14:29:25 -0700411 t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
Colin Cross519917d2017-11-02 16:35:56 -0700412 } else {
413 panic(err)
414 }
415 }
416 }
417}
418
Colin Cross25de6c32019-06-06 14:29:25 -0700419func (t *topDownMutatorContext) PrependProperties(props ...interface{}) {
Colin Cross519917d2017-11-02 16:35:56 -0700420 for _, p := range props {
Colin Cross25de6c32019-06-06 14:29:25 -0700421 err := proptools.PrependMatchingProperties(t.Module().base().customizableProperties,
Colin Cross519917d2017-11-02 16:35:56 -0700422 p, nil)
423 if err != nil {
424 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
Colin Cross25de6c32019-06-06 14:29:25 -0700425 t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
Colin Cross519917d2017-11-02 16:35:56 -0700426 } else {
427 panic(err)
428 }
429 }
430 }
431}
Colin Crossdc35e212019-06-06 16:13:11 -0700432
433// android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that
434// has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid
435// ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every
436// non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following
437// methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext.
438
Colin Crosscb55e082019-07-01 15:32:31 -0700439func (t *topDownMutatorContext) MutatorName() string {
440 return t.bp.MutatorName()
441}
442
Colin Crossdc35e212019-06-06 16:13:11 -0700443func (t *topDownMutatorContext) Rename(name string) {
444 t.bp.Rename(name)
Colin Cross9a362232019-07-01 15:32:45 -0700445 t.Module().base().commonProperties.DebugName = name
Colin Crossdc35e212019-06-06 16:13:11 -0700446}
447
Colin Crosse003c4a2019-09-25 12:58:36 -0700448func (t *topDownMutatorContext) CreateModule(factory ModuleFactory, props ...interface{}) Module {
Colin Cross18c46802019-09-24 22:19:02 -0700449 inherited := []interface{}{&t.Module().base().commonProperties}
Colin Crosse003c4a2019-09-25 12:58:36 -0700450 module := t.bp.CreateModule(ModuleFactoryAdaptor(factory), append(inherited, props...)...).(Module)
Colin Cross18c46802019-09-24 22:19:02 -0700451
452 if t.Module().base().variableProperties != nil && module.base().variableProperties != nil {
453 src := t.Module().base().variableProperties
454 dst := []interface{}{
455 module.base().variableProperties,
456 // Put an empty copy of the src properties into dst so that properties in src that are not in dst
457 // don't cause a "failed to find property to extend" error.
Colin Cross43e789d2020-01-28 09:46:50 -0800458 proptools.CloneEmptyProperties(reflect.ValueOf(src)).Interface(),
Colin Cross18c46802019-09-24 22:19:02 -0700459 }
460 err := proptools.AppendMatchingProperties(dst, src, nil)
461 if err != nil {
462 panic(err)
463 }
464 }
465
Colin Crosse003c4a2019-09-25 12:58:36 -0700466 return module
Colin Crossdc35e212019-06-06 16:13:11 -0700467}
468
Colin Crosscb55e082019-07-01 15:32:31 -0700469func (b *bottomUpMutatorContext) MutatorName() string {
470 return b.bp.MutatorName()
471}
472
Colin Crossdc35e212019-06-06 16:13:11 -0700473func (b *bottomUpMutatorContext) Rename(name string) {
474 b.bp.Rename(name)
Colin Cross9a362232019-07-01 15:32:45 -0700475 b.Module().base().commonProperties.DebugName = name
Colin Crossdc35e212019-06-06 16:13:11 -0700476}
477
Colin Cross4f1dcb02020-09-16 18:45:04 -0700478func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) []blueprint.Module {
479 return b.bp.AddDependency(module, tag, name...)
Colin Crossdc35e212019-06-06 16:13:11 -0700480}
481
482func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) {
483 b.bp.AddReverseDependency(module, tag, name)
484}
485
Colin Cross43b92e02019-11-18 15:28:57 -0800486func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []Module {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000487 if b.finalPhase {
488 panic("CreateVariations not allowed in FinalDepsMutators")
489 }
490
Colin Cross9a362232019-07-01 15:32:45 -0700491 modules := b.bp.CreateVariations(variations...)
492
Colin Cross43b92e02019-11-18 15:28:57 -0800493 aModules := make([]Module, len(modules))
Colin Cross9a362232019-07-01 15:32:45 -0700494 for i := range variations {
Colin Cross43b92e02019-11-18 15:28:57 -0800495 aModules[i] = modules[i].(Module)
496 base := aModules[i].base()
Colin Cross9a362232019-07-01 15:32:45 -0700497 base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
498 base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
499 }
500
Colin Cross43b92e02019-11-18 15:28:57 -0800501 return aModules
Colin Crossdc35e212019-06-06 16:13:11 -0700502}
503
Colin Cross43b92e02019-11-18 15:28:57 -0800504func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []Module {
Martin Stjernholm710ec3a2020-01-16 15:12:04 +0000505 if b.finalPhase {
506 panic("CreateLocalVariations not allowed in FinalDepsMutators")
507 }
508
Colin Cross9a362232019-07-01 15:32:45 -0700509 modules := b.bp.CreateLocalVariations(variations...)
510
Colin Cross43b92e02019-11-18 15:28:57 -0800511 aModules := make([]Module, len(modules))
Colin Cross9a362232019-07-01 15:32:45 -0700512 for i := range variations {
Colin Cross43b92e02019-11-18 15:28:57 -0800513 aModules[i] = modules[i].(Module)
514 base := aModules[i].base()
Colin Cross9a362232019-07-01 15:32:45 -0700515 base.commonProperties.DebugMutators = append(base.commonProperties.DebugMutators, b.MutatorName())
516 base.commonProperties.DebugVariations = append(base.commonProperties.DebugVariations, variations[i])
517 }
518
Colin Cross43b92e02019-11-18 15:28:57 -0800519 return aModules
Colin Crossdc35e212019-06-06 16:13:11 -0700520}
521
522func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
523 b.bp.SetDependencyVariation(variation)
524}
525
Jiyong Park1d1119f2019-07-29 21:27:18 +0900526func (b *bottomUpMutatorContext) SetDefaultDependencyVariation(variation *string) {
527 b.bp.SetDefaultDependencyVariation(variation)
528}
529
Colin Crossdc35e212019-06-06 16:13:11 -0700530func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700531 names ...string) []blueprint.Module {
Colin Crossdc35e212019-06-06 16:13:11 -0700532
Colin Cross4f1dcb02020-09-16 18:45:04 -0700533 return b.bp.AddVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700534}
535
536func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
Colin Cross4f1dcb02020-09-16 18:45:04 -0700537 tag blueprint.DependencyTag, names ...string) []blueprint.Module {
Colin Crossdc35e212019-06-06 16:13:11 -0700538
Colin Cross4f1dcb02020-09-16 18:45:04 -0700539 return b.bp.AddFarVariationDependencies(variations, tag, names...)
Colin Crossdc35e212019-06-06 16:13:11 -0700540}
541
542func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) {
543 b.bp.AddInterVariantDependency(tag, from, to)
544}
545
546func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
547 b.bp.ReplaceDependencies(name)
548}
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800549
Paul Duffin80342d72020-06-26 22:08:43 +0100550func (b *bottomUpMutatorContext) ReplaceDependenciesIf(name string, predicate blueprint.ReplaceDependencyPredicate) {
551 b.bp.ReplaceDependenciesIf(name, predicate)
552}
553
Jaewoong Jung9f88ce22019-11-15 10:57:34 -0800554func (b *bottomUpMutatorContext) AliasVariation(variationName string) {
555 b.bp.AliasVariation(variationName)
556}
Colin Cross1b9604b2020-08-11 12:03:56 -0700557
558func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) {
559 b.bp.CreateAliasVariation(fromVariationName, toVariationName)
560}
Colin Crossd27e7b82020-07-02 11:38:17 -0700561
562func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) {
563 b.bp.SetVariationProvider(module, provider, value)
564}