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", |
Pete Gillin | 0638dfc | 2020-07-01 10:48:14 +0100 | [diff] [blame^] | 52 | bootclasspath: config.LegacyCorePlatformBootclasspathLibraries, |
| 53 | system: config.LegacyCorePlatformSystemModules, |
| 54 | java8classpath: config.FrameworkLibraries, |
| 55 | java9classpath: config.FrameworkLibraries, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 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"`, |
Pete Gillin | 0638dfc | 2020-07-01 10:48:14 +0100 | [diff] [blame^] | 61 | bootclasspath: config.LegacyCorePlatformBootclasspathLibraries, |
| 62 | system: config.LegacyCorePlatformSystemModules, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 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: "",`, |
Pete Gillin | 0638dfc | 2020-07-01 10:48:14 +0100 | [diff] [blame^] | 69 | bootclasspath: config.LegacyCorePlatformBootclasspathLibraries, |
| 70 | system: config.LegacyCorePlatformSystemModules, |
| 71 | java8classpath: config.FrameworkLibraries, |
| 72 | java9classpath: config.FrameworkLibraries, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 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 | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 86 | 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 Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 96 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 102 | }, |
| 103 | { |
| 104 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 105 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 111 | }, |
| 112 | { |
| 113 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 114 | name: "system_29", |
| 115 | properties: `sdk_version: "system_29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 116 | bootclasspath: []string{`""`}, |
| 117 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 118 | java8classpath: []string{"prebuilts/sdk/29/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 119 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 120 | }, |
| 121 | { |
| 122 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 123 | 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 Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 133 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 139 | }, |
| 140 | { |
| 141 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 142 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 147 | }, |
| 148 | { |
| 149 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 150 | name: "nostdlib", |
| 151 | properties: `sdk_version: "none", system_modules: "none"`, |
| 152 | system: "none", |
| 153 | bootclasspath: []string{`""`}, |
| 154 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 155 | }, |
| 156 | { |
| 157 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 158 | name: "nostdlib system_modules", |
Pete Gillin | 1f41dbf | 2020-06-02 15:59:45 +0100 | [diff] [blame] | 159 | 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 Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 162 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 163 | }, |
| 164 | { |
| 165 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 166 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 172 | }, |
| 173 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 174 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 175 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 180 | }, |
| 181 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 182 | name: "host supported nostdlib", |
| 183 | host: android.Host, |
| 184 | properties: `host_supported: true, sdk_version: "none", system_modules: "none"`, |
| 185 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 186 | }, |
| 187 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 188 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 189 | name: "unbundled sdk v29", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 190 | unbundled: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 191 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 192 | bootclasspath: []string{`""`}, |
| 193 | forces8: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 194 | java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 195 | aidl: "-pprebuilts/sdk/29/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 196 | }, |
| 197 | { |
| 198 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 199 | 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 Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 210 | name: "unbundled current", |
| 211 | unbundled: true, |
| 212 | properties: `sdk_version: "current",`, |
| 213 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 214 | system: "sdk_public_current_system_modules", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 215 | 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] | 216 | 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] | 217 | aidl: "-pprebuilts/sdk/current/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 218 | }, |
| 219 | |
| 220 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 221 | name: "pdk default", |
| 222 | pdk: true, |
| 223 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 224 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 228 | }, |
| 229 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 230 | name: "pdk current", |
| 231 | pdk: true, |
| 232 | properties: `sdk_version: "current",`, |
| 233 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 234 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 238 | }, |
| 239 | { |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 240 | name: "pdk 29", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 241 | pdk: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 242 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 243 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 244 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 248 | }, |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 249 | { |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 250 | 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 Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 255 | aidl: "-p" + buildDir + "/framework_non_updatable.aidl", |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 256 | }, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 257 | { |
| 258 | name: "system_server_current", |
| 259 | properties: `sdk_version: "system_server_current",`, |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 260 | bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"}, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 261 | system: "core-current-stubs-system-modules", |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 262 | java9classpath: []string{"android_system_server_stubs_current"}, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 263 | aidl: "-p" + buildDir + "/framework.aidl", |
| 264 | }, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 267 | 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 Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 274 | props := ` |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 275 | name: "foo", |
| 276 | srcs: ["a.java"], |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 277 | target: { |
| 278 | android: { |
| 279 | srcs: ["bar-doc/IFoo.aidl"], |
| 280 | }, |
| 281 | }, |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 282 | ` |
| 283 | bp := moduleType + " {" + props + testcase.properties + ` |
| 284 | }` |
| 285 | bpJava8 := moduleType + " {" + props + `java_version: "1.8", |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 286 | ` + 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 Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 303 | java8classpath := convertModulesToPaths(testcase.java8classpath) |
| 304 | java9classpath := convertModulesToPaths(testcase.java9classpath) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 305 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 306 | 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 Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 315 | 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 Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 323 | } |
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 | system := "" |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 326 | var systemDeps []string |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 327 | if testcase.system == "none" { |
| 328 | system = "--system=none" |
| 329 | } else if testcase.system != "" { |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 330 | 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 Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 335 | // The module-relative parts of these paths are hardcoded in system_modules.go: |
| 336 | systemDeps = []string{ |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 337 | 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 Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 340 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 343 | checkClasspath := func(t *testing.T, ctx *android.TestContext, isJava8 bool) { |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 344 | foo := ctx.ModuleForTests("foo", variant) |
| 345 | javac := foo.Rule("javac") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 346 | var deps []string |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 347 | |
| 348 | aidl := foo.MaybeRule("aidl") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 349 | if aidl.Rule != nil { |
| 350 | deps = append(deps, aidl.Output.String()) |
| 351 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 352 | |
| 353 | got := javac.Args["bootClasspath"] |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 354 | expected := "" |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 355 | if isJava8 || testcase.forces8 { |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 356 | 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 Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 364 | } |
| 365 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 366 | if isJava8 || testcase.forces8 { |
| 367 | expected = j8c |
| 368 | deps = append(deps, java8classpath...) |
| 369 | } else { |
| 370 | expected = j9c |
| 371 | deps = append(deps, java9classpath...) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 372 | } |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 373 | got = javac.Args["classpath"] |
| 374 | if got != expected { |
| 375 | t.Errorf("classpath expected %q != got %q", expected, got) |
| 376 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 377 | |
| 378 | if !reflect.DeepEqual(javac.Implicits.Strings(), deps) { |
| 379 | t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings()) |
| 380 | } |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 383 | // Test with legacy javac -source 1.8 -target 1.8 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 384 | t.Run("Java language level 8", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 385 | config := testConfig(nil, bpJava8, nil) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 386 | 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 Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 392 | ctx := testContext() |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 393 | run(t, ctx, config) |
| 394 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 395 | checkClasspath(t, ctx, true /* isJava8 */) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 396 | |
| 397 | if testcase.host != android.Host { |
| 398 | aidl := ctx.ModuleForTests("foo", variant).Rule("aidl") |
| 399 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 400 | 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 Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 402 | } |
| 403 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 404 | }) |
| 405 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 406 | // Test with default javac -source 9 -target 9 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 407 | t.Run("Java language level 9", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 408 | config := testConfig(nil, bp, nil) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 409 | if testcase.unbundled { |
| 410 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 411 | } |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 412 | if testcase.pdk { |
| 413 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 414 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 415 | ctx := testContext() |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 416 | run(t, ctx, config) |
| 417 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 418 | 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 Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 426 | } |
| 427 | }) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 428 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 429 | // 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 Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 431 | config := testConfig(nil, bpJava8, nil) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 432 | 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 Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 441 | ctx := testContext() |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 442 | run(t, ctx, config) |
| 443 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 444 | checkClasspath(t, ctx, true /* isJava8 */) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 445 | }) |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 446 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 447 | // 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 Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 449 | config := testConfig(nil, bp, nil) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 450 | 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 Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 459 | ctx := testContext() |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 460 | run(t, ctx, config) |
| 461 | |
| 462 | checkClasspath(t, ctx, false /* isJava8 */) |
| 463 | }) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 464 | }) |
| 465 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 466 | } |