blob: 513ddc07fd74265de6739448243698676da79bee [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"
24 "github.com/google/blueprint"
Paul Duffin7487a7a2021-05-19 09:36:09 +010025 "github.com/google/blueprint/proptools"
Paul Duffinb432df92021-03-22 22:09:42 +000026)
27
28// Contains tests for platform_bootclasspath logic from java/platform_bootclasspath.go that requires
29// apexes.
30
31var prepareForTestWithPlatformBootclasspath = android.GroupFixturePreparers(
32 java.PrepareForTestWithDexpreopt,
33 PrepareForTestWithApexBuildComponents,
34)
35
Paul Duffinffa83752021-06-09 14:32:53 +010036func TestPlatformBootclasspath_Fragments(t *testing.T) {
37 result := android.GroupFixturePreparers(
38 prepareForTestWithPlatformBootclasspath,
Paul Duffindc3f9562021-06-09 15:31:05 +010039 prepareForTestWithMyapex,
Paul Duffinffa83752021-06-09 14:32:53 +010040 java.PrepareForTestWithJavaSdkLibraryFiles,
41 java.FixtureWithLastReleaseApis("foo"),
satayevabcd5972021-08-06 17:49:46 +010042 java.FixtureConfigureApexBootJars("myapex:bar"),
Paul Duffinffa83752021-06-09 14:32:53 +010043 android.FixtureWithRootAndroidBp(`
44 platform_bootclasspath {
45 name: "platform-bootclasspath",
46 fragments: [
Paul Duffindc3f9562021-06-09 15:31:05 +010047 {
48 apex: "myapex",
49 module:"bar-fragment",
50 },
Paul Duffinffa83752021-06-09 14:32:53 +010051 ],
52 hidden_api: {
53 unsupported: [
54 "unsupported.txt",
55 ],
56 removed: [
57 "removed.txt",
58 ],
59 max_target_r_low_priority: [
60 "max-target-r-low-priority.txt",
61 ],
62 max_target_q: [
63 "max-target-q.txt",
64 ],
65 max_target_p: [
66 "max-target-p.txt",
67 ],
68 max_target_o_low_priority: [
69 "max-target-o-low-priority.txt",
70 ],
71 blocked: [
72 "blocked.txt",
73 ],
74 unsupported_packages: [
75 "unsupported-packages.txt",
76 ],
77 },
78 }
79
Paul Duffindc3f9562021-06-09 15:31:05 +010080 apex {
81 name: "myapex",
82 key: "myapex.key",
83 bootclasspath_fragments: [
84 "bar-fragment",
85 ],
86 updatable: false,
87 }
88
89 apex_key {
90 name: "myapex.key",
91 public_key: "testkey.avbpubkey",
92 private_key: "testkey.pem",
93 }
94
Paul Duffinffa83752021-06-09 14:32:53 +010095 bootclasspath_fragment {
96 name: "bar-fragment",
97 contents: ["bar"],
Paul Duffindc3f9562021-06-09 15:31:05 +010098 apex_available: ["myapex"],
Paul Duffinffa83752021-06-09 14:32:53 +010099 api: {
100 stub_libs: ["foo"],
101 },
102 hidden_api: {
103 unsupported: [
104 "bar-unsupported.txt",
105 ],
106 removed: [
107 "bar-removed.txt",
108 ],
109 max_target_r_low_priority: [
110 "bar-max-target-r-low-priority.txt",
111 ],
112 max_target_q: [
113 "bar-max-target-q.txt",
114 ],
115 max_target_p: [
116 "bar-max-target-p.txt",
117 ],
118 max_target_o_low_priority: [
119 "bar-max-target-o-low-priority.txt",
120 ],
121 blocked: [
122 "bar-blocked.txt",
123 ],
124 unsupported_packages: [
125 "bar-unsupported-packages.txt",
126 ],
127 },
128 }
129
130 java_library {
131 name: "bar",
Paul Duffindc3f9562021-06-09 15:31:05 +0100132 apex_available: ["myapex"],
Paul Duffinffa83752021-06-09 14:32:53 +0100133 srcs: ["a.java"],
134 system_modules: "none",
135 sdk_version: "none",
136 compile_dex: true,
Paul Duffindc3f9562021-06-09 15:31:05 +0100137 permitted_packages: ["bar"],
Paul Duffinffa83752021-06-09 14:32:53 +0100138 }
139
140 java_sdk_library {
141 name: "foo",
142 srcs: ["a.java"],
143 public: {
144 enabled: true,
145 },
146 compile_dex: true,
147 }
148 `),
149 ).RunTest(t)
150
151 pbcp := result.Module("platform-bootclasspath", "android_common")
152 info := result.ModuleProvider(pbcp, java.MonolithicHiddenAPIInfoProvider).(java.MonolithicHiddenAPIInfo)
153
154 for _, category := range java.HiddenAPIFlagFileCategories {
155 name := category.PropertyName
156 message := fmt.Sprintf("category %s", name)
157 filename := strings.ReplaceAll(name, "_", "-")
158 expected := []string{fmt.Sprintf("%s.txt", filename), fmt.Sprintf("bar-%s.txt", filename)}
159 android.AssertPathsRelativeToTopEquals(t, message, expected, info.FlagsFilesByCategory[category])
160 }
161
Paul Duffindc3f9562021-06-09 15:31:05 +0100162 android.AssertPathsRelativeToTopEquals(t, "annotation flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/annotation-flags.csv"}, info.AnnotationFlagsPaths)
163 android.AssertPathsRelativeToTopEquals(t, "metadata flags", []string{"out/soong/.intermediates/bar-fragment/android_common_apex10000/modular-hiddenapi/metadata.csv"}, info.MetadataPaths)
164 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 +0100165
Paul Duffin280bae62021-07-20 18:03:53 +0100166 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())
167 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 +0100168}
169
Paul Duffinb432df92021-03-22 22:09:42 +0000170func TestPlatformBootclasspathDependencies(t *testing.T) {
171 result := android.GroupFixturePreparers(
172 prepareForTestWithPlatformBootclasspath,
173 prepareForTestWithArtApex,
174 prepareForTestWithMyapex,
175 // Configure some libraries in the art and framework boot images.
Paul Duffin60264a02021-04-12 20:02:36 +0100176 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo"),
satayevd604b212021-07-21 14:23:52 +0100177 java.FixtureConfigureApexBootJars("myapex:bar"),
Paul Duffinb432df92021-03-22 22:09:42 +0000178 java.PrepareForTestWithJavaSdkLibraryFiles,
179 java.FixtureWithLastReleaseApis("foo"),
180 ).RunTestWithBp(t, `
181 apex {
182 name: "com.android.art",
183 key: "com.android.art.key",
184 bootclasspath_fragments: [
185 "art-bootclasspath-fragment",
186 ],
187 updatable: false,
188 }
189
190 apex_key {
191 name: "com.android.art.key",
192 public_key: "com.android.art.avbpubkey",
193 private_key: "com.android.art.pem",
194 }
195
196 bootclasspath_fragment {
197 name: "art-bootclasspath-fragment",
satayevabcd5972021-08-06 17:49:46 +0100198 image_name: "art",
Paul Duffinb432df92021-03-22 22:09:42 +0000199 apex_available: [
200 "com.android.art",
201 ],
202 contents: [
203 "baz",
204 "quuz",
205 ],
206 }
207
208 java_library {
209 name: "baz",
210 apex_available: [
211 "com.android.art",
212 ],
213 srcs: ["b.java"],
214 installable: true,
215 }
216
217 // Add a java_import that is not preferred and so won't have an appropriate apex variant created
218 // for it to make sure that the platform_bootclasspath doesn't try and add a dependency onto it.
219 java_import {
220 name: "baz",
221 apex_available: [
222 "com.android.art",
223 ],
224 jars: ["b.jar"],
225 }
226
227 java_library {
228 name: "quuz",
229 apex_available: [
230 "com.android.art",
231 ],
232 srcs: ["b.java"],
233 installable: true,
234 }
235
236 apex {
237 name: "myapex",
238 key: "myapex.key",
Paul Duffin89f570a2021-06-16 01:42:33 +0100239 bootclasspath_fragments: [
240 "my-bootclasspath-fragment",
Paul Duffinb432df92021-03-22 22:09:42 +0000241 ],
242 updatable: false,
243 }
244
Paul Duffin89f570a2021-06-16 01:42:33 +0100245 bootclasspath_fragment {
246 name: "my-bootclasspath-fragment",
247 contents: ["bar"],
248 apex_available: ["myapex"],
249 }
250
Paul Duffinb432df92021-03-22 22:09:42 +0000251 apex_key {
252 name: "myapex.key",
253 public_key: "testkey.avbpubkey",
254 private_key: "testkey.pem",
255 }
256
257 java_sdk_library {
258 name: "foo",
259 srcs: ["b.java"],
260 }
261
262 java_library {
263 name: "bar",
264 srcs: ["b.java"],
265 installable: true,
266 apex_available: ["myapex"],
267 permitted_packages: ["bar"],
268 }
269
270 platform_bootclasspath {
271 name: "myplatform-bootclasspath",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100272
273 fragments: [
274 {
275 apex: "com.android.art",
276 module: "art-bootclasspath-fragment",
277 },
Paul Duffin89f570a2021-06-16 01:42:33 +0100278 {
279 apex: "myapex",
280 module: "my-bootclasspath-fragment",
281 },
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100282 ],
Paul Duffinb432df92021-03-22 22:09:42 +0000283 }
284`,
285 )
286
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100287 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100288 // The configured contents of BootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100289 "com.android.art:baz",
290 "com.android.art:quuz",
291 "platform:foo",
Paul Duffin74431d52021-04-21 14:10:42 +0100292
satayevd604b212021-07-21 14:23:52 +0100293 // The configured contents of ApexBootJars.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100294 "myapex:bar",
295 })
296
297 java.CheckPlatformBootclasspathFragments(t, result, "myplatform-bootclasspath", []string{
Paul Duffin89f570a2021-06-16 01:42:33 +0100298 "com.android.art:art-bootclasspath-fragment",
299 "myapex:my-bootclasspath-fragment",
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100300 })
301
Paul Duffinb432df92021-03-22 22:09:42 +0000302 // Make sure that the myplatform-bootclasspath has the correct dependencies.
303 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
Paul Duffin74431d52021-04-21 14:10:42 +0100304 // The following are stubs.
305 `platform:android_stubs_current`,
306 `platform:android_system_stubs_current`,
307 `platform:android_test_stubs_current`,
308 `platform:legacy.core.platform.api.stubs`,
309
310 // Needed for generating the boot image.
Paul Duffinb432df92021-03-22 22:09:42 +0000311 `platform:dex2oatd`,
Paul Duffin74431d52021-04-21 14:10:42 +0100312
313 // The configured contents of BootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000314 `com.android.art:baz`,
315 `com.android.art:quuz`,
316 `platform:foo`,
Paul Duffin74431d52021-04-21 14:10:42 +0100317
satayevd604b212021-07-21 14:23:52 +0100318 // The configured contents of ApexBootJars.
Paul Duffinb432df92021-03-22 22:09:42 +0000319 `myapex:bar`,
Paul Duffin74431d52021-04-21 14:10:42 +0100320
321 // The fragments.
Paul Duffin62d8c3b2021-04-07 20:35:11 +0100322 `com.android.art:art-bootclasspath-fragment`,
Paul Duffin89f570a2021-06-16 01:42:33 +0100323 `myapex:my-bootclasspath-fragment`,
Paul Duffinb432df92021-03-22 22:09:42 +0000324 })
325}
326
Paul Duffin7487a7a2021-05-19 09:36:09 +0100327// TestPlatformBootclasspath_AlwaysUsePrebuiltSdks verifies that the build does not fail when
328// AlwaysUsePrebuiltSdk() returns true. The structure of the modules in this test matches what
329// currently exists in some places in the Android build but it is not the intended structure. It is
330// in fact an invalid structure that should cause build failures. However, fixing that structure
331// will take too long so in the meantime this tests the workarounds to avoid build breakages.
332//
333// The main issues with this structure are:
334// 1. There is no prebuilt_bootclasspath_fragment referencing the "foo" java_sdk_library_import.
335// 2. There is no prebuilt_apex/apex_set which makes the dex implementation jar available to the
336// prebuilt_bootclasspath_fragment and the "foo" java_sdk_library_import.
337//
338// Together these cause the following symptoms:
339// 1. The "foo" java_sdk_library_import does not have a dex implementation jar.
340// 2. The "foo" java_sdk_library_import does not have a myapex variant.
341//
342// TODO(b/179354495): Fix the structure in this test once the main Android build has been fixed.
343func TestPlatformBootclasspath_AlwaysUsePrebuiltSdks(t *testing.T) {
344 result := android.GroupFixturePreparers(
345 prepareForTestWithPlatformBootclasspath,
346 prepareForTestWithMyapex,
347 // Configure two libraries, the first is a java_sdk_library whose prebuilt will be used because
348 // of AlwaysUsePrebuiltsSdk() but does not have an appropriate apex variant and does not provide
349 // a boot dex jar. The second is a normal library that is unaffected. The order matters because
350 // if the dependency on myapex:foo is filtered out because of either of those conditions then
351 // the dependencies resolved by the platform_bootclasspath will not match the configured list
352 // and so will fail the test.
satayevd604b212021-07-21 14:23:52 +0100353 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin7487a7a2021-05-19 09:36:09 +0100354 java.PrepareForTestWithJavaSdkLibraryFiles,
355 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
356 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
357 }),
358 java.FixtureWithPrebuiltApis(map[string][]string{
359 "current": {},
360 "30": {"foo"},
361 }),
362 ).RunTestWithBp(t, `
363 apex {
364 name: "myapex",
365 key: "myapex.key",
366 bootclasspath_fragments: [
367 "mybootclasspath-fragment",
368 ],
369 updatable: false,
370 }
371
372 apex_key {
373 name: "myapex.key",
374 public_key: "testkey.avbpubkey",
375 private_key: "testkey.pem",
376 }
377
378 java_library {
379 name: "bar",
380 srcs: ["b.java"],
381 installable: true,
382 apex_available: ["myapex"],
383 permitted_packages: ["bar"],
384 }
385
386 java_sdk_library {
387 name: "foo",
388 srcs: ["b.java"],
389 shared_library: false,
390 public: {
391 enabled: true,
392 },
393 apex_available: ["myapex"],
394 permitted_packages: ["foo"],
395 }
396
397 // A prebuilt java_sdk_library_import that is not preferred by default but will be preferred
398 // because AlwaysUsePrebuiltSdks() is true.
399 java_sdk_library_import {
400 name: "foo",
401 prefer: false,
402 shared_library: false,
Paul Duffin630b11e2021-07-15 13:35:26 +0100403 permitted_packages: ["foo"],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100404 public: {
405 jars: ["sdk_library/public/foo-stubs.jar"],
406 stub_srcs: ["sdk_library/public/foo_stub_sources"],
407 current_api: "sdk_library/public/foo.txt",
408 removed_api: "sdk_library/public/foo-removed.txt",
409 sdk_version: "current",
410 },
411 apex_available: ["myapex"],
412 }
413
414 // This always depends on the source foo module, its dependencies are not affected by the
415 // AlwaysUsePrebuiltSdks().
416 bootclasspath_fragment {
417 name: "mybootclasspath-fragment",
418 apex_available: [
419 "myapex",
420 ],
421 contents: [
422 "foo", "bar",
423 ],
424 }
425
426 platform_bootclasspath {
427 name: "myplatform-bootclasspath",
Paul Duffin89f570a2021-06-16 01:42:33 +0100428 fragments: [
429 {
430 apex: "myapex",
431 module:"mybootclasspath-fragment",
432 },
433 ],
Paul Duffin7487a7a2021-05-19 09:36:09 +0100434 }
435`,
436 )
437
438 java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
439 // The configured contents of BootJars.
440 "platform:prebuilt_foo", // Note: This is the platform not myapex variant.
441 "myapex:bar",
442 })
443
444 // Make sure that the myplatform-bootclasspath has the correct dependencies.
445 CheckModuleDependencies(t, result.TestContext, "myplatform-bootclasspath", "android_common", []string{
446 // The following are stubs.
447 "platform:prebuilt_sdk_public_current_android",
448 "platform:prebuilt_sdk_system_current_android",
449 "platform:prebuilt_sdk_test_current_android",
450
451 // Not a prebuilt as no prebuilt existed when it was added.
452 "platform:legacy.core.platform.api.stubs",
453
454 // Needed for generating the boot image.
Paul Duffin89f570a2021-06-16 01:42:33 +0100455 "platform:dex2oatd",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100456
457 // The platform_bootclasspath intentionally adds dependencies on both source and prebuilt
458 // modules when available as it does not know which one will be preferred.
459 //
460 // The source module has an APEX variant but the prebuilt does not.
461 "myapex:foo",
462 "platform:prebuilt_foo",
463
464 // Only a source module exists.
465 "myapex:bar",
Paul Duffin89f570a2021-06-16 01:42:33 +0100466
467 // The fragments.
468 "myapex:mybootclasspath-fragment",
Paul Duffin7487a7a2021-05-19 09:36:09 +0100469 })
470}
471
Paul Duffinb432df92021-03-22 22:09:42 +0000472// CheckModuleDependencies checks the dependencies of the selected module against the expected list.
473//
474// The expected list must be a list of strings of the form "<apex>:<module>", where <apex> is the
475// name of the apex, or platform is it is not part of an apex and <module> is the module name.
476func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
477 t.Helper()
478 module := ctx.ModuleForTests(name, variant).Module()
479 modules := []android.Module{}
480 ctx.VisitDirectDeps(module, func(m blueprint.Module) {
481 modules = append(modules, m.(android.Module))
482 })
483
484 pairs := java.ApexNamePairsFromModules(ctx, modules)
485 android.AssertDeepEquals(t, "module dependencies", expected, pairs)
486}
satayevb3090502021-06-15 17:49:10 +0100487
488// TestPlatformBootclasspath_IncludesRemainingApexJars verifies that any apex boot jar is present in
489// platform_bootclasspath's classpaths.proto config, if the apex does not generate its own config
490// by setting generate_classpaths_proto property to false.
491func TestPlatformBootclasspath_IncludesRemainingApexJars(t *testing.T) {
492 result := android.GroupFixturePreparers(
493 prepareForTestWithPlatformBootclasspath,
494 prepareForTestWithMyapex,
satayevd604b212021-07-21 14:23:52 +0100495 java.FixtureConfigureApexBootJars("myapex:foo"),
satayevb3090502021-06-15 17:49:10 +0100496 android.FixtureWithRootAndroidBp(`
497 platform_bootclasspath {
498 name: "platform-bootclasspath",
499 fragments: [
500 {
501 apex: "myapex",
502 module:"foo-fragment",
503 },
504 ],
505 }
506
507 apex {
508 name: "myapex",
509 key: "myapex.key",
510 bootclasspath_fragments: ["foo-fragment"],
511 updatable: false,
512 }
513
514 apex_key {
515 name: "myapex.key",
516 public_key: "testkey.avbpubkey",
517 private_key: "testkey.pem",
518 }
519
520 bootclasspath_fragment {
521 name: "foo-fragment",
522 generate_classpaths_proto: false,
523 contents: ["foo"],
524 apex_available: ["myapex"],
525 }
526
527 java_library {
528 name: "foo",
529 srcs: ["a.java"],
530 system_modules: "none",
531 sdk_version: "none",
532 compile_dex: true,
533 apex_available: ["myapex"],
534 permitted_packages: ["foo"],
535 }
536 `),
537 ).RunTest(t)
538
539 java.CheckClasspathFragmentProtoContentInfoProvider(t, result,
540 true, // proto should be generated
541 "myapex:foo", // apex doesn't generate its own config, so must be in platform_bootclasspath
542 "bootclasspath.pb",
543 "out/soong/target/product/test_device/system/etc/classpaths",
544 )
545}
satayevd34eb0c2021-08-06 13:20:28 +0100546
547func TestBootJarNotInApex(t *testing.T) {
548 android.GroupFixturePreparers(
549 prepareForTestWithPlatformBootclasspath,
550 PrepareForTestWithApexBuildComponents,
551 prepareForTestWithMyapex,
552 java.FixtureConfigureApexBootJars("myapex:foo"),
553 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
554 `dependency "foo" of "myplatform-bootclasspath" missing variant`)).
555 RunTestWithBp(t, `
556 apex {
557 name: "myapex",
558 key: "myapex.key",
559 updatable: false,
560 }
561
562 apex_key {
563 name: "myapex.key",
564 public_key: "testkey.avbpubkey",
565 private_key: "testkey.pem",
566 }
567
568 java_library {
569 name: "foo",
570 srcs: ["b.java"],
571 installable: true,
572 apex_available: [
573 "myapex",
574 ],
575 }
576
577 bootclasspath_fragment {
578 name: "not-in-apex-fragment",
579 contents: [
580 "foo",
581 ],
582 }
583
584 platform_bootclasspath {
585 name: "myplatform-bootclasspath",
586 }
587 `)
588}
589
590func TestBootFragmentNotInApex(t *testing.T) {
591 android.GroupFixturePreparers(
592 prepareForTestWithPlatformBootclasspath,
593 PrepareForTestWithApexBuildComponents,
594 prepareForTestWithMyapex,
595 java.FixtureConfigureApexBootJars("myapex:foo"),
596 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
597 `library foo.*have no corresponding fragment.*`)).RunTestWithBp(t, `
598 apex {
599 name: "myapex",
600 key: "myapex.key",
601 java_libs: ["foo"],
602 updatable: false,
603 }
604
605 apex_key {
606 name: "myapex.key",
607 public_key: "testkey.avbpubkey",
608 private_key: "testkey.pem",
609 }
610
611 java_library {
612 name: "foo",
613 srcs: ["b.java"],
614 installable: true,
615 apex_available: ["myapex"],
616 permitted_packages: ["foo"],
617 }
618
619 bootclasspath_fragment {
620 name: "not-in-apex-fragment",
621 contents: ["foo"],
622 }
623
624 platform_bootclasspath {
625 name: "myplatform-bootclasspath",
626 }
627 `)
628}
629
630func TestNonBootJarInFragment(t *testing.T) {
631 android.GroupFixturePreparers(
632 prepareForTestWithPlatformBootclasspath,
633 PrepareForTestWithApexBuildComponents,
634 prepareForTestWithMyapex,
635 java.FixtureConfigureApexBootJars("myapex:foo"),
636 ).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
637 `in contents must also be declared in PRODUCT_APEX_BOOT_JARS`)).
638 RunTestWithBp(t, `
639 apex {
640 name: "myapex",
641 key: "myapex.key",
642 bootclasspath_fragments: ["apex-fragment"],
643 updatable: false,
644 }
645
646 apex_key {
647 name: "myapex.key",
648 public_key: "testkey.avbpubkey",
649 private_key: "testkey.pem",
650 }
651
652 java_library {
653 name: "foo",
654 srcs: ["b.java"],
655 installable: true,
656 apex_available: ["myapex"],
657 permitted_packages: ["foo"],
658 }
659
660 java_library {
661 name: "bar",
662 srcs: ["b.java"],
663 installable: true,
664 apex_available: ["myapex"],
665 permitted_packages: ["bar"],
666 }
667
668 bootclasspath_fragment {
669 name: "apex-fragment",
670 contents: ["foo", "bar"],
671 apex_available:[ "myapex" ],
672 }
673
674 platform_bootclasspath {
675 name: "myplatform-bootclasspath",
676 fragments: [{
677 apex: "myapex",
678 module:"apex-fragment",
679 }],
680 }
681 `)
682}