Fix possible orphaned proto_library targets
This is a fix for aosp/2693190 that handled .proto files that end up in different bazel packages. It did it by creating proto_library targets in the correct bazel package. Changing the granularity causes issues if the the new proto_library in the subpackage imports a .proto file from a parent package or a different package. e.g. ``` tmp ├── foo.proto └── subdir/import_foo.proto # contains an `import "foo.proto"` └── subdir/Android.bp # package boundary ├── Android.bp # contains a cc_library with foo.proto and # subdir/import_foo.proto ``` At ToT, the ProtoInfo we provide to CcProtoGen is correct, but the proto_library in subdir/BUILD will not compile because it does not have a dep on the proto_library in ./BUILD This CL creates a workaround by adding `manual` to the proto_library targets. This CL is based on the assumption that the buildable unit in bp2build is cc_library_*, and not proto_library necessarily (atleast till we do a manual/automated cleanup) Test: Created an integration test in build/bazel Test: go test ./bp2build Bug: 292583584 Bug: 246997908 Change-Id: I73120be2411967cb144f37ed4417f76ecf1a6ffa
This commit is contained in:
@@ -283,6 +283,15 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO - b/246997908: Handle potential orphaned proto_library targets
|
||||||
|
// To create proto_library targets in the same package, we split the .proto files
|
||||||
|
// This means that if a proto_library in a subpackage imports another proto_library from the parent package
|
||||||
|
// (or a different subpackage), it will not find it.
|
||||||
|
// The CcProtoGen action itself runs fine because we construct the correct ProtoInfo,
|
||||||
|
// but the FileDescriptorSet of each proto_library might not be compile-able
|
||||||
|
if pkg != ctx.ModuleDir() {
|
||||||
|
tags.Append(bazel.MakeStringListAttribute([]string{"manual"}))
|
||||||
|
}
|
||||||
ctx.CreateBazelTargetModule(
|
ctx.CreateBazelTargetModule(
|
||||||
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
||||||
CommonAttributes{Name: name, Dir: proptools.StringPtr(pkg), Tags: tags},
|
CommonAttributes{Name: name, Dir: proptools.StringPtr(pkg), Tags: tags},
|
||||||
|
@@ -4967,6 +4967,7 @@ cc_library_static {
|
|||||||
tc.ExpectedBazelTargets = []string{
|
tc.ExpectedBazelTargets = []string{
|
||||||
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
|
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
|
||||||
"srcs": `["//bar:bar.proto"]`,
|
"srcs": `["//bar:bar.proto"]`,
|
||||||
|
"tags": `["manual"]`,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
runCcLibraryTestCase(t, tc)
|
runCcLibraryTestCase(t, tc)
|
||||||
@@ -4976,6 +4977,7 @@ cc_library_static {
|
|||||||
tc.ExpectedBazelTargets = []string{
|
tc.ExpectedBazelTargets = []string{
|
||||||
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
|
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
|
||||||
"srcs": `["//baz/subbaz:baz.proto"]`,
|
"srcs": `["//baz/subbaz:baz.proto"]`,
|
||||||
|
"tags": `["manual"]`,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
runCcLibraryTestCase(t, tc)
|
runCcLibraryTestCase(t, tc)
|
||||||
@@ -5035,6 +5037,7 @@ cc_library_static {
|
|||||||
"srcs": `["//bar:bar.proto"]`,
|
"srcs": `["//bar:bar.proto"]`,
|
||||||
"strip_import_prefix": `""`,
|
"strip_import_prefix": `""`,
|
||||||
"import_prefix": `"bar"`,
|
"import_prefix": `"bar"`,
|
||||||
|
"tags": `["manual"]`,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
runCcLibraryTestCase(t, tc)
|
runCcLibraryTestCase(t, tc)
|
||||||
@@ -5046,6 +5049,7 @@ cc_library_static {
|
|||||||
"srcs": `["//baz/subbaz:baz.proto"]`,
|
"srcs": `["//baz/subbaz:baz.proto"]`,
|
||||||
"strip_import_prefix": `""`,
|
"strip_import_prefix": `""`,
|
||||||
"import_prefix": `"baz/subbaz"`,
|
"import_prefix": `"baz/subbaz"`,
|
||||||
|
"tags": `["manual"]`,
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
runCcLibraryTestCase(t, tc)
|
runCcLibraryTestCase(t, tc)
|
||||||
|
Reference in New Issue
Block a user