Fix race CommonGlobalCflags when running tests in parallel.
Clone the commonGlobalCflags global variable when modifying it so that
it gets a unique object per context.
Test: go test -race ./...
Change-Id: Ia4b91c40939d4b4d338bd11e4d4f523521874548
diff --git a/cc/config/global.go b/cc/config/global.go
index 85ebd60..ec6dbce 100644
--- a/cc/config/global.go
+++ b/cc/config/global.go
@@ -16,6 +16,7 @@
import (
"runtime"
+ "slices"
"strings"
"android/soong/android"
@@ -400,7 +401,7 @@
exportedVars.ExportStringList("CommonGlobalCflags", commonGlobalCflags)
pctx.VariableFunc("CommonGlobalCflags", func(ctx android.PackageVarContext) string {
- flags := commonGlobalCflags
+ flags := slices.Clone(commonGlobalCflags)
// http://b/131390872
// Automatically initialize any uninitialized stack variables.