Prepare for a type-safe OnceKey
Add an opaque OnceKey type and use it for all calls to Once in
build/soong. A future patch will convert the arguments to
Once* to OnceKey once users outside build/soong have been updated.
Test: onceper_test.go
Change-Id: Ifcb338e6e603e804e507203c9508d30ffb2df966
diff --git a/cc/compiler.go b/cc/compiler.go
index fbe10b5..0aee0bd 100644
--- a/cc/compiler.go
+++ b/cc/compiler.go
@@ -250,8 +250,8 @@
return false
}
-func addToModuleList(ctx ModuleContext, list string, module string) {
- getNamedMapForConfig(ctx.Config(), list).Store(module, true)
+func addToModuleList(ctx ModuleContext, key android.OnceKey, module string) {
+ getNamedMapForConfig(ctx.Config(), key).Store(module, true)
}
// Create a Flags struct that collects the compile flags from global values,
@@ -503,10 +503,10 @@
if len(compiler.Properties.Srcs) > 0 {
module := ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName()
if inList("-Wno-error", flags.CFlags) || inList("-Wno-error", flags.CppFlags) {
- addToModuleList(ctx, modulesUsingWnoError, module)
+ addToModuleList(ctx, modulesUsingWnoErrorKey, module)
} else if !inList("-Werror", flags.CFlags) && !inList("-Werror", flags.CppFlags) {
if warningsAreAllowed(ctx.ModuleDir()) {
- addToModuleList(ctx, modulesAddedWall, module)
+ addToModuleList(ctx, modulesAddedWallKey, module)
flags.CFlags = append([]string{"-Wall"}, flags.CFlags...)
} else {
flags.CFlags = append([]string{"-Wall", "-Werror"}, flags.CFlags...)
diff --git a/cc/library.go b/cc/library.go
index d716ffa..b4b89d2 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -968,8 +968,10 @@
return library.MutatedProperties.StubsVersion
}
+var versioningMacroNamesListKey = android.NewOnceKey("versioningMacroNamesList")
+
func versioningMacroNamesList(config android.Config) *map[string]string {
- return config.Once("versioningMacroNamesList", func() interface{} {
+ return config.Once(versioningMacroNamesListKey, func() interface{} {
m := make(map[string]string)
return &m
}).(*map[string]string)
@@ -1059,9 +1061,11 @@
}
}
+var stubVersionsKey = android.NewOnceKey("stubVersions")
+
// maps a module name to the list of stubs versions available for the module
func stubsVersionsFor(config android.Config) map[string][]string {
- return config.Once("stubVersions", func() interface{} {
+ return config.Once(stubVersionsKey, func() interface{} {
return make(map[string][]string)
}).(map[string][]string)
}
diff --git a/cc/makevars.go b/cc/makevars.go
index fb567ba..d91735f 100644
--- a/cc/makevars.go
+++ b/cc/makevars.go
@@ -24,24 +24,24 @@
"android/soong/cc/config"
)
-const (
- modulesAddedWall = "ModulesAddedWall"
- modulesUsingWnoError = "ModulesUsingWnoError"
- modulesMissingProfileFile = "ModulesMissingProfileFile"
+var (
+ modulesAddedWallKey = android.NewOnceKey("ModulesAddedWall")
+ modulesUsingWnoErrorKey = android.NewOnceKey("ModulesUsingWnoError")
+ modulesMissingProfileFileKey = android.NewOnceKey("ModulesMissingProfileFile")
)
func init() {
android.RegisterMakeVarsProvider(pctx, makeVarsProvider)
}
-func getNamedMapForConfig(config android.Config, name string) *sync.Map {
- return config.Once(name, func() interface{} {
+func getNamedMapForConfig(config android.Config, key android.OnceKey) *sync.Map {
+ return config.Once(key, func() interface{} {
return &sync.Map{}
}).(*sync.Map)
}
-func makeStringOfKeys(ctx android.MakeVarsContext, setName string) string {
- set := getNamedMapForConfig(ctx.Config(), setName)
+func makeStringOfKeys(ctx android.MakeVarsContext, key android.OnceKey) string {
+ set := getNamedMapForConfig(ctx.Config(), key)
keys := []string{}
set.Range(func(key interface{}, value interface{}) bool {
keys = append(keys, key.(string))
@@ -117,9 +117,9 @@
ctx.Strict("LSDUMP_PATHS", strings.Join(lsdumpPaths, " "))
ctx.Strict("ANDROID_WARNING_ALLOWED_PROJECTS", makeStringOfWarningAllowedProjects())
- ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWall))
- ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoError))
- ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFile))
+ ctx.Strict("SOONG_MODULES_ADDED_WALL", makeStringOfKeys(ctx, modulesAddedWallKey))
+ ctx.Strict("SOONG_MODULES_USING_WNO_ERROR", makeStringOfKeys(ctx, modulesUsingWnoErrorKey))
+ ctx.Strict("SOONG_MODULES_MISSING_PGO_PROFILE_FILE", makeStringOfKeys(ctx, modulesMissingProfileFileKey))
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", strings.Join(asanCflags, " "))
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", strings.Join(asanLdflags, " "))
diff --git a/cc/pgo.go b/cc/pgo.go
index a341ab9..9363916 100644
--- a/cc/pgo.go
+++ b/cc/pgo.go
@@ -36,7 +36,8 @@
}
)
-const pgoProfileProjectsConfigKey = "PgoProfileProjects"
+var pgoProfileProjectsConfigKey = android.NewOnceKey("PgoProfileProjects")
+
const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp"
const profileSamplingFlag = "-gline-tables-only"
const profileUseInstrumentFormat = "-fprofile-use=%s"
@@ -49,7 +50,7 @@
}
func recordMissingProfileFile(ctx BaseModuleContext, missing string) {
- getNamedMapForConfig(ctx.Config(), modulesMissingProfileFile).Store(missing, true)
+ getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true)
}
type PgoProperties struct {
diff --git a/cc/sanitize.go b/cc/sanitize.go
index bcc4de3..fc2ed50 100644
--- a/cc/sanitize.go
+++ b/cc/sanitize.go
@@ -958,20 +958,26 @@
}
}
+var cfiStaticLibsKey = android.NewOnceKey("cfiStaticLibs")
+
func cfiStaticLibs(config android.Config) *[]string {
- return config.Once("cfiStaticLibs", func() interface{} {
+ return config.Once(cfiStaticLibsKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
+var hwasanStaticLibsKey = android.NewOnceKey("hwasanStaticLibs")
+
func hwasanStaticLibs(config android.Config) *[]string {
- return config.Once("hwasanStaticLibs", func() interface{} {
+ return config.Once(hwasanStaticLibsKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
+var hwasanVendorStaticLibsKey = android.NewOnceKey("hwasanVendorStaticLibs")
+
func hwasanVendorStaticLibs(config android.Config) *[]string {
- return config.Once("hwasanVendorStaticLibs", func() interface{} {
+ return config.Once(hwasanVendorStaticLibsKey, func() interface{} {
return &[]string{}
}).(*[]string)
}