From 9231537fe2ea819e370ef332da8757d980b69a01 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 2 Apr 2021 08:45:46 +0900 Subject: SdkSpec is fully using ApiLevel Previously, SdkSpec was constructed only from the user string. It didn't make use of the Config struct where information about the latest stable SDK version, etc. is recorded. As a result, the build system couldn't check if the sdk version "current" is referring to the in-development (i.e. not-yet-frozen) SDK version or the latest stable version. "current" was always assumed to be in-development (IsPreview() returns true) even when Platform_sdk_final == true. As the first step for fixing that, this change requires android.EarlyModuleContext to be passed when constructing SdkSpec from the user string. In the following changes, "current" will be mapped to either FutureApiLevel (10000) or one of the FinalApiLevels() depending on whether the platform SDK was finalized or not. Bug: 175678607 Test: m Change-Id: Ifea12ebf147ecccf12e7266dd382819806571543 --- android/sdk_version.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'android/sdk_version.go') diff --git a/android/sdk_version.go b/android/sdk_version.go index 5fdaa91f4..98db82496 100644 --- a/android/sdk_version.go +++ b/android/sdk_version.go @@ -22,15 +22,15 @@ import ( type SdkContext interface { // SdkVersion returns SdkSpec that corresponds to the sdk_version property of the current module - SdkVersion() SdkSpec + SdkVersion(ctx EarlyModuleContext) SdkSpec // SystemModules returns the system_modules property of the current module, or an empty string if it is not set. SystemModules() string // MinSdkVersion returns SdkSpec that corresponds to the min_sdk_version property of the current module, // or from sdk_version if it is not set. - MinSdkVersion() SdkSpec + MinSdkVersion(ctx EarlyModuleContext) SdkSpec // TargetSdkVersion returns the SdkSpec that corresponds to the target_sdk_version property of the current module, // or from sdk_version if it is not set. - TargetSdkVersion() SdkSpec + TargetSdkVersion(ctx EarlyModuleContext) SdkSpec } // SdkKind represents a particular category of an SDK spec like public, system, test, etc. @@ -201,15 +201,23 @@ func (s SdkSpec) EffectiveVersionString(ctx EarlyModuleContext) (string, error) return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil } -func SdkSpecFrom(str string) SdkSpec { +var ( + SdkSpecNone = SdkSpec{SdkNone, NoneApiLevel, "(no version)"} + // TODO(b/175678607) ApiLevel of SdkSpecPrivate should be FutureApiLevel + SdkSpecPrivate = SdkSpec{SdkPrivate, NoneApiLevel, ""} + // TODO(b/175678607) ApiLevel of SdkSpecCorePlatform should be FutureApiLevel + SdkSpecCorePlatform = SdkSpec{SdkCorePlatform, NoneApiLevel, "core_platform"} +) + +func SdkSpecFrom(ctx EarlyModuleContext, str string) SdkSpec { switch str { // special cases first case "": - return SdkSpec{SdkPrivate, NoneApiLevel, str} + return SdkSpecPrivate case "none": - return SdkSpec{SdkNone, NoneApiLevel, str} + return SdkSpecNone case "core_platform": - return SdkSpec{SdkCorePlatform, NoneApiLevel, str} + return SdkSpecCorePlatform default: // the syntax is [kind_]version sep := strings.LastIndex(str, "_") @@ -242,15 +250,10 @@ func SdkSpecFrom(str string) SdkSpec { return SdkSpec{SdkInvalid, NoneApiLevel, str} } - var apiLevel ApiLevel - if versionString == "current" { - apiLevel = FutureApiLevel - } else if i, err := strconv.Atoi(versionString); err == nil { - apiLevel = uncheckedFinalApiLevel(i) - } else { + apiLevel, err := ApiLevelFromUser(ctx, versionString) + if err != nil { return SdkSpec{SdkInvalid, apiLevel, str} } - return SdkSpec{kind, apiLevel, str} } } -- cgit v1.2.3-59-g8ed1b