summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2024-10-25 09:53:41 -0700
committer Colin Cross <ccross@android.com> 2024-10-25 10:04:35 -0700
commit50bc3bc677880aceb108a39b0afccf1a7fc36fcb (patch)
treea8ee0b4e10ff96c35aef987c4c9a360394dc528d
parentafcdce8be98bc89de0d2ed4cdc05e5f3ac99b7aa (diff)
Fix race condition when running tests
Tests running in parallel can trigger the race detector on addLsdumpPath vs. reading the global paths in cc/makevars.go. Move the lsdumpPaths variable into the Context instead of a global variable. Test: go test -race ./apex Flag: EXEMPT bugfix Change-Id: I0247358a5b3955d8e0e7d2ef54ce3942d973e948
-rw-r--r--cc/library.go6
-rw-r--r--cc/makevars.go1
-rw-r--r--cc/sabi.go13
3 files changed, 14 insertions, 6 deletions
diff --git a/cc/library.go b/cc/library.go
index 91a09fac7..1f2161494 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1463,7 +1463,7 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, deps PathD
headerAbiChecker.Exclude_symbol_tags,
currVendorVersion)
}
- addLsdumpPath(string(tag) + ":" + llndkDump.String())
+ addLsdumpPath(ctx.Config(), string(tag)+":"+llndkDump.String())
} else if tag == apexLsdumpTag {
if apexVariantDump == nil {
apexVariantDump = library.linkApexSAbiDumpFiles(ctx,
@@ -1472,12 +1472,12 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, deps PathD
headerAbiChecker.Exclude_symbol_tags,
currSdkVersion)
}
- addLsdumpPath(string(tag) + ":" + apexVariantDump.String())
+ addLsdumpPath(ctx.Config(), string(tag)+":"+apexVariantDump.String())
} else {
if tag.dirName() == "" {
optInTags = append(optInTags, tag)
}
- addLsdumpPath(string(tag) + ":" + implDump.String())
+ addLsdumpPath(ctx.Config(), string(tag)+":"+implDump.String())
}
}
diff --git a/cc/makevars.go b/cc/makevars.go
index c9352a4ad..f82e0e90e 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -122,6 +122,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
sort.Strings(exportedVendorPublicLibraries)
ctx.Strict("VENDOR_PUBLIC_LIBRARIES", strings.Join(exportedVendorPublicLibraries, " "))
+ lsdumpPaths := *lsdumpPaths(ctx.Config())
sort.Strings(lsdumpPaths)
ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " "))
diff --git a/cc/sabi.go b/cc/sabi.go
index 2caf0d470..bc61b6cb5 100644
--- a/cc/sabi.go
+++ b/cc/sabi.go
@@ -22,10 +22,16 @@ import (
)
var (
- lsdumpPaths []string
lsdumpPathsLock sync.Mutex
+ lsdumpKey = android.NewOnceKey("lsdump")
)
+func lsdumpPaths(config android.Config) *[]string {
+ return config.Once(lsdumpKey, func() any {
+ return &[]string{}
+ }).(*[]string)
+}
+
type lsdumpTag string
const (
@@ -291,8 +297,9 @@ func (s *sabiTransitionMutator) Mutate(ctx android.BottomUpMutatorContext, varia
// Add an entry to the global list of lsdump. The list is exported to a Make variable by
// `cc.makeVarsProvider`.
-func addLsdumpPath(lsdumpPath string) {
+func addLsdumpPath(config android.Config, lsdumpPath string) {
+ lsdumpPaths := lsdumpPaths(config)
lsdumpPathsLock.Lock()
defer lsdumpPathsLock.Unlock()
- lsdumpPaths = append(lsdumpPaths, lsdumpPath)
+ *lsdumpPaths = append(*lsdumpPaths, lsdumpPath)
}