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