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