blob: 773a70c9e8bec6d0eb412ce62a3a7f56c741de53 [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"
19 "reflect"
20 "strings"
21 "testing"
22
23 "github.com/google/blueprint/proptools"
Colin Cross60405e52019-04-18 12:31:22 -070024
25 "android/soong/android"
26 "android/soong/java/config"
Colin Crossfb6d7812019-01-09 22:17:55 -080027)
28
Colin Crossfb6d7812019-01-09 22:17:55 -080029func TestClasspath(t *testing.T) {
Colin Cross3047fa22019-04-18 10:56:44 -070030 var classpathTestcases = []struct {
Colin Cross617b1452019-10-25 15:22:50 -070031 name string
32 unbundled bool
33 pdk bool
34 moduleType string
35 host android.OsClass
36 properties string
37
38 // for java 8
39 bootclasspath []string
40 java8classpath []string
41
42 // for java 9
43 system string
44 java9classpath []string
45
46 forces8 bool // if set, javac will always be called with java 8 arguments
47
48 aidl string
Colin Cross3047fa22019-04-18 10:56:44 -070049 }{
50 {
Colin Cross617b1452019-10-25 15:22:50 -070051 name: "default",
Pete Gillin0638dfc2020-07-01 10:48:14 +010052 bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
53 system: config.LegacyCorePlatformSystemModules,
54 java8classpath: config.FrameworkLibraries,
55 java9classpath: config.FrameworkLibraries,
Colin Cross617b1452019-10-25 15:22:50 -070056 aidl: "-Iframework/aidl",
Colin Cross3047fa22019-04-18 10:56:44 -070057 },
58 {
Colin Cross617b1452019-10-25 15:22:50 -070059 name: `sdk_version:"core_platform"`,
60 properties: `sdk_version:"core_platform"`,
Pete Gillin0638dfc2020-07-01 10:48:14 +010061 bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
62 system: config.LegacyCorePlatformSystemModules,
Colin Cross617b1452019-10-25 15:22:50 -070063 java8classpath: []string{},
64 aidl: "",
Paul Duffin50c217c2019-06-12 13:25:22 +010065 },
66 {
Colin Cross617b1452019-10-25 15:22:50 -070067 name: "blank sdk version",
68 properties: `sdk_version: "",`,
Pete Gillin0638dfc2020-07-01 10:48:14 +010069 bootclasspath: config.LegacyCorePlatformBootclasspathLibraries,
70 system: config.LegacyCorePlatformSystemModules,
71 java8classpath: config.FrameworkLibraries,
72 java9classpath: config.FrameworkLibraries,
Colin Cross617b1452019-10-25 15:22:50 -070073 aidl: "-Iframework/aidl",
Colin Cross3047fa22019-04-18 10:56:44 -070074 },
75 {
76
Colin Cross74362a42019-10-28 08:05:02 -070077 name: "sdk v29",
78 properties: `sdk_version: "29",`,
Colin Cross617b1452019-10-25 15:22:50 -070079 bootclasspath: []string{`""`},
80 forces8: true,
Colin Cross74362a42019-10-28 08:05:02 -070081 java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
82 aidl: "-pprebuilts/sdk/29/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -070083 },
84 {
85
Colin Cross17dec172020-05-14 18:05:32 -070086 name: "sdk v30",
87 properties: `sdk_version: "30",`,
88 bootclasspath: []string{`""`},
89 system: "sdk_public_30_system_modules",
90 java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
91 java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
92 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
93 },
94 {
95
Colin Cross6cef4812019-10-17 14:23:50 -070096 name: "current",
97 properties: `sdk_version: "current",`,
98 bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"},
99 system: "core-current-stubs-system-modules",
100 java9classpath: []string{"android_stubs_current"},
101 aidl: "-p" + buildDir + "/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700102 },
103 {
104
Colin Cross6cef4812019-10-17 14:23:50 -0700105 name: "system_current",
106 properties: `sdk_version: "system_current",`,
107 bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"},
108 system: "core-current-stubs-system-modules",
109 java9classpath: []string{"android_system_stubs_current"},
110 aidl: "-p" + buildDir + "/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700111 },
112 {
113
Colin Cross74362a42019-10-28 08:05:02 -0700114 name: "system_29",
115 properties: `sdk_version: "system_29",`,
Colin Cross617b1452019-10-25 15:22:50 -0700116 bootclasspath: []string{`""`},
117 forces8: true,
Colin Cross74362a42019-10-28 08:05:02 -0700118 java8classpath: []string{"prebuilts/sdk/29/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
119 aidl: "-pprebuilts/sdk/29/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700120 },
121 {
122
Colin Cross17dec172020-05-14 18:05:32 -0700123 name: "system_30",
124 properties: `sdk_version: "system_30",`,
125 bootclasspath: []string{`""`},
126 system: "sdk_public_30_system_modules",
127 java8classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
128 java9classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
129 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
130 },
131 {
132
Colin Cross6cef4812019-10-17 14:23:50 -0700133 name: "test_current",
134 properties: `sdk_version: "test_current",`,
135 bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"},
136 system: "core-current-stubs-system-modules",
137 java9classpath: []string{"android_test_stubs_current"},
138 aidl: "-p" + buildDir + "/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700139 },
140 {
141
Colin Cross6cef4812019-10-17 14:23:50 -0700142 name: "core_current",
143 properties: `sdk_version: "core_current",`,
144 bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"},
145 system: "core-current-stubs-system-modules",
146 java9classpath: []string{"core.current.stubs"},
Colin Cross3047fa22019-04-18 10:56:44 -0700147 },
148 {
149
Colin Cross617b1452019-10-25 15:22:50 -0700150 name: "nostdlib",
151 properties: `sdk_version: "none", system_modules: "none"`,
152 system: "none",
153 bootclasspath: []string{`""`},
154 java8classpath: []string{},
Paul Duffin52d398a2019-06-11 12:31:14 +0100155 },
156 {
157
Colin Cross617b1452019-10-25 15:22:50 -0700158 name: "nostdlib system_modules",
Pete Gillin1f41dbf2020-06-02 15:59:45 +0100159 properties: `sdk_version: "none", system_modules: "legacy-core-platform-api-stubs-system-modules"`,
160 system: "legacy-core-platform-api-stubs-system-modules",
161 bootclasspath: []string{"legacy-core-platform-api-stubs-system-modules-lib"},
Colin Cross617b1452019-10-25 15:22:50 -0700162 java8classpath: []string{},
Paul Duffin52d398a2019-06-11 12:31:14 +0100163 },
164 {
165
Colin Cross617b1452019-10-25 15:22:50 -0700166 name: "host default",
167 moduleType: "java_library_host",
168 properties: ``,
169 host: android.Host,
170 bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
171 java8classpath: []string{},
Colin Cross3047fa22019-04-18 10:56:44 -0700172 },
173 {
Colin Cross3047fa22019-04-18 10:56:44 -0700174
Colin Cross617b1452019-10-25 15:22:50 -0700175 name: "host supported default",
176 host: android.Host,
177 properties: `host_supported: true,`,
178 java8classpath: []string{},
179 bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
Colin Cross3047fa22019-04-18 10:56:44 -0700180 },
181 {
Colin Cross617b1452019-10-25 15:22:50 -0700182 name: "host supported nostdlib",
183 host: android.Host,
184 properties: `host_supported: true, sdk_version: "none", system_modules: "none"`,
185 java8classpath: []string{},
Paul Duffin52d398a2019-06-11 12:31:14 +0100186 },
187 {
Colin Cross3047fa22019-04-18 10:56:44 -0700188
Colin Cross74362a42019-10-28 08:05:02 -0700189 name: "unbundled sdk v29",
Colin Cross617b1452019-10-25 15:22:50 -0700190 unbundled: true,
Colin Cross74362a42019-10-28 08:05:02 -0700191 properties: `sdk_version: "29",`,
Colin Cross617b1452019-10-25 15:22:50 -0700192 bootclasspath: []string{`""`},
193 forces8: true,
Colin Cross74362a42019-10-28 08:05:02 -0700194 java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
195 aidl: "-pprebuilts/sdk/29/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700196 },
197 {
198
Colin Cross17dec172020-05-14 18:05:32 -0700199 name: "unbundled sdk v30",
200 unbundled: true,
201 properties: `sdk_version: "30",`,
202 bootclasspath: []string{`""`},
203 system: "sdk_public_30_system_modules",
204 java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
205 java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
206 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
207 },
208 {
209
Colin Cross617b1452019-10-25 15:22:50 -0700210 name: "unbundled current",
211 unbundled: true,
212 properties: `sdk_version: "current",`,
213 bootclasspath: []string{`""`},
Colin Cross17dec172020-05-14 18:05:32 -0700214 system: "sdk_public_current_system_modules",
Colin Cross617b1452019-10-25 15:22:50 -0700215 java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
Colin Cross17dec172020-05-14 18:05:32 -0700216 java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
Colin Cross617b1452019-10-25 15:22:50 -0700217 aidl: "-pprebuilts/sdk/current/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700218 },
219
220 {
Colin Cross617b1452019-10-25 15:22:50 -0700221 name: "pdk default",
222 pdk: true,
223 bootclasspath: []string{`""`},
Colin Cross17dec172020-05-14 18:05:32 -0700224 system: "sdk_public_30_system_modules",
225 java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
226 java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
227 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700228 },
229 {
Colin Cross617b1452019-10-25 15:22:50 -0700230 name: "pdk current",
231 pdk: true,
232 properties: `sdk_version: "current",`,
233 bootclasspath: []string{`""`},
Colin Cross17dec172020-05-14 18:05:32 -0700234 system: "sdk_public_30_system_modules",
235 java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
236 java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
237 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700238 },
239 {
Colin Cross74362a42019-10-28 08:05:02 -0700240 name: "pdk 29",
Colin Cross617b1452019-10-25 15:22:50 -0700241 pdk: true,
Colin Cross74362a42019-10-28 08:05:02 -0700242 properties: `sdk_version: "29",`,
Colin Cross617b1452019-10-25 15:22:50 -0700243 bootclasspath: []string{`""`},
Colin Cross17dec172020-05-14 18:05:32 -0700244 system: "sdk_public_30_system_modules",
245 java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
246 java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
247 aidl: "-pprebuilts/sdk/30/public/framework.aidl",
Colin Cross3047fa22019-04-18 10:56:44 -0700248 },
Jiyong Park50146e92020-01-30 18:00:15 +0900249 {
Jiyong Park50146e92020-01-30 18:00:15 +0900250 name: "module_current",
251 properties: `sdk_version: "module_current",`,
252 bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"},
253 system: "core-current-stubs-system-modules",
254 java9classpath: []string{"android_module_lib_stubs_current"},
Anton Hansson3f07ab22020-04-09 13:29:59 +0100255 aidl: "-p" + buildDir + "/framework_non_updatable.aidl",
Jiyong Park50146e92020-01-30 18:00:15 +0900256 },
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900257 {
258 name: "system_server_current",
259 properties: `sdk_version: "system_server_current",`,
Anton Hanssonba6ab2e2020-03-19 15:23:38 +0000260 bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"},
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900261 system: "core-current-stubs-system-modules",
Anton Hanssonba6ab2e2020-03-19 15:23:38 +0000262 java9classpath: []string{"android_system_server_stubs_current"},
Jiyong Parkaae9bd12020-02-12 04:36:43 +0900263 aidl: "-p" + buildDir + "/framework.aidl",
264 },
Colin Cross3047fa22019-04-18 10:56:44 -0700265 }
266
Colin Crossfb6d7812019-01-09 22:17:55 -0800267 for _, testcase := range classpathTestcases {
268 t.Run(testcase.name, func(t *testing.T) {
269 moduleType := "java_library"
270 if testcase.moduleType != "" {
271 moduleType = testcase.moduleType
272 }
273
Pete Gillinbdf5d712019-10-21 14:29:58 +0100274 props := `
Colin Crossfb6d7812019-01-09 22:17:55 -0800275 name: "foo",
276 srcs: ["a.java"],
Colin Cross3047fa22019-04-18 10:56:44 -0700277 target: {
278 android: {
279 srcs: ["bar-doc/IFoo.aidl"],
280 },
281 },
Pete Gillinbdf5d712019-10-21 14:29:58 +0100282 `
283 bp := moduleType + " {" + props + testcase.properties + `
284 }`
285 bpJava8 := moduleType + " {" + props + `java_version: "1.8",
Colin Crossfb6d7812019-01-09 22:17:55 -0800286 ` + testcase.properties + `
287 }`
288
289 variant := "android_common"
290 if testcase.host == android.Host {
291 variant = android.BuildOs.String() + "_common"
292 }
293
294 convertModulesToPaths := func(cp []string) []string {
295 ret := make([]string, len(cp))
296 for i, e := range cp {
297 ret[i] = moduleToPath(e)
298 }
299 return ret
300 }
301
302 bootclasspath := convertModulesToPaths(testcase.bootclasspath)
Colin Cross617b1452019-10-25 15:22:50 -0700303 java8classpath := convertModulesToPaths(testcase.java8classpath)
304 java9classpath := convertModulesToPaths(testcase.java9classpath)
Colin Crossfb6d7812019-01-09 22:17:55 -0800305
Pete Gillinbdf5d712019-10-21 14:29:58 +0100306 bc := ""
307 var bcDeps []string
308 if len(bootclasspath) > 0 {
309 bc = "-bootclasspath " + strings.Join(bootclasspath, ":")
310 if bootclasspath[0] != `""` {
311 bcDeps = bootclasspath
312 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800313 }
314
Colin Cross617b1452019-10-25 15:22:50 -0700315 j8c := ""
316 if len(java8classpath) > 0 {
317 j8c = "-classpath " + strings.Join(java8classpath, ":")
318 }
319
320 j9c := ""
321 if len(java9classpath) > 0 {
322 j9c = "-classpath " + strings.Join(java9classpath, ":")
Colin Crossfb6d7812019-01-09 22:17:55 -0800323 }
Pete Gillinbdf5d712019-10-21 14:29:58 +0100324
Colin Crossfb6d7812019-01-09 22:17:55 -0800325 system := ""
Pete Gillinbdf5d712019-10-21 14:29:58 +0100326 var systemDeps []string
Colin Crossfb6d7812019-01-09 22:17:55 -0800327 if testcase.system == "none" {
328 system = "--system=none"
329 } else if testcase.system != "" {
Colin Cross17dec172020-05-14 18:05:32 -0700330 dir := ""
331 if strings.HasPrefix(testcase.system, "sdk_public_") {
332 dir = "prebuilts/sdk"
333 }
334 system = "--system=" + filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system")
Pete Gillinbdf5d712019-10-21 14:29:58 +0100335 // The module-relative parts of these paths are hardcoded in system_modules.go:
336 systemDeps = []string{
Colin Cross17dec172020-05-14 18:05:32 -0700337 filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system", "lib", "modules"),
338 filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system", "lib", "jrt-fs.jar"),
339 filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system", "release"),
Pete Gillinbdf5d712019-10-21 14:29:58 +0100340 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800341 }
342
Pete Gillinbdf5d712019-10-21 14:29:58 +0100343 checkClasspath := func(t *testing.T, ctx *android.TestContext, isJava8 bool) {
Colin Crossc0806172019-06-14 18:51:47 -0700344 foo := ctx.ModuleForTests("foo", variant)
345 javac := foo.Rule("javac")
Pete Gillinbdf5d712019-10-21 14:29:58 +0100346 var deps []string
Colin Crossc0806172019-06-14 18:51:47 -0700347
348 aidl := foo.MaybeRule("aidl")
Pete Gillinbdf5d712019-10-21 14:29:58 +0100349 if aidl.Rule != nil {
350 deps = append(deps, aidl.Output.String())
351 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800352
353 got := javac.Args["bootClasspath"]
Pete Gillinbdf5d712019-10-21 14:29:58 +0100354 expected := ""
Colin Cross617b1452019-10-25 15:22:50 -0700355 if isJava8 || testcase.forces8 {
Pete Gillinbdf5d712019-10-21 14:29:58 +0100356 expected = bc
357 deps = append(deps, bcDeps...)
358 } else {
359 expected = system
360 deps = append(deps, systemDeps...)
361 }
362 if got != expected {
363 t.Errorf("bootclasspath expected %q != got %q", expected, got)
Colin Crossfb6d7812019-01-09 22:17:55 -0800364 }
365
Colin Cross617b1452019-10-25 15:22:50 -0700366 if isJava8 || testcase.forces8 {
367 expected = j8c
368 deps = append(deps, java8classpath...)
369 } else {
370 expected = j9c
371 deps = append(deps, java9classpath...)
Colin Crossfb6d7812019-01-09 22:17:55 -0800372 }
Colin Cross617b1452019-10-25 15:22:50 -0700373 got = javac.Args["classpath"]
374 if got != expected {
375 t.Errorf("classpath expected %q != got %q", expected, got)
376 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800377
378 if !reflect.DeepEqual(javac.Implicits.Strings(), deps) {
379 t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings())
380 }
Colin Cross3047fa22019-04-18 10:56:44 -0700381 }
382
Pete Gillin1b3370f2019-10-01 13:57:31 +0100383 // Test with legacy javac -source 1.8 -target 1.8
Pete Gillin0c2143e2019-05-02 15:32:11 +0100384 t.Run("Java language level 8", func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800385 config := testConfig(nil, bpJava8, nil)
Colin Cross3047fa22019-04-18 10:56:44 -0700386 if testcase.unbundled {
387 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
388 }
389 if testcase.pdk {
390 config.TestProductVariables.Pdk = proptools.BoolPtr(true)
391 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800392 ctx := testContext()
Colin Cross3047fa22019-04-18 10:56:44 -0700393 run(t, ctx, config)
394
Pete Gillinbdf5d712019-10-21 14:29:58 +0100395 checkClasspath(t, ctx, true /* isJava8 */)
Colin Cross3047fa22019-04-18 10:56:44 -0700396
397 if testcase.host != android.Host {
398 aidl := ctx.ModuleForTests("foo", variant).Rule("aidl")
399
Colin Crossc0806172019-06-14 18:51:47 -0700400 if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) {
401 t.Errorf("want aidl command to contain %q, got %q", w, g)
Colin Cross3047fa22019-04-18 10:56:44 -0700402 }
403 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800404 })
405
Pete Gillin1b3370f2019-10-01 13:57:31 +0100406 // Test with default javac -source 9 -target 9
Pete Gillin0c2143e2019-05-02 15:32:11 +0100407 t.Run("Java language level 9", func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800408 config := testConfig(nil, bp, nil)
Colin Crossfb6d7812019-01-09 22:17:55 -0800409 if testcase.unbundled {
410 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
411 }
Colin Cross98fd5742019-01-09 23:04:25 -0800412 if testcase.pdk {
413 config.TestProductVariables.Pdk = proptools.BoolPtr(true)
414 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800415 ctx := testContext()
Colin Crossfb6d7812019-01-09 22:17:55 -0800416 run(t, ctx, config)
417
Pete Gillinbdf5d712019-10-21 14:29:58 +0100418 checkClasspath(t, ctx, false /* isJava8 */)
419
420 if testcase.host != android.Host {
421 aidl := ctx.ModuleForTests("foo", variant).Rule("aidl")
422
423 if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) {
424 t.Errorf("want aidl command to contain %q, got %q", w, g)
425 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800426 }
427 })
Colin Crossff0daf42019-04-02 16:10:56 -0700428
Pete Gillinbdf5d712019-10-21 14:29:58 +0100429 // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8
430 t.Run("REL + Java language level 8", func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800431 config := testConfig(nil, bpJava8, nil)
Colin Crossff0daf42019-04-02 16:10:56 -0700432 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
433 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
434
435 if testcase.unbundled {
436 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
437 }
438 if testcase.pdk {
439 config.TestProductVariables.Pdk = proptools.BoolPtr(true)
440 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800441 ctx := testContext()
Colin Crossff0daf42019-04-02 16:10:56 -0700442 run(t, ctx, config)
443
Pete Gillinbdf5d712019-10-21 14:29:58 +0100444 checkClasspath(t, ctx, true /* isJava8 */)
Colin Crossff0daf42019-04-02 16:10:56 -0700445 })
Pete Gillinbdf5d712019-10-21 14:29:58 +0100446
Colin Cross6cef4812019-10-17 14:23:50 -0700447 // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9
448 t.Run("REL + Java language level 9", func(t *testing.T) {
Colin Cross98be1bb2019-12-13 20:41:13 -0800449 config := testConfig(nil, bp, nil)
Colin Cross6cef4812019-10-17 14:23:50 -0700450 config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL")
451 config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true)
452
453 if testcase.unbundled {
454 config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true)
455 }
456 if testcase.pdk {
457 config.TestProductVariables.Pdk = proptools.BoolPtr(true)
458 }
Colin Cross98be1bb2019-12-13 20:41:13 -0800459 ctx := testContext()
Colin Cross6cef4812019-10-17 14:23:50 -0700460 run(t, ctx, config)
461
462 checkClasspath(t, ctx, false /* isJava8 */)
463 })
Colin Crossfb6d7812019-01-09 22:17:55 -0800464 })
465 }
Colin Crossfb6d7812019-01-09 22:17:55 -0800466}