blob: 01b616bb6be9aa045d963f6a0e23596e0f2f85eb [file] [log] [blame]
Paul Duffinb432df92021-03-22 22:09:42 +00001// 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
15package apex
16
17import (
Paul Duffinffa83752021-06-09 14:32:53 +010018 "fmt"
19 "strings"
Paul Duffinb432df92021-03-22 22:09:42 +000020 "testing"
21
22 "android/soong/android"
Jiakai Zhangb95998b2023-05-11 16:39:27 +010023 "android/soong/dexpreopt"
Paul Duffinb432df92021-03-22 22:09:42 +000024 "android/soong/java"
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +010025
Paul Duffinb432df92021-03-22 22:09:42 +000026 "github.com/google/blueprint"
Paul Duffin7487a7a2021-05-19 09:36:09 +010027 "github.com/google/blueprint/proptools"
Paul Duffinb432df92021-03-22 22:09:42 +000028)
29
30// Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires
31// apexes.
32
33var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers(
Jiakai Zhangb95998b2023-05-11 16:39:27 +010034 java.PrepareForTestWithJavaDefaultModules,
Paul Duffinb432df92021-03-22 22:09:42 +000035 PrepareForTestWithApexBuildComponents,
36)
37
Paul Duffinffa83752021-06-09 14:32:53 +010038func TestPlatformBootclasspath_Fragments(t *testing.T) {
39 result := android.GroupFixturePreparers(
40 prepareForTestWithPlatformBootclasspath,
Paul Duffindc3f9562021-06-09 15:31:05 +010041 prepareForTestWithMyapex,
Paul Duffinffa83752021-06-09 14:32:53 +010042 java.PrepareForTestWithJavaSdkLibraryFiles,
43 java.FixtureWithLastReleaseApis("foo"),
satayevabcd5972021-08-06 17:49:46 +010044 java.FixtureConfigureApexBootJars("myapex:bar"),
Paul Duffinffa83752021-06-09 14:32:53 +010045 android.FixtureWithRootAndroidBp(`
46 platform_bootclasspath {
47 name: "platform-bootclasspath",
48 fragments: [
Paul Duffindc3f9562021-06-09 15:31:05 +010049 {
50 apex: "myapex",
51 module:"bar-fragment",
52 },
Paul Duffinffa83752021-06-09 14:32:53 +010053 ],
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 Duffindc3f9562021-06-09 15:31:05 +010082 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 Duffinffa83752021-06-09 14:32:53 +010097 bootclasspath_fragment {
98 name: "bar-fragment",
99 contents: ["bar"],
Paul Duffindc3f9562021-06-09 15:31:05 +0100100 apex_available: ["myapex"],
Paul Duffinffa83752021-06-09 14:32:53 +0100101 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 Duffin9fd56472022-03-31 15:42:30 +0100129 split_packages: ["*"],
Paul Duffinffa83752021-06-09 14:32:53 +0100130 },
131 }
132
133 java_library {
134 name: "bar",
Paul Duffindc3f9562021-06-09 15:31:05 +0100135 apex_available: ["myapex"],
Paul Duffinffa83752021-06-09 14:32:53 +0100136 srcs: ["a.java"],
137 system_modules: "none",
138 sdk_version: "none",
139 compile_dex: true,
Paul Duffindc3f9562021-06-09 15:31:05 +0100140 permitted_packages: ["bar"],
Paul Duffinffa83752021-06-09 14:32:53 +0100141 }
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 Cross5a377182023-12-14 14:46:23 -0800155 info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider)
Paul Duffinffa83752021-06-09 14:32:53 +0100156
157 for _, category := range java.HiddenAPIFlagFileCategories {
158 name := category.PropertyName
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 Duffindc3f9562021-06-09 15:31:05 +0100165 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 Duffin67b9d612021-07-21 17:38:47 +0100168
Paul Duffin280bae62021-07-20 18:03:53 +0100169 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 Duffinffa83752021-06-09 14:32:53 +0100171}
172
Paul Duffin191be3a2021-08-10 16:14:16 +0100173// 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.
178func 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 Cross5a377182023-12-14 14:46:23 -0800237 info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider)
Paul Duffin191be3a2021-08-10 16:14:16 +0100238
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 Duffinb432df92021-03-22 22:09:42 +0000243func 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 Duffin60264a02021-04-12 20:02:36 +0100249 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"),
satayevd604b212021-07-21 14:23:52 +0100250 java.FixtureConfigureApexBootJars("myapex:bar"),
Paul Duffinb432df92021-03-22 22:09:42 +0000251 java.PrepareForTestWithJavaSdkLibraryFiles,
252 java.FixtureWithLastReleaseApis("foo"),
Jiakai Zhangb95998b2023-05-11 16:39:27 +0100253 java.PrepareForTestWithDexpreopt,
254 dexpreopt.FixtureDisableDexpreoptBootImages(false),
Paul Duffinb432df92021-03-22 22:09:42 +0000255 ).RunTestWithBp(t, `
256 apex {
257 name: "com.android.art",
258 key: "com.android.art.key",
259 bootclasspath_fragments: [
260 "art-bootclasspath-fragment",
261 ],
262 updatable: false,
263 }
264
265 apex_key {
266 name: "com.android.art.key",
267 public_key: "com.android.art.avbpubkey",
268 private_key: "com.android.art.pem",
269 }
270
271 bootclasspath_fragment {
272 name: "art-bootclasspath-fragment",
satayevabcd5972021-08-06 17:49:46 +0100273 image_name: "art",
Paul Duffinb432df92021-03-22 22:09:42 +0000274 apex_available: [
275 "com.android.art",
276 ],
277 contents: [
278 "baz",
279 "quuz",
280 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100281 hidden_api: {
282 split_packages: ["*"],
283 },
Paul Duffinb432df92021-03-22 22:09:42 +0000284 }
285
286 java_library {
287 name: "baz",
288 apex_available: [
289 "com.android.art",
290 ],
291 srcs: ["b.java"],
292 installable: true,
293 }
294
295 // Add a java_import that is not preferred and so won't have an appropriate apex variant created
296 // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it.
297 java_import {
298 name: "baz",
299 apex_available: [
300 "com.android.art",
301 ],
302 jars: ["b.jar"],
303 }
304
305 java_library {
306 name: "quuz",
307 apex_available: [
308 "com.android.art",
309 ],
310 srcs: ["b.java"],
311 installable: true,
312 }
313
314 apex {
315 name: "myapex",
316 key: "myapex.key",
Paul Duffin89f570a2021-06-16 01:42:33 +0100317 bootclasspath_fragments: [
318 "my-bootclasspath-fragment",
Paul Duffinb432df92021-03-22 22:09:42 +0000319 ],
320 updatable: false,
321 }
322
Paul Duffin89f570a2021-06-16 01:42:33 +0100323 bootclasspath_fragment {
324 name: "my-bootclasspath-fragment",
325 contents: ["bar"],
326 apex_available: ["myapex"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100327 hidden_api: {
328 split_packages: ["*"],
329 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100330 }
331
Paul Duffinb432df92021-03-22 22:09:42 +0000332 apex_key {
333 name: "myapex.key",
334 public_key: "testkey.avbpubkey",
335 private_key: "testkey.pem",
336 }
337
338 java_sdk_library {
339 name: "foo",
340 srcs: ["b.java"],
341 }
342
343 java_library {
344 name: "bar",
345 srcs: ["b.java"],
346 installable: true,
347 apex_available: ["myapex"],
348 permitted_packages: ["bar"],
349 }
350
351 platform_bootclasspath {
352 name: "myplatform-bootclasspath",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100353
354 fragments: [
355 {
356 apex: "com.android.art",
357 module: "art-bootclasspath-fragment",
358 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100359 {
360 apex: "myapex",
361 module: "my-bootclasspath-fragment",
362 },
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100363 ],
Paul Duffinb432df92021-03-22 22:09:42 +0000364 }
365`,
366 )
367
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100368 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100369 // The configured contents of BootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100370 "com.android.art:baz",
371 "com.android.art:quuz",
372 "platform:foo",
Paul Duffin74431d52021-04-21 14:10:42 +0100373
satayevd604b212021-07-21 14:23:52 +0100374 // The configured contents of ApexBootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100375 "myapex:bar",
376 })
377
378 java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{
Paul Duffin89f570a2021-06-16 01:42:33 +0100379 "com.android.art:art-bootclasspath-fragment",
380 "myapex:my-bootclasspath-fragment",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100381 })
382
Paul Duffinb432df92021-03-22 22:09:42 +0000383 // Make sure that the myplatform-bootclasspath has the correct dependencies.
384 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
Spandan Das64c9e0c2023-12-20 20:13:34 +0000385 // source vs prebuilt selection metadata module
386 `platform:all_apex_contributions`,
387
Paul Duffin74431d52021-04-21 14:10:42 +0100388 // The following are stubs.
389 `platform:android_stubs_current`,
390 `platform:android_system_stubs_current`,
391 `platform:android_test_stubs_current`,
392 `platform:legacy.core.platform.api.stubs`,
393
394 // Needed for generating the boot image.
Paul Duffinb432df92021-03-22 22:09:42 +0000395 `platform:dex2oatd`,
Paul Duffin74431d52021-04-21 14:10:42 +0100396
397 // The configured contents of BootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000398 `com.android.art:baz`,
399 `com.android.art:quuz`,
400 `platform:foo`,
Paul Duffin74431d52021-04-21 14:10:42 +0100401
satayevd604b212021-07-21 14:23:52 +0100402 // The configured contents of ApexBootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000403 `myapex:bar`,
Paul Duffin74431d52021-04-21 14:10:42 +0100404
405 // The fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100406 `com.android.art:art-bootclasspath-fragment`,
Paul Duffin89f570a2021-06-16 01:42:33 +0100407 `myapex:my-bootclasspath-fragment`,
Paul Duffinb432df92021-03-22 22:09:42 +0000408 })
409}
410
Paul Duffin7487a7a2021-05-19 09:36:09 +0100411// TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100412// AlwaysUsePrebuiltSdk() returns true.
Paul Duffin7487a7a2021-05-19 09:36:09 +0100413func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) {
414 result := android.GroupFixturePreparers(
415 prepareForTestWithPlatformBootclasspath,
416 prepareForTestWithMyapex,
417 // Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100418 // of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order
419 // matters, so that the dependencies resolved by the platform_bootclasspath matches the
420 // configured list.
satayevd604b212021-07-21 14:23:52 +0100421 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin7487a7a2021-05-19 09:36:09 +0100422 java.PrepareForTestWithJavaSdkLibraryFiles,
423 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
424 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
425 }),
426 java.FixtureWithPrebuiltApis(map[string][]string{
427 "current": {},
428 "30": {"foo"},
429 }),
430 ).RunTestWithBp(t, `
431 apex {
432 name: "myapex",
433 key: "myapex.key",
434 bootclasspath_fragments: [
435 "mybootclasspath-fragment",
436 ],
437 updatable: false,
438 }
439
440 apex_key {
441 name: "myapex.key",
442 public_key: "testkey.avbpubkey",
443 private_key: "testkey.pem",
444 }
445
446 java_library {
447 name: "bar",
448 srcs: ["b.java"],
449 installable: true,
450 apex_available: ["myapex"],
451 permitted_packages: ["bar"],
452 }
453
454 java_sdk_library {
455 name: "foo",
456 srcs: ["b.java"],
457 shared_library: false,
458 public: {
459 enabled: true,
460 },
461 apex_available: ["myapex"],
462 permitted_packages: ["foo"],
463 }
464
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100465 prebuilt_apex {
466 name: "myapex",
467 src: "myapex.apex",
468 exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
469 }
470
Paul Duffin7487a7a2021-05-19 09:36:09 +0100471 // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
472 // because AlwaysUsePrebuiltSdks() is true.
473 java_sdk_library_import {
474 name: "foo",
475 prefer: false,
476 shared_library: false,
Paul Duffin630b11e2021-07-15 13:35:26 +0100477 permitted_packages: ["foo"],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100478 public: {
479 jars: ["sdk_library/public/foo-stubs.jar"],
480 stub_srcs: ["sdk_library/public/foo_stub_sources"],
481 current_api: "sdk_library/public/foo.txt",
482 removed_api: "sdk_library/public/foo-removed.txt",
483 sdk_version: "current",
484 },
485 apex_available: ["myapex"],
486 }
487
488 // This always depends on the source foo module, its dependencies are not affected by the
489 // AlwaysUsePrebuiltSdks().
490 bootclasspath_fragment {
491 name: "mybootclasspath-fragment",
492 apex_available: [
493 "myapex",
494 ],
495 contents: [
496 "foo", "bar",
497 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100498 hidden_api: {
499 split_packages: ["*"],
500 },
Paul Duffin7487a7a2021-05-19 09:36:09 +0100501 }
502
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100503 prebuilt_bootclasspath_fragment {
504 name: "mybootclasspath-fragment",
505 apex_available: [
506 "myapex",
507 ],
508 contents: [
509 "foo",
510 ],
511 hidden_api: {
512 stub_flags: "",
513 annotation_flags: "",
514 metadata: "",
515 index: "",
516 all_flags: "",
517 },
518 }
519
Paul Duffin7487a7a2021-05-19 09:36:09 +0100520 platform_bootclasspath {
521 name: "myplatform-bootclasspath",
Paul Duffin89f570a2021-06-16 01:42:33 +0100522 fragments: [
523 {
524 apex: "myapex",
525 module:"mybootclasspath-fragment",
526 },
527 ],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100528 }
529`,
530 )
531
532 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
533 // The configured contents of BootJars.
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100534 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100535 "myapex:bar",
536 })
537
538 // Make sure that the myplatform-bootclasspath has the correct dependencies.
539 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
Spandan Das64c9e0c2023-12-20 20:13:34 +0000540 // source vs prebuilt selection metadata module
541 `platform:all_apex_contributions`,
542
Paul Duffin7487a7a2021-05-19 09:36:09 +0100543 // The following are stubs.
544 "platform:prebuilt_sdk_public_current_android",
545 "platform:prebuilt_sdk_system_current_android",
546 "platform:prebuilt_sdk_test_current_android",
547
548 // Not a prebuilt as no prebuilt existed when it was added.
549 "platform:legacy.core.platform.api.stubs",
550
Paul Duffin7487a7a2021-05-19 09:36:09 +0100551 // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt
552 // modules when available as it does not know which one will be preferred.
Paul Duffin7487a7a2021-05-19 09:36:09 +0100553 "myapex:foo",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100554 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100555
556 // Only a source module exists.
557 "myapex:bar",
Paul Duffin89f570a2021-06-16 01:42:33 +0100558
559 // The fragments.
560 "myapex:mybootclasspath-fragment",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100561 "myapex:prebuilt_mybootclasspath-fragment",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100562 })
563}
564
Paul Duffinb432df92021-03-22 22:09:42 +0000565// CheckModuleDependencies checks the dependencies of the selected module against the expected list.
566//
567// The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the
568// name of the apex, or platform is it is not part of an apex and <module> is the module name.
569func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
570 t.Helper()
571 module := ctx.ModuleForTests(name, variant).Module()
572 modules := []android.Module{}
573 ctx.VisitDirectDeps(module, func(m blueprint.Module) {
574 modules = append(modules, m.(android.Module))
575 })
576
577 pairs := java.ApexNamePairsFromModules(ctx, modules)
578 android.AssertDeepEquals(t, "module dependencies", expected, pairs)
579}
satayevb3090502021-06-15 17:49:10 +0100580
581// TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in
582// platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config
583// by setting generate_classpaths_proto property to false.
584func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) {
585 result := android.GroupFixturePreparers(
586 prepareForTestWithPlatformBootclasspath,
587 prepareForTestWithMyapex,
satayevd604b212021-07-21 14:23:52 +0100588 java.FixtureConfigureApexBootJars("myapex:foo"),
satayevb3090502021-06-15 17:49:10 +0100589 android.FixtureWithRootAndroidBp(`
590 platform_bootclasspath {
591 name: "platform-bootclasspath",
592 fragments: [
593 {
594 apex: "myapex",
595 module:"foo-fragment",
596 },
597 ],
598 }
599
600 apex {
601 name: "myapex",
602 key: "myapex.key",
603 bootclasspath_fragments: ["foo-fragment"],
604 updatable: false,
605 }
606
607 apex_key {
608 name: "myapex.key",
609 public_key: "testkey.avbpubkey",
610 private_key: "testkey.pem",
611 }
612
613 bootclasspath_fragment {
614 name: "foo-fragment",
615 generate_classpaths_proto: false,
616 contents: ["foo"],
617 apex_available: ["myapex"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100618 hidden_api: {
619 split_packages: ["*"],
620 },
satayevb3090502021-06-15 17:49:10 +0100621 }
622
623 java_library {
624 name: "foo",
625 srcs: ["a.java"],
626 system_modules: "none",
627 sdk_version: "none",
628 compile_dex: true,
629 apex_available: ["myapex"],
630 permitted_packages: ["foo"],
631 }
632 `),
633 ).RunTest(t)
634
635 java.CheckClasspathFragmentProtoContentInfoProvider(t, result,
636 true, // proto should be generated
637 "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath
638 "bootclasspath.pb",
639 "out/soong/target/product/test_device/system/etc/classpaths",
640 )
641}
satayevd34eb0c2021-08-06 13:20:28 +0100642
643func TestBootJarNotInApex(t *testing.T) {
644 android.GroupFixturePreparers(
645 prepareForTestWithPlatformBootclasspath,
646 PrepareForTestWithApexBuildComponents,
647 prepareForTestWithMyapex,
648 java.FixtureConfigureApexBootJars("myapex:foo"),
649 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
650 `dependency "foo" of "myplatform-bootclasspath" missing variant`)).
651 RunTestWithBp(t, `
652 apex {
653 name: "myapex",
654 key: "myapex.key",
655 updatable: false,
656 }
657
658 apex_key {
659 name: "myapex.key",
660 public_key: "testkey.avbpubkey",
661 private_key: "testkey.pem",
662 }
663
664 java_library {
665 name: "foo",
666 srcs: ["b.java"],
667 installable: true,
668 apex_available: [
669 "myapex",
670 ],
671 }
672
673 bootclasspath_fragment {
674 name: "not-in-apex-fragment",
675 contents: [
676 "foo",
677 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100678 hidden_api: {
679 split_packages: ["*"],
680 },
satayevd34eb0c2021-08-06 13:20:28 +0100681 }
682
683 platform_bootclasspath {
684 name: "myplatform-bootclasspath",
685 }
686 `)
687}
688
689func TestBootFragmentNotInApex(t *testing.T) {
690 android.GroupFixturePreparers(
691 prepareForTestWithPlatformBootclasspath,
692 PrepareForTestWithApexBuildComponents,
693 prepareForTestWithMyapex,
694 java.FixtureConfigureApexBootJars("myapex:foo"),
695 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
696 `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, `
697 apex {
698 name: "myapex",
699 key: "myapex.key",
700 java_libs: ["foo"],
701 updatable: false,
702 }
703
704 apex_key {
705 name: "myapex.key",
706 public_key: "testkey.avbpubkey",
707 private_key: "testkey.pem",
708 }
709
710 java_library {
711 name: "foo",
712 srcs: ["b.java"],
713 installable: true,
714 apex_available: ["myapex"],
715 permitted_packages: ["foo"],
716 }
717
718 bootclasspath_fragment {
719 name: "not-in-apex-fragment",
720 contents: ["foo"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100721 hidden_api: {
722 split_packages: ["*"],
723 },
satayevd34eb0c2021-08-06 13:20:28 +0100724 }
725
726 platform_bootclasspath {
727 name: "myplatform-bootclasspath",
728 }
729 `)
730}
731
732func TestNonBootJarInFragment(t *testing.T) {
733 android.GroupFixturePreparers(
734 prepareForTestWithPlatformBootclasspath,
735 PrepareForTestWithApexBuildComponents,
736 prepareForTestWithMyapex,
737 java.FixtureConfigureApexBootJars("myapex:foo"),
738 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
739 `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)).
740 RunTestWithBp(t, `
741 apex {
742 name: "myapex",
743 key: "myapex.key",
744 bootclasspath_fragments: ["apex-fragment"],
745 updatable: false,
746 }
747
748 apex_key {
749 name: "myapex.key",
750 public_key: "testkey.avbpubkey",
751 private_key: "testkey.pem",
752 }
753
754 java_library {
755 name: "foo",
756 srcs: ["b.java"],
757 installable: true,
758 apex_available: ["myapex"],
759 permitted_packages: ["foo"],
760 }
761
762 java_library {
763 name: "bar",
764 srcs: ["b.java"],
765 installable: true,
766 apex_available: ["myapex"],
767 permitted_packages: ["bar"],
768 }
769
770 bootclasspath_fragment {
771 name: "apex-fragment",
772 contents: ["foo", "bar"],
773 apex_available:[ "myapex" ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100774 hidden_api: {
775 split_packages: ["*"],
776 },
satayevd34eb0c2021-08-06 13:20:28 +0100777 }
778
779 platform_bootclasspath {
780 name: "myplatform-bootclasspath",
781 fragments: [{
782 apex: "myapex",
783 module:"apex-fragment",
784 }],
785 }
786 `)
787}