Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 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 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 15 | package android |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 16 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 17 | import "github.com/google/blueprint" |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 18 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame^] | 19 | // Mutator phases: |
| 20 | // Pre-arch |
| 21 | // Arch |
| 22 | // Pre-deps |
| 23 | // Deps |
| 24 | // PostDeps |
| 25 | |
| 26 | func 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 | |
| 51 | type registerMutatorsContext struct{} |
| 52 | |
| 53 | type RegisterMutatorsContext interface { |
| 54 | TopDown(name string, m AndroidTopDownMutator) MutatorHandle |
| 55 | BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle |
| 56 | } |
| 57 | |
| 58 | type RegisterMutatorFunc func(RegisterMutatorsContext) |
| 59 | |
| 60 | var preArch, preDeps, postDeps []RegisterMutatorFunc |
| 61 | |
| 62 | func PreArchMutators(f RegisterMutatorFunc) { |
| 63 | preArch = append(preArch, f) |
| 64 | } |
| 65 | |
| 66 | func PreDepsMutators(f RegisterMutatorFunc) { |
| 67 | preDeps = append(preDeps, f) |
| 68 | } |
| 69 | |
| 70 | func PostDepsMutators(f RegisterMutatorFunc) { |
| 71 | postDeps = append(postDeps, f) |
| 72 | } |
| 73 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 74 | type AndroidTopDownMutator func(TopDownMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 75 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 76 | type TopDownMutatorContext interface { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 77 | blueprint.TopDownMutatorContext |
| 78 | androidBaseContext |
| 79 | } |
| 80 | |
| 81 | type androidTopDownMutatorContext struct { |
| 82 | blueprint.TopDownMutatorContext |
| 83 | androidBaseContextImpl |
| 84 | } |
| 85 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 86 | type AndroidBottomUpMutator func(BottomUpMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 87 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 88 | type BottomUpMutatorContext interface { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 89 | blueprint.BottomUpMutatorContext |
| 90 | androidBaseContext |
| 91 | } |
| 92 | |
| 93 | type androidBottomUpMutatorContext struct { |
| 94 | blueprint.BottomUpMutatorContext |
| 95 | androidBaseContextImpl |
| 96 | } |
| 97 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame^] | 98 | func (registerMutatorsContext) BottomUp(name string, m AndroidBottomUpMutator) MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 99 | f := func(ctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 100 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 101 | actx := &androidBottomUpMutatorContext{ |
| 102 | BottomUpMutatorContext: ctx, |
| 103 | androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), |
| 104 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 105 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 106 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 107 | } |
| 108 | mutator := &mutator{name: name, bottomUpMutator: f} |
| 109 | mutators = append(mutators, mutator) |
| 110 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame^] | 113 | func (registerMutatorsContext) TopDown(name string, m AndroidTopDownMutator) MutatorHandle { |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 114 | f := func(ctx blueprint.TopDownMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 115 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 116 | actx := &androidTopDownMutatorContext{ |
| 117 | TopDownMutatorContext: ctx, |
| 118 | androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), |
| 119 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 120 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 121 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame] | 122 | } |
| 123 | mutator := &mutator{name: name, topDownMutator: f} |
| 124 | mutators = append(mutators, mutator) |
| 125 | return mutator |
| 126 | } |
| 127 | |
| 128 | type MutatorHandle interface { |
| 129 | Parallel() MutatorHandle |
| 130 | } |
| 131 | |
| 132 | func (mutator *mutator) Parallel() MutatorHandle { |
| 133 | mutator.parallel = true |
| 134 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 135 | } |
Colin Cross | 1e676be | 2016-10-12 14:38:15 -0700 | [diff] [blame^] | 136 | |
| 137 | func depsMutator(ctx BottomUpMutatorContext) { |
| 138 | if m, ok := ctx.Module().(Module); ok { |
| 139 | m.DepsMutator(ctx) |
| 140 | } |
| 141 | } |