blob: 4b48da8e27ea56a74ad64771991a91f06d54d1d8 [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"
Paul Duffinb432df92021-03-22 22:09:42 +000023 "android/soong/java"
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +010024
Paul Duffinb432df92021-03-22 22:09:42 +000025 "github.com/google/blueprint"
Paul Duffin7487a7a2021-05-19 09:36:09 +010026 "github.com/google/blueprint/proptools"
Paul Duffinb432df92021-03-22 22:09:42 +000027)
28
29// Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires
30// apexes.
31
32var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers(
33 java.PrepareForTestWithDexpreopt,
34 PrepareForTestWithApexBuildComponents,
35)
36
Paul Duffinffa83752021-06-09 14:32:53 +010037func TestPlatformBootclasspath_Fragments(t *testing.T) {
38 result := android.GroupFixturePreparers(
39 prepareForTestWithPlatformBootclasspath,
Paul Duffindc3f9562021-06-09 15:31:05 +010040 prepareForTestWithMyapex,
Paul Duffinffa83752021-06-09 14:32:53 +010041 java.PrepareForTestWithJavaSdkLibraryFiles,
42 java.FixtureWithLastReleaseApis("foo"),
satayevabcd5972021-08-06 17:49:46 +010043 java.FixtureConfigureApexBootJars("myapex:bar"),
Paul Duffinffa83752021-06-09 14:32:53 +010044 android.FixtureWithRootAndroidBp(`
45 platform_bootclasspath {
46 name: "platform-bootclasspath",
47 fragments: [
Paul Duffindc3f9562021-06-09 15:31:05 +010048 {
49 apex: "myapex",
50 module:"bar-fragment",
51 },
Paul Duffinffa83752021-06-09 14:32:53 +010052 ],
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 Duffindc3f9562021-06-09 15:31:05 +010081 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 Duffinffa83752021-06-09 14:32:53 +010096 bootclasspath_fragment {
97 name: "bar-fragment",
98 contents: ["bar"],
Paul Duffindc3f9562021-06-09 15:31:05 +010099 apex_available: ["myapex"],
Paul Duffinffa83752021-06-09 14:32:53 +0100100 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 Duffin9fd56472022-03-31 15:42:30 +0100128 split_packages: ["*"],
Paul Duffinffa83752021-06-09 14:32:53 +0100129 },
130 }
131
132 java_library {
133 name: "bar",
Paul Duffindc3f9562021-06-09 15:31:05 +0100134 apex_available: ["myapex"],
Paul Duffinffa83752021-06-09 14:32:53 +0100135 srcs: ["a.java"],
136 system_modules: "none",
137 sdk_version: "none",
138 compile_dex: true,
Paul Duffindc3f9562021-06-09 15:31:05 +0100139 permitted_packages: ["bar"],
Paul Duffinffa83752021-06-09 14:32:53 +0100140 }
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 Duffindc3f9562021-06-09 15:31:05 +0100164 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 Duffin67b9d612021-07-21 17:38:47 +0100167
Paul Duffin280bae62021-07-20 18:03:53 +0100168 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 Duffinffa83752021-06-09 14:32:53 +0100170}
171
Paul Duffin191be3a2021-08-10 16:14:16 +0100172// 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.
177func 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 Duffinb432df92021-03-22 22:09:42 +0000242func 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 Duffin60264a02021-04-12 20:02:36 +0100248 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"),
satayevd604b212021-07-21 14:23:52 +0100249 java.FixtureConfigureApexBootJars("myapex:bar"),
Paul Duffinb432df92021-03-22 22:09:42 +0000250 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",
satayevabcd5972021-08-06 17:49:46 +0100270 image_name: "art",
Paul Duffinb432df92021-03-22 22:09:42 +0000271 apex_available: [
272 "com.android.art",
273 ],
274 contents: [
275 "baz",
276 "quuz",
277 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100278 hidden_api: {
279 split_packages: ["*"],
280 },
Paul Duffinb432df92021-03-22 22:09:42 +0000281 }
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 Duffin89f570a2021-06-16 01:42:33 +0100314 bootclasspath_fragments: [
315 "my-bootclasspath-fragment",
Paul Duffinb432df92021-03-22 22:09:42 +0000316 ],
317 updatable: false,
318 }
319
Paul Duffin89f570a2021-06-16 01:42:33 +0100320 bootclasspath_fragment {
321 name: "my-bootclasspath-fragment",
322 contents: ["bar"],
323 apex_available: ["myapex"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100324 hidden_api: {
325 split_packages: ["*"],
326 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100327 }
328
Paul Duffinb432df92021-03-22 22:09:42 +0000329 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 Duffin62d8c3b2021-04-07 20:35:11 +0100350
351 fragments: [
352 {
353 apex: "com.android.art",
354 module: "art-bootclasspath-fragment",
355 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100356 {
357 apex: "myapex",
358 module: "my-bootclasspath-fragment",
359 },
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100360 ],
Paul Duffinb432df92021-03-22 22:09:42 +0000361 }
362`,
363 )
364
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100365 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100366 // The configured contents of BootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100367 "com.android.art:baz",
368 "com.android.art:quuz",
369 "platform:foo",
Paul Duffin74431d52021-04-21 14:10:42 +0100370
satayevd604b212021-07-21 14:23:52 +0100371 // The configured contents of ApexBootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100372 "myapex:bar",
373 })
374
375 java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{
Paul Duffin89f570a2021-06-16 01:42:33 +0100376 "com.android.art:art-bootclasspath-fragment",
377 "myapex:my-bootclasspath-fragment",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100378 })
379
Paul Duffinb432df92021-03-22 22:09:42 +0000380 // Make sure that the myplatform-bootclasspath has the correct dependencies.
381 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100382 // 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 Duffinb432df92021-03-22 22:09:42 +0000389 `platform:dex2oatd`,
Paul Duffin74431d52021-04-21 14:10:42 +0100390
391 // The configured contents of BootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000392 `com.android.art:baz`,
393 `com.android.art:quuz`,
394 `platform:foo`,
Paul Duffin74431d52021-04-21 14:10:42 +0100395
satayevd604b212021-07-21 14:23:52 +0100396 // The configured contents of ApexBootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000397 `myapex:bar`,
Paul Duffin74431d52021-04-21 14:10:42 +0100398
399 // The fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100400 `com.android.art:art-bootclasspath-fragment`,
Paul Duffin89f570a2021-06-16 01:42:33 +0100401 `myapex:my-bootclasspath-fragment`,
Paul Duffinb432df92021-03-22 22:09:42 +0000402 })
403}
404
Paul Duffin7487a7a2021-05-19 09:36:09 +0100405// TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100406// AlwaysUsePrebuiltSdk() returns true.
Paul Duffin7487a7a2021-05-19 09:36:09 +0100407func 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 Stjernholmb1e61cb2021-09-08 21:56:18 +0100412 // 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.
satayevd604b212021-07-21 14:23:52 +0100415 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin7487a7a2021-05-19 09:36:09 +0100416 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 Stjernholmb1e61cb2021-09-08 21:56:18 +0100459 prebuilt_apex {
460 name: "myapex",
461 src: "myapex.apex",
462 exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
463 }
464
Paul Duffin7487a7a2021-05-19 09:36:09 +0100465 // 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 Duffin630b11e2021-07-15 13:35:26 +0100471 permitted_packages: ["foo"],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100472 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 Duffin9fd56472022-03-31 15:42:30 +0100492 hidden_api: {
493 split_packages: ["*"],
494 },
Paul Duffin7487a7a2021-05-19 09:36:09 +0100495 }
496
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100497 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 Duffin7487a7a2021-05-19 09:36:09 +0100514 platform_bootclasspath {
515 name: "myplatform-bootclasspath",
Paul Duffin89f570a2021-06-16 01:42:33 +0100516 fragments: [
517 {
518 apex: "myapex",
519 module:"mybootclasspath-fragment",
520 },
521 ],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100522 }
523`,
524 )
525
526 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
527 // The configured contents of BootJars.
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100528 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100529 "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 Duffin89f570a2021-06-16 01:42:33 +0100543 "platform:dex2oatd",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100544
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 Duffin7487a7a2021-05-19 09:36:09 +0100547 "myapex:foo",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100548 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100549
550 // Only a source module exists.
551 "myapex:bar",
Paul Duffin89f570a2021-06-16 01:42:33 +0100552
553 // The fragments.
554 "myapex:mybootclasspath-fragment",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100555 "myapex:prebuilt_mybootclasspath-fragment",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100556 })
557}
558
Paul Duffinb432df92021-03-22 22:09:42 +0000559// 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.
563func 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}
satayevb3090502021-06-15 17:49:10 +0100574
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.
578func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) {
579 result := android.GroupFixturePreparers(
580 prepareForTestWithPlatformBootclasspath,
581 prepareForTestWithMyapex,
satayevd604b212021-07-21 14:23:52 +0100582 java.FixtureConfigureApexBootJars("myapex:foo"),
satayevb3090502021-06-15 17:49:10 +0100583 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 Duffin9fd56472022-03-31 15:42:30 +0100612 hidden_api: {
613 split_packages: ["*"],
614 },
satayevb3090502021-06-15 17:49:10 +0100615 }
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}
satayevd34eb0c2021-08-06 13:20:28 +0100636
637func 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 Duffin9fd56472022-03-31 15:42:30 +0100672 hidden_api: {
673 split_packages: ["*"],
674 },
satayevd34eb0c2021-08-06 13:20:28 +0100675 }
676
677 platform_bootclasspath {
678 name: "myplatform-bootclasspath",
679 }
680 `)
681}
682
683func 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 Duffin9fd56472022-03-31 15:42:30 +0100715 hidden_api: {
716 split_packages: ["*"],
717 },
satayevd34eb0c2021-08-06 13:20:28 +0100718 }
719
720 platform_bootclasspath {
721 name: "myplatform-bootclasspath",
722 }
723 `)
724}
725
726func 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 Duffin9fd56472022-03-31 15:42:30 +0100768 hidden_api: {
769 split_packages: ["*"],
770 },
satayevd34eb0c2021-08-06 13:20:28 +0100771 }
772
773 platform_bootclasspath {
774 name: "myplatform-bootclasspath",
775 fragments: [{
776 apex: "myapex",
777 module:"apex-fragment",
778 }],
779 }
780 `)
781}