blob: 8554c19c2f721125d4e5a9afc9199b7610dd667a [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 Duffin31fad802021-06-18 18:14:25 +0100222 android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, info.TransitiveStubDexJarsByScope[apiScope])
Paul Duffinf1b358c2021-05-17 07:38:47 +0100223 }
224
225 // Check stub dex paths exported by art.
226 artFragment := result.Module("art-bootclasspath-fragment", "android_common")
227 artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
228
229 bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
230 bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
231 bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
232
Paul Duffin31fad802021-06-18 18:14:25 +0100233 checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
234 checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
235 checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
236 checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100237
238 // Check stub dex paths exported by other.
239 otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
240 otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
241
242 fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
243 fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
244
Paul Duffin31fad802021-06-18 18:14:25 +0100245 checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
246 checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
247 checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
248 checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100249}
250
Paul Duffin58e0e762021-05-21 19:27:58 +0100251func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000252 t.Helper()
253
Paul Duffin58e0e762021-05-21 19:27:58 +0100254 bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000255
Paul Duffine946b322021-04-25 23:04:00 +0100256 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
257 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000258 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000259
260 // Get a list of all the paths in the boot image sorted by arch type.
261 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100262 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000263 for _, archType := range android.ArchTypeList() {
264 if paths, ok := bootImageFilesByArchType[archType]; ok {
265 for _, path := range paths {
266 allPaths = append(allPaths, android.NormalizePathForTesting(path))
267 }
268 }
269 }
Paul Duffin3451e162021-01-20 15:16:56 +0000270
Paul Duffin94f19632021-04-20 12:40:07 +0100271 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000272}
Paul Duffina1d60252021-01-21 18:13:43 +0000273
Paul Duffin94f19632021-04-20 12:40:07 +0100274func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000275 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100276 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000277 prepareForTestWithArtApex,
278
Paul Duffinba6afd02019-11-19 19:44:10 +0000279 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000280 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000281 name: "com.android.art",
282 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100283 bootclasspath_fragments: [
284 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000285 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000286 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100287 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
288 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000289 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000290 "bar",
291 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000292 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000293 }
294
295 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000296 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000297 public_key: "testkey.avbpubkey",
298 private_key: "testkey.pem",
299 }
300
301 java_library {
302 name: "foo",
303 srcs: ["b.java"],
304 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000305 apex_available: [
306 "com.android.art",
307 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000308 }
309
310 java_library {
311 name: "bar",
312 srcs: ["b.java"],
313 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000314 apex_available: [
315 "com.android.art",
316 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000317 }
318
Paul Duffin65898052021-04-20 22:47:03 +0100319 java_import {
320 name: "foo",
321 jars: ["foo.jar"],
322 apex_available: [
323 "com.android.art",
324 ],
Paul Duffine5218812021-06-07 13:28:19 +0100325 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100326 }
327
328 java_import {
329 name: "bar",
330 jars: ["bar.jar"],
331 apex_available: [
332 "com.android.art",
333 ],
Paul Duffine5218812021-06-07 13:28:19 +0100334 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100335 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000336 `),
337 )
Paul Duffin65898052021-04-20 22:47:03 +0100338
Paul Duffinba6afd02019-11-19 19:44:10 +0000339 contentsInsert := func(contents []string) string {
340 insert := ""
341 if contents != nil {
342 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000343 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000344 return insert
345 }
Paul Duffina1d60252021-01-21 18:13:43 +0000346
Paul Duffinba6afd02019-11-19 19:44:10 +0000347 addSource := func(contents ...string) android.FixturePreparer {
348 text := fmt.Sprintf(`
349 bootclasspath_fragment {
350 name: "mybootclasspathfragment",
351 image_name: "art",
352 %s
353 apex_available: [
354 "com.android.art",
355 ],
356 }
357 `, contentsInsert(contents))
358
359 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
360 }
361
362 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
363 text := fmt.Sprintf(`
Paul Duffince918b02021-06-07 14:33:47 +0100364 prebuilt_apex {
365 name: "com.android.art",
366 arch: {
367 arm64: {
368 src: "com.android.art-arm64.apex",
369 },
370 arm: {
371 src: "com.android.art-arm.apex",
372 },
373 },
374 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
375 }
376
Paul Duffinba6afd02019-11-19 19:44:10 +0000377 prebuilt_bootclasspath_fragment {
378 name: "mybootclasspathfragment",
379 image_name: "art",
380 %s
381 prefer: %t,
382 apex_available: [
383 "com.android.art",
384 ],
385 }
386 `, contentsInsert(contents), prefer)
387 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
388 }
389
Paul Duffince918b02021-06-07 14:33:47 +0100390 t.Run("boot image files from source", func(t *testing.T) {
391 result := android.GroupFixturePreparers(
392 commonPreparer,
393
394 // Configure some libraries in the art bootclasspath_fragment that match the source
395 // bootclasspath_fragment's contents property.
396 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
397 addSource("foo", "bar"),
398 ).RunTest(t)
399
400 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
401 "etc/classpaths/bootclasspath.pb",
402 "javalib/arm/boot.art",
403 "javalib/arm/boot.oat",
404 "javalib/arm/boot.vdex",
405 "javalib/arm/boot-bar.art",
406 "javalib/arm/boot-bar.oat",
407 "javalib/arm/boot-bar.vdex",
408 "javalib/arm64/boot.art",
409 "javalib/arm64/boot.oat",
410 "javalib/arm64/boot.vdex",
411 "javalib/arm64/boot-bar.art",
412 "javalib/arm64/boot-bar.oat",
413 "javalib/arm64/boot-bar.vdex",
414 "javalib/bar.jar",
415 "javalib/foo.jar",
416 })
417
418 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
419 `bar`,
420 `com.android.art.key`,
421 `mybootclasspathfragment`,
422 })
423
424 // Make sure that the source bootclasspath_fragment copies its dex files to the predefined
425 // locations for the art image.
426 module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
427 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
428 })
429
430 t.Run("boot image files with preferred prebuilt", func(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000431 result := android.GroupFixturePreparers(
432 commonPreparer,
433
434 // Configure some libraries in the art bootclasspath_fragment that match the source
435 // bootclasspath_fragment's contents property.
436 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
437 addSource("foo", "bar"),
438
439 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
440 addPrebuilt(true, "foo", "bar"),
441 ).RunTest(t)
442
443 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
satayev227e7452021-05-20 21:35:06 +0100444 "etc/classpaths/bootclasspath.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000445 "javalib/arm/boot.art",
446 "javalib/arm/boot.oat",
447 "javalib/arm/boot.vdex",
448 "javalib/arm/boot-bar.art",
449 "javalib/arm/boot-bar.oat",
450 "javalib/arm/boot-bar.vdex",
451 "javalib/arm64/boot.art",
452 "javalib/arm64/boot.oat",
453 "javalib/arm64/boot.vdex",
454 "javalib/arm64/boot-bar.art",
455 "javalib/arm64/boot-bar.oat",
456 "javalib/arm64/boot-bar.vdex",
457 "javalib/bar.jar",
458 "javalib/foo.jar",
459 })
460
461 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
462 `bar`,
463 `com.android.art.key`,
464 `mybootclasspathfragment`,
Paul Duffince918b02021-06-07 14:33:47 +0100465 `prebuilt_com.android.art`,
Paul Duffinba6afd02019-11-19 19:44:10 +0000466 })
Paul Duffince918b02021-06-07 14:33:47 +0100467
468 // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined
469 // locations for the art image.
470 module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art")
471 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
Paul Duffina1d60252021-01-21 18:13:43 +0000472 })
Paul Duffin396229f2021-03-18 18:30:31 +0000473
Paul Duffinba6afd02019-11-19 19:44:10 +0000474 t.Run("source with inconsistency between config and contents", func(t *testing.T) {
475 android.GroupFixturePreparers(
476 commonPreparer,
477
478 // Create an inconsistency between the ArtApexJars configuration and the art source
479 // bootclasspath_fragment module's contents property.
480 java.FixtureConfigureBootJars("com.android.art:foo"),
481 addSource("foo", "bar"),
482 ).
483 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
484 RunTest(t)
485 })
486
487 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
488 android.GroupFixturePreparers(
489 commonPreparer,
490
491 // Create an inconsistency between the ArtApexJars configuration and the art
492 // prebuilt_bootclasspath_fragment module's contents property.
493 java.FixtureConfigureBootJars("com.android.art:foo"),
494 addPrebuilt(false, "foo", "bar"),
495 ).
496 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
497 RunTest(t)
498 })
499
500 t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
501 android.GroupFixturePreparers(
502 commonPreparer,
503
504 // Create an inconsistency between the ArtApexJars configuration and the art
505 // prebuilt_bootclasspath_fragment module's contents property.
506 java.FixtureConfigureBootJars("com.android.art:foo"),
507 addPrebuilt(true, "foo", "bar"),
508
509 // Source contents property is consistent with the config.
510 addSource("foo"),
511 ).
512 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
513 RunTest(t)
514 })
515
516 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
517 android.GroupFixturePreparers(
518 commonPreparer,
519
520 // Create an inconsistency between the ArtApexJars configuration and the art
521 // prebuilt_bootclasspath_fragment module's contents property.
522 java.FixtureConfigureBootJars("com.android.art:foo"),
523 addPrebuilt(false, "foo", "bar"),
524
525 // Source contents property is consistent with the config.
526 addSource("foo"),
527
528 // This should pass because while the prebuilt is inconsistent with the configuration it is
529 // not actually used.
530 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000531 })
Paul Duffina1d60252021-01-21 18:13:43 +0000532}
533
Paul Duffin94f19632021-04-20 12:40:07 +0100534func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000535 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100536 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000537 prepareForTestWithArtApex,
538
539 android.FixtureMergeMockFs(android.MockFS{
540 "com.android.art-arm64.apex": nil,
541 "com.android.art-arm.apex": nil,
542 }),
543
Paul Duffin7771eba2021-04-23 14:25:28 +0100544 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100545 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin9ea71c02021-03-23 22:53:07 +0000546 ).RunTestWithBp(t, `
547 prebuilt_apex {
548 name: "com.android.art",
549 arch: {
550 arm64: {
551 src: "com.android.art-arm64.apex",
552 },
553 arm: {
554 src: "com.android.art-arm.apex",
555 },
556 },
Paul Duffine5218812021-06-07 13:28:19 +0100557 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000558 }
559
560 java_import {
561 name: "foo",
562 jars: ["foo.jar"],
563 apex_available: [
564 "com.android.art",
565 ],
566 }
567
568 java_import {
569 name: "bar",
570 jars: ["bar.jar"],
571 apex_available: [
572 "com.android.art",
573 ],
574 }
575
Paul Duffin7771eba2021-04-23 14:25:28 +0100576 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100577 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000578 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100579 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
580 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000581 apex_available: [
582 "com.android.art",
583 ],
584 }
585 `)
586
Paul Duffin6717d882021-06-15 19:09:41 +0100587 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
Paul Duffin11216db2021-03-01 14:14:52 +0000588 `com.android.art.apex.selector`,
Paul Duffine5218812021-06-07 13:28:19 +0100589 `prebuilt_mybootclasspathfragment`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000590 })
591
Paul Duffince918b02021-06-07 14:33:47 +0100592 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{
Paul Duffin5466a362021-06-07 10:25:31 +0100593 `com.android.art.deapexer`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000594 `dex2oatd`,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000595 `prebuilt_bar`,
596 `prebuilt_foo`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000597 })
Paul Duffince918b02021-06-07 14:33:47 +0100598
599 module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art")
600 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
601}
602
603// checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the
604// predefined locations of boot dex jars used as inputs for the ART boot image.
605func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) {
606 t.Helper()
607 bootJarLocations := []string{}
608 for _, output := range module.AllOutputs() {
609 output = android.StringRelativeToTop(config, output)
610 if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") {
611 bootJarLocations = append(bootJarLocations, output)
612 }
613 }
614
615 sort.Strings(bootJarLocations)
616 expected := []string{}
617 for _, m := range modules {
618 expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m))
619 }
620 sort.Strings(expected)
621
622 android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations)
Paul Duffin9ea71c02021-03-23 22:53:07 +0000623}
624
Paul Duffin94f19632021-04-20 12:40:07 +0100625func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000626 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100627 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000628 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100629 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
630 java.FixtureConfigureBootJars("myapex:foo", "myapex:bar"),
631 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
632 // is disabled.
633 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
634
635 java.PrepareForTestWithJavaSdkLibraryFiles,
636 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000637 ).RunTestWithBp(t, `
638 apex {
639 name: "myapex",
640 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100641 bootclasspath_fragments: [
642 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000643 ],
644 updatable: false,
645 }
646
647 apex_key {
648 name: "myapex.key",
649 public_key: "testkey.avbpubkey",
650 private_key: "testkey.pem",
651 }
652
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100653 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000654 name: "foo",
655 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100656 shared_library: false,
657 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000658 apex_available: [
659 "myapex",
660 ],
661 }
662
663 java_library {
664 name: "bar",
665 srcs: ["b.java"],
666 installable: true,
667 apex_available: [
668 "myapex",
669 ],
670 }
671
Paul Duffin7771eba2021-04-23 14:25:28 +0100672 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100673 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000674 contents: [
675 "foo",
676 "bar",
677 ],
678 apex_available: [
679 "myapex",
680 ],
681 }
682 `)
683
Paul Duffin4d101b62021-03-24 15:42:20 +0000684 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
685 // This does not include art, oat or vdex files as they are only included for the art boot
686 // image.
satayev227e7452021-05-20 21:35:06 +0100687 "etc/classpaths/bootclasspath.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000688 "javalib/bar.jar",
689 "javalib/foo.jar",
690 })
Paul Duffin82886d62021-03-24 01:34:57 +0000691
692 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
693 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100694 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000695 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100696
697 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
698 apexRule := apex.Rule("apexRule")
699 copyCommands := apexRule.Args["copy_commands"]
700
701 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
702 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
703
704 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
705
706 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
707 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100708 dexJar, err := info.DexBootJarPathForContentModule(module)
709 if err != nil {
710 t.Error(err)
711 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100712 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
713
714 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
715 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
716 }
717
Paul Duffin54c98f52021-05-15 08:54:30 +0100718 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
719 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000720}
721
Paul Duffin48b67412021-06-23 16:13:50 +0100722func getDexJarPath(result *android.TestResult, name string) string {
723 module := result.Module(name, "android_common")
724 return module.(java.UsesLibraryDependency).DexJarBuildPath().RelativeToTop().String()
725}
726
727// TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
728// passed to the hiddenapi list tool.
729func TestBootclasspathFragment_HiddenAPIList(t *testing.T) {
730 result := android.GroupFixturePreparers(
731 prepareForTestWithBootclasspathFragment,
732 prepareForTestWithArtApex,
733 prepareForTestWithMyapex,
734 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
735 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
736 java.FixtureConfigureUpdatableBootJars("myapex:foo", "myapex:bar"),
737 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
738 // is disabled.
739 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
740
741 java.PrepareForTestWithJavaSdkLibraryFiles,
742 java.FixtureWithLastReleaseApis("foo", "quuz"),
743 ).RunTestWithBp(t, `
744 apex {
745 name: "com.android.art",
746 key: "com.android.art.key",
747 bootclasspath_fragments: ["art-bootclasspath-fragment"],
748 updatable: false,
749 }
750
751 apex_key {
752 name: "com.android.art.key",
753 public_key: "com.android.art.avbpubkey",
754 private_key: "com.android.art.pem",
755 }
756
757 java_library {
758 name: "baz",
759 apex_available: [
760 "com.android.art",
761 ],
762 srcs: ["b.java"],
763 compile_dex: true,
764 }
765
766 java_sdk_library {
767 name: "quuz",
768 apex_available: [
769 "com.android.art",
770 ],
771 srcs: ["b.java"],
772 compile_dex: true,
773 public: {enabled: true},
774 system: {enabled: true},
775 test: {enabled: true},
776 module_lib: {enabled: true},
777 }
778
779 bootclasspath_fragment {
780 name: "art-bootclasspath-fragment",
781 image_name: "art",
782 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
783 contents: ["baz", "quuz"],
784 apex_available: [
785 "com.android.art",
786 ],
787 }
788
789 apex {
790 name: "myapex",
791 key: "myapex.key",
792 bootclasspath_fragments: [
793 "mybootclasspathfragment",
794 ],
795 updatable: false,
796 }
797
798 apex_key {
799 name: "myapex.key",
800 public_key: "testkey.avbpubkey",
801 private_key: "testkey.pem",
802 }
803
804 java_sdk_library {
805 name: "foo",
806 srcs: ["b.java"],
807 shared_library: false,
808 public: {enabled: true},
809 apex_available: [
810 "myapex",
811 ],
812 }
813
814 java_library {
815 name: "bar",
816 srcs: ["b.java"],
817 installable: true,
818 apex_available: [
819 "myapex",
820 ],
821 }
822
823 bootclasspath_fragment {
824 name: "mybootclasspathfragment",
825 contents: [
826 "foo",
827 "bar",
828 ],
829 apex_available: [
830 "myapex",
831 ],
832 fragments: [
833 {
834 apex: "com.android.art",
835 module: "art-bootclasspath-fragment",
836 },
837 ],
838 }
839 `)
840
841 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
842 "art-bootclasspath-fragment",
843 "bar",
844 "dex2oatd",
845 "foo",
846 })
847
848 fooStubs := getDexJarPath(result, "foo.stubs")
849 quuzPublicStubs := getDexJarPath(result, "quuz.stubs")
850 quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system")
851 quuzTestStubs := getDexJarPath(result, "quuz.stubs.test")
Paul Duffinb51db2e2021-06-21 14:08:08 +0100852 quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib")
Paul Duffin48b67412021-06-23 16:13:50 +0100853
854 // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags.
855 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
856
857 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
858 command := rule.RuleParams.Command
859 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
860
861 // Make sure that the quuz stubs are available for resolving references from the implementation
862 // boot dex jars provided by this module.
Paul Duffinb51db2e2021-06-21 14:08:08 +0100863 android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs)
Paul Duffin48b67412021-06-23 16:13:50 +0100864
865 // Make sure that the quuz stubs are available for resolving references from the different API
866 // stubs provided by this module.
867 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs)
868 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs)
869 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs)
870}
871
Paul Duffin5cca7c42021-05-26 10:16:01 +0100872// TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting
873// additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be
874// added to the hiddenapi list tool.
875func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) {
876 result := android.GroupFixturePreparers(
877 prepareForTestWithBootclasspathFragment,
878 prepareForTestWithArtApex,
879 prepareForTestWithMyapex,
880 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
881 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "myapex:foo", "myapex:bar"),
882 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
883 // is disabled.
884 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
885
886 java.PrepareForTestWithJavaSdkLibraryFiles,
887 java.FixtureWithLastReleaseApis("foo", "android-non-updatable"),
888 ).RunTestWithBp(t, `
889 java_sdk_library {
890 name: "android-non-updatable",
891 srcs: ["b.java"],
892 compile_dex: true,
893 public: {
894 enabled: true,
895 },
896 system: {
897 enabled: true,
898 },
899 test: {
900 enabled: true,
901 },
902 module_lib: {
903 enabled: true,
904 },
905 }
906
907 apex {
908 name: "com.android.art",
909 key: "com.android.art.key",
910 bootclasspath_fragments: ["art-bootclasspath-fragment"],
911 java_libs: [
912 "baz",
913 "quuz",
914 ],
915 updatable: false,
916 }
917
918 apex_key {
919 name: "com.android.art.key",
920 public_key: "com.android.art.avbpubkey",
921 private_key: "com.android.art.pem",
922 }
923
924 java_library {
925 name: "baz",
926 apex_available: [
927 "com.android.art",
928 ],
929 srcs: ["b.java"],
930 compile_dex: true,
931 }
932
933 java_library {
934 name: "quuz",
935 apex_available: [
936 "com.android.art",
937 ],
938 srcs: ["b.java"],
939 compile_dex: true,
940 }
941
942 bootclasspath_fragment {
943 name: "art-bootclasspath-fragment",
944 image_name: "art",
945 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
946 contents: ["baz", "quuz"],
947 apex_available: [
948 "com.android.art",
949 ],
950 }
951
952 apex {
953 name: "myapex",
954 key: "myapex.key",
955 bootclasspath_fragments: [
956 "mybootclasspathfragment",
957 ],
958 updatable: false,
959 }
960
961 apex_key {
962 name: "myapex.key",
963 public_key: "testkey.avbpubkey",
964 private_key: "testkey.pem",
965 }
966
967 java_sdk_library {
968 name: "foo",
969 srcs: ["b.java"],
970 shared_library: false,
971 public: {enabled: true},
972 apex_available: [
973 "myapex",
974 ],
975 }
976
977 java_library {
978 name: "bar",
979 srcs: ["b.java"],
980 installable: true,
981 apex_available: [
982 "myapex",
983 ],
984 }
985
986 bootclasspath_fragment {
987 name: "mybootclasspathfragment",
988 contents: [
989 "foo",
990 "bar",
991 ],
992 apex_available: [
993 "myapex",
994 ],
995 additional_stubs: ["android-non-updatable"],
996 fragments: [
997 {
998 apex: "com.android.art",
999 module: "art-bootclasspath-fragment",
1000 },
1001 ],
1002 }
1003 `)
1004
1005 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1006 "android-non-updatable.stubs",
1007 "android-non-updatable.stubs.module_lib",
1008 "android-non-updatable.stubs.system",
1009 "android-non-updatable.stubs.test",
1010 "art-bootclasspath-fragment",
1011 "bar",
1012 "dex2oatd",
1013 "foo",
1014 })
1015
1016 nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs")
1017 nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system")
1018 nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test")
1019 nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib")
1020
1021 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1022 // API flags.
1023 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1024
1025 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1026 command := rule.RuleParams.Command
1027 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1028
1029 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1030 // the implementation boot dex jars provided by this module.
1031 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1032
1033 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1034 // the different API stubs provided by this module.
1035 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1036 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1037 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1038}
1039
1040// TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that
1041// setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable
1042// modules to be added to the hiddenapi list tool.
1043func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) {
1044 result := android.GroupFixturePreparers(
1045 prepareForTestWithBootclasspathFragment,
1046 java.PrepareForTestWithJavaDefaultModules,
1047 prepareForTestWithArtApex,
1048 prepareForTestWithMyapex,
1049 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
1050 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "myapex:foo", "myapex:bar"),
1051 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
1052 // is disabled.
1053 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
1054
1055 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1056 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
1057 }),
1058
1059 java.PrepareForTestWithJavaSdkLibraryFiles,
1060 java.FixtureWithPrebuiltApis(map[string][]string{
1061 "current": {"android-non-updatable"},
1062 "30": {"foo"},
1063 }),
1064 ).RunTestWithBp(t, `
1065 apex {
1066 name: "com.android.art",
1067 key: "com.android.art.key",
1068 bootclasspath_fragments: ["art-bootclasspath-fragment"],
1069 java_libs: [
1070 "baz",
1071 "quuz",
1072 ],
1073 updatable: false,
1074 }
1075
1076 apex_key {
1077 name: "com.android.art.key",
1078 public_key: "com.android.art.avbpubkey",
1079 private_key: "com.android.art.pem",
1080 }
1081
1082 java_library {
1083 name: "baz",
1084 apex_available: [
1085 "com.android.art",
1086 ],
1087 srcs: ["b.java"],
1088 compile_dex: true,
1089 }
1090
1091 java_library {
1092 name: "quuz",
1093 apex_available: [
1094 "com.android.art",
1095 ],
1096 srcs: ["b.java"],
1097 compile_dex: true,
1098 }
1099
1100 bootclasspath_fragment {
1101 name: "art-bootclasspath-fragment",
1102 image_name: "art",
1103 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
1104 contents: ["baz", "quuz"],
1105 apex_available: [
1106 "com.android.art",
1107 ],
1108 }
1109
1110 apex {
1111 name: "myapex",
1112 key: "myapex.key",
1113 bootclasspath_fragments: [
1114 "mybootclasspathfragment",
1115 ],
1116 updatable: false,
1117 }
1118
1119 apex_key {
1120 name: "myapex.key",
1121 public_key: "testkey.avbpubkey",
1122 private_key: "testkey.pem",
1123 }
1124
1125 java_sdk_library {
1126 name: "foo",
1127 srcs: ["b.java"],
1128 shared_library: false,
1129 public: {enabled: true},
1130 apex_available: [
1131 "myapex",
1132 ],
1133 }
1134
1135 java_library {
1136 name: "bar",
1137 srcs: ["b.java"],
1138 installable: true,
1139 apex_available: [
1140 "myapex",
1141 ],
1142 }
1143
1144 bootclasspath_fragment {
1145 name: "mybootclasspathfragment",
1146 contents: [
1147 "foo",
1148 "bar",
1149 ],
1150 apex_available: [
1151 "myapex",
1152 ],
1153 additional_stubs: ["android-non-updatable"],
1154 fragments: [
1155 {
1156 apex: "com.android.art",
1157 module: "art-bootclasspath-fragment",
1158 },
1159 ],
1160 }
1161 `)
1162
1163 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1164 "art-bootclasspath-fragment",
1165 "bar",
1166 "dex2oatd",
1167 "foo",
1168 "prebuilt_sdk_module-lib_current_android-non-updatable",
1169 "prebuilt_sdk_public_current_android-non-updatable",
1170 "prebuilt_sdk_system_current_android-non-updatable",
1171 "prebuilt_sdk_test_current_android-non-updatable",
1172 })
1173
1174 nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable")
1175 nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable")
1176 nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable")
1177 nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable")
1178
1179 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1180 // API flags.
1181 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1182
1183 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1184 command := rule.RuleParams.Command
1185 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1186
1187 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1188 // the implementation boot dex jars provided by this module.
1189 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1190
1191 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1192 // the different API stubs provided by this module.
1193 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1194 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1195 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1196}
1197
Paul Duffina1d60252021-01-21 18:13:43 +00001198// TODO(b/177892522) - add test for host apex.