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 | |
Pete Gillin | 880f964 | 2020-07-01 13:17:16 +0100 | [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", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 146 | }, |
| 147 | { |
| 148 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 149 | name: "nostdlib", |
| 150 | properties: `sdk_version: "none", system_modules: "none"`, |
| 151 | system: "none", |
| 152 | bootclasspath: []string{`""`}, |
| 153 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 154 | }, |
| 155 | { |
| 156 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 157 | name: "nostdlib system_modules", |
Pete Gillin | 1f41dbf | 2020-06-02 15:59:45 +0100 | [diff] [blame] | 158 | properties: `sdk_version: "none", system_modules: "legacy-core-platform-api-stubs-system-modules"`, |
| 159 | system: "legacy-core-platform-api-stubs-system-modules", |
| 160 | bootclasspath: []string{"legacy-core-platform-api-stubs-system-modules-lib"}, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 161 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 162 | }, |
| 163 | { |
| 164 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 165 | name: "host default", |
| 166 | moduleType: "java_library_host", |
| 167 | properties: ``, |
| 168 | host: android.Host, |
| 169 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
| 170 | java8classpath: []string{}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 171 | }, |
| 172 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 173 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 174 | name: "host supported default", |
| 175 | host: android.Host, |
| 176 | properties: `host_supported: true,`, |
| 177 | java8classpath: []string{}, |
| 178 | bootclasspath: []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"}, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 179 | }, |
| 180 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 181 | name: "host supported nostdlib", |
| 182 | host: android.Host, |
| 183 | properties: `host_supported: true, sdk_version: "none", system_modules: "none"`, |
| 184 | java8classpath: []string{}, |
Paul Duffin | 52d398a | 2019-06-11 12:31:14 +0100 | [diff] [blame] | 185 | }, |
| 186 | { |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 187 | |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 188 | name: "unbundled sdk v29", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 189 | unbundled: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 190 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 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 | { |
| 197 | |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 198 | name: "unbundled sdk v30", |
| 199 | unbundled: true, |
| 200 | properties: `sdk_version: "30",`, |
| 201 | bootclasspath: []string{`""`}, |
| 202 | system: "sdk_public_30_system_modules", |
| 203 | java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 204 | java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 205 | aidl: "-pprebuilts/sdk/30/public/framework.aidl", |
| 206 | }, |
| 207 | { |
| 208 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 209 | name: "unbundled current", |
| 210 | unbundled: true, |
| 211 | properties: `sdk_version: "current",`, |
| 212 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 213 | system: "sdk_public_current_system_modules", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 214 | 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] | 215 | 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] | 216 | aidl: "-pprebuilts/sdk/current/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 217 | }, |
| 218 | |
| 219 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 220 | name: "pdk default", |
| 221 | pdk: true, |
| 222 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 223 | system: "sdk_public_30_system_modules", |
| 224 | java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 225 | java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 226 | aidl: "-pprebuilts/sdk/30/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 227 | }, |
| 228 | { |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 229 | name: "pdk current", |
| 230 | pdk: true, |
| 231 | properties: `sdk_version: "current",`, |
| 232 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 233 | system: "sdk_public_30_system_modules", |
| 234 | java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 235 | java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 236 | aidl: "-pprebuilts/sdk/30/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 237 | }, |
| 238 | { |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 239 | name: "pdk 29", |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 240 | pdk: true, |
Colin Cross | 74362a4 | 2019-10-28 08:05:02 -0700 | [diff] [blame] | 241 | properties: `sdk_version: "29",`, |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 242 | bootclasspath: []string{`""`}, |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 243 | system: "sdk_public_30_system_modules", |
| 244 | java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 245 | java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"}, |
| 246 | aidl: "-pprebuilts/sdk/30/public/framework.aidl", |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 247 | }, |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 248 | { |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 249 | name: "module_current", |
| 250 | properties: `sdk_version: "module_current",`, |
| 251 | bootclasspath: []string{"android_module_lib_stubs_current", "core-lambda-stubs"}, |
| 252 | system: "core-current-stubs-system-modules", |
| 253 | java9classpath: []string{"android_module_lib_stubs_current"}, |
Anton Hansson | 3f07ab2 | 2020-04-09 13:29:59 +0100 | [diff] [blame] | 254 | aidl: "-p" + buildDir + "/framework_non_updatable.aidl", |
Jiyong Park | 50146e9 | 2020-01-30 18:00:15 +0900 | [diff] [blame] | 255 | }, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 256 | { |
| 257 | name: "system_server_current", |
| 258 | properties: `sdk_version: "system_server_current",`, |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 259 | bootclasspath: []string{"android_system_server_stubs_current", "core-lambda-stubs"}, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 260 | system: "core-current-stubs-system-modules", |
Anton Hansson | ba6ab2e | 2020-03-19 15:23:38 +0000 | [diff] [blame] | 261 | java9classpath: []string{"android_system_server_stubs_current"}, |
Jiyong Park | aae9bd1 | 2020-02-12 04:36:43 +0900 | [diff] [blame] | 262 | aidl: "-p" + buildDir + "/framework.aidl", |
| 263 | }, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 266 | for _, testcase := range classpathTestcases { |
| 267 | t.Run(testcase.name, func(t *testing.T) { |
| 268 | moduleType := "java_library" |
| 269 | if testcase.moduleType != "" { |
| 270 | moduleType = testcase.moduleType |
| 271 | } |
| 272 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 273 | props := ` |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 274 | name: "foo", |
| 275 | srcs: ["a.java"], |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 276 | target: { |
| 277 | android: { |
| 278 | srcs: ["bar-doc/IFoo.aidl"], |
| 279 | }, |
| 280 | }, |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 281 | ` |
| 282 | bp := moduleType + " {" + props + testcase.properties + ` |
| 283 | }` |
| 284 | bpJava8 := moduleType + " {" + props + `java_version: "1.8", |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 285 | ` + testcase.properties + ` |
| 286 | }` |
| 287 | |
| 288 | variant := "android_common" |
| 289 | if testcase.host == android.Host { |
| 290 | variant = android.BuildOs.String() + "_common" |
| 291 | } |
| 292 | |
| 293 | convertModulesToPaths := func(cp []string) []string { |
| 294 | ret := make([]string, len(cp)) |
| 295 | for i, e := range cp { |
| 296 | ret[i] = moduleToPath(e) |
| 297 | } |
| 298 | return ret |
| 299 | } |
| 300 | |
| 301 | bootclasspath := convertModulesToPaths(testcase.bootclasspath) |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 302 | java8classpath := convertModulesToPaths(testcase.java8classpath) |
| 303 | java9classpath := convertModulesToPaths(testcase.java9classpath) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 304 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 305 | bc := "" |
| 306 | var bcDeps []string |
| 307 | if len(bootclasspath) > 0 { |
| 308 | bc = "-bootclasspath " + strings.Join(bootclasspath, ":") |
| 309 | if bootclasspath[0] != `""` { |
| 310 | bcDeps = bootclasspath |
| 311 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 314 | j8c := "" |
| 315 | if len(java8classpath) > 0 { |
| 316 | j8c = "-classpath " + strings.Join(java8classpath, ":") |
| 317 | } |
| 318 | |
| 319 | j9c := "" |
| 320 | if len(java9classpath) > 0 { |
| 321 | j9c = "-classpath " + strings.Join(java9classpath, ":") |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 322 | } |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 323 | |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 324 | system := "" |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 325 | var systemDeps []string |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 326 | if testcase.system == "none" { |
| 327 | system = "--system=none" |
| 328 | } else if testcase.system != "" { |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 329 | dir := "" |
| 330 | if strings.HasPrefix(testcase.system, "sdk_public_") { |
| 331 | dir = "prebuilts/sdk" |
| 332 | } |
| 333 | system = "--system=" + filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 334 | // The module-relative parts of these paths are hardcoded in system_modules.go: |
| 335 | systemDeps = []string{ |
Colin Cross | 17dec17 | 2020-05-14 18:05:32 -0700 | [diff] [blame] | 336 | filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system", "lib", "modules"), |
| 337 | filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system", "lib", "jrt-fs.jar"), |
| 338 | filepath.Join(buildDir, ".intermediates", dir, testcase.system, "android_common", "system", "release"), |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 339 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 340 | } |
| 341 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 342 | checkClasspath := func(t *testing.T, ctx *android.TestContext, isJava8 bool) { |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 343 | foo := ctx.ModuleForTests("foo", variant) |
| 344 | javac := foo.Rule("javac") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 345 | var deps []string |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 346 | |
| 347 | aidl := foo.MaybeRule("aidl") |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 348 | if aidl.Rule != nil { |
| 349 | deps = append(deps, aidl.Output.String()) |
| 350 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 351 | |
| 352 | got := javac.Args["bootClasspath"] |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 353 | expected := "" |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 354 | if isJava8 || testcase.forces8 { |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 355 | expected = bc |
| 356 | deps = append(deps, bcDeps...) |
| 357 | } else { |
| 358 | expected = system |
| 359 | deps = append(deps, systemDeps...) |
| 360 | } |
| 361 | if got != expected { |
| 362 | t.Errorf("bootclasspath expected %q != got %q", expected, got) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 365 | if isJava8 || testcase.forces8 { |
| 366 | expected = j8c |
| 367 | deps = append(deps, java8classpath...) |
| 368 | } else { |
| 369 | expected = j9c |
| 370 | deps = append(deps, java9classpath...) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 371 | } |
Colin Cross | 617b145 | 2019-10-25 15:22:50 -0700 | [diff] [blame] | 372 | got = javac.Args["classpath"] |
| 373 | if got != expected { |
| 374 | t.Errorf("classpath expected %q != got %q", expected, got) |
| 375 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 376 | |
| 377 | if !reflect.DeepEqual(javac.Implicits.Strings(), deps) { |
| 378 | t.Errorf("implicits expected %q != got %q", deps, javac.Implicits.Strings()) |
| 379 | } |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 382 | // Test with legacy javac -source 1.8 -target 1.8 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 383 | t.Run("Java language level 8", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 384 | config := testConfig(nil, bpJava8, nil) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 385 | if testcase.unbundled { |
| 386 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 387 | } |
| 388 | if testcase.pdk { |
| 389 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 390 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 391 | ctx := testContext() |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 392 | run(t, ctx, config) |
| 393 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 394 | checkClasspath(t, ctx, true /* isJava8 */) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 395 | |
| 396 | if testcase.host != android.Host { |
| 397 | aidl := ctx.ModuleForTests("foo", variant).Rule("aidl") |
| 398 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 399 | if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) { |
| 400 | t.Errorf("want aidl command to contain %q, got %q", w, g) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 401 | } |
| 402 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 403 | }) |
| 404 | |
Pete Gillin | 1b3370f | 2019-10-01 13:57:31 +0100 | [diff] [blame] | 405 | // Test with default javac -source 9 -target 9 |
Pete Gillin | 0c2143e | 2019-05-02 15:32:11 +0100 | [diff] [blame] | 406 | t.Run("Java language level 9", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 407 | config := testConfig(nil, bp, nil) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 408 | if testcase.unbundled { |
| 409 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 410 | } |
Colin Cross | 98fd574 | 2019-01-09 23:04:25 -0800 | [diff] [blame] | 411 | if testcase.pdk { |
| 412 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 413 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 414 | ctx := testContext() |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 415 | run(t, ctx, config) |
| 416 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 417 | checkClasspath(t, ctx, false /* isJava8 */) |
| 418 | |
| 419 | if testcase.host != android.Host { |
| 420 | aidl := ctx.ModuleForTests("foo", variant).Rule("aidl") |
| 421 | |
| 422 | if g, w := aidl.RuleParams.Command, testcase.aidl+" -I."; !strings.Contains(g, w) { |
| 423 | t.Errorf("want aidl command to contain %q, got %q", w, g) |
| 424 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 425 | } |
| 426 | }) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 427 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 428 | // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8 |
| 429 | t.Run("REL + Java language level 8", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 430 | config := testConfig(nil, bpJava8, nil) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 431 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL") |
| 432 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true) |
| 433 | |
| 434 | if testcase.unbundled { |
| 435 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 436 | } |
| 437 | if testcase.pdk { |
| 438 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 439 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 440 | ctx := testContext() |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 441 | run(t, ctx, config) |
| 442 | |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 443 | checkClasspath(t, ctx, true /* isJava8 */) |
Colin Cross | ff0daf4 | 2019-04-02 16:10:56 -0700 | [diff] [blame] | 444 | }) |
Pete Gillin | bdf5d71 | 2019-10-21 14:29:58 +0100 | [diff] [blame] | 445 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 446 | // Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9 |
| 447 | t.Run("REL + Java language level 9", func(t *testing.T) { |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 448 | config := testConfig(nil, bp, nil) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 449 | config.TestProductVariables.Platform_sdk_codename = proptools.StringPtr("REL") |
| 450 | config.TestProductVariables.Platform_sdk_final = proptools.BoolPtr(true) |
| 451 | |
| 452 | if testcase.unbundled { |
| 453 | config.TestProductVariables.Unbundled_build = proptools.BoolPtr(true) |
| 454 | } |
| 455 | if testcase.pdk { |
| 456 | config.TestProductVariables.Pdk = proptools.BoolPtr(true) |
| 457 | } |
Colin Cross | 98be1bb | 2019-12-13 20:41:13 -0800 | [diff] [blame] | 458 | ctx := testContext() |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 459 | run(t, ctx, config) |
| 460 | |
| 461 | checkClasspath(t, ctx, false /* isJava8 */) |
| 462 | }) |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 463 | }) |
| 464 | } |
Colin Cross | fb6d781 | 2019-01-09 22:17:55 -0800 | [diff] [blame] | 465 | } |