Simplify logic in Soong ApiLevelFromUserWithConfig

Currently, ApiLevelFromUser calls ReplaceFinalizedCodename(raw).
This function checks whether raw is in the getFinalCodenamesMap which is
equivalent to ApiLevelsMapReleasedVersion with an additional entry for current.

Since ApiLevelFromUserWithConfig already returned on the raw = "current"
we only care about ApiLevelsMapReleasedVersion and can avoid the unecessary
use of strconv.Atoi(strconv.Itoa(raw)) that calling ReplaceFinalizedCodename
ends up doing.

Also makes the function look more like the Bazel version in
build/bazel/rules/common/api.bzl

Change-Id: I8c03fc159d7f63298273624f030d1956e2307615
Test: m bp2build
This commit is contained in:
Alix
2023-03-06 21:04:30 +00:00
parent b72610665c
commit fb502512cb

View File

@@ -344,14 +344,17 @@ func ApiLevelFromUserWithConfig(config Config, raw string) (ApiLevel, error) {
}
}
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)
canonical, ok := getApiLevelsMapReleasedVersions()[raw]
if !ok {
asInt, err := strconv.Atoi(raw)
if err != nil {
return NoneApiLevel, fmt.Errorf("%q could not be parsed as an integer and is not a recognized codename", raw)
}
return uncheckedFinalApiLevel(asInt), nil
}
apiLevel := uncheckedFinalApiLevel(asInt)
return apiLevel, nil
return uncheckedFinalApiLevel(canonical), nil
}
// ApiLevelForTest returns an ApiLevel constructed from the supplied raw string.