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, |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 678 | java.FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"), |
| 679 | java.FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"), |
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, |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 694 | "my-new-max-target-q.txt": nil, |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 695 | }.AddToFixture(), |
| 696 | android.FixtureWithRootAndroidBp(` |
| 697 | sdk { |
| 698 | name: "mysdk", |
| 699 | bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 700 | } |
| 701 | |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 702 | apex { |
| 703 | name: "myapex", |
| 704 | key: "myapex.key", |
| 705 | min_sdk_version: "1", |
| 706 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 707 | } |
| 708 | |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 709 | bootclasspath_fragment { |
| 710 | name: "mybootclasspathfragment", |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 711 | apex_available: ["myapex"], |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 712 | contents: ["mybootlib", "mynewlibrary"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 713 | api: { |
| 714 | stub_libs: ["mysdklibrary"], |
| 715 | }, |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 716 | hidden_api: { |
| 717 | unsupported: [ |
| 718 | "my-unsupported.txt", |
| 719 | ], |
| 720 | removed: [ |
| 721 | "my-removed.txt", |
| 722 | ], |
| 723 | max_target_r_low_priority: [ |
| 724 | "my-max-target-r-low-priority.txt", |
| 725 | ], |
| 726 | max_target_q: [ |
| 727 | "my-max-target-q.txt", |
| 728 | ], |
| 729 | max_target_p: [ |
| 730 | "my-max-target-p.txt", |
| 731 | ], |
| 732 | max_target_o_low_priority: [ |
| 733 | "my-max-target-o-low-priority.txt", |
| 734 | ], |
| 735 | blocked: [ |
| 736 | "my-blocked.txt", |
| 737 | ], |
| 738 | unsupported_packages: [ |
| 739 | "my-unsupported-packages.txt", |
| 740 | ], |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 741 | split_packages: ["sdklibrary"], |
| 742 | package_prefixes: ["sdklibrary.all.mine"], |
| 743 | single_packages: ["sdklibrary.mine"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 744 | }, |
| 745 | } |
| 746 | |
| 747 | java_library { |
| 748 | name: "mybootlib", |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 749 | apex_available: ["myapex"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 750 | srcs: ["Test.java"], |
| 751 | system_modules: "none", |
| 752 | sdk_version: "none", |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 753 | min_sdk_version: "1", |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 754 | compile_dex: true, |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 755 | permitted_packages: ["mybootlib"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 756 | } |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 757 | |
| 758 | java_sdk_library { |
| 759 | name: "mysdklibrary", |
| 760 | srcs: ["Test.java"], |
| 761 | compile_dex: true, |
| 762 | public: {enabled: true}, |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 763 | permitted_packages: ["mysdklibrary"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 764 | } |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 765 | |
| 766 | java_sdk_library { |
| 767 | name: "mynewlibrary", |
| 768 | apex_available: ["myapex"], |
| 769 | srcs: ["Test.java"], |
| 770 | min_sdk_version: "10", |
| 771 | compile_dex: true, |
| 772 | public: {enabled: true}, |
| 773 | permitted_packages: ["mysdklibrary"], |
| 774 | hidden_api: { |
| 775 | max_target_q: [ |
| 776 | "my-new-max-target-q.txt", |
| 777 | ], |
| 778 | split_packages: ["sdklibrary", "newlibrary"], |
| 779 | package_prefixes: ["newlibrary.all.mine"], |
| 780 | single_packages: ["newlibrary.mine"], |
| 781 | }, |
| 782 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 783 | `), |
| 784 | ).RunTest(t) |
| 785 | |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 786 | // A preparer to update the test fixture used when processing an unpackage snapshot. |
| 787 | preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment") |
| 788 | |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 789 | CheckSnapshot(t, result, "mysdk", "", |
Paul Duffin | b01ac4b | 2022-05-24 20:10:05 +0000 | [diff] [blame] | 790 | checkAndroidBpContents(` |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 791 | // This is auto-generated. DO NOT EDIT. |
| 792 | |
| 793 | prebuilt_bootclasspath_fragment { |
| 794 | name: "mybootclasspathfragment", |
| 795 | prefer: false, |
| 796 | visibility: ["//visibility:public"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 797 | apex_available: ["myapex"], |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 798 | contents: [ |
| 799 | "mybootlib", |
| 800 | "mynewlibrary", |
| 801 | ], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 802 | api: { |
| 803 | stub_libs: ["mysdklibrary"], |
| 804 | }, |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 805 | hidden_api: { |
| 806 | unsupported: ["hiddenapi/my-unsupported.txt"], |
| 807 | removed: ["hiddenapi/my-removed.txt"], |
| 808 | max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"], |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 809 | max_target_q: [ |
| 810 | "hiddenapi/my-max-target-q.txt", |
| 811 | "hiddenapi/my-new-max-target-q.txt", |
| 812 | ], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 813 | max_target_p: ["hiddenapi/my-max-target-p.txt"], |
| 814 | max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"], |
| 815 | blocked: ["hiddenapi/my-blocked.txt"], |
| 816 | unsupported_packages: ["hiddenapi/my-unsupported-packages.txt"], |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 817 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 818 | metadata: "hiddenapi/metadata.csv", |
| 819 | index: "hiddenapi/index.csv", |
Paul Duffin | 8d007e9 | 2021-07-22 12:00:49 +0100 | [diff] [blame] | 820 | signature_patterns: "hiddenapi/signature-patterns.csv", |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 821 | filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv", |
| 822 | filtered_flags: "hiddenapi/filtered-flags.csv", |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 823 | }, |
| 824 | } |
| 825 | |
| 826 | java_import { |
| 827 | name: "mybootlib", |
| 828 | prefer: false, |
| 829 | visibility: ["//visibility:public"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 830 | apex_available: ["myapex"], |
Paul Duffin | 5c21145 | 2021-07-15 12:42:44 +0100 | [diff] [blame] | 831 | jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"], |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 832 | permitted_packages: ["mybootlib"], |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 833 | } |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 834 | |
| 835 | java_sdk_library_import { |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 836 | name: "mynewlibrary", |
| 837 | prefer: false, |
| 838 | visibility: ["//visibility:public"], |
| 839 | apex_available: ["myapex"], |
| 840 | shared_library: true, |
| 841 | compile_dex: true, |
| 842 | permitted_packages: ["mysdklibrary"], |
| 843 | public: { |
| 844 | jars: ["sdk_library/public/mynewlibrary-stubs.jar"], |
| 845 | stub_srcs: ["sdk_library/public/mynewlibrary_stub_sources"], |
| 846 | current_api: "sdk_library/public/mynewlibrary.txt", |
| 847 | removed_api: "sdk_library/public/mynewlibrary-removed.txt", |
| 848 | sdk_version: "current", |
| 849 | }, |
| 850 | } |
| 851 | |
| 852 | java_sdk_library_import { |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 853 | name: "mysdklibrary", |
| 854 | prefer: false, |
| 855 | visibility: ["//visibility:public"], |
| 856 | apex_available: ["//apex_available:platform"], |
| 857 | shared_library: true, |
| 858 | compile_dex: true, |
Paul Duffin | 869de14 | 2021-07-15 14:14:41 +0100 | [diff] [blame] | 859 | permitted_packages: ["mysdklibrary"], |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 860 | public: { |
| 861 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 862 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 863 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 864 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 865 | sdk_version: "current", |
| 866 | }, |
| 867 | } |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 868 | `), |
| 869 | checkAllCopyRules(` |
| 870 | my-unsupported.txt -> hiddenapi/my-unsupported.txt |
| 871 | my-removed.txt -> hiddenapi/my-removed.txt |
| 872 | my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt |
| 873 | my-max-target-q.txt -> hiddenapi/my-max-target-q.txt |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 874 | my-new-max-target-q.txt -> hiddenapi/my-new-max-target-q.txt |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 875 | my-max-target-p.txt -> hiddenapi/my-max-target-p.txt |
| 876 | my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt |
| 877 | my-blocked.txt -> hiddenapi/my-blocked.txt |
| 878 | my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt |
Paul Duffin | 2fef136 | 2021-04-15 13:32:00 +0100 | [diff] [blame] | 879 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 880 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 881 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
Paul Duffin | 8d007e9 | 2021-07-22 12:00:49 +0100 | [diff] [blame] | 882 | .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] | 883 | .intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv |
| 884 | .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] | 885 | .intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar |
Paul Duffin | 3f1ae0b | 2022-07-27 16:27:42 +0000 | [diff] [blame] | 886 | .intermediates/mynewlibrary.stubs/android_common/javac/mynewlibrary.stubs.jar -> sdk_library/public/mynewlibrary-stubs.jar |
| 887 | .intermediates/mynewlibrary.stubs.source/android_common/metalava/mynewlibrary.stubs.source_api.txt -> sdk_library/public/mynewlibrary.txt |
| 888 | .intermediates/mynewlibrary.stubs.source/android_common/metalava/mynewlibrary.stubs.source_removed.txt -> sdk_library/public/mynewlibrary-removed.txt |
Paul Duffin | 475daaf | 2021-05-13 00:57:55 +0100 | [diff] [blame] | 889 | .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 890 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 891 | .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] | 892 | `), |
Paul Duffin | 7c47515 | 2021-06-09 16:17:58 +0100 | [diff] [blame] | 893 | snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot), |
| 894 | snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot), |
| 895 | snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot), |
Paul Duffin | 7c95555 | 2021-04-19 13:23:53 +0100 | [diff] [blame] | 896 | ) |
| 897 | } |
Paul Duffin | 1938dba | 2022-07-26 23:53:00 +0000 | [diff] [blame^] | 898 | |
| 899 | func testSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T, targetBuildRelease string, |
| 900 | expectedSdkSnapshot string, |
| 901 | expectedCopyRules string, |
| 902 | expectedStubFlagsInputs []string, |
| 903 | suffix string) { |
| 904 | |
| 905 | result := android.GroupFixturePreparers( |
| 906 | prepareForSdkTestWithJava, |
| 907 | java.PrepareForTestWithJavaDefaultModules, |
| 908 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 909 | java.FixtureWithLastReleaseApis("mysdklibrary", "mynewsdklibrary"), |
| 910 | java.FixtureConfigureApexBootJars("myapex:mysdklibrary", "myapex:mynewsdklibrary"), |
| 911 | prepareForSdkTestWithApex, |
| 912 | |
| 913 | // Add a platform_bootclasspath that depends on the fragment. |
| 914 | fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"), |
| 915 | |
| 916 | android.FixtureMergeEnv(map[string]string{ |
| 917 | "SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease, |
| 918 | }), |
| 919 | |
| 920 | android.FixtureWithRootAndroidBp(` |
| 921 | sdk { |
| 922 | name: "mysdk", |
| 923 | apexes: ["myapex"], |
| 924 | } |
| 925 | |
| 926 | apex { |
| 927 | name: "myapex", |
| 928 | key: "myapex.key", |
| 929 | min_sdk_version: "S", |
| 930 | bootclasspath_fragments: ["mybootclasspathfragment"], |
| 931 | } |
| 932 | |
| 933 | bootclasspath_fragment { |
| 934 | name: "mybootclasspathfragment", |
| 935 | apex_available: ["myapex"], |
| 936 | contents: [ |
| 937 | "mysdklibrary", |
| 938 | "mynewsdklibrary", |
| 939 | ], |
| 940 | |
| 941 | hidden_api: { |
| 942 | split_packages: [], |
| 943 | }, |
| 944 | } |
| 945 | |
| 946 | java_sdk_library { |
| 947 | name: "mysdklibrary", |
| 948 | apex_available: ["myapex"], |
| 949 | srcs: ["Test.java"], |
| 950 | shared_library: false, |
| 951 | public: {enabled: true}, |
| 952 | min_sdk_version: "S", |
| 953 | } |
| 954 | |
| 955 | java_sdk_library { |
| 956 | name: "mynewsdklibrary", |
| 957 | apex_available: ["myapex"], |
| 958 | srcs: ["Test.java"], |
| 959 | compile_dex: true, |
| 960 | public: {enabled: true}, |
| 961 | min_sdk_version: "Tiramisu", |
| 962 | permitted_packages: ["mynewsdklibrary"], |
| 963 | } |
| 964 | `), |
| 965 | ).RunTest(t) |
| 966 | |
| 967 | bcpf := result.ModuleForTests("mybootclasspathfragment", "android_common") |
| 968 | rule := bcpf.Output("out/soong/.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi" + suffix + "/stub-flags.csv") |
| 969 | android.AssertPathsRelativeToTopEquals(t, "stub flags inputs", expectedStubFlagsInputs, rule.Implicits) |
| 970 | |
| 971 | CheckSnapshot(t, result, "mysdk", "", |
| 972 | checkAndroidBpContents(expectedSdkSnapshot), |
| 973 | checkAllCopyRules(expectedCopyRules), |
| 974 | ) |
| 975 | } |
| 976 | |
| 977 | func TestSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T) { |
| 978 | t.Run("target S build", func(t *testing.T) { |
| 979 | expectedSnapshot := ` |
| 980 | // This is auto-generated. DO NOT EDIT. |
| 981 | |
| 982 | prebuilt_bootclasspath_fragment { |
| 983 | name: "mybootclasspathfragment", |
| 984 | prefer: false, |
| 985 | visibility: ["//visibility:public"], |
| 986 | apex_available: ["myapex"], |
| 987 | contents: ["mysdklibrary"], |
| 988 | hidden_api: { |
| 989 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 990 | metadata: "hiddenapi/metadata.csv", |
| 991 | index: "hiddenapi/index.csv", |
| 992 | stub_flags: "hiddenapi/stub-flags.csv", |
| 993 | all_flags: "hiddenapi/all-flags.csv", |
| 994 | }, |
| 995 | } |
| 996 | |
| 997 | java_sdk_library_import { |
| 998 | name: "mysdklibrary", |
| 999 | prefer: false, |
| 1000 | visibility: ["//visibility:public"], |
| 1001 | apex_available: ["myapex"], |
| 1002 | shared_library: false, |
| 1003 | public: { |
| 1004 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 1005 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 1006 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 1007 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 1008 | sdk_version: "current", |
| 1009 | }, |
| 1010 | } |
| 1011 | ` |
| 1012 | expectedCopyRules := ` |
| 1013 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 1014 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/metadata.csv -> hiddenapi/metadata.csv |
| 1015 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/index.csv -> hiddenapi/index.csv |
| 1016 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/stub-flags.csv -> hiddenapi/stub-flags.csv |
| 1017 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/all-flags.csv -> hiddenapi/all-flags.csv |
| 1018 | .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 1019 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 1020 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt |
| 1021 | ` |
| 1022 | |
| 1023 | // On S the stub flags should only be generated from mysdklibrary as mynewsdklibrary is not part |
| 1024 | // of the snapshot. |
| 1025 | expectedStubFlagsInputs := []string{ |
| 1026 | "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", |
| 1027 | "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", |
| 1028 | } |
| 1029 | |
| 1030 | testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "S", |
| 1031 | expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "-for-sdk-snapshot") |
| 1032 | }) |
| 1033 | |
| 1034 | t.Run("target-Tiramisu-build", func(t *testing.T) { |
| 1035 | expectedSnapshot := ` |
| 1036 | // This is auto-generated. DO NOT EDIT. |
| 1037 | |
| 1038 | prebuilt_bootclasspath_fragment { |
| 1039 | name: "mybootclasspathfragment", |
| 1040 | prefer: false, |
| 1041 | visibility: ["//visibility:public"], |
| 1042 | apex_available: ["myapex"], |
| 1043 | contents: [ |
| 1044 | "mysdklibrary", |
| 1045 | "mynewsdklibrary", |
| 1046 | ], |
| 1047 | hidden_api: { |
| 1048 | annotation_flags: "hiddenapi/annotation-flags.csv", |
| 1049 | metadata: "hiddenapi/metadata.csv", |
| 1050 | index: "hiddenapi/index.csv", |
| 1051 | signature_patterns: "hiddenapi/signature-patterns.csv", |
| 1052 | filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv", |
| 1053 | filtered_flags: "hiddenapi/filtered-flags.csv", |
| 1054 | }, |
| 1055 | } |
| 1056 | |
| 1057 | java_sdk_library_import { |
| 1058 | name: "mysdklibrary", |
| 1059 | prefer: false, |
| 1060 | visibility: ["//visibility:public"], |
| 1061 | apex_available: ["myapex"], |
| 1062 | shared_library: false, |
| 1063 | public: { |
| 1064 | jars: ["sdk_library/public/mysdklibrary-stubs.jar"], |
| 1065 | stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"], |
| 1066 | current_api: "sdk_library/public/mysdklibrary.txt", |
| 1067 | removed_api: "sdk_library/public/mysdklibrary-removed.txt", |
| 1068 | sdk_version: "current", |
| 1069 | }, |
| 1070 | } |
| 1071 | |
| 1072 | java_sdk_library_import { |
| 1073 | name: "mynewsdklibrary", |
| 1074 | prefer: false, |
| 1075 | visibility: ["//visibility:public"], |
| 1076 | apex_available: ["myapex"], |
| 1077 | shared_library: true, |
| 1078 | compile_dex: true, |
| 1079 | permitted_packages: ["mynewsdklibrary"], |
| 1080 | public: { |
| 1081 | jars: ["sdk_library/public/mynewsdklibrary-stubs.jar"], |
| 1082 | stub_srcs: ["sdk_library/public/mynewsdklibrary_stub_sources"], |
| 1083 | current_api: "sdk_library/public/mynewsdklibrary.txt", |
| 1084 | removed_api: "sdk_library/public/mynewsdklibrary-removed.txt", |
| 1085 | sdk_version: "current", |
| 1086 | }, |
| 1087 | } |
| 1088 | ` |
| 1089 | expectedCopyRules := ` |
| 1090 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv |
| 1091 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv |
| 1092 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv |
| 1093 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv |
| 1094 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv |
| 1095 | .intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv |
| 1096 | .intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar |
| 1097 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt |
| 1098 | .intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt |
| 1099 | .intermediates/mynewsdklibrary.stubs/android_common/javac/mynewsdklibrary.stubs.jar -> sdk_library/public/mynewsdklibrary-stubs.jar |
| 1100 | .intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_api.txt -> sdk_library/public/mynewsdklibrary.txt |
| 1101 | .intermediates/mynewsdklibrary.stubs.source/android_common/metalava/mynewsdklibrary.stubs.source_removed.txt -> sdk_library/public/mynewsdklibrary-removed.txt |
| 1102 | ` |
| 1103 | |
| 1104 | // On tiramisu the stub flags should be generated from both mynewsdklibrary and mysdklibrary as |
| 1105 | // they are both part of the snapshot. |
| 1106 | expectedStubFlagsInputs := []string{ |
| 1107 | "out/soong/.intermediates/mynewsdklibrary.stubs/android_common/dex/mynewsdklibrary.stubs.jar", |
| 1108 | "out/soong/.intermediates/mynewsdklibrary/android_common/aligned/mynewsdklibrary.jar", |
| 1109 | "out/soong/.intermediates/mysdklibrary.stubs/android_common/dex/mysdklibrary.stubs.jar", |
| 1110 | "out/soong/.intermediates/mysdklibrary/android_common/aligned/mysdklibrary.jar", |
| 1111 | } |
| 1112 | |
| 1113 | testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "Tiramisu", |
| 1114 | expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "") |
| 1115 | }) |
| 1116 | } |