diff options
author | 2021-11-24 15:18:37 +0000 | |
---|---|---|
committer | 2021-11-24 15:18:37 +0000 | |
commit | 8c64fa9a8efafadb787143296750b32a0119f23b (patch) | |
tree | b500eac2dde5e1fafdb784a47320221ea1905542 | |
parent | 4ad40d99b08022f532d2eb2e5a4d66b3e3f6c20f (diff) | |
parent | ef3676c94b6cd5d158c86416124eb4ded1645e98 (diff) |
Merge "Minor refactoring of Append/PrependProperties() methods Test: `m nothing` and compare ninja file Bug: n/a"
-rw-r--r-- | android/hooks.go | 21 | ||||
-rw-r--r-- | android/module.go | 2 | ||||
-rw-r--r-- | android/mutator.go | 22 |
3 files changed, 16 insertions, 29 deletions
diff --git a/android/hooks.go b/android/hooks.go index 85fc08168..9eaa1ac85 100644 --- a/android/hooks.go +++ b/android/hooks.go @@ -65,10 +65,10 @@ func (l *loadHookContext) moduleFactories() map[string]blueprint.ModuleFactory { return l.bp.ModuleFactories() } -func (l *loadHookContext) AppendProperties(props ...interface{}) { +func (l *loadHookContext) appendPrependHelper(props []interface{}, + extendFn func([]interface{}, interface{}, proptools.ExtendPropertyFilterFunc) error) { for _, p := range props { - err := proptools.AppendMatchingProperties(l.Module().base().customizableProperties, - p, nil) + err := extendFn(l.Module().base().customizableProperties, p, nil) if err != nil { if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { l.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) @@ -78,19 +78,12 @@ func (l *loadHookContext) AppendProperties(props ...interface{}) { } } } +func (l *loadHookContext) AppendProperties(props ...interface{}) { + l.appendPrependHelper(props, proptools.AppendMatchingProperties) +} func (l *loadHookContext) PrependProperties(props ...interface{}) { - for _, p := range props { - err := proptools.PrependMatchingProperties(l.Module().base().customizableProperties, - p, nil) - if err != nil { - if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { - l.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) - } else { - panic(err) - } - } - } + l.appendPrependHelper(props, proptools.PrependMatchingProperties) } func (l *loadHookContext) CreateModule(factory ModuleFactory, props ...interface{}) Module { diff --git a/android/module.go b/android/module.go index e100330de..4a388b562 100644 --- a/android/module.go +++ b/android/module.go @@ -1148,7 +1148,7 @@ func (attrs *CommonAttributes) fillCommonBp2BuildModuleAttrs(ctx *topDownMutator // } // } // -// func NewMyModule() android.Module) { +// func NewMyModule() android.Module { // m := &myModule{} // m.AddProperties(&m.properties) // android.InitAndroidModule(m) diff --git a/android/mutator.go b/android/mutator.go index 4b373778e..461cb17d8 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -529,10 +529,10 @@ func (t *topDownMutatorContext) CreateBazelTargetModule( mod.base().addBp2buildInfo(info) } -func (t *topDownMutatorContext) AppendProperties(props ...interface{}) { +func (t *topDownMutatorContext) appendPrependHelper(props []interface{}, + extendFn func([]interface{}, interface{}, proptools.ExtendPropertyFilterFunc) error) { for _, p := range props { - err := proptools.AppendMatchingProperties(t.Module().base().customizableProperties, - p, nil) + err := extendFn(t.Module().base().customizableProperties, p, nil) if err != nil { if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) @@ -543,18 +543,12 @@ func (t *topDownMutatorContext) AppendProperties(props ...interface{}) { } } +func (t *topDownMutatorContext) AppendProperties(props ...interface{}) { + t.appendPrependHelper(props, proptools.AppendMatchingProperties) +} + func (t *topDownMutatorContext) PrependProperties(props ...interface{}) { - for _, p := range props { - err := proptools.PrependMatchingProperties(t.Module().base().customizableProperties, - p, nil) - if err != nil { - if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok { - t.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error()) - } else { - panic(err) - } - } - } + t.appendPrependHelper(props, proptools.PrependMatchingProperties) } // android.topDownMutatorContext either has to embed blueprint.TopDownMutatorContext, in which case every method that |