blob: b375bce27f7aa82fd88496b2394c28e9fbb78b38 [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 Cross798bfce2016-10-12 14:28:16 -070017import "github.com/google/blueprint"
Colin Cross6362e272015-10-29 15:25:03 -070018
Colin Cross1e676be2016-10-12 14:38:15 -070019// Mutator phases:
20// Pre-arch
21// Arch
22// Pre-deps
23// Deps
24// PostDeps
25
26func registerMutators() {
27 ctx := registerMutatorsContext{}
28
29 register := func(funcs []RegisterMutatorFunc) {
30 for _, f := range funcs {
31 f(ctx)
32 }
33 }
34
35 ctx.TopDown("load_hooks", loadHookMutator).Parallel()
36 ctx.BottomUp("defaults_deps", defaultsDepsMutator).Parallel()
37 ctx.TopDown("defaults", defaultsMutator).Parallel()
38
39 register(preArch)
40
41 ctx.BottomUp("arch", archMutator).Parallel()
42 ctx.TopDown("arch_hooks", archHookMutator).Parallel()
43
44 register(preDeps)
45
46 ctx.BottomUp("deps", depsMutator).Parallel()
47
48 register(postDeps)
49}
50
51type registerMutatorsContext struct{}
52
53type RegisterMutatorsContext interface {
54 TopDown(name string, m AndroidTopDownMutator) MutatorHandle
55 BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle
56}
57
58type RegisterMutatorFunc func(RegisterMutatorsContext)
59
60var preArch, preDeps, postDeps []RegisterMutatorFunc
61
62func PreArchMutators(f RegisterMutatorFunc) {
63 preArch = append(preArch, f)
64}
65
66func PreDepsMutators(f RegisterMutatorFunc) {
67 preDeps = append(preDeps, f)
68}
69
70func PostDepsMutators(f RegisterMutatorFunc) {
71 postDeps = append(postDeps, f)
72}
73
Colin Cross635c3b02016-05-18 15:37:25 -070074type AndroidTopDownMutator func(TopDownMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -070075
Colin Cross635c3b02016-05-18 15:37:25 -070076type TopDownMutatorContext interface {
Colin Cross6362e272015-10-29 15:25:03 -070077 blueprint.TopDownMutatorContext
78 androidBaseContext
79}
80
81type androidTopDownMutatorContext struct {
82 blueprint.TopDownMutatorContext
83 androidBaseContextImpl
84}
85
Colin Cross635c3b02016-05-18 15:37:25 -070086type AndroidBottomUpMutator func(BottomUpMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -070087
Colin Cross635c3b02016-05-18 15:37:25 -070088type BottomUpMutatorContext interface {
Colin Cross6362e272015-10-29 15:25:03 -070089 blueprint.BottomUpMutatorContext
90 androidBaseContext
91}
92
93type androidBottomUpMutatorContext struct {
94 blueprint.BottomUpMutatorContext
95 androidBaseContextImpl
96}
97
Colin Cross1e676be2016-10-12 14:38:15 -070098func (registerMutatorsContext) BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle {
Colin Cross798bfce2016-10-12 14:28:16 -070099 f := func(ctx blueprint.BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700100 if a, ok := ctx.Module().(Module); ok {
Colin Cross6362e272015-10-29 15:25:03 -0700101 actx := &androidBottomUpMutatorContext{
102 BottomUpMutatorContext: ctx,
103 androidBaseContextImpl: a.base().androidBaseContextFactory(ctx),
104 }
Colin Cross798bfce2016-10-12 14:28:16 -0700105 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -0700106 }
Colin Cross798bfce2016-10-12 14:28:16 -0700107 }
108 mutator := &mutator{name: name, bottomUpMutator: f}
109 mutators = append(mutators, mutator)
110 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700111}
112
Colin Cross1e676be2016-10-12 14:38:15 -0700113func (registerMutatorsContext) TopDown(name string, m AndroidTopDownMutator) MutatorHandle {
Colin Cross798bfce2016-10-12 14:28:16 -0700114 f := func(ctx blueprint.TopDownMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -0700115 if a, ok := ctx.Module().(Module); ok {
Colin Cross6362e272015-10-29 15:25:03 -0700116 actx := &androidTopDownMutatorContext{
117 TopDownMutatorContext: ctx,
118 androidBaseContextImpl: a.base().androidBaseContextFactory(ctx),
119 }
Colin Cross798bfce2016-10-12 14:28:16 -0700120 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -0700121 }
Colin Cross798bfce2016-10-12 14:28:16 -0700122 }
123 mutator := &mutator{name: name, topDownMutator: f}
124 mutators = append(mutators, mutator)
125 return mutator
126}
127
128type MutatorHandle interface {
129 Parallel() MutatorHandle
130}
131
132func (mutator *mutator) Parallel() MutatorHandle {
133 mutator.parallel = true
134 return mutator
Colin Cross6362e272015-10-29 15:25:03 -0700135}
Colin Cross1e676be2016-10-12 14:38:15 -0700136
137func depsMutator(ctx BottomUpMutatorContext) {
138 if m, ok := ctx.Module().(Module); ok {
139 m.DepsMutator(ctx)
140 }
141}