[Cherry picked from I86e0bf684a5083221dae53907d9f548a0390b673]
Move target sdk version enforcement check Enforce target sdk version flag could only be used by `android_app`, moving the check into a common function `generateAndroidBuildActions`. This would ensure that the `enforce_target_sdk_version` flag can also be set by `android_test` and `android_test_helper_app`. Bug: b/227460469 Test: m nothing Change-Id: I86e0bf684a5083221dae53907d9f548a0390b673
This commit is contained in:
@@ -315,10 +315,6 @@ func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if Bool(a.appProperties.Enforce_default_target_sdk_version) {
|
|
||||||
a.SetEnforceDefaultTargetSdkVersion(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
a.checkPlatformAPI(ctx)
|
a.checkPlatformAPI(ctx)
|
||||||
a.checkSdkVersions(ctx)
|
a.checkSdkVersions(ctx)
|
||||||
}
|
}
|
||||||
@@ -620,6 +616,11 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath)
|
a.aapt.noticeFile = android.OptionalPathForPath(noticeAssetPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For apps targeting latest target_sdk_version
|
||||||
|
if Bool(a.appProperties.Enforce_default_target_sdk_version) {
|
||||||
|
a.SetEnforceDefaultTargetSdkVersion(true)
|
||||||
|
}
|
||||||
|
|
||||||
// Process all building blocks, from AAPT to certificates.
|
// Process all building blocks, from AAPT to certificates.
|
||||||
a.aaptBuildActions(ctx)
|
a.aaptBuildActions(ctx)
|
||||||
|
|
||||||
|
@@ -3166,7 +3166,7 @@ func TestEnforceDefaultAppTargetSdkVersionFlag(t *testing.T) {
|
|||||||
updatable: true,
|
updatable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion",
|
name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion",
|
||||||
enforceDefaultTargetSdkVersion: true,
|
enforceDefaultTargetSdkVersion: true,
|
||||||
platform_sdk_final: false,
|
platform_sdk_final: false,
|
||||||
targetSdkVersionInBp: "current",
|
targetSdkVersionInBp: "current",
|
||||||
@@ -3222,6 +3222,76 @@ func TestEnforceDefaultAppTargetSdkVersionFlag(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnforceDefaultAppTargetSdkVersionFlagForTests(t *testing.T) {
|
||||||
|
platform_sdk_codename := "Tiramisu"
|
||||||
|
platform_sdk_version := 33
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
enforceDefaultTargetSdkVersion bool
|
||||||
|
expectedError string
|
||||||
|
platform_sdk_final bool
|
||||||
|
targetSdkVersionInBp string
|
||||||
|
targetSdkVersionExpected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Not enforcing Target SDK Version: Android.bp has older targetSdkVersion",
|
||||||
|
enforceDefaultTargetSdkVersion: false,
|
||||||
|
targetSdkVersionInBp: "29",
|
||||||
|
targetSdkVersionExpected: "29",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "[SDK finalised] Enforce Target SDK Version: Android.bp has current targetSdkVersion",
|
||||||
|
enforceDefaultTargetSdkVersion: true,
|
||||||
|
platform_sdk_final: true,
|
||||||
|
targetSdkVersionInBp: "current",
|
||||||
|
targetSdkVersionExpected: "33",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Enforce Target SDK Version: Android.bp has current targetSdkVersion",
|
||||||
|
enforceDefaultTargetSdkVersion: true,
|
||||||
|
platform_sdk_final: false,
|
||||||
|
targetSdkVersionInBp: "current",
|
||||||
|
targetSdkVersionExpected: "10000",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
errExpected := testCase.expectedError != ""
|
||||||
|
bp := fmt.Sprintf(`
|
||||||
|
android_test {
|
||||||
|
name: "foo",
|
||||||
|
enforce_default_target_sdk_version: %t,
|
||||||
|
min_sdk_version: "29",
|
||||||
|
target_sdk_version: "%v",
|
||||||
|
}
|
||||||
|
`, testCase.enforceDefaultTargetSdkVersion, testCase.targetSdkVersionInBp)
|
||||||
|
|
||||||
|
fixture := android.GroupFixturePreparers(
|
||||||
|
PrepareForTestWithJavaDefaultModules,
|
||||||
|
android.PrepareForTestWithAllowMissingDependencies,
|
||||||
|
android.PrepareForTestWithAndroidMk,
|
||||||
|
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
|
||||||
|
// explicitly set following platform variables to make the test deterministic
|
||||||
|
variables.Platform_sdk_final = &testCase.platform_sdk_final
|
||||||
|
variables.Platform_sdk_version = &platform_sdk_version
|
||||||
|
variables.Platform_sdk_codename = &platform_sdk_codename
|
||||||
|
variables.Unbundled_build_apps = []string{"sampleModule"}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
errorHandler := android.FixtureExpectsNoErrors
|
||||||
|
if errExpected {
|
||||||
|
errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(testCase.expectedError)
|
||||||
|
}
|
||||||
|
result := fixture.ExtendWithErrorHandler(errorHandler).RunTestWithBp(t, bp)
|
||||||
|
|
||||||
|
if !errExpected {
|
||||||
|
foo := result.ModuleForTests("foo", "android_common")
|
||||||
|
manifestFixerArgs := foo.Output("manifest_fixer/AndroidManifest.xml").Args["args"]
|
||||||
|
android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) {
|
func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) {
|
||||||
result := android.GroupFixturePreparers(
|
result := android.GroupFixturePreparers(
|
||||||
PrepareForTestWithJavaDefaultModules,
|
PrepareForTestWithJavaDefaultModules,
|
||||||
|
Reference in New Issue
Block a user