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