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
diff --git a/cc/library.go b/cc/library.go
index 91a09fa..1f21614 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1463,7 +1463,7 @@
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 @@
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 c9352a4..f82e0e9 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -122,6 +122,7 @@
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 2caf0d4..bc61b6c 100644
--- a/cc/sabi.go
+++ b/cc/sabi.go
@@ -22,10 +22,16 @@
)
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 @@
// 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)
}