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