Loading bazel/properties.go +5 −0 Original line number Diff line number Diff line Loading @@ -674,6 +674,11 @@ type LabelListAttribute struct { // specific select statements where an empty list for a non-default select // key has a meaning. EmitEmptyList bool // If a property has struct tag "variant_prepend", this value should // be set to True, so that when bp2build generates BUILD.bazel, variant // properties(select ...) come before general properties. Prepend bool } type configurableLabelLists map[ConfigurationAxis]labelListSelectValues Loading bp2build/cc_library_headers_conversion_test.go +4 −2 Original line number Diff line number Diff line Loading @@ -186,6 +186,8 @@ func TestCcApiHeaders(t *testing.T) { }) } // header_libs has "variant_prepend" tag. In bp2build output, // variant info(select) should go before general info. func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ Description: "cc_library_headers test with os-specific header_libs props", Loading Loading @@ -247,14 +249,14 @@ cc_library_headers { }`, ExpectedBazelTargets: []string{ MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "deps": `[":base-lib"] + select({ "deps": `select({ "//build/bazel/platforms/os:android": [":android-lib"], "//build/bazel/platforms/os:darwin": [":darwin-lib"], "//build/bazel/platforms/os:linux_bionic": [":linux_bionic-lib"], "//build/bazel/platforms/os:linux_glibc": [":linux-lib"], "//build/bazel/platforms/os:windows": [":windows-lib"], "//conditions:default": [], })`, }) + [":base-lib"]`, }), }, }) Loading bp2build/cc_library_static_conversion_test.go +6 −4 Original line number Diff line number Diff line Loading @@ -1003,6 +1003,8 @@ cc_library_static { }) } // generated_headers has "variant_prepend" tag. In bp2build output, // variant info(select) should go before general info. func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) { runCcLibraryStaticTestCase(t, Bp2buildTestCase{ Description: "cc_library_static arch srcs/exclude_srcs with generated files", Loading Loading @@ -1066,13 +1068,13 @@ cc_library_static { "//build/bazel/platforms/os:android": [":generated_src_android"], "//conditions:default": [], })`, "hdrs": `["//dep:generated_hdr_other_pkg"] + select({ "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"], "hdrs": `select({ "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"], "//conditions:default": [], }) + select({ "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"], "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"], "//conditions:default": [], })`, }) + ["//dep:generated_hdr_other_pkg"]`, "local_includes": `["."]`, "export_absolute_includes": `["dep"]`, }), Loading bp2build/configurability.go +4 −3 Original line number Diff line number Diff line Loading @@ -106,8 +106,9 @@ func getBoolValue(boolAttr bazel.BoolAttribute) (reflect.Value, []selects) { return value, []selects{ret} } func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects) { func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects, bool) { value := reflect.ValueOf(list.Value.Includes) prepend := list.Prepend var ret []selects for _, axis := range list.SortedConfigurationAxes() { configToLabels := list.ConfigurableValues[axis] Loading @@ -133,7 +134,7 @@ func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects } } return value, ret return value, ret, prepend } func labelListSelectValue(selectKey string, list bazel.LabelList, emitEmptyList bool) (bool, reflect.Value) { Loading Loading @@ -173,7 +174,7 @@ func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) { value, configurableAttrs, prepend = getStringListValues(list) defaultSelectValue = &emptyBazelList case bazel.LabelListAttribute: value, configurableAttrs = getLabelListValues(list) value, configurableAttrs, prepend = getLabelListValues(list) emitZeroValues = list.EmitEmptyList defaultSelectValue = &emptyBazelList if list.ForceSpecifyEmptyList && (!value.IsNil() || list.HasConfigurableValues()) { Loading cc/bp2build.go +6 −0 Original line number Diff line number Diff line Loading @@ -804,6 +804,12 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) (&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs)) } linkerAttrs.wholeArchiveDeps.Prepend = true linkerAttrs.deps.Prepend = true compilerAttrs.localIncludes.Prepend = true compilerAttrs.absoluteIncludes.Prepend = true compilerAttrs.hdrs.Prepend = true features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module)) features.DeduplicateAxesFromBase() Loading Loading
bazel/properties.go +5 −0 Original line number Diff line number Diff line Loading @@ -674,6 +674,11 @@ type LabelListAttribute struct { // specific select statements where an empty list for a non-default select // key has a meaning. EmitEmptyList bool // If a property has struct tag "variant_prepend", this value should // be set to True, so that when bp2build generates BUILD.bazel, variant // properties(select ...) come before general properties. Prepend bool } type configurableLabelLists map[ConfigurationAxis]labelListSelectValues Loading
bp2build/cc_library_headers_conversion_test.go +4 −2 Original line number Diff line number Diff line Loading @@ -186,6 +186,8 @@ func TestCcApiHeaders(t *testing.T) { }) } // header_libs has "variant_prepend" tag. In bp2build output, // variant info(select) should go before general info. func TestCcLibraryHeadersOsSpecificHeader(t *testing.T) { runCcLibraryHeadersTestCase(t, Bp2buildTestCase{ Description: "cc_library_headers test with os-specific header_libs props", Loading Loading @@ -247,14 +249,14 @@ cc_library_headers { }`, ExpectedBazelTargets: []string{ MakeBazelTarget("cc_library_headers", "foo_headers", AttrNameToString{ "deps": `[":base-lib"] + select({ "deps": `select({ "//build/bazel/platforms/os:android": [":android-lib"], "//build/bazel/platforms/os:darwin": [":darwin-lib"], "//build/bazel/platforms/os:linux_bionic": [":linux_bionic-lib"], "//build/bazel/platforms/os:linux_glibc": [":linux-lib"], "//build/bazel/platforms/os:windows": [":windows-lib"], "//conditions:default": [], })`, }) + [":base-lib"]`, }), }, }) Loading
bp2build/cc_library_static_conversion_test.go +6 −4 Original line number Diff line number Diff line Loading @@ -1003,6 +1003,8 @@ cc_library_static { }) } // generated_headers has "variant_prepend" tag. In bp2build output, // variant info(select) should go before general info. func TestCcLibraryStaticArchSrcsExcludeSrcsGeneratedFiles(t *testing.T) { runCcLibraryStaticTestCase(t, Bp2buildTestCase{ Description: "cc_library_static arch srcs/exclude_srcs with generated files", Loading Loading @@ -1066,13 +1068,13 @@ cc_library_static { "//build/bazel/platforms/os:android": [":generated_src_android"], "//conditions:default": [], })`, "hdrs": `["//dep:generated_hdr_other_pkg"] + select({ "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"], "hdrs": `select({ "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"], "//conditions:default": [], }) + select({ "//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"], "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"], "//conditions:default": [], })`, }) + ["//dep:generated_hdr_other_pkg"]`, "local_includes": `["."]`, "export_absolute_includes": `["dep"]`, }), Loading
bp2build/configurability.go +4 −3 Original line number Diff line number Diff line Loading @@ -106,8 +106,9 @@ func getBoolValue(boolAttr bazel.BoolAttribute) (reflect.Value, []selects) { return value, []selects{ret} } func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects) { func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects, bool) { value := reflect.ValueOf(list.Value.Includes) prepend := list.Prepend var ret []selects for _, axis := range list.SortedConfigurationAxes() { configToLabels := list.ConfigurableValues[axis] Loading @@ -133,7 +134,7 @@ func getLabelListValues(list bazel.LabelListAttribute) (reflect.Value, []selects } } return value, ret return value, ret, prepend } func labelListSelectValue(selectKey string, list bazel.LabelList, emitEmptyList bool) (bool, reflect.Value) { Loading Loading @@ -173,7 +174,7 @@ func prettyPrintAttribute(v bazel.Attribute, indent int) (string, error) { value, configurableAttrs, prepend = getStringListValues(list) defaultSelectValue = &emptyBazelList case bazel.LabelListAttribute: value, configurableAttrs = getLabelListValues(list) value, configurableAttrs, prepend = getLabelListValues(list) emitZeroValues = list.EmitEmptyList defaultSelectValue = &emptyBazelList if list.ForceSpecifyEmptyList && (!value.IsNil() || list.HasConfigurableValues()) { Loading
cc/bp2build.go +6 −0 Original line number Diff line number Diff line Loading @@ -804,6 +804,12 @@ func bp2BuildParseBaseProps(ctx android.Bp2buildMutatorContext, module *Module) (&linkerAttrs).wholeArchiveDeps.Add(bp2buildCcSysprop(ctx, module.Name(), module.Properties.Min_sdk_version, compilerAttrs.syspropSrcs)) } linkerAttrs.wholeArchiveDeps.Prepend = true linkerAttrs.deps.Prepend = true compilerAttrs.localIncludes.Prepend = true compilerAttrs.absoluteIncludes.Prepend = true compilerAttrs.hdrs.Prepend = true features := compilerAttrs.features.Clone().Append(linkerAttrs.features).Append(bp2buildSanitizerFeatures(ctx, module)) features.DeduplicateAxesFromBase() Loading