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,
+ )
+ }
}
}
}
diff --git a/bp2build/bzl_conversion_test.go b/bp2build/bzl_conversion_test.go
index 30c1a5b..32b12e4 100644
--- a/bp2build/bzl_conversion_test.go
+++ b/bp2build/bzl_conversion_test.go
@@ -86,6 +86,7 @@
"soong_module_name": attr.string(mandatory = True),
"soong_module_variant": attr.string(),
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
+ "arch_paths": attr.string_list(),
# bazel_module start
# "label": attr.string(),
# "bp2build_available": attr.bool(),
@@ -114,6 +115,7 @@
"soong_module_name": attr.string(mandatory = True),
"soong_module_variant": attr.string(),
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
+ "arch_paths": attr.string_list(),
"bool_prop": attr.bool(),
"bool_ptr_prop": attr.bool(),
"int64_ptr_prop": attr.int(),
@@ -138,6 +140,7 @@
"soong_module_name": attr.string(mandatory = True),
"soong_module_variant": attr.string(),
"soong_module_deps": attr.label_list(providers = [SoongModuleInfo]),
+ "arch_paths": attr.string_list(),
"bool_prop": attr.bool(),
"bool_ptr_prop": attr.bool(),
"int64_ptr_prop": attr.int(),
diff --git a/bp2build/testing.go b/bp2build/testing.go
index ef3a78f..d65aa0b 100644
--- a/bp2build/testing.go
+++ b/bp2build/testing.go
@@ -28,6 +28,8 @@
Nested_props nestedProps
Nested_props_ptr *nestedProps
+
+ Arch_paths []string `android:"path,arch_variant"`
}
type customModule struct {
@@ -56,7 +58,7 @@
func customModuleFactory() android.Module {
m := customModuleFactoryBase()
- android.InitAndroidModule(m)
+ android.InitAndroidArchModule(m, android.HostAndDeviceSupported, android.MultilibBoth)
return m
}
@@ -114,6 +116,7 @@
type customBazelModuleAttributes struct {
String_prop string
String_list_prop []string
+ Arch_paths bazel.LabelListAttribute
}
type customBazelModule struct {
@@ -137,9 +140,18 @@
return
}
+ paths := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, m.props.Arch_paths))
+
+ for arch, props := range m.GetArchProperties(&customProps{}) {
+ if archProps, ok := props.(*customProps); ok && archProps.Arch_paths != nil {
+ paths.SetValueForArch(arch.Name, android.BazelLabelForModuleSrc(ctx, archProps.Arch_paths))
+ }
+ }
+
attrs := &customBazelModuleAttributes{
String_prop: m.props.String_prop,
String_list_prop: m.props.String_list_prop,
+ Arch_paths: paths,
}
props := bazel.BazelTargetModuleProperties{