refactor of api_levels map for soong injection

Change-Id: I58449fc84617e46727f23ab3d8dd5f118d2ee0d2
Bug: 249265719
Test: go test ./bp2build and locally ran bazel tests
This commit is contained in:
Alix
2023-02-14 16:43:55 +00:00
parent 92ac65952d
commit c566ad8a4f
3 changed files with 42 additions and 54 deletions

View File

@@ -302,31 +302,35 @@ func GetApiLevelsJson(ctx PathContext) WritablePath {
return PathForOutput(ctx, "api_levels.json")
}
func getApiLevelsMapReleasedVersions() map[string]int {
return map[string]int{
"G": 9,
"I": 14,
"J": 16,
"J-MR1": 17,
"J-MR2": 18,
"K": 19,
"L": 21,
"L-MR1": 22,
"M": 23,
"N": 24,
"N-MR1": 25,
"O": 26,
"O-MR1": 27,
"P": 28,
"Q": 29,
"R": 30,
"S": 31,
"S-V2": 32,
"Tiramisu": 33,
}
}
var finalCodenamesMapKey = NewOnceKey("FinalCodenamesMap")
func getFinalCodenamesMap(config Config) map[string]int {
return config.Once(finalCodenamesMapKey, func() interface{} {
apiLevelsMap := map[string]int{
"G": 9,
"I": 14,
"J": 16,
"J-MR1": 17,
"J-MR2": 18,
"K": 19,
"L": 21,
"L-MR1": 22,
"M": 23,
"N": 24,
"N-MR1": 25,
"O": 26,
"O-MR1": 27,
"P": 28,
"Q": 29,
"R": 30,
"S": 31,
"S-V2": 32,
"Tiramisu": 33,
}
apiLevelsMap := getApiLevelsMapReleasedVersions()
// TODO: Differentiate "current" and "future".
// The code base calls it FutureApiLevel, but the spelling is "current",
@@ -349,29 +353,10 @@ func getFinalCodenamesMap(config Config) map[string]int {
var apiLevelsMapKey = NewOnceKey("ApiLevelsMap")
// ApiLevelsMap has entries for preview API levels
func GetApiLevelsMap(config Config) map[string]int {
return config.Once(apiLevelsMapKey, func() interface{} {
apiLevelsMap := map[string]int{
"G": 9,
"I": 14,
"J": 16,
"J-MR1": 17,
"J-MR2": 18,
"K": 19,
"L": 21,
"L-MR1": 22,
"M": 23,
"N": 24,
"N-MR1": 25,
"O": 26,
"O-MR1": 27,
"P": 28,
"Q": 29,
"R": 30,
"S": 31,
"S-V2": 32,
"Tiramisu": 33,
}
apiLevelsMap := getApiLevelsMapReleasedVersions()
for i, codename := range config.PlatformVersionActiveCodenames() {
apiLevelsMap[codename] = previewAPILevelBase + i
}
@@ -386,20 +371,11 @@ func (a *apiLevelsSingleton) GenerateBuildActions(ctx SingletonContext) {
createApiLevelsJson(ctx, apiLevelsJson, apiLevelsMap)
}
func printApiLevelsStarlarkDict(config Config) string {
apiLevelsMap := GetApiLevelsMap(config)
valDict := make(map[string]string, len(apiLevelsMap))
for k, v := range apiLevelsMap {
valDict[k] = strconv.Itoa(v)
}
return starlark_fmt.PrintDict(valDict, 0)
}
func StarlarkApiLevelConfigs(config Config) string {
return fmt.Sprintf(bazel.GeneratedBazelFileWarning+`
_api_levels = %s
_api_levels_released_versions = %s
api_levels = _api_levels
`, printApiLevelsStarlarkDict(config),
api_levels_released_versions = _api_levels_released_versions
`, starlark_fmt.PrintStringIntDict(getApiLevelsMapReleasedVersions(), 0),
)
}