blob: 9e8ba6ed064467ff97ad90cd4210420602dcde04 [file] [log] [blame]
Colin Crossfb6d7812019-01-09 22:17:55 -08001// 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
15package java
16
17import (
Colin Crossfb6d7812019-01-09 22:17:55 -080018 "path/filepath"
Colin Crossfb6d7812019-01-09 22:17:55 -080019 "strings"
20 "testing"
21
22 "github.com/google/blueprint/proptools"
Colin Cross60405e52019-04-18 12:31:22 -070023
24 "android/soong/android"
25 "android/soong/java/config"
Colin Crossfb6d7812019-01-09 22:17:55 -080026)
27
Paul Duffin0b3b36a2021-10-28 18:05:53 +010028type classpathTestCase struct {
29 name string
30 unbundled bool
31 moduleType string
32 host android.OsClass
33 properties string
34
35 // for java 8
36 bootclasspath []string
37 java8classpath []string
38
39 // for java 9
40 system string
41 java9classpath []string
42
43 forces8 bool // if set, javac will always be called with java 8 arguments
44
45 aidl string
Paul Duffin132c3e62021-10-28 18:16:14 +010046
47 // Indicates how this test case is affected by the setting of Always_use_prebuilt_sdks.
48 //
49 // If this is nil then the test case is unaffected by the setting of Always_use_prebuilt_sdks.
50 // Otherwise, the test case can only be used when
51 // Always_use_prebuilt_sdks=*forAlwaysUsePrebuiltSdks.
52 forAlwaysUsePrebuiltSdks *bool
Paul Duffin0b3b36a2021-10-28 18:05:53 +010053}
54
Colin Crossfb6d7812019-01-09 22:17:55 -080055func TestClasspath(t *testing.T) {
Paul Duffin76101fa2021-03-13 09:55:25 +000056 const frameworkAidl = "-I" + defaultJavaDir + "/framework/aidl"
Paul Duffin0b3b36a2021-10-28 18:05:53 +010057 var classpathTestcases = []classpathTestCase{
Colin Cross3047fa22019-04-18 10:56:44 -070058 {
Colin Cross617b1452019-10-25 15:22:50 -070059 name: "default",
Pete Gillin84c38072020-07-09 18:03:41 +010060 bootclasspath: config.StableCorePlatformBootclasspathLibraries,
61 system: config.StableCorePlatformSystemModules,
Pete Gillin0638dfc2020-07-01 10:48:14 +010062 java8classpath: config.FrameworkLibraries,
63 java9classpath: config.FrameworkLibraries,
Paul Duffin76101fa2021-03-13 09:55:25 +000064 aidl: frameworkAidl,
Colin Cross3047fa22019-04-18 10:56:44 -070065 },
66 {
Colin Cross617b1452019-10-25 15:22:50 -070067 name: `sdk_version:"core_platform"`,
68 properties: `sdk_version:"core_platform"`,
Pete Gillin84c38072020-07-09 18:03:41 +010069 bootclasspath: config.StableCorePlatformBootclasspathLibraries,
70 system: config.StableCorePlatformSystemModules,
Colin Cross617b1452019-10-25 15:22:50 -070071 java8classpath: []string{},
72 aidl: "",
Paul Duffin50c217c2019-06-12 13:25:22 +010073 },
74 {
Colin Cross617b1452019-10-25 15:22:50 -070075 name: "blank sdk version",
76 properties: `sdk_version: "",`,
Pete Gillin84c38072020-07-09 18:03:41 +010077 bootclasspath: config.StableCorePlatformBootclasspathLibraries,
78 system: config.StableCorePlatformSystemModules,
Pete Gillin0638dfc2020-07-01 10:48:14 +010079 java8classpath: config.FrameworkLibraries,
80 java9classpath: config.FrameworkLibraries,
Paul Duffin76101fa2021-03-13 09:55:25 +000081 aidl: frameworkAidl,
Colin Cross3047fa22019-04-18 10:56:44 -070082 },
83 {
84
Colin Cross74362a42019-10-28 08:05:02 -070085 name: "sdk v29",
86 properties: `sdk_version: "29",`,
Colin Cross617b1452019-10-25 15:22:50 -070087 bootclasspath: []string{`""`},
88 forces8: true,
Colin Cross74362a42019-10-28 08:05:02 -070089 java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
90 aidl: "-pprebuilts/sdk/29/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -070091 },
92 {
93
Colin Cross17dec172020-05-14 18:05:32 -070094 name: "sdk v30",
95 properties: `sdk_version: "30",`,
96 bootclasspath: []string{`""`},
97 system: "sdk_public_30_system_modules",
98 java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
99 java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
100 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
101 },
102 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100103 // Test case only applies when Always_use_prebuilt_sdks=false (the default).
104 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
Colin Cross17dec172020-05-14 18:05:32 -0700105
Colin Cross6cef4812019-10-17 14:23:50 -0700106 name: "current",
107 properties: `sdk_version: "current",`,
108 bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"},
Paul Duffin10fb76f2021-11-03 16:53:31 +0000109 system: "core-public-stubs-system-modules",
Colin Cross6cef4812019-10-17 14:23:50 -0700110 java9classpath: []string{"android_stubs_current"},
Paul Duffin414ea5e2021-03-22 17:31:52 +0000111 aidl: "-pout/soong/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700112 },
113 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100114 // Test case only applies when Always_use_prebuilt_sdks=true.
115 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
116
117 name: "current",
118 properties: `sdk_version: "current",`,
119 bootclasspath: []string{`""`},
120 system: "sdk_public_current_system_modules",
121 java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
122 java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
123 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
124 },
125 {
126 // Test case only applies when Always_use_prebuilt_sdks=false (the default).
127 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
Colin Cross3047fa22019-04-18 10:56:44 -0700128
Colin Cross6cef4812019-10-17 14:23:50 -0700129 name: "system_current",
130 properties: `sdk_version: "system_current",`,
131 bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"},
Paul Duffin10fb76f2021-11-03 16:53:31 +0000132 system: "core-public-stubs-system-modules",
Colin Cross6cef4812019-10-17 14:23:50 -0700133 java9classpath: []string{"android_system_stubs_current"},
Paul Duffin414ea5e2021-03-22 17:31:52 +0000134 aidl: "-pout/soong/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700135 },
136 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100137 // Test case only applies when Always_use_prebuilt_sdks=true.
138 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
Colin Cross3047fa22019-04-18 10:56:44 -0700139
Paul Duffin132c3e62021-10-28 18:16:14 +0100140 name: "system_current",
141 properties: `sdk_version: "system_current",`,
142 bootclasspath: []string{`""`},
143 system: "sdk_public_current_system_modules",
144 java8classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
145 java9classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
146 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
147 },
148 {
Colin Cross74362a42019-10-28 08:05:02 -0700149 name: "system_29",
150 properties: `sdk_version: "system_29",`,
Colin Cross617b1452019-10-25 15:22:50 -0700151 bootclasspath: []string{`""`},
152 forces8: true,
Colin Cross74362a42019-10-28 08:05:02 -0700153 java8classpath: []string{"prebuilts/sdk/29/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
154 aidl: "-pprebuilts/sdk/29/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700155 },
156 {
Colin Cross17dec172020-05-14 18:05:32 -0700157 name: "system_30",
158 properties: `sdk_version: "system_30",`,
159 bootclasspath: []string{`""`},
160 system: "sdk_public_30_system_modules",
161 java8classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
162 java9classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
163 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
164 },
165 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100166 // Test case only applies when Always_use_prebuilt_sdks=false (the default).
167 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
168
Colin Cross6cef4812019-10-17 14:23:50 -0700169 name: "test_current",
170 properties: `sdk_version: "test_current",`,
171 bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"},
Paul Duffin10fb76f2021-11-03 16:53:31 +0000172 system: "core-public-stubs-system-modules",
Colin Cross6cef4812019-10-17 14:23:50 -0700173 java9classpath: []string{"android_test_stubs_current"},
Paul Duffin414ea5e2021-03-22 17:31:52 +0000174 aidl: "-pout/soong/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700175 },
176 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100177 // Test case only applies when Always_use_prebuilt_sdks=true.
178 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
179
180 name: "test_current",
181 properties: `sdk_version: "test_current",`,
182 bootclasspath: []string{`""`},
183 system: "sdk_public_current_system_modules",
184 java8classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
185 java9classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
186 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
187 },
188 {
Paul Duffin12e311d2021-10-28 17:42:16 +0100189 name: "test_30",
190 properties: `sdk_version: "test_30",`,
191 bootclasspath: []string{`""`},
192 system: "sdk_public_30_system_modules",
193 java8classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
194 java9classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
195 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
196 },
197 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100198 // Test case only applies when Always_use_prebuilt_sdks=false (the default).
199 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
Colin Cross3047fa22019-04-18 10:56:44 -0700200
Pete Gillin880f9642020-07-01 13:17:16 +0100201 name: "core_current",
202 properties: `sdk_version: "core_current",`,
203 bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"},
Paul Duffin10fb76f2021-11-03 16:53:31 +0000204 system: "core-public-stubs-system-modules",
Colin Cross3047fa22019-04-18 10:56:44 -0700205 },
206 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100207 // Test case only applies when Always_use_prebuilt_sdks=true.
208 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
209
210 name: "core_current",
211 properties: `sdk_version: "core_current",`,
212 bootclasspath: []string{`""`},
213 system: "sdk_public_current_system_modules",
214 java8classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
215 java9classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
216 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
217 },
218 {
Colin Cross3047fa22019-04-18 10:56:44 -0700219
Colin Cross617b1452019-10-25 15:22:50 -0700220 name: "nostdlib",
221 properties: `sdk_version: "none", system_modules: "none"`,
222 system: "none",
223 bootclasspath: []string{`""`},
224 java8classpath: []string{},
Paul Duffin52d398a2019-06-11 12:31:14 +0100225 },
226 {
227
Colin Cross617b1452019-10-25 15:22:50 -0700228 name: "nostdlib system_modules",
Pete Gillin84c38072020-07-09 18:03:41 +0100229 properties: `sdk_version: "none", system_modules: "stable-core-platform-api-stubs-system-modules"`,
230 system: "stable-core-platform-api-stubs-system-modules",
231 bootclasspath: []string{"stable-core-platform-api-stubs-system-modules-lib"},
Colin Cross617b1452019-10-25 15:22:50 -0700232 java8classpath: []string{},
Paul Duffin52d398a2019-06-11 12:31:14 +0100233 },
234 {
235
Colin Cross617b1452019-10-25 15:22:50 -0700236 name: "host default",
237 moduleType: "java_library_host",
238 properties: ``,
239 host: android.Host,
240 bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
241 java8classpath: []string{},
Colin Cross3047fa22019-04-18 10:56:44 -0700242 },
243 {
Colin Cross3047fa22019-04-18 10:56:44 -0700244
Colin Cross617b1452019-10-25 15:22:50 -0700245 name: "host supported default",
246 host: android.Host,
247 properties: `host_supported: true,`,
248 java8classpath: []string{},
249 bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
Colin Cross3047fa22019-04-18 10:56:44 -0700250 },
251 {
Colin Cross617b1452019-10-25 15:22:50 -0700252 name: "host supported nostdlib",
253 host: android.Host,
254 properties: `host_supported: true, sdk_version: "none", system_modules: "none"`,
255 java8classpath: []string{},
Paul Duffin52d398a2019-06-11 12:31:14 +0100256 },
257 {
Colin Cross3047fa22019-04-18 10:56:44 -0700258
Colin Cross74362a42019-10-28 08:05:02 -0700259 name: "unbundled sdk v29",
Colin Cross617b1452019-10-25 15:22:50 -0700260 unbundled: true,
Colin Cross74362a42019-10-28 08:05:02 -0700261 properties: `sdk_version: "29",`,
Colin Cross617b1452019-10-25 15:22:50 -0700262 bootclasspath: []string{`""`},
263 forces8: true,
Colin Cross74362a42019-10-28 08:05:02 -0700264 java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
265 aidl: "-pprebuilts/sdk/29/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700266 },
267 {
268
Colin Cross17dec172020-05-14 18:05:32 -0700269 name: "unbundled sdk v30",
270 unbundled: true,
271 properties: `sdk_version: "30",`,
272 bootclasspath: []string{`""`},
273 system: "sdk_public_30_system_modules",
274 java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
275 java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
276 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
277 },
278 {
279
Colin Cross617b1452019-10-25 15:22:50 -0700280 name: "unbundled current",
281 unbundled: true,
282 properties: `sdk_version: "current",`,
283 bootclasspath: []string{`""`},
Colin Cross17dec172020-05-14 18:05:32 -0700284 system: "sdk_public_current_system_modules",
Colin Cross617b1452019-10-25 15:22:50 -0700285 java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
Colin Cross17dec172020-05-14 18:05:32 -0700286 java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
Colin Cross617b1452019-10-25 15:22:50 -0700287 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700288 },
Colin Cross3047fa22019-04-18 10:56:44 -0700289 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100290 // Test case only applies when Always_use_prebuilt_sdks=false (the default).
291 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
292
Jiyong Park50146e92020-01-30 18:00:15 +0900293 name: "module_current",
294 properties: `sdk_version: "module_current",`,
295 bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"},
Victor Changb54f5aa2021-06-29 22:05:58 +0100296 system: "core-module-lib-stubs-system-modules",
Jiyong Park50146e92020-01-30 18:00:15 +0900297 java9classpath: []string{"android_module_lib_stubs_current"},
Paul Duffin414ea5e2021-03-22 17:31:52 +0000298 aidl: "-pout/soong/framework_non_updatable.aidl",
Jiyong Park50146e92020-01-30 18:00:15 +0900299 },
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900300 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100301 // Test case only applies when Always_use_prebuilt_sdks=true.
302 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
303
304 name: "module_current",
305 properties: `sdk_version: "module_current",`,
306 bootclasspath: []string{`""`},
Paul Duffin004547f2021-10-29 13:50:24 +0100307 system: "sdk_module-lib_current_system_modules",
Paul Duffin132c3e62021-10-28 18:16:14 +0100308 java8classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
309 java9classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
310 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
311 },
312 {
Paul Duffin12e311d2021-10-28 17:42:16 +0100313 name: "module_30",
314 properties: `sdk_version: "module_30",`,
315 bootclasspath: []string{`""`},
316 system: "sdk_public_30_system_modules",
317 java8classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
318 java9classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
319 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
320 },
321 {
322 name: "module_31",
323 properties: `sdk_version: "module_31",`,
324 bootclasspath: []string{`""`},
325 system: "sdk_public_31_system_modules",
326 java8classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
327 java9classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
328 aidl: "-pprebuilts/sdk/31/public/framework.aidl",
329 },
330 {
331 name: "module_32",
332 properties: `sdk_version: "module_32",`,
333 bootclasspath: []string{`""`},
Paul Duffin004547f2021-10-29 13:50:24 +0100334 system: "sdk_module-lib_32_system_modules",
Paul Duffin12e311d2021-10-28 17:42:16 +0100335 java8classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
336 java9classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
337 aidl: "-pprebuilts/sdk/32/public/framework.aidl",
338 },
339 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100340 // Test case only applies when Always_use_prebuilt_sdks=false (the default).
341 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
342
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900343 name: "system_server_current",
344 properties: `sdk_version: "system_server_current",`,
Anton Hanssonba6ab2e2020-03-19 15:23:38 +0000345 bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"},
Victor Changb54f5aa2021-06-29 22:05:58 +0100346 system: "core-module-lib-stubs-system-modules",
Anton Hanssonba6ab2e2020-03-19 15:23:38 +0000347 java9classpath: []string{"android_system_server_stubs_current"},
Paul Duffin414ea5e2021-03-22 17:31:52 +0000348 aidl: "-pout/soong/framework.aidl",
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900349 },
Paul Duffin12e311d2021-10-28 17:42:16 +0100350 {
Paul Duffin132c3e62021-10-28 18:16:14 +0100351 // Test case only applies when Always_use_prebuilt_sdks=true.
352 forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
353
354 name: "system_server_current",
355 properties: `sdk_version: "system_server_current",`,
356 bootclasspath: []string{`""`},
Paul Duffin004547f2021-10-29 13:50:24 +0100357 system: "sdk_module-lib_current_system_modules",
Paul Duffin132c3e62021-10-28 18:16:14 +0100358 java8classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
359 java9classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
360 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
361 },
362 {
Paul Duffin12e311d2021-10-28 17:42:16 +0100363 name: "system_server_30",
364 properties: `sdk_version: "system_server_30",`,
365 bootclasspath: []string{`""`},
366 system: "sdk_public_30_system_modules",
367 java8classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
368 java9classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
369 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
370 },
371 {
372 name: "system_server_31",
373 properties: `sdk_version: "system_server_31",`,
374 bootclasspath: []string{`""`},
375 system: "sdk_public_31_system_modules",
376 java8classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
377 java9classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
378 aidl: "-pprebuilts/sdk/31/public/framework.aidl",
379 },
380 {
381 name: "system_server_32",
382 properties: `sdk_version: "system_server_32",`,
383 bootclasspath: []string{`""`},
Paul Duffin004547f2021-10-29 13:50:24 +0100384 system: "sdk_module-lib_32_system_modules",
Paul Duffin12e311d2021-10-28 17:42:16 +0100385 java8classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
386 java9classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
387 aidl: "-pprebuilts/sdk/32/public/framework.aidl",
388 },
Colin Cross3047fa22019-04-18 10:56:44 -0700389 }
390
Paul Duffin132c3e62021-10-28 18:16:14 +0100391 t.Run("basic", func(t *testing.T) {
392 testClasspathTestCases(t, classpathTestcases, false)
393 })
394
395 t.Run("Always_use_prebuilt_sdks=true", func(t *testing.T) {
396 testClasspathTestCases(t, classpathTestcases, true)
397 })
Paul Duffin0b3b36a2021-10-28 18:05:53 +0100398}
399
Paul Duffin132c3e62021-10-28 18:16:14 +0100400func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase, alwaysUsePrebuiltSdks bool) {
Colin Crossfb6d7812019-01-09 22:17:55 -0800401 for _, testcase := range classpathTestcases {
Paul Duffin132c3e62021-10-28 18:16:14 +0100402 if testcase.forAlwaysUsePrebuiltSdks != nil && *testcase.forAlwaysUsePrebuiltSdks != alwaysUsePrebuiltSdks {
403 continue
404 }
405
Colin Crossfb6d7812019-01-09 22:17:55 -0800406 t.Run(testcase.name, func(t *testing.T) {
407 moduleType := "java_library"
408 if testcase.moduleType != "" {
409 moduleType = testcase.moduleType
410 }
411
Pete Gillinbdf5d712019-10-21 14:29:58 +0100412 props := `
Colin Crossfb6d7812019-01-09 22:17:55 -0800413 name: "foo",
414 srcs: ["a.java"],
Colin Cross3047fa22019-04-18 10:56:44 -0700415 target: {
416 android: {
417 srcs: ["bar-doc/IFoo.aidl"],
418 },
419 },
Pete Gillinbdf5d712019-10-21 14:29:58 +0100420 `
421 bp := moduleType + " {" + props + testcase.properties + `
422 }`
423 bpJava8 := moduleType + " {" + props + `java_version: "1.8",
Colin Crossfb6d7812019-01-09 22:17:55 -0800424 ` + testcase.properties + `
425 }`
426
Colin Cross0c66bc62021-07-20 09:47:41 -0700427 variant := func(result *android.TestResult) string {
428 if testcase.host == android.Host {
429 return result.Config.BuildOS.String() + "_common"
430 }
431 return "android_common"
Colin Crossfb6d7812019-01-09 22:17:55 -0800432 }
433
434 convertModulesToPaths := func(cp []string) []string {
435 ret := make([]string, len(cp))
436 for i, e := range cp {
Paul Duffin76101fa2021-03-13 09:55:25 +0000437 ret[i] = defaultModuleToPath(e)
Colin Crossfb6d7812019-01-09 22:17:55 -0800438 }
439 return ret
440 }
441
442 bootclasspath := convertModulesToPaths(testcase.bootclasspath)
Colin Cross617b1452019-10-25 15:22:50 -0700443 java8classpath := convertModulesToPaths(testcase.java8classpath)
444 java9classpath := convertModulesToPaths(testcase.java9classpath)
Colin Crossfb6d7812019-01-09 22:17:55 -0800445
Pete Gillinbdf5d712019-10-21 14:29:58 +0100446 bc := ""
447 var bcDeps []string
448 if len(bootclasspath) > 0 {
449 bc = "-bootclasspath " + strings.Join(bootclasspath, ":")
450 if bootclasspath[0] != `""` {
451 bcDeps = bootclasspath
452 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800453 }
454
Colin Cross617b1452019-10-25 15:22:50 -0700455 j8c := ""
456 if len(java8classpath) > 0 {
457 j8c = "-classpath " + strings.Join(java8classpath, ":")
458 }
459
460 j9c := ""
461 if len(java9classpath) > 0 {
462 j9c = "-classpath " + strings.Join(java9classpath, ":")
Colin Crossfb6d7812019-01-09 22:17:55 -0800463 }
Pete Gillinbdf5d712019-10-21 14:29:58 +0100464
Colin Crossfb6d7812019-01-09 22:17:55 -0800465 system := ""
Pete Gillinbdf5d712019-10-21 14:29:58 +0100466 var systemDeps []string
Colin Crossfb6d7812019-01-09 22:17:55 -0800467 if testcase.system == "none" {
468 system = "--system=none"
469 } else if testcase.system != "" {
Colin Cross17dec172020-05-14 18:05:32 -0700470 dir := ""
Paul Duffin12e311d2021-10-28 17:42:16 +0100471 // If the system modules name starts with sdk_ then it is a prebuilt module and so comes
472 // from the prebuilt directory.
473 if strings.HasPrefix(testcase.system, "sdk_") {
Colin Cross17dec172020-05-14 18:05:32 -0700474 dir = "prebuilts/sdk"
Paul Duffin76101fa2021-03-13 09:55:25 +0000475 } else {
476 dir = defaultJavaDir
Colin Cross17dec172020-05-14 18:05:32 -0700477 }
Paul Duffin414ea5e2021-03-22 17:31:52 +0000478 system = "--system=" + filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system")
Pete Gillinbdf5d712019-10-21 14:29:58 +0100479 // The module-relative parts of these paths are hardcoded in system_modules.go:
480 systemDeps = []string{
Paul Duffin414ea5e2021-03-22 17:31:52 +0000481 filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "lib", "modules"),
482 filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "lib", "jrt-fs.jar"),
483 filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "release"),
Pete Gillinbdf5d712019-10-21 14:29:58 +0100484 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800485 }
486
Paul Duffin76101fa2021-03-13 09:55:25 +0000487 checkClasspath := func(t *testing.T, result *android.TestResult, isJava8 bool) {
Colin Cross0c66bc62021-07-20 09:47:41 -0700488 foo := result.ModuleForTests("foo", variant(result))
Paul Duffina71a67a2021-03-29 00:42:57 +0100489 javac := foo.Rule("javac")
Pete Gillinbdf5d712019-10-21 14:29:58 +0100490 var deps []string
Colin Crossc0806172019-06-14 18:51:47 -0700491
Paul Duffina71a67a2021-03-29 00:42:57 +0100492 aidl := foo.MaybeRule("aidl")
Pete Gillinbdf5d712019-10-21 14:29:58 +0100493 if aidl.Rule != nil {
Paul Duffin414ea5e2021-03-22 17:31:52 +0000494 deps = append(deps, android.PathRelativeToTop(aidl.Output))
Pete Gillinbdf5d712019-10-21 14:29:58 +0100495 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800496
497 got := javac.Args["bootClasspath"]
Pete Gillinbdf5d712019-10-21 14:29:58 +0100498 expected := ""
Colin Cross617b1452019-10-25 15:22:50 -0700499 if isJava8 || testcase.forces8 {
Pete Gillinbdf5d712019-10-21 14:29:58 +0100500 expected = bc
501 deps = append(deps, bcDeps...)
502 } else {
503 expected = system
504 deps = append(deps, systemDeps...)
505 }
506 if got != expected {
507 t.Errorf("bootclasspath expected %q != got %q", expected, got)
Colin Crossfb6d7812019-01-09 22:17:55 -0800508 }
509
Colin Cross617b1452019-10-25 15:22:50 -0700510 if isJava8 || testcase.forces8 {
511 expected = j8c
512 deps = append(deps, java8classpath...)
513 } else {
514 expected = j9c
515 deps = append(deps, java9classpath...)
Colin Crossfb6d7812019-01-09 22:17:55 -0800516 }
Colin Cross617b1452019-10-25 15:22:50 -0700517 got = javac.Args["classpath"]
518 if got != expected {
519 t.Errorf("classpath expected %q != got %q", expected, got)
520 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800521
Paul Duffin414ea5e2021-03-22 17:31:52 +0000522 android.AssertPathsRelativeToTopEquals(t, "implicits", deps, javac.Implicits)
Colin Cross3047fa22019-04-18 10:56:44 -0700523 }
524
Paul Duffin132c3e62021-10-28 18:16:14 +0100525 preparer := android.NullFixturePreparer
526 if alwaysUsePrebuiltSdks {
527 preparer = android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
528 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
529 })
530 }
531
Paul Duffin71ae5942021-03-22 15:36:52 +0000532 fixtureFactory := android.GroupFixturePreparers(
533 prepareForJavaTest,
Paul Duffin171de3e2021-03-13 10:18:26 +0000534 FixtureWithPrebuiltApis(map[string][]string{
535 "29": {},
536 "30": {},
Paul Duffin12e311d2021-10-28 17:42:16 +0100537 "31": {},
538 "32": {},
Paul Duffin171de3e2021-03-13 10:18:26 +0000539 "current": {},
540 }),
Paul Duffin76101fa2021-03-13 09:55:25 +0000541 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
542 if testcase.unbundled {
543 variables.Unbundled_build = proptools.BoolPtr(true)
544 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
545 }
546 }),
547 android.FixtureModifyEnv(func(env map[string]string) {
548 if env["ANDROID_JAVA8_HOME"] == "" {
549 env["ANDROID_JAVA8_HOME"] = "jdk8"
550 }
551 }),
Paul Duffin132c3e62021-10-28 18:16:14 +0100552 preparer,
Paul Duffin76101fa2021-03-13 09:55:25 +0000553 )
554
Pete Gillin1b3370f2019-10-01 13:57:31 +0100555 // Test with legacy javac -source 1.8 -target 1.8
Pete Gillin0c2143e2019-05-02 15:32:11 +0100556 t.Run("Java language level 8", func(t *testing.T) {
Paul Duffin76101fa2021-03-13 09:55:25 +0000557 result := fixtureFactory.RunTestWithBp(t, bpJava8)
Colin Cross3047fa22019-04-18 10:56:44 -0700558
Paul Duffin76101fa2021-03-13 09:55:25 +0000559 checkClasspath(t, result, true /* isJava8 */)
Colin Cross3047fa22019-04-18 10:56:44 -0700560
561 if testcase.host != android.Host {
Colin Cross0c66bc62021-07-20 09:47:41 -0700562 aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl")
Colin Cross3047fa22019-04-18 10:56:44 -0700563
Paul Duffin76101fa2021-03-13 09:55:25 +0000564 android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.")
Colin Cross3047fa22019-04-18 10:56:44 -0700565 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800566 })
567
Pete Gillin1b3370f2019-10-01 13:57:31 +0100568 // Test with default javac -source 9 -target 9
Pete Gillin0c2143e2019-05-02 15:32:11 +0100569 t.Run("Java language level 9", func(t *testing.T) {
Paul Duffin76101fa2021-03-13 09:55:25 +0000570 result := fixtureFactory.RunTestWithBp(t, bp)
Colin Crossfb6d7812019-01-09 22:17:55 -0800571
Paul Duffin76101fa2021-03-13 09:55:25 +0000572 checkClasspath(t, result, false /* isJava8 */)
Pete Gillinbdf5d712019-10-21 14:29:58 +0100573
574 if testcase.host != android.Host {
Colin Cross0c66bc62021-07-20 09:47:41 -0700575 aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl")
Pete Gillinbdf5d712019-10-21 14:29:58 +0100576
Paul Duffin76101fa2021-03-13 09:55:25 +0000577 android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.")
Colin Crossfb6d7812019-01-09 22:17:55 -0800578 }
579 })
Colin Crossff0daf42019-04-02 16:10:56 -0700580
Paul Duffin76101fa2021-03-13 09:55:25 +0000581 prepareWithPlatformVersionRel := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
582 variables.Platform_sdk_codename = proptools.StringPtr("REL")
583 variables.Platform_sdk_final = proptools.BoolPtr(true)
584 })
585
Pete Gillinbdf5d712019-10-21 14:29:58 +0100586 // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8
587 t.Run("REL + Java language level 8", func(t *testing.T) {
Paul Duffin79abe572021-03-29 02:16:14 +0100588 result := android.GroupFixturePreparers(
589 fixtureFactory, prepareWithPlatformVersionRel).RunTestWithBp(t, bpJava8)
Colin Crossff0daf42019-04-02 16:10:56 -0700590
Paul Duffin76101fa2021-03-13 09:55:25 +0000591 checkClasspath(t, result, true /* isJava8 */)
Colin Crossff0daf42019-04-02 16:10:56 -0700592 })
Pete Gillinbdf5d712019-10-21 14:29:58 +0100593
Colin Cross6cef4812019-10-17 14:23:50 -0700594 // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9
595 t.Run("REL + Java language level 9", func(t *testing.T) {
Paul Duffin79abe572021-03-29 02:16:14 +0100596 result := android.GroupFixturePreparers(
597 fixtureFactory, prepareWithPlatformVersionRel).RunTestWithBp(t, bp)
Colin Cross6cef4812019-10-17 14:23:50 -0700598
Paul Duffin76101fa2021-03-13 09:55:25 +0000599 checkClasspath(t, result, false /* isJava8 */)
Colin Cross6cef4812019-10-17 14:23:50 -0700600 })
Colin Crossfb6d7812019-01-09 22:17:55 -0800601 })
602 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800603}