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