2015-10-29 23:25:03 +01:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
package android
|
2015-10-29 23:25:03 +01:00
|
|
|
|
2017-03-17 00:50:10 +01:00
|
|
|
import (
|
|
|
|
"github.com/google/blueprint"
|
2017-11-03 00:35:56 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
2017-03-17 00:50:10 +01:00
|
|
|
)
|
2015-10-29 23:25:03 +01:00
|
|
|
|
2017-09-28 02:01:44 +02:00
|
|
|
// Phases:
|
|
|
|
// run Pre-arch mutators
|
|
|
|
// run archMutator
|
|
|
|
// run Pre-deps mutators
|
|
|
|
// run depsMutator
|
|
|
|
// run PostDeps mutators
|
|
|
|
// continue on to GenerateAndroidBuildActions
|
2016-10-12 23:38:15 +02:00
|
|
|
|
2017-03-17 00:50:10 +01:00
|
|
|
func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
|
|
|
|
for _, t := range mutators {
|
|
|
|
var handle blueprint.MutatorHandle
|
|
|
|
if t.bottomUpMutator != nil {
|
|
|
|
handle = ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator)
|
|
|
|
} else if t.topDownMutator != nil {
|
|
|
|
handle = ctx.RegisterTopDownMutator(t.name, t.topDownMutator)
|
|
|
|
}
|
|
|
|
if t.parallel {
|
|
|
|
handle.Parallel()
|
2016-10-12 23:38:15 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-17 00:50:10 +01:00
|
|
|
}
|
|
|
|
|
2017-07-13 23:43:27 +02:00
|
|
|
func registerMutators(ctx *blueprint.Context, preArch, preDeps, postDeps []RegisterMutatorFunc) {
|
|
|
|
mctx := ®isterMutatorsContext{}
|
2017-02-27 19:12:13 +01:00
|
|
|
|
|
|
|
register := func(funcs []RegisterMutatorFunc) {
|
|
|
|
for _, f := range funcs {
|
2017-07-13 23:43:27 +02:00
|
|
|
f(mctx)
|
2017-02-27 19:12:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 23:43:27 +02:00
|
|
|
register(preArch)
|
|
|
|
|
|
|
|
register(preDeps)
|
|
|
|
|
|
|
|
mctx.BottomUp("deps", depsMutator).Parallel()
|
|
|
|
|
|
|
|
register(postDeps)
|
2017-02-27 19:12:13 +01:00
|
|
|
|
2017-07-13 23:43:27 +02:00
|
|
|
registerMutatorsToContext(ctx, mctx.mutators)
|
2017-03-17 00:50:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type registerMutatorsContext struct {
|
|
|
|
mutators []*mutator
|
|
|
|
}
|
2016-10-12 23:38:15 +02:00
|
|
|
|
|
|
|
type RegisterMutatorsContext interface {
|
2019-06-06 23:29:25 +02:00
|
|
|
TopDown(name string, m TopDownMutator) MutatorHandle
|
|
|
|
BottomUp(name string, m BottomUpMutator) MutatorHandle
|
2016-10-12 23:38:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type RegisterMutatorFunc func(RegisterMutatorsContext)
|
|
|
|
|
2017-07-13 23:43:27 +02:00
|
|
|
var preArch = []RegisterMutatorFunc{
|
2019-04-16 23:43:28 +02:00
|
|
|
registerLoadHookMutator,
|
2018-01-27 03:27:02 +01:00
|
|
|
RegisterNamespaceMutator,
|
2019-05-31 15:00:04 +02:00
|
|
|
// Rename package module types.
|
|
|
|
registerPackageRenamer,
|
2017-07-28 00:41:32 +02:00
|
|
|
RegisterPrebuiltsPreArchMutators,
|
2019-05-17 23:42:02 +02:00
|
|
|
registerVisibilityRuleChecker,
|
2017-07-07 23:35:50 +02:00
|
|
|
RegisterDefaultsPreArchMutators,
|
2019-03-28 15:10:57 +01:00
|
|
|
registerVisibilityRuleGatherer,
|
2017-07-13 23:43:27 +02:00
|
|
|
}
|
|
|
|
|
2017-09-16 02:33:55 +02:00
|
|
|
func registerArchMutator(ctx RegisterMutatorsContext) {
|
|
|
|
ctx.BottomUp("arch", archMutator).Parallel()
|
|
|
|
ctx.TopDown("arch_hooks", archHookMutator).Parallel()
|
|
|
|
}
|
|
|
|
|
2017-07-13 23:43:27 +02:00
|
|
|
var preDeps = []RegisterMutatorFunc{
|
2017-09-16 02:33:55 +02:00
|
|
|
registerArchMutator,
|
2017-07-13 23:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var postDeps = []RegisterMutatorFunc{
|
2019-03-05 07:33:56 +01:00
|
|
|
registerPathDepsMutator,
|
2017-07-28 00:41:32 +02:00
|
|
|
RegisterPrebuiltsPostDepsMutators,
|
2019-03-28 15:10:57 +01:00
|
|
|
registerVisibilityRuleEnforcer,
|
2017-12-06 23:18:35 +01:00
|
|
|
registerNeverallowMutator,
|
2019-05-11 00:16:29 +02:00
|
|
|
RegisterOverridePostDepsMutators,
|
2017-07-13 23:43:27 +02:00
|
|
|
}
|
2016-10-12 23:38:15 +02:00
|
|
|
|
|
|
|
func PreArchMutators(f RegisterMutatorFunc) {
|
|
|
|
preArch = append(preArch, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func PreDepsMutators(f RegisterMutatorFunc) {
|
|
|
|
preDeps = append(preDeps, f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func PostDepsMutators(f RegisterMutatorFunc) {
|
|
|
|
postDeps = append(postDeps, f)
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
type TopDownMutator func(TopDownMutatorContext)
|
2015-10-29 23:25:03 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
type TopDownMutatorContext interface {
|
2017-11-29 09:27:14 +01:00
|
|
|
BaseModuleContext
|
2017-10-24 02:10:29 +02:00
|
|
|
|
2019-07-02 00:32:31 +02:00
|
|
|
MutatorName() string
|
|
|
|
|
2017-10-24 02:10:29 +02:00
|
|
|
Rename(name string)
|
|
|
|
|
|
|
|
CreateModule(blueprint.ModuleFactory, ...interface{})
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
type topDownMutatorContext struct {
|
2019-06-07 01:13:11 +02:00
|
|
|
bp blueprint.TopDownMutatorContext
|
2019-06-06 23:33:29 +02:00
|
|
|
baseModuleContext
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
type BottomUpMutator func(BottomUpMutatorContext)
|
2015-10-29 23:25:03 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
type BottomUpMutatorContext interface {
|
2017-11-29 09:27:14 +01:00
|
|
|
BaseModuleContext
|
|
|
|
|
2019-07-02 00:32:31 +02:00
|
|
|
MutatorName() string
|
|
|
|
|
2017-11-29 09:27:14 +01:00
|
|
|
Rename(name string)
|
|
|
|
|
|
|
|
AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string)
|
|
|
|
AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string)
|
|
|
|
CreateVariations(...string) []blueprint.Module
|
|
|
|
CreateLocalVariations(...string) []blueprint.Module
|
|
|
|
SetDependencyVariation(string)
|
|
|
|
AddVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
|
|
|
|
AddFarVariationDependencies([]blueprint.Variation, blueprint.DependencyTag, ...string)
|
|
|
|
AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module)
|
|
|
|
ReplaceDependencies(string)
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
type bottomUpMutatorContext struct {
|
2019-06-07 01:13:11 +02:00
|
|
|
bp blueprint.BottomUpMutatorContext
|
2019-06-06 23:33:29 +02:00
|
|
|
baseModuleContext
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
func (x *registerMutatorsContext) BottomUp(name string, m BottomUpMutator) MutatorHandle {
|
2016-10-12 23:28:16 +02:00
|
|
|
f := func(ctx blueprint.BottomUpMutatorContext) {
|
2016-05-19 00:37:25 +02:00
|
|
|
if a, ok := ctx.Module().(Module); ok {
|
2019-06-06 23:29:25 +02:00
|
|
|
actx := &bottomUpMutatorContext{
|
2019-06-07 01:13:11 +02:00
|
|
|
bp: ctx,
|
|
|
|
baseModuleContext: a.base().baseModuleContextFactory(ctx),
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2016-10-12 23:28:16 +02:00
|
|
|
m(actx)
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2016-10-12 23:28:16 +02:00
|
|
|
}
|
|
|
|
mutator := &mutator{name: name, bottomUpMutator: f}
|
2017-03-17 00:50:10 +01:00
|
|
|
x.mutators = append(x.mutators, mutator)
|
2016-10-12 23:28:16 +02:00
|
|
|
return mutator
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
func (x *registerMutatorsContext) TopDown(name string, m TopDownMutator) MutatorHandle {
|
2016-10-12 23:28:16 +02:00
|
|
|
f := func(ctx blueprint.TopDownMutatorContext) {
|
2016-05-19 00:37:25 +02:00
|
|
|
if a, ok := ctx.Module().(Module); ok {
|
2019-06-06 23:29:25 +02:00
|
|
|
actx := &topDownMutatorContext{
|
2019-06-07 01:13:11 +02:00
|
|
|
bp: ctx,
|
|
|
|
baseModuleContext: a.base().baseModuleContextFactory(ctx),
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2016-10-12 23:28:16 +02:00
|
|
|
m(actx)
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2016-10-12 23:28:16 +02:00
|
|
|
}
|
|
|
|
mutator := &mutator{name: name, topDownMutator: f}
|
2017-03-17 00:50:10 +01:00
|
|
|
x.mutators = append(x.mutators, mutator)
|
2016-10-12 23:28:16 +02:00
|
|
|
return mutator
|
|
|
|
}
|
|
|
|
|
|
|
|
type MutatorHandle interface {
|
|
|
|
Parallel() MutatorHandle
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mutator *mutator) Parallel() MutatorHandle {
|
|
|
|
mutator.parallel = true
|
|
|
|
return mutator
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2016-10-12 23:38:15 +02:00
|
|
|
|
|
|
|
func depsMutator(ctx BottomUpMutatorContext) {
|
2018-08-30 21:52:41 +02:00
|
|
|
if m, ok := ctx.Module().(Module); ok && m.Enabled() {
|
2016-10-12 23:38:15 +02:00
|
|
|
m.DepsMutator(ctx)
|
|
|
|
}
|
|
|
|
}
|
2017-10-24 02:59:01 +02:00
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
func (t *topDownMutatorContext) AppendProperties(props ...interface{}) {
|
2017-11-03 00:35:56 +01:00
|
|
|
for _, p := range props {
|
2019-06-06 23:29:25 +02:00
|
|
|
err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties,
|
2017-11-03 00:35:56 +01:00
|
|
|
p, nil)
|
|
|
|
if err != nil {
|
|
|
|
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
2019-06-06 23:29:25 +02:00
|
|
|
t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
2017-11-03 00:35:56 +01:00
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 23:29:25 +02:00
|
|
|
func (t *topDownMutatorContext) PrependProperties(props ...interface{}) {
|
2017-11-03 00:35:56 +01:00
|
|
|
for _, p := range props {
|
2019-06-06 23:29:25 +02:00
|
|
|
err := proptools.PrependMatchingProperties(t.Module().base().customizableProperties,
|
2017-11-03 00:35:56 +01:00
|
|
|
p, nil)
|
|
|
|
if err != nil {
|
|
|
|
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
2019-06-06 23:29:25 +02:00
|
|
|
t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
2017-11-03 00:35:56 +01:00
|
|
|
} else {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-07 01:13:11 +02:00
|
|
|
|
|
|
|
// android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that
|
|
|
|
// has an overridden version in android.BaseModuleContext has to be manually forwarded to BaseModuleContext to avoid
|
|
|
|
// ambiguous method errors, or it has to store a blueprint.TopDownMutatorContext non-embedded, in which case every
|
|
|
|
// non-overridden method has to be forwarded. There are fewer non-overridden methods, so use the latter. The following
|
|
|
|
// methods forward to the identical blueprint versions for topDownMutatorContext and bottomUpMutatorContext.
|
|
|
|
|
2019-07-02 00:32:31 +02:00
|
|
|
func (t *topDownMutatorContext) MutatorName() string {
|
|
|
|
return t.bp.MutatorName()
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:13:11 +02:00
|
|
|
func (t *topDownMutatorContext) Rename(name string) {
|
|
|
|
t.bp.Rename(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *topDownMutatorContext) CreateModule(factory blueprint.ModuleFactory, props ...interface{}) {
|
|
|
|
t.bp.CreateModule(factory, props...)
|
|
|
|
}
|
|
|
|
|
2019-07-02 00:32:31 +02:00
|
|
|
func (b *bottomUpMutatorContext) MutatorName() string {
|
|
|
|
return b.bp.MutatorName()
|
|
|
|
}
|
|
|
|
|
2019-06-07 01:13:11 +02:00
|
|
|
func (b *bottomUpMutatorContext) Rename(name string) {
|
|
|
|
b.bp.Rename(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) AddDependency(module blueprint.Module, tag blueprint.DependencyTag, name ...string) {
|
|
|
|
b.bp.AddDependency(module, tag, name...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) AddReverseDependency(module blueprint.Module, tag blueprint.DependencyTag, name string) {
|
|
|
|
b.bp.AddReverseDependency(module, tag, name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) CreateVariations(variations ...string) []blueprint.Module {
|
|
|
|
return b.bp.CreateVariations(variations...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) CreateLocalVariations(variations ...string) []blueprint.Module {
|
|
|
|
return b.bp.CreateLocalVariations(variations...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) SetDependencyVariation(variation string) {
|
|
|
|
b.bp.SetDependencyVariation(variation)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) AddVariationDependencies(variations []blueprint.Variation, tag blueprint.DependencyTag,
|
|
|
|
names ...string) {
|
|
|
|
|
|
|
|
b.bp.AddVariationDependencies(variations, tag, names...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) AddFarVariationDependencies(variations []blueprint.Variation,
|
|
|
|
tag blueprint.DependencyTag, names ...string) {
|
|
|
|
|
|
|
|
b.bp.AddFarVariationDependencies(variations, tag, names...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) AddInterVariantDependency(tag blueprint.DependencyTag, from, to blueprint.Module) {
|
|
|
|
b.bp.AddInterVariantDependency(tag, from, to)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *bottomUpMutatorContext) ReplaceDependencies(name string) {
|
|
|
|
b.bp.ReplaceDependencies(name)
|
|
|
|
}
|