blob: 3e19014a3daa181d26e70aa62f1db2f07245a347 [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.
satayevabcd5972021-08-06 17:49:46 +0100133 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
134 java.FixtureConfigureApexBootJars("someapex:foo", "someapex:bar"),
Paul Duffinf1b358c2021-05-17 07:38:47 +0100135 prepareForTestWithArtApex,
136
137 java.PrepareForTestWithJavaSdkLibraryFiles,
138 java.FixtureWithLastReleaseApis("foo", "baz"),
139 ).RunTestWithBp(t, `
140 java_sdk_library {
141 name: "foo",
142 srcs: ["b.java"],
143 shared_library: false,
144 public: {
145 enabled: true,
146 },
147 system: {
148 enabled: true,
149 },
150 }
151
152 java_library {
153 name: "bar",
154 srcs: ["b.java"],
155 installable: true,
156 }
157
158 apex {
159 name: "com.android.art",
160 key: "com.android.art.key",
161 bootclasspath_fragments: ["art-bootclasspath-fragment"],
162 updatable: false,
163 }
164
165 apex_key {
166 name: "com.android.art.key",
167 public_key: "com.android.art.avbpubkey",
168 private_key: "com.android.art.pem",
169 }
170
171 java_sdk_library {
172 name: "baz",
173 apex_available: [
174 "com.android.art",
175 ],
176 srcs: ["b.java"],
177 shared_library: false,
178 public: {
179 enabled: true,
180 },
181 system: {
182 enabled: true,
183 },
184 test: {
185 enabled: true,
186 },
187 }
188
189 java_library {
190 name: "quuz",
191 apex_available: [
192 "com.android.art",
193 ],
194 srcs: ["b.java"],
195 compile_dex: true,
196 }
197
198 bootclasspath_fragment {
199 name: "art-bootclasspath-fragment",
200 image_name: "art",
201 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
202 contents: ["baz", "quuz"],
203 apex_available: [
204 "com.android.art",
205 ],
206 }
207
208 bootclasspath_fragment {
209 name: "other-bootclasspath-fragment",
210 contents: ["foo", "bar"],
211 fragments: [
212 {
213 apex: "com.android.art",
214 module: "art-bootclasspath-fragment",
215 },
216 ],
217 }
218`,
219 )
220
Paul Duffin31fad802021-06-18 18:14:25 +0100221 checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) {
Paul Duffinf1b358c2021-05-17 07:38:47 +0100222 t.Helper()
Paul Duffin280a31a2021-06-27 20:28:29 +0100223 paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope)
224 android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100225 }
226
227 // Check stub dex paths exported by art.
228 artFragment := result.Module("art-bootclasspath-fragment", "android_common")
229 artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
230
231 bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
232 bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
233 bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
234
Paul Duffin31fad802021-06-18 18:14:25 +0100235 checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
236 checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
237 checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
238 checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100239
240 // Check stub dex paths exported by other.
241 otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
242 otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
243
244 fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
245 fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
246
Paul Duffin31fad802021-06-18 18:14:25 +0100247 checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
248 checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
249 checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
250 checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100251}
252
Paul Duffin58e0e762021-05-21 19:27:58 +0100253func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000254 t.Helper()
255
Paul Duffin58e0e762021-05-21 19:27:58 +0100256 bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000257
Paul Duffine946b322021-04-25 23:04:00 +0100258 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
259 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000260 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000261
262 // Get a list of all the paths in the boot image sorted by arch type.
263 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100264 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000265 for _, archType := range android.ArchTypeList() {
266 if paths, ok := bootImageFilesByArchType[archType]; ok {
267 for _, path := range paths {
268 allPaths = append(allPaths, android.NormalizePathForTesting(path))
269 }
270 }
271 }
Paul Duffin3451e162021-01-20 15:16:56 +0000272
Paul Duffin94f19632021-04-20 12:40:07 +0100273 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000274}
Paul Duffina1d60252021-01-21 18:13:43 +0000275
Paul Duffin94f19632021-04-20 12:40:07 +0100276func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000277 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100278 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000279 prepareForTestWithArtApex,
280
Paul Duffinba6afd02019-11-19 19:44:10 +0000281 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000282 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000283 name: "com.android.art",
284 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100285 bootclasspath_fragments: [
286 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000287 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000288 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100289 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
290 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000291 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000292 "bar",
293 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000294 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000295 }
296
297 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000298 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000299 public_key: "testkey.avbpubkey",
300 private_key: "testkey.pem",
301 }
302
303 java_library {
304 name: "foo",
305 srcs: ["b.java"],
306 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000307 apex_available: [
308 "com.android.art",
309 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000310 }
311
312 java_library {
313 name: "bar",
314 srcs: ["b.java"],
315 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000316 apex_available: [
317 "com.android.art",
318 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000319 }
320
Paul Duffin65898052021-04-20 22:47:03 +0100321 java_import {
322 name: "foo",
323 jars: ["foo.jar"],
324 apex_available: [
325 "com.android.art",
326 ],
Paul Duffine5218812021-06-07 13:28:19 +0100327 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100328 }
329
330 java_import {
331 name: "bar",
332 jars: ["bar.jar"],
333 apex_available: [
334 "com.android.art",
335 ],
Paul Duffine5218812021-06-07 13:28:19 +0100336 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100337 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000338 `),
339 )
Paul Duffin65898052021-04-20 22:47:03 +0100340
Paul Duffinba6afd02019-11-19 19:44:10 +0000341 contentsInsert := func(contents []string) string {
342 insert := ""
343 if contents != nil {
344 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000345 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000346 return insert
347 }
Paul Duffina1d60252021-01-21 18:13:43 +0000348
Paul Duffinba6afd02019-11-19 19:44:10 +0000349 addSource := func(contents ...string) android.FixturePreparer {
350 text := fmt.Sprintf(`
351 bootclasspath_fragment {
352 name: "mybootclasspathfragment",
353 image_name: "art",
354 %s
355 apex_available: [
356 "com.android.art",
357 ],
358 }
359 `, contentsInsert(contents))
360
361 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
362 }
363
364 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
365 text := fmt.Sprintf(`
Paul Duffince918b02021-06-07 14:33:47 +0100366 prebuilt_apex {
367 name: "com.android.art",
368 arch: {
369 arm64: {
370 src: "com.android.art-arm64.apex",
371 },
372 arm: {
373 src: "com.android.art-arm.apex",
374 },
375 },
376 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
377 }
378
Paul Duffinba6afd02019-11-19 19:44:10 +0000379 prebuilt_bootclasspath_fragment {
380 name: "mybootclasspathfragment",
381 image_name: "art",
382 %s
383 prefer: %t,
384 apex_available: [
385 "com.android.art",
386 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100387 hidden_api: {
388 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
389 metadata: "mybootclasspathfragment/metadata.csv",
390 index: "mybootclasspathfragment/index.csv",
391 stub_flags: "mybootclasspathfragment/stub-flags.csv",
392 all_flags: "mybootclasspathfragment/all-flags.csv",
393 },
Paul Duffinba6afd02019-11-19 19:44:10 +0000394 }
395 `, contentsInsert(contents), prefer)
396 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
397 }
398
Paul Duffince918b02021-06-07 14:33:47 +0100399 t.Run("boot image files from source", func(t *testing.T) {
400 result := android.GroupFixturePreparers(
401 commonPreparer,
402
403 // Configure some libraries in the art bootclasspath_fragment that match the source
404 // bootclasspath_fragment's contents property.
405 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
406 addSource("foo", "bar"),
407 ).RunTest(t)
408
409 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
410 "etc/classpaths/bootclasspath.pb",
411 "javalib/arm/boot.art",
412 "javalib/arm/boot.oat",
413 "javalib/arm/boot.vdex",
414 "javalib/arm/boot-bar.art",
415 "javalib/arm/boot-bar.oat",
416 "javalib/arm/boot-bar.vdex",
417 "javalib/arm64/boot.art",
418 "javalib/arm64/boot.oat",
419 "javalib/arm64/boot.vdex",
420 "javalib/arm64/boot-bar.art",
421 "javalib/arm64/boot-bar.oat",
422 "javalib/arm64/boot-bar.vdex",
423 "javalib/bar.jar",
424 "javalib/foo.jar",
425 })
426
427 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
428 `bar`,
429 `com.android.art.key`,
430 `mybootclasspathfragment`,
431 })
432
433 // Make sure that the source bootclasspath_fragment copies its dex files to the predefined
434 // locations for the art image.
435 module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
436 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
437 })
438
439 t.Run("boot image files with preferred prebuilt", func(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000440 result := android.GroupFixturePreparers(
441 commonPreparer,
442
443 // Configure some libraries in the art bootclasspath_fragment that match the source
444 // bootclasspath_fragment's contents property.
445 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
446 addSource("foo", "bar"),
447
448 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
449 addPrebuilt(true, "foo", "bar"),
450 ).RunTest(t)
451
452 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
satayev227e7452021-05-20 21:35:06 +0100453 "etc/classpaths/bootclasspath.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000454 "javalib/arm/boot.art",
455 "javalib/arm/boot.oat",
456 "javalib/arm/boot.vdex",
457 "javalib/arm/boot-bar.art",
458 "javalib/arm/boot-bar.oat",
459 "javalib/arm/boot-bar.vdex",
460 "javalib/arm64/boot.art",
461 "javalib/arm64/boot.oat",
462 "javalib/arm64/boot.vdex",
463 "javalib/arm64/boot-bar.art",
464 "javalib/arm64/boot-bar.oat",
465 "javalib/arm64/boot-bar.vdex",
466 "javalib/bar.jar",
467 "javalib/foo.jar",
468 })
469
470 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
471 `bar`,
472 `com.android.art.key`,
473 `mybootclasspathfragment`,
Paul Duffince918b02021-06-07 14:33:47 +0100474 `prebuilt_com.android.art`,
Paul Duffinba6afd02019-11-19 19:44:10 +0000475 })
Paul Duffince918b02021-06-07 14:33:47 +0100476
477 // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined
478 // locations for the art image.
479 module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art")
480 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
Paul Duffina1d60252021-01-21 18:13:43 +0000481 })
Paul Duffin396229f2021-03-18 18:30:31 +0000482
Paul Duffinba6afd02019-11-19 19:44:10 +0000483 t.Run("source with inconsistency between config and contents", func(t *testing.T) {
484 android.GroupFixturePreparers(
485 commonPreparer,
486
487 // Create an inconsistency between the ArtApexJars configuration and the art source
488 // bootclasspath_fragment module's contents property.
489 java.FixtureConfigureBootJars("com.android.art:foo"),
490 addSource("foo", "bar"),
491 ).
492 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
493 RunTest(t)
494 })
495
496 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
497 android.GroupFixturePreparers(
498 commonPreparer,
499
500 // Create an inconsistency between the ArtApexJars configuration and the art
501 // prebuilt_bootclasspath_fragment module's contents property.
502 java.FixtureConfigureBootJars("com.android.art:foo"),
503 addPrebuilt(false, "foo", "bar"),
504 ).
505 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
506 RunTest(t)
507 })
508
509 t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
510 android.GroupFixturePreparers(
511 commonPreparer,
512
513 // Create an inconsistency between the ArtApexJars configuration and the art
514 // prebuilt_bootclasspath_fragment module's contents property.
515 java.FixtureConfigureBootJars("com.android.art:foo"),
516 addPrebuilt(true, "foo", "bar"),
517
518 // Source contents property is consistent with the config.
519 addSource("foo"),
520 ).
521 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
522 RunTest(t)
523 })
524
525 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
526 android.GroupFixturePreparers(
527 commonPreparer,
528
529 // Create an inconsistency between the ArtApexJars configuration and the art
530 // prebuilt_bootclasspath_fragment module's contents property.
531 java.FixtureConfigureBootJars("com.android.art:foo"),
532 addPrebuilt(false, "foo", "bar"),
533
534 // Source contents property is consistent with the config.
535 addSource("foo"),
536
537 // This should pass because while the prebuilt is inconsistent with the configuration it is
538 // not actually used.
539 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000540 })
Paul Duffina1d60252021-01-21 18:13:43 +0000541}
542
Paul Duffin94f19632021-04-20 12:40:07 +0100543func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000544 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100545 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000546 prepareForTestWithArtApex,
547
548 android.FixtureMergeMockFs(android.MockFS{
549 "com.android.art-arm64.apex": nil,
550 "com.android.art-arm.apex": nil,
551 }),
552
Paul Duffin7771eba2021-04-23 14:25:28 +0100553 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100554 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Paul Duffin9ea71c02021-03-23 22:53:07 +0000555 ).RunTestWithBp(t, `
556 prebuilt_apex {
557 name: "com.android.art",
558 arch: {
559 arm64: {
560 src: "com.android.art-arm64.apex",
561 },
562 arm: {
563 src: "com.android.art-arm.apex",
564 },
565 },
Paul Duffine5218812021-06-07 13:28:19 +0100566 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000567 }
568
569 java_import {
570 name: "foo",
571 jars: ["foo.jar"],
572 apex_available: [
573 "com.android.art",
574 ],
575 }
576
577 java_import {
578 name: "bar",
579 jars: ["bar.jar"],
580 apex_available: [
581 "com.android.art",
582 ],
583 }
584
Paul Duffin7771eba2021-04-23 14:25:28 +0100585 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100586 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000587 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100588 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
589 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000590 apex_available: [
591 "com.android.art",
592 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100593 hidden_api: {
594 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
595 metadata: "mybootclasspathfragment/metadata.csv",
596 index: "mybootclasspathfragment/index.csv",
597 stub_flags: "mybootclasspathfragment/stub-flags.csv",
598 all_flags: "mybootclasspathfragment/all-flags.csv",
599 },
Paul Duffin9ea71c02021-03-23 22:53:07 +0000600 }
601 `)
602
Paul Duffin6717d882021-06-15 19:09:41 +0100603 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
Paul Duffin11216db2021-03-01 14:14:52 +0000604 `com.android.art.apex.selector`,
Paul Duffine5218812021-06-07 13:28:19 +0100605 `prebuilt_mybootclasspathfragment`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000606 })
607
Paul Duffince918b02021-06-07 14:33:47 +0100608 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{
Paul Duffin5466a362021-06-07 10:25:31 +0100609 `com.android.art.deapexer`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000610 `dex2oatd`,
Paul Duffinc7ef9892021-03-23 23:21:59 +0000611 `prebuilt_bar`,
612 `prebuilt_foo`,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000613 })
Paul Duffince918b02021-06-07 14:33:47 +0100614
615 module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art")
616 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
617}
618
619// checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the
620// predefined locations of boot dex jars used as inputs for the ART boot image.
621func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) {
622 t.Helper()
623 bootJarLocations := []string{}
624 for _, output := range module.AllOutputs() {
625 output = android.StringRelativeToTop(config, output)
626 if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") {
627 bootJarLocations = append(bootJarLocations, output)
628 }
629 }
630
631 sort.Strings(bootJarLocations)
632 expected := []string{}
633 for _, m := range modules {
634 expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m))
635 }
636 sort.Strings(expected)
637
638 android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations)
Paul Duffin9ea71c02021-03-23 22:53:07 +0000639}
640
Paul Duffin94f19632021-04-20 12:40:07 +0100641func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000642 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100643 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000644 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100645 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +0100646 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100647 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
648 // is disabled.
649 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
650
651 java.PrepareForTestWithJavaSdkLibraryFiles,
652 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000653 ).RunTestWithBp(t, `
654 apex {
655 name: "myapex",
656 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100657 bootclasspath_fragments: [
658 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000659 ],
660 updatable: false,
661 }
662
663 apex_key {
664 name: "myapex.key",
665 public_key: "testkey.avbpubkey",
666 private_key: "testkey.pem",
667 }
668
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100669 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000670 name: "foo",
671 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100672 shared_library: false,
673 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000674 apex_available: [
675 "myapex",
676 ],
677 }
678
679 java_library {
680 name: "bar",
681 srcs: ["b.java"],
682 installable: true,
683 apex_available: [
684 "myapex",
685 ],
686 }
687
Paul Duffin7771eba2021-04-23 14:25:28 +0100688 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100689 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000690 contents: [
691 "foo",
692 "bar",
693 ],
694 apex_available: [
695 "myapex",
696 ],
697 }
698 `)
699
Paul Duffin4d101b62021-03-24 15:42:20 +0000700 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
701 // This does not include art, oat or vdex files as they are only included for the art boot
702 // image.
satayev227e7452021-05-20 21:35:06 +0100703 "etc/classpaths/bootclasspath.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000704 "javalib/bar.jar",
705 "javalib/foo.jar",
706 })
Paul Duffin82886d62021-03-24 01:34:57 +0000707
708 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
709 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100710 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000711 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100712
713 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
714 apexRule := apex.Rule("apexRule")
715 copyCommands := apexRule.Args["copy_commands"]
716
717 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
718 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
719
720 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
721
722 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
723 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100724 dexJar, err := info.DexBootJarPathForContentModule(module)
725 if err != nil {
726 t.Error(err)
727 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100728 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
729
730 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
731 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
732 }
733
Paul Duffin54c98f52021-05-15 08:54:30 +0100734 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
735 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000736}
737
Paul Duffin48b67412021-06-23 16:13:50 +0100738func getDexJarPath(result *android.TestResult, name string) string {
739 module := result.Module(name, "android_common")
740 return module.(java.UsesLibraryDependency).DexJarBuildPath().RelativeToTop().String()
741}
742
743// TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
744// passed to the hiddenapi list tool.
745func TestBootclasspathFragment_HiddenAPIList(t *testing.T) {
746 result := android.GroupFixturePreparers(
747 prepareForTestWithBootclasspathFragment,
748 prepareForTestWithArtApex,
749 prepareForTestWithMyapex,
750 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
751 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
satayevd604b212021-07-21 14:23:52 +0100752 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin48b67412021-06-23 16:13:50 +0100753 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
754 // is disabled.
755 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
756
757 java.PrepareForTestWithJavaSdkLibraryFiles,
758 java.FixtureWithLastReleaseApis("foo", "quuz"),
759 ).RunTestWithBp(t, `
760 apex {
761 name: "com.android.art",
762 key: "com.android.art.key",
763 bootclasspath_fragments: ["art-bootclasspath-fragment"],
764 updatable: false,
765 }
766
767 apex_key {
768 name: "com.android.art.key",
769 public_key: "com.android.art.avbpubkey",
770 private_key: "com.android.art.pem",
771 }
772
773 java_library {
774 name: "baz",
775 apex_available: [
776 "com.android.art",
777 ],
778 srcs: ["b.java"],
779 compile_dex: true,
780 }
781
782 java_sdk_library {
783 name: "quuz",
784 apex_available: [
785 "com.android.art",
786 ],
787 srcs: ["b.java"],
788 compile_dex: true,
789 public: {enabled: true},
790 system: {enabled: true},
791 test: {enabled: true},
792 module_lib: {enabled: true},
793 }
794
795 bootclasspath_fragment {
796 name: "art-bootclasspath-fragment",
797 image_name: "art",
798 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
799 contents: ["baz", "quuz"],
800 apex_available: [
801 "com.android.art",
802 ],
803 }
804
805 apex {
806 name: "myapex",
807 key: "myapex.key",
808 bootclasspath_fragments: [
809 "mybootclasspathfragment",
810 ],
811 updatable: false,
812 }
813
814 apex_key {
815 name: "myapex.key",
816 public_key: "testkey.avbpubkey",
817 private_key: "testkey.pem",
818 }
819
820 java_sdk_library {
821 name: "foo",
822 srcs: ["b.java"],
823 shared_library: false,
824 public: {enabled: true},
825 apex_available: [
826 "myapex",
827 ],
828 }
829
830 java_library {
831 name: "bar",
832 srcs: ["b.java"],
833 installable: true,
834 apex_available: [
835 "myapex",
836 ],
837 }
838
839 bootclasspath_fragment {
840 name: "mybootclasspathfragment",
841 contents: [
842 "foo",
843 "bar",
844 ],
845 apex_available: [
846 "myapex",
847 ],
848 fragments: [
849 {
850 apex: "com.android.art",
851 module: "art-bootclasspath-fragment",
852 },
853 ],
854 }
855 `)
856
857 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
858 "art-bootclasspath-fragment",
859 "bar",
860 "dex2oatd",
861 "foo",
862 })
863
864 fooStubs := getDexJarPath(result, "foo.stubs")
865 quuzPublicStubs := getDexJarPath(result, "quuz.stubs")
866 quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system")
867 quuzTestStubs := getDexJarPath(result, "quuz.stubs.test")
Paul Duffinb51db2e2021-06-21 14:08:08 +0100868 quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib")
Paul Duffin48b67412021-06-23 16:13:50 +0100869
870 // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags.
871 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
872
873 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
874 command := rule.RuleParams.Command
875 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
876
877 // Make sure that the quuz stubs are available for resolving references from the implementation
878 // boot dex jars provided by this module.
Paul Duffinb51db2e2021-06-21 14:08:08 +0100879 android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs)
Paul Duffin48b67412021-06-23 16:13:50 +0100880
881 // Make sure that the quuz stubs are available for resolving references from the different API
882 // stubs provided by this module.
883 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs)
884 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs)
885 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs)
886}
887
Paul Duffin5cca7c42021-05-26 10:16:01 +0100888// TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting
889// additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be
890// added to the hiddenapi list tool.
891func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) {
892 result := android.GroupFixturePreparers(
893 prepareForTestWithBootclasspathFragment,
894 prepareForTestWithArtApex,
895 prepareForTestWithMyapex,
896 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +0100897 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
898 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin5cca7c42021-05-26 10:16:01 +0100899 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
900 // is disabled.
901 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
902
903 java.PrepareForTestWithJavaSdkLibraryFiles,
904 java.FixtureWithLastReleaseApis("foo", "android-non-updatable"),
905 ).RunTestWithBp(t, `
906 java_sdk_library {
907 name: "android-non-updatable",
908 srcs: ["b.java"],
909 compile_dex: true,
910 public: {
911 enabled: true,
912 },
913 system: {
914 enabled: true,
915 },
916 test: {
917 enabled: true,
918 },
919 module_lib: {
920 enabled: true,
921 },
922 }
923
924 apex {
925 name: "com.android.art",
926 key: "com.android.art.key",
927 bootclasspath_fragments: ["art-bootclasspath-fragment"],
928 java_libs: [
929 "baz",
930 "quuz",
931 ],
932 updatable: false,
933 }
934
935 apex_key {
936 name: "com.android.art.key",
937 public_key: "com.android.art.avbpubkey",
938 private_key: "com.android.art.pem",
939 }
940
941 java_library {
942 name: "baz",
943 apex_available: [
944 "com.android.art",
945 ],
946 srcs: ["b.java"],
947 compile_dex: true,
948 }
949
950 java_library {
951 name: "quuz",
952 apex_available: [
953 "com.android.art",
954 ],
955 srcs: ["b.java"],
956 compile_dex: true,
957 }
958
959 bootclasspath_fragment {
960 name: "art-bootclasspath-fragment",
961 image_name: "art",
962 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
963 contents: ["baz", "quuz"],
964 apex_available: [
965 "com.android.art",
966 ],
967 }
968
969 apex {
970 name: "myapex",
971 key: "myapex.key",
972 bootclasspath_fragments: [
973 "mybootclasspathfragment",
974 ],
975 updatable: false,
976 }
977
978 apex_key {
979 name: "myapex.key",
980 public_key: "testkey.avbpubkey",
981 private_key: "testkey.pem",
982 }
983
984 java_sdk_library {
985 name: "foo",
986 srcs: ["b.java"],
987 shared_library: false,
988 public: {enabled: true},
989 apex_available: [
990 "myapex",
991 ],
992 }
993
994 java_library {
995 name: "bar",
996 srcs: ["b.java"],
997 installable: true,
998 apex_available: [
999 "myapex",
1000 ],
1001 }
1002
1003 bootclasspath_fragment {
1004 name: "mybootclasspathfragment",
1005 contents: [
1006 "foo",
1007 "bar",
1008 ],
1009 apex_available: [
1010 "myapex",
1011 ],
1012 additional_stubs: ["android-non-updatable"],
1013 fragments: [
1014 {
1015 apex: "com.android.art",
1016 module: "art-bootclasspath-fragment",
1017 },
1018 ],
1019 }
1020 `)
1021
1022 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1023 "android-non-updatable.stubs",
1024 "android-non-updatable.stubs.module_lib",
1025 "android-non-updatable.stubs.system",
1026 "android-non-updatable.stubs.test",
1027 "art-bootclasspath-fragment",
1028 "bar",
1029 "dex2oatd",
1030 "foo",
1031 })
1032
1033 nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs")
1034 nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system")
1035 nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test")
1036 nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib")
1037
1038 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1039 // API flags.
1040 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1041
1042 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1043 command := rule.RuleParams.Command
1044 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1045
1046 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1047 // the implementation boot dex jars provided by this module.
1048 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1049
1050 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1051 // the different API stubs provided by this module.
1052 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1053 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1054 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1055}
1056
1057// TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that
1058// setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable
1059// modules to be added to the hiddenapi list tool.
1060func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) {
1061 result := android.GroupFixturePreparers(
1062 prepareForTestWithBootclasspathFragment,
1063 java.PrepareForTestWithJavaDefaultModules,
1064 prepareForTestWithArtApex,
1065 prepareForTestWithMyapex,
1066 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +01001067 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
1068 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin5cca7c42021-05-26 10:16:01 +01001069 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
1070 // is disabled.
1071 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
1072
1073 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1074 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
1075 }),
1076
1077 java.PrepareForTestWithJavaSdkLibraryFiles,
1078 java.FixtureWithPrebuiltApis(map[string][]string{
1079 "current": {"android-non-updatable"},
1080 "30": {"foo"},
1081 }),
1082 ).RunTestWithBp(t, `
1083 apex {
1084 name: "com.android.art",
1085 key: "com.android.art.key",
1086 bootclasspath_fragments: ["art-bootclasspath-fragment"],
1087 java_libs: [
1088 "baz",
1089 "quuz",
1090 ],
1091 updatable: false,
1092 }
1093
1094 apex_key {
1095 name: "com.android.art.key",
1096 public_key: "com.android.art.avbpubkey",
1097 private_key: "com.android.art.pem",
1098 }
1099
1100 java_library {
1101 name: "baz",
1102 apex_available: [
1103 "com.android.art",
1104 ],
1105 srcs: ["b.java"],
1106 compile_dex: true,
1107 }
1108
1109 java_library {
1110 name: "quuz",
1111 apex_available: [
1112 "com.android.art",
1113 ],
1114 srcs: ["b.java"],
1115 compile_dex: true,
1116 }
1117
1118 bootclasspath_fragment {
1119 name: "art-bootclasspath-fragment",
1120 image_name: "art",
1121 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
1122 contents: ["baz", "quuz"],
1123 apex_available: [
1124 "com.android.art",
1125 ],
1126 }
1127
1128 apex {
1129 name: "myapex",
1130 key: "myapex.key",
1131 bootclasspath_fragments: [
1132 "mybootclasspathfragment",
1133 ],
1134 updatable: false,
1135 }
1136
1137 apex_key {
1138 name: "myapex.key",
1139 public_key: "testkey.avbpubkey",
1140 private_key: "testkey.pem",
1141 }
1142
1143 java_sdk_library {
1144 name: "foo",
1145 srcs: ["b.java"],
1146 shared_library: false,
1147 public: {enabled: true},
1148 apex_available: [
1149 "myapex",
1150 ],
1151 }
1152
1153 java_library {
1154 name: "bar",
1155 srcs: ["b.java"],
1156 installable: true,
1157 apex_available: [
1158 "myapex",
1159 ],
1160 }
1161
1162 bootclasspath_fragment {
1163 name: "mybootclasspathfragment",
1164 contents: [
1165 "foo",
1166 "bar",
1167 ],
1168 apex_available: [
1169 "myapex",
1170 ],
1171 additional_stubs: ["android-non-updatable"],
1172 fragments: [
1173 {
1174 apex: "com.android.art",
1175 module: "art-bootclasspath-fragment",
1176 },
1177 ],
1178 }
1179 `)
1180
1181 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1182 "art-bootclasspath-fragment",
1183 "bar",
1184 "dex2oatd",
1185 "foo",
1186 "prebuilt_sdk_module-lib_current_android-non-updatable",
1187 "prebuilt_sdk_public_current_android-non-updatable",
1188 "prebuilt_sdk_system_current_android-non-updatable",
1189 "prebuilt_sdk_test_current_android-non-updatable",
1190 })
1191
1192 nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable")
1193 nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable")
1194 nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable")
1195 nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable")
1196
1197 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1198 // API flags.
1199 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1200
1201 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1202 command := rule.RuleParams.Command
1203 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1204
1205 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1206 // the implementation boot dex jars provided by this module.
1207 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1208
1209 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1210 // the different API stubs provided by this module.
1211 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1212 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1213 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1214}
1215
Paul Duffina1d60252021-01-21 18:13:43 +00001216// TODO(b/177892522) - add test for host apex.