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
This commit is contained in:
@@ -250,8 +250,8 @@ func warningsAreAllowed(subdir string) bool {
|
||||
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 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
||||
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...)
|
||||
|
@@ -968,8 +968,10 @@ func (library *libraryDecorator) stubsVersion() string {
|
||||
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 @@ func LinkageMutator(mctx android.BottomUpMutatorContext) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
@@ -24,24 +24,24 @@ import (
|
||||
"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 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
|
||||
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, " "))
|
||||
|
@@ -36,7 +36,8 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
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 getPgoProfileProjects(config android.DeviceConfig) []string {
|
||||
}
|
||||
|
||||
func recordMissingProfileFile(ctx BaseModuleContext, missing string) {
|
||||
getNamedMapForConfig(ctx.Config(), modulesMissingProfileFile).Store(missing, true)
|
||||
getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true)
|
||||
}
|
||||
|
||||
type PgoProperties struct {
|
||||
|
@@ -958,20 +958,26 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user