Add StringAttribute for bp2building
Instead of a StringListAttribute of length 1,
introduce a more appropriately reduced StringAttribute
so that e.g. `select`s work properly
Test: new cases in TestGenerateBazelTargetModules
Change-Id: I0ae0e4a51e39f85caf55b0d00459222ede6de79c
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index c5644ed..1ac7518 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -231,6 +231,52 @@
func TestGenerateBazelTargetModules(t *testing.T) {
testCases := []Bp2buildTestCase{
{
+ Description: "string prop empty",
+ Blueprint: `custom {
+ name: "foo",
+ string_literal_prop: "",
+ bazel_module: { bp2build_available: true },
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("custom", "foo", AttrNameToString{
+ "string_literal_prop": `""`,
+ }),
+ },
+ },
+ {
+ Description: `string prop "PROP"`,
+ Blueprint: `custom {
+ name: "foo",
+ string_literal_prop: "PROP",
+ bazel_module: { bp2build_available: true },
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("custom", "foo", AttrNameToString{
+ "string_literal_prop": `"PROP"`,
+ }),
+ },
+ },
+ {
+ Description: `string prop arch variant`,
+ Blueprint: `custom {
+ name: "foo",
+ arch: {
+ arm: { string_literal_prop: "ARM" },
+ arm64: { string_literal_prop: "ARM64" },
+ },
+ bazel_module: { bp2build_available: true },
+}`,
+ ExpectedBazelTargets: []string{
+ makeBazelTarget("custom", "foo", AttrNameToString{
+ "string_literal_prop": `select({
+ "//build/bazel/platforms/arch:arm": "ARM",
+ "//build/bazel/platforms/arch:arm64": "ARM64",
+ "//conditions:default": None,
+ })`,
+ }),
+ },
+ },
+ {
Description: "string ptr props",
Blueprint: `custom {
name: "foo",
@@ -244,7 +290,7 @@
},
},
{
- Description: "string props",
+ Description: "string list props",
Blueprint: `custom {
name: "foo",
string_list_prop: ["a", "b"],