bp2build: support full/lite protos in cc libs

Test: bp2build.sh
Bug: 200601772
Change-Id: I3a7e00546726bc63b5eb8d5604557c5988a5320b
This commit is contained in:
Liz Kammer
2021-09-28 09:19:17 -04:00
parent a9351ef6e6
commit 12615dbbca
13 changed files with 605 additions and 96 deletions

View File

@@ -24,8 +24,7 @@ import (
)
const (
ccBinaryTypePlaceHolder = "{rule_name}"
compatibleWithPlaceHolder = "{target_compatible_with}"
ccBinaryTypePlaceHolder = "{rule_name}"
)
type testBazelTarget struct {
@@ -84,12 +83,15 @@ func runCcBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
func runCcHostBinaryTestCase(t *testing.T, tc ccBinaryBp2buildTestCase) {
t.Helper()
testCase := tc
for i, t := range testCase.targets {
t.attrs["target_compatible_with"] = `select({
for i, tar := range testCase.targets {
if tar.typ != "cc_binary" {
continue
}
tar.attrs["target_compatible_with"] = `select({
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
"//conditions:default": [],
})`
testCase.targets[i] = t
testCase.targets[i] = tar
}
moduleTypeUnderTest := "cc_binary_host"
t.Run(testCase.description, func(t *testing.T) {
@@ -448,3 +450,51 @@ func TestCcBinaryPropertiesToFeatures(t *testing.T) {
})
}
}
func TestCcBinarySharedProto(t *testing.T) {
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
blueprint: soongCcProtoLibraries + `{rule_name} {
name: "foo",
srcs: ["foo.proto"],
proto: {
canonical_path_from_root: false,
},
include_build_directory: false,
}`,
targets: []testBazelTarget{
{"proto_library", "foo_proto", attrNameToString{
"srcs": `["foo.proto"]`,
}}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{
"deps": `[":foo_proto"]`,
}}, {"cc_binary", "foo", attrNameToString{
"dynamic_deps": `[":libprotobuf-cpp-lite"]`,
"whole_archive_deps": `[":foo_cc_proto_lite"]`,
}},
},
})
}
func TestCcBinaryStaticProto(t *testing.T) {
runCcBinaryTests(t, ccBinaryBp2buildTestCase{
blueprint: soongCcProtoLibraries + `{rule_name} {
name: "foo",
srcs: ["foo.proto"],
static_executable: true,
proto: {
canonical_path_from_root: false,
},
include_build_directory: false,
}`,
targets: []testBazelTarget{
{"proto_library", "foo_proto", attrNameToString{
"srcs": `["foo.proto"]`,
}}, {"cc_lite_proto_library", "foo_cc_proto_lite", attrNameToString{
"deps": `[":foo_proto"]`,
}}, {"cc_binary", "foo", attrNameToString{
"deps": `[":libprotobuf-cpp-lite"]`,
"whole_archive_deps": `[":foo_cc_proto_lite"]`,
"linkshared": `False`,
}},
},
})
}