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