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