commit | 32a0339340092a223efa2abfbe972047864490c6 | [log] [tgz] |
---|---|---|
author | Liz Kammer <eakammer@google.com> | Tue Sep 14 11:17:21 2021 -0400 |
committer | Liz Kammer <eakammer@google.com> | Tue Sep 14 14:41:36 2021 -0400 |
tree | 2303fad4af6c9afeb383e8df9482e6adee164576 | |
parent | 4011ebb12d1e474ef6aa2c1895ea32f72b03200f [diff] [blame] |
Bp2build: handle embedded structs as blueprint For structs that are embedded, Blueprint does not nest under the embedded name, flattening them into the original struct for blueprint files (e.g. https://cs.android.com/android/_/android/platform/build/blueprint/+/9fd2ed93dfb82baf7688c1b2b29aa4b2cc125721:proptools/unpack_test.go;l=402-431;drc=3adb2409648d6f8b25354ac47f083dae87731f10). We should do the same for bp2build. This will also allow us to embed structs for bp2build conversion allowing more reuse. Test: go test bp2build tests Change-Id: I9ce088462adaf59bffa80bea76cd488e31f98e9d
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go index f652a35..94084af 100644 --- a/bp2build/build_conversion.go +++ b/bp2build/build_conversion.go
@@ -575,6 +575,19 @@ // Ignore zero-valued fields continue } + // if the struct is embedded (anonymous), flatten the properties into the containing struct + if field.Anonymous { + if field.Type.Kind() == reflect.Ptr { + fieldValue = fieldValue.Elem() + } + if fieldValue.Type().Kind() == reflect.Struct { + propsToMerge := extractStructProperties(fieldValue, indent) + for prop, value := range propsToMerge { + ret[prop] = value + } + continue + } + } propertyName := proptools.PropertyNameForField(field.Name) prettyPrintedValue, err := prettyPrint(fieldValue, indent+1)