Apex: support codenames for min_sdk_version

Apex can use codenames like "Q", "R" for its min_sdk_version property.
Also, cc_library can use codenames for its stubs.versions.

Bug: 152655956
Test: m
Merged-In: I077ad7b2ac5d90b4c8708921e43846206f05ba70
Change-Id: I077ad7b2ac5d90b4c8708921e43846206f05ba70
(cherry picked from commit 29e91d2121)
This commit is contained in:
Jooyung Han
2020-04-02 01:41:41 +09:00
parent b54015fa54
commit aed150d6ed
6 changed files with 135 additions and 19 deletions

View File

@@ -16,6 +16,7 @@ package android
import (
"encoding/json"
"fmt"
"strconv"
)
@@ -84,14 +85,19 @@ func getApiLevelsMap(config Config) map[string]int {
// Converts an API level string into its numeric form.
// * Codenames are decoded.
// * Numeric API levels are simply converted.
// * "minimum" and "current" are not currently handled since the former is
// NDK specific and the latter has inconsistent meaning.
// * "current" is mapped to FutureApiLevel(10000)
// * "minimum" is NDK specific and not handled with this. (refer normalizeNdkApiLevel in cc.go)
func ApiStrToNum(ctx BaseModuleContext, apiLevel string) (int, error) {
num, ok := getApiLevelsMap(ctx.Config())[apiLevel]
if ok {
if apiLevel == "current" {
return FutureApiLevel, nil
}
if num, ok := getApiLevelsMap(ctx.Config())[apiLevel]; ok {
return num, nil
}
return strconv.Atoi(apiLevel)
if num, err := strconv.Atoi(apiLevel); err == nil {
return num, nil
}
return 0, fmt.Errorf("SDK version should be one of \"current\", <number> or <codename>: %q", apiLevel)
}
func (a *apiLevelsSingleton) GenerateBuildActions(ctx SingletonContext) {