Merge "Bugfixes for proto_library (proto.include_dirs)" into main am: 26e2967e54
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2727054 Change-Id: I45f5b2f47ef65cc8320866dfdf291d1722352a15 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -231,6 +231,7 @@ type Bp2buildMutatorContext interface {
|
|||||||
BazelConversionPathContext
|
BazelConversionPathContext
|
||||||
|
|
||||||
CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
|
CreateBazelTargetModule(bazel.BazelTargetModuleProperties, CommonAttributes, interface{})
|
||||||
|
CreateBazelTargetModuleWithRestrictions(bazel.BazelTargetModuleProperties, CommonAttributes, interface{}, bazel.BoolAttribute)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
|
// PreArchBp2BuildMutators adds mutators to be register for converting Android Blueprint modules
|
||||||
|
@@ -330,7 +330,8 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
|
|||||||
Label: l,
|
Label: l,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
protoLibrariesInIncludeDir := createProtoLibraryTargetsForIncludeDirs(ctx, protoIncludeDirs)
|
// Partitioning by packages can create dupes of protoIncludeDirs, so dedupe it first.
|
||||||
|
protoLibrariesInIncludeDir := createProtoLibraryTargetsForIncludeDirs(ctx, SortedUniqueStrings(protoIncludeDirs))
|
||||||
transitiveProtoLibraries.Append(protoLibrariesInIncludeDir)
|
transitiveProtoLibraries.Append(protoLibrariesInIncludeDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +402,13 @@ func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, include
|
|||||||
if rel != "." {
|
if rel != "." {
|
||||||
attrs.Import_prefix = proptools.StringPtr(rel)
|
attrs.Import_prefix = proptools.StringPtr(rel)
|
||||||
}
|
}
|
||||||
ctx.CreateBazelTargetModule(
|
|
||||||
|
// If a specific directory is listed in proto.include_dirs of two separate modules (one host-specific and another device-specific),
|
||||||
|
// we do not want to create the proto_library with target_compatible_with of the first visited of these two modules
|
||||||
|
// As a workarounds, delete `target_compatible_with`
|
||||||
|
alwaysEnabled := bazel.BoolAttribute{}
|
||||||
|
alwaysEnabled.Value = proptools.BoolPtr(true)
|
||||||
|
ctx.CreateBazelTargetModuleWithRestrictions(
|
||||||
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
|
||||||
CommonAttributes{
|
CommonAttributes{
|
||||||
Name: label,
|
Name: label,
|
||||||
@@ -411,6 +418,7 @@ func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, include
|
|||||||
Tags: bazel.MakeStringListAttribute([]string{"manual"}),
|
Tags: bazel.MakeStringListAttribute([]string{"manual"}),
|
||||||
},
|
},
|
||||||
&attrs,
|
&attrs,
|
||||||
|
alwaysEnabled,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5120,7 +5120,7 @@ cc_library_static {
|
|||||||
// bar dir
|
// bar dir
|
||||||
tc.Dir = "bar"
|
tc.Dir = "bar"
|
||||||
tc.ExpectedBazelTargets = []string{
|
tc.ExpectedBazelTargets = []string{
|
||||||
MakeBazelTarget("proto_library", "bar.include_dir_bp2build_generated_proto", AttrNameToString{
|
MakeBazelTargetNoRestrictions("proto_library", "bar.include_dir_bp2build_generated_proto", AttrNameToString{
|
||||||
"srcs": `["bar.proto"]`,
|
"srcs": `["bar.proto"]`,
|
||||||
"strip_import_prefix": `""`,
|
"strip_import_prefix": `""`,
|
||||||
"tags": `["manual"]`,
|
"tags": `["manual"]`,
|
||||||
@@ -5131,7 +5131,7 @@ cc_library_static {
|
|||||||
// bar/baz dir
|
// bar/baz dir
|
||||||
tc.Dir = "bar/baz"
|
tc.Dir = "bar/baz"
|
||||||
tc.ExpectedBazelTargets = []string{
|
tc.ExpectedBazelTargets = []string{
|
||||||
MakeBazelTarget("proto_library", "bar.include_dir_bp2build_generated_proto", AttrNameToString{
|
MakeBazelTargetNoRestrictions("proto_library", "bar.include_dir_bp2build_generated_proto", AttrNameToString{
|
||||||
"srcs": `["//bar/baz:baz.proto"]`,
|
"srcs": `["//bar/baz:baz.proto"]`,
|
||||||
"strip_import_prefix": `""`,
|
"strip_import_prefix": `""`,
|
||||||
"import_prefix": `"baz"`,
|
"import_prefix": `"baz"`,
|
||||||
@@ -5141,6 +5141,52 @@ cc_library_static {
|
|||||||
runCcLibraryTestCase(t, tc)
|
runCcLibraryTestCase(t, tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestProtoIncludeDirsWithSrcsInMultiplePackages(t *testing.T) {
|
||||||
|
tc := Bp2buildTestCase{
|
||||||
|
Description: "cc_library has srcs in multiple bazel packages and uses proto.include_dirs",
|
||||||
|
ModuleTypeUnderTest: "cc_library",
|
||||||
|
ModuleTypeUnderTestFactory: cc.LibraryFactory,
|
||||||
|
Blueprint: `
|
||||||
|
cc_library_static {
|
||||||
|
name: "foo",
|
||||||
|
srcs: [
|
||||||
|
"foo.proto",
|
||||||
|
"bar/bar.proto",
|
||||||
|
],
|
||||||
|
proto: {
|
||||||
|
include_dirs: ["baz"],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
` + simpleModuleDoNotConvertBp2build("cc_library", "libprotobuf-cpp-lite"),
|
||||||
|
Filesystem: map[string]string{
|
||||||
|
"bar/Android.bp": "", // package boundary
|
||||||
|
"baz/Android.bp": "",
|
||||||
|
"baz/baz.proto": "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
tc.ExpectedBazelTargets = []string{
|
||||||
|
MakeBazelTarget("cc_library_static", "foo", AttrNameToString{
|
||||||
|
"local_includes": `["."]`,
|
||||||
|
"deps": `[":libprotobuf-cpp-lite"]`,
|
||||||
|
"implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
|
||||||
|
"srcs": `["foo.proto"]`,
|
||||||
|
"tags": `["manual"]`,
|
||||||
|
}),
|
||||||
|
MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
|
||||||
|
"deps": `[
|
||||||
|
":foo_proto",
|
||||||
|
"//bar:foo_proto",
|
||||||
|
]`,
|
||||||
|
"transitive_deps": `["//baz:baz.include_dir_bp2build_generated_proto"]`,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
runCcLibraryTestCase(t, tc)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestProtoLocalIncludeDirs(t *testing.T) {
|
func TestProtoLocalIncludeDirs(t *testing.T) {
|
||||||
tc := Bp2buildTestCase{
|
tc := Bp2buildTestCase{
|
||||||
Description: "cc_library depends on .proto files using proto.local_include_dirs",
|
Description: "cc_library depends on .proto files using proto.local_include_dirs",
|
||||||
@@ -5187,7 +5233,7 @@ func TestProtoLocalIncludeDirs(t *testing.T) {
|
|||||||
// foo/foo_subdir
|
// foo/foo_subdir
|
||||||
tc.Dir = "foo/foo_subdir"
|
tc.Dir = "foo/foo_subdir"
|
||||||
tc.ExpectedBazelTargets = []string{
|
tc.ExpectedBazelTargets = []string{
|
||||||
MakeBazelTarget("proto_library", "foo.foo_subdir.include_dir_bp2build_generated_proto", AttrNameToString{
|
MakeBazelTargetNoRestrictions("proto_library", "foo.foo_subdir.include_dir_bp2build_generated_proto", AttrNameToString{
|
||||||
"srcs": `["foo_subdir.proto"]`,
|
"srcs": `["foo_subdir.proto"]`,
|
||||||
"strip_import_prefix": `""`,
|
"strip_import_prefix": `""`,
|
||||||
"tags": `["manual"]`,
|
"tags": `["manual"]`,
|
||||||
|
Reference in New Issue
Block a user