blob: 2bd3159be97b6d3d179f39b435486b762e51036b [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 {
Cole Faust22e8abc2024-01-23 17:52:13 -0800158 name := category.PropertyName()
Paul Duffinffa83752021-06-09 14:32:53 +0100159 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),
Jihoon Kangbd093452023-12-26 19:08:01 +0000255 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
256 variables.BuildFlags = map[string]string{
257 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
258 }
259 }),
Paul Duffinb432df92021-03-22 22:09:42 +0000260 ).RunTestWithBp(t, `
261 apex {
262 name: "com.android.art",
263 key: "com.android.art.key",
264 bootclasspath_fragments: [
265 "art-bootclasspath-fragment",
266 ],
267 updatable: false,
268 }
269
270 apex_key {
271 name: "com.android.art.key",
272 public_key: "com.android.art.avbpubkey",
273 private_key: "com.android.art.pem",
274 }
275
276 bootclasspath_fragment {
277 name: "art-bootclasspath-fragment",
satayevabcd5972021-08-06 17:49:46 +0100278 image_name: "art",
Paul Duffinb432df92021-03-22 22:09:42 +0000279 apex_available: [
280 "com.android.art",
281 ],
282 contents: [
283 "baz",
284 "quuz",
285 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100286 hidden_api: {
287 split_packages: ["*"],
288 },
Paul Duffinb432df92021-03-22 22:09:42 +0000289 }
290
291 java_library {
292 name: "baz",
293 apex_available: [
294 "com.android.art",
295 ],
296 srcs: ["b.java"],
297 installable: true,
298 }
299
300 // Add a java_import that is not preferred and so won't have an appropriate apex variant created
301 // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it.
302 java_import {
303 name: "baz",
304 apex_available: [
305 "com.android.art",
306 ],
307 jars: ["b.jar"],
308 }
309
310 java_library {
311 name: "quuz",
312 apex_available: [
313 "com.android.art",
314 ],
315 srcs: ["b.java"],
316 installable: true,
317 }
318
319 apex {
320 name: "myapex",
321 key: "myapex.key",
Paul Duffin89f570a2021-06-16 01:42:33 +0100322 bootclasspath_fragments: [
323 "my-bootclasspath-fragment",
Paul Duffinb432df92021-03-22 22:09:42 +0000324 ],
325 updatable: false,
326 }
327
Paul Duffin89f570a2021-06-16 01:42:33 +0100328 bootclasspath_fragment {
329 name: "my-bootclasspath-fragment",
330 contents: ["bar"],
331 apex_available: ["myapex"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100332 hidden_api: {
333 split_packages: ["*"],
334 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100335 }
336
Paul Duffinb432df92021-03-22 22:09:42 +0000337 apex_key {
338 name: "myapex.key",
339 public_key: "testkey.avbpubkey",
340 private_key: "testkey.pem",
341 }
342
343 java_sdk_library {
344 name: "foo",
345 srcs: ["b.java"],
346 }
347
348 java_library {
349 name: "bar",
350 srcs: ["b.java"],
351 installable: true,
352 apex_available: ["myapex"],
353 permitted_packages: ["bar"],
354 }
355
356 platform_bootclasspath {
357 name: "myplatform-bootclasspath",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100358
359 fragments: [
360 {
361 apex: "com.android.art",
362 module: "art-bootclasspath-fragment",
363 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100364 {
365 apex: "myapex",
366 module: "my-bootclasspath-fragment",
367 },
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100368 ],
Paul Duffinb432df92021-03-22 22:09:42 +0000369 }
370`,
371 )
372
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100373 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100374 // The configured contents of BootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100375 "com.android.art:baz",
376 "com.android.art:quuz",
377 "platform:foo",
Paul Duffin74431d52021-04-21 14:10:42 +0100378
satayevd604b212021-07-21 14:23:52 +0100379 // The configured contents of ApexBootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100380 "myapex:bar",
381 })
382
383 java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{
Paul Duffin89f570a2021-06-16 01:42:33 +0100384 "com.android.art:art-bootclasspath-fragment",
385 "myapex:my-bootclasspath-fragment",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100386 })
387
Paul Duffinb432df92021-03-22 22:09:42 +0000388 // Make sure that the myplatform-bootclasspath has the correct dependencies.
389 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
Spandan Das64c9e0c2023-12-20 20:13:34 +0000390 // source vs prebuilt selection metadata module
391 `platform:all_apex_contributions`,
392
Paul Duffin74431d52021-04-21 14:10:42 +0100393 // The following are stubs.
Jihoon Kangbd093452023-12-26 19:08:01 +0000394 `platform:android_stubs_current_exportable`,
395 `platform:android_system_stubs_current_exportable`,
396 `platform:android_test_stubs_current_exportable`,
397 `platform:legacy.core.platform.api.stubs.exportable`,
Paul Duffin74431d52021-04-21 14:10:42 +0100398
399 // Needed for generating the boot image.
Paul Duffinb432df92021-03-22 22:09:42 +0000400 `platform:dex2oatd`,
Paul Duffin74431d52021-04-21 14:10:42 +0100401
402 // The configured contents of BootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000403 `com.android.art:baz`,
404 `com.android.art:quuz`,
405 `platform:foo`,
Paul Duffin74431d52021-04-21 14:10:42 +0100406
satayevd604b212021-07-21 14:23:52 +0100407 // The configured contents of ApexBootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000408 `myapex:bar`,
Paul Duffin74431d52021-04-21 14:10:42 +0100409
410 // The fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100411 `com.android.art:art-bootclasspath-fragment`,
Paul Duffin89f570a2021-06-16 01:42:33 +0100412 `myapex:my-bootclasspath-fragment`,
Paul Duffinb432df92021-03-22 22:09:42 +0000413 })
414}
415
Paul Duffin7487a7a2021-05-19 09:36:09 +0100416// TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100417// AlwaysUsePrebuiltSdk() returns true.
Paul Duffin7487a7a2021-05-19 09:36:09 +0100418func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) {
419 result := android.GroupFixturePreparers(
420 prepareForTestWithPlatformBootclasspath,
421 prepareForTestWithMyapex,
422 // Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100423 // of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order
424 // matters, so that the dependencies resolved by the platform_bootclasspath matches the
425 // configured list.
satayevd604b212021-07-21 14:23:52 +0100426 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin7487a7a2021-05-19 09:36:09 +0100427 java.PrepareForTestWithJavaSdkLibraryFiles,
428 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
429 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
Jihoon Kangbd093452023-12-26 19:08:01 +0000430 variables.BuildFlags = map[string]string{
431 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
432 }
Paul Duffin7487a7a2021-05-19 09:36:09 +0100433 }),
434 java.FixtureWithPrebuiltApis(map[string][]string{
435 "current": {},
436 "30": {"foo"},
437 }),
438 ).RunTestWithBp(t, `
439 apex {
440 name: "myapex",
441 key: "myapex.key",
442 bootclasspath_fragments: [
443 "mybootclasspath-fragment",
444 ],
445 updatable: false,
446 }
447
448 apex_key {
449 name: "myapex.key",
450 public_key: "testkey.avbpubkey",
451 private_key: "testkey.pem",
452 }
453
454 java_library {
455 name: "bar",
456 srcs: ["b.java"],
457 installable: true,
458 apex_available: ["myapex"],
459 permitted_packages: ["bar"],
460 }
461
462 java_sdk_library {
463 name: "foo",
464 srcs: ["b.java"],
465 shared_library: false,
466 public: {
467 enabled: true,
468 },
469 apex_available: ["myapex"],
470 permitted_packages: ["foo"],
471 }
472
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100473 prebuilt_apex {
474 name: "myapex",
475 src: "myapex.apex",
476 exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
477 }
478
Paul Duffin7487a7a2021-05-19 09:36:09 +0100479 // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
480 // because AlwaysUsePrebuiltSdks() is true.
481 java_sdk_library_import {
482 name: "foo",
483 prefer: false,
484 shared_library: false,
Paul Duffin630b11e2021-07-15 13:35:26 +0100485 permitted_packages: ["foo"],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100486 public: {
487 jars: ["sdk_library/public/foo-stubs.jar"],
488 stub_srcs: ["sdk_library/public/foo_stub_sources"],
489 current_api: "sdk_library/public/foo.txt",
490 removed_api: "sdk_library/public/foo-removed.txt",
491 sdk_version: "current",
492 },
493 apex_available: ["myapex"],
494 }
495
496 // This always depends on the source foo module, its dependencies are not affected by the
497 // AlwaysUsePrebuiltSdks().
498 bootclasspath_fragment {
499 name: "mybootclasspath-fragment",
500 apex_available: [
501 "myapex",
502 ],
503 contents: [
504 "foo", "bar",
505 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100506 hidden_api: {
507 split_packages: ["*"],
508 },
Paul Duffin7487a7a2021-05-19 09:36:09 +0100509 }
510
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100511 prebuilt_bootclasspath_fragment {
512 name: "mybootclasspath-fragment",
513 apex_available: [
514 "myapex",
515 ],
516 contents: [
517 "foo",
518 ],
519 hidden_api: {
520 stub_flags: "",
521 annotation_flags: "",
522 metadata: "",
523 index: "",
524 all_flags: "",
525 },
526 }
527
Paul Duffin7487a7a2021-05-19 09:36:09 +0100528 platform_bootclasspath {
529 name: "myplatform-bootclasspath",
Paul Duffin89f570a2021-06-16 01:42:33 +0100530 fragments: [
531 {
532 apex: "myapex",
533 module:"mybootclasspath-fragment",
534 },
535 ],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100536 }
537`,
538 )
539
540 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
541 // The configured contents of BootJars.
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100542 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100543 "myapex:bar",
544 })
545
546 // Make sure that the myplatform-bootclasspath has the correct dependencies.
547 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
Spandan Das64c9e0c2023-12-20 20:13:34 +0000548 // source vs prebuilt selection metadata module
549 `platform:all_apex_contributions`,
550
Paul Duffin7487a7a2021-05-19 09:36:09 +0100551 // The following are stubs.
552 "platform:prebuilt_sdk_public_current_android",
553 "platform:prebuilt_sdk_system_current_android",
554 "platform:prebuilt_sdk_test_current_android",
555
556 // Not a prebuilt as no prebuilt existed when it was added.
Jihoon Kangbd093452023-12-26 19:08:01 +0000557 "platform:legacy.core.platform.api.stubs.exportable",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100558
Paul Duffin7487a7a2021-05-19 09:36:09 +0100559 // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt
560 // modules when available as it does not know which one will be preferred.
Paul Duffin7487a7a2021-05-19 09:36:09 +0100561 "myapex:foo",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100562 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100563
564 // Only a source module exists.
565 "myapex:bar",
Paul Duffin89f570a2021-06-16 01:42:33 +0100566
567 // The fragments.
568 "myapex:mybootclasspath-fragment",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100569 "myapex:prebuilt_mybootclasspath-fragment",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100570 })
571}
572
Paul Duffinb432df92021-03-22 22:09:42 +0000573// CheckModuleDependencies checks the dependencies of the selected module against the expected list.
574//
575// The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the
576// name of the apex, or platform is it is not part of an apex and <module> is the module name.
577func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
578 t.Helper()
579 module := ctx.ModuleForTests(name, variant).Module()
580 modules := []android.Module{}
581 ctx.VisitDirectDeps(module, func(m blueprint.Module) {
582 modules = append(modules, m.(android.Module))
583 })
584
585 pairs := java.ApexNamePairsFromModules(ctx, modules)
586 android.AssertDeepEquals(t, "module dependencies", expected, pairs)
587}
satayevb3090502021-06-15 17:49:10 +0100588
589// TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in
590// platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config
591// by setting generate_classpaths_proto property to false.
592func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) {
593 result := android.GroupFixturePreparers(
594 prepareForTestWithPlatformBootclasspath,
595 prepareForTestWithMyapex,
satayevd604b212021-07-21 14:23:52 +0100596 java.FixtureConfigureApexBootJars("myapex:foo"),
satayevb3090502021-06-15 17:49:10 +0100597 android.FixtureWithRootAndroidBp(`
598 platform_bootclasspath {
599 name: "platform-bootclasspath",
600 fragments: [
601 {
602 apex: "myapex",
603 module:"foo-fragment",
604 },
605 ],
606 }
607
608 apex {
609 name: "myapex",
610 key: "myapex.key",
611 bootclasspath_fragments: ["foo-fragment"],
612 updatable: false,
613 }
614
615 apex_key {
616 name: "myapex.key",
617 public_key: "testkey.avbpubkey",
618 private_key: "testkey.pem",
619 }
620
621 bootclasspath_fragment {
622 name: "foo-fragment",
623 generate_classpaths_proto: false,
624 contents: ["foo"],
625 apex_available: ["myapex"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100626 hidden_api: {
627 split_packages: ["*"],
628 },
satayevb3090502021-06-15 17:49:10 +0100629 }
630
631 java_library {
632 name: "foo",
633 srcs: ["a.java"],
634 system_modules: "none",
635 sdk_version: "none",
636 compile_dex: true,
637 apex_available: ["myapex"],
638 permitted_packages: ["foo"],
639 }
640 `),
641 ).RunTest(t)
642
643 java.CheckClasspathFragmentProtoContentInfoProvider(t, result,
644 true, // proto should be generated
645 "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath
646 "bootclasspath.pb",
647 "out/soong/target/product/test_device/system/etc/classpaths",
648 )
649}
satayevd34eb0c2021-08-06 13:20:28 +0100650
651func TestBootJarNotInApex(t *testing.T) {
652 android.GroupFixturePreparers(
653 prepareForTestWithPlatformBootclasspath,
654 PrepareForTestWithApexBuildComponents,
655 prepareForTestWithMyapex,
656 java.FixtureConfigureApexBootJars("myapex:foo"),
657 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
658 `dependency "foo" of "myplatform-bootclasspath" missing variant`)).
659 RunTestWithBp(t, `
660 apex {
661 name: "myapex",
662 key: "myapex.key",
663 updatable: false,
664 }
665
666 apex_key {
667 name: "myapex.key",
668 public_key: "testkey.avbpubkey",
669 private_key: "testkey.pem",
670 }
671
672 java_library {
673 name: "foo",
674 srcs: ["b.java"],
675 installable: true,
676 apex_available: [
677 "myapex",
678 ],
679 }
680
681 bootclasspath_fragment {
682 name: "not-in-apex-fragment",
683 contents: [
684 "foo",
685 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100686 hidden_api: {
687 split_packages: ["*"],
688 },
satayevd34eb0c2021-08-06 13:20:28 +0100689 }
690
691 platform_bootclasspath {
692 name: "myplatform-bootclasspath",
693 }
694 `)
695}
696
697func TestBootFragmentNotInApex(t *testing.T) {
698 android.GroupFixturePreparers(
699 prepareForTestWithPlatformBootclasspath,
700 PrepareForTestWithApexBuildComponents,
701 prepareForTestWithMyapex,
702 java.FixtureConfigureApexBootJars("myapex:foo"),
703 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
704 `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, `
705 apex {
706 name: "myapex",
707 key: "myapex.key",
708 java_libs: ["foo"],
709 updatable: false,
710 }
711
712 apex_key {
713 name: "myapex.key",
714 public_key: "testkey.avbpubkey",
715 private_key: "testkey.pem",
716 }
717
718 java_library {
719 name: "foo",
720 srcs: ["b.java"],
721 installable: true,
722 apex_available: ["myapex"],
723 permitted_packages: ["foo"],
724 }
725
726 bootclasspath_fragment {
727 name: "not-in-apex-fragment",
728 contents: ["foo"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100729 hidden_api: {
730 split_packages: ["*"],
731 },
satayevd34eb0c2021-08-06 13:20:28 +0100732 }
733
734 platform_bootclasspath {
735 name: "myplatform-bootclasspath",
736 }
737 `)
738}
739
740func TestNonBootJarInFragment(t *testing.T) {
741 android.GroupFixturePreparers(
742 prepareForTestWithPlatformBootclasspath,
743 PrepareForTestWithApexBuildComponents,
744 prepareForTestWithMyapex,
745 java.FixtureConfigureApexBootJars("myapex:foo"),
746 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
747 `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)).
748 RunTestWithBp(t, `
749 apex {
750 name: "myapex",
751 key: "myapex.key",
752 bootclasspath_fragments: ["apex-fragment"],
753 updatable: false,
754 }
755
756 apex_key {
757 name: "myapex.key",
758 public_key: "testkey.avbpubkey",
759 private_key: "testkey.pem",
760 }
761
762 java_library {
763 name: "foo",
764 srcs: ["b.java"],
765 installable: true,
766 apex_available: ["myapex"],
767 permitted_packages: ["foo"],
768 }
769
770 java_library {
771 name: "bar",
772 srcs: ["b.java"],
773 installable: true,
774 apex_available: ["myapex"],
775 permitted_packages: ["bar"],
776 }
777
778 bootclasspath_fragment {
779 name: "apex-fragment",
780 contents: ["foo", "bar"],
781 apex_available:[ "myapex" ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100782 hidden_api: {
783 split_packages: ["*"],
784 },
satayevd34eb0c2021-08-06 13:20:28 +0100785 }
786
787 platform_bootclasspath {
788 name: "myplatform-bootclasspath",
789 fragments: [{
790 apex: "myapex",
791 module:"apex-fragment",
792 }],
793 }
794 `)
795}