• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android
16
17import (
18	"github.com/google/blueprint"
19)
20
21type moduleType struct {
22	name    string
23	factory blueprint.ModuleFactory
24}
25
26var moduleTypes []moduleType
27
28type singleton struct {
29	name    string
30	factory blueprint.SingletonFactory
31}
32
33var singletons []singleton
34
35type mutator struct {
36	name            string
37	bottomUpMutator blueprint.BottomUpMutator
38	topDownMutator  blueprint.TopDownMutator
39	parallel        bool
40}
41
42var mutators []*mutator
43
44type ModuleFactory func() Module
45
46// ModuleFactoryAdapter Wraps a ModuleFactory into a blueprint.ModuleFactory by converting an Module
47// into a blueprint.Module and a list of property structs
48func ModuleFactoryAdaptor(factory ModuleFactory) blueprint.ModuleFactory {
49	return func() (blueprint.Module, []interface{}) {
50		module := factory()
51		return module, module.GetProperties()
52	}
53}
54
55func RegisterModuleType(name string, factory ModuleFactory) {
56	moduleTypes = append(moduleTypes, moduleType{name, ModuleFactoryAdaptor(factory)})
57}
58
59func RegisterSingletonType(name string, factory blueprint.SingletonFactory) {
60	singletons = append(singletons, singleton{name, factory})
61}
62
63type Context struct {
64	*blueprint.Context
65}
66
67func NewContext() *Context {
68	return &Context{blueprint.NewContext()}
69}
70
71func (ctx *Context) Register() {
72	for _, t := range moduleTypes {
73		ctx.RegisterModuleType(t.name, t.factory)
74	}
75
76	for _, t := range singletons {
77		ctx.RegisterSingletonType(t.name, t.factory)
78	}
79
80	registerMutators(ctx.Context, preArch, preDeps, postDeps)
81
82	ctx.RegisterSingletonType("env", EnvSingleton)
83}
84