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