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