Update min_sdk_version from SdkSpec to ApiLevel
min_sdk_version signifies device version and does not need an sdkKind to
describe it fully. Update the type and cleanup existing usages. As a
side benefit, we also get better error handling since users can no
longer enter something like `public_30` as a valid min_sdk_version in bp
files
Will do a similar cleanup for targetSdkVersion and maxSdkVersion in a
followup CL
Test: m nothing
Test: no change in ninja files (this should be a no-op)
Bug: 208456999
Change-Id: Ie6ae7e267d093c5e4787e82685daaca1021d202e
diff --git a/java/base.go b/java/base.go
index 85f4a5e..75ec16d 100644
--- a/java/base.go
+++ b/java/base.go
@@ -489,7 +489,7 @@
hideApexVariantFromMake bool
sdkVersion android.SdkSpec
- minSdkVersion android.SdkSpec
+ minSdkVersion android.ApiLevel
maxSdkVersion android.SdkSpec
sourceExtensions []string
@@ -665,11 +665,11 @@
return proptools.String(j.deviceProperties.System_modules)
}
-func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
+func (j *Module) MinSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
if j.deviceProperties.Min_sdk_version != nil {
- return android.SdkSpecFrom(ctx, *j.deviceProperties.Min_sdk_version)
+ return android.ApiLevelFrom(ctx, *j.deviceProperties.Min_sdk_version)
}
- return j.SdkVersion(ctx)
+ return j.SdkVersion(ctx).ApiLevel
}
func (j *Module) MaxSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
@@ -685,7 +685,7 @@
}
func (j *Module) MinSdkVersionString() string {
- return j.minSdkVersion.Raw
+ return j.minSdkVersion.String()
}
func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
@@ -881,7 +881,7 @@
j.ignoredAidlPermissionList = android.PathsForModuleSrcExcludes(ctx, exceptions, nil)
}
- aidlMinSdkVersion := j.MinSdkVersion(ctx).ApiLevel.String()
+ aidlMinSdkVersion := j.MinSdkVersion(ctx).String()
flags = append(flags, "--min_sdk_version="+aidlMinSdkVersion)
return strings.Join(flags, " "), deps
@@ -1542,9 +1542,9 @@
}
if ctx.Device() {
- lintSDKVersion := func(sdkSpec android.SdkSpec) int {
- if v := sdkSpec.ApiLevel; !v.IsPreview() {
- return v.FinalInt()
+ lintSDKVersion := func(apiLevel android.ApiLevel) int {
+ if !apiLevel.IsPreview() {
+ return apiLevel.FinalInt()
} else {
// When running metalava, we pass --version-codename. When that value
// is not REL, metalava will add 1 to the --current-version argument.
@@ -1575,8 +1575,8 @@
j.linter.classpath = append(append(android.Paths(nil), flags.bootClasspath...), flags.classpath...)
j.linter.classes = j.implementationJarFile
j.linter.minSdkVersion = lintSDKVersion(j.MinSdkVersion(ctx))
- j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx))
- j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx))
+ j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx).ApiLevel)
+ j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx).ApiLevel)
j.linter.compileSdkKind = j.SdkVersion(ctx).Kind
j.linter.javaLanguageLevel = flags.javaVersion.String()
j.linter.kotlinLanguageLevel = "1.3"
@@ -1846,15 +1846,14 @@
// Implements android.ApexModule
func (j *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error {
sdkVersionSpec := j.SdkVersion(ctx)
- minSdkVersionSpec := j.MinSdkVersion(ctx)
- if !minSdkVersionSpec.Specified() {
+ minSdkVersion := j.MinSdkVersion(ctx)
+ if !minSdkVersion.Specified() {
return fmt.Errorf("min_sdk_version is not specified")
}
// If the module is compiling against core (via sdk_version), skip comparison check.
if sdkVersionSpec.Kind == android.SdkCore {
return nil
}
- minSdkVersion := minSdkVersionSpec.ApiLevel
if minSdkVersion.GreaterThan(sdkVersion) {
return fmt.Errorf("newer SDK(%v)", minSdkVersion)
}