Support proto.include_dirs

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 to the bp2build code, by this way a proper dependency
relationship can be established and used by bazel.

Bug: 239944064
Test: Added unit tests and manually verified include_dirs can be
properly converted to bazel and used by bazel to build the targets.

Change-Id: I50d8ee21fabcfec0a44487f6e5f3d8a3845e79c3
This commit is contained in:
Yu Liu
2022-08-18 14:46:13 -07:00
parent 9ba17e8702
commit 2d13614b89
2 changed files with 61 additions and 1 deletions

View File

@@ -15,9 +15,10 @@
package android
import (
"android/soong/bazel"
"strings"
"android/soong/bazel"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
)
@@ -161,6 +162,13 @@ type Bp2buildProtoInfo struct {
type protoAttrs struct {
Srcs bazel.LabelListAttribute
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
@@ -191,6 +199,14 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
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 {
ctx.ModuleErrorf("Cannot handle arch-variant types for protos at this time.")
}