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" |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 19 | "sort" |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 20 | "strings" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 21 | "testing" |
| 22 | |
| 23 | "android/soong/android" |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 24 | "android/soong/java" |
| 25 | ) |
| 26 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 27 | // Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART |
| 28 | // bootclasspath_fragment requires modules from the ART apex. |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 29 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 30 | var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers( |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 31 | java.PrepareForTestWithDexpreopt, |
| 32 | PrepareForTestWithApexBuildComponents, |
| 33 | ) |
| 34 | |
| 35 | // Some additional files needed for the art apex. |
| 36 | var prepareForTestWithArtApex = android.FixtureMergeMockFs(android.MockFS{ |
| 37 | "com.android.art.avbpubkey": nil, |
| 38 | "com.android.art.pem": nil, |
| 39 | "system/sepolicy/apex/com.android.art-file_contexts": nil, |
| 40 | }) |
| 41 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 42 | func TestBootclasspathFragments(t *testing.T) { |
Paul Duffin | 52bfaa4 | 2021-03-23 23:40:12 +0000 | [diff] [blame] | 43 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 44 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 45 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 46 | 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] | 47 | prepareForTestWithArtApex, |
| 48 | |
| 49 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 50 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 51 | ).RunTestWithBp(t, ` |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 52 | java_sdk_library { |
| 53 | name: "foo", |
| 54 | srcs: ["b.java"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | java_library { |
| 58 | name: "bar", |
| 59 | srcs: ["b.java"], |
| 60 | installable: true, |
| 61 | } |
| 62 | |
| 63 | apex { |
| 64 | name: "com.android.art", |
| 65 | key: "com.android.art.key", |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 66 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 67 | java_libs: [ |
| 68 | "baz", |
| 69 | "quuz", |
| 70 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 71 | updatable: false, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | apex_key { |
| 75 | name: "com.android.art.key", |
| 76 | public_key: "com.android.art.avbpubkey", |
| 77 | private_key: "com.android.art.pem", |
| 78 | } |
| 79 | |
| 80 | java_library { |
| 81 | name: "baz", |
| 82 | apex_available: [ |
| 83 | "com.android.art", |
| 84 | ], |
| 85 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 86 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | java_library { |
| 90 | name: "quuz", |
| 91 | apex_available: [ |
| 92 | "com.android.art", |
| 93 | ], |
| 94 | srcs: ["b.java"], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 95 | compile_dex: true, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 96 | } |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 97 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 98 | bootclasspath_fragment { |
| 99 | name: "art-bootclasspath-fragment", |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 100 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 101 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 102 | contents: ["baz", "quuz"], |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 103 | apex_available: [ |
| 104 | "com.android.art", |
| 105 | ], |
Paul Duffin | 5bbfef8 | 2021-01-30 12:57:26 +0000 | [diff] [blame] | 106 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 107 | `, |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 108 | ) |
| 109 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 110 | // Make sure that the art-bootclasspath-fragment is using the correct configuration. |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 111 | checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000", |
| 112 | "com.android.art:baz,com.android.art:quuz", ` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 113 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art |
| 114 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat |
| 115 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex |
| 116 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art |
| 117 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat |
| 118 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex |
| 119 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art |
| 120 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat |
| 121 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex |
| 122 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art |
| 123 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat |
| 124 | test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex |
| 125 | `) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 128 | func TestBootclasspathFragments_FragmentDependency(t *testing.T) { |
| 129 | result := android.GroupFixturePreparers( |
| 130 | prepareForTestWithBootclasspathFragment, |
| 131 | // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath. |
| 132 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"), |
| 133 | prepareForTestWithArtApex, |
| 134 | |
| 135 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 136 | java.FixtureWithLastReleaseApis("foo", "baz"), |
| 137 | ).RunTestWithBp(t, ` |
| 138 | java_sdk_library { |
| 139 | name: "foo", |
| 140 | srcs: ["b.java"], |
| 141 | shared_library: false, |
| 142 | public: { |
| 143 | enabled: true, |
| 144 | }, |
| 145 | system: { |
| 146 | enabled: true, |
| 147 | }, |
| 148 | } |
| 149 | |
| 150 | java_library { |
| 151 | name: "bar", |
| 152 | srcs: ["b.java"], |
| 153 | installable: true, |
| 154 | } |
| 155 | |
| 156 | apex { |
| 157 | name: "com.android.art", |
| 158 | key: "com.android.art.key", |
| 159 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 160 | updatable: false, |
| 161 | } |
| 162 | |
| 163 | apex_key { |
| 164 | name: "com.android.art.key", |
| 165 | public_key: "com.android.art.avbpubkey", |
| 166 | private_key: "com.android.art.pem", |
| 167 | } |
| 168 | |
| 169 | java_sdk_library { |
| 170 | name: "baz", |
| 171 | apex_available: [ |
| 172 | "com.android.art", |
| 173 | ], |
| 174 | srcs: ["b.java"], |
| 175 | shared_library: false, |
| 176 | public: { |
| 177 | enabled: true, |
| 178 | }, |
| 179 | system: { |
| 180 | enabled: true, |
| 181 | }, |
| 182 | test: { |
| 183 | enabled: true, |
| 184 | }, |
| 185 | } |
| 186 | |
| 187 | java_library { |
| 188 | name: "quuz", |
| 189 | apex_available: [ |
| 190 | "com.android.art", |
| 191 | ], |
| 192 | srcs: ["b.java"], |
| 193 | compile_dex: true, |
| 194 | } |
| 195 | |
| 196 | bootclasspath_fragment { |
| 197 | name: "art-bootclasspath-fragment", |
| 198 | image_name: "art", |
| 199 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 200 | contents: ["baz", "quuz"], |
| 201 | apex_available: [ |
| 202 | "com.android.art", |
| 203 | ], |
| 204 | } |
| 205 | |
| 206 | bootclasspath_fragment { |
| 207 | name: "other-bootclasspath-fragment", |
| 208 | contents: ["foo", "bar"], |
| 209 | fragments: [ |
| 210 | { |
| 211 | apex: "com.android.art", |
| 212 | module: "art-bootclasspath-fragment", |
| 213 | }, |
| 214 | ], |
| 215 | } |
| 216 | `, |
| 217 | ) |
| 218 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 219 | checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) { |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 220 | t.Helper() |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 221 | android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, info.TransitiveStubDexJarsByScope[apiScope]) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | // Check stub dex paths exported by art. |
| 225 | artFragment := result.Module("art-bootclasspath-fragment", "android_common") |
| 226 | artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 227 | |
| 228 | bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar" |
| 229 | bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar" |
| 230 | bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar" |
| 231 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 232 | checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs) |
| 233 | checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs) |
| 234 | checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs) |
| 235 | checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 236 | |
| 237 | // Check stub dex paths exported by other. |
| 238 | otherFragment := result.Module("other-bootclasspath-fragment", "android_common") |
| 239 | otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) |
| 240 | |
| 241 | fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar" |
| 242 | fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar" |
| 243 | |
Paul Duffin | 31fad80 | 2021-06-18 18:14:25 +0100 | [diff] [blame] | 244 | checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs) |
| 245 | checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs) |
| 246 | checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs) |
| 247 | checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope) |
Paul Duffin | f1b358c | 2021-05-17 07:38:47 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 250 | 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] | 251 | t.Helper() |
| 252 | |
Paul Duffin | 58e0e76 | 2021-05-21 19:27:58 +0100 | [diff] [blame] | 253 | bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 254 | |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 255 | bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 256 | modules := bootclasspathFragmentInfo.Modules() |
Paul Duffin | 34d433a | 2021-03-09 14:13:25 +0000 | [diff] [blame] | 257 | android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String()) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 258 | |
| 259 | // Get a list of all the paths in the boot image sorted by arch type. |
| 260 | allPaths := []string{} |
Paul Duffin | e946b32 | 2021-04-25 23:04:00 +0100 | [diff] [blame] | 261 | bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType() |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 262 | for _, archType := range android.ArchTypeList() { |
| 263 | if paths, ok := bootImageFilesByArchType[archType]; ok { |
| 264 | for _, path := range paths { |
| 265 | allPaths = append(allPaths, android.NormalizePathForTesting(path)) |
| 266 | } |
| 267 | } |
| 268 | } |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 269 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 270 | android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n")) |
Paul Duffin | 3451e16 | 2021-01-20 15:16:56 +0000 | [diff] [blame] | 271 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 272 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 273 | func TestBootclasspathFragmentInArtApex(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 274 | commonPreparer := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 275 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 276 | prepareForTestWithArtApex, |
| 277 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 278 | android.FixtureWithRootAndroidBp(` |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 279 | apex { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 280 | name: "com.android.art", |
| 281 | key: "com.android.art.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 282 | bootclasspath_fragments: [ |
| 283 | "mybootclasspathfragment", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 284 | ], |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 285 | // 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] | 286 | // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the |
| 287 | // apex dedups the files correctly. |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 288 | java_libs: [ |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 289 | "bar", |
| 290 | ], |
Mathew Inwood | f8dcf5e | 2021-02-16 11:40:16 +0000 | [diff] [blame] | 291 | updatable: false, |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | apex_key { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 295 | name: "com.android.art.key", |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 296 | public_key: "testkey.avbpubkey", |
| 297 | private_key: "testkey.pem", |
| 298 | } |
| 299 | |
| 300 | java_library { |
| 301 | name: "foo", |
| 302 | srcs: ["b.java"], |
| 303 | installable: true, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 304 | apex_available: [ |
| 305 | "com.android.art", |
| 306 | ], |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | java_library { |
| 310 | name: "bar", |
| 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 | |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 318 | java_import { |
| 319 | name: "foo", |
| 320 | jars: ["foo.jar"], |
| 321 | apex_available: [ |
| 322 | "com.android.art", |
| 323 | ], |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 324 | compile_dex: true, |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | java_import { |
| 328 | name: "bar", |
| 329 | jars: ["bar.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 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 335 | `), |
| 336 | ) |
Paul Duffin | 6589805 | 2021-04-20 22:47:03 +0100 | [diff] [blame] | 337 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 338 | contentsInsert := func(contents []string) string { |
| 339 | insert := "" |
| 340 | if contents != nil { |
| 341 | insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`)) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 342 | } |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 343 | return insert |
| 344 | } |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 345 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 346 | addSource := func(contents ...string) android.FixturePreparer { |
| 347 | text := fmt.Sprintf(` |
| 348 | bootclasspath_fragment { |
| 349 | name: "mybootclasspathfragment", |
| 350 | image_name: "art", |
| 351 | %s |
| 352 | apex_available: [ |
| 353 | "com.android.art", |
| 354 | ], |
| 355 | } |
| 356 | `, contentsInsert(contents)) |
| 357 | |
| 358 | return android.FixtureAddTextFile("art/build/boot/Android.bp", text) |
| 359 | } |
| 360 | |
| 361 | addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer { |
| 362 | text := fmt.Sprintf(` |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 363 | prebuilt_apex { |
| 364 | name: "com.android.art", |
| 365 | arch: { |
| 366 | arm64: { |
| 367 | src: "com.android.art-arm64.apex", |
| 368 | }, |
| 369 | arm: { |
| 370 | src: "com.android.art-arm.apex", |
| 371 | }, |
| 372 | }, |
| 373 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
| 374 | } |
| 375 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 376 | prebuilt_bootclasspath_fragment { |
| 377 | name: "mybootclasspathfragment", |
| 378 | image_name: "art", |
| 379 | %s |
| 380 | prefer: %t, |
| 381 | apex_available: [ |
| 382 | "com.android.art", |
| 383 | ], |
| 384 | } |
| 385 | `, contentsInsert(contents), prefer) |
| 386 | return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text) |
| 387 | } |
| 388 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 389 | t.Run("boot image files from source", func(t *testing.T) { |
| 390 | result := android.GroupFixturePreparers( |
| 391 | commonPreparer, |
| 392 | |
| 393 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 394 | // bootclasspath_fragment's contents property. |
| 395 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 396 | addSource("foo", "bar"), |
| 397 | ).RunTest(t) |
| 398 | |
| 399 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 400 | "etc/classpaths/bootclasspath.pb", |
| 401 | "javalib/arm/boot.art", |
| 402 | "javalib/arm/boot.oat", |
| 403 | "javalib/arm/boot.vdex", |
| 404 | "javalib/arm/boot-bar.art", |
| 405 | "javalib/arm/boot-bar.oat", |
| 406 | "javalib/arm/boot-bar.vdex", |
| 407 | "javalib/arm64/boot.art", |
| 408 | "javalib/arm64/boot.oat", |
| 409 | "javalib/arm64/boot.vdex", |
| 410 | "javalib/arm64/boot-bar.art", |
| 411 | "javalib/arm64/boot-bar.oat", |
| 412 | "javalib/arm64/boot-bar.vdex", |
| 413 | "javalib/bar.jar", |
| 414 | "javalib/foo.jar", |
| 415 | }) |
| 416 | |
| 417 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 418 | `bar`, |
| 419 | `com.android.art.key`, |
| 420 | `mybootclasspathfragment`, |
| 421 | }) |
| 422 | |
| 423 | // Make sure that the source bootclasspath_fragment copies its dex files to the predefined |
| 424 | // locations for the art image. |
| 425 | module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 426 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
| 427 | }) |
| 428 | |
| 429 | t.Run("boot image files with preferred prebuilt", func(t *testing.T) { |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 430 | result := android.GroupFixturePreparers( |
| 431 | commonPreparer, |
| 432 | |
| 433 | // Configure some libraries in the art bootclasspath_fragment that match the source |
| 434 | // bootclasspath_fragment's contents property. |
| 435 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
| 436 | addSource("foo", "bar"), |
| 437 | |
| 438 | // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex. |
| 439 | addPrebuilt(true, "foo", "bar"), |
| 440 | ).RunTest(t) |
| 441 | |
| 442 | ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 443 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 444 | "javalib/arm/boot.art", |
| 445 | "javalib/arm/boot.oat", |
| 446 | "javalib/arm/boot.vdex", |
| 447 | "javalib/arm/boot-bar.art", |
| 448 | "javalib/arm/boot-bar.oat", |
| 449 | "javalib/arm/boot-bar.vdex", |
| 450 | "javalib/arm64/boot.art", |
| 451 | "javalib/arm64/boot.oat", |
| 452 | "javalib/arm64/boot.vdex", |
| 453 | "javalib/arm64/boot-bar.art", |
| 454 | "javalib/arm64/boot-bar.oat", |
| 455 | "javalib/arm64/boot-bar.vdex", |
| 456 | "javalib/bar.jar", |
| 457 | "javalib/foo.jar", |
| 458 | }) |
| 459 | |
| 460 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{ |
| 461 | `bar`, |
| 462 | `com.android.art.key`, |
| 463 | `mybootclasspathfragment`, |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 464 | `prebuilt_com.android.art`, |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 465 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 466 | |
| 467 | // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined |
| 468 | // locations for the art image. |
| 469 | module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art") |
| 470 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 471 | }) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 472 | |
Paul Duffin | ba6afd0 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 473 | t.Run("source with inconsistency between config and contents", func(t *testing.T) { |
| 474 | android.GroupFixturePreparers( |
| 475 | commonPreparer, |
| 476 | |
| 477 | // Create an inconsistency between the ArtApexJars configuration and the art source |
| 478 | // bootclasspath_fragment module's contents property. |
| 479 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 480 | addSource("foo", "bar"), |
| 481 | ). |
| 482 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 483 | RunTest(t) |
| 484 | }) |
| 485 | |
| 486 | t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 487 | android.GroupFixturePreparers( |
| 488 | commonPreparer, |
| 489 | |
| 490 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 491 | // prebuilt_bootclasspath_fragment module's contents property. |
| 492 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 493 | addPrebuilt(false, "foo", "bar"), |
| 494 | ). |
| 495 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 496 | RunTest(t) |
| 497 | }) |
| 498 | |
| 499 | t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 500 | android.GroupFixturePreparers( |
| 501 | commonPreparer, |
| 502 | |
| 503 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 504 | // prebuilt_bootclasspath_fragment module's contents property. |
| 505 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 506 | addPrebuilt(true, "foo", "bar"), |
| 507 | |
| 508 | // Source contents property is consistent with the config. |
| 509 | addSource("foo"), |
| 510 | ). |
| 511 | ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)). |
| 512 | RunTest(t) |
| 513 | }) |
| 514 | |
| 515 | t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) { |
| 516 | android.GroupFixturePreparers( |
| 517 | commonPreparer, |
| 518 | |
| 519 | // Create an inconsistency between the ArtApexJars configuration and the art |
| 520 | // prebuilt_bootclasspath_fragment module's contents property. |
| 521 | java.FixtureConfigureBootJars("com.android.art:foo"), |
| 522 | addPrebuilt(false, "foo", "bar"), |
| 523 | |
| 524 | // Source contents property is consistent with the config. |
| 525 | addSource("foo"), |
| 526 | |
| 527 | // This should pass because while the prebuilt is inconsistent with the configuration it is |
| 528 | // not actually used. |
| 529 | ).RunTest(t) |
Paul Duffin | 396229f | 2021-03-18 18:30:31 +0000 | [diff] [blame] | 530 | }) |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 533 | func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) { |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 534 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 535 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 536 | prepareForTestWithArtApex, |
| 537 | |
| 538 | android.FixtureMergeMockFs(android.MockFS{ |
| 539 | "com.android.art-arm64.apex": nil, |
| 540 | "com.android.art-arm.apex": nil, |
| 541 | }), |
| 542 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 543 | // Configure some libraries in the art bootclasspath_fragment. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 544 | java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"), |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 545 | ).RunTestWithBp(t, ` |
| 546 | prebuilt_apex { |
| 547 | name: "com.android.art", |
| 548 | arch: { |
| 549 | arm64: { |
| 550 | src: "com.android.art-arm64.apex", |
| 551 | }, |
| 552 | arm: { |
| 553 | src: "com.android.art-arm.apex", |
| 554 | }, |
| 555 | }, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 556 | exported_bootclasspath_fragments: ["mybootclasspathfragment"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | java_import { |
| 560 | name: "foo", |
| 561 | jars: ["foo.jar"], |
| 562 | apex_available: [ |
| 563 | "com.android.art", |
| 564 | ], |
| 565 | } |
| 566 | |
| 567 | java_import { |
| 568 | name: "bar", |
| 569 | jars: ["bar.jar"], |
| 570 | apex_available: [ |
| 571 | "com.android.art", |
| 572 | ], |
| 573 | } |
| 574 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 575 | prebuilt_bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 576 | name: "mybootclasspathfragment", |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 577 | image_name: "art", |
Paul Duffin | f23bc47 | 2021-04-27 12:42:20 +0100 | [diff] [blame] | 578 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 579 | contents: ["foo", "bar"], |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 580 | apex_available: [ |
| 581 | "com.android.art", |
| 582 | ], |
| 583 | } |
| 584 | `) |
| 585 | |
Paul Duffin | 6717d88 | 2021-06-15 19:09:41 +0100 | [diff] [blame] | 586 | java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{ |
Paul Duffin | 11216db | 2021-03-01 14:14:52 +0000 | [diff] [blame] | 587 | `com.android.art.apex.selector`, |
Paul Duffin | e521881 | 2021-06-07 13:28:19 +0100 | [diff] [blame] | 588 | `prebuilt_mybootclasspathfragment`, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 589 | }) |
| 590 | |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 591 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{ |
Paul Duffin | 5466a36 | 2021-06-07 10:25:31 +0100 | [diff] [blame] | 592 | `com.android.art.deapexer`, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 593 | `dex2oatd`, |
Paul Duffin | c7ef989 | 2021-03-23 23:21:59 +0000 | [diff] [blame] | 594 | `prebuilt_bar`, |
| 595 | `prebuilt_foo`, |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 596 | }) |
Paul Duffin | ce918b0 | 2021-06-07 14:33:47 +0100 | [diff] [blame] | 597 | |
| 598 | module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art") |
| 599 | checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo") |
| 600 | } |
| 601 | |
| 602 | // checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the |
| 603 | // predefined locations of boot dex jars used as inputs for the ART boot image. |
| 604 | func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) { |
| 605 | t.Helper() |
| 606 | bootJarLocations := []string{} |
| 607 | for _, output := range module.AllOutputs() { |
| 608 | output = android.StringRelativeToTop(config, output) |
| 609 | if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") { |
| 610 | bootJarLocations = append(bootJarLocations, output) |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | sort.Strings(bootJarLocations) |
| 615 | expected := []string{} |
| 616 | for _, m := range modules { |
| 617 | expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m)) |
| 618 | } |
| 619 | sort.Strings(expected) |
| 620 | |
| 621 | android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations) |
Paul Duffin | 9ea71c0 | 2021-03-23 22:53:07 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 624 | func TestBootclasspathFragmentContentsNoName(t *testing.T) { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 625 | result := android.GroupFixturePreparers( |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 626 | prepareForTestWithBootclasspathFragment, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 627 | prepareForTestWithMyapex, |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 628 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
| 629 | java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"), |
| 630 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 631 | // is disabled. |
| 632 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 633 | |
| 634 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 635 | java.FixtureWithLastReleaseApis("foo"), |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 636 | ).RunTestWithBp(t, ` |
| 637 | apex { |
| 638 | name: "myapex", |
| 639 | key: "myapex.key", |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 640 | bootclasspath_fragments: [ |
| 641 | "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 642 | ], |
| 643 | updatable: false, |
| 644 | } |
| 645 | |
| 646 | apex_key { |
| 647 | name: "myapex.key", |
| 648 | public_key: "testkey.avbpubkey", |
| 649 | private_key: "testkey.pem", |
| 650 | } |
| 651 | |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 652 | java_sdk_library { |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 653 | name: "foo", |
| 654 | srcs: ["b.java"], |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 655 | shared_library: false, |
| 656 | public: {enabled: true}, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 657 | apex_available: [ |
| 658 | "myapex", |
| 659 | ], |
| 660 | } |
| 661 | |
| 662 | java_library { |
| 663 | name: "bar", |
| 664 | srcs: ["b.java"], |
| 665 | installable: true, |
| 666 | apex_available: [ |
| 667 | "myapex", |
| 668 | ], |
| 669 | } |
| 670 | |
Paul Duffin | 7771eba | 2021-04-23 14:25:28 +0100 | [diff] [blame] | 671 | bootclasspath_fragment { |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 672 | name: "mybootclasspathfragment", |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 673 | contents: [ |
| 674 | "foo", |
| 675 | "bar", |
| 676 | ], |
| 677 | apex_available: [ |
| 678 | "myapex", |
| 679 | ], |
| 680 | } |
| 681 | `) |
| 682 | |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 683 | ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 684 | // This does not include art, oat or vdex files as they are only included for the art boot |
| 685 | // image. |
satayev | 227e745 | 2021-05-20 21:35:06 +0100 | [diff] [blame] | 686 | "etc/classpaths/bootclasspath.pb", |
Paul Duffin | 4d101b6 | 2021-03-24 15:42:20 +0000 | [diff] [blame] | 687 | "javalib/bar.jar", |
| 688 | "javalib/foo.jar", |
| 689 | }) |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 690 | |
| 691 | java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{ |
| 692 | `myapex.key`, |
Paul Duffin | 94f1963 | 2021-04-20 12:40:07 +0100 | [diff] [blame] | 693 | `mybootclasspathfragment`, |
Paul Duffin | 82886d6 | 2021-03-24 01:34:57 +0000 | [diff] [blame] | 694 | }) |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 695 | |
| 696 | apex := result.ModuleForTests("myapex", "android_common_myapex_image") |
| 697 | apexRule := apex.Rule("apexRule") |
| 698 | copyCommands := apexRule.Args["copy_commands"] |
| 699 | |
| 700 | // Make sure that the fragment provides the hidden API encoded dex jars to the APEX. |
| 701 | fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") |
| 702 | |
| 703 | info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) |
| 704 | |
| 705 | checkFragmentExportedDexJar := func(name string, expectedDexJar string) { |
| 706 | module := result.Module(name, "android_common_apex10000") |
Paul Duffin | 1a8010a | 2021-05-15 12:39:23 +0100 | [diff] [blame] | 707 | dexJar, err := info.DexBootJarPathForContentModule(module) |
| 708 | if err != nil { |
| 709 | t.Error(err) |
| 710 | } |
Paul Duffin | f2fa0b5 | 2021-05-14 18:21:45 +0100 | [diff] [blame] | 711 | android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar) |
| 712 | |
| 713 | expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name) |
| 714 | android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand) |
| 715 | } |
| 716 | |
Paul Duffin | 54c98f5 | 2021-05-15 08:54:30 +0100 | [diff] [blame] | 717 | checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar") |
| 718 | 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] | 719 | } |
| 720 | |
Paul Duffin | 48b6741 | 2021-06-23 16:13:50 +0100 | [diff] [blame^] | 721 | func getDexJarPath(result *android.TestResult, name string) string { |
| 722 | module := result.Module(name, "android_common") |
| 723 | return module.(java.UsesLibraryDependency).DexJarBuildPath().RelativeToTop().String() |
| 724 | } |
| 725 | |
| 726 | // TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are |
| 727 | // passed to the hiddenapi list tool. |
| 728 | func TestBootclasspathFragment_HiddenAPIList(t *testing.T) { |
| 729 | result := android.GroupFixturePreparers( |
| 730 | prepareForTestWithBootclasspathFragment, |
| 731 | prepareForTestWithArtApex, |
| 732 | prepareForTestWithMyapex, |
| 733 | // Configure bootclasspath jars to ensure that hidden API encoding is performed on them. |
| 734 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"), |
| 735 | java.FixtureConfigureUpdatableBootJars("myapex:foo", "myapex:bar"), |
| 736 | // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding |
| 737 | // is disabled. |
| 738 | android.FixtureAddTextFile("frameworks/base/Android.bp", ""), |
| 739 | |
| 740 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 741 | java.FixtureWithLastReleaseApis("foo", "quuz"), |
| 742 | ).RunTestWithBp(t, ` |
| 743 | apex { |
| 744 | name: "com.android.art", |
| 745 | key: "com.android.art.key", |
| 746 | bootclasspath_fragments: ["art-bootclasspath-fragment"], |
| 747 | updatable: false, |
| 748 | } |
| 749 | |
| 750 | apex_key { |
| 751 | name: "com.android.art.key", |
| 752 | public_key: "com.android.art.avbpubkey", |
| 753 | private_key: "com.android.art.pem", |
| 754 | } |
| 755 | |
| 756 | java_library { |
| 757 | name: "baz", |
| 758 | apex_available: [ |
| 759 | "com.android.art", |
| 760 | ], |
| 761 | srcs: ["b.java"], |
| 762 | compile_dex: true, |
| 763 | } |
| 764 | |
| 765 | java_sdk_library { |
| 766 | name: "quuz", |
| 767 | apex_available: [ |
| 768 | "com.android.art", |
| 769 | ], |
| 770 | srcs: ["b.java"], |
| 771 | compile_dex: true, |
| 772 | public: {enabled: true}, |
| 773 | system: {enabled: true}, |
| 774 | test: {enabled: true}, |
| 775 | module_lib: {enabled: true}, |
| 776 | } |
| 777 | |
| 778 | bootclasspath_fragment { |
| 779 | name: "art-bootclasspath-fragment", |
| 780 | image_name: "art", |
| 781 | // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above. |
| 782 | contents: ["baz", "quuz"], |
| 783 | apex_available: [ |
| 784 | "com.android.art", |
| 785 | ], |
| 786 | } |
| 787 | |
| 788 | apex { |
| 789 | name: "myapex", |
| 790 | key: "myapex.key", |
| 791 | bootclasspath_fragments: [ |
| 792 | "mybootclasspathfragment", |
| 793 | ], |
| 794 | updatable: false, |
| 795 | } |
| 796 | |
| 797 | apex_key { |
| 798 | name: "myapex.key", |
| 799 | public_key: "testkey.avbpubkey", |
| 800 | private_key: "testkey.pem", |
| 801 | } |
| 802 | |
| 803 | java_sdk_library { |
| 804 | name: "foo", |
| 805 | srcs: ["b.java"], |
| 806 | shared_library: false, |
| 807 | public: {enabled: true}, |
| 808 | apex_available: [ |
| 809 | "myapex", |
| 810 | ], |
| 811 | } |
| 812 | |
| 813 | java_library { |
| 814 | name: "bar", |
| 815 | srcs: ["b.java"], |
| 816 | installable: true, |
| 817 | apex_available: [ |
| 818 | "myapex", |
| 819 | ], |
| 820 | } |
| 821 | |
| 822 | bootclasspath_fragment { |
| 823 | name: "mybootclasspathfragment", |
| 824 | contents: [ |
| 825 | "foo", |
| 826 | "bar", |
| 827 | ], |
| 828 | apex_available: [ |
| 829 | "myapex", |
| 830 | ], |
| 831 | fragments: [ |
| 832 | { |
| 833 | apex: "com.android.art", |
| 834 | module: "art-bootclasspath-fragment", |
| 835 | }, |
| 836 | ], |
| 837 | } |
| 838 | `) |
| 839 | |
| 840 | java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{ |
| 841 | "art-bootclasspath-fragment", |
| 842 | "bar", |
| 843 | "dex2oatd", |
| 844 | "foo", |
| 845 | }) |
| 846 | |
| 847 | fooStubs := getDexJarPath(result, "foo.stubs") |
| 848 | quuzPublicStubs := getDexJarPath(result, "quuz.stubs") |
| 849 | quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system") |
| 850 | quuzTestStubs := getDexJarPath(result, "quuz.stubs.test") |
| 851 | |
| 852 | // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags. |
| 853 | fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000") |
| 854 | |
| 855 | rule := fragment.Rule("modularHiddenAPIStubFlagsFile") |
| 856 | command := rule.RuleParams.Command |
| 857 | android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list") |
| 858 | |
| 859 | // Make sure that the quuz stubs are available for resolving references from the implementation |
| 860 | // boot dex jars provided by this module. |
| 861 | android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzTestStubs) |
| 862 | |
| 863 | // Make sure that the quuz stubs are available for resolving references from the different API |
| 864 | // stubs provided by this module. |
| 865 | android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs) |
| 866 | android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs) |
| 867 | android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs) |
| 868 | } |
| 869 | |
Paul Duffin | a1d6025 | 2021-01-21 18:13:43 +0000 | [diff] [blame] | 870 | // TODO(b/177892522) - add test for host apex. |