diff options
author | Colin Cross <ccross@android.com> | 2015-10-27 18:15:15 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2015-10-31 20:09:58 -0700 |
commit | 0bc7e077ebfe716c6353c6fe5b9c01087867ee12 (patch) | |
tree | 97397f676755e70ca8e9a133faa115b2f0afcde6 /unpack.go | |
parent | 75c938b6ed6b97a2b7a695a37ba6af160c3289fb (diff) | |
download | android_build_blueprint-0bc7e077ebfe716c6353c6fe5b9c01087867ee12.tar.gz android_build_blueprint-0bc7e077ebfe716c6353c6fe5b9c01087867ee12.tar.bz2 android_build_blueprint-0bc7e077ebfe716c6353c6fe5b9c01087867ee12.zip |
Add helpers for extending properties to proptools
It is common for a mutator to append or prepend property structs
together. Add helper functions to append or prepend properties in property
structs. The append operation is defined as appending string and slices
of strings normally, OR-ing bool values, and recursing into embedded
structs, pointers to structs, and interfaces containing pointers to
structs. Appending or prepending the zero value of a property will
always be a no-op.
Diffstat (limited to 'unpack.go')
-rw-r--r-- | unpack.go | 17 |
1 files changed, 3 insertions, 14 deletions
@@ -173,7 +173,7 @@ func unpackStructValue(namePrefix string, structValue reflect.Value, } case reflect.Int, reflect.Uint: - if !hasTag(field, "blueprint", "mutated") { + if !proptools.HasTag(field, "blueprint", "mutated") { panic(fmt.Errorf(`int field %s must be tagged blueprint:"mutated"`, field.Name)) } @@ -192,7 +192,7 @@ func unpackStructValue(namePrefix string, structValue reflect.Value, packedProperty.unpacked = true - if hasTag(field, "blueprint", "mutated") { + if proptools.HasTag(field, "blueprint", "mutated") { errs = append(errs, &Error{ Err: fmt.Errorf("mutated field %s cannot be set in a Blueprint file", propertyName), @@ -204,7 +204,7 @@ func unpackStructValue(namePrefix string, structValue reflect.Value, continue } - if filterKey != "" && !hasTag(field, filterKey, filterValue) { + if filterKey != "" && !proptools.HasTag(field, filterKey, filterValue) { errs = append(errs, &Error{ Err: fmt.Errorf("filtered field %s cannot be set in a Blueprint file", propertyName), @@ -326,17 +326,6 @@ func unpackStruct(namePrefix string, structValue reflect.Value, return unpackStructValue(namePrefix, structValue, propertyMap, filterKey, filterValue) } -func hasTag(field reflect.StructField, name, value string) bool { - tag := field.Tag.Get(name) - for _, entry := range strings.Split(tag, ",") { - if entry == value { - return true - } - } - - return false -} - func HasFilter(field reflect.StructTag) (k, v string, err error) { tag := field.Get("blueprint") for _, entry := range strings.Split(tag, ",") { |