blob: 7cc9d50eef4c84fdc4b21683c3b93db0aa641578 [file] [log] [blame]
Colin Cross463a90e2015-06-17 14:20:06 -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 Cross798bfce2016-10-12 14:28:16 -070015package android
Colin Cross463a90e2015-06-17 14:20:06 -070016
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
Colin Cross6362e272015-10-29 15:25:03 -070033type mutator struct {
34 name string
35 bottomUpMutator blueprint.BottomUpMutator
36 topDownMutator blueprint.TopDownMutator
Colin Crosse8a67a72016-08-07 21:17:54 -070037 parallel bool
Colin Cross463a90e2015-06-17 14:20:06 -070038}
39
Colin Crosse8a67a72016-08-07 21:17:54 -070040var mutators []*mutator
Colin Cross463a90e2015-06-17 14:20:06 -070041
42func RegisterModuleType(name string, factory blueprint.ModuleFactory) {
43 moduleTypes = append(moduleTypes, moduleType{name, factory})
44}
45
46func RegisterSingletonType(name string, factory blueprint.SingletonFactory) {
47 singletons = append(singletons, singleton{name, factory})
48}
49
Colin Cross463a90e2015-06-17 14:20:06 -070050func NewContext() *blueprint.Context {
51 ctx := blueprint.NewContext()
52
53 for _, t := range moduleTypes {
54 ctx.RegisterModuleType(t.name, t.factory)
55 }
56
57 for _, t := range singletons {
58 ctx.RegisterSingletonType(t.name, t.factory)
59 }
60
Colin Cross6362e272015-10-29 15:25:03 -070061 for _, t := range mutators {
Colin Cross76f2f972016-08-11 14:10:54 -070062 var handle blueprint.MutatorHandle
Colin Cross6362e272015-10-29 15:25:03 -070063 if t.bottomUpMutator != nil {
Colin Cross76f2f972016-08-11 14:10:54 -070064 handle = ctx.RegisterBottomUpMutator(t.name, t.bottomUpMutator)
65 } else if t.topDownMutator != nil {
66 handle = ctx.RegisterTopDownMutator(t.name, t.topDownMutator)
Colin Cross6362e272015-10-29 15:25:03 -070067 }
Colin Cross76f2f972016-08-11 14:10:54 -070068 if t.parallel {
69 handle.Parallel()
Colin Cross6362e272015-10-29 15:25:03 -070070 }
Colin Cross463a90e2015-06-17 14:20:06 -070071 }
72
73 return ctx
74}