blob: b3f70cdac8d55962c231e6f346d4864c1d285dbf [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 Duffin94f19632021-04-20 12:40:07 +0100144func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000145 t.Helper()
146
Paul Duffin7771eba2021-04-23 14:25:28 +0100147 bootclasspathFragment := result.ModuleForTests(moduleName, "android_common").Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000148
Paul Duffine946b322021-04-25 23:04:00 +0100149 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
150 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000151 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000152
153 // Get a list of all the paths in the boot image sorted by arch type.
154 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100155 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000156 for _, archType := range android.ArchTypeList() {
157 if paths, ok := bootImageFilesByArchType[archType]; ok {
158 for _, path := range paths {
159 allPaths = append(allPaths, android.NormalizePathForTesting(path))
160 }
161 }
162 }
Paul Duffin3451e162021-01-20 15:16:56 +0000163
Paul Duffin94f19632021-04-20 12:40:07 +0100164 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000165}
Paul Duffina1d60252021-01-21 18:13:43 +0000166
Paul Duffin94f19632021-04-20 12:40:07 +0100167func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000168 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100169 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000170 prepareForTestWithArtApex,
171
Paul Duffinba6afd02019-11-19 19:44:10 +0000172 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000173 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000174 name: "com.android.art",
175 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100176 bootclasspath_fragments: [
177 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000178 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000179 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100180 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
181 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000182 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000183 "bar",
184 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000185 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000186 }
187
188 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000189 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000190 public_key: "testkey.avbpubkey",
191 private_key: "testkey.pem",
192 }
193
194 java_library {
195 name: "foo",
196 srcs: ["b.java"],
197 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000198 apex_available: [
199 "com.android.art",
200 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000201 }
202
203 java_library {
204 name: "bar",
205 srcs: ["b.java"],
206 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000207 apex_available: [
208 "com.android.art",
209 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000210 }
211
Paul Duffin65898052021-04-20 22:47:03 +0100212 java_import {
213 name: "foo",
214 jars: ["foo.jar"],
215 apex_available: [
216 "com.android.art",
217 ],
218 }
219
220 java_import {
221 name: "bar",
222 jars: ["bar.jar"],
223 apex_available: [
224 "com.android.art",
225 ],
226 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000227 `),
228 )
Paul Duffin65898052021-04-20 22:47:03 +0100229
Paul Duffinba6afd02019-11-19 19:44:10 +0000230 contentsInsert := func(contents []string) string {
231 insert := ""
232 if contents != nil {
233 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000234 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000235 return insert
236 }
Paul Duffina1d60252021-01-21 18:13:43 +0000237
Paul Duffinba6afd02019-11-19 19:44:10 +0000238 addSource := func(contents ...string) android.FixturePreparer {
239 text := fmt.Sprintf(`
240 bootclasspath_fragment {
241 name: "mybootclasspathfragment",
242 image_name: "art",
243 %s
244 apex_available: [
245 "com.android.art",
246 ],
247 }
248 `, contentsInsert(contents))
249
250 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
251 }
252
253 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
254 text := fmt.Sprintf(`
255 prebuilt_bootclasspath_fragment {
256 name: "mybootclasspathfragment",
257 image_name: "art",
258 %s
259 prefer: %t,
260 apex_available: [
261 "com.android.art",
262 ],
263 }
264 `, contentsInsert(contents), prefer)
265 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
266 }
267
268 t.Run("boot image files", func(t *testing.T) {
269 result := android.GroupFixturePreparers(
270 commonPreparer,
271
272 // Configure some libraries in the art bootclasspath_fragment that match the source
273 // bootclasspath_fragment's contents property.
274 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
275 addSource("foo", "bar"),
276
277 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
278 addPrebuilt(true, "foo", "bar"),
279 ).RunTest(t)
280
281 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
satayev3db35472021-05-06 23:59:58 +0100282 "etc/classpaths/mybootclasspathfragment.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000283 "javalib/arm/boot.art",
284 "javalib/arm/boot.oat",
285 "javalib/arm/boot.vdex",
286 "javalib/arm/boot-bar.art",
287 "javalib/arm/boot-bar.oat",
288 "javalib/arm/boot-bar.vdex",
289 "javalib/arm64/boot.art",
290 "javalib/arm64/boot.oat",
291 "javalib/arm64/boot.vdex",
292 "javalib/arm64/boot-bar.art",
293 "javalib/arm64/boot-bar.oat",
294 "javalib/arm64/boot-bar.vdex",
295 "javalib/bar.jar",
296 "javalib/foo.jar",
297 })
298
299 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
300 `bar`,
301 `com.android.art.key`,
302 `mybootclasspathfragment`,
303 })
Paul Duffina1d60252021-01-21 18:13:43 +0000304 })
Paul Duffin396229f2021-03-18 18:30:31 +0000305
Paul Duffinba6afd02019-11-19 19:44:10 +0000306 t.Run("source with inconsistency between config and contents", func(t *testing.T) {
307 android.GroupFixturePreparers(
308 commonPreparer,
309
310 // Create an inconsistency between the ArtApexJars configuration and the art source
311 // bootclasspath_fragment module's contents property.
312 java.FixtureConfigureBootJars("com.android.art:foo"),
313 addSource("foo", "bar"),
314 ).
315 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
316 RunTest(t)
317 })
318
319 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
320 android.GroupFixturePreparers(
321 commonPreparer,
322
323 // Create an inconsistency between the ArtApexJars configuration and the art
324 // prebuilt_bootclasspath_fragment module's contents property.
325 java.FixtureConfigureBootJars("com.android.art:foo"),
326 addPrebuilt(false, "foo", "bar"),
327 ).
328 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
329 RunTest(t)
330 })
331
332 t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
333 android.GroupFixturePreparers(
334 commonPreparer,
335
336 // Create an inconsistency between the ArtApexJars configuration and the art
337 // prebuilt_bootclasspath_fragment module's contents property.
338 java.FixtureConfigureBootJars("com.android.art:foo"),
339 addPrebuilt(true, "foo", "bar"),
340
341 // Source contents property is consistent with the config.
342 addSource("foo"),
343 ).
344 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
345 RunTest(t)
346 })
347
348 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
349 android.GroupFixturePreparers(
350 commonPreparer,
351
352 // Create an inconsistency between the ArtApexJars configuration and the art
353 // prebuilt_bootclasspath_fragment module's contents property.
354 java.FixtureConfigureBootJars("com.android.art:foo"),
355 addPrebuilt(false, "foo", "bar"),
356
357 // Source contents property is consistent with the config.
358 addSource("foo"),
359
360 // This should pass because while the prebuilt is inconsistent with the configuration it is
361 // not actually used.
362 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000363 })
Paul Duffina1d60252021-01-21 18:13:43 +0000364}
365
Paul Duffin94f19632021-04-20 12:40:07 +0100366func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000367 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100368 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000369 prepareForTestWithArtApex,
370
371 android.FixtureMergeMockFs(android.MockFS{
372 "com.android.art-arm64.apex": nil,
373 "com.android.art-arm.apex": nil,
374 }),
375
Paul Duffin7771eba2021-04-23 14:25:28 +0100376 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100377 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin9ea71c02021-03-23 22:53:07 +0000378 ).RunTestWithBp(t, `
379 prebuilt_apex {
380 name: "com.android.art",
381 arch: {
382 arm64: {
383 src: "com.android.art-arm64.apex",
384 },
385 arm: {
386 src: "com.android.art-arm.apex",
387 },
388 },
389 exported_java_libs: ["foo", "bar"],
390 }
391
392 java_import {
393 name: "foo",
394 jars: ["foo.jar"],
395 apex_available: [
396 "com.android.art",
397 ],
398 }
399
400 java_import {
401 name: "bar",
402 jars: ["bar.jar"],
403 apex_available: [
404 "com.android.art",
405 ],
406 }
407
Paul Duffin7771eba2021-04-23 14:25:28 +0100408 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100409 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000410 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100411 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
412 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000413 apex_available: [
414 "com.android.art",
415 ],
416 }
417 `)
418
419 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common", []string{
Paul Duffin11216db2021-03-01 14:14:52 +0000420 `com.android.art.apex.selector`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000421 `prebuilt_bar`,
422 `prebuilt_foo`,
423 })
424
Paul Duffin94f19632021-04-20 12:40:07 +0100425 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common", []string{
Paul Duffin9ea71c02021-03-23 22:53:07 +0000426 `dex2oatd`,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000427 `prebuilt_bar`,
428 `prebuilt_foo`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000429 })
430}
431
Paul Duffin94f19632021-04-20 12:40:07 +0100432func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000433 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100434 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000435 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100436 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
437 java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"),
438 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
439 // is disabled.
440 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
441
442 java.PrepareForTestWithJavaSdkLibraryFiles,
443 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000444 ).RunTestWithBp(t, `
445 apex {
446 name: "myapex",
447 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100448 bootclasspath_fragments: [
449 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000450 ],
451 updatable: false,
452 }
453
454 apex_key {
455 name: "myapex.key",
456 public_key: "testkey.avbpubkey",
457 private_key: "testkey.pem",
458 }
459
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100460 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000461 name: "foo",
462 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100463 shared_library: false,
464 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000465 apex_available: [
466 "myapex",
467 ],
468 }
469
470 java_library {
471 name: "bar",
472 srcs: ["b.java"],
473 installable: true,
474 apex_available: [
475 "myapex",
476 ],
477 }
478
Paul Duffin7771eba2021-04-23 14:25:28 +0100479 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100480 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000481 contents: [
482 "foo",
483 "bar",
484 ],
485 apex_available: [
486 "myapex",
487 ],
488 }
489 `)
490
Paul Duffin4d101b62021-03-24 15:42:20 +0000491 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
492 // This does not include art, oat or vdex files as they are only included for the art boot
493 // image.
satayev3db35472021-05-06 23:59:58 +0100494 "etc/classpaths/mybootclasspathfragment.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000495 "javalib/bar.jar",
496 "javalib/foo.jar",
497 })
Paul Duffin82886d62021-03-24 01:34:57 +0000498
499 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
500 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100501 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000502 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100503
504 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
505 apexRule := apex.Rule("apexRule")
506 copyCommands := apexRule.Args["copy_commands"]
507
508 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
509 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
510
511 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
512
513 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
514 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100515 dexJar, err := info.DexBootJarPathForContentModule(module)
516 if err != nil {
517 t.Error(err)
518 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100519 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
520
521 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
522 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
523 }
524
Paul Duffin54c98f52021-05-15 08:54:30 +0100525 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
526 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000527}
528
Paul Duffina1d60252021-01-21 18:13:43 +0000529// TODO(b/177892522) - add test for host apex.