Merge "Support proto.include_dirs" am: dd6321213e am: a1afe2023d

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2189729

Change-Id: Iee224de5390858a26eaa1b3597a1494cb5200452
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yu Liu 2022-09-08 19:17:32 +00:00 committed by Automerger Merge Worker
commit fbccc24d22
2 changed files with 61 additions and 1 deletions

View file

@ -15,9 +15,10 @@
package android package android
import ( import (
"android/soong/bazel"
"strings" "strings"
"android/soong/bazel"
"github.com/google/blueprint" "github.com/google/blueprint"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
) )
@ -161,6 +162,13 @@ type Bp2buildProtoInfo struct {
type protoAttrs struct { type protoAttrs struct {
Srcs bazel.LabelListAttribute Srcs bazel.LabelListAttribute
Strip_import_prefix *string Strip_import_prefix *string
Deps bazel.LabelListAttribute
}
// For each package in the include_dirs property a proto_library target should
// be added to the BUILD file in that package and a mapping should be added here
var includeDirsToProtoDeps = map[string]string{
"external/protobuf/src": "//external/protobuf:libprotobuf-proto",
} }
// Bp2buildProtoProperties converts proto properties, creating a proto_library and returning the // Bp2buildProtoProperties converts proto properties, creating a proto_library and returning the
@ -191,6 +199,14 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
path := "" path := ""
attrs.Strip_import_prefix = &path attrs.Strip_import_prefix = &path
} }
for _, dir := range props.Proto.Include_dirs {
if dep, ok := includeDirsToProtoDeps[dir]; ok {
attrs.Deps.Add(bazel.MakeLabelAttribute(dep))
} else {
ctx.PropertyErrorf("Could not find the proto_library target for include dir", dir)
}
}
} else if props.Proto.Type != info.Type && props.Proto.Type != nil { } else if props.Proto.Type != info.Type && props.Proto.Type != nil {
ctx.ModuleErrorf("Cannot handle arch-variant types for protos at this time.") ctx.ModuleErrorf("Cannot handle arch-variant types for protos at this time.")
} }

View file

@ -2217,6 +2217,50 @@ func TestCcLibraryProtoExportHeaders(t *testing.T) {
}) })
} }
func TestCcLibraryProtoIncludeDirs(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
proto: {
include_dirs: ["external/protobuf/src"],
},
include_build_directory: false,
}`,
ExpectedBazelTargets: []string{
MakeBazelTarget("proto_library", "foo_proto", AttrNameToString{
"srcs": `["foo.proto"]`,
"deps": `["//external/protobuf:libprotobuf-proto"]`,
}), MakeBazelTarget("cc_lite_proto_library", "foo_cc_proto_lite", AttrNameToString{
"deps": `[":foo_proto"]`,
}), MakeBazelTarget("cc_library_static", "foo_bp2build_cc_library_static", AttrNameToString{
"deps": `[":libprotobuf-cpp-lite"]`,
"implementation_whole_archive_deps": `[":foo_cc_proto_lite"]`,
}), MakeBazelTarget("cc_library_shared", "foo", AttrNameToString{
"dynamic_deps": `[":libprotobuf-cpp-lite"]`,
}),
},
})
}
func TestCcLibraryProtoIncludeDirsUnknown(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library",
ModuleTypeUnderTestFactory: cc.LibraryFactory,
Blueprint: soongCcProtoPreamble + `cc_library {
name: "foo",
srcs: ["foo.proto"],
proto: {
include_dirs: ["external/protobuf/abc"],
},
include_build_directory: false,
}`,
ExpectedErr: fmt.Errorf("module \"foo\": Could not find the proto_library target for include dir: external/protobuf/abc"),
})
}
func TestCcLibraryProtoFilegroups(t *testing.T) { func TestCcLibraryProtoFilegroups(t *testing.T) {
runCcLibraryTestCase(t, Bp2buildTestCase{ runCcLibraryTestCase(t, Bp2buildTestCase{
ModuleTypeUnderTest: "cc_library", ModuleTypeUnderTest: "cc_library",