bp2build; Update handling of linker flags
Test: build/bazel/ci/bp2build.sh
Bug: 197920036
Change-Id: I6e3100574fa0e40bcd8cf0e6af0efd3310aa41bf
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index c05a62b..aa1cf70 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -239,9 +239,7 @@
func propsToAttributes(props map[string]string) string {
var attributes string
for _, propName := range android.SortedStringKeys(props) {
- if shouldGenerateAttribute(propName) {
- attributes += fmt.Sprintf(" %s = %s,\n", propName, props[propName])
- }
+ attributes += fmt.Sprintf(" %s = %s,\n", propName, props[propName])
}
return attributes
}
@@ -422,7 +420,8 @@
attrs := m.BazelAttributes()
props := extractModuleProperties(attrs, true)
- delete(props.Attrs, "bp2build_available")
+ // name is handled in a special manner
+ delete(props.Attrs, "name")
// Return the Bazel target with rule class and attributes, ready to be
// code-generated.
@@ -457,6 +456,10 @@
depLabels[qualifiedTargetLabel(ctx, depModule)] = true
})
}
+
+ for p, _ := range ignoredPropNames {
+ delete(props.Attrs, p)
+ }
attributes := propsToAttributes(props.Attrs)
depLabelList := "[\n"
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index bfe88f5..8c2fe7b 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -873,7 +873,7 @@
})
}
-func TestCcLibraryPackRelocations(t *testing.T) {
+func TestCcLibraryFeatures(t *testing.T) {
runCcLibraryTestCase(t, bp2buildTestCase{
description: "cc_library pack_relocations test",
moduleTypeUnderTest: "cc_library",
@@ -884,6 +884,7 @@
name: "a",
srcs: ["a.cpp"],
pack_relocations: false,
+ allow_undefined_symbols: true,
include_build_directory: false,
}
@@ -893,6 +894,7 @@
arch: {
x86_64: {
pack_relocations: false,
+ allow_undefined_symbols: true,
},
},
include_build_directory: false,
@@ -904,25 +906,35 @@
target: {
darwin: {
pack_relocations: false,
+ allow_undefined_symbols: true,
},
},
include_build_directory: false,
}`,
expectedBazelTargets: []string{`cc_library(
name = "a",
- linkopts = ["-Wl,--pack-dyn-relocs=none"],
+ features = [
+ "disable_pack_relocations",
+ "-no_undefined_symbols",
+ ],
srcs = ["a.cpp"],
)`, `cc_library(
name = "b",
- linkopts = select({
- "//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"],
+ features = select({
+ "//build/bazel/platforms/arch:x86_64": [
+ "disable_pack_relocations",
+ "-no_undefined_symbols",
+ ],
"//conditions:default": [],
}),
srcs = ["b.cpp"],
)`, `cc_library(
name = "c",
- linkopts = select({
- "//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"],
+ features = select({
+ "//build/bazel/platforms/os:darwin": [
+ "disable_pack_relocations",
+ "-no_undefined_symbols",
+ ],
"//conditions:default": [],
}),
srcs = ["c.cpp"],