convert java proto libraries with bp2build
Allow java_libraries that depend on protobufs to be converted with bp2build. Bug: 215230097 Test: build/bazel/ci/bp2build.sh Change-Id: I3ce52389e7e4e82755605ee277c1e527a6aebc6b
This commit is contained in:
@@ -16,7 +16,6 @@ package cc
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
@@ -34,12 +33,6 @@ const (
|
||||
protoSrcPartition = "proto"
|
||||
)
|
||||
|
||||
var (
|
||||
// ignoring case, checks for proto or protos as an independent word in the name, whether at the
|
||||
// beginning, end, or middle. e.g. "proto.foo", "bar-protos", "baz_proto_srcs" would all match
|
||||
filegroupLikelyProtoPattern = regexp.MustCompile("(?i)(^|[^a-z])proto(s)?([^a-z]|$)")
|
||||
)
|
||||
|
||||
// staticOrSharedAttributes are the Bazel-ified versions of StaticOrSharedProperties --
|
||||
// properties which apply to either the shared or static version of a cc_library module.
|
||||
type staticOrSharedAttributes struct {
|
||||
@@ -61,46 +54,32 @@ type staticOrSharedAttributes struct {
|
||||
Enabled bazel.BoolAttribute
|
||||
}
|
||||
|
||||
// groupSrcsByExtension partitions `srcs` into groups based on file extension.
|
||||
func groupSrcsByExtension(ctx android.BazelConversionPathContext, srcs bazel.LabelListAttribute) bazel.PartitionToLabelListAttribute {
|
||||
// Check that a module is a filegroup type
|
||||
isFilegroup := func(m blueprint.Module) bool {
|
||||
return ctx.OtherModuleType(m) == "filegroup"
|
||||
}
|
||||
|
||||
// Convert filegroup dependencies into extension-specific filegroups filtered in the filegroup.bzl
|
||||
// macro.
|
||||
addSuffixForFilegroup := func(suffix string) bazel.LabelMapper {
|
||||
return func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
|
||||
m, exists := ctx.ModuleFromName(label.OriginalModuleName)
|
||||
labelStr := label.Label
|
||||
if !exists || !isFilegroup(m) {
|
||||
if !exists || !android.IsFilegroup(ctx, m) {
|
||||
return labelStr, false
|
||||
}
|
||||
return labelStr + suffix, true
|
||||
}
|
||||
}
|
||||
|
||||
isProtoFilegroup := func(ctx bazel.OtherModuleContext, label bazel.Label) (string, bool) {
|
||||
m, exists := ctx.ModuleFromName(label.OriginalModuleName)
|
||||
labelStr := label.Label
|
||||
if !exists || !isFilegroup(m) {
|
||||
return labelStr, false
|
||||
}
|
||||
likelyProtos := filegroupLikelyProtoPattern.MatchString(label.OriginalModuleName)
|
||||
return labelStr, likelyProtos
|
||||
}
|
||||
|
||||
// TODO(b/190006308): Handle language detection of sources in a Bazel rule.
|
||||
partitioned := bazel.PartitionLabelListAttribute(ctx, &srcs, bazel.LabelPartitions{
|
||||
protoSrcPartition: bazel.LabelPartition{Extensions: []string{".proto"}, LabelMapper: isProtoFilegroup},
|
||||
labels := bazel.LabelPartitions{
|
||||
protoSrcPartition: android.ProtoSrcLabelPartition,
|
||||
cSrcPartition: bazel.LabelPartition{Extensions: []string{".c"}, LabelMapper: addSuffixForFilegroup("_c_srcs")},
|
||||
asSrcPartition: bazel.LabelPartition{Extensions: []string{".s", ".S"}, LabelMapper: addSuffixForFilegroup("_as_srcs")},
|
||||
// C++ is the "catch-all" group, and comprises generated sources because we don't
|
||||
// know the language of these sources until the genrule is executed.
|
||||
cppSrcPartition: bazel.LabelPartition{Extensions: []string{".cpp", ".cc", ".cxx", ".mm"}, LabelMapper: addSuffixForFilegroup("_cpp_srcs"), Keep_remainder: true},
|
||||
})
|
||||
}
|
||||
|
||||
return partitioned
|
||||
return bazel.PartitionLabelListAttribute(ctx, &srcs, labels)
|
||||
}
|
||||
|
||||
// bp2BuildParseLibProps returns the attributes for a variant of a cc_library.
|
||||
|
Reference in New Issue
Block a user