Add variant_prepend support for all the properties in bp2build
This is a follow up of aosp/2336916. All the properties that have
variant_prepend tag are supported in bp2build.
Bug: 261644490
Test: TH and modified tests with updated expected behaviors
Change-Id: I13bb5d4d8fcd38bf153fa9083c9c945aec2dfa19
diff --git a/bazel/properties.go b/bazel/properties.go
index f9cabf2..76450dc 100644
--- a/bazel/properties.go
+++ b/bazel/properties.go
@@ -674,6 +674,11 @@
// 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
diff --git a/bp2build/cc_library_headers_conversion_test.go b/bp2build/cc_library_headers_conversion_test.go
index 32500a0..072f5b3 100644
--- a/bp2build/cc_library_headers_conversion_test.go
+++ b/bp2build/cc_library_headers_conversion_test.go
@@ -186,6 +186,8 @@
})
}
+// 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",
@@ -247,14 +249,14 @@
}`,
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"]`,
}),
},
})
diff --git a/bp2build/cc_library_static_conversion_test.go b/bp2build/cc_library_static_conversion_test.go
index 5a1260f..767f4ad 100644
--- a/bp2build/cc_library_static_conversion_test.go
+++ b/bp2build/cc_library_static_conversion_test.go
@@ -1003,6 +1003,8 @@
})
}
+// 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",
@@ -1066,13 +1068,13 @@
"//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"],
- "//conditions:default": [],
- }) + select({
+ "hdrs": `select({
"//build/bazel/platforms/os:android": ["//dep:generated_hdr_other_pkg_android"],
"//conditions:default": [],
- })`,
+ }) + select({
+ "//build/bazel/platforms/arch:x86": ["//dep:generated_hdr_other_pkg_x86"],
+ "//conditions:default": [],
+ }) + ["//dep:generated_hdr_other_pkg"]`,
"local_includes": `["."]`,
"export_absolute_includes": `["dep"]`,
}),
diff --git a/bp2build/configurability.go b/bp2build/configurability.go
index c630965..987c903 100644
--- a/bp2build/configurability.go
+++ b/bp2build/configurability.go
@@ -106,8 +106,9 @@
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]
@@ -133,7 +134,7 @@
}
}
- return value, ret
+ return value, ret, prepend
}
func labelListSelectValue(selectKey string, list bazel.LabelList, emitEmptyList bool) (bool, reflect.Value) {
@@ -173,7 +174,7 @@
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()) {
diff --git a/cc/bp2build.go b/cc/bp2build.go
index a7ee5d1..d331d89 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -804,6 +804,12 @@
(&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()
diff --git a/cc/object.go b/cc/object.go
index c3a198d..6cb1a30 100644
--- a/cc/object.go
+++ b/cc/object.go
@@ -78,7 +78,7 @@
Static_libs []string `android:"arch_variant,variant_prepend"`
// list of shared library modules should only provide headers for this module.
- Shared_libs []string `android:"arch_variant"`
+ Shared_libs []string `android:"arch_variant,variant_prepend"`
// list of modules that should only provide headers for this module.
Header_libs []string `android:"arch_variant,variant_prepend"`
@@ -178,6 +178,8 @@
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Static_libs))
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Shared_libs))
deps.SetSelectValue(axis, config, android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Header_libs))
+ // static_libs, shared_libs, and header_libs have variant_prepend tag
+ deps.Prepend = true
}
}
}