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 | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 19 | type AndroidTopDownMutator func(TopDownMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 20 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 21 | type TopDownMutatorContext interface { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 22 | blueprint.TopDownMutatorContext |
| 23 | androidBaseContext |
| 24 | } |
| 25 | |
| 26 | type androidTopDownMutatorContext struct { |
| 27 | blueprint.TopDownMutatorContext |
| 28 | androidBaseContextImpl |
| 29 | } |
| 30 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 31 | type AndroidBottomUpMutator func(BottomUpMutatorContext) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 32 | |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 33 | type BottomUpMutatorContext interface { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 34 | blueprint.BottomUpMutatorContext |
| 35 | androidBaseContext |
| 36 | } |
| 37 | |
| 38 | type androidBottomUpMutatorContext struct { |
| 39 | blueprint.BottomUpMutatorContext |
| 40 | androidBaseContextImpl |
| 41 | } |
| 42 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame^] | 43 | func RegisterBottomUpMutator(name string, m AndroidBottomUpMutator) MutatorHandle { |
| 44 | f := func(ctx blueprint.BottomUpMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 45 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 46 | actx := &androidBottomUpMutatorContext{ |
| 47 | BottomUpMutatorContext: ctx, |
| 48 | androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), |
| 49 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame^] | 50 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 51 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame^] | 52 | } |
| 53 | mutator := &mutator{name: name, bottomUpMutator: f} |
| 54 | mutators = append(mutators, mutator) |
| 55 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame^] | 58 | func RegisterTopDownMutator(name string, m AndroidTopDownMutator) MutatorHandle { |
| 59 | f := func(ctx blueprint.TopDownMutatorContext) { |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 60 | if a, ok := ctx.Module().(Module); ok { |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 61 | actx := &androidTopDownMutatorContext{ |
| 62 | TopDownMutatorContext: ctx, |
| 63 | androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), |
| 64 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame^] | 65 | m(actx) |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 66 | } |
Colin Cross | 798bfce | 2016-10-12 14:28:16 -0700 | [diff] [blame^] | 67 | } |
| 68 | mutator := &mutator{name: name, topDownMutator: f} |
| 69 | mutators = append(mutators, mutator) |
| 70 | return mutator |
| 71 | } |
| 72 | |
| 73 | type MutatorHandle interface { |
| 74 | Parallel() MutatorHandle |
| 75 | } |
| 76 | |
| 77 | func (mutator *mutator) Parallel() MutatorHandle { |
| 78 | mutator.parallel = true |
| 79 | return mutator |
Colin Cross | 6362e27 | 2015-10-29 15:25:03 -0700 | [diff] [blame] | 80 | } |