| Colin Cross | 463a90e | 2015-06-17 14:20:06 -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 | |
| 15 | package soong |
| 16 | |
| 17 | import "github.com/google/blueprint" |
| 18 | |
| 19 | type moduleType struct { |
| 20 | name string |
| 21 | factory blueprint.ModuleFactory |
| 22 | } |
| 23 | |
| 24 | var moduleTypes []moduleType |
| 25 | |
| 26 | type singleton struct { |
| 27 | name string |
| 28 | factory blueprint.SingletonFactory |
| 29 | } |
| 30 | |
| 31 | var singletons []singleton |
| 32 | |
| 33 | type earlyMutator struct { |
| 34 | name string |
| 35 | mutator blueprint.EarlyMutator |
| 36 | } |
| 37 | |
| 38 | var earlyMutators []earlyMutator |
| 39 | |
| 40 | func RegisterModuleType(name string, factory blueprint.ModuleFactory) { |
| 41 | moduleTypes = append(moduleTypes, moduleType{name, factory}) |
| 42 | } |
| 43 | |
| 44 | func RegisterSingletonType(name string, factory blueprint.SingletonFactory) { |
| 45 | singletons = append(singletons, singleton{name, factory}) |
| 46 | } |
| 47 | |
| 48 | func RegisterEarlyMutator(name string, mutator blueprint.EarlyMutator) { |
| 49 | earlyMutators = append(earlyMutators, earlyMutator{name, mutator}) |
| 50 | } |
| 51 | |
| 52 | func NewContext() *blueprint.Context { |
| 53 | ctx := blueprint.NewContext() |
| 54 | |
| 55 | for _, t := range moduleTypes { |
| 56 | ctx.RegisterModuleType(t.name, t.factory) |
| 57 | } |
| 58 | |
| 59 | for _, t := range singletons { |
| 60 | ctx.RegisterSingletonType(t.name, t.factory) |
| 61 | } |
| 62 | |
| 63 | for _, t := range earlyMutators { |
| 64 | ctx.RegisterEarlyMutator(t.name, t.mutator) |
| 65 | } |
| 66 | |
| 67 | return ctx |
| 68 | } |