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