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 ( |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 18 | "fmt" |
| 19 | "path/filepath" |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 23 | "android/soong/java" |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 24 | ) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 25 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 26 | // fixtureAddPlatformBootclasspathForBootclasspathFragment adds a platform_bootclasspath module that |
| 27 | // references the bootclasspath fragment. |
| 28 | func fixtureAddPlatformBootclasspathForBootclasspathFragment(apex, fragment string) android.FixturePreparer { |
| 29 | return android.GroupFixturePreparers( |
| 30 | // Add a platform_bootclasspath module. |
| 31 | android.FixtureAddTextFile("frameworks/base/boot/Android.bp", fmt.Sprintf(` |
| 32 | platform_bootclasspath { |
| 33 | name: "platform-bootclasspath", |
| 34 | fragments: [ |
| 35 | { |
| 36 | apex: "%s", |
| 37 | module: "%s", |
| 38 | }, |
| 39 | ], |
| 40 | } |
| 41 | `, apex, fragment)), |
| 42 | android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil), |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 43 | android.FixtureAddFile("build/soong/scripts/check_boot_jars/package_allowed_list.txt", nil), |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 44 | ) |
| 45 | } |
| 46 | |
| 47 | // fixtureAddPrebuiltApexForBootclasspathFragment adds a prebuilt_apex that exports the fragment. |
| 48 | func fixtureAddPrebuiltApexForBootclasspathFragment(apex, fragment string) android.FixturePreparer { |
| 49 | apexFile := fmt.Sprintf("%s.apex", apex) |
| 50 | dir := "prebuilts/apex" |
| 51 | return android.GroupFixturePreparers( |
| 52 | // A preparer to add a prebuilt apex to the test fixture. |
| 53 | android.FixtureAddTextFile(filepath.Join(dir, "Android.bp"), fmt.Sprintf(` |
| 54 | prebuilt_apex { |
| 55 | name: "%s", |
| 56 | src: "%s", |
| 57 | exported_bootclasspath_fragments: [ |
| 58 | "%s", |
| 59 | ], |
| 60 | } |
| 61 | `, apex, apexFile, fragment)), |
| 62 | android.FixtureAddFile(filepath.Join(dir, apexFile), nil), |
| 63 | ) |
| 64 | } |
| 65 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 66 | func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) { |
| 67 | result := android.GroupFixturePreparers( |
| 68 | prepareForSdkTestWithJava, |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 69 | java.PrepareForTestWithJavaDefaultModules, |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 70 | prepareForSdkTestWithApex, |
| 71 | |
| 72 | // Some additional files needed for the art apex. |
| 73 | android.FixtureMergeMockFs(android.MockFS{ |
| 74 | "com.android.art.avbpubkey": nil, |
| 75 | "com.android.art.pem": nil, |
| 76 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 77 | }), |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 78 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 79 | // Add a platform_bootclasspath that depends on the fragment. |
| 80 | fixtureAddPlatformBootclasspathForBootclasspathFragment("com.android.art", "mybootclasspathfragment"), |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 81 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 82 | java.FixtureConfigureBootJars("com.android.art:mybootlib"), |
| 83 | android.FixtureWithRootAndroidBp(` |
| 84 | sdk { |
| 85 | name: "mysdk", |
| 86 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | apex { |
| 90 | name: "com.android.art", |
| 91 | key: "com.android.art.key", |
| 92 | bootclasspath_fragments: [ |
| 93 | "mybootclasspathfragment", |
| 94 | ], |
| 95 | updatable: false, |
| 96 | } |
| 97 | |
| 98 | bootclasspath_fragment { |
| 99 | name: "mybootclasspathfragment", |
| 100 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 101 | contents: ["mybootlib"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 102 | apex_available: ["com.android.art"], |
| 103 | } |
| 104 | |
| 105 | apex_key { |
| 106 | name: "com.android.art.key", |
| 107 | public_key: "com.android.art.avbpubkey", |
| 108 | private_key: "com.android.art.pem", |
| 109 | } |
| 110 | |
| 111 | java_library { |
| 112 | name: "mybootlib", |
| 113 | srcs: ["Test.java"], |
| 114 | system_modules: "none", |
| 115 | sdk_version: "none", |
| 116 | compile_dex: true, |
| 117 | apex_available: ["com.android.art"], |
| 118 | } |
| 119 | `), |
| 120 | ).RunTest(t) |
| 121 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 122 | // A preparer to update the test fixture used when processing an unpackage snapshot. |
| 123 | preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "mybootclasspathfragment") |
Paul Duffin | 023dba0 | 2021-04-22 01:45:29 +0100 | [diff] [blame] | 124 | |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 125 | CheckSnapshot(t, result, "mysdk", "", |
| 126 | checkUnversionedAndroidBpContents(` |
| 127 | // This is auto-generated. DO NOT EDIT. |
| 128 | |
| 129 | prebuilt_bootclasspath_fragment { |
| 130 | name: "mybootclasspathfragment", |
| 131 | prefer: false, |
| 132 | visibility: ["//visibility:public"], |
| 133 | apex_available: ["com.android.art"], |
| 134 | image_name: "art", |
Paul Duffin | 2dc665b | 2021-04-23 16:58:51 +0100 | [diff] [blame] | 135 | contents: ["mybootlib"], |
Paul Duffin | da286f4 | 2021-06-29 11:59:23 +0100 | [diff] [blame] | 136 | hidden_api: { |
| 137 | stub_flags: "hiddenapi/stub-flags.csv", |
| 138 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 139 | metadata: "hiddenapi/metadata.csv", |
| 140 | index: "hiddenapi/index.csv", |
| 141 | all_flags: "hiddenapi/all-flags.csv", |
| 142 | }, |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | java_import { |
| 146 | name: "mybootlib", |
| 147 | prefer: false, |
| 148 | visibility: ["//visibility:public"], |
| 149 | apex_available: ["com.android.art"], |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 150 | jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 151 | } |
| 152 | `), |
| 153 | checkVersionedAndroidBpContents(` |
| 154 | // This is auto-generated. DO NOT EDIT. |
| 155 | |
| 156 | prebuilt_bootclasspath_fragment { |
| 157 | name: "mysdk_mybootclasspathfragment@current", |
| 158 | sdk_member_name: "mybootclasspathfragment", |
| 159 | visibility: ["//visibility:public"], |
| 160 | apex_available: ["com.android.art"], |
| 161 | image_name: "art", |
Paul Duffin | 2dc665b | 2021-04-23 16:58:51 +0100 | [diff] [blame] | 162 | contents: ["mysdk_mybootlib@current"], |
Paul Duffin | da286f4 | 2021-06-29 11:59:23 +0100 | [diff] [blame] | 163 | hidden_api: { |
| 164 | stub_flags: "hiddenapi/stub-flags.csv", |
| 165 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 166 | metadata: "hiddenapi/metadata.csv", |
| 167 | index: "hiddenapi/index.csv", |
| 168 | all_flags: "hiddenapi/all-flags.csv", |
| 169 | }, |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | java_import { |
| 173 | name: "mysdk_mybootlib@current", |
| 174 | sdk_member_name: "mybootlib", |
| 175 | visibility: ["//visibility:public"], |
| 176 | apex_available: ["com.android.art"], |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 177 | jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | sdk_snapshot { |
| 181 | name: "mysdk@current", |
| 182 | visibility: ["//visibility:public"], |
| 183 | bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], |
| 184 | java_boot_libs: ["mysdk_mybootlib@current"], |
| 185 | } |
| 186 | `), |
| 187 | checkAllCopyRules(` |
Paul Duffin | da286f4 | 2021-06-29 11:59:23 +0100 | [diff] [blame] | 188 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv |
| 189 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 190 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 191 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
| 192 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 193 | .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar |
Paul Duffin | da286f4 | 2021-06-29 11:59:23 +0100 | [diff] [blame] | 194 | `), |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 195 | snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot), |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 196 | |
| 197 | // Check the behavior of the snapshot without the source. |
| 198 | snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) { |
| 199 | // Make sure that the boot jars package check rule includes the dex jar retrieved from the prebuilt apex. |
| 200 | checkBootJarsPackageCheckRule(t, result, "out/soong/.intermediates/prebuilts/apex/com.android.art.deapexer/android_common/deapexer/javalib/mybootlib.jar") |
| 201 | }), |
| 202 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 203 | snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot), |
| 204 | snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 205 | ) |
Paul Duffin | c8ead41 | 2021-06-07 19:28:15 +0100 | [diff] [blame] | 206 | |
| 207 | // Make sure that the boot jars package check rule includes the dex jar created from the source. |
| 208 | checkBootJarsPackageCheckRule(t, result, "out/soong/.intermediates/mybootlib/android_common_apex10000/aligned/mybootlib.jar") |
| 209 | } |
| 210 | |
| 211 | // checkBootJarsPackageCheckRule checks that the supplied module is an input to the boot jars |
| 212 | // package check rule. |
| 213 | func checkBootJarsPackageCheckRule(t *testing.T, result *android.TestResult, expectedModule string) { |
| 214 | platformBcp := result.ModuleForTests("platform-bootclasspath", "android_common") |
| 215 | bootJarsCheckRule := platformBcp.Rule("boot_jars_package_check") |
| 216 | command := bootJarsCheckRule.RuleParams.Command |
| 217 | expectedCommandArgs := " out/soong/host/linux-x86/bin/dexdump build/soong/scripts/check_boot_jars/package_allowed_list.txt " + expectedModule + " &&" |
| 218 | android.AssertStringDoesContain(t, "boot jars package check", command, expectedCommandArgs) |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) { |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 222 | result := android.GroupFixturePreparers( |
| 223 | prepareForSdkTestWithJava, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 224 | java.PrepareForTestWithJavaDefaultModules, |
| 225 | java.PrepareForTestWithJavaSdkLibraryFiles, |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 226 | java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame^] | 227 | java.FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:myothersdklibrary"), |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 228 | prepareForSdkTestWithApex, |
| 229 | |
| 230 | // Add a platform_bootclasspath that depends on the fragment. |
| 231 | fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"), |
| 232 | |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 233 | android.FixtureWithRootAndroidBp(` |
| 234 | sdk { |
| 235 | name: "mysdk", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 236 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 237 | java_sdk_libs: [ |
| 238 | // This is not strictly needed as it should be automatically added to the sdk_snapshot as |
| 239 | // a java_sdk_libs module because it is used in the mybootclasspathfragment's |
| 240 | // api.stub_libs property. However, it is specified here to ensure that duplicates are |
| 241 | // correctly deduped. |
| 242 | "mysdklibrary", |
| 243 | ], |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 244 | } |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 245 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 246 | apex { |
| 247 | name: "myapex", |
| 248 | key: "myapex.key", |
| 249 | min_sdk_version: "2", |
| 250 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 251 | } |
| 252 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 253 | bootclasspath_fragment { |
| 254 | name: "mybootclasspathfragment", |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 255 | apex_available: ["myapex"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 256 | contents: [ |
| 257 | // This should be automatically added to the sdk_snapshot as a java_boot_libs module. |
| 258 | "mybootlib", |
| 259 | // This should be automatically added to the sdk_snapshot as a java_sdk_libs module. |
| 260 | "myothersdklibrary", |
| 261 | ], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 262 | api: { |
| 263 | stub_libs: ["mysdklibrary"], |
| 264 | }, |
| 265 | core_platform_api: { |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 266 | // This should be automatically added to the sdk_snapshot as a java_sdk_libs module. |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 267 | stub_libs: ["mycoreplatform"], |
| 268 | }, |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | java_library { |
| 272 | name: "mybootlib", |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 273 | apex_available: ["myapex"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 274 | srcs: ["Test.java"], |
| 275 | system_modules: "none", |
| 276 | sdk_version: "none", |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 277 | min_sdk_version: "2", |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 278 | compile_dex: true, |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 279 | permitted_packages: ["mybootlib"], |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 280 | } |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 281 | |
| 282 | java_sdk_library { |
| 283 | name: "mysdklibrary", |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 284 | apex_available: ["myapex"], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 285 | srcs: ["Test.java"], |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 286 | shared_library: false, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 287 | public: {enabled: true}, |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 288 | min_sdk_version: "2", |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | java_sdk_library { |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 292 | name: "myothersdklibrary", |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 293 | apex_available: ["myapex"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 294 | srcs: ["Test.java"], |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 295 | compile_dex: true, |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 296 | public: {enabled: true}, |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 297 | min_sdk_version: "2", |
| 298 | permitted_packages: ["myothersdklibrary"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | java_sdk_library { |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 302 | name: "mycoreplatform", |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 303 | apex_available: ["myapex"], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 304 | srcs: ["Test.java"], |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 305 | compile_dex: true, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 306 | public: {enabled: true}, |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 307 | min_sdk_version: "2", |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 308 | } |
Paul Duffin | 4a1d451 | 2021-03-18 10:12:26 +0000 | [diff] [blame] | 309 | `), |
| 310 | ).RunTest(t) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 311 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 312 | // A preparer to update the test fixture used when processing an unpackage snapshot. |
| 313 | preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment") |
| 314 | |
Paul Duffin | 36474d3 | 2021-03-12 12:19:43 +0000 | [diff] [blame] | 315 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 316 | checkUnversionedAndroidBpContents(` |
| 317 | // This is auto-generated. DO NOT EDIT. |
| 318 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 319 | prebuilt_bootclasspath_fragment { |
| 320 | name: "mybootclasspathfragment", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 321 | prefer: false, |
| 322 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 323 | apex_available: ["myapex"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 324 | contents: [ |
| 325 | "mybootlib", |
| 326 | "myothersdklibrary", |
| 327 | ], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 328 | api: { |
| 329 | stub_libs: ["mysdklibrary"], |
| 330 | }, |
| 331 | core_platform_api: { |
| 332 | stub_libs: ["mycoreplatform"], |
| 333 | }, |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 334 | hidden_api: { |
| 335 | stub_flags: "hiddenapi/stub-flags.csv", |
| 336 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 337 | metadata: "hiddenapi/metadata.csv", |
| 338 | index: "hiddenapi/index.csv", |
| 339 | all_flags: "hiddenapi/all-flags.csv", |
| 340 | }, |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | java_import { |
| 344 | name: "mybootlib", |
| 345 | prefer: false, |
| 346 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 347 | apex_available: ["myapex"], |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 348 | jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 349 | permitted_packages: ["mybootlib"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 350 | } |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 351 | |
| 352 | java_sdk_library_import { |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 353 | name: "myothersdklibrary", |
| 354 | prefer: false, |
| 355 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 356 | apex_available: ["myapex"], |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 357 | shared_library: true, |
| 358 | compile_dex: true, |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 359 | permitted_packages: ["myothersdklibrary"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 360 | public: { |
| 361 | jars: ["sdk_library/public/myothersdklibrary-stubs.jar"], |
| 362 | stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"], |
| 363 | current_api: "sdk_library/public/myothersdklibrary.txt", |
| 364 | removed_api: "sdk_library/public/myothersdklibrary-removed.txt", |
| 365 | sdk_version: "current", |
| 366 | }, |
| 367 | } |
| 368 | |
| 369 | java_sdk_library_import { |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 370 | name: "mysdklibrary", |
| 371 | prefer: false, |
| 372 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 373 | apex_available: ["myapex"], |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 374 | shared_library: false, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 375 | public: { |
| 376 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 377 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 378 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 379 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 380 | sdk_version: "current", |
| 381 | }, |
| 382 | } |
| 383 | |
| 384 | java_sdk_library_import { |
| 385 | name: "mycoreplatform", |
| 386 | prefer: false, |
| 387 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 388 | apex_available: ["myapex"], |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 389 | shared_library: true, |
| 390 | compile_dex: true, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 391 | public: { |
| 392 | jars: ["sdk_library/public/mycoreplatform-stubs.jar"], |
| 393 | stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"], |
| 394 | current_api: "sdk_library/public/mycoreplatform.txt", |
| 395 | removed_api: "sdk_library/public/mycoreplatform-removed.txt", |
| 396 | sdk_version: "current", |
| 397 | }, |
| 398 | } |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 399 | `), |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 400 | checkVersionedAndroidBpContents(` |
| 401 | // This is auto-generated. DO NOT EDIT. |
| 402 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 403 | prebuilt_bootclasspath_fragment { |
| 404 | name: "mysdk_mybootclasspathfragment@current", |
| 405 | sdk_member_name: "mybootclasspathfragment", |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 406 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 407 | apex_available: ["myapex"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 408 | contents: [ |
| 409 | "mysdk_mybootlib@current", |
| 410 | "mysdk_myothersdklibrary@current", |
| 411 | ], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 412 | api: { |
| 413 | stub_libs: ["mysdk_mysdklibrary@current"], |
| 414 | }, |
| 415 | core_platform_api: { |
| 416 | stub_libs: ["mysdk_mycoreplatform@current"], |
| 417 | }, |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 418 | hidden_api: { |
| 419 | stub_flags: "hiddenapi/stub-flags.csv", |
| 420 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 421 | metadata: "hiddenapi/metadata.csv", |
| 422 | index: "hiddenapi/index.csv", |
| 423 | all_flags: "hiddenapi/all-flags.csv", |
| 424 | }, |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | java_import { |
| 428 | name: "mysdk_mybootlib@current", |
| 429 | sdk_member_name: "mybootlib", |
| 430 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 431 | apex_available: ["myapex"], |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 432 | jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 433 | permitted_packages: ["mybootlib"], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 436 | java_sdk_library_import { |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 437 | name: "mysdk_myothersdklibrary@current", |
| 438 | sdk_member_name: "myothersdklibrary", |
| 439 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 440 | apex_available: ["myapex"], |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 441 | shared_library: true, |
| 442 | compile_dex: true, |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 443 | permitted_packages: ["myothersdklibrary"], |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 444 | public: { |
| 445 | jars: ["sdk_library/public/myothersdklibrary-stubs.jar"], |
| 446 | stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"], |
| 447 | current_api: "sdk_library/public/myothersdklibrary.txt", |
| 448 | removed_api: "sdk_library/public/myothersdklibrary-removed.txt", |
| 449 | sdk_version: "current", |
| 450 | }, |
| 451 | } |
| 452 | |
| 453 | java_sdk_library_import { |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 454 | name: "mysdk_mysdklibrary@current", |
| 455 | sdk_member_name: "mysdklibrary", |
| 456 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 457 | apex_available: ["myapex"], |
Paul Duffin | f4600f6 | 2021-05-13 22:34:45 +0100 | [diff] [blame] | 458 | shared_library: false, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 459 | public: { |
| 460 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 461 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 462 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 463 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 464 | sdk_version: "current", |
| 465 | }, |
| 466 | } |
| 467 | |
| 468 | java_sdk_library_import { |
| 469 | name: "mysdk_mycoreplatform@current", |
| 470 | sdk_member_name: "mycoreplatform", |
| 471 | visibility: ["//visibility:public"], |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 472 | apex_available: ["myapex"], |
Paul Duffin | ea8f808 | 2021-06-24 13:25:57 +0100 | [diff] [blame] | 473 | shared_library: true, |
| 474 | compile_dex: true, |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 475 | public: { |
| 476 | jars: ["sdk_library/public/mycoreplatform-stubs.jar"], |
| 477 | stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"], |
| 478 | current_api: "sdk_library/public/mycoreplatform.txt", |
| 479 | removed_api: "sdk_library/public/mycoreplatform-removed.txt", |
| 480 | sdk_version: "current", |
| 481 | }, |
| 482 | } |
| 483 | |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 484 | sdk_snapshot { |
| 485 | name: "mysdk@current", |
| 486 | visibility: ["//visibility:public"], |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 487 | bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"], |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 488 | java_boot_libs: ["mysdk_mybootlib@current"], |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 489 | java_sdk_libs: [ |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 490 | "mysdk_myothersdklibrary@current", |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 491 | "mysdk_mysdklibrary@current", |
| 492 | "mysdk_mycoreplatform@current", |
| 493 | ], |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 494 | } |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 495 | `), |
Paul Duffin | a57835e | 2021-04-19 13:23:06 +0100 | [diff] [blame] | 496 | checkAllCopyRules(` |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 497 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv |
| 498 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 499 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 500 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
| 501 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 502 | .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar |
Paul Duffin | a10bd3c | 2021-05-12 13:46:54 +0100 | [diff] [blame] | 503 | .intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar |
| 504 | .intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt |
| 505 | .intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt |
Paul Duffin | 895c714 | 2021-04-25 13:40:15 +0100 | [diff] [blame] | 506 | .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 507 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 508 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt |
| 509 | .intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar |
| 510 | .intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt |
| 511 | .intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 512 | `), |
| 513 | snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot), |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 514 | snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) { |
| 515 | module := result.ModuleForTests("platform-bootclasspath", "android_common") |
| 516 | var rule android.TestingBuildParams |
| 517 | rule = module.Output("out/soong/hiddenapi/hiddenapi-flags.csv") |
| 518 | java.CheckHiddenAPIRuleInputs(t, "monolithic flags", ` |
| 519 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/annotation-flags-from-classes.csv |
| 520 | out/soong/hiddenapi/hiddenapi-stub-flags.txt |
| 521 | snapshot/hiddenapi/annotation-flags.csv |
| 522 | `, rule) |
| 523 | |
| 524 | rule = module.Output("out/soong/hiddenapi/hiddenapi-unsupported.csv") |
| 525 | java.CheckHiddenAPIRuleInputs(t, "monolithic metadata", ` |
| 526 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/metadata-from-classes.csv |
| 527 | snapshot/hiddenapi/metadata.csv |
| 528 | `, rule) |
| 529 | |
| 530 | rule = module.Output("out/soong/hiddenapi/hiddenapi-index.csv") |
| 531 | java.CheckHiddenAPIRuleInputs(t, "monolithic index", ` |
| 532 | out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv |
| 533 | snapshot/hiddenapi/index.csv |
| 534 | `, rule) |
Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 535 | |
| 536 | // Make sure that the permitted packages from the prebuilts end up in the |
| 537 | // updatable-bcp-packages.txt file. |
| 538 | rule = module.Output("updatable-bcp-packages.txt") |
| 539 | expectedContents := `'mybootlib\nmyothersdklibrary\n'` |
| 540 | android.AssertStringEquals(t, "updatable-bcp-packages.txt", expectedContents, rule.Args["content"]) |
Paul Duffin | d061d40 | 2021-06-07 21:36:01 +0100 | [diff] [blame] | 541 | }), |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 542 | snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot), |
| 543 | snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), |
| 544 | ) |
Paul Duffin | f7f65da | 2021-03-10 15:00:46 +0000 | [diff] [blame] | 545 | } |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 546 | |
Paul Duffin | 51227d8 | 2021-05-18 12:54:27 +0100 | [diff] [blame] | 547 | // TestSnapshotWithBootClasspathFragment_Fragments makes sure that the fragments property of a |
| 548 | // bootclasspath_fragment is correctly output to the sdk snapshot. |
| 549 | func TestSnapshotWithBootClasspathFragment_Fragments(t *testing.T) { |
| 550 | result := android.GroupFixturePreparers( |
| 551 | prepareForSdkTestWithJava, |
| 552 | java.PrepareForTestWithJavaDefaultModules, |
| 553 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 554 | java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary"), |
| 555 | prepareForSdkTestWithApex, |
| 556 | |
| 557 | // Some additional files needed for the myotherapex. |
| 558 | android.FixtureMergeMockFs(android.MockFS{ |
| 559 | "system/sepolicy/apex/myotherapex-file_contexts": nil, |
| 560 | "myotherapex/apex_manifest.json": nil, |
| 561 | "myotherapex/Test.java": nil, |
| 562 | }), |
| 563 | |
| 564 | android.FixtureAddTextFile("myotherapex/Android.bp", ` |
| 565 | apex { |
| 566 | name: "myotherapex", |
| 567 | key: "myapex.key", |
| 568 | min_sdk_version: "2", |
| 569 | bootclasspath_fragments: ["myotherbootclasspathfragment"], |
| 570 | } |
| 571 | |
| 572 | bootclasspath_fragment { |
| 573 | name: "myotherbootclasspathfragment", |
| 574 | apex_available: ["myotherapex"], |
| 575 | contents: [ |
| 576 | "myotherlib", |
| 577 | ], |
| 578 | } |
| 579 | |
| 580 | java_library { |
| 581 | name: "myotherlib", |
| 582 | apex_available: ["myotherapex"], |
| 583 | srcs: ["Test.java"], |
| 584 | min_sdk_version: "2", |
| 585 | permitted_packages: ["myothersdklibrary"], |
| 586 | compile_dex: true, |
| 587 | } |
| 588 | `), |
| 589 | |
| 590 | android.FixtureWithRootAndroidBp(` |
| 591 | sdk { |
| 592 | name: "mysdk", |
| 593 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 594 | } |
| 595 | |
| 596 | bootclasspath_fragment { |
| 597 | name: "mybootclasspathfragment", |
| 598 | contents: [ |
| 599 | "mysdklibrary", |
| 600 | ], |
| 601 | fragments: [ |
| 602 | { |
| 603 | apex: "myotherapex", |
| 604 | module: "myotherbootclasspathfragment" |
| 605 | }, |
| 606 | ], |
| 607 | } |
| 608 | |
| 609 | java_sdk_library { |
| 610 | name: "mysdklibrary", |
| 611 | srcs: ["Test.java"], |
| 612 | shared_library: false, |
| 613 | public: {enabled: true}, |
| 614 | min_sdk_version: "2", |
| 615 | } |
| 616 | `), |
| 617 | ).RunTest(t) |
| 618 | |
| 619 | // A preparer to update the test fixture used when processing an unpackage snapshot. |
| 620 | preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment") |
| 621 | |
| 622 | CheckSnapshot(t, result, "mysdk", "", |
| 623 | checkUnversionedAndroidBpContents(` |
| 624 | // This is auto-generated. DO NOT EDIT. |
| 625 | |
| 626 | prebuilt_bootclasspath_fragment { |
| 627 | name: "mybootclasspathfragment", |
| 628 | prefer: false, |
| 629 | visibility: ["//visibility:public"], |
| 630 | apex_available: ["//apex_available:platform"], |
| 631 | contents: ["mysdklibrary"], |
| 632 | fragments: [ |
| 633 | { |
| 634 | apex: "myotherapex", |
| 635 | module: "myotherbootclasspathfragment", |
| 636 | }, |
| 637 | ], |
| 638 | hidden_api: { |
| 639 | stub_flags: "hiddenapi/stub-flags.csv", |
| 640 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 641 | metadata: "hiddenapi/metadata.csv", |
| 642 | index: "hiddenapi/index.csv", |
| 643 | all_flags: "hiddenapi/all-flags.csv", |
| 644 | }, |
| 645 | } |
| 646 | |
| 647 | java_sdk_library_import { |
| 648 | name: "mysdklibrary", |
| 649 | prefer: false, |
| 650 | visibility: ["//visibility:public"], |
| 651 | apex_available: ["//apex_available:platform"], |
| 652 | shared_library: false, |
| 653 | public: { |
| 654 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 655 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 656 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 657 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 658 | sdk_version: "current", |
| 659 | }, |
| 660 | } |
| 661 | `), |
| 662 | snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot), |
| 663 | snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot), |
| 664 | snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), |
| 665 | ) |
| 666 | } |
| 667 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 668 | // Test that bootclasspath_fragment works with sdk. |
| 669 | func TestBasicSdkWithBootclasspathFragment(t *testing.T) { |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 670 | android.GroupFixturePreparers( |
| 671 | prepareForSdkTestWithApex, |
| 672 | prepareForSdkTestWithJava, |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 673 | android.FixtureAddFile("java/mybootlib.jar", nil), |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 674 | android.FixtureWithRootAndroidBp(` |
| 675 | sdk { |
| 676 | name: "mysdk", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 677 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 680 | bootclasspath_fragment { |
| 681 | name: "mybootclasspathfragment", |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 682 | image_name: "art", |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 683 | contents: ["mybootlib"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 684 | apex_available: ["myapex"], |
| 685 | } |
| 686 | |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 687 | java_library { |
| 688 | name: "mybootlib", |
| 689 | apex_available: ["myapex"], |
| 690 | srcs: ["Test.java"], |
| 691 | system_modules: "none", |
| 692 | sdk_version: "none", |
| 693 | min_sdk_version: "1", |
| 694 | compile_dex: true, |
| 695 | } |
| 696 | |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 697 | sdk_snapshot { |
| 698 | name: "mysdk@1", |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 699 | bootclasspath_fragments: ["mysdk_mybootclasspathfragment@1"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 702 | prebuilt_bootclasspath_fragment { |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 703 | name: "mysdk_mybootclasspathfragment@1", |
Paul Duffin | 0b28a8d | 2021-04-21 23:38:34 +0100 | [diff] [blame] | 704 | sdk_member_name: "mybootclasspathfragment", |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 705 | prefer: false, |
| 706 | visibility: ["//visibility:public"], |
| 707 | apex_available: [ |
| 708 | "myapex", |
| 709 | ], |
| 710 | image_name: "art", |
Paul Duffin | 8018e50 | 2021-05-21 19:28:09 +0100 | [diff] [blame] | 711 | contents: ["mysdk_mybootlib@1"], |
| 712 | } |
| 713 | |
| 714 | java_import { |
| 715 | name: "mysdk_mybootlib@1", |
| 716 | sdk_member_name: "mybootlib", |
| 717 | visibility: ["//visibility:public"], |
| 718 | apex_available: ["com.android.art"], |
| 719 | jars: ["java/mybootlib.jar"], |
Paul Duffin | 04b4a19 | 2021-03-18 11:05:31 +0000 | [diff] [blame] | 720 | } |
| 721 | `), |
| 722 | ).RunTest(t) |
| 723 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 724 | |
| 725 | func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { |
| 726 | result := android.GroupFixturePreparers( |
| 727 | prepareForSdkTestWithJava, |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 728 | java.PrepareForTestWithJavaDefaultModules, |
| 729 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 730 | java.FixtureWithLastReleaseApis("mysdklibrary"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame^] | 731 | java.FixtureConfigureApexBootJars("myapex:mybootlib"), |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 732 | prepareForSdkTestWithApex, |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 733 | |
| 734 | // Add a platform_bootclasspath that depends on the fragment. |
| 735 | fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"), |
| 736 | |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 737 | android.MockFS{ |
| 738 | "my-blocked.txt": nil, |
| 739 | "my-max-target-o-low-priority.txt": nil, |
| 740 | "my-max-target-p.txt": nil, |
| 741 | "my-max-target-q.txt": nil, |
| 742 | "my-max-target-r-low-priority.txt": nil, |
| 743 | "my-removed.txt": nil, |
| 744 | "my-unsupported-packages.txt": nil, |
| 745 | "my-unsupported.txt": nil, |
| 746 | }.AddToFixture(), |
| 747 | android.FixtureWithRootAndroidBp(` |
| 748 | sdk { |
| 749 | name: "mysdk", |
| 750 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 751 | } |
| 752 | |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 753 | apex { |
| 754 | name: "myapex", |
| 755 | key: "myapex.key", |
| 756 | min_sdk_version: "1", |
| 757 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 758 | } |
| 759 | |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 760 | bootclasspath_fragment { |
| 761 | name: "mybootclasspathfragment", |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 762 | apex_available: ["myapex"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 763 | contents: ["mybootlib"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 764 | api: { |
| 765 | stub_libs: ["mysdklibrary"], |
| 766 | }, |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 767 | hidden_api: { |
| 768 | unsupported: [ |
| 769 | "my-unsupported.txt", |
| 770 | ], |
| 771 | removed: [ |
| 772 | "my-removed.txt", |
| 773 | ], |
| 774 | max_target_r_low_priority: [ |
| 775 | "my-max-target-r-low-priority.txt", |
| 776 | ], |
| 777 | max_target_q: [ |
| 778 | "my-max-target-q.txt", |
| 779 | ], |
| 780 | max_target_p: [ |
| 781 | "my-max-target-p.txt", |
| 782 | ], |
| 783 | max_target_o_low_priority: [ |
| 784 | "my-max-target-o-low-priority.txt", |
| 785 | ], |
| 786 | blocked: [ |
| 787 | "my-blocked.txt", |
| 788 | ], |
| 789 | unsupported_packages: [ |
| 790 | "my-unsupported-packages.txt", |
| 791 | ], |
| 792 | }, |
| 793 | } |
| 794 | |
| 795 | java_library { |
| 796 | name: "mybootlib", |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 797 | apex_available: ["myapex"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 798 | srcs: ["Test.java"], |
| 799 | system_modules: "none", |
| 800 | sdk_version: "none", |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 801 | min_sdk_version: "1", |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 802 | compile_dex: true, |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 803 | permitted_packages: ["mybootlib"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 804 | } |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 805 | |
| 806 | java_sdk_library { |
| 807 | name: "mysdklibrary", |
| 808 | srcs: ["Test.java"], |
| 809 | compile_dex: true, |
| 810 | public: {enabled: true}, |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 811 | permitted_packages: ["mysdklibrary"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 812 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 813 | `), |
| 814 | ).RunTest(t) |
| 815 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 816 | // A preparer to update the test fixture used when processing an unpackage snapshot. |
| 817 | preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment") |
| 818 | |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 819 | CheckSnapshot(t, result, "mysdk", "", |
| 820 | checkUnversionedAndroidBpContents(` |
| 821 | // This is auto-generated. DO NOT EDIT. |
| 822 | |
| 823 | prebuilt_bootclasspath_fragment { |
| 824 | name: "mybootclasspathfragment", |
| 825 | prefer: false, |
| 826 | visibility: ["//visibility:public"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 827 | apex_available: ["myapex"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 828 | contents: ["mybootlib"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 829 | api: { |
| 830 | stub_libs: ["mysdklibrary"], |
| 831 | }, |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 832 | hidden_api: { |
| 833 | unsupported: ["hiddenapi/my-unsupported.txt"], |
| 834 | removed: ["hiddenapi/my-removed.txt"], |
| 835 | max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"], |
| 836 | max_target_q: ["hiddenapi/my-max-target-q.txt"], |
| 837 | max_target_p: ["hiddenapi/my-max-target-p.txt"], |
| 838 | max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"], |
| 839 | blocked: ["hiddenapi/my-blocked.txt"], |
| 840 | unsupported_packages: ["hiddenapi/my-unsupported-packages.txt"], |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 841 | stub_flags: "hiddenapi/stub-flags.csv", |
| 842 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 843 | metadata: "hiddenapi/metadata.csv", |
| 844 | index: "hiddenapi/index.csv", |
| 845 | all_flags: "hiddenapi/all-flags.csv", |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 846 | }, |
| 847 | } |
| 848 | |
| 849 | java_import { |
| 850 | name: "mybootlib", |
| 851 | prefer: false, |
| 852 | visibility: ["//visibility:public"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 853 | apex_available: ["myapex"], |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 854 | jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 855 | permitted_packages: ["mybootlib"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 856 | } |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 857 | |
| 858 | java_sdk_library_import { |
| 859 | name: "mysdklibrary", |
| 860 | prefer: false, |
| 861 | visibility: ["//visibility:public"], |
| 862 | apex_available: ["//apex_available:platform"], |
| 863 | shared_library: true, |
| 864 | compile_dex: true, |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 865 | permitted_packages: ["mysdklibrary"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 866 | public: { |
| 867 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 868 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 869 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 870 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 871 | sdk_version: "current", |
| 872 | }, |
| 873 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 874 | `), |
| 875 | checkAllCopyRules(` |
| 876 | my-unsupported.txt -> hiddenapi/my-unsupported.txt |
| 877 | my-removed.txt -> hiddenapi/my-removed.txt |
| 878 | my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt |
| 879 | my-max-target-q.txt -> hiddenapi/my-max-target-q.txt |
| 880 | my-max-target-p.txt -> hiddenapi/my-max-target-p.txt |
| 881 | my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt |
| 882 | my-blocked.txt -> hiddenapi/my-blocked.txt |
| 883 | my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 884 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv |
| 885 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 886 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 887 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
| 888 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 889 | .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 890 | .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 891 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 892 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 893 | `), |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 894 | snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot), |
| 895 | snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot), |
| 896 | snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 897 | ) |
| 898 | } |