blob: 1971dcd637340c766081cf9451566869c6c01a1a [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",
Paul Duffin58e0e762021-05-21 19:27:58 +010065 bootclasspath_fragments: ["art-bootclasspath-fragment"],
Paul Duffin3451e162021-01-20 15:16:56 +000066 java_libs: [
67 "baz",
68 "quuz",
69 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000070 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000071 }
72
73 apex_key {
74 name: "com.android.art.key",
75 public_key: "com.android.art.avbpubkey",
76 private_key: "com.android.art.pem",
77 }
78
79 java_library {
80 name: "baz",
81 apex_available: [
82 "com.android.art",
83 ],
84 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +010085 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +000086 }
87
88 java_library {
89 name: "quuz",
90 apex_available: [
91 "com.android.art",
92 ],
93 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +010094 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +000095 }
Paul Duffin5bbfef82021-01-30 12:57:26 +000096
Paul Duffin94f19632021-04-20 12:40:07 +010097 bootclasspath_fragment {
98 name: "art-bootclasspath-fragment",
Paul Duffin5bbfef82021-01-30 12:57:26 +000099 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100100 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
101 contents: ["baz", "quuz"],
Paul Duffinc7ef9892021-03-23 23:21:59 +0000102 apex_available: [
103 "com.android.art",
104 ],
Paul Duffin5bbfef82021-01-30 12:57:26 +0000105 }
Paul Duffin3451e162021-01-20 15:16:56 +0000106`,
Paul Duffin3451e162021-01-20 15:16:56 +0000107 )
108
Paul Duffin94f19632021-04-20 12:40:07 +0100109 // Make sure that the art-bootclasspath-fragment is using the correct configuration.
Paul Duffin58e0e762021-05-21 19:27:58 +0100110 checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000",
111 "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000112test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
113test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
114test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
115test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
116test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
117test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
118test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
119test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
120test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
121test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
122test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
123test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
124`)
Paul Duffin3451e162021-01-20 15:16:56 +0000125}
126
Paul Duffinf1b358c2021-05-17 07:38:47 +0100127func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
128 result := android.GroupFixturePreparers(
129 prepareForTestWithBootclasspathFragment,
130 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
131 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
132 prepareForTestWithArtApex,
133
134 java.PrepareForTestWithJavaSdkLibraryFiles,
135 java.FixtureWithLastReleaseApis("foo", "baz"),
136 ).RunTestWithBp(t, `
137 java_sdk_library {
138 name: "foo",
139 srcs: ["b.java"],
140 shared_library: false,
141 public: {
142 enabled: true,
143 },
144 system: {
145 enabled: true,
146 },
147 }
148
149 java_library {
150 name: "bar",
151 srcs: ["b.java"],
152 installable: true,
153 }
154
155 apex {
156 name: "com.android.art",
157 key: "com.android.art.key",
158 bootclasspath_fragments: ["art-bootclasspath-fragment"],
159 updatable: false,
160 }
161
162 apex_key {
163 name: "com.android.art.key",
164 public_key: "com.android.art.avbpubkey",
165 private_key: "com.android.art.pem",
166 }
167
168 java_sdk_library {
169 name: "baz",
170 apex_available: [
171 "com.android.art",
172 ],
173 srcs: ["b.java"],
174 shared_library: false,
175 public: {
176 enabled: true,
177 },
178 system: {
179 enabled: true,
180 },
181 test: {
182 enabled: true,
183 },
184 }
185
186 java_library {
187 name: "quuz",
188 apex_available: [
189 "com.android.art",
190 ],
191 srcs: ["b.java"],
192 compile_dex: true,
193 }
194
195 bootclasspath_fragment {
196 name: "art-bootclasspath-fragment",
197 image_name: "art",
198 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
199 contents: ["baz", "quuz"],
200 apex_available: [
201 "com.android.art",
202 ],
203 }
204
205 bootclasspath_fragment {
206 name: "other-bootclasspath-fragment",
207 contents: ["foo", "bar"],
208 fragments: [
209 {
210 apex: "com.android.art",
211 module: "art-bootclasspath-fragment",
212 },
213 ],
214 }
215`,
216 )
217
218 checkSdkKindStubs := func(message string, info java.HiddenAPIInfo, kind android.SdkKind, expectedPaths ...string) {
219 t.Helper()
220 android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, kind), expectedPaths, info.TransitiveStubDexJarsByKind[kind])
221 }
222
223 // Check stub dex paths exported by art.
224 artFragment := result.Module("art-bootclasspath-fragment", "android_common")
225 artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
226
227 bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
228 bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
229 bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
230
231 checkSdkKindStubs("art", artInfo, android.SdkPublic, bazPublicStubs)
232 checkSdkKindStubs("art", artInfo, android.SdkSystem, bazSystemStubs)
233 checkSdkKindStubs("art", artInfo, android.SdkTest, bazTestStubs)
234 checkSdkKindStubs("art", artInfo, android.SdkCorePlatform)
235
236 // Check stub dex paths exported by other.
237 otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
238 otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
239
240 fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
241 fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
242
243 checkSdkKindStubs("other", otherInfo, android.SdkPublic, bazPublicStubs, fooPublicStubs)
244 checkSdkKindStubs("other", otherInfo, android.SdkSystem, bazSystemStubs, fooSystemStubs)
245 checkSdkKindStubs("other", otherInfo, android.SdkTest, bazTestStubs, fooSystemStubs)
246 checkSdkKindStubs("other", otherInfo, android.SdkCorePlatform)
247}
248
Paul Duffin58e0e762021-05-21 19:27:58 +0100249func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000250 t.Helper()
251
Paul Duffin58e0e762021-05-21 19:27:58 +0100252 bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000253
Paul Duffine946b322021-04-25 23:04:00 +0100254 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
255 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000256 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000257
258 // Get a list of all the paths in the boot image sorted by arch type.
259 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100260 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000261 for _, archType := range android.ArchTypeList() {
262 if paths, ok := bootImageFilesByArchType[archType]; ok {
263 for _, path := range paths {
264 allPaths = append(allPaths, android.NormalizePathForTesting(path))
265 }
266 }
267 }
Paul Duffin3451e162021-01-20 15:16:56 +0000268
Paul Duffin94f19632021-04-20 12:40:07 +0100269 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000270}
Paul Duffina1d60252021-01-21 18:13:43 +0000271
Paul Duffin94f19632021-04-20 12:40:07 +0100272func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000273 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100274 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000275 prepareForTestWithArtApex,
276
Paul Duffinba6afd02019-11-19 19:44:10 +0000277 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000278 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000279 name: "com.android.art",
280 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100281 bootclasspath_fragments: [
282 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000283 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000284 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100285 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
286 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000287 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000288 "bar",
289 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000290 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000291 }
292
293 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000294 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000295 public_key: "testkey.avbpubkey",
296 private_key: "testkey.pem",
297 }
298
299 java_library {
300 name: "foo",
301 srcs: ["b.java"],
302 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000303 apex_available: [
304 "com.android.art",
305 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000306 }
307
308 java_library {
309 name: "bar",
310 srcs: ["b.java"],
311 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000312 apex_available: [
313 "com.android.art",
314 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000315 }
316
Paul Duffin65898052021-04-20 22:47:03 +0100317 java_import {
318 name: "foo",
319 jars: ["foo.jar"],
320 apex_available: [
321 "com.android.art",
322 ],
Paul Duffine5218812021-06-07 13:28:19 +0100323 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100324 }
325
326 java_import {
327 name: "bar",
328 jars: ["bar.jar"],
329 apex_available: [
330 "com.android.art",
331 ],
Paul Duffine5218812021-06-07 13:28:19 +0100332 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100333 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000334 `),
335 )
Paul Duffin65898052021-04-20 22:47:03 +0100336
Paul Duffinba6afd02019-11-19 19:44:10 +0000337 contentsInsert := func(contents []string) string {
338 insert := ""
339 if contents != nil {
340 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000341 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000342 return insert
343 }
Paul Duffina1d60252021-01-21 18:13:43 +0000344
Paul Duffinba6afd02019-11-19 19:44:10 +0000345 addSource := func(contents ...string) android.FixturePreparer {
346 text := fmt.Sprintf(`
347 bootclasspath_fragment {
348 name: "mybootclasspathfragment",
349 image_name: "art",
350 %s
351 apex_available: [
352 "com.android.art",
353 ],
354 }
355 `, contentsInsert(contents))
356
357 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
358 }
359
360 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
361 text := fmt.Sprintf(`
362 prebuilt_bootclasspath_fragment {
363 name: "mybootclasspathfragment",
364 image_name: "art",
365 %s
366 prefer: %t,
367 apex_available: [
368 "com.android.art",
369 ],
370 }
371 `, contentsInsert(contents), prefer)
372 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
373 }
374
375 t.Run("boot image files", func(t *testing.T) {
376 result := android.GroupFixturePreparers(
377 commonPreparer,
378
379 // Configure some libraries in the art bootclasspath_fragment that match the source
380 // bootclasspath_fragment's contents property.
381 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
382 addSource("foo", "bar"),
383
384 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
385 addPrebuilt(true, "foo", "bar"),
386 ).RunTest(t)
387
388 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
satayev227e7452021-05-20 21:35:06 +0100389 "etc/classpaths/bootclasspath.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000390 "javalib/arm/boot.art",
391 "javalib/arm/boot.oat",
392 "javalib/arm/boot.vdex",
393 "javalib/arm/boot-bar.art",
394 "javalib/arm/boot-bar.oat",
395 "javalib/arm/boot-bar.vdex",
396 "javalib/arm64/boot.art",
397 "javalib/arm64/boot.oat",
398 "javalib/arm64/boot.vdex",
399 "javalib/arm64/boot-bar.art",
400 "javalib/arm64/boot-bar.oat",
401 "javalib/arm64/boot-bar.vdex",
402 "javalib/bar.jar",
403 "javalib/foo.jar",
404 })
405
406 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
407 `bar`,
408 `com.android.art.key`,
409 `mybootclasspathfragment`,
410 })
Paul Duffina1d60252021-01-21 18:13:43 +0000411 })
Paul Duffin396229f2021-03-18 18:30:31 +0000412
Paul Duffinba6afd02019-11-19 19:44:10 +0000413 t.Run("source with inconsistency between config and contents", func(t *testing.T) {
414 android.GroupFixturePreparers(
415 commonPreparer,
416
417 // Create an inconsistency between the ArtApexJars configuration and the art source
418 // bootclasspath_fragment module's contents property.
419 java.FixtureConfigureBootJars("com.android.art:foo"),
420 addSource("foo", "bar"),
421 ).
422 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
423 RunTest(t)
424 })
425
426 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
427 android.GroupFixturePreparers(
428 commonPreparer,
429
430 // Create an inconsistency between the ArtApexJars configuration and the art
431 // prebuilt_bootclasspath_fragment module's contents property.
432 java.FixtureConfigureBootJars("com.android.art:foo"),
433 addPrebuilt(false, "foo", "bar"),
434 ).
435 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
436 RunTest(t)
437 })
438
439 t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
440 android.GroupFixturePreparers(
441 commonPreparer,
442
443 // Create an inconsistency between the ArtApexJars configuration and the art
444 // prebuilt_bootclasspath_fragment module's contents property.
445 java.FixtureConfigureBootJars("com.android.art:foo"),
446 addPrebuilt(true, "foo", "bar"),
447
448 // Source contents property is consistent with the config.
449 addSource("foo"),
450 ).
451 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
452 RunTest(t)
453 })
454
455 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
456 android.GroupFixturePreparers(
457 commonPreparer,
458
459 // Create an inconsistency between the ArtApexJars configuration and the art
460 // prebuilt_bootclasspath_fragment module's contents property.
461 java.FixtureConfigureBootJars("com.android.art:foo"),
462 addPrebuilt(false, "foo", "bar"),
463
464 // Source contents property is consistent with the config.
465 addSource("foo"),
466
467 // This should pass because while the prebuilt is inconsistent with the configuration it is
468 // not actually used.
469 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000470 })
Paul Duffina1d60252021-01-21 18:13:43 +0000471}
472
Paul Duffin94f19632021-04-20 12:40:07 +0100473func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000474 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100475 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000476 prepareForTestWithArtApex,
477
478 android.FixtureMergeMockFs(android.MockFS{
479 "com.android.art-arm64.apex": nil,
480 "com.android.art-arm.apex": nil,
481 }),
482
Paul Duffin7771eba2021-04-23 14:25:28 +0100483 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100484 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin9ea71c02021-03-23 22:53:07 +0000485 ).RunTestWithBp(t, `
486 prebuilt_apex {
487 name: "com.android.art",
488 arch: {
489 arm64: {
490 src: "com.android.art-arm64.apex",
491 },
492 arm: {
493 src: "com.android.art-arm.apex",
494 },
495 },
Paul Duffine5218812021-06-07 13:28:19 +0100496 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000497 }
498
499 java_import {
500 name: "foo",
501 jars: ["foo.jar"],
502 apex_available: [
503 "com.android.art",
504 ],
505 }
506
507 java_import {
508 name: "bar",
509 jars: ["bar.jar"],
510 apex_available: [
511 "com.android.art",
512 ],
513 }
514
Paul Duffin7771eba2021-04-23 14:25:28 +0100515 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100516 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000517 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100518 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
519 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000520 apex_available: [
521 "com.android.art",
522 ],
523 }
524 `)
525
Paul Duffin6717d882021-06-15 19:09:41 +0100526 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
Paul Duffin11216db2021-03-01 14:14:52 +0000527 `com.android.art.apex.selector`,
Paul Duffine5218812021-06-07 13:28:19 +0100528 `prebuilt_mybootclasspathfragment`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000529 })
530
Paul Duffin94f19632021-04-20 12:40:07 +0100531 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common", []string{
Paul Duffin9ea71c02021-03-23 22:53:07 +0000532 `dex2oatd`,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000533 `prebuilt_bar`,
534 `prebuilt_foo`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000535 })
536}
537
Paul Duffin94f19632021-04-20 12:40:07 +0100538func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000539 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100540 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000541 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100542 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
543 java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"),
544 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
545 // is disabled.
546 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
547
548 java.PrepareForTestWithJavaSdkLibraryFiles,
549 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000550 ).RunTestWithBp(t, `
551 apex {
552 name: "myapex",
553 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100554 bootclasspath_fragments: [
555 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000556 ],
557 updatable: false,
558 }
559
560 apex_key {
561 name: "myapex.key",
562 public_key: "testkey.avbpubkey",
563 private_key: "testkey.pem",
564 }
565
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100566 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000567 name: "foo",
568 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100569 shared_library: false,
570 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000571 apex_available: [
572 "myapex",
573 ],
574 }
575
576 java_library {
577 name: "bar",
578 srcs: ["b.java"],
579 installable: true,
580 apex_available: [
581 "myapex",
582 ],
583 }
584
Paul Duffin7771eba2021-04-23 14:25:28 +0100585 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100586 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000587 contents: [
588 "foo",
589 "bar",
590 ],
591 apex_available: [
592 "myapex",
593 ],
594 }
595 `)
596
Paul Duffin4d101b62021-03-24 15:42:20 +0000597 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
598 // This does not include art, oat or vdex files as they are only included for the art boot
599 // image.
satayev227e7452021-05-20 21:35:06 +0100600 "etc/classpaths/bootclasspath.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000601 "javalib/bar.jar",
602 "javalib/foo.jar",
603 })
Paul Duffin82886d62021-03-24 01:34:57 +0000604
605 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
606 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100607 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000608 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100609
610 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
611 apexRule := apex.Rule("apexRule")
612 copyCommands := apexRule.Args["copy_commands"]
613
614 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
615 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
616
617 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
618
619 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
620 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100621 dexJar, err := info.DexBootJarPathForContentModule(module)
622 if err != nil {
623 t.Error(err)
624 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100625 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
626
627 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
628 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
629 }
630
Paul Duffin54c98f52021-05-15 08:54:30 +0100631 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
632 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000633}
634
Paul Duffina1d60252021-01-21 18:13:43 +0000635// TODO(b/177892522) - add test for host apex.