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", |
| 116 | } |
| 117 | |
| 118 | java_import { |
| 119 | name: "mybootlib", |
| 120 | prefer: false, |
| 121 | visibility: ["//visibility:public"], |
| 122 | apex_available: ["com.android.art"], |
| 123 | jars: ["java/mybootlib.jar"], |
| 124 | } |
| 125 | `), |
| 126 | checkVersionedAndroidBpContents(` |
| 127 | // This is auto-generated. DO NOT EDIT. |
| 128 | |
| 129 | prebuilt_bootclasspath_fragment { |
| 130 | name: "mysdk_mybootclasspathfragment@current", |
| 131 | sdk_member_name: "mybootclasspathfragment", |
| 132 | visibility: ["//visibility:public"], |
| 133 | apex_available: ["com.android.art"], |
| 134 | image_name: "art", |
| 135 | } |
| 136 | |
| 137 | java_import { |
| 138 | name: "mysdk_mybootlib@current", |
| 139 | sdk_member_name: "mybootlib", |
| 140 | visibility: ["//visibility:public"], |
| 141 | apex_available: ["com.android.art"], |
| 142 | jars: ["java/mybootlib.jar"], |
| 143 | } |
| 144 | |
| 145 | sdk_snapshot { |
| 146 | name: "mysdk@current", |
| 147 | visibility: ["//visibility:public"], |
| 148 | bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], |
| 149 | java_boot_libs: ["mysdk_mybootlib@current"], |
| 150 | } |
| 151 | `), |
| 152 | checkAllCopyRules(` |
| 153 | .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar |
| 154 | `), |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 155 | snapshotTestPreparer(checkSnapshotWithoutSource, prepareWithPrebuiltApex), |
| 156 | snapshotTestPreparer(checkSnapshotWithSourcePreferred, prepareWithPrebuiltApex), |
| 157 | snapshotTestPreparer(checkSnapshotPreferredWithSource, prepareWithPrebuiltApex), |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 158 | ) |
| 159 | } |
| 160 | |
| 161 | func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 162 | result := android.GroupFixturePreparers( |
| 163 | prepareForSdkTestWithJava, |
| 164 | android.FixtureWithRootAndroidBp(` |
| 165 | sdk { |
| 166 | name: "mysdk", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 167 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 168 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 169 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 170 | bootclasspath_fragment { |
| 171 | name: "mybootclasspathfragment", |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 172 | contents: ["mybootlib"], |
| 173 | } |
| 174 | |
| 175 | java_library { |
| 176 | name: "mybootlib", |
| 177 | srcs: ["Test.java"], |
| 178 | system_modules: "none", |
| 179 | sdk_version: "none", |
| 180 | compile_dex: true, |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 181 | } |
| 182 | `), |
| 183 | ).RunTest(t) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 184 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 185 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 186 | checkUnversionedAndroidBpContents(` |
| 187 | // This is auto-generated. DO NOT EDIT. |
| 188 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 189 | prebuilt_bootclasspath_fragment { |
| 190 | name: "mybootclasspathfragment", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 191 | prefer: false, |
| 192 | visibility: ["//visibility:public"], |
| 193 | apex_available: ["//apex_available:platform"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 194 | contents: ["mybootlib"], |
| 195 | } |
| 196 | |
| 197 | java_import { |
| 198 | name: "mybootlib", |
| 199 | prefer: false, |
| 200 | visibility: ["//visibility:public"], |
| 201 | apex_available: ["//apex_available:platform"], |
| 202 | jars: ["java/mybootlib.jar"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 203 | } |
| 204 | `), |
| 205 | checkVersionedAndroidBpContents(` |
| 206 | // This is auto-generated. DO NOT EDIT. |
| 207 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 208 | prebuilt_bootclasspath_fragment { |
| 209 | name: "mysdk_mybootclasspathfragment@current", |
| 210 | sdk_member_name: "mybootclasspathfragment", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 211 | visibility: ["//visibility:public"], |
| 212 | apex_available: ["//apex_available:platform"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 213 | contents: ["mysdk_mybootlib@current"], |
| 214 | } |
| 215 | |
| 216 | java_import { |
| 217 | name: "mysdk_mybootlib@current", |
| 218 | sdk_member_name: "mybootlib", |
| 219 | visibility: ["//visibility:public"], |
| 220 | apex_available: ["//apex_available:platform"], |
| 221 | jars: ["java/mybootlib.jar"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | sdk_snapshot { |
| 225 | name: "mysdk@current", |
| 226 | visibility: ["//visibility:public"], |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 227 | bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 228 | java_boot_libs: ["mysdk_mybootlib@current"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 229 | } |
| 230 | `), |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 231 | checkAllCopyRules(` |
| 232 | .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar |
| 233 | `)) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 234 | } |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 235 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 236 | // Test that bootclasspath_fragment works with sdk. |
| 237 | func TestBasicSdkWithBootclasspathFragment(t *testing.T) { |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 238 | android.GroupFixturePreparers( |
| 239 | prepareForSdkTestWithApex, |
| 240 | prepareForSdkTestWithJava, |
| 241 | android.FixtureWithRootAndroidBp(` |
| 242 | sdk { |
| 243 | name: "mysdk", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 244 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 247 | bootclasspath_fragment { |
| 248 | name: "mybootclasspathfragment", |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 249 | image_name: "art", |
| 250 | apex_available: ["myapex"], |
| 251 | } |
| 252 | |
| 253 | sdk_snapshot { |
| 254 | name: "mysdk@1", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 255 | bootclasspath_fragments: ["mybootclasspathfragment_mysdk_1"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 258 | prebuilt_bootclasspath_fragment { |
| 259 | name: "mybootclasspathfragment_mysdk_1", |
| 260 | sdk_member_name: "mybootclasspathfragment", |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 261 | prefer: false, |
| 262 | visibility: ["//visibility:public"], |
| 263 | apex_available: [ |
| 264 | "myapex", |
| 265 | ], |
| 266 | image_name: "art", |
| 267 | } |
| 268 | `), |
| 269 | ).RunTest(t) |
| 270 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 271 | |
| 272 | func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { |
| 273 | result := android.GroupFixturePreparers( |
| 274 | prepareForSdkTestWithJava, |
| 275 | android.MockFS{ |
| 276 | "my-blocked.txt": nil, |
| 277 | "my-max-target-o-low-priority.txt": nil, |
| 278 | "my-max-target-p.txt": nil, |
| 279 | "my-max-target-q.txt": nil, |
| 280 | "my-max-target-r-low-priority.txt": nil, |
| 281 | "my-removed.txt": nil, |
| 282 | "my-unsupported-packages.txt": nil, |
| 283 | "my-unsupported.txt": nil, |
| 284 | }.AddToFixture(), |
| 285 | android.FixtureWithRootAndroidBp(` |
| 286 | sdk { |
| 287 | name: "mysdk", |
| 288 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | bootclasspath_fragment { |
| 292 | name: "mybootclasspathfragment", |
| 293 | contents: ["mybootlib"], |
| 294 | hidden_api: { |
| 295 | unsupported: [ |
| 296 | "my-unsupported.txt", |
| 297 | ], |
| 298 | removed: [ |
| 299 | "my-removed.txt", |
| 300 | ], |
| 301 | max_target_r_low_priority: [ |
| 302 | "my-max-target-r-low-priority.txt", |
| 303 | ], |
| 304 | max_target_q: [ |
| 305 | "my-max-target-q.txt", |
| 306 | ], |
| 307 | max_target_p: [ |
| 308 | "my-max-target-p.txt", |
| 309 | ], |
| 310 | max_target_o_low_priority: [ |
| 311 | "my-max-target-o-low-priority.txt", |
| 312 | ], |
| 313 | blocked: [ |
| 314 | "my-blocked.txt", |
| 315 | ], |
| 316 | unsupported_packages: [ |
| 317 | "my-unsupported-packages.txt", |
| 318 | ], |
| 319 | }, |
| 320 | } |
| 321 | |
| 322 | java_library { |
| 323 | name: "mybootlib", |
| 324 | srcs: ["Test.java"], |
| 325 | system_modules: "none", |
| 326 | sdk_version: "none", |
| 327 | compile_dex: true, |
| 328 | } |
| 329 | `), |
| 330 | ).RunTest(t) |
| 331 | |
| 332 | CheckSnapshot(t, result, "mysdk", "", |
| 333 | checkUnversionedAndroidBpContents(` |
| 334 | // This is auto-generated. DO NOT EDIT. |
| 335 | |
| 336 | prebuilt_bootclasspath_fragment { |
| 337 | name: "mybootclasspathfragment", |
| 338 | prefer: false, |
| 339 | visibility: ["//visibility:public"], |
| 340 | apex_available: ["//apex_available:platform"], |
| 341 | contents: ["mybootlib"], |
| 342 | hidden_api: { |
| 343 | unsupported: ["hiddenapi/my-unsupported.txt"], |
| 344 | removed: ["hiddenapi/my-removed.txt"], |
| 345 | max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"], |
| 346 | max_target_q: ["hiddenapi/my-max-target-q.txt"], |
| 347 | max_target_p: ["hiddenapi/my-max-target-p.txt"], |
| 348 | max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"], |
| 349 | blocked: ["hiddenapi/my-blocked.txt"], |
| 350 | unsupported_packages: ["hiddenapi/my-unsupported-packages.txt"], |
| 351 | }, |
| 352 | } |
| 353 | |
| 354 | java_import { |
| 355 | name: "mybootlib", |
| 356 | prefer: false, |
| 357 | visibility: ["//visibility:public"], |
| 358 | apex_available: ["//apex_available:platform"], |
| 359 | jars: ["java/mybootlib.jar"], |
| 360 | } |
| 361 | `), |
| 362 | checkAllCopyRules(` |
| 363 | my-unsupported.txt -> hiddenapi/my-unsupported.txt |
| 364 | my-removed.txt -> hiddenapi/my-removed.txt |
| 365 | my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt |
| 366 | my-max-target-q.txt -> hiddenapi/my-max-target-q.txt |
| 367 | my-max-target-p.txt -> hiddenapi/my-max-target-p.txt |
| 368 | my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt |
| 369 | my-blocked.txt -> hiddenapi/my-blocked.txt |
| 370 | my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt |
| 371 | .intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar |
| 372 | `), |
| 373 | ) |
| 374 | } |