blob: 056880dab7b36d5d9734128abf1b892288e44caf [file] [log] [blame]
Colin Crossa120ec12016-08-19 16:07:38 -07001// Copyright 2016 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 "github.com/google/blueprint/proptools"
18
19type CustomizePropertiesContext interface {
20 BaseContext
21 AppendProperties(...interface{})
22 PrependProperties(...interface{})
23}
24
25type customizePropertiesContext struct {
26 BaseContext
27
28 module *ModuleBase
29}
30
31type PropertyCustomizer interface {
32 CustomizeProperties(CustomizePropertiesContext)
33}
34
35func customizerMutator(ctx TopDownMutatorContext) {
36 if m, ok := ctx.Module().(Module); ok {
37 a := m.base()
38 if len(a.customizers) > 0 {
39 mctx := &customizePropertiesContext{
40 BaseContext: ctx,
41 module: a,
42 }
43 for _, c := range a.customizers {
44 c.CustomizeProperties(mctx)
45 if mctx.Failed() {
46 return
47 }
48 }
49 }
50 }
51}
52
53func (ctx *customizePropertiesContext) AppendProperties(props ...interface{}) {
54 for _, p := range props {
55 err := proptools.AppendMatchingProperties(ctx.module.customizableProperties, p, nil)
56 if err != nil {
57 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
58 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
59 } else {
60 panic(err)
61 }
62 }
63 }
64}
65
66func (ctx *customizePropertiesContext) PrependProperties(props ...interface{}) {
67 for _, p := range props {
68 err := proptools.PrependMatchingProperties(ctx.module.customizableProperties, p, nil)
69 if err != nil {
70 if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
71 ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
72 } else {
73 panic(err)
74 }
75 }
76 }
77}