Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 1 | // Copyright (C) 2021 The Android Open Source Project |
| 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 sdk |
| 16 | |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 17 | import ( |
| 18 | "testing" |
| 19 | |
| 20 | "android/soong/android" |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 21 | "android/soong/java" |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 22 | ) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 23 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 24 | func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { |
| 25 | result := android.GroupFixturePreparers( |
| 26 | prepareForSdkTestWithJava, |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 27 | java.PrepareForTestWithJavaDefaultModules, |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 28 | prepareForSdkTestWithApex, |
| 29 | |
| 30 | // Some additional files needed for the art apex. |
| 31 | android.FixtureMergeMockFs(android.MockFS{ |
| 32 | "com.android.art.avbpubkey": nil, |
| 33 | "com.android.art.pem": nil, |
| 34 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 35 | }), |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 36 | |
| 37 | // platform_bootclasspath that depends on the fragment. |
| 38 | android.FixtureAddTextFile("frameworks/base/boot/Android.bp", ` |
| 39 | platform_bootclasspath { |
| 40 | name: "platform-bootclasspath", |
| 41 | fragments: [ |
| 42 | { |
| 43 | apex: "com.android.art", |
| 44 | module: "mybootclasspathfragment", |
| 45 | }, |
| 46 | ], |
| 47 | } |
| 48 | `), |
| 49 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 50 | java.FixtureConfigureBootJars("com.android.art:mybootlib"), |
| 51 | android.FixtureWithRootAndroidBp(` |
| 52 | sdk { |
| 53 | name: "mysdk", |
| 54 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | apex { |
| 58 | name: "com.android.art", |
| 59 | key: "com.android.art.key", |
| 60 | bootclasspath_fragments: [ |
| 61 | "mybootclasspathfragment", |
| 62 | ], |
| 63 | updatable: false, |
| 64 | } |
| 65 | |
| 66 | bootclasspath_fragment { |
| 67 | name: "mybootclasspathfragment", |
| 68 | image_name: "art", |
| 69 | apex_available: ["com.android.art"], |
| 70 | } |
| 71 | |
| 72 | apex_key { |
| 73 | name: "com.android.art.key", |
| 74 | public_key: "com.android.art.avbpubkey", |
| 75 | private_key: "com.android.art.pem", |
| 76 | } |
| 77 | |
| 78 | java_library { |
| 79 | name: "mybootlib", |
| 80 | srcs: ["Test.java"], |
| 81 | system_modules: "none", |
| 82 | sdk_version: "none", |
| 83 | compile_dex: true, |
| 84 | apex_available: ["com.android.art"], |
| 85 | } |
| 86 | `), |
| 87 | ).RunTest(t) |
| 88 | |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 89 | // A preparer to add a prebuilt apex to the test fixture. |
| 90 | prepareWithPrebuiltApex := android.GroupFixturePreparers( |
| 91 | android.FixtureAddTextFile("prebuilts/apex/Android.bp", ` |
| 92 | prebuilt_apex { |
| 93 | name: "com.android.art", |
| 94 | src: "art.apex", |
| 95 | exported_java_libs: [ |
| 96 | "mybootlib", |
| 97 | ], |
| 98 | exported_bootclasspath_fragments: [ |
| 99 | "mybootclasspathfragment", |
| 100 | ], |
| 101 | } |
| 102 | `), |
| 103 | android.FixtureAddFile("prebuilts/apex/art.apex", nil), |
| 104 | ) |
| 105 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 106 | CheckSnapshot(t, result, "mysdk", "", |
| 107 | checkUnversionedAndroidBpContents(` |
| 108 | // This is auto-generated. DO NOT EDIT. |
| 109 | |
| 110 | prebuilt_bootclasspath_fragment { |
| 111 | name: "mybootclasspathfragment", |
| 112 | prefer: false, |
| 113 | visibility: ["//visibility:public"], |
| 114 | apex_available: ["com.android.art"], |
| 115 | image_name: "art", |
Paul Duffin | 2dc665b | 2021-04-23 16:58:51 +0100 | [diff] [blame^] | 116 | contents: ["mybootlib"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | java_import { |
| 120 | name: "mybootlib", |
| 121 | prefer: false, |
| 122 | visibility: ["//visibility:public"], |
| 123 | apex_available: ["com.android.art"], |
| 124 | jars: ["java/mybootlib.jar"], |
| 125 | } |
| 126 | `), |
| 127 | checkVersionedAndroidBpContents(` |
| 128 | // This is auto-generated. DO NOT EDIT. |
| 129 | |
| 130 | prebuilt_bootclasspath_fragment { |
| 131 | name: "mysdk_mybootclasspathfragment@current", |
| 132 | sdk_member_name: "mybootclasspathfragment", |
| 133 | visibility: ["//visibility:public"], |
| 134 | apex_available: ["com.android.art"], |
| 135 | image_name: "art", |
Paul Duffin | 2dc665b | 2021-04-23 16:58:51 +0100 | [diff] [blame^] | 136 | contents: ["mysdk_mybootlib@current"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | java_import { |
| 140 | name: "mysdk_mybootlib@current", |
| 141 | sdk_member_name: "mybootlib", |
| 142 | visibility: ["//visibility:public"], |
| 143 | apex_available: ["com.android.art"], |
| 144 | jars: ["java/mybootlib.jar"], |
| 145 | } |
| 146 | |
| 147 | sdk_snapshot { |
| 148 | name: "mysdk@current", |
| 149 | visibility: ["//visibility:public"], |
| 150 | bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], |
| 151 | java_boot_libs: ["mysdk_mybootlib@current"], |
| 152 | } |
| 153 | `), |
| 154 | checkAllCopyRules(` |
| 155 | .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar |
| 156 | `), |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 157 | snapshotTestPreparer(checkSnapshotWithoutSource, prepareWithPrebuiltApex), |
| 158 | snapshotTestPreparer(checkSnapshotWithSourcePreferred, prepareWithPrebuiltApex), |
| 159 | snapshotTestPreparer(checkSnapshotPreferredWithSource, prepareWithPrebuiltApex), |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 160 | ) |
| 161 | } |
| 162 | |
| 163 | func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 164 | result := android.GroupFixturePreparers( |
| 165 | prepareForSdkTestWithJava, |
| 166 | android.FixtureWithRootAndroidBp(` |
| 167 | sdk { |
| 168 | name: "mysdk", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 169 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 170 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 171 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 172 | bootclasspath_fragment { |
| 173 | name: "mybootclasspathfragment", |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 174 | contents: ["mybootlib"], |
| 175 | } |
| 176 | |
| 177 | java_library { |
| 178 | name: "mybootlib", |
| 179 | srcs: ["Test.java"], |
| 180 | system_modules: "none", |
| 181 | sdk_version: "none", |
| 182 | compile_dex: true, |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 183 | } |
| 184 | `), |
| 185 | ).RunTest(t) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 186 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 187 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 188 | checkUnversionedAndroidBpContents(` |
| 189 | // This is auto-generated. DO NOT EDIT. |
| 190 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 191 | prebuilt_bootclasspath_fragment { |
| 192 | name: "mybootclasspathfragment", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 193 | prefer: false, |
| 194 | visibility: ["//visibility:public"], |
| 195 | apex_available: ["//apex_available:platform"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 196 | contents: ["mybootlib"], |
| 197 | } |
| 198 | |
| 199 | java_import { |
| 200 | name: "mybootlib", |
| 201 | prefer: false, |
| 202 | visibility: ["//visibility:public"], |
| 203 | apex_available: ["//apex_available:platform"], |
| 204 | jars: ["java/mybootlib.jar"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 205 | } |
| 206 | `), |
| 207 | checkVersionedAndroidBpContents(` |
| 208 | // This is auto-generated. DO NOT EDIT. |
| 209 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 210 | prebuilt_bootclasspath_fragment { |
| 211 | name: "mysdk_mybootclasspathfragment@current", |
| 212 | sdk_member_name: "mybootclasspathfragment", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 213 | visibility: ["//visibility:public"], |
| 214 | apex_available: ["//apex_available:platform"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 215 | contents: ["mysdk_mybootlib@current"], |
| 216 | } |
| 217 | |
| 218 | java_import { |
| 219 | name: "mysdk_mybootlib@current", |
| 220 | sdk_member_name: "mybootlib", |
| 221 | visibility: ["//visibility:public"], |
| 222 | apex_available: ["//apex_available:platform"], |
| 223 | jars: ["java/mybootlib.jar"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | sdk_snapshot { |
| 227 | name: "mysdk@current", |
| 228 | visibility: ["//visibility:public"], |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 229 | bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 230 | java_boot_libs: ["mysdk_mybootlib@current"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 231 | } |
| 232 | `), |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 233 | checkAllCopyRules(` |
| 234 | .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar |
| 235 | `)) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 236 | } |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 237 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 238 | // Test that bootclasspath_fragment works with sdk. |
| 239 | func TestBasicSdkWithBootclasspathFragment(t *testing.T) { |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 240 | android.GroupFixturePreparers( |
| 241 | prepareForSdkTestWithApex, |
| 242 | prepareForSdkTestWithJava, |
| 243 | android.FixtureWithRootAndroidBp(` |
| 244 | sdk { |
| 245 | name: "mysdk", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 246 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 247 | } |
| 248 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 249 | bootclasspath_fragment { |
| 250 | name: "mybootclasspathfragment", |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 251 | image_name: "art", |
| 252 | apex_available: ["myapex"], |
| 253 | } |
| 254 | |
| 255 | sdk_snapshot { |
| 256 | name: "mysdk@1", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 257 | bootclasspath_fragments: ["mybootclasspathfragment_mysdk_1"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 260 | prebuilt_bootclasspath_fragment { |
| 261 | name: "mybootclasspathfragment_mysdk_1", |
| 262 | sdk_member_name: "mybootclasspathfragment", |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 263 | prefer: false, |
| 264 | visibility: ["//visibility:public"], |
| 265 | apex_available: [ |
| 266 | "myapex", |
| 267 | ], |
| 268 | image_name: "art", |
| 269 | } |
| 270 | `), |
| 271 | ).RunTest(t) |
| 272 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 273 | |
| 274 | func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { |
| 275 | result := android.GroupFixturePreparers( |
| 276 | prepareForSdkTestWithJava, |
| 277 | android.MockFS{ |
| 278 | "my-blocked.txt": nil, |
| 279 | "my-max-target-o-low-priority.txt": nil, |
| 280 | "my-max-target-p.txt": nil, |
| 281 | "my-max-target-q.txt": nil, |
| 282 | "my-max-target-r-low-priority.txt": nil, |
| 283 | "my-removed.txt": nil, |
| 284 | "my-unsupported-packages.txt": nil, |
| 285 | "my-unsupported.txt": nil, |
| 286 | }.AddToFixture(), |
| 287 | android.FixtureWithRootAndroidBp(` |
| 288 | sdk { |
| 289 | name: "mysdk", |
| 290 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | bootclasspath_fragment { |
| 294 | name: "mybootclasspathfragment", |
| 295 | contents: ["mybootlib"], |
| 296 | hidden_api: { |
| 297 | unsupported: [ |
| 298 | "my-unsupported.txt", |
| 299 | ], |
| 300 | removed: [ |
| 301 | "my-removed.txt", |
| 302 | ], |
| 303 | max_target_r_low_priority: [ |
| 304 | "my-max-target-r-low-priority.txt", |
| 305 | ], |
| 306 | max_target_q: [ |
| 307 | "my-max-target-q.txt", |
| 308 | ], |
| 309 | max_target_p: [ |
| 310 | "my-max-target-p.txt", |
| 311 | ], |
| 312 | max_target_o_low_priority: [ |
| 313 | "my-max-target-o-low-priority.txt", |
| 314 | ], |
| 315 | blocked: [ |
| 316 | "my-blocked.txt", |
| 317 | ], |
| 318 | unsupported_packages: [ |
| 319 | "my-unsupported-packages.txt", |
| 320 | ], |
| 321 | }, |
| 322 | } |
| 323 | |
| 324 | java_library { |
| 325 | name: "mybootlib", |
| 326 | srcs: ["Test.java"], |
| 327 | system_modules: "none", |
| 328 | sdk_version: "none", |
| 329 | compile_dex: true, |
| 330 | } |
| 331 | `), |
| 332 | ).RunTest(t) |
| 333 | |
| 334 | CheckSnapshot(t, result, "mysdk", "", |
| 335 | checkUnversionedAndroidBpContents(` |
| 336 | // This is auto-generated. DO NOT EDIT. |
| 337 | |
| 338 | prebuilt_bootclasspath_fragment { |
| 339 | name: "mybootclasspathfragment", |
| 340 | prefer: false, |
| 341 | visibility: ["//visibility:public"], |
| 342 | apex_available: ["//apex_available:platform"], |
| 343 | contents: ["mybootlib"], |
| 344 | hidden_api: { |
| 345 | unsupported: ["hiddenapi/my-unsupported.txt"], |
| 346 | removed: ["hiddenapi/my-removed.txt"], |
| 347 | max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"], |
| 348 | max_target_q: ["hiddenapi/my-max-target-q.txt"], |
| 349 | max_target_p: ["hiddenapi/my-max-target-p.txt"], |
| 350 | max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"], |
| 351 | blocked: ["hiddenapi/my-blocked.txt"], |
| 352 | unsupported_packages: ["hiddenapi/my-unsupported-packages.txt"], |
| 353 | }, |
| 354 | } |
| 355 | |
| 356 | java_import { |
| 357 | name: "mybootlib", |
| 358 | prefer: false, |
| 359 | visibility: ["//visibility:public"], |
| 360 | apex_available: ["//apex_available:platform"], |
| 361 | jars: ["java/mybootlib.jar"], |
| 362 | } |
| 363 | `), |
| 364 | checkAllCopyRules(` |
| 365 | my-unsupported.txt -> hiddenapi/my-unsupported.txt |
| 366 | my-removed.txt -> hiddenapi/my-removed.txt |
| 367 | my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt |
| 368 | my-max-target-q.txt -> hiddenapi/my-max-target-q.txt |
| 369 | my-max-target-p.txt -> hiddenapi/my-max-target-p.txt |
| 370 | my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt |
| 371 | my-blocked.txt -> hiddenapi/my-blocked.txt |
| 372 | my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt |
| 373 | .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar |
| 374 | `), |
| 375 | ) |
| 376 | } |