diff options
author | 2022-02-04 21:01:20 +0000 | |
---|---|---|
committer | 2022-02-15 21:04:59 +0000 | |
commit | c768102bce5d64f93559a75783edb5509669f58c (patch) | |
tree | a97f73fda34be89600ae76b5db867ad7bdac144b /cc | |
parent | 5ee913f527829e0f3465c50a13825e1a7065288f (diff) |
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
Diffstat (limited to 'cc')
-rw-r--r-- | cc/bp2build.go | 33 | ||||
-rw-r--r-- | cc/proto.go | 2 |
2 files changed, 7 insertions, 28 deletions
diff --git a/cc/bp2build.go b/cc/bp2build.go index 42fc0e494..379d6f246 100644 --- a/cc/bp2build.go +++ b/cc/bp2build.go @@ -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. diff --git a/cc/proto.go b/cc/proto.go index 3cf1453c8..8e6d5ed5f 100644 --- a/cc/proto.go +++ b/cc/proto.go @@ -177,7 +177,7 @@ type bp2buildProtoDeps struct { func bp2buildProto(ctx android.Bp2buildMutatorContext, m *Module, protoSrcs bazel.LabelListAttribute) bp2buildProtoDeps { var ret bp2buildProtoDeps - protoInfo, ok := android.Bp2buildProtoProperties(ctx, m, protoSrcs) + protoInfo, ok := android.Bp2buildProtoProperties(ctx, &m.ModuleBase, protoSrcs) if !ok { return ret } |