summaryrefslogtreecommitdiff
path: root/android/api_levels.go
diff options
context:
space:
mode:
authorJooyung Han <jooyung@google.com>2021-02-05 02:28:22 +0900
committerJooyung Han <jooyung@google.com>2021-02-05 11:27:57 +0900
commit11b0fbdbf61ac09067c3b8b706af8f79ffa9bb9b (patch)
tree539ed05d86c4af3e80504b7131fac4a107a8f6a8 /android/api_levels.go
parent23c38fa9a7c1922ffbc6ccd76ad48ef0360ce586 (diff)
cc: fix version macro for stubs
When a cc module is built against a stub, compiler passes version macro of the stub lib. Version macro should be numeric, so codenames or "current" should be mapped to numbers just like how ndkstubgen maps to. * "current" -> future (10000) * codenames -> look up api_level.json * otherwise -> cast to int Bug: 179329813 Test: m / soong test / manually check the output build.ninja Change-Id: Ic0e1dd904984e161694a0b77fad5559c06a4462f
Diffstat (limited to 'android/api_levels.go')
-rw-r--r--android/api_levels.go20
1 files changed, 18 insertions, 2 deletions
diff --git a/android/api_levels.go b/android/api_levels.go
index 1b53f3f2a..2f6a9d29d 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -24,6 +24,8 @@ func init() {
RegisterSingletonType("api_levels", ApiLevelsSingleton)
}
+const previewAPILevelBase = 9000
+
// An API level, which may be a finalized (numbered) API, a preview (codenamed)
// API, or the future API level (10000). Can be parsed from a string with
// ApiLevelFromUser or ApiLevelOrPanic.
@@ -57,6 +59,21 @@ func (this ApiLevel) FinalOrFutureInt() int {
}
}
+// FinalOrPreviewInt distinguishes preview versions from "current" (future).
+// This is for "native" stubs and should be in sync with ndkstubgen/getApiLevelsMap().
+// - "current" -> future (10000)
+// - preview codenames -> preview base (9000) + index
+// - otherwise -> cast to int
+func (this ApiLevel) FinalOrPreviewInt() int {
+ if this.IsCurrent() {
+ return this.number
+ }
+ if this.IsPreview() {
+ return previewAPILevelBase + this.number
+ }
+ return this.number
+}
+
// Returns the canonical name for this API level. For a finalized API level
// this will be the API number as a string. For a preview API level this
// will be the codename, or "current".
@@ -282,7 +299,6 @@ var apiLevelsMapKey = NewOnceKey("ApiLevelsMap")
func getApiLevelsMap(config Config) map[string]int {
return config.Once(apiLevelsMapKey, func() interface{} {
- baseApiLevel := 9000
apiLevelsMap := map[string]int{
"G": 9,
"I": 14,
@@ -302,7 +318,7 @@ func getApiLevelsMap(config Config) map[string]int {
"R": 30,
}
for i, codename := range config.PlatformVersionActiveCodenames() {
- apiLevelsMap[codename] = baseApiLevel + i
+ apiLevelsMap[codename] = previewAPILevelBase + i
}
return apiLevelsMap