Loading bp2build/build_conversion.go +13 −0 Original line number Diff line number Diff line Loading @@ -575,6 +575,19 @@ func extractStructProperties(structValue reflect.Value, indent int) map[string]s // 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) Loading bp2build/build_conversion_test.go +24 −0 Original line number Diff line number Diff line Loading @@ -319,6 +319,30 @@ custom { "//build/bazel/platforms/arch:x86": [":dep"], "//conditions:default": [], }), )`, }, }, { blueprint: `custom { name: "embedded_props", embedded_prop: "abc", bazel_module: { bp2build_available: true }, }`, expectedBazelTargets: []string{`custom( name = "embedded_props", embedded_attr = "abc", )`, }, }, { blueprint: `custom { name: "ptr_to_embedded_props", other_embedded_prop: "abc", bazel_module: { bp2build_available: true }, }`, expectedBazelTargets: []string{`custom( name = "ptr_to_embedded_props", other_embedded_attr = "abc", )`, }, }, Loading bp2build/bzl_conversion.go +9 −2 Original line number Diff line number Diff line Loading @@ -160,8 +160,15 @@ func extractPropertyDescriptionsFromStruct(structType reflect.Type) []property { if shouldSkipStructField(field) { continue } properties = append(properties, extractPropertyDescriptions(field.Name, field.Type)...) subProps := extractPropertyDescriptions(field.Name, field.Type) // if the struct is embedded (anonymous), flatten the properties into the containing struct if field.Anonymous { for _, prop := range subProps { properties = append(properties, prop.properties...) } } else { properties = append(properties, subProps...) } } return properties } Loading bp2build/bzl_conversion_test.go +6 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ custom = rule( # bazel_module end "bool_prop": attr.bool(), "bool_ptr_prop": attr.bool(), "embedded_prop": attr.string(), "int64_ptr_prop": attr.int(), # nested_props start # "nested_prop": attr.string(), Loading @@ -99,6 +100,7 @@ custom = rule( # nested_props_ptr start # "nested_prop": attr.string(), # nested_props_ptr end "other_embedded_prop": attr.string(), "string_list_prop": attr.string_list(), "string_prop": attr.string(), "string_ptr_prop": attr.string(), Loading @@ -118,6 +120,7 @@ custom_defaults = rule( "arch_paths_exclude": attr.string_list(), "bool_prop": attr.bool(), "bool_ptr_prop": attr.bool(), "embedded_prop": attr.string(), "int64_ptr_prop": attr.int(), # nested_props start # "nested_prop": attr.string(), Loading @@ -125,6 +128,7 @@ custom_defaults = rule( # nested_props_ptr start # "nested_prop": attr.string(), # nested_props_ptr end "other_embedded_prop": attr.string(), "string_list_prop": attr.string_list(), "string_prop": attr.string(), "string_ptr_prop": attr.string(), Loading @@ -144,6 +148,7 @@ custom_test_ = rule( "arch_paths_exclude": attr.string_list(), "bool_prop": attr.bool(), "bool_ptr_prop": attr.bool(), "embedded_prop": attr.string(), "int64_ptr_prop": attr.int(), # nested_props start # "nested_prop": attr.string(), Loading @@ -151,6 +156,7 @@ custom_test_ = rule( # nested_props_ptr start # "nested_prop": attr.string(), # nested_props_ptr end "other_embedded_prop": attr.string(), "string_list_prop": attr.string_list(), "string_prop": attr.string(), "string_ptr_prop": attr.string(), Loading bp2build/testing.go +25 −0 Original line number Diff line number Diff line Loading @@ -148,7 +148,18 @@ type nestedProps struct { Nested_prop string } type EmbeddedProps struct { Embedded_prop string } type OtherEmbeddedProps struct { Other_embedded_prop string } type customProps struct { EmbeddedProps *OtherEmbeddedProps Bool_prop bool Bool_ptr_prop *bool // Ensure that properties tagged `blueprint:mutated` are omitted Loading Loading @@ -246,7 +257,17 @@ func customDefaultsModuleFactory() android.Module { return m } type EmbeddedAttr struct { Embedded_attr string } type OtherEmbeddedAttr struct { Other_embedded_attr string } type customBazelModuleAttributes struct { EmbeddedAttr *OtherEmbeddedAttr String_prop string String_list_prop []string Arch_paths bazel.LabelListAttribute Loading Loading @@ -275,6 +296,10 @@ func customBp2BuildMutator(ctx android.TopDownMutatorContext) { String_list_prop: m.props.String_list_prop, Arch_paths: paths, } attrs.Embedded_attr = m.props.Embedded_prop if m.props.OtherEmbeddedProps != nil { attrs.OtherEmbeddedAttr = &OtherEmbeddedAttr{Other_embedded_attr: m.props.OtherEmbeddedProps.Other_embedded_prop} } props := bazel.BazelTargetModuleProperties{ Rule_class: "custom", Loading Loading
bp2build/build_conversion.go +13 −0 Original line number Diff line number Diff line Loading @@ -575,6 +575,19 @@ func extractStructProperties(structValue reflect.Value, indent int) map[string]s // 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) Loading
bp2build/build_conversion_test.go +24 −0 Original line number Diff line number Diff line Loading @@ -319,6 +319,30 @@ custom { "//build/bazel/platforms/arch:x86": [":dep"], "//conditions:default": [], }), )`, }, }, { blueprint: `custom { name: "embedded_props", embedded_prop: "abc", bazel_module: { bp2build_available: true }, }`, expectedBazelTargets: []string{`custom( name = "embedded_props", embedded_attr = "abc", )`, }, }, { blueprint: `custom { name: "ptr_to_embedded_props", other_embedded_prop: "abc", bazel_module: { bp2build_available: true }, }`, expectedBazelTargets: []string{`custom( name = "ptr_to_embedded_props", other_embedded_attr = "abc", )`, }, }, Loading
bp2build/bzl_conversion.go +9 −2 Original line number Diff line number Diff line Loading @@ -160,8 +160,15 @@ func extractPropertyDescriptionsFromStruct(structType reflect.Type) []property { if shouldSkipStructField(field) { continue } properties = append(properties, extractPropertyDescriptions(field.Name, field.Type)...) subProps := extractPropertyDescriptions(field.Name, field.Type) // if the struct is embedded (anonymous), flatten the properties into the containing struct if field.Anonymous { for _, prop := range subProps { properties = append(properties, prop.properties...) } } else { properties = append(properties, subProps...) } } return properties } Loading
bp2build/bzl_conversion_test.go +6 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,7 @@ custom = rule( # bazel_module end "bool_prop": attr.bool(), "bool_ptr_prop": attr.bool(), "embedded_prop": attr.string(), "int64_ptr_prop": attr.int(), # nested_props start # "nested_prop": attr.string(), Loading @@ -99,6 +100,7 @@ custom = rule( # nested_props_ptr start # "nested_prop": attr.string(), # nested_props_ptr end "other_embedded_prop": attr.string(), "string_list_prop": attr.string_list(), "string_prop": attr.string(), "string_ptr_prop": attr.string(), Loading @@ -118,6 +120,7 @@ custom_defaults = rule( "arch_paths_exclude": attr.string_list(), "bool_prop": attr.bool(), "bool_ptr_prop": attr.bool(), "embedded_prop": attr.string(), "int64_ptr_prop": attr.int(), # nested_props start # "nested_prop": attr.string(), Loading @@ -125,6 +128,7 @@ custom_defaults = rule( # nested_props_ptr start # "nested_prop": attr.string(), # nested_props_ptr end "other_embedded_prop": attr.string(), "string_list_prop": attr.string_list(), "string_prop": attr.string(), "string_ptr_prop": attr.string(), Loading @@ -144,6 +148,7 @@ custom_test_ = rule( "arch_paths_exclude": attr.string_list(), "bool_prop": attr.bool(), "bool_ptr_prop": attr.bool(), "embedded_prop": attr.string(), "int64_ptr_prop": attr.int(), # nested_props start # "nested_prop": attr.string(), Loading @@ -151,6 +156,7 @@ custom_test_ = rule( # nested_props_ptr start # "nested_prop": attr.string(), # nested_props_ptr end "other_embedded_prop": attr.string(), "string_list_prop": attr.string_list(), "string_prop": attr.string(), "string_ptr_prop": attr.string(), Loading
bp2build/testing.go +25 −0 Original line number Diff line number Diff line Loading @@ -148,7 +148,18 @@ type nestedProps struct { Nested_prop string } type EmbeddedProps struct { Embedded_prop string } type OtherEmbeddedProps struct { Other_embedded_prop string } type customProps struct { EmbeddedProps *OtherEmbeddedProps Bool_prop bool Bool_ptr_prop *bool // Ensure that properties tagged `blueprint:mutated` are omitted Loading Loading @@ -246,7 +257,17 @@ func customDefaultsModuleFactory() android.Module { return m } type EmbeddedAttr struct { Embedded_attr string } type OtherEmbeddedAttr struct { Other_embedded_attr string } type customBazelModuleAttributes struct { EmbeddedAttr *OtherEmbeddedAttr String_prop string String_list_prop []string Arch_paths bazel.LabelListAttribute Loading Loading @@ -275,6 +296,10 @@ func customBp2BuildMutator(ctx android.TopDownMutatorContext) { String_list_prop: m.props.String_list_prop, Arch_paths: paths, } attrs.Embedded_attr = m.props.Embedded_prop if m.props.OtherEmbeddedProps != nil { attrs.OtherEmbeddedAttr = &OtherEmbeddedAttr{Other_embedded_attr: m.props.OtherEmbeddedProps.Other_embedded_prop} } props := bazel.BazelTargetModuleProperties{ Rule_class: "custom", Loading