blob: d8a4a7a66ef6bb637e5636771c9719581d196709 [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 ],
128 },
129 }
130
131 java_library {
132 name: "bar",
Paul Duffindc3f9562021-06-09 15:31:05 +0100133 apex_available: ["myapex"],
Paul Duffinffa83752021-06-09 14:32:53 +0100134 srcs: ["a.java"],
135 system_modules: "none",
136 sdk_version: "none",
137 compile_dex: true,
Paul Duffindc3f9562021-06-09 15:31:05 +0100138 permitted_packages: ["bar"],
Paul Duffinffa83752021-06-09 14:32:53 +0100139 }
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 Duffindc3f9562021-06-09 15:31:05 +0100163 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 Duffin67b9d612021-07-21 17:38:47 +0100166
Paul Duffin280bae62021-07-20 18:03:53 +0100167 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 Duffinffa83752021-06-09 14:32:53 +0100169}
170
Paul Duffinb432df92021-03-22 22:09:42 +0000171func TestPlatformBootclasspathDependencies(t *testing.T) {
172 result := android.GroupFixturePreparers(
173 prepareForTestWithPlatformBootclasspath,
174 prepareForTestWithArtApex,
175 prepareForTestWithMyapex,
176 // Configure some libraries in the art and framework boot images.
Paul Duffin60264a02021-04-12 20:02:36 +0100177 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"),
satayevd604b212021-07-21 14:23:52 +0100178 java.FixtureConfigureApexBootJars("myapex:bar"),
Paul Duffinb432df92021-03-22 22:09:42 +0000179 java.PrepareForTestWithJavaSdkLibraryFiles,
180 java.FixtureWithLastReleaseApis("foo"),
181 ).RunTestWithBp(t, `
182 apex {
183 name: "com.android.art",
184 key: "com.android.art.key",
185 bootclasspath_fragments: [
186 "art-bootclasspath-fragment",
187 ],
188 updatable: false,
189 }
190
191 apex_key {
192 name: "com.android.art.key",
193 public_key: "com.android.art.avbpubkey",
194 private_key: "com.android.art.pem",
195 }
196
197 bootclasspath_fragment {
198 name: "art-bootclasspath-fragment",
satayevabcd5972021-08-06 17:49:46 +0100199 image_name: "art",
Paul Duffinb432df92021-03-22 22:09:42 +0000200 apex_available: [
201 "com.android.art",
202 ],
203 contents: [
204 "baz",
205 "quuz",
206 ],
207 }
208
209 java_library {
210 name: "baz",
211 apex_available: [
212 "com.android.art",
213 ],
214 srcs: ["b.java"],
215 installable: true,
216 }
217
218 // Add a java_import that is not preferred and so won't have an appropriate apex variant created
219 // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it.
220 java_import {
221 name: "baz",
222 apex_available: [
223 "com.android.art",
224 ],
225 jars: ["b.jar"],
226 }
227
228 java_library {
229 name: "quuz",
230 apex_available: [
231 "com.android.art",
232 ],
233 srcs: ["b.java"],
234 installable: true,
235 }
236
237 apex {
238 name: "myapex",
239 key: "myapex.key",
Paul Duffin89f570a2021-06-16 01:42:33 +0100240 bootclasspath_fragments: [
241 "my-bootclasspath-fragment",
Paul Duffinb432df92021-03-22 22:09:42 +0000242 ],
243 updatable: false,
244 }
245
Paul Duffin89f570a2021-06-16 01:42:33 +0100246 bootclasspath_fragment {
247 name: "my-bootclasspath-fragment",
248 contents: ["bar"],
249 apex_available: ["myapex"],
250 }
251
Paul Duffinb432df92021-03-22 22:09:42 +0000252 apex_key {
253 name: "myapex.key",
254 public_key: "testkey.avbpubkey",
255 private_key: "testkey.pem",
256 }
257
258 java_sdk_library {
259 name: "foo",
260 srcs: ["b.java"],
261 }
262
263 java_library {
264 name: "bar",
265 srcs: ["b.java"],
266 installable: true,
267 apex_available: ["myapex"],
268 permitted_packages: ["bar"],
269 }
270
271 platform_bootclasspath {
272 name: "myplatform-bootclasspath",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100273
274 fragments: [
275 {
276 apex: "com.android.art",
277 module: "art-bootclasspath-fragment",
278 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100279 {
280 apex: "myapex",
281 module: "my-bootclasspath-fragment",
282 },
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100283 ],
Paul Duffinb432df92021-03-22 22:09:42 +0000284 }
285`,
286 )
287
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100288 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100289 // The configured contents of BootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100290 "com.android.art:baz",
291 "com.android.art:quuz",
292 "platform:foo",
Paul Duffin74431d52021-04-21 14:10:42 +0100293
satayevd604b212021-07-21 14:23:52 +0100294 // The configured contents of ApexBootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100295 "myapex:bar",
296 })
297
298 java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{
Paul Duffin89f570a2021-06-16 01:42:33 +0100299 "com.android.art:art-bootclasspath-fragment",
300 "myapex:my-bootclasspath-fragment",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100301 })
302
Paul Duffinb432df92021-03-22 22:09:42 +0000303 // Make sure that the myplatform-bootclasspath has the correct dependencies.
304 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100305 // The following are stubs.
306 `platform:android_stubs_current`,
307 `platform:android_system_stubs_current`,
308 `platform:android_test_stubs_current`,
309 `platform:legacy.core.platform.api.stubs`,
310
311 // Needed for generating the boot image.
Paul Duffinb432df92021-03-22 22:09:42 +0000312 `platform:dex2oatd`,
Paul Duffin74431d52021-04-21 14:10:42 +0100313
314 // The configured contents of BootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000315 `com.android.art:baz`,
316 `com.android.art:quuz`,
317 `platform:foo`,
Paul Duffin74431d52021-04-21 14:10:42 +0100318
satayevd604b212021-07-21 14:23:52 +0100319 // The configured contents of ApexBootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000320 `myapex:bar`,
Paul Duffin74431d52021-04-21 14:10:42 +0100321
322 // The fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100323 `com.android.art:art-bootclasspath-fragment`,
Paul Duffin89f570a2021-06-16 01:42:33 +0100324 `myapex:my-bootclasspath-fragment`,
Paul Duffinb432df92021-03-22 22:09:42 +0000325 })
326}
327
Paul Duffin7487a7a2021-05-19 09:36:09 +0100328// TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100329// AlwaysUsePrebuiltSdk() returns true.
Paul Duffin7487a7a2021-05-19 09:36:09 +0100330func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) {
331 result := android.GroupFixturePreparers(
332 prepareForTestWithPlatformBootclasspath,
333 prepareForTestWithMyapex,
334 // Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100335 // of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order
336 // matters, so that the dependencies resolved by the platform_bootclasspath matches the
337 // configured list.
satayevd604b212021-07-21 14:23:52 +0100338 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin7487a7a2021-05-19 09:36:09 +0100339 java.PrepareForTestWithJavaSdkLibraryFiles,
340 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
341 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
342 }),
343 java.FixtureWithPrebuiltApis(map[string][]string{
344 "current": {},
345 "30": {"foo"},
346 }),
347 ).RunTestWithBp(t, `
348 apex {
349 name: "myapex",
350 key: "myapex.key",
351 bootclasspath_fragments: [
352 "mybootclasspath-fragment",
353 ],
354 updatable: false,
355 }
356
357 apex_key {
358 name: "myapex.key",
359 public_key: "testkey.avbpubkey",
360 private_key: "testkey.pem",
361 }
362
363 java_library {
364 name: "bar",
365 srcs: ["b.java"],
366 installable: true,
367 apex_available: ["myapex"],
368 permitted_packages: ["bar"],
369 }
370
371 java_sdk_library {
372 name: "foo",
373 srcs: ["b.java"],
374 shared_library: false,
375 public: {
376 enabled: true,
377 },
378 apex_available: ["myapex"],
379 permitted_packages: ["foo"],
380 }
381
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100382 prebuilt_apex {
383 name: "myapex",
384 src: "myapex.apex",
385 exported_bootclasspath_fragments: ["mybootclasspath-fragment"],
386 }
387
Paul Duffin7487a7a2021-05-19 09:36:09 +0100388 // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
389 // because AlwaysUsePrebuiltSdks() is true.
390 java_sdk_library_import {
391 name: "foo",
392 prefer: false,
393 shared_library: false,
Paul Duffin630b11e2021-07-15 13:35:26 +0100394 permitted_packages: ["foo"],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100395 public: {
396 jars: ["sdk_library/public/foo-stubs.jar"],
397 stub_srcs: ["sdk_library/public/foo_stub_sources"],
398 current_api: "sdk_library/public/foo.txt",
399 removed_api: "sdk_library/public/foo-removed.txt",
400 sdk_version: "current",
401 },
402 apex_available: ["myapex"],
403 }
404
405 // This always depends on the source foo module, its dependencies are not affected by the
406 // AlwaysUsePrebuiltSdks().
407 bootclasspath_fragment {
408 name: "mybootclasspath-fragment",
409 apex_available: [
410 "myapex",
411 ],
412 contents: [
413 "foo", "bar",
414 ],
415 }
416
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100417 prebuilt_bootclasspath_fragment {
418 name: "mybootclasspath-fragment",
419 apex_available: [
420 "myapex",
421 ],
422 contents: [
423 "foo",
424 ],
425 hidden_api: {
426 stub_flags: "",
427 annotation_flags: "",
428 metadata: "",
429 index: "",
430 all_flags: "",
431 },
432 }
433
Paul Duffin7487a7a2021-05-19 09:36:09 +0100434 platform_bootclasspath {
435 name: "myplatform-bootclasspath",
Paul Duffin89f570a2021-06-16 01:42:33 +0100436 fragments: [
437 {
438 apex: "myapex",
439 module:"mybootclasspath-fragment",
440 },
441 ],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100442 }
443`,
444 )
445
446 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
447 // The configured contents of BootJars.
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100448 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100449 "myapex:bar",
450 })
451
452 // Make sure that the myplatform-bootclasspath has the correct dependencies.
453 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
454 // The following are stubs.
455 "platform:prebuilt_sdk_public_current_android",
456 "platform:prebuilt_sdk_system_current_android",
457 "platform:prebuilt_sdk_test_current_android",
458
459 // Not a prebuilt as no prebuilt existed when it was added.
460 "platform:legacy.core.platform.api.stubs",
461
462 // Needed for generating the boot image.
Paul Duffin89f570a2021-06-16 01:42:33 +0100463 "platform:dex2oatd",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100464
465 // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt
466 // modules when available as it does not know which one will be preferred.
Paul Duffin7487a7a2021-05-19 09:36:09 +0100467 "myapex:foo",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100468 "myapex:prebuilt_foo",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100469
470 // Only a source module exists.
471 "myapex:bar",
Paul Duffin89f570a2021-06-16 01:42:33 +0100472
473 // The fragments.
474 "myapex:mybootclasspath-fragment",
Martin Stjernholmb1e61cb2021-09-08 21:56:18 +0100475 "myapex:prebuilt_mybootclasspath-fragment",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100476 })
477}
478
Paul Duffinb432df92021-03-22 22:09:42 +0000479// CheckModuleDependencies checks the dependencies of the selected module against the expected list.
480//
481// The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the
482// name of the apex, or platform is it is not part of an apex and <module> is the module name.
483func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
484 t.Helper()
485 module := ctx.ModuleForTests(name, variant).Module()
486 modules := []android.Module{}
487 ctx.VisitDirectDeps(module, func(m blueprint.Module) {
488 modules = append(modules, m.(android.Module))
489 })
490
491 pairs := java.ApexNamePairsFromModules(ctx, modules)
492 android.AssertDeepEquals(t, "module dependencies", expected, pairs)
493}
satayevb3090502021-06-15 17:49:10 +0100494
495// TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in
496// platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config
497// by setting generate_classpaths_proto property to false.
498func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) {
499 result := android.GroupFixturePreparers(
500 prepareForTestWithPlatformBootclasspath,
501 prepareForTestWithMyapex,
satayevd604b212021-07-21 14:23:52 +0100502 java.FixtureConfigureApexBootJars("myapex:foo"),
satayevb3090502021-06-15 17:49:10 +0100503 android.FixtureWithRootAndroidBp(`
504 platform_bootclasspath {
505 name: "platform-bootclasspath",
506 fragments: [
507 {
508 apex: "myapex",
509 module:"foo-fragment",
510 },
511 ],
512 }
513
514 apex {
515 name: "myapex",
516 key: "myapex.key",
517 bootclasspath_fragments: ["foo-fragment"],
518 updatable: false,
519 }
520
521 apex_key {
522 name: "myapex.key",
523 public_key: "testkey.avbpubkey",
524 private_key: "testkey.pem",
525 }
526
527 bootclasspath_fragment {
528 name: "foo-fragment",
529 generate_classpaths_proto: false,
530 contents: ["foo"],
531 apex_available: ["myapex"],
532 }
533
534 java_library {
535 name: "foo",
536 srcs: ["a.java"],
537 system_modules: "none",
538 sdk_version: "none",
539 compile_dex: true,
540 apex_available: ["myapex"],
541 permitted_packages: ["foo"],
542 }
543 `),
544 ).RunTest(t)
545
546 java.CheckClasspathFragmentProtoContentInfoProvider(t, result,
547 true, // proto should be generated
548 "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath
549 "bootclasspath.pb",
550 "out/soong/target/product/test_device/system/etc/classpaths",
551 )
552}
satayevd34eb0c2021-08-06 13:20:28 +0100553
554func TestBootJarNotInApex(t *testing.T) {
555 android.GroupFixturePreparers(
556 prepareForTestWithPlatformBootclasspath,
557 PrepareForTestWithApexBuildComponents,
558 prepareForTestWithMyapex,
559 java.FixtureConfigureApexBootJars("myapex:foo"),
560 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
561 `dependency "foo" of "myplatform-bootclasspath" missing variant`)).
562 RunTestWithBp(t, `
563 apex {
564 name: "myapex",
565 key: "myapex.key",
566 updatable: false,
567 }
568
569 apex_key {
570 name: "myapex.key",
571 public_key: "testkey.avbpubkey",
572 private_key: "testkey.pem",
573 }
574
575 java_library {
576 name: "foo",
577 srcs: ["b.java"],
578 installable: true,
579 apex_available: [
580 "myapex",
581 ],
582 }
583
584 bootclasspath_fragment {
585 name: "not-in-apex-fragment",
586 contents: [
587 "foo",
588 ],
589 }
590
591 platform_bootclasspath {
592 name: "myplatform-bootclasspath",
593 }
594 `)
595}
596
597func TestBootFragmentNotInApex(t *testing.T) {
598 android.GroupFixturePreparers(
599 prepareForTestWithPlatformBootclasspath,
600 PrepareForTestWithApexBuildComponents,
601 prepareForTestWithMyapex,
602 java.FixtureConfigureApexBootJars("myapex:foo"),
603 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
604 `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, `
605 apex {
606 name: "myapex",
607 key: "myapex.key",
608 java_libs: ["foo"],
609 updatable: false,
610 }
611
612 apex_key {
613 name: "myapex.key",
614 public_key: "testkey.avbpubkey",
615 private_key: "testkey.pem",
616 }
617
618 java_library {
619 name: "foo",
620 srcs: ["b.java"],
621 installable: true,
622 apex_available: ["myapex"],
623 permitted_packages: ["foo"],
624 }
625
626 bootclasspath_fragment {
627 name: "not-in-apex-fragment",
628 contents: ["foo"],
629 }
630
631 platform_bootclasspath {
632 name: "myplatform-bootclasspath",
633 }
634 `)
635}
636
637func TestNonBootJarInFragment(t *testing.T) {
638 android.GroupFixturePreparers(
639 prepareForTestWithPlatformBootclasspath,
640 PrepareForTestWithApexBuildComponents,
641 prepareForTestWithMyapex,
642 java.FixtureConfigureApexBootJars("myapex:foo"),
643 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
644 `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)).
645 RunTestWithBp(t, `
646 apex {
647 name: "myapex",
648 key: "myapex.key",
649 bootclasspath_fragments: ["apex-fragment"],
650 updatable: false,
651 }
652
653 apex_key {
654 name: "myapex.key",
655 public_key: "testkey.avbpubkey",
656 private_key: "testkey.pem",
657 }
658
659 java_library {
660 name: "foo",
661 srcs: ["b.java"],
662 installable: true,
663 apex_available: ["myapex"],
664 permitted_packages: ["foo"],
665 }
666
667 java_library {
668 name: "bar",
669 srcs: ["b.java"],
670 installable: true,
671 apex_available: ["myapex"],
672 permitted_packages: ["bar"],
673 }
674
675 bootclasspath_fragment {
676 name: "apex-fragment",
677 contents: ["foo", "bar"],
678 apex_available:[ "myapex" ],
679 }
680
681 platform_bootclasspath {
682 name: "myplatform-bootclasspath",
683 fragments: [{
684 apex: "myapex",
685 module:"apex-fragment",
686 }],
687 }
688 `)
689}