Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +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 apex |
| 16 | |
| 17 | import ( |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 18 | "fmt" |
Jiakai Zhang | 7d3c9e0 | 2021-12-13 17:19:05 +0000 | [diff] [blame] | 19 | "path" |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 20 | "sort" |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 21 | "strings" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 22 | "testing" |
| 23 | |
| 24 | "android/soong/android" |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 25 | "android/soong/dexpreopt" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 26 | "android/soong/java" |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 27 | |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 28 | "github.com/google/blueprint/proptools" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 29 | ) |
| 30 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 31 | // Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART |
| 32 | // bootclasspath_fragment requires modules from the ART apex. |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 33 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 34 | var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers( |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 35 | java.PrepareForTestWithDexpreopt, |
| 36 | PrepareForTestWithApexBuildComponents, |
| 37 | ) |
| 38 | |
| 39 | // Some additional files needed for the art apex. |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 40 | var prepareForTestWithArtApex = android.GroupFixturePreparers( |
| 41 | android.FixtureMergeMockFs(android.MockFS{ |
| 42 | "com.android.art.avbpubkey": nil, |
| 43 | "com.android.art.pem": nil, |
| 44 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 45 | }), |
| 46 | dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"), |
| 47 | ) |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 48 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 49 | func TestBootclasspathFragments(t *testing.T) { |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 50 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 51 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 52 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 53 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"), |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 54 | prepareForTestWithArtApex, |
| 55 | |
| 56 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 57 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 58 | ).RunTestWithBp(t, ` |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 59 | java_sdk_library { |
| 60 | name: "foo", |
| 61 | srcs: ["b.java"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | java_library { |
| 65 | name: "bar", |
| 66 | srcs: ["b.java"], |
| 67 | installable: true, |
| 68 | } |
| 69 | |
| 70 | apex { |
| 71 | name: "com.android.art", |
| 72 | key: "com.android.art.key", |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 73 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 74 | updatable: false, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | apex_key { |
| 78 | name: "com.android.art.key", |
| 79 | public_key: "com.android.art.avbpubkey", |
| 80 | private_key: "com.android.art.pem", |
| 81 | } |
| 82 | |
| 83 | java_library { |
| 84 | name: "baz", |
| 85 | apex_available: [ |
| 86 | "com.android.art", |
| 87 | ], |
| 88 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 89 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | java_library { |
| 93 | name: "quuz", |
| 94 | apex_available: [ |
| 95 | "com.android.art", |
| 96 | ], |
| 97 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 98 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 99 | } |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 100 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 101 | bootclasspath_fragment { |
| 102 | name: "art-bootclasspath-fragment", |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 103 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 104 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 105 | contents: ["baz", "quuz"], |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 106 | apex_available: [ |
| 107 | "com.android.art", |
| 108 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 109 | hidden_api: { |
| 110 | split_packages: ["*"], |
| 111 | }, |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 112 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 113 | `, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 114 | ) |
| 115 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 116 | // Make sure that the art-bootclasspath-fragment is using the correct configuration. |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 117 | checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000", |
| 118 | "com.android.art:baz,com.android.art:quuz", ` |
Jeongik Cha | 4753b39 | 2023-04-19 23:25:41 +0900 | [diff] [blame] | 119 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art |
| 120 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat |
| 121 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex |
| 122 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art |
| 123 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat |
| 124 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex |
| 125 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art |
| 126 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat |
| 127 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex |
| 128 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art |
| 129 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat |
| 130 | dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 131 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 134 | func TestBootclasspathFragments_FragmentDependency(t *testing.T) { |
| 135 | result := android.GroupFixturePreparers( |
| 136 | prepareForTestWithBootclasspathFragment, |
| 137 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 138 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 139 | java.FixtureConfigureApexBootJars("someapex:foo", "someapex:bar"), |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 140 | prepareForTestWithArtApex, |
| 141 | |
| 142 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 143 | java.FixtureWithLastReleaseApis("foo", "baz"), |
| 144 | ).RunTestWithBp(t, ` |
| 145 | java_sdk_library { |
| 146 | name: "foo", |
| 147 | srcs: ["b.java"], |
| 148 | shared_library: false, |
| 149 | public: { |
| 150 | enabled: true, |
| 151 | }, |
| 152 | system: { |
| 153 | enabled: true, |
| 154 | }, |
| 155 | } |
| 156 | |
| 157 | java_library { |
| 158 | name: "bar", |
| 159 | srcs: ["b.java"], |
| 160 | installable: true, |
| 161 | } |
| 162 | |
| 163 | apex { |
| 164 | name: "com.android.art", |
| 165 | key: "com.android.art.key", |
| 166 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 167 | updatable: false, |
| 168 | } |
| 169 | |
| 170 | apex_key { |
| 171 | name: "com.android.art.key", |
| 172 | public_key: "com.android.art.avbpubkey", |
| 173 | private_key: "com.android.art.pem", |
| 174 | } |
| 175 | |
| 176 | java_sdk_library { |
| 177 | name: "baz", |
| 178 | apex_available: [ |
| 179 | "com.android.art", |
| 180 | ], |
| 181 | srcs: ["b.java"], |
| 182 | shared_library: false, |
| 183 | public: { |
| 184 | enabled: true, |
| 185 | }, |
| 186 | system: { |
| 187 | enabled: true, |
| 188 | }, |
| 189 | test: { |
| 190 | enabled: true, |
| 191 | }, |
| 192 | } |
| 193 | |
| 194 | java_library { |
| 195 | name: "quuz", |
| 196 | apex_available: [ |
| 197 | "com.android.art", |
| 198 | ], |
| 199 | srcs: ["b.java"], |
| 200 | compile_dex: true, |
| 201 | } |
| 202 | |
| 203 | bootclasspath_fragment { |
| 204 | name: "art-bootclasspath-fragment", |
| 205 | image_name: "art", |
| 206 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 207 | contents: ["baz", "quuz"], |
| 208 | apex_available: [ |
| 209 | "com.android.art", |
| 210 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 211 | hidden_api: { |
| 212 | split_packages: ["*"], |
| 213 | }, |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | bootclasspath_fragment { |
| 217 | name: "other-bootclasspath-fragment", |
| 218 | contents: ["foo", "bar"], |
| 219 | fragments: [ |
| 220 | { |
| 221 | apex: "com.android.art", |
| 222 | module: "art-bootclasspath-fragment", |
| 223 | }, |
| 224 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 225 | hidden_api: { |
| 226 | split_packages: ["*"], |
| 227 | }, |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 228 | } |
| 229 | `, |
| 230 | ) |
| 231 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 232 | checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) { |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 233 | t.Helper() |
Paul Duffin | 280a31a | 2021-06-27 20:28:29 +0100 | [diff] [blame] | 234 | paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope) |
| 235 | android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // Check stub dex paths exported by art. |
| 239 | artFragment := result.Module("art-bootclasspath-fragment", "android_common") |
| 240 | artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 241 | |
| 242 | bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar" |
| 243 | bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar" |
| 244 | bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar" |
| 245 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 246 | checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs) |
| 247 | checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs) |
| 248 | checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs) |
| 249 | checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 250 | |
| 251 | // Check stub dex paths exported by other. |
| 252 | otherFragment := result.Module("other-bootclasspath-fragment", "android_common") |
| 253 | otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 254 | |
| 255 | fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar" |
| 256 | fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar" |
| 257 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 258 | checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs) |
| 259 | checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs) |
| 260 | checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs) |
| 261 | checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 262 | } |
| 263 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 264 | func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) { |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 265 | t.Helper() |
| 266 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 267 | bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 268 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 269 | bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 270 | modules := bootclasspathFragmentInfo.Modules() |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 271 | android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 272 | |
| 273 | // Get a list of all the paths in the boot image sorted by arch type. |
| 274 | allPaths := []string{} |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 275 | bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 276 | for _, archType := range android.ArchTypeList() { |
| 277 | if paths, ok := bootImageFilesByArchType[archType]; ok { |
| 278 | for _, path := range paths { |
| 279 | allPaths = append(allPaths, android.NormalizePathForTesting(path)) |
| 280 | } |
| 281 | } |
| 282 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 283 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 284 | android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n")) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 285 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 286 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 287 | func TestBootclasspathFragmentInArtApex(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 288 | commonPreparer := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 289 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 290 | prepareForTestWithArtApex, |
| 291 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 292 | android.FixtureWithRootAndroidBp(` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 293 | apex { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 294 | name: "com.android.art", |
| 295 | key: "com.android.art.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 296 | bootclasspath_fragments: [ |
| 297 | "mybootclasspathfragment", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 298 | ], |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 299 | // bar (like foo) should be transitively included in this apex because it is part of the |
Jooyung Han | 862c0d6 | 2022-12-21 10:15:37 +0900 | [diff] [blame] | 300 | // mybootclasspathfragment bootclasspath_fragment. |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 301 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | apex_key { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 305 | name: "com.android.art.key", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 306 | public_key: "testkey.avbpubkey", |
| 307 | private_key: "testkey.pem", |
| 308 | } |
| 309 | |
| 310 | java_library { |
| 311 | name: "foo", |
| 312 | srcs: ["b.java"], |
| 313 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 314 | apex_available: [ |
| 315 | "com.android.art", |
| 316 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | java_library { |
| 320 | name: "bar", |
| 321 | srcs: ["b.java"], |
| 322 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 323 | apex_available: [ |
| 324 | "com.android.art", |
| 325 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 328 | java_import { |
| 329 | name: "foo", |
| 330 | jars: ["foo.jar"], |
| 331 | apex_available: [ |
| 332 | "com.android.art", |
| 333 | ], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 334 | compile_dex: true, |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | java_import { |
| 338 | name: "bar", |
| 339 | jars: ["bar.jar"], |
| 340 | apex_available: [ |
| 341 | "com.android.art", |
| 342 | ], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 343 | compile_dex: true, |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 344 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 345 | `), |
| 346 | ) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 347 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 348 | contentsInsert := func(contents []string) string { |
| 349 | insert := "" |
| 350 | if contents != nil { |
| 351 | insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`)) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 352 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 353 | return insert |
| 354 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 355 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 356 | addSource := func(contents ...string) android.FixturePreparer { |
| 357 | text := fmt.Sprintf(` |
| 358 | bootclasspath_fragment { |
| 359 | name: "mybootclasspathfragment", |
| 360 | image_name: "art", |
| 361 | %s |
| 362 | apex_available: [ |
| 363 | "com.android.art", |
| 364 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 365 | hidden_api: { |
| 366 | split_packages: ["*"], |
| 367 | }, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 368 | } |
| 369 | `, contentsInsert(contents)) |
| 370 | |
| 371 | return android.FixtureAddTextFile("art/build/boot/Android.bp", text) |
| 372 | } |
| 373 | |
| 374 | addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer { |
| 375 | text := fmt.Sprintf(` |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 376 | prebuilt_apex { |
| 377 | name: "com.android.art", |
| 378 | arch: { |
| 379 | arm64: { |
| 380 | src: "com.android.art-arm64.apex", |
| 381 | }, |
| 382 | arm: { |
| 383 | src: "com.android.art-arm.apex", |
| 384 | }, |
| 385 | }, |
| 386 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
| 387 | } |
| 388 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 389 | prebuilt_bootclasspath_fragment { |
| 390 | name: "mybootclasspathfragment", |
| 391 | image_name: "art", |
| 392 | %s |
| 393 | prefer: %t, |
| 394 | apex_available: [ |
| 395 | "com.android.art", |
| 396 | ], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 397 | hidden_api: { |
| 398 | annotation_flags: "mybootclasspathfragment/annotation-flags.csv", |
| 399 | metadata: "mybootclasspathfragment/metadata.csv", |
| 400 | index: "mybootclasspathfragment/index.csv", |
| 401 | stub_flags: "mybootclasspathfragment/stub-flags.csv", |
| 402 | all_flags: "mybootclasspathfragment/all-flags.csv", |
| 403 | }, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 404 | } |
| 405 | `, contentsInsert(contents), prefer) |
| 406 | return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text) |
| 407 | } |
| 408 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 409 | t.Run("boot image files from source", func(t *testing.T) { |
| 410 | result := android.GroupFixturePreparers( |
| 411 | commonPreparer, |
| 412 | |
| 413 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 414 | // bootclasspath_fragment's contents property. |
| 415 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 416 | addSource("foo", "bar"), |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 417 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 418 | ).RunTest(t) |
| 419 | |
| 420 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 421 | "etc/boot-image.prof", |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 422 | "etc/classpaths/bootclasspath.pb", |
| 423 | "javalib/arm/boot.art", |
| 424 | "javalib/arm/boot.oat", |
| 425 | "javalib/arm/boot.vdex", |
| 426 | "javalib/arm/boot-bar.art", |
| 427 | "javalib/arm/boot-bar.oat", |
| 428 | "javalib/arm/boot-bar.vdex", |
| 429 | "javalib/arm64/boot.art", |
| 430 | "javalib/arm64/boot.oat", |
| 431 | "javalib/arm64/boot.vdex", |
| 432 | "javalib/arm64/boot-bar.art", |
| 433 | "javalib/arm64/boot-bar.oat", |
| 434 | "javalib/arm64/boot-bar.vdex", |
| 435 | "javalib/bar.jar", |
| 436 | "javalib/foo.jar", |
| 437 | }) |
| 438 | |
| 439 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 440 | `com.android.art.key`, |
| 441 | `mybootclasspathfragment`, |
| 442 | }) |
| 443 | |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 444 | // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. |
| 445 | ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 446 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 447 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 448 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 449 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 450 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 451 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 452 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 453 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 454 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 455 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 456 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 457 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 458 | }) |
| 459 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 460 | // Make sure that the source bootclasspath_fragment copies its dex files to the predefined |
| 461 | // locations for the art image. |
| 462 | module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 463 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
| 464 | }) |
| 465 | |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 466 | t.Run("boot image files from source no boot image in apex", func(t *testing.T) { |
| 467 | result := android.GroupFixturePreparers( |
| 468 | commonPreparer, |
| 469 | |
| 470 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 471 | // bootclasspath_fragment's contents property. |
| 472 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 473 | addSource("foo", "bar"), |
| 474 | java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), |
| 475 | ).RunTest(t) |
| 476 | |
| 477 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 478 | "etc/boot-image.prof", |
| 479 | "etc/classpaths/bootclasspath.pb", |
| 480 | "javalib/bar.jar", |
| 481 | "javalib/foo.jar", |
| 482 | }) |
| 483 | |
| 484 | ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 485 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 486 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 487 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 488 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 489 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 490 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 491 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 492 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 493 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 494 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 495 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 496 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 497 | }) |
| 498 | }) |
| 499 | |
Jiakai Zhang | bc698cd | 2023-05-08 16:28:38 +0000 | [diff] [blame] | 500 | t.Run("generate boot image profile even if dexpreopt is disabled", func(t *testing.T) { |
| 501 | result := android.GroupFixturePreparers( |
| 502 | commonPreparer, |
| 503 | |
| 504 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 505 | // bootclasspath_fragment's contents property. |
| 506 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 507 | addSource("foo", "bar"), |
| 508 | java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), |
| 509 | dexpreopt.FixtureDisableDexpreoptBootImages(true), |
| 510 | ).RunTest(t) |
| 511 | |
| 512 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 513 | "etc/boot-image.prof", |
| 514 | "etc/classpaths/bootclasspath.pb", |
| 515 | "javalib/bar.jar", |
| 516 | "javalib/foo.jar", |
| 517 | }) |
| 518 | }) |
| 519 | |
Jiakai Zhang | 7d3c9e0 | 2021-12-13 17:19:05 +0000 | [diff] [blame] | 520 | t.Run("boot image disable generate profile", func(t *testing.T) { |
| 521 | result := android.GroupFixturePreparers( |
| 522 | commonPreparer, |
| 523 | |
| 524 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 525 | // bootclasspath_fragment's contents property. |
| 526 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 527 | addSource("foo", "bar"), |
| 528 | dexpreopt.FixtureDisableGenerateProfile(true), |
| 529 | ).RunTest(t) |
| 530 | |
| 531 | files := getFiles(t, result.TestContext, "com.android.art", "android_common_com.android.art_image") |
| 532 | for _, file := range files { |
| 533 | matched, _ := path.Match("etc/boot-image.prof", file.path) |
| 534 | android.AssertBoolEquals(t, "\"etc/boot-image.prof\" should not be in the APEX", matched, false) |
| 535 | } |
| 536 | }) |
| 537 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 538 | t.Run("boot image files with preferred prebuilt", func(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 539 | result := android.GroupFixturePreparers( |
| 540 | commonPreparer, |
| 541 | |
| 542 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 543 | // bootclasspath_fragment's contents property. |
| 544 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 545 | addSource("foo", "bar"), |
| 546 | |
| 547 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 548 | addPrebuilt(true, "foo", "bar"), |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 549 | |
| 550 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 551 | ).RunTest(t) |
| 552 | |
Jiakai Zhang | ebf48bf | 2023-02-10 01:51:53 +0800 | [diff] [blame] | 553 | ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{ |
Jiakai Zhang | 49b1eb6 | 2021-11-26 18:09:27 +0000 | [diff] [blame] | 554 | "etc/boot-image.prof", |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 555 | "javalib/arm/boot.art", |
| 556 | "javalib/arm/boot.oat", |
| 557 | "javalib/arm/boot.vdex", |
| 558 | "javalib/arm/boot-bar.art", |
| 559 | "javalib/arm/boot-bar.oat", |
| 560 | "javalib/arm/boot-bar.vdex", |
| 561 | "javalib/arm64/boot.art", |
| 562 | "javalib/arm64/boot.oat", |
| 563 | "javalib/arm64/boot.vdex", |
| 564 | "javalib/arm64/boot-bar.art", |
| 565 | "javalib/arm64/boot-bar.oat", |
| 566 | "javalib/arm64/boot-bar.vdex", |
| 567 | "javalib/bar.jar", |
| 568 | "javalib/foo.jar", |
| 569 | }) |
| 570 | |
| 571 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 572 | `com.android.art.key`, |
| 573 | `mybootclasspathfragment`, |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 574 | `prebuilt_com.android.art`, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 575 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 576 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 577 | // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. |
| 578 | ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 579 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 580 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 581 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 582 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 583 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 584 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 585 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 586 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 587 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 588 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 589 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 590 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 591 | }) |
| 592 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 593 | // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined |
| 594 | // locations for the art image. |
| 595 | module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art") |
| 596 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 597 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 598 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 599 | t.Run("boot image files from preferred prebuilt no boot image in apex", func(t *testing.T) { |
| 600 | result := android.GroupFixturePreparers( |
| 601 | commonPreparer, |
| 602 | |
| 603 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 604 | // bootclasspath_fragment's contents property. |
| 605 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 606 | addSource("foo", "bar"), |
| 607 | |
| 608 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 609 | addPrebuilt(true, "foo", "bar"), |
| 610 | |
| 611 | java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), |
| 612 | ).RunTest(t) |
| 613 | |
Jiakai Zhang | ebf48bf | 2023-02-10 01:51:53 +0800 | [diff] [blame] | 614 | ensureExactDeapexedContents(t, result.TestContext, "com.android.art", "android_common", []string{ |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 615 | "etc/boot-image.prof", |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 616 | "javalib/bar.jar", |
| 617 | "javalib/foo.jar", |
| 618 | }) |
| 619 | |
| 620 | ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 621 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 622 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 623 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 624 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 625 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 626 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 627 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 628 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 629 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 630 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 631 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 632 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 633 | }) |
| 634 | }) |
| 635 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 636 | t.Run("source with inconsistency between config and contents", func(t *testing.T) { |
| 637 | android.GroupFixturePreparers( |
| 638 | commonPreparer, |
| 639 | |
| 640 | // Create an inconsistency between the ArtApexJars configuration and the art source |
| 641 | // bootclasspath_fragment module's contents property. |
| 642 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 643 | addSource("foo", "bar"), |
| 644 | ). |
| 645 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 646 | RunTest(t) |
| 647 | }) |
| 648 | |
| 649 | t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 650 | android.GroupFixturePreparers( |
| 651 | commonPreparer, |
| 652 | |
| 653 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 654 | // prebuilt_bootclasspath_fragment module's contents property. |
| 655 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 656 | addPrebuilt(false, "foo", "bar"), |
| 657 | ). |
| 658 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 659 | RunTest(t) |
| 660 | }) |
| 661 | |
| 662 | t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 663 | android.GroupFixturePreparers( |
| 664 | commonPreparer, |
| 665 | |
| 666 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 667 | // prebuilt_bootclasspath_fragment module's contents property. |
| 668 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 669 | addPrebuilt(true, "foo", "bar"), |
| 670 | |
| 671 | // Source contents property is consistent with the config. |
| 672 | addSource("foo"), |
| 673 | ). |
| 674 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 675 | RunTest(t) |
| 676 | }) |
| 677 | |
| 678 | t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 679 | android.GroupFixturePreparers( |
| 680 | commonPreparer, |
| 681 | |
| 682 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 683 | // prebuilt_bootclasspath_fragment module's contents property. |
| 684 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 685 | addPrebuilt(false, "foo", "bar"), |
| 686 | |
| 687 | // Source contents property is consistent with the config. |
| 688 | addSource("foo"), |
| 689 | |
| 690 | // This should pass because while the prebuilt is inconsistent with the configuration it is |
| 691 | // not actually used. |
| 692 | ).RunTest(t) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 693 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 696 | func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 697 | preparers := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 698 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 699 | prepareForTestWithArtApex, |
| 700 | |
| 701 | android.FixtureMergeMockFs(android.MockFS{ |
| 702 | "com.android.art-arm64.apex": nil, |
| 703 | "com.android.art-arm.apex": nil, |
| 704 | }), |
| 705 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 706 | // Configure some libraries in the art bootclasspath_fragment. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 707 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 708 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 709 | ) |
| 710 | |
| 711 | bp := ` |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 712 | prebuilt_apex { |
| 713 | name: "com.android.art", |
| 714 | arch: { |
| 715 | arm64: { |
| 716 | src: "com.android.art-arm64.apex", |
| 717 | }, |
| 718 | arm: { |
| 719 | src: "com.android.art-arm.apex", |
| 720 | }, |
| 721 | }, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 722 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | java_import { |
| 726 | name: "foo", |
| 727 | jars: ["foo.jar"], |
| 728 | apex_available: [ |
| 729 | "com.android.art", |
| 730 | ], |
| 731 | } |
| 732 | |
| 733 | java_import { |
| 734 | name: "bar", |
| 735 | jars: ["bar.jar"], |
| 736 | apex_available: [ |
| 737 | "com.android.art", |
| 738 | ], |
| 739 | } |
| 740 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 741 | prebuilt_bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 742 | name: "mybootclasspathfragment", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 743 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 744 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 745 | contents: ["foo", "bar"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 746 | apex_available: [ |
| 747 | "com.android.art", |
| 748 | ], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 749 | hidden_api: { |
| 750 | annotation_flags: "mybootclasspathfragment/annotation-flags.csv", |
| 751 | metadata: "mybootclasspathfragment/metadata.csv", |
| 752 | index: "mybootclasspathfragment/index.csv", |
| 753 | stub_flags: "mybootclasspathfragment/stub-flags.csv", |
| 754 | all_flags: "mybootclasspathfragment/all-flags.csv", |
| 755 | }, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 756 | } |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 757 | |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 758 | // A prebuilt apex with the same apex_name that shouldn't interfere when it isn't enabled. |
| 759 | prebuilt_apex { |
| 760 | name: "com.mycompany.android.art", |
| 761 | apex_name: "com.android.art", |
| 762 | %s |
| 763 | src: "com.mycompany.android.art.apex", |
| 764 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
| 765 | } |
| 766 | ` |
| 767 | |
| 768 | t.Run("disabled alternative APEX", func(t *testing.T) { |
| 769 | result := preparers.RunTestWithBp(t, fmt.Sprintf(bp, "enabled: false,")) |
| 770 | |
| 771 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ |
| 772 | `com.android.art.apex.selector`, |
| 773 | `prebuilt_mybootclasspathfragment`, |
| 774 | }) |
| 775 | |
| 776 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{ |
| 777 | `com.android.art.deapexer`, |
| 778 | `dex2oatd`, |
| 779 | `prebuilt_bar`, |
| 780 | `prebuilt_foo`, |
| 781 | }) |
| 782 | |
| 783 | module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art") |
| 784 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
| 785 | |
| 786 | // Check that the right deapexer module was chosen for a boot image. |
Jeongik Cha | 4753b39 | 2023-04-19 23:25:41 +0900 | [diff] [blame] | 787 | param := module.Output("out/soong/dexpreopt_arm64/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art") |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 788 | android.AssertStringDoesContain(t, "didn't find the expected deapexer in the input path", param.Input.String(), "/com.android.art.deapexer") |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 789 | }) |
| 790 | |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 791 | t.Run("enabled alternative APEX", func(t *testing.T) { |
| 792 | preparers.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 793 | "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.art and com.mycompany.android.art")). |
| 794 | RunTestWithBp(t, fmt.Sprintf(bp, "")) |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 795 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | // checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the |
| 799 | // predefined locations of boot dex jars used as inputs for the ART boot image. |
| 800 | func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) { |
| 801 | t.Helper() |
| 802 | bootJarLocations := []string{} |
| 803 | for _, output := range module.AllOutputs() { |
| 804 | output = android.StringRelativeToTop(config, output) |
Jeongik Cha | 4753b39 | 2023-04-19 23:25:41 +0900 | [diff] [blame] | 805 | if strings.HasPrefix(output, "out/soong/dexpreopt_arm64/dex_artjars_input/") { |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 806 | bootJarLocations = append(bootJarLocations, output) |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | sort.Strings(bootJarLocations) |
| 811 | expected := []string{} |
| 812 | for _, m := range modules { |
Jeongik Cha | 4753b39 | 2023-04-19 23:25:41 +0900 | [diff] [blame] | 813 | expected = append(expected, fmt.Sprintf("out/soong/dexpreopt_arm64/dex_artjars_input/%s.jar", m)) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 814 | } |
| 815 | sort.Strings(expected) |
| 816 | |
| 817 | android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations) |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 820 | func TestBootclasspathFragmentContentsNoName(t *testing.T) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 821 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 822 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 823 | prepareForTestWithMyapex, |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 824 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 825 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 826 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 827 | // is disabled. |
| 828 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 829 | |
| 830 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 831 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 832 | ).RunTestWithBp(t, ` |
| 833 | apex { |
| 834 | name: "myapex", |
| 835 | key: "myapex.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 836 | bootclasspath_fragments: [ |
| 837 | "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 838 | ], |
| 839 | updatable: false, |
| 840 | } |
| 841 | |
| 842 | apex_key { |
| 843 | name: "myapex.key", |
| 844 | public_key: "testkey.avbpubkey", |
| 845 | private_key: "testkey.pem", |
| 846 | } |
| 847 | |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 848 | java_sdk_library { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 849 | name: "foo", |
| 850 | srcs: ["b.java"], |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 851 | shared_library: false, |
| 852 | public: {enabled: true}, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 853 | apex_available: [ |
| 854 | "myapex", |
| 855 | ], |
| 856 | } |
| 857 | |
| 858 | java_library { |
| 859 | name: "bar", |
| 860 | srcs: ["b.java"], |
| 861 | installable: true, |
| 862 | apex_available: [ |
| 863 | "myapex", |
| 864 | ], |
| 865 | } |
| 866 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 867 | bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 868 | name: "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 869 | contents: [ |
| 870 | "foo", |
| 871 | "bar", |
| 872 | ], |
| 873 | apex_available: [ |
| 874 | "myapex", |
| 875 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 876 | hidden_api: { |
| 877 | split_packages: ["*"], |
| 878 | }, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 879 | } |
| 880 | `) |
| 881 | |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 882 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 883 | // This does not include art, oat or vdex files as they are only included for the art boot |
| 884 | // image. |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 885 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 886 | "javalib/bar.jar", |
| 887 | "javalib/foo.jar", |
| 888 | }) |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 889 | |
| 890 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 891 | `myapex.key`, |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 892 | `mybootclasspathfragment`, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 893 | }) |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 894 | |
| 895 | apex := result.ModuleForTests("myapex", "android_common_myapex_image") |
| 896 | apexRule := apex.Rule("apexRule") |
| 897 | copyCommands := apexRule.Args["copy_commands"] |
| 898 | |
| 899 | // Make sure that the fragment provides the hidden API encoded dex jars to the APEX. |
| 900 | fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") |
| 901 | |
| 902 | info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 903 | |
| 904 | checkFragmentExportedDexJar := func(name string, expectedDexJar string) { |
| 905 | module := result.Module(name, "android_common_apex10000") |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 906 | dexJar, err := info.DexBootJarPathForContentModule(module) |
| 907 | if err != nil { |
| 908 | t.Error(err) |
| 909 | } |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 910 | android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar) |
| 911 | |
| 912 | expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name) |
| 913 | android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand) |
| 914 | } |
| 915 | |
Paul Duffin | 54c98f5 | 2021-05-15 08:54:30 +0100 | [diff] [blame] | 916 | checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar") |
| 917 | checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar") |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 918 | } |
| 919 | |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 920 | func getDexJarPath(result *android.TestResult, name string) string { |
| 921 | module := result.Module(name, "android_common") |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 922 | return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String() |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | // TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are |
| 926 | // passed to the hiddenapi list tool. |
| 927 | func TestBootclasspathFragment_HiddenAPIList(t *testing.T) { |
| 928 | result := android.GroupFixturePreparers( |
| 929 | prepareForTestWithBootclasspathFragment, |
| 930 | prepareForTestWithArtApex, |
| 931 | prepareForTestWithMyapex, |
| 932 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
| 933 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 934 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 935 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 936 | // is disabled. |
| 937 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 938 | |
| 939 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 940 | java.FixtureWithLastReleaseApis("foo", "quuz"), |
| 941 | ).RunTestWithBp(t, ` |
| 942 | apex { |
| 943 | name: "com.android.art", |
| 944 | key: "com.android.art.key", |
| 945 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 946 | updatable: false, |
| 947 | } |
| 948 | |
| 949 | apex_key { |
| 950 | name: "com.android.art.key", |
| 951 | public_key: "com.android.art.avbpubkey", |
| 952 | private_key: "com.android.art.pem", |
| 953 | } |
| 954 | |
| 955 | java_library { |
| 956 | name: "baz", |
| 957 | apex_available: [ |
| 958 | "com.android.art", |
| 959 | ], |
| 960 | srcs: ["b.java"], |
| 961 | compile_dex: true, |
| 962 | } |
| 963 | |
| 964 | java_sdk_library { |
| 965 | name: "quuz", |
| 966 | apex_available: [ |
| 967 | "com.android.art", |
| 968 | ], |
| 969 | srcs: ["b.java"], |
| 970 | compile_dex: true, |
| 971 | public: {enabled: true}, |
| 972 | system: {enabled: true}, |
| 973 | test: {enabled: true}, |
| 974 | module_lib: {enabled: true}, |
| 975 | } |
| 976 | |
| 977 | bootclasspath_fragment { |
| 978 | name: "art-bootclasspath-fragment", |
| 979 | image_name: "art", |
| 980 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 981 | contents: ["baz", "quuz"], |
| 982 | apex_available: [ |
| 983 | "com.android.art", |
| 984 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 985 | hidden_api: { |
| 986 | split_packages: ["*"], |
| 987 | }, |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | apex { |
| 991 | name: "myapex", |
| 992 | key: "myapex.key", |
| 993 | bootclasspath_fragments: [ |
| 994 | "mybootclasspathfragment", |
| 995 | ], |
| 996 | updatable: false, |
| 997 | } |
| 998 | |
| 999 | apex_key { |
| 1000 | name: "myapex.key", |
| 1001 | public_key: "testkey.avbpubkey", |
| 1002 | private_key: "testkey.pem", |
| 1003 | } |
| 1004 | |
| 1005 | java_sdk_library { |
| 1006 | name: "foo", |
| 1007 | srcs: ["b.java"], |
| 1008 | shared_library: false, |
| 1009 | public: {enabled: true}, |
| 1010 | apex_available: [ |
| 1011 | "myapex", |
| 1012 | ], |
| 1013 | } |
| 1014 | |
| 1015 | java_library { |
| 1016 | name: "bar", |
| 1017 | srcs: ["b.java"], |
| 1018 | installable: true, |
| 1019 | apex_available: [ |
| 1020 | "myapex", |
| 1021 | ], |
| 1022 | } |
| 1023 | |
| 1024 | bootclasspath_fragment { |
| 1025 | name: "mybootclasspathfragment", |
| 1026 | contents: [ |
| 1027 | "foo", |
| 1028 | "bar", |
| 1029 | ], |
| 1030 | apex_available: [ |
| 1031 | "myapex", |
| 1032 | ], |
| 1033 | fragments: [ |
| 1034 | { |
| 1035 | apex: "com.android.art", |
| 1036 | module: "art-bootclasspath-fragment", |
| 1037 | }, |
| 1038 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1039 | hidden_api: { |
| 1040 | split_packages: ["*"], |
| 1041 | }, |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1042 | } |
| 1043 | `) |
| 1044 | |
| 1045 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1046 | "art-bootclasspath-fragment", |
| 1047 | "bar", |
| 1048 | "dex2oatd", |
| 1049 | "foo", |
| 1050 | }) |
| 1051 | |
| 1052 | fooStubs := getDexJarPath(result, "foo.stubs") |
| 1053 | quuzPublicStubs := getDexJarPath(result, "quuz.stubs") |
| 1054 | quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system") |
| 1055 | quuzTestStubs := getDexJarPath(result, "quuz.stubs.test") |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 1056 | quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib") |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1057 | |
| 1058 | // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags. |
| 1059 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1060 | |
| 1061 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1062 | command := rule.RuleParams.Command |
| 1063 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1064 | |
| 1065 | // Make sure that the quuz stubs are available for resolving references from the implementation |
| 1066 | // boot dex jars provided by this module. |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 1067 | android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs) |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1068 | |
| 1069 | // Make sure that the quuz stubs are available for resolving references from the different API |
| 1070 | // stubs provided by this module. |
| 1071 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs) |
| 1072 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs) |
| 1073 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs) |
| 1074 | } |
| 1075 | |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1076 | // TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting |
| 1077 | // additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be |
| 1078 | // added to the hiddenapi list tool. |
| 1079 | func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) { |
| 1080 | result := android.GroupFixturePreparers( |
| 1081 | prepareForTestWithBootclasspathFragment, |
| 1082 | prepareForTestWithArtApex, |
| 1083 | prepareForTestWithMyapex, |
| 1084 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 1085 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 1086 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1087 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 1088 | // is disabled. |
| 1089 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 1090 | |
| 1091 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 1092 | java.FixtureWithLastReleaseApis("foo", "android-non-updatable"), |
| 1093 | ).RunTestWithBp(t, ` |
| 1094 | java_sdk_library { |
| 1095 | name: "android-non-updatable", |
| 1096 | srcs: ["b.java"], |
| 1097 | compile_dex: true, |
| 1098 | public: { |
| 1099 | enabled: true, |
| 1100 | }, |
| 1101 | system: { |
| 1102 | enabled: true, |
| 1103 | }, |
| 1104 | test: { |
| 1105 | enabled: true, |
| 1106 | }, |
| 1107 | module_lib: { |
| 1108 | enabled: true, |
| 1109 | }, |
| 1110 | } |
| 1111 | |
| 1112 | apex { |
| 1113 | name: "com.android.art", |
| 1114 | key: "com.android.art.key", |
| 1115 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1116 | updatable: false, |
| 1117 | } |
| 1118 | |
| 1119 | apex_key { |
| 1120 | name: "com.android.art.key", |
| 1121 | public_key: "com.android.art.avbpubkey", |
| 1122 | private_key: "com.android.art.pem", |
| 1123 | } |
| 1124 | |
| 1125 | java_library { |
| 1126 | name: "baz", |
| 1127 | apex_available: [ |
| 1128 | "com.android.art", |
| 1129 | ], |
| 1130 | srcs: ["b.java"], |
| 1131 | compile_dex: true, |
| 1132 | } |
| 1133 | |
| 1134 | java_library { |
| 1135 | name: "quuz", |
| 1136 | apex_available: [ |
| 1137 | "com.android.art", |
| 1138 | ], |
| 1139 | srcs: ["b.java"], |
| 1140 | compile_dex: true, |
| 1141 | } |
| 1142 | |
| 1143 | bootclasspath_fragment { |
| 1144 | name: "art-bootclasspath-fragment", |
| 1145 | image_name: "art", |
| 1146 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 1147 | contents: ["baz", "quuz"], |
| 1148 | apex_available: [ |
| 1149 | "com.android.art", |
| 1150 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1151 | hidden_api: { |
| 1152 | split_packages: ["*"], |
| 1153 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | apex { |
| 1157 | name: "myapex", |
| 1158 | key: "myapex.key", |
| 1159 | bootclasspath_fragments: [ |
| 1160 | "mybootclasspathfragment", |
| 1161 | ], |
| 1162 | updatable: false, |
| 1163 | } |
| 1164 | |
| 1165 | apex_key { |
| 1166 | name: "myapex.key", |
| 1167 | public_key: "testkey.avbpubkey", |
| 1168 | private_key: "testkey.pem", |
| 1169 | } |
| 1170 | |
| 1171 | java_sdk_library { |
| 1172 | name: "foo", |
| 1173 | srcs: ["b.java"], |
| 1174 | shared_library: false, |
| 1175 | public: {enabled: true}, |
| 1176 | apex_available: [ |
| 1177 | "myapex", |
| 1178 | ], |
| 1179 | } |
| 1180 | |
| 1181 | java_library { |
| 1182 | name: "bar", |
| 1183 | srcs: ["b.java"], |
| 1184 | installable: true, |
| 1185 | apex_available: [ |
| 1186 | "myapex", |
| 1187 | ], |
| 1188 | } |
| 1189 | |
| 1190 | bootclasspath_fragment { |
| 1191 | name: "mybootclasspathfragment", |
| 1192 | contents: [ |
| 1193 | "foo", |
| 1194 | "bar", |
| 1195 | ], |
| 1196 | apex_available: [ |
| 1197 | "myapex", |
| 1198 | ], |
| 1199 | additional_stubs: ["android-non-updatable"], |
| 1200 | fragments: [ |
| 1201 | { |
| 1202 | apex: "com.android.art", |
| 1203 | module: "art-bootclasspath-fragment", |
| 1204 | }, |
| 1205 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1206 | hidden_api: { |
| 1207 | split_packages: ["*"], |
| 1208 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1209 | } |
| 1210 | `) |
| 1211 | |
| 1212 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1213 | "android-non-updatable.stubs", |
| 1214 | "android-non-updatable.stubs.module_lib", |
| 1215 | "android-non-updatable.stubs.system", |
| 1216 | "android-non-updatable.stubs.test", |
| 1217 | "art-bootclasspath-fragment", |
| 1218 | "bar", |
| 1219 | "dex2oatd", |
| 1220 | "foo", |
| 1221 | }) |
| 1222 | |
| 1223 | nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs") |
| 1224 | nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system") |
| 1225 | nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test") |
| 1226 | nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib") |
| 1227 | |
| 1228 | // Make sure that the fragment uses the android-non-updatable modules when generating the hidden |
| 1229 | // API flags. |
| 1230 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1231 | |
| 1232 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1233 | command := rule.RuleParams.Command |
| 1234 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1235 | |
| 1236 | // Make sure that the module_lib non-updatable stubs are available for resolving references from |
| 1237 | // the implementation boot dex jars provided by this module. |
| 1238 | android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs) |
| 1239 | |
| 1240 | // Make sure that the appropriate non-updatable stubs are available for resolving references from |
| 1241 | // the different API stubs provided by this module. |
| 1242 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs) |
| 1243 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs) |
| 1244 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs) |
| 1245 | } |
| 1246 | |
| 1247 | // TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that |
| 1248 | // setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable |
| 1249 | // modules to be added to the hiddenapi list tool. |
| 1250 | func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) { |
| 1251 | result := android.GroupFixturePreparers( |
| 1252 | prepareForTestWithBootclasspathFragment, |
Jiakai Zhang | b95998b | 2023-05-11 16:39:27 +0100 | [diff] [blame^] | 1253 | java.PrepareForTestWithDexpreopt, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1254 | prepareForTestWithArtApex, |
| 1255 | prepareForTestWithMyapex, |
| 1256 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 1257 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 1258 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1259 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 1260 | // is disabled. |
| 1261 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 1262 | |
| 1263 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1264 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 1265 | }), |
| 1266 | |
| 1267 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 1268 | java.FixtureWithPrebuiltApis(map[string][]string{ |
| 1269 | "current": {"android-non-updatable"}, |
| 1270 | "30": {"foo"}, |
| 1271 | }), |
| 1272 | ).RunTestWithBp(t, ` |
| 1273 | apex { |
| 1274 | name: "com.android.art", |
| 1275 | key: "com.android.art.key", |
| 1276 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1277 | updatable: false, |
| 1278 | } |
| 1279 | |
| 1280 | apex_key { |
| 1281 | name: "com.android.art.key", |
| 1282 | public_key: "com.android.art.avbpubkey", |
| 1283 | private_key: "com.android.art.pem", |
| 1284 | } |
| 1285 | |
| 1286 | java_library { |
| 1287 | name: "baz", |
| 1288 | apex_available: [ |
| 1289 | "com.android.art", |
| 1290 | ], |
| 1291 | srcs: ["b.java"], |
| 1292 | compile_dex: true, |
| 1293 | } |
| 1294 | |
| 1295 | java_library { |
| 1296 | name: "quuz", |
| 1297 | apex_available: [ |
| 1298 | "com.android.art", |
| 1299 | ], |
| 1300 | srcs: ["b.java"], |
| 1301 | compile_dex: true, |
| 1302 | } |
| 1303 | |
| 1304 | bootclasspath_fragment { |
| 1305 | name: "art-bootclasspath-fragment", |
| 1306 | image_name: "art", |
| 1307 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 1308 | contents: ["baz", "quuz"], |
| 1309 | apex_available: [ |
| 1310 | "com.android.art", |
| 1311 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1312 | hidden_api: { |
| 1313 | split_packages: ["*"], |
| 1314 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | apex { |
| 1318 | name: "myapex", |
| 1319 | key: "myapex.key", |
| 1320 | bootclasspath_fragments: [ |
| 1321 | "mybootclasspathfragment", |
| 1322 | ], |
| 1323 | updatable: false, |
| 1324 | } |
| 1325 | |
| 1326 | apex_key { |
| 1327 | name: "myapex.key", |
| 1328 | public_key: "testkey.avbpubkey", |
| 1329 | private_key: "testkey.pem", |
| 1330 | } |
| 1331 | |
| 1332 | java_sdk_library { |
| 1333 | name: "foo", |
| 1334 | srcs: ["b.java"], |
| 1335 | shared_library: false, |
| 1336 | public: {enabled: true}, |
| 1337 | apex_available: [ |
| 1338 | "myapex", |
| 1339 | ], |
| 1340 | } |
| 1341 | |
| 1342 | java_library { |
| 1343 | name: "bar", |
| 1344 | srcs: ["b.java"], |
| 1345 | installable: true, |
| 1346 | apex_available: [ |
| 1347 | "myapex", |
| 1348 | ], |
| 1349 | } |
| 1350 | |
| 1351 | bootclasspath_fragment { |
| 1352 | name: "mybootclasspathfragment", |
| 1353 | contents: [ |
| 1354 | "foo", |
| 1355 | "bar", |
| 1356 | ], |
| 1357 | apex_available: [ |
| 1358 | "myapex", |
| 1359 | ], |
| 1360 | additional_stubs: ["android-non-updatable"], |
| 1361 | fragments: [ |
| 1362 | { |
| 1363 | apex: "com.android.art", |
| 1364 | module: "art-bootclasspath-fragment", |
| 1365 | }, |
| 1366 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1367 | hidden_api: { |
| 1368 | split_packages: ["*"], |
| 1369 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1370 | } |
| 1371 | `) |
| 1372 | |
| 1373 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1374 | "art-bootclasspath-fragment", |
| 1375 | "bar", |
| 1376 | "dex2oatd", |
| 1377 | "foo", |
| 1378 | "prebuilt_sdk_module-lib_current_android-non-updatable", |
| 1379 | "prebuilt_sdk_public_current_android-non-updatable", |
| 1380 | "prebuilt_sdk_system_current_android-non-updatable", |
| 1381 | "prebuilt_sdk_test_current_android-non-updatable", |
| 1382 | }) |
| 1383 | |
| 1384 | nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable") |
| 1385 | nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable") |
| 1386 | nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable") |
| 1387 | nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable") |
| 1388 | |
| 1389 | // Make sure that the fragment uses the android-non-updatable modules when generating the hidden |
| 1390 | // API flags. |
| 1391 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1392 | |
| 1393 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1394 | command := rule.RuleParams.Command |
| 1395 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1396 | |
| 1397 | // Make sure that the module_lib non-updatable stubs are available for resolving references from |
| 1398 | // the implementation boot dex jars provided by this module. |
| 1399 | android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs) |
| 1400 | |
| 1401 | // Make sure that the appropriate non-updatable stubs are available for resolving references from |
| 1402 | // the different API stubs provided by this module. |
| 1403 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs) |
| 1404 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs) |
| 1405 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs) |
| 1406 | } |
| 1407 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 1408 | // TODO(b/177892522) - add test for host apex. |