Merge "Revert^2 "Fix erroneous "Field requires API level 33 (current min is 32)" warnings""

This commit is contained in:
Cole Faust
2022-07-01 22:48:49 +00:00
committed by Gerrit Code Review
3 changed files with 38 additions and 10 deletions

View File

@@ -54,6 +54,14 @@ type ApiLevel struct {
isPreview bool isPreview bool
} }
func (this ApiLevel) FinalInt() int {
if this.IsPreview() {
panic("Requested a final int from a non-final ApiLevel")
} else {
return this.number
}
}
func (this ApiLevel) FinalOrFutureInt() int { func (this ApiLevel) FinalOrFutureInt() int {
if this.IsPreview() { if this.IsPreview() {
return FutureApiLevelInt return FutureApiLevelInt

View File

@@ -1485,11 +1485,30 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
} }
if ctx.Device() { if ctx.Device() {
lintSDKVersion := func(sdkSpec android.SdkSpec) android.ApiLevel { lintSDKVersion := func(sdkSpec android.SdkSpec) int {
if v := sdkSpec.ApiLevel; !v.IsPreview() { if v := sdkSpec.ApiLevel; !v.IsPreview() {
return v return v.FinalInt()
} else { } else {
return ctx.Config().DefaultAppTargetSdk(ctx) // 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
} }
} }

View File

@@ -17,6 +17,7 @@ package java
import ( import (
"fmt" "fmt"
"sort" "sort"
"strconv"
"strings" "strings"
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
@@ -75,9 +76,9 @@ type linter struct {
extraLintCheckJars android.Paths extraLintCheckJars android.Paths
test bool test bool
library bool library bool
minSdkVersion android.ApiLevel minSdkVersion int
targetSdkVersion android.ApiLevel targetSdkVersion int
compileSdkVersion android.ApiLevel compileSdkVersion int
compileSdkKind android.SdkKind compileSdkKind android.SdkKind
javaLanguageLevel string javaLanguageLevel string
kotlinLanguageLevel string kotlinLanguageLevel string
@@ -299,8 +300,8 @@ func (l *linter) generateManifest(ctx android.ModuleContext, rule *android.RuleB
Text(`echo "<?xml version='1.0' encoding='utf-8'?>" &&`). Text(`echo "<?xml version='1.0' encoding='utf-8'?>" &&`).
Text(`echo "<manifest xmlns:android='http://schemas.android.com/apk/res/android'" &&`). Text(`echo "<manifest xmlns:android='http://schemas.android.com/apk/res/android'" &&`).
Text(`echo " android:versionCode='1' android:versionName='1' >" &&`). Text(`echo " android:versionCode='1' android:versionName='1' >" &&`).
Textf(`echo " <uses-sdk android:minSdkVersion='%s' android:targetSdkVersion='%s'/>" &&`, Textf(`echo " <uses-sdk android:minSdkVersion='%d' android:targetSdkVersion='%d'/>" &&`,
l.minSdkVersion.String(), l.targetSdkVersion.String()). l.minSdkVersion, l.targetSdkVersion).
Text(`echo "</manifest>"`). Text(`echo "</manifest>"`).
Text(") >").Output(manifestPath) Text(") >").Output(manifestPath)
@@ -325,7 +326,7 @@ func (l *linter) lint(ctx android.ModuleContext) {
return return
} }
if l.minSdkVersion.CompareTo(l.compileSdkVersion) == -1 { if l.minSdkVersion != l.compileSdkVersion {
l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, updatabilityChecks...) l.extraMainlineLintErrors = append(l.extraMainlineLintErrors, updatabilityChecks...)
_, filtered := android.FilterList(l.properties.Lint.Warning_checks, updatabilityChecks) _, filtered := android.FilterList(l.properties.Lint.Warning_checks, updatabilityChecks)
if len(filtered) != 0 { if len(filtered) != 0 {
@@ -427,7 +428,7 @@ func (l *linter) lint(ctx android.ModuleContext) {
FlagWithOutput("--html ", html). FlagWithOutput("--html ", html).
FlagWithOutput("--text ", text). FlagWithOutput("--text ", text).
FlagWithOutput("--xml ", xml). FlagWithOutput("--xml ", xml).
FlagWithArg("--compile-sdk-version ", l.compileSdkVersion.String()). FlagWithArg("--compile-sdk-version ", strconv.Itoa(l.compileSdkVersion)).
FlagWithArg("--java-language-level ", l.javaLanguageLevel). FlagWithArg("--java-language-level ", l.javaLanguageLevel).
FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel). FlagWithArg("--kotlin-language-level ", l.kotlinLanguageLevel).
FlagWithArg("--url ", fmt.Sprintf(".=.,%s=out", android.PathForOutput(ctx).String())). FlagWithArg("--url ", fmt.Sprintf(".=.,%s=out", android.PathForOutput(ctx).String())).