blob: ff2f9ad4033fa0c1b7c6dd81028e212e646160ea [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 Cross635c3b02016-05-18 15:37:25 -070019type AndroidTopDownMutator func(TopDownMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -070020
Colin Cross635c3b02016-05-18 15:37:25 -070021type TopDownMutatorContext interface {
Colin Cross6362e272015-10-29 15:25:03 -070022 blueprint.TopDownMutatorContext
23 androidBaseContext
24}
25
26type androidTopDownMutatorContext struct {
27 blueprint.TopDownMutatorContext
28 androidBaseContextImpl
29}
30
Colin Cross635c3b02016-05-18 15:37:25 -070031type AndroidBottomUpMutator func(BottomUpMutatorContext)
Colin Cross6362e272015-10-29 15:25:03 -070032
Colin Cross635c3b02016-05-18 15:37:25 -070033type BottomUpMutatorContext interface {
Colin Cross6362e272015-10-29 15:25:03 -070034 blueprint.BottomUpMutatorContext
35 androidBaseContext
36}
37
38type androidBottomUpMutatorContext struct {
39 blueprint.BottomUpMutatorContext
40 androidBaseContextImpl
41}
42
Colin Cross798bfce2016-10-12 14:28:16 -070043func RegisterBottomUpMutator(name string, m AndroidBottomUpMutator) MutatorHandle {
44 f := func(ctx blueprint.BottomUpMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -070045 if a, ok := ctx.Module().(Module); ok {
Colin Cross6362e272015-10-29 15:25:03 -070046 actx := &androidBottomUpMutatorContext{
47 BottomUpMutatorContext: ctx,
48 androidBaseContextImpl: a.base().androidBaseContextFactory(ctx),
49 }
Colin Cross798bfce2016-10-12 14:28:16 -070050 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -070051 }
Colin Cross798bfce2016-10-12 14:28:16 -070052 }
53 mutator := &mutator{name: name, bottomUpMutator: f}
54 mutators = append(mutators, mutator)
55 return mutator
Colin Cross6362e272015-10-29 15:25:03 -070056}
57
Colin Cross798bfce2016-10-12 14:28:16 -070058func RegisterTopDownMutator(name string, m AndroidTopDownMutator) MutatorHandle {
59 f := func(ctx blueprint.TopDownMutatorContext) {
Colin Cross635c3b02016-05-18 15:37:25 -070060 if a, ok := ctx.Module().(Module); ok {
Colin Cross6362e272015-10-29 15:25:03 -070061 actx := &androidTopDownMutatorContext{
62 TopDownMutatorContext: ctx,
63 androidBaseContextImpl: a.base().androidBaseContextFactory(ctx),
64 }
Colin Cross798bfce2016-10-12 14:28:16 -070065 m(actx)
Colin Cross6362e272015-10-29 15:25:03 -070066 }
Colin Cross798bfce2016-10-12 14:28:16 -070067 }
68 mutator := &mutator{name: name, topDownMutator: f}
69 mutators = append(mutators, mutator)
70 return mutator
71}
72
73type MutatorHandle interface {
74 Parallel() MutatorHandle
75}
76
77func (mutator *mutator) Parallel() MutatorHandle {
78 mutator.parallel = true
79 return mutator
Colin Cross6362e272015-10-29 15:25:03 -070080}