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", ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 119 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art |
| 120 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat |
| 121 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex |
| 122 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art |
| 123 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat |
| 124 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex |
| 125 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art |
| 126 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat |
| 127 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex |
| 128 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art |
| 129 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat |
| 130 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex |
| 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 | 7d3c9e0 | 2021-12-13 17:19:05 +0000 | [diff] [blame] | 500 | t.Run("boot image disable generate profile", 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 | dexpreopt.FixtureDisableGenerateProfile(true), |
| 509 | ).RunTest(t) |
| 510 | |
| 511 | files := getFiles(t, result.TestContext, "com.android.art", "android_common_com.android.art_image") |
| 512 | for _, file := range files { |
| 513 | matched, _ := path.Match("etc/boot-image.prof", file.path) |
| 514 | android.AssertBoolEquals(t, "\"etc/boot-image.prof\" should not be in the APEX", matched, false) |
| 515 | } |
| 516 | }) |
| 517 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 518 | t.Run("boot image files with preferred prebuilt", func(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 519 | result := android.GroupFixturePreparers( |
| 520 | commonPreparer, |
| 521 | |
| 522 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 523 | // bootclasspath_fragment's contents property. |
| 524 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 525 | addSource("foo", "bar"), |
| 526 | |
| 527 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 528 | addPrebuilt(true, "foo", "bar"), |
Jiakai Zhang | 6decef9 | 2022-01-12 17:56:19 +0000 | [diff] [blame] | 529 | |
| 530 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 531 | ).RunTest(t) |
| 532 | |
| 533 | 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] | 534 | "etc/boot-image.prof", |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 535 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 536 | "javalib/arm/boot.art", |
| 537 | "javalib/arm/boot.oat", |
| 538 | "javalib/arm/boot.vdex", |
| 539 | "javalib/arm/boot-bar.art", |
| 540 | "javalib/arm/boot-bar.oat", |
| 541 | "javalib/arm/boot-bar.vdex", |
| 542 | "javalib/arm64/boot.art", |
| 543 | "javalib/arm64/boot.oat", |
| 544 | "javalib/arm64/boot.vdex", |
| 545 | "javalib/arm64/boot-bar.art", |
| 546 | "javalib/arm64/boot-bar.oat", |
| 547 | "javalib/arm64/boot-bar.vdex", |
| 548 | "javalib/bar.jar", |
| 549 | "javalib/foo.jar", |
| 550 | }) |
| 551 | |
| 552 | 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] | 553 | `com.android.art.key`, |
| 554 | `mybootclasspathfragment`, |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 555 | `prebuilt_com.android.art`, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 556 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 557 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 558 | // The boot images are installed in the APEX by Soong, so there shouldn't be any dexpreopt-related Make modules. |
| 559 | ensureDoesNotContainRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 560 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 561 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 562 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 563 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 564 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 565 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 566 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 567 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 568 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 569 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 570 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 571 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 572 | }) |
| 573 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 574 | // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined |
| 575 | // locations for the art image. |
| 576 | module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art") |
| 577 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 578 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 579 | |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 580 | t.Run("boot image files from preferred prebuilt no boot image in apex", func(t *testing.T) { |
| 581 | result := android.GroupFixturePreparers( |
| 582 | commonPreparer, |
| 583 | |
| 584 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 585 | // bootclasspath_fragment's contents property. |
| 586 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 587 | addSource("foo", "bar"), |
| 588 | |
| 589 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 590 | addPrebuilt(true, "foo", "bar"), |
| 591 | |
| 592 | java.FixtureSetBootImageInstallDirOnDevice("art", "system/framework"), |
| 593 | ).RunTest(t) |
| 594 | |
| 595 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 596 | "etc/boot-image.prof", |
| 597 | "etc/classpaths/bootclasspath.pb", |
| 598 | "javalib/bar.jar", |
| 599 | "javalib/foo.jar", |
| 600 | }) |
| 601 | |
| 602 | ensureContainsRequiredDeps(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 603 | "mybootclasspathfragment-dexpreopt-arm64-boot.art", |
| 604 | "mybootclasspathfragment-dexpreopt-arm64-boot.oat", |
| 605 | "mybootclasspathfragment-dexpreopt-arm64-boot.vdex", |
| 606 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.art", |
| 607 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.oat", |
| 608 | "mybootclasspathfragment-dexpreopt-arm64-boot-bar.vdex", |
| 609 | "mybootclasspathfragment-dexpreopt-arm-boot.art", |
| 610 | "mybootclasspathfragment-dexpreopt-arm-boot.oat", |
| 611 | "mybootclasspathfragment-dexpreopt-arm-boot.vdex", |
| 612 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.art", |
| 613 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.oat", |
| 614 | "mybootclasspathfragment-dexpreopt-arm-boot-bar.vdex", |
| 615 | }) |
| 616 | }) |
| 617 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 618 | t.Run("source with inconsistency between config and contents", func(t *testing.T) { |
| 619 | android.GroupFixturePreparers( |
| 620 | commonPreparer, |
| 621 | |
| 622 | // Create an inconsistency between the ArtApexJars configuration and the art source |
| 623 | // bootclasspath_fragment module's contents property. |
| 624 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 625 | addSource("foo", "bar"), |
| 626 | ). |
| 627 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 628 | RunTest(t) |
| 629 | }) |
| 630 | |
| 631 | t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 632 | android.GroupFixturePreparers( |
| 633 | commonPreparer, |
| 634 | |
| 635 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 636 | // prebuilt_bootclasspath_fragment module's contents property. |
| 637 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 638 | addPrebuilt(false, "foo", "bar"), |
| 639 | ). |
| 640 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 641 | RunTest(t) |
| 642 | }) |
| 643 | |
| 644 | t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 645 | android.GroupFixturePreparers( |
| 646 | commonPreparer, |
| 647 | |
| 648 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 649 | // prebuilt_bootclasspath_fragment module's contents property. |
| 650 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 651 | addPrebuilt(true, "foo", "bar"), |
| 652 | |
| 653 | // Source contents property is consistent with the config. |
| 654 | addSource("foo"), |
| 655 | ). |
| 656 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 657 | RunTest(t) |
| 658 | }) |
| 659 | |
| 660 | t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 661 | android.GroupFixturePreparers( |
| 662 | commonPreparer, |
| 663 | |
| 664 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 665 | // prebuilt_bootclasspath_fragment module's contents property. |
| 666 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 667 | addPrebuilt(false, "foo", "bar"), |
| 668 | |
| 669 | // Source contents property is consistent with the config. |
| 670 | addSource("foo"), |
| 671 | |
| 672 | // This should pass because while the prebuilt is inconsistent with the configuration it is |
| 673 | // not actually used. |
| 674 | ).RunTest(t) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 675 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 678 | func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 679 | preparers := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 680 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 681 | prepareForTestWithArtApex, |
| 682 | |
| 683 | android.FixtureMergeMockFs(android.MockFS{ |
| 684 | "com.android.art-arm64.apex": nil, |
| 685 | "com.android.art-arm.apex": nil, |
| 686 | }), |
| 687 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 688 | // Configure some libraries in the art bootclasspath_fragment. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 689 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
Jiakai Zhang | e6e90db | 2022-01-28 14:58:56 +0000 | [diff] [blame] | 690 | java.FixtureSetBootImageInstallDirOnDevice("art", "apex/com.android.art/javalib"), |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 691 | ) |
| 692 | |
| 693 | bp := ` |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 694 | prebuilt_apex { |
| 695 | name: "com.android.art", |
| 696 | arch: { |
| 697 | arm64: { |
| 698 | src: "com.android.art-arm64.apex", |
| 699 | }, |
| 700 | arm: { |
| 701 | src: "com.android.art-arm.apex", |
| 702 | }, |
| 703 | }, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 704 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | java_import { |
| 708 | name: "foo", |
| 709 | jars: ["foo.jar"], |
| 710 | apex_available: [ |
| 711 | "com.android.art", |
| 712 | ], |
| 713 | } |
| 714 | |
| 715 | java_import { |
| 716 | name: "bar", |
| 717 | jars: ["bar.jar"], |
| 718 | apex_available: [ |
| 719 | "com.android.art", |
| 720 | ], |
| 721 | } |
| 722 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 723 | prebuilt_bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 724 | name: "mybootclasspathfragment", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 725 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 726 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 727 | contents: ["foo", "bar"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 728 | apex_available: [ |
| 729 | "com.android.art", |
| 730 | ], |
Paul Duffin | 54e4197 | 2021-07-19 13:23:40 +0100 | [diff] [blame] | 731 | hidden_api: { |
| 732 | annotation_flags: "mybootclasspathfragment/annotation-flags.csv", |
| 733 | metadata: "mybootclasspathfragment/metadata.csv", |
| 734 | index: "mybootclasspathfragment/index.csv", |
| 735 | stub_flags: "mybootclasspathfragment/stub-flags.csv", |
| 736 | all_flags: "mybootclasspathfragment/all-flags.csv", |
| 737 | }, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 738 | } |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 739 | |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 740 | // A prebuilt apex with the same apex_name that shouldn't interfere when it isn't enabled. |
| 741 | prebuilt_apex { |
| 742 | name: "com.mycompany.android.art", |
| 743 | apex_name: "com.android.art", |
| 744 | %s |
| 745 | src: "com.mycompany.android.art.apex", |
| 746 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
| 747 | } |
| 748 | ` |
| 749 | |
| 750 | t.Run("disabled alternative APEX", func(t *testing.T) { |
| 751 | result := preparers.RunTestWithBp(t, fmt.Sprintf(bp, "enabled: false,")) |
| 752 | |
| 753 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ |
| 754 | `com.android.art.apex.selector`, |
| 755 | `prebuilt_mybootclasspathfragment`, |
| 756 | }) |
| 757 | |
| 758 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{ |
| 759 | `com.android.art.deapexer`, |
| 760 | `dex2oatd`, |
| 761 | `prebuilt_bar`, |
| 762 | `prebuilt_foo`, |
| 763 | }) |
| 764 | |
| 765 | module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art") |
| 766 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
| 767 | |
| 768 | // Check that the right deapexer module was chosen for a boot image. |
| 769 | param := module.Output("out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art") |
| 770 | 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] | 771 | }) |
| 772 | |
Martin Stjernholm | 43c44b0 | 2021-06-30 16:35:07 +0100 | [diff] [blame] | 773 | t.Run("enabled alternative APEX", func(t *testing.T) { |
| 774 | preparers.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 775 | "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.art and com.mycompany.android.art")). |
| 776 | RunTestWithBp(t, fmt.Sprintf(bp, "")) |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 777 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | // checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the |
| 781 | // predefined locations of boot dex jars used as inputs for the ART boot image. |
| 782 | func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) { |
| 783 | t.Helper() |
| 784 | bootJarLocations := []string{} |
| 785 | for _, output := range module.AllOutputs() { |
| 786 | output = android.StringRelativeToTop(config, output) |
| 787 | if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") { |
| 788 | bootJarLocations = append(bootJarLocations, output) |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | sort.Strings(bootJarLocations) |
| 793 | expected := []string{} |
| 794 | for _, m := range modules { |
| 795 | expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m)) |
| 796 | } |
| 797 | sort.Strings(expected) |
| 798 | |
| 799 | android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations) |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 802 | func TestBootclasspathFragmentContentsNoName(t *testing.T) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 803 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 804 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 805 | prepareForTestWithMyapex, |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 806 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 807 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 808 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 809 | // is disabled. |
| 810 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 811 | |
| 812 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 813 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 814 | ).RunTestWithBp(t, ` |
| 815 | apex { |
| 816 | name: "myapex", |
| 817 | key: "myapex.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 818 | bootclasspath_fragments: [ |
| 819 | "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 820 | ], |
| 821 | updatable: false, |
| 822 | } |
| 823 | |
| 824 | apex_key { |
| 825 | name: "myapex.key", |
| 826 | public_key: "testkey.avbpubkey", |
| 827 | private_key: "testkey.pem", |
| 828 | } |
| 829 | |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 830 | java_sdk_library { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 831 | name: "foo", |
| 832 | srcs: ["b.java"], |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 833 | shared_library: false, |
| 834 | public: {enabled: true}, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 835 | apex_available: [ |
| 836 | "myapex", |
| 837 | ], |
| 838 | } |
| 839 | |
| 840 | java_library { |
| 841 | name: "bar", |
| 842 | srcs: ["b.java"], |
| 843 | installable: true, |
| 844 | apex_available: [ |
| 845 | "myapex", |
| 846 | ], |
| 847 | } |
| 848 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 849 | bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 850 | name: "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 851 | contents: [ |
| 852 | "foo", |
| 853 | "bar", |
| 854 | ], |
| 855 | apex_available: [ |
| 856 | "myapex", |
| 857 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 858 | hidden_api: { |
| 859 | split_packages: ["*"], |
| 860 | }, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 861 | } |
| 862 | `) |
| 863 | |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 864 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 865 | // This does not include art, oat or vdex files as they are only included for the art boot |
| 866 | // image. |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 867 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 868 | "javalib/bar.jar", |
| 869 | "javalib/foo.jar", |
| 870 | }) |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 871 | |
| 872 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 873 | `myapex.key`, |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 874 | `mybootclasspathfragment`, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 875 | }) |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 876 | |
| 877 | apex := result.ModuleForTests("myapex", "android_common_myapex_image") |
| 878 | apexRule := apex.Rule("apexRule") |
| 879 | copyCommands := apexRule.Args["copy_commands"] |
| 880 | |
| 881 | // Make sure that the fragment provides the hidden API encoded dex jars to the APEX. |
| 882 | fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") |
| 883 | |
| 884 | info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 885 | |
| 886 | checkFragmentExportedDexJar := func(name string, expectedDexJar string) { |
| 887 | module := result.Module(name, "android_common_apex10000") |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 888 | dexJar, err := info.DexBootJarPathForContentModule(module) |
| 889 | if err != nil { |
| 890 | t.Error(err) |
| 891 | } |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 892 | android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar) |
| 893 | |
| 894 | expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name) |
| 895 | android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand) |
| 896 | } |
| 897 | |
Paul Duffin | 54c98f5 | 2021-05-15 08:54:30 +0100 | [diff] [blame] | 898 | checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar") |
| 899 | 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] | 900 | } |
| 901 | |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 902 | func getDexJarPath(result *android.TestResult, name string) string { |
| 903 | module := result.Module(name, "android_common") |
Martin Stjernholm | 8be1e6d | 2021-09-15 03:34:04 +0100 | [diff] [blame] | 904 | return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String() |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | // TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are |
| 908 | // passed to the hiddenapi list tool. |
| 909 | func TestBootclasspathFragment_HiddenAPIList(t *testing.T) { |
| 910 | result := android.GroupFixturePreparers( |
| 911 | prepareForTestWithBootclasspathFragment, |
| 912 | prepareForTestWithArtApex, |
| 913 | prepareForTestWithMyapex, |
| 914 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
| 915 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 916 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 917 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 918 | // is disabled. |
| 919 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 920 | |
| 921 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 922 | java.FixtureWithLastReleaseApis("foo", "quuz"), |
| 923 | ).RunTestWithBp(t, ` |
| 924 | apex { |
| 925 | name: "com.android.art", |
| 926 | key: "com.android.art.key", |
| 927 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 928 | updatable: false, |
| 929 | } |
| 930 | |
| 931 | apex_key { |
| 932 | name: "com.android.art.key", |
| 933 | public_key: "com.android.art.avbpubkey", |
| 934 | private_key: "com.android.art.pem", |
| 935 | } |
| 936 | |
| 937 | java_library { |
| 938 | name: "baz", |
| 939 | apex_available: [ |
| 940 | "com.android.art", |
| 941 | ], |
| 942 | srcs: ["b.java"], |
| 943 | compile_dex: true, |
| 944 | } |
| 945 | |
| 946 | java_sdk_library { |
| 947 | name: "quuz", |
| 948 | apex_available: [ |
| 949 | "com.android.art", |
| 950 | ], |
| 951 | srcs: ["b.java"], |
| 952 | compile_dex: true, |
| 953 | public: {enabled: true}, |
| 954 | system: {enabled: true}, |
| 955 | test: {enabled: true}, |
| 956 | module_lib: {enabled: true}, |
| 957 | } |
| 958 | |
| 959 | bootclasspath_fragment { |
| 960 | name: "art-bootclasspath-fragment", |
| 961 | image_name: "art", |
| 962 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 963 | contents: ["baz", "quuz"], |
| 964 | apex_available: [ |
| 965 | "com.android.art", |
| 966 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 967 | hidden_api: { |
| 968 | split_packages: ["*"], |
| 969 | }, |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | apex { |
| 973 | name: "myapex", |
| 974 | key: "myapex.key", |
| 975 | bootclasspath_fragments: [ |
| 976 | "mybootclasspathfragment", |
| 977 | ], |
| 978 | updatable: false, |
| 979 | } |
| 980 | |
| 981 | apex_key { |
| 982 | name: "myapex.key", |
| 983 | public_key: "testkey.avbpubkey", |
| 984 | private_key: "testkey.pem", |
| 985 | } |
| 986 | |
| 987 | java_sdk_library { |
| 988 | name: "foo", |
| 989 | srcs: ["b.java"], |
| 990 | shared_library: false, |
| 991 | public: {enabled: true}, |
| 992 | apex_available: [ |
| 993 | "myapex", |
| 994 | ], |
| 995 | } |
| 996 | |
| 997 | java_library { |
| 998 | name: "bar", |
| 999 | srcs: ["b.java"], |
| 1000 | installable: true, |
| 1001 | apex_available: [ |
| 1002 | "myapex", |
| 1003 | ], |
| 1004 | } |
| 1005 | |
| 1006 | bootclasspath_fragment { |
| 1007 | name: "mybootclasspathfragment", |
| 1008 | contents: [ |
| 1009 | "foo", |
| 1010 | "bar", |
| 1011 | ], |
| 1012 | apex_available: [ |
| 1013 | "myapex", |
| 1014 | ], |
| 1015 | fragments: [ |
| 1016 | { |
| 1017 | apex: "com.android.art", |
| 1018 | module: "art-bootclasspath-fragment", |
| 1019 | }, |
| 1020 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1021 | hidden_api: { |
| 1022 | split_packages: ["*"], |
| 1023 | }, |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1024 | } |
| 1025 | `) |
| 1026 | |
| 1027 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1028 | "art-bootclasspath-fragment", |
| 1029 | "bar", |
| 1030 | "dex2oatd", |
| 1031 | "foo", |
| 1032 | }) |
| 1033 | |
| 1034 | fooStubs := getDexJarPath(result, "foo.stubs") |
| 1035 | quuzPublicStubs := getDexJarPath(result, "quuz.stubs") |
| 1036 | quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system") |
| 1037 | quuzTestStubs := getDexJarPath(result, "quuz.stubs.test") |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 1038 | quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib") |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1039 | |
| 1040 | // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags. |
| 1041 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1042 | |
| 1043 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1044 | command := rule.RuleParams.Command |
| 1045 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1046 | |
| 1047 | // Make sure that the quuz stubs are available for resolving references from the implementation |
| 1048 | // boot dex jars provided by this module. |
Paul Duffin | b51db2e | 2021-06-21 14:08:08 +0100 | [diff] [blame] | 1049 | android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs) |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame] | 1050 | |
| 1051 | // Make sure that the quuz stubs are available for resolving references from the different API |
| 1052 | // stubs provided by this module. |
| 1053 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs) |
| 1054 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs) |
| 1055 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs) |
| 1056 | } |
| 1057 | |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1058 | // TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting |
| 1059 | // additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be |
| 1060 | // added to the hiddenapi list tool. |
| 1061 | func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) { |
| 1062 | result := android.GroupFixturePreparers( |
| 1063 | prepareForTestWithBootclasspathFragment, |
| 1064 | prepareForTestWithArtApex, |
| 1065 | prepareForTestWithMyapex, |
| 1066 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 1067 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 1068 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1069 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 1070 | // is disabled. |
| 1071 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 1072 | |
| 1073 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 1074 | java.FixtureWithLastReleaseApis("foo", "android-non-updatable"), |
| 1075 | ).RunTestWithBp(t, ` |
| 1076 | java_sdk_library { |
| 1077 | name: "android-non-updatable", |
| 1078 | srcs: ["b.java"], |
| 1079 | compile_dex: true, |
| 1080 | public: { |
| 1081 | enabled: true, |
| 1082 | }, |
| 1083 | system: { |
| 1084 | enabled: true, |
| 1085 | }, |
| 1086 | test: { |
| 1087 | enabled: true, |
| 1088 | }, |
| 1089 | module_lib: { |
| 1090 | enabled: true, |
| 1091 | }, |
| 1092 | } |
| 1093 | |
| 1094 | apex { |
| 1095 | name: "com.android.art", |
| 1096 | key: "com.android.art.key", |
| 1097 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1098 | updatable: false, |
| 1099 | } |
| 1100 | |
| 1101 | apex_key { |
| 1102 | name: "com.android.art.key", |
| 1103 | public_key: "com.android.art.avbpubkey", |
| 1104 | private_key: "com.android.art.pem", |
| 1105 | } |
| 1106 | |
| 1107 | java_library { |
| 1108 | name: "baz", |
| 1109 | apex_available: [ |
| 1110 | "com.android.art", |
| 1111 | ], |
| 1112 | srcs: ["b.java"], |
| 1113 | compile_dex: true, |
| 1114 | } |
| 1115 | |
| 1116 | java_library { |
| 1117 | name: "quuz", |
| 1118 | apex_available: [ |
| 1119 | "com.android.art", |
| 1120 | ], |
| 1121 | srcs: ["b.java"], |
| 1122 | compile_dex: true, |
| 1123 | } |
| 1124 | |
| 1125 | bootclasspath_fragment { |
| 1126 | name: "art-bootclasspath-fragment", |
| 1127 | image_name: "art", |
| 1128 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 1129 | contents: ["baz", "quuz"], |
| 1130 | apex_available: [ |
| 1131 | "com.android.art", |
| 1132 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1133 | hidden_api: { |
| 1134 | split_packages: ["*"], |
| 1135 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | apex { |
| 1139 | name: "myapex", |
| 1140 | key: "myapex.key", |
| 1141 | bootclasspath_fragments: [ |
| 1142 | "mybootclasspathfragment", |
| 1143 | ], |
| 1144 | updatable: false, |
| 1145 | } |
| 1146 | |
| 1147 | apex_key { |
| 1148 | name: "myapex.key", |
| 1149 | public_key: "testkey.avbpubkey", |
| 1150 | private_key: "testkey.pem", |
| 1151 | } |
| 1152 | |
| 1153 | java_sdk_library { |
| 1154 | name: "foo", |
| 1155 | srcs: ["b.java"], |
| 1156 | shared_library: false, |
| 1157 | public: {enabled: true}, |
| 1158 | apex_available: [ |
| 1159 | "myapex", |
| 1160 | ], |
| 1161 | } |
| 1162 | |
| 1163 | java_library { |
| 1164 | name: "bar", |
| 1165 | srcs: ["b.java"], |
| 1166 | installable: true, |
| 1167 | apex_available: [ |
| 1168 | "myapex", |
| 1169 | ], |
| 1170 | } |
| 1171 | |
| 1172 | bootclasspath_fragment { |
| 1173 | name: "mybootclasspathfragment", |
| 1174 | contents: [ |
| 1175 | "foo", |
| 1176 | "bar", |
| 1177 | ], |
| 1178 | apex_available: [ |
| 1179 | "myapex", |
| 1180 | ], |
| 1181 | additional_stubs: ["android-non-updatable"], |
| 1182 | fragments: [ |
| 1183 | { |
| 1184 | apex: "com.android.art", |
| 1185 | module: "art-bootclasspath-fragment", |
| 1186 | }, |
| 1187 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1188 | hidden_api: { |
| 1189 | split_packages: ["*"], |
| 1190 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1191 | } |
| 1192 | `) |
| 1193 | |
| 1194 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1195 | "android-non-updatable.stubs", |
| 1196 | "android-non-updatable.stubs.module_lib", |
| 1197 | "android-non-updatable.stubs.system", |
| 1198 | "android-non-updatable.stubs.test", |
| 1199 | "art-bootclasspath-fragment", |
| 1200 | "bar", |
| 1201 | "dex2oatd", |
| 1202 | "foo", |
| 1203 | }) |
| 1204 | |
| 1205 | nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs") |
| 1206 | nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system") |
| 1207 | nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test") |
| 1208 | nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib") |
| 1209 | |
| 1210 | // Make sure that the fragment uses the android-non-updatable modules when generating the hidden |
| 1211 | // API flags. |
| 1212 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1213 | |
| 1214 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1215 | command := rule.RuleParams.Command |
| 1216 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1217 | |
| 1218 | // Make sure that the module_lib non-updatable stubs are available for resolving references from |
| 1219 | // the implementation boot dex jars provided by this module. |
| 1220 | android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs) |
| 1221 | |
| 1222 | // Make sure that the appropriate non-updatable stubs are available for resolving references from |
| 1223 | // the different API stubs provided by this module. |
| 1224 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs) |
| 1225 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs) |
| 1226 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs) |
| 1227 | } |
| 1228 | |
| 1229 | // TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that |
| 1230 | // setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable |
| 1231 | // modules to be added to the hiddenapi list tool. |
| 1232 | func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) { |
| 1233 | result := android.GroupFixturePreparers( |
| 1234 | prepareForTestWithBootclasspathFragment, |
| 1235 | java.PrepareForTestWithJavaDefaultModules, |
| 1236 | prepareForTestWithArtApex, |
| 1237 | prepareForTestWithMyapex, |
| 1238 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 1239 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 1240 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1241 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 1242 | // is disabled. |
| 1243 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 1244 | |
| 1245 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 1246 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
| 1247 | }), |
| 1248 | |
| 1249 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 1250 | java.FixtureWithPrebuiltApis(map[string][]string{ |
| 1251 | "current": {"android-non-updatable"}, |
| 1252 | "30": {"foo"}, |
| 1253 | }), |
| 1254 | ).RunTestWithBp(t, ` |
| 1255 | apex { |
| 1256 | name: "com.android.art", |
| 1257 | key: "com.android.art.key", |
| 1258 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1259 | updatable: false, |
| 1260 | } |
| 1261 | |
| 1262 | apex_key { |
| 1263 | name: "com.android.art.key", |
| 1264 | public_key: "com.android.art.avbpubkey", |
| 1265 | private_key: "com.android.art.pem", |
| 1266 | } |
| 1267 | |
| 1268 | java_library { |
| 1269 | name: "baz", |
| 1270 | apex_available: [ |
| 1271 | "com.android.art", |
| 1272 | ], |
| 1273 | srcs: ["b.java"], |
| 1274 | compile_dex: true, |
| 1275 | } |
| 1276 | |
| 1277 | java_library { |
| 1278 | name: "quuz", |
| 1279 | apex_available: [ |
| 1280 | "com.android.art", |
| 1281 | ], |
| 1282 | srcs: ["b.java"], |
| 1283 | compile_dex: true, |
| 1284 | } |
| 1285 | |
| 1286 | bootclasspath_fragment { |
| 1287 | name: "art-bootclasspath-fragment", |
| 1288 | image_name: "art", |
| 1289 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 1290 | contents: ["baz", "quuz"], |
| 1291 | apex_available: [ |
| 1292 | "com.android.art", |
| 1293 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1294 | hidden_api: { |
| 1295 | split_packages: ["*"], |
| 1296 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | apex { |
| 1300 | name: "myapex", |
| 1301 | key: "myapex.key", |
| 1302 | bootclasspath_fragments: [ |
| 1303 | "mybootclasspathfragment", |
| 1304 | ], |
| 1305 | updatable: false, |
| 1306 | } |
| 1307 | |
| 1308 | apex_key { |
| 1309 | name: "myapex.key", |
| 1310 | public_key: "testkey.avbpubkey", |
| 1311 | private_key: "testkey.pem", |
| 1312 | } |
| 1313 | |
| 1314 | java_sdk_library { |
| 1315 | name: "foo", |
| 1316 | srcs: ["b.java"], |
| 1317 | shared_library: false, |
| 1318 | public: {enabled: true}, |
| 1319 | apex_available: [ |
| 1320 | "myapex", |
| 1321 | ], |
| 1322 | } |
| 1323 | |
| 1324 | java_library { |
| 1325 | name: "bar", |
| 1326 | srcs: ["b.java"], |
| 1327 | installable: true, |
| 1328 | apex_available: [ |
| 1329 | "myapex", |
| 1330 | ], |
| 1331 | } |
| 1332 | |
| 1333 | bootclasspath_fragment { |
| 1334 | name: "mybootclasspathfragment", |
| 1335 | contents: [ |
| 1336 | "foo", |
| 1337 | "bar", |
| 1338 | ], |
| 1339 | apex_available: [ |
| 1340 | "myapex", |
| 1341 | ], |
| 1342 | additional_stubs: ["android-non-updatable"], |
| 1343 | fragments: [ |
| 1344 | { |
| 1345 | apex: "com.android.art", |
| 1346 | module: "art-bootclasspath-fragment", |
| 1347 | }, |
| 1348 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 1349 | hidden_api: { |
| 1350 | split_packages: ["*"], |
| 1351 | }, |
Paul Duffin | 5cca7c4 | 2021-05-26 10:16:01 +0100 | [diff] [blame] | 1352 | } |
| 1353 | `) |
| 1354 | |
| 1355 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 1356 | "art-bootclasspath-fragment", |
| 1357 | "bar", |
| 1358 | "dex2oatd", |
| 1359 | "foo", |
| 1360 | "prebuilt_sdk_module-lib_current_android-non-updatable", |
| 1361 | "prebuilt_sdk_public_current_android-non-updatable", |
| 1362 | "prebuilt_sdk_system_current_android-non-updatable", |
| 1363 | "prebuilt_sdk_test_current_android-non-updatable", |
| 1364 | }) |
| 1365 | |
| 1366 | nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable") |
| 1367 | nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable") |
| 1368 | nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable") |
| 1369 | nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable") |
| 1370 | |
| 1371 | // Make sure that the fragment uses the android-non-updatable modules when generating the hidden |
| 1372 | // API flags. |
| 1373 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 1374 | |
| 1375 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 1376 | command := rule.RuleParams.Command |
| 1377 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 1378 | |
| 1379 | // Make sure that the module_lib non-updatable stubs are available for resolving references from |
| 1380 | // the implementation boot dex jars provided by this module. |
| 1381 | android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs) |
| 1382 | |
| 1383 | // Make sure that the appropriate non-updatable stubs are available for resolving references from |
| 1384 | // the different API stubs provided by this module. |
| 1385 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs) |
| 1386 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs) |
| 1387 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs) |
| 1388 | } |
| 1389 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 1390 | // TODO(b/177892522) - add test for host apex. |