summaryrefslogtreecommitdiff
path: root/android/proto.go
diff options
context:
space:
mode:
Diffstat (limited to 'android/proto.go')
-rw-r--r--android/proto.go53
1 files changed, 45 insertions, 8 deletions
diff --git a/android/proto.go b/android/proto.go
index 0ffb9b62a..fc21d0177 100644
--- a/android/proto.go
+++ b/android/proto.go
@@ -17,6 +17,7 @@ package android
import (
"path/filepath"
"strings"
+ "sync"
"android/soong/bazel"
@@ -268,12 +269,26 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
protoIncludeDirs = append(protoIncludeDirs, dir)
}
}
+
+ // proto.local_include_dirs are similar to proto.include_dirs, except that it is relative to the module directory
+ for _, dir := range props.Proto.Local_include_dirs {
+ relativeToTop := pathForModuleSrc(ctx, dir).String()
+ protoIncludeDirs = append(protoIncludeDirs, relativeToTop)
+ }
+
} else if props.Proto.Type != info.Type && props.Proto.Type != nil {
ctx.ModuleErrorf("Cannot handle arch-variant types for protos at this time.")
}
}
}
+ if p, ok := m.module.(PkgPathInterface); ok && p.PkgPath(ctx) != nil {
+ // python_library with pkg_path
+ // proto_library for this module should have the pkg_path as the import_prefix
+ attrs.Import_prefix = p.PkgPath(ctx)
+ attrs.Strip_import_prefix = proptools.StringPtr("")
+ }
+
tags := ApexAvailableTagsWithoutTestApexes(ctx.(TopDownMutatorContext), ctx.Module())
moduleDir := ctx.ModuleDir()
@@ -292,9 +307,14 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
// (or a different subpackage), it will not find it.
// The CcProtoGen action itself runs fine because we construct the correct ProtoInfo,
// but the FileDescriptorSet of each proto_library might not be compile-able
- if pkg != ctx.ModuleDir() {
+ //
+ // Add manual tag if either
+ // 1. .proto files are in more than one package
+ // 2. proto.include_dirs is not empty
+ if len(SortedStringKeys(pkgToSrcs)) > 1 || len(protoIncludeDirs) > 0 {
tags.Append(bazel.MakeStringListAttribute([]string{"manual"}))
}
+
ctx.CreateBazelTargetModule(
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
CommonAttributes{Name: name, Dir: proptools.StringPtr(pkg), Tags: tags},
@@ -311,7 +331,8 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
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)
}
@@ -321,15 +342,20 @@ func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs baz
return info, true
}
+// PkgPathInterface is used as a type assertion in bp2build to get pkg_path property of python_library_host
+type PkgPathInterface interface {
+ PkgPath(ctx BazelConversionContext) *string
+}
+
var (
protoIncludeDirGeneratedSuffix = ".include_dir_bp2build_generated_proto"
protoIncludeDirsBp2buildKey = NewOnceKey("protoIncludeDirsBp2build")
)
-func getProtoIncludeDirsBp2build(config Config) *map[protoIncludeDirKey]bool {
+func getProtoIncludeDirsBp2build(config Config) *sync.Map {
return config.Once(protoIncludeDirsBp2buildKey, func() interface{} {
- return &map[protoIncludeDirKey]bool{}
- }).(*map[protoIncludeDirKey]bool)
+ return &sync.Map{}
+ }).(*sync.Map)
}
// key for dynamically creating proto_library per proto.include_dirs
@@ -359,11 +385,10 @@ func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, include
Label: "//" + pkg + ":" + label,
})
key := protoIncludeDirKey{dir: dir, subpackgeInDir: pkg}
- if _, exists := (*dirMap)[key]; exists {
+ if _, exists := dirMap.LoadOrStore(key, true); exists {
// A proto_library has already been created for this package relative to this include dir
continue
}
- (*dirMap)[key] = true
srcs := protoLabelelsPartitionedByPkg[pkg]
rel, err := filepath.Rel(dir, pkg)
if err != nil {
@@ -377,7 +402,18 @@ func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, include
if 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)
+ // Add android and linux explicitly so that fillcommonbp2buildmoduleattrs can override these configs
+ // When we extend b support for other os'es (darwin/windows), we should add those configs here as well
+ alwaysEnabled.SetSelectValue(bazel.OsConfigurationAxis, bazel.OsAndroid, proptools.BoolPtr(true))
+ alwaysEnabled.SetSelectValue(bazel.OsConfigurationAxis, bazel.OsLinux, proptools.BoolPtr(true))
+
+ ctx.CreateBazelTargetModuleWithRestrictions(
bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
CommonAttributes{
Name: label,
@@ -387,6 +423,7 @@ func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, include
Tags: bazel.MakeStringListAttribute([]string{"manual"}),
},
&attrs,
+ alwaysEnabled,
)
}
}