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