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 15package soong 16 17import "github.com/google/blueprint" 18 19type moduleType struct { 20 name string 21 factory blueprint.ModuleFactory 22} 23 24var moduleTypes []moduleType 25 26type singleton struct { 27 name string 28 factory blueprint.SingletonFactory 29} 30 31var singletons []singleton 32 33type mutator struct { 34 name string 35 bottomUpMutator blueprint.BottomUpMutator 36 topDownMutator blueprint.TopDownMutator 37} 38 39var mutators []mutator 40 41func RegisterModuleType(name string, factory blueprint.ModuleFactory) { 42 moduleTypes = append(moduleTypes, moduleType{name, factory}) 43} 44 45func RegisterSingletonType(name string, factory blueprint.SingletonFactory) { 46 singletons = append(singletons, singleton{name, factory}) 47} 48 49func RegisterBottomUpMutator(name string, m blueprint.BottomUpMutator) { 50 mutators = append(mutators, mutator{name: name, bottomUpMutator: m}) 51} 52 53func RegisterTopDownMutator(name string, m blueprint.TopDownMutator) { 54 mutators = append(mutators, mutator{name: name, topDownMutator: m}) 55} 56 57func NewContext() *blueprint.Context { 58 ctx := blueprint.NewContext() 59 60 for _, t := range moduleTypes { 61 ctx.RegisterModuleType(t.name, t.factory) 62 } 63 64 for _, t := range singletons { 65 ctx.RegisterSingletonType(t.name, t.factory) 66 } 67 68 for _, t := range mutators { 69 if t.bottomUpMutator != nil { 70 ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator) 71 } 72 if t.topDownMutator != nil { 73 ctx.RegisterTopDownMutator(t.name, t.topDownMutator) 74 } 75 } 76 77 return ctx 78} 79