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: vendor/google/build/build_mainline_modules.sh
Change-Id: I077ad7b2ac5d90b4c8708921e43846206f05ba70
diff --git a/android/api_levels.go b/android/api_levels.go
index 4f6efee..62a5fce 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -16,6 +16,7 @@
import (
"encoding/json"
+ "fmt"
"strconv"
)
@@ -84,14 +85,19 @@
// 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) {