blob: 5cd3eab6ad680486b1c4280548c6b478a5d192c5 [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 Duffince918b02021-06-07 14:33:47 +010019 "sort"
Paul Duffina1d60252021-01-21 18:13:43 +000020 "strings"
Paul Duffin3451e162021-01-20 15:16:56 +000021 "testing"
22
23 "android/soong/android"
Paul Duffin3451e162021-01-20 15:16:56 +000024 "android/soong/java"
Paul Duffin5cca7c42021-05-26 10:16:01 +010025 "github.com/google/blueprint/proptools"
Paul Duffin3451e162021-01-20 15:16:56 +000026)
27
Paul Duffin7771eba2021-04-23 14:25:28 +010028// Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART
29// bootclasspath_fragment requires modules from the ART apex.
Paul Duffin3451e162021-01-20 15:16:56 +000030
Paul Duffin94f19632021-04-20 12:40:07 +010031var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
Paul Duffin52bfaa42021-03-23 23:40:12 +000032 java.PrepareForTestWithDexpreopt,
33 PrepareForTestWithApexBuildComponents,
34)
35
36// Some additional files needed for the art apex.
37var prepareForTestWithArtApex = android.FixtureMergeMockFs(android.MockFS{
38 "com.android.art.avbpubkey": nil,
39 "com.android.art.pem": nil,
40 "system/sepolicy/apex/com.android.art-file_contexts": nil,
41})
42
Paul Duffin94f19632021-04-20 12:40:07 +010043func TestBootclasspathFragments(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +000044 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +010045 prepareForTestWithBootclasspathFragment,
Paul Duffin7771eba2021-04-23 14:25:28 +010046 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
Paul Duffin60264a02021-04-12 20:02:36 +010047 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
Paul Duffin52bfaa42021-03-23 23:40:12 +000048 prepareForTestWithArtApex,
49
50 java.PrepareForTestWithJavaSdkLibraryFiles,
51 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin34d433a2021-03-09 14:13:25 +000052 ).RunTestWithBp(t, `
Paul Duffin3451e162021-01-20 15:16:56 +000053 java_sdk_library {
54 name: "foo",
55 srcs: ["b.java"],
Paul Duffin3451e162021-01-20 15:16:56 +000056 }
57
58 java_library {
59 name: "bar",
60 srcs: ["b.java"],
61 installable: true,
62 }
63
64 apex {
65 name: "com.android.art",
66 key: "com.android.art.key",
Paul Duffin58e0e762021-05-21 19:27:58 +010067 bootclasspath_fragments: ["art-bootclasspath-fragment"],
Paul Duffin3451e162021-01-20 15:16:56 +000068 java_libs: [
69 "baz",
70 "quuz",
71 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000072 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000073 }
74
75 apex_key {
76 name: "com.android.art.key",
77 public_key: "com.android.art.avbpubkey",
78 private_key: "com.android.art.pem",
79 }
80
81 java_library {
82 name: "baz",
83 apex_available: [
84 "com.android.art",
85 ],
86 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +010087 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +000088 }
89
90 java_library {
91 name: "quuz",
92 apex_available: [
93 "com.android.art",
94 ],
95 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +010096 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +000097 }
Paul Duffin5bbfef82021-01-30 12:57:26 +000098
Paul Duffin94f19632021-04-20 12:40:07 +010099 bootclasspath_fragment {
100 name: "art-bootclasspath-fragment",
Paul Duffin5bbfef82021-01-30 12:57:26 +0000101 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100102 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
103 contents: ["baz", "quuz"],
Paul Duffinc7ef9892021-03-23 23:21:59 +0000104 apex_available: [
105 "com.android.art",
106 ],
Paul Duffin5bbfef82021-01-30 12:57:26 +0000107 }
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 art-bootclasspath-fragment is using the correct configuration.
Paul Duffin58e0e762021-05-21 19:27:58 +0100112 checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000",
113 "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000114test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
115test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
116test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
117test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
118test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
119test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
120test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
121test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
122test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
123test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
124test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
125test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
126`)
Paul Duffin3451e162021-01-20 15:16:56 +0000127}
128
Paul Duffinf1b358c2021-05-17 07:38:47 +0100129func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
130 result := android.GroupFixturePreparers(
131 prepareForTestWithBootclasspathFragment,
132 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
133 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
134 prepareForTestWithArtApex,
135
136 java.PrepareForTestWithJavaSdkLibraryFiles,
137 java.FixtureWithLastReleaseApis("foo", "baz"),
138 ).RunTestWithBp(t, `
139 java_sdk_library {
140 name: "foo",
141 srcs: ["b.java"],
142 shared_library: false,
143 public: {
144 enabled: true,
145 },
146 system: {
147 enabled: true,
148 },
149 }
150
151 java_library {
152 name: "bar",
153 srcs: ["b.java"],
154 installable: true,
155 }
156
157 apex {
158 name: "com.android.art",
159 key: "com.android.art.key",
160 bootclasspath_fragments: ["art-bootclasspath-fragment"],
161 updatable: false,
162 }
163
164 apex_key {
165 name: "com.android.art.key",
166 public_key: "com.android.art.avbpubkey",
167 private_key: "com.android.art.pem",
168 }
169
170 java_sdk_library {
171 name: "baz",
172 apex_available: [
173 "com.android.art",
174 ],
175 srcs: ["b.java"],
176 shared_library: false,
177 public: {
178 enabled: true,
179 },
180 system: {
181 enabled: true,
182 },
183 test: {
184 enabled: true,
185 },
186 }
187
188 java_library {
189 name: "quuz",
190 apex_available: [
191 "com.android.art",
192 ],
193 srcs: ["b.java"],
194 compile_dex: true,
195 }
196
197 bootclasspath_fragment {
198 name: "art-bootclasspath-fragment",
199 image_name: "art",
200 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
201 contents: ["baz", "quuz"],
202 apex_available: [
203 "com.android.art",
204 ],
205 }
206
207 bootclasspath_fragment {
208 name: "other-bootclasspath-fragment",
209 contents: ["foo", "bar"],
210 fragments: [
211 {
212 apex: "com.android.art",
213 module: "art-bootclasspath-fragment",
214 },
215 ],
216 }
217`,
218 )
219
Paul Duffin31fad802021-06-18 18:14:25 +0100220 checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) {
Paul Duffinf1b358c2021-05-17 07:38:47 +0100221 t.Helper()
Paul Duffin280a31a2021-06-27 20:28:29 +0100222 paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope)
223 android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100224 }
225
226 // Check stub dex paths exported by art.
227 artFragment := result.Module("art-bootclasspath-fragment", "android_common")
228 artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
229
230 bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
231 bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
232 bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
233
Paul Duffin31fad802021-06-18 18:14:25 +0100234 checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
235 checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
236 checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
237 checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100238
239 // Check stub dex paths exported by other.
240 otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
241 otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
242
243 fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
244 fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
245
Paul Duffin31fad802021-06-18 18:14:25 +0100246 checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
247 checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
248 checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
249 checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100250}
251
Paul Duffin58e0e762021-05-21 19:27:58 +0100252func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000253 t.Helper()
254
Paul Duffin58e0e762021-05-21 19:27:58 +0100255 bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000256
Paul Duffine946b322021-04-25 23:04:00 +0100257 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
258 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000259 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000260
261 // Get a list of all the paths in the boot image sorted by arch type.
262 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100263 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000264 for _, archType := range android.ArchTypeList() {
265 if paths, ok := bootImageFilesByArchType[archType]; ok {
266 for _, path := range paths {
267 allPaths = append(allPaths, android.NormalizePathForTesting(path))
268 }
269 }
270 }
Paul Duffin3451e162021-01-20 15:16:56 +0000271
Paul Duffin94f19632021-04-20 12:40:07 +0100272 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000273}
Paul Duffina1d60252021-01-21 18:13:43 +0000274
Paul Duffin94f19632021-04-20 12:40:07 +0100275func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000276 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100277 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000278 prepareForTestWithArtApex,
279
Paul Duffinba6afd02019-11-19 19:44:10 +0000280 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000281 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000282 name: "com.android.art",
283 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100284 bootclasspath_fragments: [
285 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000286 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000287 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100288 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
289 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000290 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000291 "bar",
292 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000293 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000294 }
295
296 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000297 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000298 public_key: "testkey.avbpubkey",
299 private_key: "testkey.pem",
300 }
301
302 java_library {
303 name: "foo",
304 srcs: ["b.java"],
305 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000306 apex_available: [
307 "com.android.art",
308 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000309 }
310
311 java_library {
312 name: "bar",
313 srcs: ["b.java"],
314 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000315 apex_available: [
316 "com.android.art",
317 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000318 }
319
Paul Duffin65898052021-04-20 22:47:03 +0100320 java_import {
321 name: "foo",
322 jars: ["foo.jar"],
323 apex_available: [
324 "com.android.art",
325 ],
Paul Duffine5218812021-06-07 13:28:19 +0100326 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100327 }
328
329 java_import {
330 name: "bar",
331 jars: ["bar.jar"],
332 apex_available: [
333 "com.android.art",
334 ],
Paul Duffine5218812021-06-07 13:28:19 +0100335 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100336 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000337 `),
338 )
Paul Duffin65898052021-04-20 22:47:03 +0100339
Paul Duffinba6afd02019-11-19 19:44:10 +0000340 contentsInsert := func(contents []string) string {
341 insert := ""
342 if contents != nil {
343 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000344 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000345 return insert
346 }
Paul Duffina1d60252021-01-21 18:13:43 +0000347
Paul Duffinba6afd02019-11-19 19:44:10 +0000348 addSource := func(contents ...string) android.FixturePreparer {
349 text := fmt.Sprintf(`
350 bootclasspath_fragment {
351 name: "mybootclasspathfragment",
352 image_name: "art",
353 %s
354 apex_available: [
355 "com.android.art",
356 ],
357 }
358 `, contentsInsert(contents))
359
360 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
361 }
362
363 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
364 text := fmt.Sprintf(`
Paul Duffince918b02021-06-07 14:33:47 +0100365 prebuilt_apex {
366 name: "com.android.art",
367 arch: {
368 arm64: {
369 src: "com.android.art-arm64.apex",
370 },
371 arm: {
372 src: "com.android.art-arm.apex",
373 },
374 },
375 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
376 }
377
Paul Duffinba6afd02019-11-19 19:44:10 +0000378 prebuilt_bootclasspath_fragment {
379 name: "mybootclasspathfragment",
380 image_name: "art",
381 %s
382 prefer: %t,
383 apex_available: [
384 "com.android.art",
385 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100386 hidden_api: {
387 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
388 metadata: "mybootclasspathfragment/metadata.csv",
389 index: "mybootclasspathfragment/index.csv",
390 stub_flags: "mybootclasspathfragment/stub-flags.csv",
391 all_flags: "mybootclasspathfragment/all-flags.csv",
392 },
Paul Duffinba6afd02019-11-19 19:44:10 +0000393 }
394 `, contentsInsert(contents), prefer)
395 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
396 }
397
Paul Duffince918b02021-06-07 14:33:47 +0100398 t.Run("boot image files from source", func(t *testing.T) {
399 result := android.GroupFixturePreparers(
400 commonPreparer,
401
402 // Configure some libraries in the art bootclasspath_fragment that match the source
403 // bootclasspath_fragment's contents property.
404 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
405 addSource("foo", "bar"),
406 ).RunTest(t)
407
408 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
409 "etc/classpaths/bootclasspath.pb",
410 "javalib/arm/boot.art",
411 "javalib/arm/boot.oat",
412 "javalib/arm/boot.vdex",
413 "javalib/arm/boot-bar.art",
414 "javalib/arm/boot-bar.oat",
415 "javalib/arm/boot-bar.vdex",
416 "javalib/arm64/boot.art",
417 "javalib/arm64/boot.oat",
418 "javalib/arm64/boot.vdex",
419 "javalib/arm64/boot-bar.art",
420 "javalib/arm64/boot-bar.oat",
421 "javalib/arm64/boot-bar.vdex",
422 "javalib/bar.jar",
423 "javalib/foo.jar",
424 })
425
426 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
427 `bar`,
428 `com.android.art.key`,
429 `mybootclasspathfragment`,
430 })
431
432 // Make sure that the source bootclasspath_fragment copies its dex files to the predefined
433 // locations for the art image.
434 module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
435 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
436 })
437
438 t.Run("boot image files with preferred prebuilt", func(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000439 result := android.GroupFixturePreparers(
440 commonPreparer,
441
442 // Configure some libraries in the art bootclasspath_fragment that match the source
443 // bootclasspath_fragment's contents property.
444 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
445 addSource("foo", "bar"),
446
447 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
448 addPrebuilt(true, "foo", "bar"),
449 ).RunTest(t)
450
451 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
satayev227e7452021-05-20 21:35:06 +0100452 "etc/classpaths/bootclasspath.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000453 "javalib/arm/boot.art",
454 "javalib/arm/boot.oat",
455 "javalib/arm/boot.vdex",
456 "javalib/arm/boot-bar.art",
457 "javalib/arm/boot-bar.oat",
458 "javalib/arm/boot-bar.vdex",
459 "javalib/arm64/boot.art",
460 "javalib/arm64/boot.oat",
461 "javalib/arm64/boot.vdex",
462 "javalib/arm64/boot-bar.art",
463 "javalib/arm64/boot-bar.oat",
464 "javalib/arm64/boot-bar.vdex",
465 "javalib/bar.jar",
466 "javalib/foo.jar",
467 })
468
469 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
470 `bar`,
471 `com.android.art.key`,
472 `mybootclasspathfragment`,
Paul Duffince918b02021-06-07 14:33:47 +0100473 `prebuilt_com.android.art`,
Paul Duffinba6afd02019-11-19 19:44:10 +0000474 })
Paul Duffince918b02021-06-07 14:33:47 +0100475
476 // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined
477 // locations for the art image.
478 module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art")
479 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
Paul Duffina1d60252021-01-21 18:13:43 +0000480 })
Paul Duffin396229f2021-03-18 18:30:31 +0000481
Paul Duffinba6afd02019-11-19 19:44:10 +0000482 t.Run("source with inconsistency between config and contents", func(t *testing.T) {
483 android.GroupFixturePreparers(
484 commonPreparer,
485
486 // Create an inconsistency between the ArtApexJars configuration and the art source
487 // bootclasspath_fragment module's contents property.
488 java.FixtureConfigureBootJars("com.android.art:foo"),
489 addSource("foo", "bar"),
490 ).
491 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
492 RunTest(t)
493 })
494
495 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
496 android.GroupFixturePreparers(
497 commonPreparer,
498
499 // Create an inconsistency between the ArtApexJars configuration and the art
500 // prebuilt_bootclasspath_fragment module's contents property.
501 java.FixtureConfigureBootJars("com.android.art:foo"),
502 addPrebuilt(false, "foo", "bar"),
503 ).
504 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
505 RunTest(t)
506 })
507
508 t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
509 android.GroupFixturePreparers(
510 commonPreparer,
511
512 // Create an inconsistency between the ArtApexJars configuration and the art
513 // prebuilt_bootclasspath_fragment module's contents property.
514 java.FixtureConfigureBootJars("com.android.art:foo"),
515 addPrebuilt(true, "foo", "bar"),
516
517 // Source contents property is consistent with the config.
518 addSource("foo"),
519 ).
520 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
521 RunTest(t)
522 })
523
524 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
525 android.GroupFixturePreparers(
526 commonPreparer,
527
528 // Create an inconsistency between the ArtApexJars configuration and the art
529 // prebuilt_bootclasspath_fragment module's contents property.
530 java.FixtureConfigureBootJars("com.android.art:foo"),
531 addPrebuilt(false, "foo", "bar"),
532
533 // Source contents property is consistent with the config.
534 addSource("foo"),
535
536 // This should pass because while the prebuilt is inconsistent with the configuration it is
537 // not actually used.
538 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000539 })
Paul Duffina1d60252021-01-21 18:13:43 +0000540}
541
Paul Duffin94f19632021-04-20 12:40:07 +0100542func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000543 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100544 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000545 prepareForTestWithArtApex,
546
547 android.FixtureMergeMockFs(android.MockFS{
548 "com.android.art-arm64.apex": nil,
549 "com.android.art-arm.apex": nil,
550 }),
551
Paul Duffin7771eba2021-04-23 14:25:28 +0100552 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100553 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin9ea71c02021-03-23 22:53:07 +0000554 ).RunTestWithBp(t, `
555 prebuilt_apex {
556 name: "com.android.art",
557 arch: {
558 arm64: {
559 src: "com.android.art-arm64.apex",
560 },
561 arm: {
562 src: "com.android.art-arm.apex",
563 },
564 },
Paul Duffine5218812021-06-07 13:28:19 +0100565 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000566 }
567
568 java_import {
569 name: "foo",
570 jars: ["foo.jar"],
571 apex_available: [
572 "com.android.art",
573 ],
574 }
575
576 java_import {
577 name: "bar",
578 jars: ["bar.jar"],
579 apex_available: [
580 "com.android.art",
581 ],
582 }
583
Paul Duffin7771eba2021-04-23 14:25:28 +0100584 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100585 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000586 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100587 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
588 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000589 apex_available: [
590 "com.android.art",
591 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100592 hidden_api: {
593 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
594 metadata: "mybootclasspathfragment/metadata.csv",
595 index: "mybootclasspathfragment/index.csv",
596 stub_flags: "mybootclasspathfragment/stub-flags.csv",
597 all_flags: "mybootclasspathfragment/all-flags.csv",
598 },
Paul Duffin9ea71c02021-03-23 22:53:07 +0000599 }
600 `)
601
Paul Duffin6717d882021-06-15 19:09:41 +0100602 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
Paul Duffin11216db2021-03-01 14:14:52 +0000603 `com.android.art.apex.selector`,
Paul Duffine5218812021-06-07 13:28:19 +0100604 `prebuilt_mybootclasspathfragment`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000605 })
606
Paul Duffince918b02021-06-07 14:33:47 +0100607 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{
Paul Duffin5466a362021-06-07 10:25:31 +0100608 `com.android.art.deapexer`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000609 `dex2oatd`,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000610 `prebuilt_bar`,
611 `prebuilt_foo`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000612 })
Paul Duffince918b02021-06-07 14:33:47 +0100613
614 module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art")
615 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
616}
617
618// checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the
619// predefined locations of boot dex jars used as inputs for the ART boot image.
620func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) {
621 t.Helper()
622 bootJarLocations := []string{}
623 for _, output := range module.AllOutputs() {
624 output = android.StringRelativeToTop(config, output)
625 if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") {
626 bootJarLocations = append(bootJarLocations, output)
627 }
628 }
629
630 sort.Strings(bootJarLocations)
631 expected := []string{}
632 for _, m := range modules {
633 expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m))
634 }
635 sort.Strings(expected)
636
637 android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations)
Paul Duffin9ea71c02021-03-23 22:53:07 +0000638}
639
Paul Duffin94f19632021-04-20 12:40:07 +0100640func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000641 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100642 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000643 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100644 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
645 java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"),
646 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
647 // is disabled.
648 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
649
650 java.PrepareForTestWithJavaSdkLibraryFiles,
651 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000652 ).RunTestWithBp(t, `
653 apex {
654 name: "myapex",
655 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100656 bootclasspath_fragments: [
657 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000658 ],
659 updatable: false,
660 }
661
662 apex_key {
663 name: "myapex.key",
664 public_key: "testkey.avbpubkey",
665 private_key: "testkey.pem",
666 }
667
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100668 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000669 name: "foo",
670 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100671 shared_library: false,
672 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000673 apex_available: [
674 "myapex",
675 ],
676 }
677
678 java_library {
679 name: "bar",
680 srcs: ["b.java"],
681 installable: true,
682 apex_available: [
683 "myapex",
684 ],
685 }
686
Paul Duffin7771eba2021-04-23 14:25:28 +0100687 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100688 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000689 contents: [
690 "foo",
691 "bar",
692 ],
693 apex_available: [
694 "myapex",
695 ],
696 }
697 `)
698
Paul Duffin4d101b62021-03-24 15:42:20 +0000699 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
700 // This does not include art, oat or vdex files as they are only included for the art boot
701 // image.
satayev227e7452021-05-20 21:35:06 +0100702 "etc/classpaths/bootclasspath.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000703 "javalib/bar.jar",
704 "javalib/foo.jar",
705 })
Paul Duffin82886d62021-03-24 01:34:57 +0000706
707 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
708 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100709 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000710 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100711
712 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
713 apexRule := apex.Rule("apexRule")
714 copyCommands := apexRule.Args["copy_commands"]
715
716 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
717 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
718
719 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
720
721 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
722 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100723 dexJar, err := info.DexBootJarPathForContentModule(module)
724 if err != nil {
725 t.Error(err)
726 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100727 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
728
729 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
730 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
731 }
732
Paul Duffin54c98f52021-05-15 08:54:30 +0100733 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
734 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000735}
736
Paul Duffin48b67412021-06-23 16:13:50 +0100737func getDexJarPath(result *android.TestResult, name string) string {
738 module := result.Module(name, "android_common")
739 return module.(java.UsesLibraryDependency).DexJarBuildPath().RelativeToTop().String()
740}
741
742// TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
743// passed to the hiddenapi list tool.
744func TestBootclasspathFragment_HiddenAPIList(t *testing.T) {
745 result := android.GroupFixturePreparers(
746 prepareForTestWithBootclasspathFragment,
747 prepareForTestWithArtApex,
748 prepareForTestWithMyapex,
749 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
750 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
751 java.FixtureConfigureUpdatableBootJars("myapex:foo", "myapex:bar"),
752 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
753 // is disabled.
754 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
755
756 java.PrepareForTestWithJavaSdkLibraryFiles,
757 java.FixtureWithLastReleaseApis("foo", "quuz"),
758 ).RunTestWithBp(t, `
759 apex {
760 name: "com.android.art",
761 key: "com.android.art.key",
762 bootclasspath_fragments: ["art-bootclasspath-fragment"],
763 updatable: false,
764 }
765
766 apex_key {
767 name: "com.android.art.key",
768 public_key: "com.android.art.avbpubkey",
769 private_key: "com.android.art.pem",
770 }
771
772 java_library {
773 name: "baz",
774 apex_available: [
775 "com.android.art",
776 ],
777 srcs: ["b.java"],
778 compile_dex: true,
779 }
780
781 java_sdk_library {
782 name: "quuz",
783 apex_available: [
784 "com.android.art",
785 ],
786 srcs: ["b.java"],
787 compile_dex: true,
788 public: {enabled: true},
789 system: {enabled: true},
790 test: {enabled: true},
791 module_lib: {enabled: true},
792 }
793
794 bootclasspath_fragment {
795 name: "art-bootclasspath-fragment",
796 image_name: "art",
797 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
798 contents: ["baz", "quuz"],
799 apex_available: [
800 "com.android.art",
801 ],
802 }
803
804 apex {
805 name: "myapex",
806 key: "myapex.key",
807 bootclasspath_fragments: [
808 "mybootclasspathfragment",
809 ],
810 updatable: false,
811 }
812
813 apex_key {
814 name: "myapex.key",
815 public_key: "testkey.avbpubkey",
816 private_key: "testkey.pem",
817 }
818
819 java_sdk_library {
820 name: "foo",
821 srcs: ["b.java"],
822 shared_library: false,
823 public: {enabled: true},
824 apex_available: [
825 "myapex",
826 ],
827 }
828
829 java_library {
830 name: "bar",
831 srcs: ["b.java"],
832 installable: true,
833 apex_available: [
834 "myapex",
835 ],
836 }
837
838 bootclasspath_fragment {
839 name: "mybootclasspathfragment",
840 contents: [
841 "foo",
842 "bar",
843 ],
844 apex_available: [
845 "myapex",
846 ],
847 fragments: [
848 {
849 apex: "com.android.art",
850 module: "art-bootclasspath-fragment",
851 },
852 ],
853 }
854 `)
855
856 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
857 "art-bootclasspath-fragment",
858 "bar",
859 "dex2oatd",
860 "foo",
861 })
862
863 fooStubs := getDexJarPath(result, "foo.stubs")
864 quuzPublicStubs := getDexJarPath(result, "quuz.stubs")
865 quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system")
866 quuzTestStubs := getDexJarPath(result, "quuz.stubs.test")
Paul Duffinb51db2e2021-06-21 14:08:08 +0100867 quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib")
Paul Duffin48b67412021-06-23 16:13:50 +0100868
869 // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags.
870 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
871
872 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
873 command := rule.RuleParams.Command
874 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
875
876 // Make sure that the quuz stubs are available for resolving references from the implementation
877 // boot dex jars provided by this module.
Paul Duffinb51db2e2021-06-21 14:08:08 +0100878 android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs)
Paul Duffin48b67412021-06-23 16:13:50 +0100879
880 // Make sure that the quuz stubs are available for resolving references from the different API
881 // stubs provided by this module.
882 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs)
883 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs)
884 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs)
885}
886
Paul Duffin5cca7c42021-05-26 10:16:01 +0100887// TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting
888// additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be
889// added to the hiddenapi list tool.
890func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) {
891 result := android.GroupFixturePreparers(
892 prepareForTestWithBootclasspathFragment,
893 prepareForTestWithArtApex,
894 prepareForTestWithMyapex,
895 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
896 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "myapex:foo", "myapex:bar"),
897 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
898 // is disabled.
899 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
900
901 java.PrepareForTestWithJavaSdkLibraryFiles,
902 java.FixtureWithLastReleaseApis("foo", "android-non-updatable"),
903 ).RunTestWithBp(t, `
904 java_sdk_library {
905 name: "android-non-updatable",
906 srcs: ["b.java"],
907 compile_dex: true,
908 public: {
909 enabled: true,
910 },
911 system: {
912 enabled: true,
913 },
914 test: {
915 enabled: true,
916 },
917 module_lib: {
918 enabled: true,
919 },
920 }
921
922 apex {
923 name: "com.android.art",
924 key: "com.android.art.key",
925 bootclasspath_fragments: ["art-bootclasspath-fragment"],
926 java_libs: [
927 "baz",
928 "quuz",
929 ],
930 updatable: false,
931 }
932
933 apex_key {
934 name: "com.android.art.key",
935 public_key: "com.android.art.avbpubkey",
936 private_key: "com.android.art.pem",
937 }
938
939 java_library {
940 name: "baz",
941 apex_available: [
942 "com.android.art",
943 ],
944 srcs: ["b.java"],
945 compile_dex: true,
946 }
947
948 java_library {
949 name: "quuz",
950 apex_available: [
951 "com.android.art",
952 ],
953 srcs: ["b.java"],
954 compile_dex: true,
955 }
956
957 bootclasspath_fragment {
958 name: "art-bootclasspath-fragment",
959 image_name: "art",
960 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
961 contents: ["baz", "quuz"],
962 apex_available: [
963 "com.android.art",
964 ],
965 }
966
967 apex {
968 name: "myapex",
969 key: "myapex.key",
970 bootclasspath_fragments: [
971 "mybootclasspathfragment",
972 ],
973 updatable: false,
974 }
975
976 apex_key {
977 name: "myapex.key",
978 public_key: "testkey.avbpubkey",
979 private_key: "testkey.pem",
980 }
981
982 java_sdk_library {
983 name: "foo",
984 srcs: ["b.java"],
985 shared_library: false,
986 public: {enabled: true},
987 apex_available: [
988 "myapex",
989 ],
990 }
991
992 java_library {
993 name: "bar",
994 srcs: ["b.java"],
995 installable: true,
996 apex_available: [
997 "myapex",
998 ],
999 }
1000
1001 bootclasspath_fragment {
1002 name: "mybootclasspathfragment",
1003 contents: [
1004 "foo",
1005 "bar",
1006 ],
1007 apex_available: [
1008 "myapex",
1009 ],
1010 additional_stubs: ["android-non-updatable"],
1011 fragments: [
1012 {
1013 apex: "com.android.art",
1014 module: "art-bootclasspath-fragment",
1015 },
1016 ],
1017 }
1018 `)
1019
1020 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1021 "android-non-updatable.stubs",
1022 "android-non-updatable.stubs.module_lib",
1023 "android-non-updatable.stubs.system",
1024 "android-non-updatable.stubs.test",
1025 "art-bootclasspath-fragment",
1026 "bar",
1027 "dex2oatd",
1028 "foo",
1029 })
1030
1031 nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs")
1032 nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system")
1033 nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test")
1034 nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib")
1035
1036 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1037 // API flags.
1038 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1039
1040 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1041 command := rule.RuleParams.Command
1042 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1043
1044 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1045 // the implementation boot dex jars provided by this module.
1046 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1047
1048 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1049 // the different API stubs provided by this module.
1050 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1051 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1052 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1053}
1054
1055// TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that
1056// setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable
1057// modules to be added to the hiddenapi list tool.
1058func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) {
1059 result := android.GroupFixturePreparers(
1060 prepareForTestWithBootclasspathFragment,
1061 java.PrepareForTestWithJavaDefaultModules,
1062 prepareForTestWithArtApex,
1063 prepareForTestWithMyapex,
1064 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
1065 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "myapex:foo", "myapex:bar"),
1066 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
1067 // is disabled.
1068 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
1069
1070 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1071 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
1072 }),
1073
1074 java.PrepareForTestWithJavaSdkLibraryFiles,
1075 java.FixtureWithPrebuiltApis(map[string][]string{
1076 "current": {"android-non-updatable"},
1077 "30": {"foo"},
1078 }),
1079 ).RunTestWithBp(t, `
1080 apex {
1081 name: "com.android.art",
1082 key: "com.android.art.key",
1083 bootclasspath_fragments: ["art-bootclasspath-fragment"],
1084 java_libs: [
1085 "baz",
1086 "quuz",
1087 ],
1088 updatable: false,
1089 }
1090
1091 apex_key {
1092 name: "com.android.art.key",
1093 public_key: "com.android.art.avbpubkey",
1094 private_key: "com.android.art.pem",
1095 }
1096
1097 java_library {
1098 name: "baz",
1099 apex_available: [
1100 "com.android.art",
1101 ],
1102 srcs: ["b.java"],
1103 compile_dex: true,
1104 }
1105
1106 java_library {
1107 name: "quuz",
1108 apex_available: [
1109 "com.android.art",
1110 ],
1111 srcs: ["b.java"],
1112 compile_dex: true,
1113 }
1114
1115 bootclasspath_fragment {
1116 name: "art-bootclasspath-fragment",
1117 image_name: "art",
1118 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
1119 contents: ["baz", "quuz"],
1120 apex_available: [
1121 "com.android.art",
1122 ],
1123 }
1124
1125 apex {
1126 name: "myapex",
1127 key: "myapex.key",
1128 bootclasspath_fragments: [
1129 "mybootclasspathfragment",
1130 ],
1131 updatable: false,
1132 }
1133
1134 apex_key {
1135 name: "myapex.key",
1136 public_key: "testkey.avbpubkey",
1137 private_key: "testkey.pem",
1138 }
1139
1140 java_sdk_library {
1141 name: "foo",
1142 srcs: ["b.java"],
1143 shared_library: false,
1144 public: {enabled: true},
1145 apex_available: [
1146 "myapex",
1147 ],
1148 }
1149
1150 java_library {
1151 name: "bar",
1152 srcs: ["b.java"],
1153 installable: true,
1154 apex_available: [
1155 "myapex",
1156 ],
1157 }
1158
1159 bootclasspath_fragment {
1160 name: "mybootclasspathfragment",
1161 contents: [
1162 "foo",
1163 "bar",
1164 ],
1165 apex_available: [
1166 "myapex",
1167 ],
1168 additional_stubs: ["android-non-updatable"],
1169 fragments: [
1170 {
1171 apex: "com.android.art",
1172 module: "art-bootclasspath-fragment",
1173 },
1174 ],
1175 }
1176 `)
1177
1178 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1179 "art-bootclasspath-fragment",
1180 "bar",
1181 "dex2oatd",
1182 "foo",
1183 "prebuilt_sdk_module-lib_current_android-non-updatable",
1184 "prebuilt_sdk_public_current_android-non-updatable",
1185 "prebuilt_sdk_system_current_android-non-updatable",
1186 "prebuilt_sdk_test_current_android-non-updatable",
1187 })
1188
1189 nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable")
1190 nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable")
1191 nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable")
1192 nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable")
1193
1194 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1195 // API flags.
1196 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1197
1198 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1199 command := rule.RuleParams.Command
1200 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1201
1202 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1203 // the implementation boot dex jars provided by this module.
1204 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1205
1206 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1207 // the different API stubs provided by this module.
1208 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1209 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1210 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1211}
1212
Paul Duffina1d60252021-01-21 18:13:43 +00001213// TODO(b/177892522) - add test for host apex.