Store ndkKnownLibs in the config
Storing ndkKnownLibs prevents multiple tests from running in parallel
as one may be writing to the list while another is reading from it.
Store it in the config so each test has its own copy.
Test: go test -race ./apex
Change-Id: Iba57c9494012c9e0ae9e5ffaa63b9b2bd2c77492
diff --git a/cc/ndk_library.go b/cc/ndk_library.go
index 9097e7b..a5c43fe 100644
--- a/cc/ndk_library.go
+++ b/cc/ndk_library.go
@@ -45,8 +45,7 @@
ndkLibrarySuffix = ".ndk"
- // Added as a variation dependency via depsMutator.
- ndkKnownLibs = []string{}
+ ndkKnownLibsKey = android.NewOnceKey("ndkKnownLibsKey")
// protects ndkKnownLibs writes during parallel BeginMutator.
ndkKnownLibsLock sync.Mutex
)
@@ -158,6 +157,12 @@
return true
}
+func getNDKKnownLibs(config android.Config) *[]string {
+ return config.Once(ndkKnownLibsKey, func() interface{} {
+ return &[]string{}
+ }).(*[]string)
+}
+
func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
c.baseCompiler.compilerInit(ctx)
@@ -168,12 +173,13 @@
ndkKnownLibsLock.Lock()
defer ndkKnownLibsLock.Unlock()
- for _, lib := range ndkKnownLibs {
+ ndkKnownLibs := getNDKKnownLibs(ctx.Config())
+ for _, lib := range *ndkKnownLibs {
if lib == name {
return
}
}
- ndkKnownLibs = append(ndkKnownLibs, name)
+ *ndkKnownLibs = append(*ndkKnownLibs, name)
}
func addStubLibraryCompilerFlags(flags Flags) Flags {