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