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" |
| 19 | "reflect" |
| 20 | "strings" |
| 21 | "testing" |
| 22 | |
| 23 | "github.com/google/blueprint/proptools" |
Colin Cross | 60405e5 | 2019-04-18 12:31:22 -0700 | [diff] [blame] | 24 | |
| 25 | "android/soong/android" |
| 26 | "android/soong/java/config" |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 27 | ) |
| 28 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 29 | func TestClasspath(t *testing.T) { |
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 |
| 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 49 | }{ |
| 50 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 51 | name: "default", |
| 52 | bootclasspath: config.DefaultBootclasspathLibraries, |
| 53 | system: config.DefaultSystemModules, |
| 54 | java8classpath: config.DefaultLibraries, |
| 55 | java9classpath: config.DefaultLibraries, |
| 56 | aidl: "-Iframework/aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 57 | }, |
| 58 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 59 | name: `sdk_version:"core_platform"`, |
| 60 | properties: `sdk_version:"core_platform"`, |
| 61 | bootclasspath: config.DefaultBootclasspathLibraries, |
| 62 | system: config.DefaultSystemModules, |
| 63 | java8classpath: []string{}, |
| 64 | aidl: "", |
Paul Duffin | 50c217c | 2019-06-12 13:25:22 +0100 | [diff] [blame] | 65 | }, |
| 66 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 67 | name: "blank sdk version", |
| 68 | properties: `sdk_version: "",`, |
| 69 | bootclasspath: config.DefaultBootclasspathLibraries, |
| 70 | system: config.DefaultSystemModules, |
| 71 | java8classpath: config.DefaultLibraries, |
| 72 | java9classpath: config.DefaultLibraries, |
| 73 | aidl: "-Iframework/aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 74 | }, |
| 75 | { |
| 76 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 77 | name: "sdk v29", |
| 78 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 79 | bootclasspath: []string{`""`}, |
| 80 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 81 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 82 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 83 | }, |
| 84 | { |
| 85 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 86 | name: "current", |
| 87 | properties: `sdk_version: "current",`, |
| 88 | bootclasspath: []string{"android_stubs_current", "core-lambda-stubs"}, |
| 89 | system: "core-current-stubs-system-modules", |
| 90 | java9classpath: []string{"android_stubs_current"}, |
| 91 | aidl: "-p" + buildDir + "/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 92 | }, |
| 93 | { |
| 94 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 95 | name: "system_current", |
| 96 | properties: `sdk_version: "system_current",`, |
| 97 | bootclasspath: []string{"android_system_stubs_current", "core-lambda-stubs"}, |
| 98 | system: "core-current-stubs-system-modules", |
| 99 | java9classpath: []string{"android_system_stubs_current"}, |
| 100 | aidl: "-p" + buildDir + "/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 101 | }, |
| 102 | { |
| 103 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 104 | name: "system_29", |
| 105 | properties: `sdk_version: "system_29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 106 | bootclasspath: []string{`""`}, |
| 107 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 108 | java8classpath: []string{"prebuilts/sdk/29/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 109 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 110 | }, |
| 111 | { |
| 112 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 113 | name: "test_current", |
| 114 | properties: `sdk_version: "test_current",`, |
| 115 | bootclasspath: []string{"android_test_stubs_current", "core-lambda-stubs"}, |
| 116 | system: "core-current-stubs-system-modules", |
| 117 | java9classpath: []string{"android_test_stubs_current"}, |
| 118 | aidl: "-p" + buildDir + "/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 119 | }, |
| 120 | { |
| 121 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 122 | name: "core_current", |
| 123 | properties: `sdk_version: "core_current",`, |
| 124 | bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"}, |
| 125 | system: "core-current-stubs-system-modules", |
| 126 | java9classpath: []string{"core.current.stubs"}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 127 | }, |
| 128 | { |
| 129 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 130 | name: "nostdlib", |
| 131 | properties: `sdk_version: "none", system_modules: "none"`, |
| 132 | system: "none", |
| 133 | bootclasspath: []string{`""`}, |
| 134 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 135 | }, |
| 136 | { |
| 137 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 138 | name: "nostdlib system_modules", |
| 139 | properties: `sdk_version: "none", system_modules: "core-platform-api-stubs-system-modules"`, |
| 140 | system: "core-platform-api-stubs-system-modules", |
| 141 | bootclasspath: []string{"core-platform-api-stubs-system-modules-lib"}, |
| 142 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 143 | }, |
| 144 | { |
| 145 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 146 | name: "host default", |
| 147 | moduleType: "java_library_host", |
| 148 | properties: ``, |
| 149 | host: android.Host, |
| 150 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
| 151 | java8classpath: []string{}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 152 | }, |
| 153 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 154 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 155 | name: "host supported default", |
| 156 | host: android.Host, |
| 157 | properties: `host_supported: true,`, |
| 158 | java8classpath: []string{}, |
| 159 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 160 | }, |
| 161 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 162 | name: "host supported nostdlib", |
| 163 | host: android.Host, |
| 164 | properties: `host_supported: true, sdk_version: "none", system_modules: "none"`, |
| 165 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 166 | }, |
| 167 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 168 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 169 | name: "unbundled sdk v29", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 170 | unbundled: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 171 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 172 | bootclasspath: []string{`""`}, |
| 173 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 174 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 175 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 176 | }, |
| 177 | { |
| 178 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 179 | name: "unbundled current", |
| 180 | unbundled: true, |
| 181 | properties: `sdk_version: "current",`, |
| 182 | bootclasspath: []string{`""`}, |
| 183 | forces8: true, |
| 184 | java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 185 | aidl: "-pprebuilts/sdk/current/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 186 | }, |
| 187 | |
| 188 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 189 | name: "pdk default", |
| 190 | pdk: true, |
| 191 | bootclasspath: []string{`""`}, |
| 192 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 193 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 194 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 195 | }, |
| 196 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 197 | name: "pdk current", |
| 198 | pdk: true, |
| 199 | properties: `sdk_version: "current",`, |
| 200 | bootclasspath: []string{`""`}, |
| 201 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 202 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 203 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 204 | }, |
| 205 | { |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 206 | name: "pdk 29", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 207 | pdk: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 208 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 209 | bootclasspath: []string{`""`}, |
| 210 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 211 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 212 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 213 | }, |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 214 | { |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 215 | name: "module_current", |
| 216 | properties: `sdk_version: "module_current",`, |
| 217 | bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"}, |
| 218 | system: "core-current-stubs-system-modules", |
| 219 | java9classpath: []string{"android_module_lib_stubs_current"}, |
| 220 | aidl: "-p" + buildDir + "/framework.aidl", |
| 221 | }, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame^] | 222 | { |
| 223 | name: "system_server_current", |
| 224 | properties: `sdk_version: "system_server_current",`, |
| 225 | bootclasspath: []string{"android_module_lib_stubs_current", "services-stubs", "core-lambda-stubs"}, |
| 226 | system: "core-current-stubs-system-modules", |
| 227 | java9classpath: []string{"android_module_lib_stubs_current", "services-stubs"}, |
| 228 | aidl: "-p" + buildDir + "/framework.aidl", |
| 229 | }, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 232 | for _, testcase := range classpathTestcases { |
| 233 | t.Run(testcase.name, func(t *testing.T) { |
| 234 | moduleType := "java_library" |
| 235 | if testcase.moduleType != "" { |
| 236 | moduleType = testcase.moduleType |
| 237 | } |
| 238 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 239 | props := ` |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 240 | name: "foo", |
| 241 | srcs: ["a.java"], |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 242 | target: { |
| 243 | android: { |
| 244 | srcs: ["bar-doc/IFoo.aidl"], |
| 245 | }, |
| 246 | }, |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 247 | ` |
| 248 | bp := moduleType + " {" + props + testcase.properties + ` |
| 249 | }` |
| 250 | bpJava8 := moduleType + " {" + props + `java_version: "1.8", |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 251 | ` + testcase.properties + ` |
| 252 | }` |
| 253 | |
| 254 | variant := "android_common" |
| 255 | if testcase.host == android.Host { |
| 256 | variant = android.BuildOs.String() + "_common" |
| 257 | } |
| 258 | |
| 259 | convertModulesToPaths := func(cp []string) []string { |
| 260 | ret := make([]string, len(cp)) |
| 261 | for i, e := range cp { |
| 262 | ret[i] = moduleToPath(e) |
| 263 | } |
| 264 | return ret |
| 265 | } |
| 266 | |
| 267 | bootclasspath := convertModulesToPaths(testcase.bootclasspath) |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 268 | java8classpath := convertModulesToPaths(testcase.java8classpath) |
| 269 | java9classpath := convertModulesToPaths(testcase.java9classpath) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 270 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 271 | bc := "" |
| 272 | var bcDeps []string |
| 273 | if len(bootclasspath) > 0 { |
| 274 | bc = "-bootclasspath " + strings.Join(bootclasspath, ":") |
| 275 | if bootclasspath[0] != `""` { |
| 276 | bcDeps = bootclasspath |
| 277 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 280 | j8c := "" |
| 281 | if len(java8classpath) > 0 { |
| 282 | j8c = "-classpath " + strings.Join(java8classpath, ":") |
| 283 | } |
| 284 | |
| 285 | j9c := "" |
| 286 | if len(java9classpath) > 0 { |
| 287 | j9c = "-classpath " + strings.Join(java9classpath, ":") |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 288 | } |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 289 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 290 | system := "" |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 291 | var systemDeps []string |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 292 | if testcase.system == "none" { |
| 293 | system = "--system=none" |
| 294 | } else if testcase.system != "" { |
Dan Willemsen | ff60a73 | 2019-06-13 16:52:01 +0000 | [diff] [blame] | 295 | system = "--system=" + filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 296 | // The module-relative parts of these paths are hardcoded in system_modules.go: |
| 297 | systemDeps = []string{ |
| 298 | filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system", "lib", "modules"), |
| 299 | filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system", "lib", "jrt-fs.jar"), |
| 300 | filepath.Join(buildDir, ".intermediates", testcase.system, "android_common", "system", "release"), |
| 301 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 302 | } |
| 303 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 304 | checkClasspath := func(t *testing.T, ctx *android.TestContext, isJava8 bool) { |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 305 | foo := ctx.ModuleForTests("foo", variant) |
| 306 | javac := foo.Rule("javac") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 307 | var deps []string |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 308 | |
| 309 | aidl := foo.MaybeRule("aidl") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 310 | if aidl.Rule != nil { |
| 311 | deps = append(deps, aidl.Output.String()) |
| 312 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 313 | |
| 314 | got := javac.Args["bootClasspath"] |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 315 | expected := "" |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 316 | if isJava8 || testcase.forces8 { |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 317 | expected = bc |
| 318 | deps = append(deps, bcDeps...) |
| 319 | } else { |
| 320 | expected = system |
| 321 | deps = append(deps, systemDeps...) |
| 322 | } |
| 323 | if got != expected { |
| 324 | t.Errorf("bootclasspath expected %q != got %q", expected, got) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 327 | if isJava8 || testcase.forces8 { |
| 328 | expected = j8c |
| 329 | deps = append(deps, java8classpath...) |
| 330 | } else { |
| 331 | expected = j9c |
| 332 | deps = append(deps, java9classpath...) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 333 | } |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 334 | got = javac.Args["classpath"] |
| 335 | if got != expected { |
| 336 | t.Errorf("classpath expected %q != got %q", expected, got) |
| 337 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 338 | |
| 339 | if !reflect.DeepEqual(javac.Implicits.Strings(), deps) { |
| 340 | t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings()) |
| 341 | } |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 344 | // Test with legacy javac -source 1.8 -target 1.8 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 345 | t.Run("Java language level 8", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 346 | config := testConfig(nil, bpJava8, nil) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 347 | if testcase.unbundled { |
| 348 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 349 | } |
| 350 | if testcase.pdk { |
| 351 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 352 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 353 | ctx := testContext() |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 354 | run(t, ctx, config) |
| 355 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 356 | checkClasspath(t, ctx, true /* isJava8 */) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 357 | |
| 358 | if testcase.host != android.Host { |
| 359 | aidl := ctx.ModuleForTests("foo", variant).Rule("aidl") |
| 360 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 361 | if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) { |
| 362 | t.Errorf("want aidl command to contain %q, got %q", w, g) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 363 | } |
| 364 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 365 | }) |
| 366 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 367 | // Test with default javac -source 9 -target 9 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 368 | t.Run("Java language level 9", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 369 | config := testConfig(nil, bp, nil) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 370 | if testcase.unbundled { |
| 371 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 372 | } |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 373 | if testcase.pdk { |
| 374 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 375 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 376 | ctx := testContext() |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 377 | run(t, ctx, config) |
| 378 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 379 | checkClasspath(t, ctx, false /* isJava8 */) |
| 380 | |
| 381 | if testcase.host != android.Host { |
| 382 | aidl := ctx.ModuleForTests("foo", variant).Rule("aidl") |
| 383 | |
| 384 | if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) { |
| 385 | t.Errorf("want aidl command to contain %q, got %q", w, g) |
| 386 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 387 | } |
| 388 | }) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 389 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 390 | // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8 |
| 391 | t.Run("REL + Java language level 8", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 392 | config := testConfig(nil, bpJava8, nil) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 393 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL") |
| 394 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true) |
| 395 | |
| 396 | if testcase.unbundled { |
| 397 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 398 | } |
| 399 | if testcase.pdk { |
| 400 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 401 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 402 | ctx := testContext() |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 403 | run(t, ctx, config) |
| 404 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 405 | checkClasspath(t, ctx, true /* isJava8 */) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 406 | }) |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 407 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 408 | // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9 |
| 409 | t.Run("REL + Java language level 9", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 410 | config := testConfig(nil, bp, nil) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 411 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL") |
| 412 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true) |
| 413 | |
| 414 | if testcase.unbundled { |
| 415 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 416 | } |
| 417 | if testcase.pdk { |
| 418 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 419 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 420 | ctx := testContext() |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 421 | run(t, ctx, config) |
| 422 | |
| 423 | checkClasspath(t, ctx, false /* isJava8 */) |
| 424 | }) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 425 | }) |
| 426 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 427 | } |