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 15 package common 16 17 import ( 18 "android/soong" 19 20 "github.com/google/blueprint" 21 ) 22 23 type AndroidTopDownMutator func(AndroidTopDownMutatorContext) 24 25 type AndroidTopDownMutatorContext interface { 26 blueprint.TopDownMutatorContext 27 androidBaseContext 28 } 29 30 type androidTopDownMutatorContext struct { 31 blueprint.TopDownMutatorContext 32 androidBaseContextImpl 33 } 34 35 type AndroidBottomUpMutator func(AndroidBottomUpMutatorContext) 36 37 type AndroidBottomUpMutatorContext interface { 38 blueprint.BottomUpMutatorContext 39 androidBaseContext 40 } 41 42 type androidBottomUpMutatorContext struct { 43 blueprint.BottomUpMutatorContext 44 androidBaseContextImpl 45 } 46 47 func RegisterBottomUpMutator(name string, mutator AndroidBottomUpMutator) { 48 soong.RegisterBottomUpMutator(name, func(ctx blueprint.BottomUpMutatorContext) { 49 if a, ok := ctx.Module().(AndroidModule); ok { 50 actx := &androidBottomUpMutatorContext{ 51 BottomUpMutatorContext: ctx, 52 androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), 53 } 54 mutator(actx) 55 } 56 }) 57 } 58 59 func RegisterTopDownMutator(name string, mutator AndroidTopDownMutator) { 60 soong.RegisterTopDownMutator(name, func(ctx blueprint.TopDownMutatorContext) { 61 if a, ok := ctx.Module().(AndroidModule); ok { 62 actx := &androidTopDownMutatorContext{ 63 TopDownMutatorContext: ctx, 64 androidBaseContextImpl: a.base().androidBaseContextFactory(ctx), 65 } 66 mutator(actx) 67 } 68 }) 69 } 70