Merge "Test SdkSpecForm." am: a71eabb705 am: 1fc2cf0ef6 am: 48fe6ad1cd

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1907852

Change-Id: I90ebac8f747498b0e174adfe7f01316295d3c808
This commit is contained in:
Artur Satayev
2021-12-02 15:56:22 +00:00
committed by Automerger Merge Worker
4 changed files with 107 additions and 7 deletions

View File

@@ -192,8 +192,8 @@ var LastWithoutModuleLibCoreSystemModules = uncheckedFinalApiLevel(31)
// * "30" -> "30"
// * "R" -> "30"
// * "S" -> "S"
func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
num, ok := getFinalCodenamesMap(ctx.Config())[raw]
func ReplaceFinalizedCodenames(config Config, raw string) string {
num, ok := getFinalCodenamesMap(config)[raw]
if !ok {
return raw
}
@@ -201,7 +201,7 @@ func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
return strconv.Itoa(num)
}
// Converts the given string `raw` to an ApiLevel, possibly returning an error.
// ApiLevelFromUser converts the given string `raw` to an ApiLevel, possibly returning an error.
//
// `raw` must be non-empty. Passing an empty string results in a panic.
//
@@ -216,6 +216,12 @@ func ReplaceFinalizedCodenames(ctx PathContext, raw string) string {
// Inputs that are not "current", known previews, or convertible to an integer
// will return an error.
func ApiLevelFromUser(ctx PathContext, raw string) (ApiLevel, error) {
return ApiLevelFromUserWithConfig(ctx.Config(), raw)
}
// ApiLevelFromUserWithConfig implements ApiLevelFromUser, see comments for
// ApiLevelFromUser for more details.
func ApiLevelFromUserWithConfig(config Config, raw string) (ApiLevel, error) {
if raw == "" {
panic("API level string must be non-empty")
}
@@ -224,13 +230,13 @@ func ApiLevelFromUser(ctx PathContext, raw string) (ApiLevel, error) {
return FutureApiLevel, nil
}
for _, preview := range ctx.Config().PreviewApiLevels() {
for _, preview := range config.PreviewApiLevels() {
if raw == preview.String() {
return preview, nil
}
}
canonical := ReplaceFinalizedCodenames(ctx, raw)
canonical := ReplaceFinalizedCodenames(config, raw)
asInt, err := strconv.Atoi(canonical)
if err != nil {
return NoneApiLevel, fmt.Errorf("%q could not be parsed as an integer and is not a recognized codename", canonical)