summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Spandan Das <spandandas@google.com> 2023-08-29 23:55:49 +0000
committer Spandan Das <spandandas@google.com> 2023-08-29 23:59:20 +0000
commitfc6e64564557b91fd89f58738d0a1669436bb978 (patch)
treebf123c2b695611f758ae674fc72ab9694bc870f1
parent791f60365ea7cb32effa5f312c5f34409282ff98 (diff)
Prevent concurrent read/writes to a map
This should hopefully fix an intermittent flake in bp2build, which is now run by default. Test: go build ./android Change-Id: Ic257a34448ab323df1680cf1990b087ed415a592
-rw-r--r--android/proto.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/android/proto.go b/android/proto.go
index b9365a70f..a44daf0e9 100644
--- a/android/proto.go
+++ b/android/proto.go
@@ -17,6 +17,7 @@ package android
import (
"path/filepath"
"strings"
+ "sync"
"android/soong/bazel"
@@ -348,6 +349,7 @@ type PkgPathInterface interface {
var (
protoIncludeDirGeneratedSuffix = ".include_dir_bp2build_generated_proto"
protoIncludeDirsBp2buildKey = NewOnceKey("protoIncludeDirsBp2build")
+ protoIncludeDirsBp2buildLock sync.Mutex
)
func getProtoIncludeDirsBp2build(config Config) *map[protoIncludeDirKey]bool {
@@ -367,6 +369,9 @@ type protoIncludeDirKey struct {
// might create the targets in a subdirectory of `includeDir`
// Returns the labels of the proto_library targets
func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, includeDirs []string) bazel.LabelList {
+ protoIncludeDirsBp2buildLock.Lock()
+ defer protoIncludeDirsBp2buildLock.Unlock()
+
var ret bazel.LabelList
for _, dir := range includeDirs {
if exists, _, _ := ctx.Config().fs.Exists(filepath.Join(dir, "Android.bp")); !exists {