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