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