Fix sdk_version: "system_current" when Platform_sdk_final=true
When PLATFORM_VERSION_CODENAME is set to REL Platform_sdk_final
becomes true, which causes the return value of sdkVersionToNumber
for "system_current" to a real version number instead of
FutureApiLevel. This enables the check against
PlatformSystemSdkVersions, which doesn't contain "current". Use
the numeric value instead.
Fixes: 129786845
Test: sdk_test.go
Change-Id: If7cf211cc01c5fbf3e3ece3c3f604718a13d5a9b
diff --git a/java/java_test.go b/java/java_test.go
index 6cb4818..2546698 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -138,6 +138,9 @@
"prebuilts/sdk/17/public/android.jar": nil,
"prebuilts/sdk/17/public/framework.aidl": nil,
"prebuilts/sdk/17/system/android.jar": nil,
+ "prebuilts/sdk/25/public/android.jar": nil,
+ "prebuilts/sdk/25/public/framework.aidl": nil,
+ "prebuilts/sdk/25/system/android.jar": nil,
"prebuilts/sdk/current/core/android.jar": nil,
"prebuilts/sdk/current/public/android.jar": nil,
"prebuilts/sdk/current/public/framework.aidl": nil,
diff --git a/java/sdk.go b/java/sdk.go
index 0959be7..48e7746 100644
--- a/java/sdk.go
+++ b/java/sdk.go
@@ -84,7 +84,7 @@
v = strconv.Itoa(latestSdkVersion)
}
- i, err := sdkVersionToNumber(ctx, v)
+ numericSdkVersion, err := sdkVersionToNumber(ctx, v)
if err != nil {
ctx.PropertyErrorf("sdk_version", "%s", err)
return sdkDep{}
@@ -151,15 +151,14 @@
// Ensures that the specificed system SDK version is one of BOARD_SYSTEMSDK_VERSIONS (for vendor apks)
// or PRODUCT_SYSTEMSDK_VERSIONS (for other apks or when BOARD_SYSTEMSDK_VERSIONS is not set)
- if strings.HasPrefix(v, "system_") && i != android.FutureApiLevel {
+ if strings.HasPrefix(v, "system_") && numericSdkVersion != android.FutureApiLevel {
allowed_versions := ctx.DeviceConfig().PlatformSystemSdkVersions()
if ctx.DeviceSpecific() || ctx.SocSpecific() {
if len(ctx.DeviceConfig().SystemSdkVersions()) > 0 {
allowed_versions = ctx.DeviceConfig().SystemSdkVersions()
}
}
- version := strings.TrimPrefix(v, "system_")
- if len(allowed_versions) > 0 && !android.InList(version, allowed_versions) {
+ if len(allowed_versions) > 0 && !android.InList(strconv.Itoa(numericSdkVersion), allowed_versions) {
ctx.PropertyErrorf("sdk_version", "incompatible sdk version %q. System SDK version should be one of %q",
v, allowed_versions)
}
diff --git a/java/sdk_test.go b/java/sdk_test.go
index 6924e26..7fa40a3 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -50,11 +50,11 @@
},
{
- name: "sdk v14",
- properties: `sdk_version: "14",`,
+ name: "sdk v25",
+ properties: `sdk_version: "25",`,
bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
- classpath: []string{"prebuilts/sdk/14/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
+ classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
},
{
@@ -72,11 +72,11 @@
},
{
- name: "system_14",
- properties: `sdk_version: "system_14",`,
+ name: "system_25",
+ properties: `sdk_version: "system_25",`,
bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
- classpath: []string{"prebuilts/sdk/14/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
+ classpath: []string{"prebuilts/sdk/25/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
},
{
@@ -140,12 +140,12 @@
},
{
- name: "unbundled sdk v14",
+ name: "unbundled sdk v25",
unbundled: true,
- properties: `sdk_version: "14",`,
+ properties: `sdk_version: "25",`,
bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
- classpath: []string{"prebuilts/sdk/14/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
+ classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
},
{
@@ -162,7 +162,7 @@
pdk: true,
bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
- classpath: []string{"prebuilts/sdk/17/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
+ classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
},
{
name: "pdk current",
@@ -170,15 +170,15 @@
properties: `sdk_version: "current",`,
bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
- classpath: []string{"prebuilts/sdk/17/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
+ classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
},
{
- name: "pdk 14",
+ name: "pdk 25",
pdk: true,
- properties: `sdk_version: "14",`,
+ properties: `sdk_version: "25",`,
bootclasspath: []string{`""`},
system: "bootclasspath", // special value to tell 1.9 test to expect bootclasspath
- classpath: []string{"prebuilts/sdk/14/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
+ classpath: []string{"prebuilts/sdk/25/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
},
}
@@ -285,6 +285,44 @@
t.Errorf("bootclasspath expected %q != got %q", expected, got)
}
})
+
+ // Test again with PLATFORM_VERSION_CODENAME=REL
+ t.Run("REL", func(t *testing.T) {
+ config := testConfig(nil)
+ config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
+ config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
+
+ if testcase.unbundled {
+ config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
+ }
+ if testcase.pdk {
+ config.TestProductVariables.Pdk = proptools.BoolPtr(true)
+ }
+ ctx := testContext(config, bp, nil)
+ run(t, ctx, config)
+
+ javac := ctx.ModuleForTests("foo", variant).Rule("javac")
+
+ got := javac.Args["bootClasspath"]
+ if got != bc {
+ t.Errorf("bootclasspath expected %q != got %q", bc, got)
+ }
+
+ got = javac.Args["classpath"]
+ if got != c {
+ t.Errorf("classpath expected %q != got %q", c, got)
+ }
+
+ var deps []string
+ if len(bootclasspath) > 0 && bootclasspath[0] != `""` {
+ deps = append(deps, bootclasspath...)
+ }
+ deps = append(deps, classpath...)
+
+ if !reflect.DeepEqual(javac.Implicits.Strings(), deps) {
+ t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings())
+ }
+ })
})
}
diff --git a/java/testing.go b/java/testing.go
index 6febfa1..7d23d8f 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -28,7 +28,6 @@
env["ANDROID_JAVA8_HOME"] = "jdk8"
}
config := android.TestArchConfig(buildDir, env)
- config.TestProductVariables.DeviceSystemSdkVersions = []string{"14", "15"}
return config
}