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