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