Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 1 | // Copyright 2019 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 18 | "path/filepath" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 19 | "strings" |
| 20 | "testing" |
| 21 | |
| 22 | "github.com/google/blueprint/proptools" |
Colin Cross | 60405e5 | 2019-04-18 12:31:22 -0700 | [diff] [blame] | 23 | |
| 24 | "android/soong/android" |
| 25 | "android/soong/java/config" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 28 | func TestClasspath(t *testing.T) { |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 29 | const frameworkAidl = "-I" + defaultJavaDir + "/framework/aidl" |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 30 | var classpathTestcases = []struct { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 31 | name string |
| 32 | unbundled bool |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 33 | moduleType string |
| 34 | host android.OsClass |
| 35 | properties string |
| 36 | |
| 37 | // for java 8 |
| 38 | bootclasspath []string |
| 39 | java8classpath []string |
| 40 | |
| 41 | // for java 9 |
| 42 | system string |
| 43 | java9classpath []string |
| 44 | |
| 45 | forces8 bool // if set, javac will always be called with java 8 arguments |
| 46 | |
| 47 | aidl string |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 48 | }{ |
| 49 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 50 | name: "default", |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 51 | bootclasspath: config.StableCorePlatformBootclasspathLibraries, |
| 52 | system: config.StableCorePlatformSystemModules, |
Pete Gillin | 0638dfc | 2020-07-01 10:48:14 +0100 | [diff] [blame] | 53 | java8classpath: config.FrameworkLibraries, |
| 54 | java9classpath: config.FrameworkLibraries, |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 55 | aidl: frameworkAidl, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 56 | }, |
| 57 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 58 | name: `sdk_version:"core_platform"`, |
| 59 | properties: `sdk_version:"core_platform"`, |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 60 | bootclasspath: config.StableCorePlatformBootclasspathLibraries, |
| 61 | system: config.StableCorePlatformSystemModules, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 62 | java8classpath: []string{}, |
| 63 | aidl: "", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 64 | }, |
| 65 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 66 | name: "blank sdk version", |
| 67 | properties: `sdk_version: "",`, |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 68 | bootclasspath: config.StableCorePlatformBootclasspathLibraries, |
| 69 | system: config.StableCorePlatformSystemModules, |
Pete Gillin | 0638dfc | 2020-07-01 10:48:14 +0100 | [diff] [blame] | 70 | java8classpath: config.FrameworkLibraries, |
| 71 | java9classpath: config.FrameworkLibraries, |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 72 | aidl: frameworkAidl, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 73 | }, |
| 74 | { |
| 75 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 76 | name: "sdk v29", |
| 77 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 78 | bootclasspath: []string{`""`}, |
| 79 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 80 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 81 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 82 | }, |
| 83 | { |
| 84 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 85 | name: "sdk v30", |
| 86 | properties: `sdk_version: "30",`, |
| 87 | bootclasspath: []string{`""`}, |
| 88 | system: "sdk_public_30_system_modules", |
| 89 | java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 90 | java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 91 | aidl: "-pprebuilts/sdk/30/public/framework.aidl", |
| 92 | }, |
| 93 | { |
| 94 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 95 | name: "current", |
| 96 | properties: `sdk_version: "current",`, |
| 97 | bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"}, |
| 98 | system: "core-current-stubs-system-modules", |
| 99 | java9classpath: []string{"android_stubs_current"}, |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 100 | aidl: "-pout/soong/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 101 | }, |
| 102 | { |
| 103 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 104 | name: "system_current", |
| 105 | properties: `sdk_version: "system_current",`, |
| 106 | bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"}, |
| 107 | system: "core-current-stubs-system-modules", |
| 108 | java9classpath: []string{"android_system_stubs_current"}, |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 109 | aidl: "-pout/soong/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 110 | }, |
| 111 | { |
| 112 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 113 | name: "system_29", |
| 114 | properties: `sdk_version: "system_29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 115 | bootclasspath: []string{`""`}, |
| 116 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 117 | java8classpath: []string{"prebuilts/sdk/29/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 118 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 119 | }, |
| 120 | { |
| 121 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 122 | name: "system_30", |
| 123 | properties: `sdk_version: "system_30",`, |
| 124 | bootclasspath: []string{`""`}, |
| 125 | system: "sdk_public_30_system_modules", |
| 126 | java8classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 127 | java9classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 128 | aidl: "-pprebuilts/sdk/30/public/framework.aidl", |
| 129 | }, |
| 130 | { |
| 131 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 132 | name: "test_current", |
| 133 | properties: `sdk_version: "test_current",`, |
| 134 | bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"}, |
| 135 | system: "core-current-stubs-system-modules", |
| 136 | java9classpath: []string{"android_test_stubs_current"}, |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 137 | aidl: "-pout/soong/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 138 | }, |
| 139 | { |
| 140 | |
Pete Gillin | 880f964 | 2020-07-01 13:17:16 +0100 | [diff] [blame] | 141 | name: "core_current", |
| 142 | properties: `sdk_version: "core_current",`, |
| 143 | bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"}, |
| 144 | system: "core-current-stubs-system-modules", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 145 | }, |
| 146 | { |
| 147 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 148 | name: "nostdlib", |
| 149 | properties: `sdk_version: "none", system_modules: "none"`, |
| 150 | system: "none", |
| 151 | bootclasspath: []string{`""`}, |
| 152 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 153 | }, |
| 154 | { |
| 155 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 156 | name: "nostdlib system_modules", |
Pete Gillin | 84c3807 | 2020-07-09 18:03:41 +0100 | [diff] [blame] | 157 | properties: `sdk_version: "none", system_modules: "stable-core-platform-api-stubs-system-modules"`, |
| 158 | system: "stable-core-platform-api-stubs-system-modules", |
| 159 | bootclasspath: []string{"stable-core-platform-api-stubs-system-modules-lib"}, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 160 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 161 | }, |
| 162 | { |
| 163 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 164 | name: "host default", |
| 165 | moduleType: "java_library_host", |
| 166 | properties: ``, |
| 167 | host: android.Host, |
| 168 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
| 169 | java8classpath: []string{}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 170 | }, |
| 171 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 172 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 173 | name: "host supported default", |
| 174 | host: android.Host, |
| 175 | properties: `host_supported: true,`, |
| 176 | java8classpath: []string{}, |
| 177 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 178 | }, |
| 179 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 180 | name: "host supported nostdlib", |
| 181 | host: android.Host, |
| 182 | properties: `host_supported: true, sdk_version: "none", system_modules: "none"`, |
| 183 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 184 | }, |
| 185 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 186 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 187 | name: "unbundled sdk v29", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 188 | unbundled: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 189 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 190 | bootclasspath: []string{`""`}, |
| 191 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 192 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 193 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 194 | }, |
| 195 | { |
| 196 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 197 | name: "unbundled sdk v30", |
| 198 | unbundled: true, |
| 199 | properties: `sdk_version: "30",`, |
| 200 | bootclasspath: []string{`""`}, |
| 201 | system: "sdk_public_30_system_modules", |
| 202 | java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 203 | java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 204 | aidl: "-pprebuilts/sdk/30/public/framework.aidl", |
| 205 | }, |
| 206 | { |
| 207 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 208 | name: "unbundled current", |
| 209 | unbundled: true, |
| 210 | properties: `sdk_version: "current",`, |
| 211 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 212 | system: "sdk_public_current_system_modules", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 213 | java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 214 | java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 215 | aidl: "-pprebuilts/sdk/current/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 216 | }, |
| 217 | |
| 218 | { |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 219 | name: "module_current", |
| 220 | properties: `sdk_version: "module_current",`, |
| 221 | bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"}, |
Victor Chang | b54f5aa | 2021-06-29 22:05:58 +0100 | [diff] [blame] | 222 | system: "core-module-lib-stubs-system-modules", |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 223 | java9classpath: []string{"android_module_lib_stubs_current"}, |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 224 | aidl: "-pout/soong/framework_non_updatable.aidl", |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 225 | }, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 226 | { |
| 227 | name: "system_server_current", |
| 228 | properties: `sdk_version: "system_server_current",`, |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 229 | bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"}, |
Victor Chang | b54f5aa | 2021-06-29 22:05:58 +0100 | [diff] [blame] | 230 | system: "core-module-lib-stubs-system-modules", |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 231 | java9classpath: []string{"android_system_server_stubs_current"}, |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 232 | aidl: "-pout/soong/framework.aidl", |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 233 | }, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 234 | } |
| 235 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 236 | for _, testcase := range classpathTestcases { |
| 237 | t.Run(testcase.name, func(t *testing.T) { |
| 238 | moduleType := "java_library" |
| 239 | if testcase.moduleType != "" { |
| 240 | moduleType = testcase.moduleType |
| 241 | } |
| 242 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 243 | props := ` |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 244 | name: "foo", |
| 245 | srcs: ["a.java"], |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 246 | target: { |
| 247 | android: { |
| 248 | srcs: ["bar-doc/IFoo.aidl"], |
| 249 | }, |
| 250 | }, |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 251 | ` |
| 252 | bp := moduleType + " {" + props + testcase.properties + ` |
| 253 | }` |
| 254 | bpJava8 := moduleType + " {" + props + `java_version: "1.8", |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 255 | ` + testcase.properties + ` |
| 256 | }` |
| 257 | |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame^] | 258 | variant := func(result *android.TestResult) string { |
| 259 | if testcase.host == android.Host { |
| 260 | return result.Config.BuildOS.String() + "_common" |
| 261 | } |
| 262 | return "android_common" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | convertModulesToPaths := func(cp []string) []string { |
| 266 | ret := make([]string, len(cp)) |
| 267 | for i, e := range cp { |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 268 | ret[i] = defaultModuleToPath(e) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 269 | } |
| 270 | return ret |
| 271 | } |
| 272 | |
| 273 | bootclasspath := convertModulesToPaths(testcase.bootclasspath) |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 274 | java8classpath := convertModulesToPaths(testcase.java8classpath) |
| 275 | java9classpath := convertModulesToPaths(testcase.java9classpath) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 276 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 277 | bc := "" |
| 278 | var bcDeps []string |
| 279 | if len(bootclasspath) > 0 { |
| 280 | bc = "-bootclasspath " + strings.Join(bootclasspath, ":") |
| 281 | if bootclasspath[0] != `""` { |
| 282 | bcDeps = bootclasspath |
| 283 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 286 | j8c := "" |
| 287 | if len(java8classpath) > 0 { |
| 288 | j8c = "-classpath " + strings.Join(java8classpath, ":") |
| 289 | } |
| 290 | |
| 291 | j9c := "" |
| 292 | if len(java9classpath) > 0 { |
| 293 | j9c = "-classpath " + strings.Join(java9classpath, ":") |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 294 | } |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 295 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 296 | system := "" |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 297 | var systemDeps []string |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 298 | if testcase.system == "none" { |
| 299 | system = "--system=none" |
| 300 | } else if testcase.system != "" { |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 301 | dir := "" |
| 302 | if strings.HasPrefix(testcase.system, "sdk_public_") { |
| 303 | dir = "prebuilts/sdk" |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 304 | } else { |
| 305 | dir = defaultJavaDir |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 306 | } |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 307 | system = "--system=" + filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 308 | // The module-relative parts of these paths are hardcoded in system_modules.go: |
| 309 | systemDeps = []string{ |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 310 | filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "lib", "modules"), |
| 311 | filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "lib", "jrt-fs.jar"), |
| 312 | filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "release"), |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 313 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 316 | checkClasspath := func(t *testing.T, result *android.TestResult, isJava8 bool) { |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame^] | 317 | foo := result.ModuleForTests("foo", variant(result)) |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 318 | javac := foo.Rule("javac") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 319 | var deps []string |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 320 | |
Paul Duffin | a71a67a | 2021-03-29 00:42:57 +0100 | [diff] [blame] | 321 | aidl := foo.MaybeRule("aidl") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 322 | if aidl.Rule != nil { |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 323 | deps = append(deps, android.PathRelativeToTop(aidl.Output)) |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 324 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 325 | |
| 326 | got := javac.Args["bootClasspath"] |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 327 | expected := "" |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 328 | if isJava8 || testcase.forces8 { |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 329 | expected = bc |
| 330 | deps = append(deps, bcDeps...) |
| 331 | } else { |
| 332 | expected = system |
| 333 | deps = append(deps, systemDeps...) |
| 334 | } |
| 335 | if got != expected { |
| 336 | t.Errorf("bootclasspath expected %q != got %q", expected, got) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 339 | if isJava8 || testcase.forces8 { |
| 340 | expected = j8c |
| 341 | deps = append(deps, java8classpath...) |
| 342 | } else { |
| 343 | expected = j9c |
| 344 | deps = append(deps, java9classpath...) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 345 | } |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 346 | got = javac.Args["classpath"] |
| 347 | if got != expected { |
| 348 | t.Errorf("classpath expected %q != got %q", expected, got) |
| 349 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 350 | |
Paul Duffin | 414ea5e | 2021-03-22 17:31:52 +0000 | [diff] [blame] | 351 | android.AssertPathsRelativeToTopEquals(t, "implicits", deps, javac.Implicits) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Paul Duffin | 71ae594 | 2021-03-22 15:36:52 +0000 | [diff] [blame] | 354 | fixtureFactory := android.GroupFixturePreparers( |
| 355 | prepareForJavaTest, |
Paul Duffin | 171de3e | 2021-03-13 10:18:26 +0000 | [diff] [blame] | 356 | FixtureWithPrebuiltApis(map[string][]string{ |
| 357 | "29": {}, |
| 358 | "30": {}, |
| 359 | "current": {}, |
| 360 | }), |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 361 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 362 | if testcase.unbundled { |
| 363 | variables.Unbundled_build = proptools.BoolPtr(true) |
| 364 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 365 | } |
| 366 | }), |
| 367 | android.FixtureModifyEnv(func(env map[string]string) { |
| 368 | if env["ANDROID_JAVA8_HOME"] == "" { |
| 369 | env["ANDROID_JAVA8_HOME"] = "jdk8" |
| 370 | } |
| 371 | }), |
| 372 | ) |
| 373 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 374 | // Test with legacy javac -source 1.8 -target 1.8 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 375 | t.Run("Java language level 8", func(t *testing.T) { |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 376 | result := fixtureFactory.RunTestWithBp(t, bpJava8) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 377 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 378 | checkClasspath(t, result, true /* isJava8 */) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 379 | |
| 380 | if testcase.host != android.Host { |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame^] | 381 | aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl") |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 382 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 383 | android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.") |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 384 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 385 | }) |
| 386 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 387 | // Test with default javac -source 9 -target 9 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 388 | t.Run("Java language level 9", func(t *testing.T) { |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 389 | result := fixtureFactory.RunTestWithBp(t, bp) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 390 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 391 | checkClasspath(t, result, false /* isJava8 */) |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 392 | |
| 393 | if testcase.host != android.Host { |
Colin Cross | 0c66bc6 | 2021-07-20 09:47:41 -0700 | [diff] [blame^] | 394 | aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 395 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 396 | android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.") |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 397 | } |
| 398 | }) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 399 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 400 | prepareWithPlatformVersionRel := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 401 | variables.Platform_sdk_codename = proptools.StringPtr("REL") |
| 402 | variables.Platform_sdk_final = proptools.BoolPtr(true) |
| 403 | }) |
| 404 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 405 | // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8 |
| 406 | t.Run("REL + Java language level 8", func(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 407 | result := android.GroupFixturePreparers( |
| 408 | fixtureFactory, prepareWithPlatformVersionRel).RunTestWithBp(t, bpJava8) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 409 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 410 | checkClasspath(t, result, true /* isJava8 */) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 411 | }) |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 412 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 413 | // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9 |
| 414 | t.Run("REL + Java language level 9", func(t *testing.T) { |
Paul Duffin | 79abe57 | 2021-03-29 02:16:14 +0100 | [diff] [blame] | 415 | result := android.GroupFixturePreparers( |
| 416 | fixtureFactory, prepareWithPlatformVersionRel).RunTestWithBp(t, bp) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 417 | |
Paul Duffin | 76101fa | 2021-03-13 09:55:25 +0000 | [diff] [blame] | 418 | checkClasspath(t, result, false /* isJava8 */) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 419 | }) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 420 | }) |
| 421 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 422 | } |