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