blob: 9965f83bd4bbf9c3593492b0ef040687c84c8e72 [file] [log] [blame]
Paul Duffin3451e162021-01-20 15:16:56 +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 Duffinba6afd02019-11-19 19:44:10 +000018 "fmt"
Paul Duffina1d60252021-01-21 18:13:43 +000019 "strings"
Paul Duffin3451e162021-01-20 15:16:56 +000020 "testing"
21
22 "android/soong/android"
Paul Duffin3451e162021-01-20 15:16:56 +000023 "android/soong/java"
24)
25
Paul Duffin7771eba2021-04-23 14:25:28 +010026// Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART
27// bootclasspath_fragment requires modules from the ART apex.
Paul Duffin3451e162021-01-20 15:16:56 +000028
Paul Duffin94f19632021-04-20 12:40:07 +010029var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
Paul Duffin52bfaa42021-03-23 23:40:12 +000030 java.PrepareForTestWithDexpreopt,
31 PrepareForTestWithApexBuildComponents,
32)
33
34// Some additional files needed for the art apex.
35var prepareForTestWithArtApex = android.FixtureMergeMockFs(android.MockFS{
36 "com.android.art.avbpubkey": nil,
37 "com.android.art.pem": nil,
38 "system/sepolicy/apex/com.android.art-file_contexts": nil,
39})
40
Paul Duffin94f19632021-04-20 12:40:07 +010041func TestBootclasspathFragments(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +000042 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +010043 prepareForTestWithBootclasspathFragment,
Paul Duffin7771eba2021-04-23 14:25:28 +010044 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
Paul Duffin60264a02021-04-12 20:02:36 +010045 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
Paul Duffin52bfaa42021-03-23 23:40:12 +000046 prepareForTestWithArtApex,
47
48 java.PrepareForTestWithJavaSdkLibraryFiles,
49 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin34d433a2021-03-09 14:13:25 +000050 ).RunTestWithBp(t, `
Paul Duffin3451e162021-01-20 15:16:56 +000051 java_sdk_library {
52 name: "foo",
53 srcs: ["b.java"],
Paul Duffin3451e162021-01-20 15:16:56 +000054 }
55
56 java_library {
57 name: "bar",
58 srcs: ["b.java"],
59 installable: true,
60 }
61
62 apex {
63 name: "com.android.art",
64 key: "com.android.art.key",
65 java_libs: [
66 "baz",
67 "quuz",
68 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000069 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000070 }
71
72 apex_key {
73 name: "com.android.art.key",
74 public_key: "com.android.art.avbpubkey",
75 private_key: "com.android.art.pem",
76 }
77
78 java_library {
79 name: "baz",
80 apex_available: [
81 "com.android.art",
82 ],
83 srcs: ["b.java"],
84 }
85
86 java_library {
87 name: "quuz",
88 apex_available: [
89 "com.android.art",
90 ],
91 srcs: ["b.java"],
92 }
Paul Duffin5bbfef82021-01-30 12:57:26 +000093
Paul Duffin94f19632021-04-20 12:40:07 +010094 bootclasspath_fragment {
95 name: "art-bootclasspath-fragment",
Paul Duffin5bbfef82021-01-30 12:57:26 +000096 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +010097 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
98 contents: ["baz", "quuz"],
Paul Duffinc7ef9892021-03-23 23:21:59 +000099 apex_available: [
100 "com.android.art",
101 ],
Paul Duffin5bbfef82021-01-30 12:57:26 +0000102 }
103
Paul Duffin94f19632021-04-20 12:40:07 +0100104 bootclasspath_fragment {
105 name: "framework-bootclasspath-fragment",
Paul Duffin5bbfef82021-01-30 12:57:26 +0000106 image_name: "boot",
107 }
Paul Duffin3451e162021-01-20 15:16:56 +0000108`,
Paul Duffin3451e162021-01-20 15:16:56 +0000109 )
110
Paul Duffin94f19632021-04-20 12:40:07 +0100111 // Make sure that the framework-bootclasspath-fragment is using the correct configuration.
112 checkBootclasspathFragment(t, result, "framework-bootclasspath-fragment", "platform:foo,platform:bar", `
Paul Duffina1d60252021-01-21 18:13:43 +0000113test_device/dex_bootjars/android/system/framework/arm/boot-foo.art
114test_device/dex_bootjars/android/system/framework/arm/boot-foo.oat
115test_device/dex_bootjars/android/system/framework/arm/boot-foo.vdex
116test_device/dex_bootjars/android/system/framework/arm/boot-bar.art
117test_device/dex_bootjars/android/system/framework/arm/boot-bar.oat
118test_device/dex_bootjars/android/system/framework/arm/boot-bar.vdex
119test_device/dex_bootjars/android/system/framework/arm64/boot-foo.art
120test_device/dex_bootjars/android/system/framework/arm64/boot-foo.oat
121test_device/dex_bootjars/android/system/framework/arm64/boot-foo.vdex
122test_device/dex_bootjars/android/system/framework/arm64/boot-bar.art
123test_device/dex_bootjars/android/system/framework/arm64/boot-bar.oat
124test_device/dex_bootjars/android/system/framework/arm64/boot-bar.vdex
125`)
Paul Duffin3451e162021-01-20 15:16:56 +0000126
Paul Duffin94f19632021-04-20 12:40:07 +0100127 // Make sure that the art-bootclasspath-fragment is using the correct configuration.
128 checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000129test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
130test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
131test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
132test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
133test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
134test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
135test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
136test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
137test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
138test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
139test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
140test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
141`)
Paul Duffin3451e162021-01-20 15:16:56 +0000142}
143
Paul Duffinf1b358c2021-05-17 07:38:47 +0100144func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
145 result := android.GroupFixturePreparers(
146 prepareForTestWithBootclasspathFragment,
147 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
148 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
149 prepareForTestWithArtApex,
150
151 java.PrepareForTestWithJavaSdkLibraryFiles,
152 java.FixtureWithLastReleaseApis("foo", "baz"),
153 ).RunTestWithBp(t, `
154 java_sdk_library {
155 name: "foo",
156 srcs: ["b.java"],
157 shared_library: false,
158 public: {
159 enabled: true,
160 },
161 system: {
162 enabled: true,
163 },
164 }
165
166 java_library {
167 name: "bar",
168 srcs: ["b.java"],
169 installable: true,
170 }
171
172 apex {
173 name: "com.android.art",
174 key: "com.android.art.key",
175 bootclasspath_fragments: ["art-bootclasspath-fragment"],
176 updatable: false,
177 }
178
179 apex_key {
180 name: "com.android.art.key",
181 public_key: "com.android.art.avbpubkey",
182 private_key: "com.android.art.pem",
183 }
184
185 java_sdk_library {
186 name: "baz",
187 apex_available: [
188 "com.android.art",
189 ],
190 srcs: ["b.java"],
191 shared_library: false,
192 public: {
193 enabled: true,
194 },
195 system: {
196 enabled: true,
197 },
198 test: {
199 enabled: true,
200 },
201 }
202
203 java_library {
204 name: "quuz",
205 apex_available: [
206 "com.android.art",
207 ],
208 srcs: ["b.java"],
209 compile_dex: true,
210 }
211
212 bootclasspath_fragment {
213 name: "art-bootclasspath-fragment",
214 image_name: "art",
215 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
216 contents: ["baz", "quuz"],
217 apex_available: [
218 "com.android.art",
219 ],
220 }
221
222 bootclasspath_fragment {
223 name: "other-bootclasspath-fragment",
224 contents: ["foo", "bar"],
225 fragments: [
226 {
227 apex: "com.android.art",
228 module: "art-bootclasspath-fragment",
229 },
230 ],
231 }
232`,
233 )
234
235 checkSdkKindStubs := func(message string, info java.HiddenAPIInfo, kind android.SdkKind, expectedPaths ...string) {
236 t.Helper()
237 android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, kind), expectedPaths, info.TransitiveStubDexJarsByKind[kind])
238 }
239
240 // Check stub dex paths exported by art.
241 artFragment := result.Module("art-bootclasspath-fragment", "android_common")
242 artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
243
244 bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
245 bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
246 bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
247
248 checkSdkKindStubs("art", artInfo, android.SdkPublic, bazPublicStubs)
249 checkSdkKindStubs("art", artInfo, android.SdkSystem, bazSystemStubs)
250 checkSdkKindStubs("art", artInfo, android.SdkTest, bazTestStubs)
251 checkSdkKindStubs("art", artInfo, android.SdkCorePlatform)
252
253 // Check stub dex paths exported by other.
254 otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
255 otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
256
257 fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
258 fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
259
260 checkSdkKindStubs("other", otherInfo, android.SdkPublic, bazPublicStubs, fooPublicStubs)
261 checkSdkKindStubs("other", otherInfo, android.SdkSystem, bazSystemStubs, fooSystemStubs)
262 checkSdkKindStubs("other", otherInfo, android.SdkTest, bazTestStubs, fooSystemStubs)
263 checkSdkKindStubs("other", otherInfo, android.SdkCorePlatform)
264}
265
Paul Duffin94f19632021-04-20 12:40:07 +0100266func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000267 t.Helper()
268
Paul Duffin7771eba2021-04-23 14:25:28 +0100269 bootclasspathFragment := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000270
Paul Duffine946b322021-04-25 23:04:00 +0100271 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
272 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000273 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000274
275 // Get a list of all the paths in the boot image sorted by arch type.
276 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100277 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000278 for _, archType := range android.ArchTypeList() {
279 if paths, ok := bootImageFilesByArchType[archType]; ok {
280 for _, path := range paths {
281 allPaths = append(allPaths, android.NormalizePathForTesting(path))
282 }
283 }
284 }
Paul Duffin3451e162021-01-20 15:16:56 +0000285
Paul Duffin94f19632021-04-20 12:40:07 +0100286 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000287}
Paul Duffina1d60252021-01-21 18:13:43 +0000288
Paul Duffin94f19632021-04-20 12:40:07 +0100289func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000290 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100291 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000292 prepareForTestWithArtApex,
293
Paul Duffinba6afd02019-11-19 19:44:10 +0000294 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000295 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000296 name: "com.android.art",
297 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100298 bootclasspath_fragments: [
299 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000300 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000301 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100302 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
303 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000304 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000305 "bar",
306 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000307 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000308 }
309
310 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000311 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000312 public_key: "testkey.avbpubkey",
313 private_key: "testkey.pem",
314 }
315
316 java_library {
317 name: "foo",
318 srcs: ["b.java"],
319 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000320 apex_available: [
321 "com.android.art",
322 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000323 }
324
325 java_library {
326 name: "bar",
327 srcs: ["b.java"],
328 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000329 apex_available: [
330 "com.android.art",
331 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000332 }
333
Paul Duffin65898052021-04-20 22:47:03 +0100334 java_import {
335 name: "foo",
336 jars: ["foo.jar"],
337 apex_available: [
338 "com.android.art",
339 ],
340 }
341
342 java_import {
343 name: "bar",
344 jars: ["bar.jar"],
345 apex_available: [
346 "com.android.art",
347 ],
348 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000349 `),
350 )
Paul Duffin65898052021-04-20 22:47:03 +0100351
Paul Duffinba6afd02019-11-19 19:44:10 +0000352 contentsInsert := func(contents []string) string {
353 insert := ""
354 if contents != nil {
355 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000356 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000357 return insert
358 }
Paul Duffina1d60252021-01-21 18:13:43 +0000359
Paul Duffinba6afd02019-11-19 19:44:10 +0000360 addSource := func(contents ...string) android.FixturePreparer {
361 text := fmt.Sprintf(`
362 bootclasspath_fragment {
363 name: "mybootclasspathfragment",
364 image_name: "art",
365 %s
366 apex_available: [
367 "com.android.art",
368 ],
369 }
370 `, contentsInsert(contents))
371
372 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
373 }
374
375 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
376 text := fmt.Sprintf(`
377 prebuilt_bootclasspath_fragment {
378 name: "mybootclasspathfragment",
379 image_name: "art",
380 %s
381 prefer: %t,
382 apex_available: [
383 "com.android.art",
384 ],
385 }
386 `, contentsInsert(contents), prefer)
387 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
388 }
389
390 t.Run("boot image files", func(t *testing.T) {
391 result := android.GroupFixturePreparers(
392 commonPreparer,
393
394 // Configure some libraries in the art bootclasspath_fragment that match the source
395 // bootclasspath_fragment's contents property.
396 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
397 addSource("foo", "bar"),
398
399 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
400 addPrebuilt(true, "foo", "bar"),
401 ).RunTest(t)
402
403 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
satayev3db35472021-05-06 23:59:58 +0100404 "etc/classpaths/mybootclasspathfragment.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000405 "javalib/arm/boot.art",
406 "javalib/arm/boot.oat",
407 "javalib/arm/boot.vdex",
408 "javalib/arm/boot-bar.art",
409 "javalib/arm/boot-bar.oat",
410 "javalib/arm/boot-bar.vdex",
411 "javalib/arm64/boot.art",
412 "javalib/arm64/boot.oat",
413 "javalib/arm64/boot.vdex",
414 "javalib/arm64/boot-bar.art",
415 "javalib/arm64/boot-bar.oat",
416 "javalib/arm64/boot-bar.vdex",
417 "javalib/bar.jar",
418 "javalib/foo.jar",
419 })
420
421 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
422 `bar`,
423 `com.android.art.key`,
424 `mybootclasspathfragment`,
425 })
Paul Duffina1d60252021-01-21 18:13:43 +0000426 })
Paul Duffin396229f2021-03-18 18:30:31 +0000427
Paul Duffinba6afd02019-11-19 19:44:10 +0000428 t.Run("source with inconsistency between config and contents", func(t *testing.T) {
429 android.GroupFixturePreparers(
430 commonPreparer,
431
432 // Create an inconsistency between the ArtApexJars configuration and the art source
433 // bootclasspath_fragment module's contents property.
434 java.FixtureConfigureBootJars("com.android.art:foo"),
435 addSource("foo", "bar"),
436 ).
437 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
438 RunTest(t)
439 })
440
441 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
442 android.GroupFixturePreparers(
443 commonPreparer,
444
445 // Create an inconsistency between the ArtApexJars configuration and the art
446 // prebuilt_bootclasspath_fragment module's contents property.
447 java.FixtureConfigureBootJars("com.android.art:foo"),
448 addPrebuilt(false, "foo", "bar"),
449 ).
450 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
451 RunTest(t)
452 })
453
454 t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
455 android.GroupFixturePreparers(
456 commonPreparer,
457
458 // Create an inconsistency between the ArtApexJars configuration and the art
459 // prebuilt_bootclasspath_fragment module's contents property.
460 java.FixtureConfigureBootJars("com.android.art:foo"),
461 addPrebuilt(true, "foo", "bar"),
462
463 // Source contents property is consistent with the config.
464 addSource("foo"),
465 ).
466 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
467 RunTest(t)
468 })
469
470 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
471 android.GroupFixturePreparers(
472 commonPreparer,
473
474 // Create an inconsistency between the ArtApexJars configuration and the art
475 // prebuilt_bootclasspath_fragment module's contents property.
476 java.FixtureConfigureBootJars("com.android.art:foo"),
477 addPrebuilt(false, "foo", "bar"),
478
479 // Source contents property is consistent with the config.
480 addSource("foo"),
481
482 // This should pass because while the prebuilt is inconsistent with the configuration it is
483 // not actually used.
484 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000485 })
Paul Duffina1d60252021-01-21 18:13:43 +0000486}
487
Paul Duffin94f19632021-04-20 12:40:07 +0100488func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000489 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100490 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000491 prepareForTestWithArtApex,
492
493 android.FixtureMergeMockFs(android.MockFS{
494 "com.android.art-arm64.apex": nil,
495 "com.android.art-arm.apex": nil,
496 }),
497
Paul Duffin7771eba2021-04-23 14:25:28 +0100498 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100499 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin9ea71c02021-03-23 22:53:07 +0000500 ).RunTestWithBp(t, `
501 prebuilt_apex {
502 name: "com.android.art",
503 arch: {
504 arm64: {
505 src: "com.android.art-arm64.apex",
506 },
507 arm: {
508 src: "com.android.art-arm.apex",
509 },
510 },
511 exported_java_libs: ["foo", "bar"],
512 }
513
514 java_import {
515 name: "foo",
516 jars: ["foo.jar"],
517 apex_available: [
518 "com.android.art",
519 ],
520 }
521
522 java_import {
523 name: "bar",
524 jars: ["bar.jar"],
525 apex_available: [
526 "com.android.art",
527 ],
528 }
529
Paul Duffin7771eba2021-04-23 14:25:28 +0100530 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100531 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000532 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100533 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
534 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000535 apex_available: [
536 "com.android.art",
537 ],
538 }
539 `)
540
541 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common", []string{
Paul Duffin11216db2021-03-01 14:14:52 +0000542 `com.android.art.apex.selector`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000543 `prebuilt_bar`,
544 `prebuilt_foo`,
545 })
546
Paul Duffin94f19632021-04-20 12:40:07 +0100547 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common", []string{
Paul Duffin9ea71c02021-03-23 22:53:07 +0000548 `dex2oatd`,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000549 `prebuilt_bar`,
550 `prebuilt_foo`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000551 })
552}
553
Paul Duffin94f19632021-04-20 12:40:07 +0100554func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000555 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100556 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000557 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100558 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
559 java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"),
560 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
561 // is disabled.
562 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
563
564 java.PrepareForTestWithJavaSdkLibraryFiles,
565 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000566 ).RunTestWithBp(t, `
567 apex {
568 name: "myapex",
569 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100570 bootclasspath_fragments: [
571 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000572 ],
573 updatable: false,
574 }
575
576 apex_key {
577 name: "myapex.key",
578 public_key: "testkey.avbpubkey",
579 private_key: "testkey.pem",
580 }
581
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100582 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000583 name: "foo",
584 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100585 shared_library: false,
586 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000587 apex_available: [
588 "myapex",
589 ],
590 }
591
592 java_library {
593 name: "bar",
594 srcs: ["b.java"],
595 installable: true,
596 apex_available: [
597 "myapex",
598 ],
599 }
600
Paul Duffin7771eba2021-04-23 14:25:28 +0100601 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100602 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000603 contents: [
604 "foo",
605 "bar",
606 ],
607 apex_available: [
608 "myapex",
609 ],
610 }
611 `)
612
Paul Duffin4d101b62021-03-24 15:42:20 +0000613 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
614 // This does not include art, oat or vdex files as they are only included for the art boot
615 // image.
satayev3db35472021-05-06 23:59:58 +0100616 "etc/classpaths/mybootclasspathfragment.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000617 "javalib/bar.jar",
618 "javalib/foo.jar",
619 })
Paul Duffin82886d62021-03-24 01:34:57 +0000620
621 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
622 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100623 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000624 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100625
626 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
627 apexRule := apex.Rule("apexRule")
628 copyCommands := apexRule.Args["copy_commands"]
629
630 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
631 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
632
633 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
634
635 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
636 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100637 dexJar, err := info.DexBootJarPathForContentModule(module)
638 if err != nil {
639 t.Error(err)
640 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100641 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
642
643 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
644 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
645 }
646
Paul Duffin54c98f52021-05-15 08:54:30 +0100647 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
648 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000649}
650
Paul Duffina1d60252021-01-21 18:13:43 +0000651// TODO(b/177892522) - add test for host apex.