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