From 4f378d75aa2dd590998fdb943e54745f39453621 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 23 Jul 2020 17:32:15 -0700 Subject: [PATCH] Convert more versions in config to ApiLevel. The test case I removed is invalid. The codename has had its int assigned, but the config claims it is not final. If this ever does need to be supported it's just a matter of making sure the Q -> 29 mapping (or whatever) in the finalized codenames map in android/api_levels.go. Test: treehugger Bug: http://b/154667674 Change-Id: I4f42ec2fd4a37750519ee3937938a1c65b6bb1e8 --- android/api_levels.go | 2 +- android/config.go | 51 +++++++++++++++++++------------------------ apex/apex_test.go | 2 +- apex/builder.go | 4 ++-- apex/prebuilt.go | 2 +- java/aar.go | 2 +- java/app.go | 2 +- java/app_test.go | 15 +++++-------- java/droiddoc.go | 2 +- java/java.go | 2 +- java/sdk.go | 6 ++--- 11 files changed, 41 insertions(+), 49 deletions(-) diff --git a/android/api_levels.go b/android/api_levels.go index cba13ee2d..97683404e 100644 --- a/android/api_levels.go +++ b/android/api_levels.go @@ -274,7 +274,7 @@ func getFinalCodenamesMap(config Config) map[string]int { // neither R nor S are final, but the S APIs stop being available in a // final R build. if Bool(config.productVariables.Platform_sdk_final) { - apiLevelsMap["current"] = config.PlatformSdkVersionInt() + apiLevelsMap["current"] = config.PlatformSdkVersion().FinalOrFutureInt() } return apiLevelsMap diff --git a/android/config.go b/android/config.go index 34f1580a3..f5deeee57 100644 --- a/android/config.go +++ b/android/config.go @@ -21,7 +21,6 @@ import ( "os" "path/filepath" "runtime" - "strconv" "strings" "sync" @@ -228,15 +227,17 @@ func TestConfig(buildDir string, env map[string]string, bp string, fs map[string config := &config{ productVariables: productVariables{ - DeviceName: stringPtr("test_device"), - Platform_sdk_version: intPtr(30), - DeviceSystemSdkVersions: []string{"14", "15"}, - Platform_systemsdk_versions: []string{"29", "30"}, - AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}, - AAPTPreferredConfig: stringPtr("xhdpi"), - AAPTCharacteristics: stringPtr("nosdcard"), - AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"}, - UncompressPrivAppDex: boolPtr(true), + DeviceName: stringPtr("test_device"), + Platform_sdk_version: intPtr(30), + Platform_sdk_codename: stringPtr("S"), + Platform_version_active_codenames: []string{"S"}, + DeviceSystemSdkVersions: []string{"14", "15"}, + Platform_systemsdk_versions: []string{"29", "30"}, + AAPTConfig: []string{"normal", "large", "xlarge", "hdpi", "xhdpi", "xxhdpi"}, + AAPTPreferredConfig: stringPtr("xhdpi"), + AAPTCharacteristics: stringPtr("nosdcard"), + AAPTPrebuiltDPI: []string{"xhdpi", "xxhdpi"}, + UncompressPrivAppDex: boolPtr(true), }, buildDir: buildDir, @@ -620,12 +621,8 @@ func (c *config) PlatformVersionName() string { return String(c.productVariables.Platform_version_name) } -func (c *config) PlatformSdkVersionInt() int { - return *c.productVariables.Platform_sdk_version -} - -func (c *config) PlatformSdkVersion() string { - return strconv.Itoa(c.PlatformSdkVersionInt()) +func (c *config) PlatformSdkVersion() ApiLevel { + return uncheckedFinalApiLevel(*c.productVariables.Platform_sdk_version) } func (c *config) PlatformSdkCodename() string { @@ -654,7 +651,7 @@ func (c *config) MinSupportedSdkVersion() ApiLevel { func (c *config) FinalApiLevels() []ApiLevel { var levels []ApiLevel - for i := 1; i <= c.PlatformSdkVersionInt(); i++ { + for i := 1; i <= c.PlatformSdkVersion().FinalOrFutureInt(); i++ { levels = append(levels, uncheckedFinalApiLevel(i)) } return levels @@ -678,20 +675,18 @@ func (c *config) AllSupportedApiLevels() []ApiLevel { return append(levels, c.PreviewApiLevels()...) } -// TODO: Merge this and DefaultAppTargetSdk to just return an ApiLevel. -func (c *config) DefaultAppTargetSdkInt() int { - if Bool(c.productVariables.Platform_sdk_final) { - return c.PlatformSdkVersionInt() - } else { - return FutureApiLevelInt - } -} - -func (c *config) DefaultAppTargetSdk() string { +func (c *config) DefaultAppTargetSdk(ctx EarlyModuleContext) ApiLevel { if Bool(c.productVariables.Platform_sdk_final) { return c.PlatformSdkVersion() } else { - return c.PlatformSdkCodename() + codename := c.PlatformSdkCodename() + if codename == "" { + return NoneApiLevel + } + if codename == "REL" { + panic("Platform_sdk_codename should not be REL when Platform_sdk_final is true") + } + return ApiLevelOrPanic(ctx, codename) } } diff --git a/apex/apex_test.go b/apex/apex_test.go index cb125be4c..02689a0b7 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -207,7 +207,7 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr config.TestProductVariables.CertificateOverrides = []string{"myapex_keytest:myapex.certificate.override"} config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("Q") config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(false) - config.TestProductVariables.Platform_version_active_codenames = []string{"R"} + config.TestProductVariables.Platform_version_active_codenames = []string{"Q"} config.TestProductVariables.Platform_vndk_version = proptools.StringPtr("VER") for _, handler := range handlers { diff --git a/apex/builder.go b/apex/builder.go index a3c4d5cea..b0f0c8212 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -533,9 +533,9 @@ func (a *apexBundle) buildUnflattenedApex(ctx android.ModuleContext) { optFlags = append(optFlags, "--android_manifest "+androidManifestFile.String()) } - targetSdkVersion := ctx.Config().DefaultAppTargetSdk() + targetSdkVersion := ctx.Config().DefaultAppTargetSdk(ctx).String() // TODO(b/157078772): propagate min_sdk_version to apexer. - minSdkVersion := ctx.Config().DefaultAppTargetSdk() + minSdkVersion := ctx.Config().DefaultAppTargetSdk(ctx).String() moduleMinSdkVersion := a.minSdkVersion(ctx) if moduleMinSdkVersion.EqualTo(android.SdkVersion_Android10) { diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 37457e921..9f6c8ada9 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -326,7 +326,7 @@ func (a *ApexSet) GenerateAndroidBuildActions(ctx android.ModuleContext) { Args: map[string]string{ "abis": strings.Join(java.SupportedAbis(ctx), ","), "allow-prereleased": strconv.FormatBool(proptools.Bool(a.properties.Prerelease)), - "sdk-version": ctx.Config().PlatformSdkVersion(), + "sdk-version": ctx.Config().PlatformSdkVersion().String(), }, }) diff --git a/java/aar.go b/java/aar.go index fcdd9c3de..9cab0bdca 100644 --- a/java/aar.go +++ b/java/aar.go @@ -189,7 +189,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext sdkContext, // Version code if !hasVersionCode { - linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion()) + linkFlags = append(linkFlags, "--version-code", ctx.Config().PlatformSdkVersion().String()) } if !hasVersionName { diff --git a/java/app.go b/java/app.go index 99943f2de..2377c911b 100755 --- a/java/app.go +++ b/java/app.go @@ -157,7 +157,7 @@ func (as *AndroidAppSet) GenerateAndroidBuildActions(ctx android.ModuleContext) "abis": strings.Join(SupportedAbis(ctx), ","), "allow-prereleased": strconv.FormatBool(proptools.Bool(as.properties.Prerelease)), "screen-densities": screenDensities, - "sdk-version": ctx.Config().PlatformSdkVersion(), + "sdk-version": ctx.Config().PlatformSdkVersion().String(), "stem": as.BaseModuleName(), "apkcerts": as.apkcertsFile.String(), "partition": as.PartitionTag(ctx.DeviceConfig()), diff --git a/java/app_test.go b/java/app_test.go index 536797119..4347db8b1 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -1078,6 +1078,7 @@ func TestAppSdkVersion(t *testing.T) { platformSdkFinal bool expectedMinSdkVersion string platformApis bool + activeCodenames []string }{ { name: "current final SDK", @@ -1094,6 +1095,7 @@ func TestAppSdkVersion(t *testing.T) { platformSdkCodename: "OMR1", platformSdkFinal: false, expectedMinSdkVersion: "OMR1", + activeCodenames: []string{"OMR1"}, }, { name: "default final SDK", @@ -1112,11 +1114,14 @@ func TestAppSdkVersion(t *testing.T) { platformSdkCodename: "OMR1", platformSdkFinal: false, expectedMinSdkVersion: "OMR1", + activeCodenames: []string{"OMR1"}, }, { name: "14", sdkVersion: "14", expectedMinSdkVersion: "14", + platformSdkCodename: "S", + activeCodenames: []string{"S"}, }, } @@ -1137,6 +1142,7 @@ func TestAppSdkVersion(t *testing.T) { config := testAppConfig(nil, bp, nil) config.TestProductVariables.Platform_sdk_version = &test.platformSdkInt config.TestProductVariables.Platform_sdk_codename = &test.platformSdkCodename + config.TestProductVariables.Platform_version_active_codenames = test.activeCodenames config.TestProductVariables.Platform_sdk_final = &test.platformSdkFinal checkSdkVersion(t, config, test.expectedMinSdkVersion) @@ -1173,15 +1179,6 @@ func TestVendorAppSdkVersion(t *testing.T) { deviceCurrentApiLevelForVendorModules: "28", expectedMinSdkVersion: "28", }, - { - name: "current final SDK", - sdkVersion: "current", - platformSdkInt: 29, - platformSdkCodename: "Q", - platformSdkFinal: false, - deviceCurrentApiLevelForVendorModules: "current", - expectedMinSdkVersion: "Q", - }, { name: "current final SDK", sdkVersion: "current", diff --git a/java/droiddoc.go b/java/droiddoc.go index 85a61dd98..55bc04173 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -1228,7 +1228,7 @@ func (d *Droidstubs) apiLevelsAnnotationsFlags(ctx android.ModuleContext, cmd *a cmd.FlagWithOutput("--generate-api-levels ", d.apiVersionsXml) cmd.FlagWithInput("--apply-api-levels ", d.apiVersionsXml) - cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion()) + cmd.FlagWithArg("--current-version ", ctx.Config().PlatformSdkVersion().String()) cmd.FlagWithArg("--current-codename ", ctx.Config().PlatformSdkCodename()) filename := proptools.StringDefault(d.properties.Api_levels_jar_filename, "android.jar") diff --git a/java/java.go b/java/java.go index 1395ec485..1d7eaa771 100644 --- a/java/java.go +++ b/java/java.go @@ -1658,7 +1658,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { if v := sdkSpec.version; v.isNumbered() { return v.String() } else { - return ctx.Config().DefaultAppTargetSdk() + return ctx.Config().DefaultAppTargetSdk(ctx).String() } } diff --git a/java/sdk.go b/java/sdk.go index 0d7341e96..f59926502 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -247,7 +247,7 @@ func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, e if s.version.isNumbered() { return s.version, nil } - return sdkVersion(ctx.Config().DefaultAppTargetSdkInt()), nil + return sdkVersion(ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt()), nil } // effectiveVersionString converts an sdkSpec into the concrete version string that the module @@ -255,8 +255,8 @@ func (s sdkSpec) effectiveVersion(ctx android.EarlyModuleContext) (sdkVersion, e // it returns the codename (P, Q, R, etc.) func (s sdkSpec) effectiveVersionString(ctx android.EarlyModuleContext) (string, error) { ver, err := s.effectiveVersion(ctx) - if err == nil && int(ver) == ctx.Config().DefaultAppTargetSdkInt() { - return ctx.Config().DefaultAppTargetSdk(), nil + if err == nil && int(ver) == ctx.Config().DefaultAppTargetSdk(ctx).FinalOrFutureInt() { + return ctx.Config().DefaultAppTargetSdk(ctx).String(), nil } return ver.String(), err }