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