diff options
author | 2022-09-22 16:21:54 +0100 | |
---|---|---|
committer | 2022-09-26 18:28:56 +0100 | |
commit | bfdca968288c930a8d717ceb76349c19bef42fd1 (patch) | |
tree | de6b7ecd2dad4ee5657e4b5f53bdf1b9bd234c08 /sdk/update.go | |
parent | 02e25c85eb32c337b3f8a2033c6c092b8fea91d3 (diff) |
Add sdk:"keep" tag support
Fields tagged with `sdk:"keep"` will keep the value even if it would
normally be cleared because it was common across a number of structs.
This will allow a module type to specify the same value across all
structs populated directly from variants and have it be copied into all
common property structs without clearing it from the variant specific
structs.
Bug: 248258460
Test: m nothing
Change-Id: I147d946b11fd8766a7d875d9206e8f5034f585d6
Diffstat (limited to 'sdk/update.go')
-rw-r--r-- | sdk/update.go | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/sdk/update.go b/sdk/update.go index f20f1d6e9..92a13fa7f 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -2172,6 +2172,11 @@ type extractorProperty struct { // Retrieves the value on which common value optimization will be performed. getter fieldAccessorFunc + // True if the field should never be cleared. + // + // This is set to true if and only if the field is annotated with `sdk:"keep"`. + keep bool + // The empty value for the field. emptyValue reflect.Value @@ -2236,6 +2241,8 @@ func (e *commonValueExtractor) gatherFields(structType reflect.Type, containingS } } + keep := proptools.HasTag(field, "sdk", "keep") + // Save a copy of the field index for use in the function. fieldIndex := f @@ -2275,6 +2282,7 @@ func (e *commonValueExtractor) gatherFields(structType reflect.Type, containingS name, filter, fieldGetter, + keep, reflect.Zero(field.Type), proptools.HasTag(field, "android", "arch_variant"), } @@ -2394,11 +2402,13 @@ func (e *commonValueExtractor) extractCommonProperties(commonProperties interfac if commonValue != nil { emptyValue := property.emptyValue fieldGetter(commonStructValue).Set(*commonValue) - for i := 0; i < sliceValue.Len(); i++ { - container := sliceValue.Index(i).Interface().(propertiesContainer) - itemValue := reflect.ValueOf(container.optimizableProperties()) - fieldValue := fieldGetter(itemValue) - fieldValue.Set(emptyValue) + if !property.keep { + for i := 0; i < sliceValue.Len(); i++ { + container := sliceValue.Index(i).Interface().(propertiesContainer) + itemValue := reflect.ValueOf(container.optimizableProperties()) + fieldValue := fieldGetter(itemValue) + fieldValue.Set(emptyValue) + } } } |