Paul Duffin | b432df9 | 2021-03-22 22:09:42 +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 | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 18 | "fmt" |
| 19 | "strings" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 20 | "testing" |
| 21 | |
| 22 | "android/soong/android" |
Jiakai Zhang | b95998b | 2023-05-11 16:39:27 +0100 | [diff] [blame] | 23 | "android/soong/dexpreopt" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 24 | "android/soong/java" |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 25 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | // Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires |
| 31 | // apexes. |
| 32 | |
| 33 | var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers( |
Jiakai Zhang | b95998b | 2023-05-11 16:39:27 +0100 | [diff] [blame] | 34 | java.PrepareForTestWithJavaDefaultModules, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 35 | PrepareForTestWithApexBuildComponents, |
| 36 | ) |
| 37 | |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 38 | func TestPlatformBootclasspath_Fragments(t *testing.T) { |
| 39 | result := android.GroupFixturePreparers( |
| 40 | prepareForTestWithPlatformBootclasspath, |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 41 | prepareForTestWithMyapex, |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 42 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 43 | java.FixtureWithLastReleaseApis("foo"), |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 44 | java.FixtureConfigureApexBootJars("myapex:bar"), |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 45 | android.FixtureWithRootAndroidBp(` |
| 46 | platform_bootclasspath { |
| 47 | name: "platform-bootclasspath", |
| 48 | fragments: [ |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 49 | { |
| 50 | apex: "myapex", |
| 51 | module:"bar-fragment", |
| 52 | }, |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 53 | ], |
| 54 | hidden_api: { |
| 55 | unsupported: [ |
| 56 | "unsupported.txt", |
| 57 | ], |
| 58 | removed: [ |
| 59 | "removed.txt", |
| 60 | ], |
| 61 | max_target_r_low_priority: [ |
| 62 | "max-target-r-low-priority.txt", |
| 63 | ], |
| 64 | max_target_q: [ |
| 65 | "max-target-q.txt", |
| 66 | ], |
| 67 | max_target_p: [ |
| 68 | "max-target-p.txt", |
| 69 | ], |
| 70 | max_target_o_low_priority: [ |
| 71 | "max-target-o-low-priority.txt", |
| 72 | ], |
| 73 | blocked: [ |
| 74 | "blocked.txt", |
| 75 | ], |
| 76 | unsupported_packages: [ |
| 77 | "unsupported-packages.txt", |
| 78 | ], |
| 79 | }, |
| 80 | } |
| 81 | |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 82 | apex { |
| 83 | name: "myapex", |
| 84 | key: "myapex.key", |
| 85 | bootclasspath_fragments: [ |
| 86 | "bar-fragment", |
| 87 | ], |
| 88 | updatable: false, |
| 89 | } |
| 90 | |
| 91 | apex_key { |
| 92 | name: "myapex.key", |
| 93 | public_key: "testkey.avbpubkey", |
| 94 | private_key: "testkey.pem", |
| 95 | } |
| 96 | |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 97 | bootclasspath_fragment { |
| 98 | name: "bar-fragment", |
| 99 | contents: ["bar"], |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 100 | apex_available: ["myapex"], |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 101 | api: { |
| 102 | stub_libs: ["foo"], |
| 103 | }, |
| 104 | hidden_api: { |
| 105 | unsupported: [ |
| 106 | "bar-unsupported.txt", |
| 107 | ], |
| 108 | removed: [ |
| 109 | "bar-removed.txt", |
| 110 | ], |
| 111 | max_target_r_low_priority: [ |
| 112 | "bar-max-target-r-low-priority.txt", |
| 113 | ], |
| 114 | max_target_q: [ |
| 115 | "bar-max-target-q.txt", |
| 116 | ], |
| 117 | max_target_p: [ |
| 118 | "bar-max-target-p.txt", |
| 119 | ], |
| 120 | max_target_o_low_priority: [ |
| 121 | "bar-max-target-o-low-priority.txt", |
| 122 | ], |
| 123 | blocked: [ |
| 124 | "bar-blocked.txt", |
| 125 | ], |
| 126 | unsupported_packages: [ |
| 127 | "bar-unsupported-packages.txt", |
| 128 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 129 | split_packages: ["*"], |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 130 | }, |
| 131 | } |
| 132 | |
| 133 | java_library { |
| 134 | name: "bar", |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 135 | apex_available: ["myapex"], |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 136 | srcs: ["a.java"], |
| 137 | system_modules: "none", |
| 138 | sdk_version: "none", |
| 139 | compile_dex: true, |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 140 | permitted_packages: ["bar"], |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | java_sdk_library { |
| 144 | name: "foo", |
| 145 | srcs: ["a.java"], |
| 146 | public: { |
| 147 | enabled: true, |
| 148 | }, |
| 149 | compile_dex: true, |
| 150 | } |
| 151 | `), |
| 152 | ).RunTest(t) |
| 153 | |
| 154 | pbcp := result.Module("platform-bootclasspath", "android_common") |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 155 | info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider) |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 156 | |
| 157 | for _, category := range java.HiddenAPIFlagFileCategories { |
Cole Faust | 22e8abc | 2024-01-23 17:52:13 -0800 | [diff] [blame] | 158 | name := category.PropertyName() |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 159 | message := fmt.Sprintf("category %s", name) |
| 160 | filename := strings.ReplaceAll(name, "_", "-") |
| 161 | expected := []string{fmt.Sprintf("%s.txt", filename), fmt.Sprintf("bar-%s.txt", filename)} |
| 162 | android.AssertPathsRelativeToTopEquals(t, message, expected, info.FlagsFilesByCategory[category]) |
| 163 | } |
| 164 | |
Paul Duffin | dc3f956 | 2021-06-09 15:31:05 +0100 | [diff] [blame] | 165 | android.AssertPathsRelativeToTopEquals(t, "annotation flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/annotation-flags.csv"}, info.AnnotationFlagsPaths) |
| 166 | android.AssertPathsRelativeToTopEquals(t, "metadata flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/metadata.csv"}, info.MetadataPaths) |
| 167 | android.AssertPathsRelativeToTopEquals(t, "index flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/index.csv"}, info.IndexPaths) |
Paul Duffin | 67b9d61 | 2021-07-21 17:38:47 +0100 | [diff] [blame] | 168 | |
Paul Duffin | 280bae6 | 2021-07-20 18:03:53 +0100 | [diff] [blame] | 169 | android.AssertArrayString(t, "stub flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-stub-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop()) |
| 170 | android.AssertArrayString(t, "all flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/filtered-flags.csv:out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop()) |
Paul Duffin | ffa8375 | 2021-06-09 14:32:53 +0100 | [diff] [blame] | 171 | } |
| 172 | |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 173 | // TestPlatformBootclasspath_LegacyPrebuiltFragment verifies that the |
| 174 | // prebuilt_bootclasspath_fragment falls back to using the complete stub-flags/all-flags if the |
| 175 | // filtered files are not provided. |
| 176 | // |
| 177 | // TODO: Remove once all prebuilts use the filtered_... properties. |
| 178 | func TestPlatformBootclasspath_LegacyPrebuiltFragment(t *testing.T) { |
| 179 | result := android.GroupFixturePreparers( |
| 180 | prepareForTestWithPlatformBootclasspath, |
| 181 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 182 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 183 | ).RunTestWithBp(t, ` |
| 184 | prebuilt_apex { |
| 185 | name: "myapex", |
| 186 | src: "myapex.apex", |
| 187 | exported_bootclasspath_fragments: ["mybootclasspath-fragment"], |
| 188 | } |
| 189 | |
| 190 | // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred |
| 191 | // because AlwaysUsePrebuiltSdks() is true. |
| 192 | java_sdk_library_import { |
| 193 | name: "foo", |
| 194 | prefer: false, |
| 195 | shared_library: false, |
| 196 | permitted_packages: ["foo"], |
| 197 | public: { |
| 198 | jars: ["sdk_library/public/foo-stubs.jar"], |
| 199 | stub_srcs: ["sdk_library/public/foo_stub_sources"], |
| 200 | current_api: "sdk_library/public/foo.txt", |
| 201 | removed_api: "sdk_library/public/foo-removed.txt", |
| 202 | sdk_version: "current", |
| 203 | }, |
| 204 | apex_available: ["myapex"], |
| 205 | } |
| 206 | |
| 207 | prebuilt_bootclasspath_fragment { |
| 208 | name: "mybootclasspath-fragment", |
| 209 | apex_available: [ |
| 210 | "myapex", |
| 211 | ], |
| 212 | contents: [ |
| 213 | "foo", |
| 214 | ], |
| 215 | hidden_api: { |
| 216 | stub_flags: "prebuilt-stub-flags.csv", |
| 217 | annotation_flags: "prebuilt-annotation-flags.csv", |
| 218 | metadata: "prebuilt-metadata.csv", |
| 219 | index: "prebuilt-index.csv", |
| 220 | all_flags: "prebuilt-all-flags.csv", |
| 221 | }, |
| 222 | } |
| 223 | |
| 224 | platform_bootclasspath { |
| 225 | name: "myplatform-bootclasspath", |
| 226 | fragments: [ |
| 227 | { |
| 228 | apex: "myapex", |
| 229 | module:"mybootclasspath-fragment", |
| 230 | }, |
| 231 | ], |
| 232 | } |
| 233 | `, |
| 234 | ) |
| 235 | |
| 236 | pbcp := result.Module("myplatform-bootclasspath", "android_common") |
Colin Cross | 5a37718 | 2023-12-14 14:46:23 -0800 | [diff] [blame] | 237 | info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider) |
Paul Duffin | 191be3a | 2021-08-10 16:14:16 +0100 | [diff] [blame] | 238 | |
| 239 | android.AssertArrayString(t, "stub flags", []string{"prebuilt-stub-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop()) |
| 240 | android.AssertArrayString(t, "all flags", []string{"prebuilt-all-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop()) |
| 241 | } |
| 242 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 243 | func TestPlatformBootclasspathDependencies(t *testing.T) { |
| 244 | result := android.GroupFixturePreparers( |
| 245 | prepareForTestWithPlatformBootclasspath, |
| 246 | prepareForTestWithArtApex, |
| 247 | prepareForTestWithMyapex, |
| 248 | // Configure some libraries in the art and framework boot images. |
Paul Duffin | 60264a0 | 2021-04-12 20:02:36 +0100 | [diff] [blame] | 249 | java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"), |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 250 | java.FixtureConfigureApexBootJars("myapex:bar"), |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 251 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 252 | java.FixtureWithLastReleaseApis("foo"), |
Jiakai Zhang | b95998b | 2023-05-11 16:39:27 +0100 | [diff] [blame] | 253 | java.PrepareForTestWithDexpreopt, |
| 254 | dexpreopt.FixtureDisableDexpreoptBootImages(false), |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 255 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 256 | variables.BuildFlags = map[string]string{ |
| 257 | "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", |
| 258 | } |
| 259 | }), |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 260 | ).RunTestWithBp(t, ` |
| 261 | apex { |
| 262 | name: "com.android.art", |
| 263 | key: "com.android.art.key", |
| 264 | bootclasspath_fragments: [ |
| 265 | "art-bootclasspath-fragment", |
| 266 | ], |
| 267 | updatable: false, |
| 268 | } |
| 269 | |
| 270 | apex_key { |
| 271 | name: "com.android.art.key", |
| 272 | public_key: "com.android.art.avbpubkey", |
| 273 | private_key: "com.android.art.pem", |
| 274 | } |
| 275 | |
| 276 | bootclasspath_fragment { |
| 277 | name: "art-bootclasspath-fragment", |
satayev | abcd597 | 2021-08-06 17:49:46 +0100 | [diff] [blame] | 278 | image_name: "art", |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 279 | apex_available: [ |
| 280 | "com.android.art", |
| 281 | ], |
| 282 | contents: [ |
| 283 | "baz", |
| 284 | "quuz", |
| 285 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 286 | hidden_api: { |
| 287 | split_packages: ["*"], |
| 288 | }, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | java_library { |
| 292 | name: "baz", |
| 293 | apex_available: [ |
| 294 | "com.android.art", |
| 295 | ], |
| 296 | srcs: ["b.java"], |
| 297 | installable: true, |
| 298 | } |
| 299 | |
| 300 | // Add a java_import that is not preferred and so won't have an appropriate apex variant created |
| 301 | // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it. |
| 302 | java_import { |
| 303 | name: "baz", |
| 304 | apex_available: [ |
| 305 | "com.android.art", |
| 306 | ], |
| 307 | jars: ["b.jar"], |
| 308 | } |
| 309 | |
| 310 | java_library { |
| 311 | name: "quuz", |
| 312 | apex_available: [ |
| 313 | "com.android.art", |
| 314 | ], |
| 315 | srcs: ["b.java"], |
| 316 | installable: true, |
| 317 | } |
| 318 | |
| 319 | apex { |
| 320 | name: "myapex", |
| 321 | key: "myapex.key", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 322 | bootclasspath_fragments: [ |
| 323 | "my-bootclasspath-fragment", |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 324 | ], |
| 325 | updatable: false, |
| 326 | } |
| 327 | |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 328 | bootclasspath_fragment { |
| 329 | name: "my-bootclasspath-fragment", |
| 330 | contents: ["bar"], |
| 331 | apex_available: ["myapex"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 332 | hidden_api: { |
| 333 | split_packages: ["*"], |
| 334 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 335 | } |
| 336 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 337 | apex_key { |
| 338 | name: "myapex.key", |
| 339 | public_key: "testkey.avbpubkey", |
| 340 | private_key: "testkey.pem", |
| 341 | } |
| 342 | |
| 343 | java_sdk_library { |
| 344 | name: "foo", |
| 345 | srcs: ["b.java"], |
| 346 | } |
| 347 | |
| 348 | java_library { |
| 349 | name: "bar", |
| 350 | srcs: ["b.java"], |
| 351 | installable: true, |
| 352 | apex_available: ["myapex"], |
| 353 | permitted_packages: ["bar"], |
| 354 | } |
| 355 | |
| 356 | platform_bootclasspath { |
| 357 | name: "myplatform-bootclasspath", |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 358 | |
| 359 | fragments: [ |
| 360 | { |
| 361 | apex: "com.android.art", |
| 362 | module: "art-bootclasspath-fragment", |
| 363 | }, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 364 | { |
| 365 | apex: "myapex", |
| 366 | module: "my-bootclasspath-fragment", |
| 367 | }, |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 368 | ], |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 369 | } |
| 370 | `, |
| 371 | ) |
| 372 | |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 373 | java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{ |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 374 | // The configured contents of BootJars. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 375 | "com.android.art:baz", |
| 376 | "com.android.art:quuz", |
| 377 | "platform:foo", |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 378 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 379 | // The configured contents of ApexBootJars. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 380 | "myapex:bar", |
| 381 | }) |
| 382 | |
| 383 | java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{ |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 384 | "com.android.art:art-bootclasspath-fragment", |
| 385 | "myapex:my-bootclasspath-fragment", |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 386 | }) |
| 387 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 388 | // Make sure that the myplatform-bootclasspath has the correct dependencies. |
| 389 | CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{ |
Spandan Das | 64c9e0c | 2023-12-20 20:13:34 +0000 | [diff] [blame] | 390 | // source vs prebuilt selection metadata module |
| 391 | `platform:all_apex_contributions`, |
| 392 | |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 393 | // The following are stubs. |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 394 | `platform:android_stubs_current_exportable`, |
| 395 | `platform:android_system_stubs_current_exportable`, |
| 396 | `platform:android_test_stubs_current_exportable`, |
| 397 | `platform:legacy.core.platform.api.stubs.exportable`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 398 | |
| 399 | // Needed for generating the boot image. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 400 | `platform:dex2oatd`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 401 | |
| 402 | // The configured contents of BootJars. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 403 | `com.android.art:baz`, |
| 404 | `com.android.art:quuz`, |
| 405 | `platform:foo`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 406 | |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 407 | // The configured contents of ApexBootJars. |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 408 | `myapex:bar`, |
Paul Duffin | 74431d5 | 2021-04-21 14:10:42 +0100 | [diff] [blame] | 409 | |
| 410 | // The fragments. |
Paul Duffin | 62d8c3b | 2021-04-07 20:35:11 +0100 | [diff] [blame] | 411 | `com.android.art:art-bootclasspath-fragment`, |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 412 | `myapex:my-bootclasspath-fragment`, |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 413 | }) |
| 414 | } |
| 415 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 416 | // TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 417 | // AlwaysUsePrebuiltSdk() returns true. |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 418 | func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) { |
| 419 | result := android.GroupFixturePreparers( |
| 420 | prepareForTestWithPlatformBootclasspath, |
| 421 | prepareForTestWithMyapex, |
| 422 | // Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 423 | // of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order |
| 424 | // matters, so that the dependencies resolved by the platform_bootclasspath matches the |
| 425 | // configured list. |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 426 | java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"), |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 427 | java.PrepareForTestWithJavaSdkLibraryFiles, |
| 428 | android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { |
| 429 | variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true) |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 430 | variables.BuildFlags = map[string]string{ |
| 431 | "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true", |
| 432 | } |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 433 | }), |
| 434 | java.FixtureWithPrebuiltApis(map[string][]string{ |
| 435 | "current": {}, |
| 436 | "30": {"foo"}, |
| 437 | }), |
| 438 | ).RunTestWithBp(t, ` |
| 439 | apex { |
| 440 | name: "myapex", |
| 441 | key: "myapex.key", |
| 442 | bootclasspath_fragments: [ |
| 443 | "mybootclasspath-fragment", |
| 444 | ], |
| 445 | updatable: false, |
| 446 | } |
| 447 | |
| 448 | apex_key { |
| 449 | name: "myapex.key", |
| 450 | public_key: "testkey.avbpubkey", |
| 451 | private_key: "testkey.pem", |
| 452 | } |
| 453 | |
| 454 | java_library { |
| 455 | name: "bar", |
| 456 | srcs: ["b.java"], |
| 457 | installable: true, |
| 458 | apex_available: ["myapex"], |
| 459 | permitted_packages: ["bar"], |
| 460 | } |
| 461 | |
| 462 | java_sdk_library { |
| 463 | name: "foo", |
| 464 | srcs: ["b.java"], |
| 465 | shared_library: false, |
| 466 | public: { |
| 467 | enabled: true, |
| 468 | }, |
| 469 | apex_available: ["myapex"], |
| 470 | permitted_packages: ["foo"], |
| 471 | } |
| 472 | |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 473 | prebuilt_apex { |
| 474 | name: "myapex", |
| 475 | src: "myapex.apex", |
| 476 | exported_bootclasspath_fragments: ["mybootclasspath-fragment"], |
| 477 | } |
| 478 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 479 | // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred |
| 480 | // because AlwaysUsePrebuiltSdks() is true. |
| 481 | java_sdk_library_import { |
| 482 | name: "foo", |
| 483 | prefer: false, |
| 484 | shared_library: false, |
Paul Duffin | 630b11e | 2021-07-15 13:35:26 +0100 | [diff] [blame] | 485 | permitted_packages: ["foo"], |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 486 | public: { |
| 487 | jars: ["sdk_library/public/foo-stubs.jar"], |
| 488 | stub_srcs: ["sdk_library/public/foo_stub_sources"], |
| 489 | current_api: "sdk_library/public/foo.txt", |
| 490 | removed_api: "sdk_library/public/foo-removed.txt", |
| 491 | sdk_version: "current", |
| 492 | }, |
| 493 | apex_available: ["myapex"], |
| 494 | } |
| 495 | |
| 496 | // This always depends on the source foo module, its dependencies are not affected by the |
| 497 | // AlwaysUsePrebuiltSdks(). |
| 498 | bootclasspath_fragment { |
| 499 | name: "mybootclasspath-fragment", |
| 500 | apex_available: [ |
| 501 | "myapex", |
| 502 | ], |
| 503 | contents: [ |
| 504 | "foo", "bar", |
| 505 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 506 | hidden_api: { |
| 507 | split_packages: ["*"], |
| 508 | }, |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 509 | } |
| 510 | |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 511 | prebuilt_bootclasspath_fragment { |
| 512 | name: "mybootclasspath-fragment", |
| 513 | apex_available: [ |
| 514 | "myapex", |
| 515 | ], |
| 516 | contents: [ |
| 517 | "foo", |
| 518 | ], |
| 519 | hidden_api: { |
| 520 | stub_flags: "", |
| 521 | annotation_flags: "", |
| 522 | metadata: "", |
| 523 | index: "", |
| 524 | all_flags: "", |
| 525 | }, |
| 526 | } |
| 527 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 528 | platform_bootclasspath { |
| 529 | name: "myplatform-bootclasspath", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 530 | fragments: [ |
| 531 | { |
| 532 | apex: "myapex", |
| 533 | module:"mybootclasspath-fragment", |
| 534 | }, |
| 535 | ], |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 536 | } |
| 537 | `, |
| 538 | ) |
| 539 | |
| 540 | java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{ |
| 541 | // The configured contents of BootJars. |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 542 | "myapex:prebuilt_foo", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 543 | "myapex:bar", |
| 544 | }) |
| 545 | |
| 546 | // Make sure that the myplatform-bootclasspath has the correct dependencies. |
| 547 | CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{ |
Spandan Das | 64c9e0c | 2023-12-20 20:13:34 +0000 | [diff] [blame] | 548 | // source vs prebuilt selection metadata module |
| 549 | `platform:all_apex_contributions`, |
| 550 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 551 | // The following are stubs. |
| 552 | "platform:prebuilt_sdk_public_current_android", |
| 553 | "platform:prebuilt_sdk_system_current_android", |
| 554 | "platform:prebuilt_sdk_test_current_android", |
| 555 | |
| 556 | // Not a prebuilt as no prebuilt existed when it was added. |
Jihoon Kang | bd09345 | 2023-12-26 19:08:01 +0000 | [diff] [blame] | 557 | "platform:legacy.core.platform.api.stubs.exportable", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 558 | |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 559 | // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt |
| 560 | // modules when available as it does not know which one will be preferred. |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 561 | "myapex:foo", |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 562 | "myapex:prebuilt_foo", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 563 | |
| 564 | // Only a source module exists. |
| 565 | "myapex:bar", |
Paul Duffin | 89f570a | 2021-06-16 01:42:33 +0100 | [diff] [blame] | 566 | |
| 567 | // The fragments. |
| 568 | "myapex:mybootclasspath-fragment", |
Martin Stjernholm | b1e61cb | 2021-09-08 21:56:18 +0100 | [diff] [blame] | 569 | "myapex:prebuilt_mybootclasspath-fragment", |
Paul Duffin | 7487a7a | 2021-05-19 09:36:09 +0100 | [diff] [blame] | 570 | }) |
| 571 | } |
| 572 | |
Paul Duffin | b432df9 | 2021-03-22 22:09:42 +0000 | [diff] [blame] | 573 | // CheckModuleDependencies checks the dependencies of the selected module against the expected list. |
| 574 | // |
| 575 | // The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the |
| 576 | // name of the apex, or platform is it is not part of an apex and <module> is the module name. |
| 577 | func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) { |
| 578 | t.Helper() |
| 579 | module := ctx.ModuleForTests(name, variant).Module() |
| 580 | modules := []android.Module{} |
| 581 | ctx.VisitDirectDeps(module, func(m blueprint.Module) { |
| 582 | modules = append(modules, m.(android.Module)) |
| 583 | }) |
| 584 | |
| 585 | pairs := java.ApexNamePairsFromModules(ctx, modules) |
| 586 | android.AssertDeepEquals(t, "module dependencies", expected, pairs) |
| 587 | } |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 588 | |
| 589 | // TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in |
| 590 | // platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config |
| 591 | // by setting generate_classpaths_proto property to false. |
| 592 | func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) { |
| 593 | result := android.GroupFixturePreparers( |
| 594 | prepareForTestWithPlatformBootclasspath, |
| 595 | prepareForTestWithMyapex, |
satayev | d604b21 | 2021-07-21 14:23:52 +0100 | [diff] [blame] | 596 | java.FixtureConfigureApexBootJars("myapex:foo"), |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 597 | android.FixtureWithRootAndroidBp(` |
| 598 | platform_bootclasspath { |
| 599 | name: "platform-bootclasspath", |
| 600 | fragments: [ |
| 601 | { |
| 602 | apex: "myapex", |
| 603 | module:"foo-fragment", |
| 604 | }, |
| 605 | ], |
| 606 | } |
| 607 | |
| 608 | apex { |
| 609 | name: "myapex", |
| 610 | key: "myapex.key", |
| 611 | bootclasspath_fragments: ["foo-fragment"], |
| 612 | updatable: false, |
| 613 | } |
| 614 | |
| 615 | apex_key { |
| 616 | name: "myapex.key", |
| 617 | public_key: "testkey.avbpubkey", |
| 618 | private_key: "testkey.pem", |
| 619 | } |
| 620 | |
| 621 | bootclasspath_fragment { |
| 622 | name: "foo-fragment", |
| 623 | generate_classpaths_proto: false, |
| 624 | contents: ["foo"], |
| 625 | apex_available: ["myapex"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 626 | hidden_api: { |
| 627 | split_packages: ["*"], |
| 628 | }, |
satayev | b309050 | 2021-06-15 17:49:10 +0100 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | java_library { |
| 632 | name: "foo", |
| 633 | srcs: ["a.java"], |
| 634 | system_modules: "none", |
| 635 | sdk_version: "none", |
| 636 | compile_dex: true, |
| 637 | apex_available: ["myapex"], |
| 638 | permitted_packages: ["foo"], |
| 639 | } |
| 640 | `), |
| 641 | ).RunTest(t) |
| 642 | |
| 643 | java.CheckClasspathFragmentProtoContentInfoProvider(t, result, |
| 644 | true, // proto should be generated |
| 645 | "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath |
| 646 | "bootclasspath.pb", |
| 647 | "out/soong/target/product/test_device/system/etc/classpaths", |
| 648 | ) |
| 649 | } |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 650 | |
| 651 | func TestBootJarNotInApex(t *testing.T) { |
| 652 | android.GroupFixturePreparers( |
| 653 | prepareForTestWithPlatformBootclasspath, |
| 654 | PrepareForTestWithApexBuildComponents, |
| 655 | prepareForTestWithMyapex, |
| 656 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 657 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 658 | `dependency "foo" of "myplatform-bootclasspath" missing variant`)). |
| 659 | RunTestWithBp(t, ` |
| 660 | apex { |
| 661 | name: "myapex", |
| 662 | key: "myapex.key", |
| 663 | updatable: false, |
| 664 | } |
| 665 | |
| 666 | apex_key { |
| 667 | name: "myapex.key", |
| 668 | public_key: "testkey.avbpubkey", |
| 669 | private_key: "testkey.pem", |
| 670 | } |
| 671 | |
| 672 | java_library { |
| 673 | name: "foo", |
| 674 | srcs: ["b.java"], |
| 675 | installable: true, |
| 676 | apex_available: [ |
| 677 | "myapex", |
| 678 | ], |
| 679 | } |
| 680 | |
| 681 | bootclasspath_fragment { |
| 682 | name: "not-in-apex-fragment", |
| 683 | contents: [ |
| 684 | "foo", |
| 685 | ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 686 | hidden_api: { |
| 687 | split_packages: ["*"], |
| 688 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | platform_bootclasspath { |
| 692 | name: "myplatform-bootclasspath", |
| 693 | } |
| 694 | `) |
| 695 | } |
| 696 | |
| 697 | func TestBootFragmentNotInApex(t *testing.T) { |
| 698 | android.GroupFixturePreparers( |
| 699 | prepareForTestWithPlatformBootclasspath, |
| 700 | PrepareForTestWithApexBuildComponents, |
| 701 | prepareForTestWithMyapex, |
| 702 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 703 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 704 | `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, ` |
| 705 | apex { |
| 706 | name: "myapex", |
| 707 | key: "myapex.key", |
| 708 | java_libs: ["foo"], |
| 709 | updatable: false, |
| 710 | } |
| 711 | |
| 712 | apex_key { |
| 713 | name: "myapex.key", |
| 714 | public_key: "testkey.avbpubkey", |
| 715 | private_key: "testkey.pem", |
| 716 | } |
| 717 | |
| 718 | java_library { |
| 719 | name: "foo", |
| 720 | srcs: ["b.java"], |
| 721 | installable: true, |
| 722 | apex_available: ["myapex"], |
| 723 | permitted_packages: ["foo"], |
| 724 | } |
| 725 | |
| 726 | bootclasspath_fragment { |
| 727 | name: "not-in-apex-fragment", |
| 728 | contents: ["foo"], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 729 | hidden_api: { |
| 730 | split_packages: ["*"], |
| 731 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | platform_bootclasspath { |
| 735 | name: "myplatform-bootclasspath", |
| 736 | } |
| 737 | `) |
| 738 | } |
| 739 | |
| 740 | func TestNonBootJarInFragment(t *testing.T) { |
| 741 | android.GroupFixturePreparers( |
| 742 | prepareForTestWithPlatformBootclasspath, |
| 743 | PrepareForTestWithApexBuildComponents, |
| 744 | prepareForTestWithMyapex, |
| 745 | java.FixtureConfigureApexBootJars("myapex:foo"), |
| 746 | ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern( |
| 747 | `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)). |
| 748 | RunTestWithBp(t, ` |
| 749 | apex { |
| 750 | name: "myapex", |
| 751 | key: "myapex.key", |
| 752 | bootclasspath_fragments: ["apex-fragment"], |
| 753 | updatable: false, |
| 754 | } |
| 755 | |
| 756 | apex_key { |
| 757 | name: "myapex.key", |
| 758 | public_key: "testkey.avbpubkey", |
| 759 | private_key: "testkey.pem", |
| 760 | } |
| 761 | |
| 762 | java_library { |
| 763 | name: "foo", |
| 764 | srcs: ["b.java"], |
| 765 | installable: true, |
| 766 | apex_available: ["myapex"], |
| 767 | permitted_packages: ["foo"], |
| 768 | } |
| 769 | |
| 770 | java_library { |
| 771 | name: "bar", |
| 772 | srcs: ["b.java"], |
| 773 | installable: true, |
| 774 | apex_available: ["myapex"], |
| 775 | permitted_packages: ["bar"], |
| 776 | } |
| 777 | |
| 778 | bootclasspath_fragment { |
| 779 | name: "apex-fragment", |
| 780 | contents: ["foo", "bar"], |
| 781 | apex_available:[ "myapex" ], |
Paul Duffin | 9fd5647 | 2022-03-31 15:42:30 +0100 | [diff] [blame] | 782 | hidden_api: { |
| 783 | split_packages: ["*"], |
| 784 | }, |
satayev | d34eb0c | 2021-08-06 13:20:28 +0100 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | platform_bootclasspath { |
| 788 | name: "myplatform-bootclasspath", |
| 789 | fragments: [{ |
| 790 | apex: "myapex", |
| 791 | module:"apex-fragment", |
| 792 | }], |
| 793 | } |
| 794 | `) |
| 795 | } |