Fix target_compatible_with non-determinism for proto.include_dirs
A single proto providing directory can be used by multiple soong modules. Some of these
can be
1. Host specific
2. Device specific
3. Both host and device
Since the generated proto_library can have 1:many mapping, it should
have an empty target_compatible_with. Compatiblity will be enforced at
the top-level {cc|java|python}_proto_library.
(This is a followup to aosp/2727054 which did not handle this correctly)
Test: Added a unit test
Change-Id: I09b3def70e3d043fd8ba0d1eb4ffff1910f097d1
diff --git a/bp2build/cc_library_conversion_test.go b/bp2build/cc_library_conversion_test.go
index 02ed57a..e50c710 100644
--- a/bp2build/cc_library_conversion_test.go
+++ b/bp2build/cc_library_conversion_test.go
@@ -5241,3 +5241,41 @@
}
runCcLibraryTestCase(t, tc)
}
+
+// `foo_device` and `bar_host` can depend on .proto files of a specific dir,
+// the dynamically generated proto_library should not have any target_compatible_with
+func TestProtoLibraryForIncludeDirsIsOsAgnostic(t *testing.T) {
+ tc := Bp2buildTestCase{
+ Description: "proto_library generated for proto.include_dirs is compatible for all axes",
+ ModuleTypeUnderTest: "cc_library",
+ ModuleTypeUnderTestFactory: cc.LibraryFactory,
+ Blueprint: simpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite") + `
+cc_library {
+ name: "foo_device",
+ device_supported: true, // this is the default behavior, but added explicitly here for illustration
+ host_supported: false,
+ proto: {include_dirs: ["dir"]},
+}
+cc_library {
+ name: "bar_host",
+ device_supported: false,
+ host_supported: true,
+ srcs: ["bar.proto"],
+ proto: {include_dirs: ["dir"]},
+}
+`,
+ Filesystem: map[string]string{
+ "dir/Android.bp": "",
+ "dir/dir.proto": "",
+ },
+ Dir: "dir", // check for the generated proto_library
+ ExpectedBazelTargets: []string{
+ MakeBazelTargetNoRestrictions("proto_library", "dir.include_dir_bp2build_generated_proto", AttrNameToString{
+ "srcs": `["dir.proto"]`,
+ "strip_import_prefix": `""`,
+ "tags": `["manual"]`,
+ }),
+ },
+ }
+ runCcLibraryTestCase(t, tc)
+}