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