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