Add bp2build arch-specific paths mutator
Adds deps for properties tagged `android:"path"` within arch, multilib,
and target properties.
Test: build/bazel/ci/bp2build.sh
Test: m nothing
Bug: 185217298
Change-Id: I0230da399d2c4e984b837f69523fa09eadba3ff1
diff --git a/bp2build/build_conversion_test.go b/bp2build/build_conversion_test.go
index 1ede442..21d7062 100644
--- a/bp2build/build_conversion_test.go
+++ b/bp2build/build_conversion_test.go
@@ -204,8 +204,9 @@
func TestGenerateBazelTargetModules(t *testing.T) {
testCases := []struct {
- bp string
- expectedBazelTarget string
+ name string
+ bp string
+ expectedBazelTargets []string
}{
{
bp: `custom {
@@ -214,7 +215,7 @@
string_prop: "a",
bazel_module: { bp2build_available: true },
}`,
- expectedBazelTarget: `custom(
+ expectedBazelTargets: []string{`custom(
name = "foo",
string_list_prop = [
"a",
@@ -222,6 +223,7 @@
],
string_prop = "a",
)`,
+ },
},
{
bp: `custom {
@@ -230,7 +232,7 @@
string_prop: "a\t\n\r",
bazel_module: { bp2build_available: true },
}`,
- expectedBazelTarget: `custom(
+ expectedBazelTargets: []string{`custom(
name = "control_characters",
string_list_prop = [
"\t",
@@ -238,6 +240,77 @@
],
string_prop = "a\t\n\r",
)`,
+ },
+ },
+ {
+ bp: `custom {
+ name: "has_dep",
+ arch_paths: [":dep"],
+ bazel_module: { bp2build_available: true },
+}
+
+custom {
+ name: "dep",
+ arch_paths: ["abc"],
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{`custom(
+ name = "dep",
+ arch_paths = ["abc"],
+)`,
+ `custom(
+ name = "has_dep",
+ arch_paths = [":dep"],
+)`,
+ },
+ },
+ {
+ bp: `custom {
+ name: "arch_paths",
+ arch: {
+ x86: {
+ arch_paths: ["abc"],
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{`custom(
+ name = "arch_paths",
+ arch_paths = select({
+ "//build/bazel/platforms/arch:x86": ["abc"],
+ "//conditions:default": [],
+ }),
+)`,
+ },
+ },
+ {
+ bp: `custom {
+ name: "has_dep",
+ arch: {
+ x86: {
+ arch_paths: [":dep"],
+ },
+ },
+ bazel_module: { bp2build_available: true },
+}
+
+custom {
+ name: "dep",
+ arch_paths: ["abc"],
+ bazel_module: { bp2build_available: true },
+}`,
+ expectedBazelTargets: []string{`custom(
+ name = "dep",
+ arch_paths = ["abc"],
+)`,
+ `custom(
+ name = "has_dep",
+ arch_paths = select({
+ "//build/bazel/platforms/arch:x86": [":dep"],
+ "//conditions:default": [],
+ }),
+)`,
+ },
},
}
@@ -262,16 +335,18 @@
codegenCtx := NewCodegenContext(config, *ctx.Context, Bp2Build)
bazelTargets := generateBazelTargetsForDir(codegenCtx, dir)
- if actualCount, expectedCount := len(bazelTargets), 1; actualCount != expectedCount {
+ if actualCount, expectedCount := len(bazelTargets), len(testCase.expectedBazelTargets); actualCount != expectedCount {
t.Errorf("Expected %d bazel target, got %d", expectedCount, actualCount)
} else {
- actualBazelTarget := bazelTargets[0]
- if actualBazelTarget.content != testCase.expectedBazelTarget {
- t.Errorf(
- "Expected generated Bazel target to be '%s', got '%s'",
- testCase.expectedBazelTarget,
- actualBazelTarget.content,
- )
+ for i, expectedBazelTarget := range testCase.expectedBazelTargets {
+ actualBazelTarget := bazelTargets[i]
+ if actualBazelTarget.content != expectedBazelTarget {
+ t.Errorf(
+ "Expected generated Bazel target to be '%s', got '%s'",
+ expectedBazelTarget,
+ actualBazelTarget.content,
+ )
+ }
}
}
}