From e1166f081f5e163e03252114193cb435dc932dcc Mon Sep 17 00:00:00 2001 From: Zi Wang Date: Mon, 6 Nov 2023 11:43:17 -0800 Subject: [PATCH] Use ApiLevel on min, target and compile Sdk version This change is a partial revert of aosp/2143082. The reason is that unreleased apis should be referenced by name instead of a number. link to xml reports before/after this cl: https://drive.google.com/drive/folders/1woIgVlHF6qude5RpW-0mEQLzcXo4isX4?usp=sharing Test: m lint-check Change-Id: I6d801f95a24400c9c5c23546e19d6440bd357873 --- java/base.go | 25 +++---------------------- java/lint.go | 15 +++++++-------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/java/base.go b/java/base.go index 3d7d3de01..566d570da 100644 --- a/java/base.go +++ b/java/base.go @@ -1678,30 +1678,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath } if ctx.Device() { - lintSDKVersion := func(apiLevel android.ApiLevel) int { + lintSDKVersion := func(apiLevel android.ApiLevel) android.ApiLevel { if !apiLevel.IsPreview() { - return apiLevel.FinalInt() + return apiLevel } else { - // When running metalava, we pass --version-codename. When that value - // is not REL, metalava will add 1 to the --current-version argument. - // On old branches, PLATFORM_SDK_VERSION is the latest version (for that - // branch) and the codename is REL, except potentially on the most - // recent non-master branch. On that branch, it goes through two other - // phases before it gets to the phase previously described: - // - PLATFORM_SDK_VERSION has not been updated yet, and the codename - // is not rel. This happens for most of the internal branch's life - // while the branch has been cut but is still under active development. - // - PLATFORM_SDK_VERSION has been set, but the codename is still not - // REL. This happens briefly during the release process. During this - // state the code to add --current-version is commented out, and then - // that commenting out is reverted after the codename is set to REL. - // On the master branch, the PLATFORM_SDK_VERSION always represents a - // prior version and the codename is always non-REL. - // - // We need to add one here to match metalava adding 1. Technically - // this means that in the state described in the second bullet point - // above, this number is 1 higher than it should be. - return ctx.Config().PlatformSdkVersion().FinalInt() + 1 + return ctx.Config().DefaultAppTargetSdk(ctx) } } diff --git a/java/lint.go b/java/lint.go index 34720e51d..e831faf9d 100644 --- a/java/lint.go +++ b/java/lint.go @@ -17,7 +17,6 @@ package java import ( "fmt" "sort" - "strconv" "strings" "github.com/google/blueprint/proptools" @@ -84,9 +83,9 @@ type linter struct { classes android.Path extraLintCheckJars android.Paths library bool - minSdkVersion int - targetSdkVersion int - compileSdkVersion int + minSdkVersion android.ApiLevel + targetSdkVersion android.ApiLevel + compileSdkVersion android.ApiLevel compileSdkKind android.SdkKind javaLanguageLevel string kotlinLanguageLevel string @@ -356,8 +355,8 @@ func (l *linter) generateManifest(ctx android.ModuleContext, rule *android.RuleB Text(`echo "" &&`). Text(`echo "" &&`). - Textf(`echo " " &&`, - l.minSdkVersion, l.targetSdkVersion). + Textf(`echo " " &&`, + l.minSdkVersion.String(), l.targetSdkVersion.String()). Text(`echo ""`). Text(") >").Output(manifestPath) @@ -382,7 +381,7 @@ func (l *linter) lint(ctx android.ModuleContext) { return } - if l.minSdkVersion != l.compileSdkVersion { + if l.minSdkVersion.CompareTo(l.compileSdkVersion) == -1 { l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, updatabilityChecks...) // Skip lint warning checks for NewApi warnings for libcore where they come from source // files that reference the API they are adding (b/208656169). @@ -496,7 +495,7 @@ func (l *linter) lint(ctx android.ModuleContext) { FlagWithOutput("--html ", html). FlagWithOutput("--text ", text). FlagWithOutput("--xml ", xml). - FlagWithArg("--compile-sdk-version ", strconv.Itoa(l.compileSdkVersion)). + FlagWithArg("--compile-sdk-version ", l.compileSdkVersion.String()). FlagWithArg("--java-language-level ", l.javaLanguageLevel). FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel). FlagWithArg("--url ", fmt.Sprintf(".=.,%s=out", android.PathForOutput(ctx).String())).