Merge "Update target_sdk_version from SdkSpec to ApiLevel"

This commit is contained in:
Spandan Das 2023-03-24 00:09:50 +00:00 committed by Gerrit Code Review
commit f5d3906505
8 changed files with 31 additions and 23 deletions

View file

@ -31,9 +31,9 @@ type SdkContext interface {
// ReplaceMaxSdkVersionPlaceholder returns SdkSpec to replace the maxSdkVersion property of permission and
// uses-permission tags if it is set.
ReplaceMaxSdkVersionPlaceholder(ctx EarlyModuleContext) SdkSpec
// TargetSdkVersion returns the SdkSpec that corresponds to the target_sdk_version property of the current module,
// TargetSdkVersion returns the ApiLevel that corresponds to the target_sdk_version property of the current module,
// or from sdk_version if it is not set.
TargetSdkVersion(ctx EarlyModuleContext) SdkSpec
TargetSdkVersion(ctx EarlyModuleContext) ApiLevel
}
// SdkKind represents a particular category of an SDK spec like public, system, test, etc.

View file

@ -725,8 +725,8 @@ func (a *AARImport) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleConte
return android.SdkSpecFrom(ctx, "")
}
func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return a.SdkVersion(ctx)
func (a *AARImport) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
return a.SdkVersion(ctx).ApiLevel
}
func (a *AARImport) javaVersion() string {

View file

@ -44,14 +44,14 @@ var manifestMergerRule = pctx.AndroidStaticRule("manifestMerger",
// When TARGET_BUILD_APPS is not empty, this method returns 10000 for modules targeting an unreleased SDK
// This enables release builds (that run with TARGET_BUILD_APPS=[val...]) to target APIs that have not yet been finalized as part of an SDK
func targetSdkVersionForManifestFixer(ctx android.ModuleContext, params ManifestFixerParams) string {
targetSdkVersionSpec := params.SdkContext.TargetSdkVersion(ctx)
targetSdkVersionLevel := params.SdkContext.TargetSdkVersion(ctx)
// Check if we want to return 10000
// TODO(b/240294501): Determine the rules for handling test apexes
if shouldReturnFinalOrFutureInt(ctx, targetSdkVersionSpec, params.EnforceDefaultTargetSdkVersion) {
if shouldReturnFinalOrFutureInt(ctx, targetSdkVersionLevel, params.EnforceDefaultTargetSdkVersion) {
return strconv.Itoa(android.FutureApiLevel.FinalOrFutureInt())
}
targetSdkVersion, err := targetSdkVersionSpec.EffectiveVersionString(ctx)
targetSdkVersion, err := targetSdkVersionLevel.EffectiveVersionString(ctx)
if err != nil {
ctx.ModuleErrorf("invalid targetSdkVersion: %s", err)
}
@ -62,11 +62,11 @@ func targetSdkVersionForManifestFixer(ctx android.ModuleContext, params Manifest
// 1. The module is built in unbundled mode (TARGET_BUILD_APPS not empty)
// 2. The module is run as part of MTS, and should be testable on stable branches
// Do not return 10000 if we are enforcing default targetSdkVersion and sdk has been finalised
func shouldReturnFinalOrFutureInt(ctx android.ModuleContext, targetSdkVersionSpec android.SdkSpec, enforceDefaultTargetSdkVersion bool) bool {
func shouldReturnFinalOrFutureInt(ctx android.ModuleContext, targetSdkVersionLevel android.ApiLevel, enforceDefaultTargetSdkVersion bool) bool {
if enforceDefaultTargetSdkVersion && ctx.Config().PlatformSdkFinal() {
return false
}
return targetSdkVersionSpec.ApiLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module()))
return targetSdkVersionLevel.IsPreview() && (ctx.Config().UnbundledBuildApps() || includedInMts(ctx.Module()))
}
// Helper function that casts android.Module to java.androidTestApp

View file

@ -3077,13 +3077,17 @@ func TestTargetSdkVersionManifestFixer(t *testing.T) {
},
}
for _, testCase := range testCases {
targetSdkVersionTemplate := ""
if testCase.targetSdkVersionInBp != "" {
targetSdkVersionTemplate = fmt.Sprintf(`target_sdk_version: "%s",`, testCase.targetSdkVersionInBp)
}
bp := fmt.Sprintf(`
android_app {
name: "foo",
sdk_version: "current",
target_sdk_version: "%v",
%s
}
`, testCase.targetSdkVersionInBp)
`, targetSdkVersionTemplate)
fixture := android.GroupFixturePreparers(
prepareForJavaTest,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
@ -3161,16 +3165,20 @@ func TestDefaultAppTargetSdkVersionForUpdatableModules(t *testing.T) {
},
}
for _, testCase := range testCases {
targetSdkVersionTemplate := ""
if testCase.targetSdkVersionInBp != nil {
targetSdkVersionTemplate = fmt.Sprintf(`target_sdk_version: "%s",`, *testCase.targetSdkVersionInBp)
}
bp := fmt.Sprintf(`
android_app {
name: "foo",
sdk_version: "current",
min_sdk_version: "29",
target_sdk_version: "%v",
%s
updatable: %t,
enforce_default_target_sdk_version: %t
}
`, proptools.String(testCase.targetSdkVersionInBp), testCase.updatable, testCase.updatable) // enforce default target sdk version if app is updatable
`, targetSdkVersionTemplate, testCase.updatable, testCase.updatable) // enforce default target sdk version if app is updatable
fixture := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,

View file

@ -688,11 +688,11 @@ func (j *Module) MinSdkVersionString() string {
return j.minSdkVersion.String()
}
func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
func (j *Module) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
if j.deviceProperties.Target_sdk_version != nil {
return android.SdkSpecFrom(ctx, *j.deviceProperties.Target_sdk_version)
return android.ApiLevelFrom(ctx, *j.deviceProperties.Target_sdk_version)
}
return j.SdkVersion(ctx)
return j.SdkVersion(ctx).ApiLevel
}
func (j *Module) AvailableFor(what string) bool {
@ -1575,7 +1575,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
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).ApiLevel)
j.linter.targetSdkVersion = lintSDKVersion(j.TargetSdkVersion(ctx))
j.linter.compileSdkVersion = lintSDKVersion(j.SdkVersion(ctx).ApiLevel)
j.linter.compileSdkKind = j.SdkVersion(ctx).Kind
j.linter.javaLanguageLevel = flags.javaVersion.String()

View file

@ -256,8 +256,8 @@ func (j *Javadoc) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext
return j.SdkVersion(ctx)
}
func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return j.SdkVersion(ctx)
func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
return j.SdkVersion(ctx).ApiLevel
}
func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) {

View file

@ -1905,8 +1905,8 @@ func (j *Import) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext)
return android.SdkSpecFrom(ctx, "")
}
func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return j.SdkVersion(ctx)
func (j *Import) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
return j.SdkVersion(ctx).ApiLevel
}
func (j *Import) Prebuilt() *android.Prebuilt {

View file

@ -186,8 +186,8 @@ func (r *RuntimeResourceOverlay) ReplaceMaxSdkVersionPlaceholder(ctx android.Ear
return android.SdkSpecFrom(ctx, "")
}
func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec {
return r.SdkVersion(ctx)
func (r *RuntimeResourceOverlay) TargetSdkVersion(ctx android.EarlyModuleContext) android.ApiLevel {
return r.SdkVersion(ctx).ApiLevel
}
func (r *RuntimeResourceOverlay) Certificate() Certificate {