blob: 7ecf9b20f73060887a0bc2914b81f191082b0bb4 [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"
Jiakai Zhang49b1eb62021-11-26 18:09:27 +000024 "android/soong/dexpreopt"
Paul Duffin3451e162021-01-20 15:16:56 +000025 "android/soong/java"
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +010026
Paul Duffin5cca7c42021-05-26 10:16:01 +010027 "github.com/google/blueprint/proptools"
Paul Duffin3451e162021-01-20 15:16:56 +000028)
29
Paul Duffin7771eba2021-04-23 14:25:28 +010030// Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART
31// bootclasspath_fragment requires modules from the ART apex.
Paul Duffin3451e162021-01-20 15:16:56 +000032
Paul Duffin94f19632021-04-20 12:40:07 +010033var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
Paul Duffin52bfaa42021-03-23 23:40:12 +000034 java.PrepareForTestWithDexpreopt,
35 PrepareForTestWithApexBuildComponents,
36)
37
38// Some additional files needed for the art apex.
Jiakai Zhang49b1eb62021-11-26 18:09:27 +000039var prepareForTestWithArtApex = android.GroupFixturePreparers(
40 android.FixtureMergeMockFs(android.MockFS{
41 "com.android.art.avbpubkey": nil,
42 "com.android.art.pem": nil,
43 "system/sepolicy/apex/com.android.art-file_contexts": nil,
44 }),
45 dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"),
46)
Paul Duffin52bfaa42021-03-23 23:40:12 +000047
Paul Duffin94f19632021-04-20 12:40:07 +010048func TestBootclasspathFragments(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +000049 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +010050 prepareForTestWithBootclasspathFragment,
Paul Duffin7771eba2021-04-23 14:25:28 +010051 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
Paul Duffin60264a02021-04-12 20:02:36 +010052 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
Paul Duffin52bfaa42021-03-23 23:40:12 +000053 prepareForTestWithArtApex,
54
55 java.PrepareForTestWithJavaSdkLibraryFiles,
56 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin34d433a2021-03-09 14:13:25 +000057 ).RunTestWithBp(t, `
Paul Duffin3451e162021-01-20 15:16:56 +000058 java_sdk_library {
59 name: "foo",
60 srcs: ["b.java"],
Paul Duffin3451e162021-01-20 15:16:56 +000061 }
62
63 java_library {
64 name: "bar",
65 srcs: ["b.java"],
66 installable: true,
67 }
68
69 apex {
70 name: "com.android.art",
71 key: "com.android.art.key",
Paul Duffin58e0e762021-05-21 19:27:58 +010072 bootclasspath_fragments: ["art-bootclasspath-fragment"],
Paul Duffin3451e162021-01-20 15:16:56 +000073 java_libs: [
74 "baz",
75 "quuz",
76 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000077 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000078 }
79
80 apex_key {
81 name: "com.android.art.key",
82 public_key: "com.android.art.avbpubkey",
83 private_key: "com.android.art.pem",
84 }
85
86 java_library {
87 name: "baz",
88 apex_available: [
89 "com.android.art",
90 ],
91 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +010092 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +000093 }
94
95 java_library {
96 name: "quuz",
97 apex_available: [
98 "com.android.art",
99 ],
100 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +0100101 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +0000102 }
Paul Duffin5bbfef82021-01-30 12:57:26 +0000103
Paul Duffin94f19632021-04-20 12:40:07 +0100104 bootclasspath_fragment {
105 name: "art-bootclasspath-fragment",
Paul Duffin5bbfef82021-01-30 12:57:26 +0000106 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100107 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
108 contents: ["baz", "quuz"],
Paul Duffinc7ef9892021-03-23 23:21:59 +0000109 apex_available: [
110 "com.android.art",
111 ],
Paul Duffin5bbfef82021-01-30 12:57:26 +0000112 }
Paul Duffin3451e162021-01-20 15:16:56 +0000113`,
Paul Duffin3451e162021-01-20 15:16:56 +0000114 )
115
Paul Duffin94f19632021-04-20 12:40:07 +0100116 // Make sure that the art-bootclasspath-fragment is using the correct configuration.
Paul Duffin58e0e762021-05-21 19:27:58 +0100117 checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000",
118 "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000119test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
120test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
121test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
122test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
123test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
124test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
125test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
126test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
127test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
128test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
129test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
130test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
131`)
Paul Duffin3451e162021-01-20 15:16:56 +0000132}
133
Paul Duffinf1b358c2021-05-17 07:38:47 +0100134func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
135 result := android.GroupFixturePreparers(
136 prepareForTestWithBootclasspathFragment,
137 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
satayevabcd5972021-08-06 17:49:46 +0100138 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
139 java.FixtureConfigureApexBootJars("someapex:foo", "someapex:bar"),
Paul Duffinf1b358c2021-05-17 07:38:47 +0100140 prepareForTestWithArtApex,
141
142 java.PrepareForTestWithJavaSdkLibraryFiles,
143 java.FixtureWithLastReleaseApis("foo", "baz"),
144 ).RunTestWithBp(t, `
145 java_sdk_library {
146 name: "foo",
147 srcs: ["b.java"],
148 shared_library: false,
149 public: {
150 enabled: true,
151 },
152 system: {
153 enabled: true,
154 },
155 }
156
157 java_library {
158 name: "bar",
159 srcs: ["b.java"],
160 installable: true,
161 }
162
163 apex {
164 name: "com.android.art",
165 key: "com.android.art.key",
166 bootclasspath_fragments: ["art-bootclasspath-fragment"],
167 updatable: false,
168 }
169
170 apex_key {
171 name: "com.android.art.key",
172 public_key: "com.android.art.avbpubkey",
173 private_key: "com.android.art.pem",
174 }
175
176 java_sdk_library {
177 name: "baz",
178 apex_available: [
179 "com.android.art",
180 ],
181 srcs: ["b.java"],
182 shared_library: false,
183 public: {
184 enabled: true,
185 },
186 system: {
187 enabled: true,
188 },
189 test: {
190 enabled: true,
191 },
192 }
193
194 java_library {
195 name: "quuz",
196 apex_available: [
197 "com.android.art",
198 ],
199 srcs: ["b.java"],
200 compile_dex: true,
201 }
202
203 bootclasspath_fragment {
204 name: "art-bootclasspath-fragment",
205 image_name: "art",
206 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
207 contents: ["baz", "quuz"],
208 apex_available: [
209 "com.android.art",
210 ],
211 }
212
213 bootclasspath_fragment {
214 name: "other-bootclasspath-fragment",
215 contents: ["foo", "bar"],
216 fragments: [
217 {
218 apex: "com.android.art",
219 module: "art-bootclasspath-fragment",
220 },
221 ],
222 }
223`,
224 )
225
Paul Duffin31fad802021-06-18 18:14:25 +0100226 checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) {
Paul Duffinf1b358c2021-05-17 07:38:47 +0100227 t.Helper()
Paul Duffin280a31a2021-06-27 20:28:29 +0100228 paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope)
229 android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100230 }
231
232 // Check stub dex paths exported by art.
233 artFragment := result.Module("art-bootclasspath-fragment", "android_common")
234 artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
235
236 bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
237 bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
238 bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
239
Paul Duffin31fad802021-06-18 18:14:25 +0100240 checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
241 checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
242 checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
243 checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100244
245 // Check stub dex paths exported by other.
246 otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
247 otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
248
249 fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
250 fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
251
Paul Duffin31fad802021-06-18 18:14:25 +0100252 checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
253 checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
254 checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
255 checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100256}
257
Paul Duffin58e0e762021-05-21 19:27:58 +0100258func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000259 t.Helper()
260
Paul Duffin58e0e762021-05-21 19:27:58 +0100261 bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000262
Paul Duffine946b322021-04-25 23:04:00 +0100263 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
264 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000265 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000266
267 // Get a list of all the paths in the boot image sorted by arch type.
268 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100269 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000270 for _, archType := range android.ArchTypeList() {
271 if paths, ok := bootImageFilesByArchType[archType]; ok {
272 for _, path := range paths {
273 allPaths = append(allPaths, android.NormalizePathForTesting(path))
274 }
275 }
276 }
Paul Duffin3451e162021-01-20 15:16:56 +0000277
Paul Duffin94f19632021-04-20 12:40:07 +0100278 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000279}
Paul Duffina1d60252021-01-21 18:13:43 +0000280
Paul Duffin94f19632021-04-20 12:40:07 +0100281func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000282 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100283 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000284 prepareForTestWithArtApex,
285
Paul Duffinba6afd02019-11-19 19:44:10 +0000286 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000287 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000288 name: "com.android.art",
289 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100290 bootclasspath_fragments: [
291 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000292 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000293 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100294 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
295 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000296 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000297 "bar",
298 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000299 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000300 }
301
302 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000303 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000304 public_key: "testkey.avbpubkey",
305 private_key: "testkey.pem",
306 }
307
308 java_library {
309 name: "foo",
310 srcs: ["b.java"],
311 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000312 apex_available: [
313 "com.android.art",
314 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000315 }
316
317 java_library {
318 name: "bar",
319 srcs: ["b.java"],
320 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000321 apex_available: [
322 "com.android.art",
323 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000324 }
325
Paul Duffin65898052021-04-20 22:47:03 +0100326 java_import {
327 name: "foo",
328 jars: ["foo.jar"],
329 apex_available: [
330 "com.android.art",
331 ],
Paul Duffine5218812021-06-07 13:28:19 +0100332 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100333 }
334
335 java_import {
336 name: "bar",
337 jars: ["bar.jar"],
338 apex_available: [
339 "com.android.art",
340 ],
Paul Duffine5218812021-06-07 13:28:19 +0100341 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100342 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000343 `),
344 )
Paul Duffin65898052021-04-20 22:47:03 +0100345
Paul Duffinba6afd02019-11-19 19:44:10 +0000346 contentsInsert := func(contents []string) string {
347 insert := ""
348 if contents != nil {
349 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000350 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000351 return insert
352 }
Paul Duffina1d60252021-01-21 18:13:43 +0000353
Paul Duffinba6afd02019-11-19 19:44:10 +0000354 addSource := func(contents ...string) android.FixturePreparer {
355 text := fmt.Sprintf(`
356 bootclasspath_fragment {
357 name: "mybootclasspathfragment",
358 image_name: "art",
359 %s
360 apex_available: [
361 "com.android.art",
362 ],
363 }
364 `, contentsInsert(contents))
365
366 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
367 }
368
369 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
370 text := fmt.Sprintf(`
Paul Duffince918b02021-06-07 14:33:47 +0100371 prebuilt_apex {
372 name: "com.android.art",
373 arch: {
374 arm64: {
375 src: "com.android.art-arm64.apex",
376 },
377 arm: {
378 src: "com.android.art-arm.apex",
379 },
380 },
381 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
382 }
383
Paul Duffinba6afd02019-11-19 19:44:10 +0000384 prebuilt_bootclasspath_fragment {
385 name: "mybootclasspathfragment",
386 image_name: "art",
387 %s
388 prefer: %t,
389 apex_available: [
390 "com.android.art",
391 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100392 hidden_api: {
393 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
394 metadata: "mybootclasspathfragment/metadata.csv",
395 index: "mybootclasspathfragment/index.csv",
396 stub_flags: "mybootclasspathfragment/stub-flags.csv",
397 all_flags: "mybootclasspathfragment/all-flags.csv",
398 },
Paul Duffinba6afd02019-11-19 19:44:10 +0000399 }
400 `, contentsInsert(contents), prefer)
401 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
402 }
403
Paul Duffince918b02021-06-07 14:33:47 +0100404 t.Run("boot image files from source", func(t *testing.T) {
405 result := android.GroupFixturePreparers(
406 commonPreparer,
407
408 // Configure some libraries in the art bootclasspath_fragment that match the source
409 // bootclasspath_fragment's contents property.
410 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
411 addSource("foo", "bar"),
412 ).RunTest(t)
413
414 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
Jiakai Zhang49b1eb62021-11-26 18:09:27 +0000415 "etc/boot-image.prof",
Paul Duffince918b02021-06-07 14:33:47 +0100416 "etc/classpaths/bootclasspath.pb",
417 "javalib/arm/boot.art",
418 "javalib/arm/boot.oat",
419 "javalib/arm/boot.vdex",
420 "javalib/arm/boot-bar.art",
421 "javalib/arm/boot-bar.oat",
422 "javalib/arm/boot-bar.vdex",
423 "javalib/arm64/boot.art",
424 "javalib/arm64/boot.oat",
425 "javalib/arm64/boot.vdex",
426 "javalib/arm64/boot-bar.art",
427 "javalib/arm64/boot-bar.oat",
428 "javalib/arm64/boot-bar.vdex",
429 "javalib/bar.jar",
430 "javalib/foo.jar",
431 })
432
433 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
434 `bar`,
435 `com.android.art.key`,
436 `mybootclasspathfragment`,
437 })
438
439 // Make sure that the source bootclasspath_fragment copies its dex files to the predefined
440 // locations for the art image.
441 module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
442 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
443 })
444
445 t.Run("boot image files with preferred prebuilt", func(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000446 result := android.GroupFixturePreparers(
447 commonPreparer,
448
449 // Configure some libraries in the art bootclasspath_fragment that match the source
450 // bootclasspath_fragment's contents property.
451 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
452 addSource("foo", "bar"),
453
454 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
455 addPrebuilt(true, "foo", "bar"),
456 ).RunTest(t)
457
458 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
Jiakai Zhang49b1eb62021-11-26 18:09:27 +0000459 "etc/boot-image.prof",
satayev227e7452021-05-20 21:35:06 +0100460 "etc/classpaths/bootclasspath.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000461 "javalib/arm/boot.art",
462 "javalib/arm/boot.oat",
463 "javalib/arm/boot.vdex",
464 "javalib/arm/boot-bar.art",
465 "javalib/arm/boot-bar.oat",
466 "javalib/arm/boot-bar.vdex",
467 "javalib/arm64/boot.art",
468 "javalib/arm64/boot.oat",
469 "javalib/arm64/boot.vdex",
470 "javalib/arm64/boot-bar.art",
471 "javalib/arm64/boot-bar.oat",
472 "javalib/arm64/boot-bar.vdex",
473 "javalib/bar.jar",
474 "javalib/foo.jar",
475 })
476
477 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
478 `bar`,
479 `com.android.art.key`,
480 `mybootclasspathfragment`,
Paul Duffince918b02021-06-07 14:33:47 +0100481 `prebuilt_com.android.art`,
Paul Duffinba6afd02019-11-19 19:44:10 +0000482 })
Paul Duffince918b02021-06-07 14:33:47 +0100483
484 // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined
485 // locations for the art image.
486 module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art")
487 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
Paul Duffina1d60252021-01-21 18:13:43 +0000488 })
Paul Duffin396229f2021-03-18 18:30:31 +0000489
Paul Duffinba6afd02019-11-19 19:44:10 +0000490 t.Run("source with inconsistency between config and contents", func(t *testing.T) {
491 android.GroupFixturePreparers(
492 commonPreparer,
493
494 // Create an inconsistency between the ArtApexJars configuration and the art source
495 // bootclasspath_fragment module's contents property.
496 java.FixtureConfigureBootJars("com.android.art:foo"),
497 addSource("foo", "bar"),
498 ).
499 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
500 RunTest(t)
501 })
502
503 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
504 android.GroupFixturePreparers(
505 commonPreparer,
506
507 // Create an inconsistency between the ArtApexJars configuration and the art
508 // prebuilt_bootclasspath_fragment module's contents property.
509 java.FixtureConfigureBootJars("com.android.art:foo"),
510 addPrebuilt(false, "foo", "bar"),
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("preferred 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(true, "foo", "bar"),
524
525 // Source contents property is consistent with the config.
526 addSource("foo"),
527 ).
528 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
529 RunTest(t)
530 })
531
532 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
533 android.GroupFixturePreparers(
534 commonPreparer,
535
536 // Create an inconsistency between the ArtApexJars configuration and the art
537 // prebuilt_bootclasspath_fragment module's contents property.
538 java.FixtureConfigureBootJars("com.android.art:foo"),
539 addPrebuilt(false, "foo", "bar"),
540
541 // Source contents property is consistent with the config.
542 addSource("foo"),
543
544 // This should pass because while the prebuilt is inconsistent with the configuration it is
545 // not actually used.
546 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000547 })
Paul Duffina1d60252021-01-21 18:13:43 +0000548}
549
Paul Duffin94f19632021-04-20 12:40:07 +0100550func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100551 preparers := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100552 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000553 prepareForTestWithArtApex,
554
555 android.FixtureMergeMockFs(android.MockFS{
556 "com.android.art-arm64.apex": nil,
557 "com.android.art-arm.apex": nil,
558 }),
559
Paul Duffin7771eba2021-04-23 14:25:28 +0100560 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100561 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100562 )
563
564 bp := `
Paul Duffin9ea71c02021-03-23 22:53:07 +0000565 prebuilt_apex {
566 name: "com.android.art",
567 arch: {
568 arm64: {
569 src: "com.android.art-arm64.apex",
570 },
571 arm: {
572 src: "com.android.art-arm.apex",
573 },
574 },
Paul Duffine5218812021-06-07 13:28:19 +0100575 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000576 }
577
578 java_import {
579 name: "foo",
580 jars: ["foo.jar"],
581 apex_available: [
582 "com.android.art",
583 ],
584 }
585
586 java_import {
587 name: "bar",
588 jars: ["bar.jar"],
589 apex_available: [
590 "com.android.art",
591 ],
592 }
593
Paul Duffin7771eba2021-04-23 14:25:28 +0100594 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100595 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000596 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100597 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
598 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000599 apex_available: [
600 "com.android.art",
601 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100602 hidden_api: {
603 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
604 metadata: "mybootclasspathfragment/metadata.csv",
605 index: "mybootclasspathfragment/index.csv",
606 stub_flags: "mybootclasspathfragment/stub-flags.csv",
607 all_flags: "mybootclasspathfragment/all-flags.csv",
608 },
Paul Duffin9ea71c02021-03-23 22:53:07 +0000609 }
Paul Duffin9ea71c02021-03-23 22:53:07 +0000610
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100611 // A prebuilt apex with the same apex_name that shouldn't interfere when it isn't enabled.
612 prebuilt_apex {
613 name: "com.mycompany.android.art",
614 apex_name: "com.android.art",
615 %s
616 src: "com.mycompany.android.art.apex",
617 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
618 }
619 `
620
621 t.Run("disabled alternative APEX", func(t *testing.T) {
622 result := preparers.RunTestWithBp(t, fmt.Sprintf(bp, "enabled: false,"))
623
624 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
625 `com.android.art.apex.selector`,
626 `prebuilt_mybootclasspathfragment`,
627 })
628
629 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{
630 `com.android.art.deapexer`,
631 `dex2oatd`,
632 `prebuilt_bar`,
633 `prebuilt_foo`,
634 })
635
636 module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art")
637 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
638
639 // Check that the right deapexer module was chosen for a boot image.
640 param := module.Output("out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art")
641 android.AssertStringDoesContain(t, "didn't find the expected deapexer in the input path", param.Input.String(), "/com.android.art.deapexer")
Paul Duffin9ea71c02021-03-23 22:53:07 +0000642 })
643
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100644 t.Run("enabled alternative APEX", func(t *testing.T) {
645 preparers.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
646 "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.art and com.mycompany.android.art")).
647 RunTestWithBp(t, fmt.Sprintf(bp, ""))
Paul Duffin9ea71c02021-03-23 22:53:07 +0000648 })
Paul Duffince918b02021-06-07 14:33:47 +0100649}
650
651// checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the
652// predefined locations of boot dex jars used as inputs for the ART boot image.
653func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) {
654 t.Helper()
655 bootJarLocations := []string{}
656 for _, output := range module.AllOutputs() {
657 output = android.StringRelativeToTop(config, output)
658 if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") {
659 bootJarLocations = append(bootJarLocations, output)
660 }
661 }
662
663 sort.Strings(bootJarLocations)
664 expected := []string{}
665 for _, m := range modules {
666 expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m))
667 }
668 sort.Strings(expected)
669
670 android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations)
Paul Duffin9ea71c02021-03-23 22:53:07 +0000671}
672
Paul Duffin94f19632021-04-20 12:40:07 +0100673func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000674 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100675 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000676 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100677 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +0100678 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100679 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
680 // is disabled.
681 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
682
683 java.PrepareForTestWithJavaSdkLibraryFiles,
684 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000685 ).RunTestWithBp(t, `
686 apex {
687 name: "myapex",
688 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100689 bootclasspath_fragments: [
690 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000691 ],
692 updatable: false,
693 }
694
695 apex_key {
696 name: "myapex.key",
697 public_key: "testkey.avbpubkey",
698 private_key: "testkey.pem",
699 }
700
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100701 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000702 name: "foo",
703 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100704 shared_library: false,
705 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000706 apex_available: [
707 "myapex",
708 ],
709 }
710
711 java_library {
712 name: "bar",
713 srcs: ["b.java"],
714 installable: true,
715 apex_available: [
716 "myapex",
717 ],
718 }
719
Paul Duffin7771eba2021-04-23 14:25:28 +0100720 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100721 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000722 contents: [
723 "foo",
724 "bar",
725 ],
726 apex_available: [
727 "myapex",
728 ],
729 }
730 `)
731
Paul Duffin4d101b62021-03-24 15:42:20 +0000732 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
733 // This does not include art, oat or vdex files as they are only included for the art boot
734 // image.
satayev227e7452021-05-20 21:35:06 +0100735 "etc/classpaths/bootclasspath.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000736 "javalib/bar.jar",
737 "javalib/foo.jar",
738 })
Paul Duffin82886d62021-03-24 01:34:57 +0000739
740 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
741 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100742 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000743 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100744
745 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
746 apexRule := apex.Rule("apexRule")
747 copyCommands := apexRule.Args["copy_commands"]
748
749 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
750 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
751
752 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
753
754 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
755 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100756 dexJar, err := info.DexBootJarPathForContentModule(module)
757 if err != nil {
758 t.Error(err)
759 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100760 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
761
762 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
763 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
764 }
765
Paul Duffin54c98f52021-05-15 08:54:30 +0100766 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
767 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000768}
769
Paul Duffin48b67412021-06-23 16:13:50 +0100770func getDexJarPath(result *android.TestResult, name string) string {
771 module := result.Module(name, "android_common")
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100772 return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String()
Paul Duffin48b67412021-06-23 16:13:50 +0100773}
774
775// TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
776// passed to the hiddenapi list tool.
777func TestBootclasspathFragment_HiddenAPIList(t *testing.T) {
778 result := android.GroupFixturePreparers(
779 prepareForTestWithBootclasspathFragment,
780 prepareForTestWithArtApex,
781 prepareForTestWithMyapex,
782 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
783 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
satayevd604b212021-07-21 14:23:52 +0100784 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin48b67412021-06-23 16:13:50 +0100785 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
786 // is disabled.
787 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
788
789 java.PrepareForTestWithJavaSdkLibraryFiles,
790 java.FixtureWithLastReleaseApis("foo", "quuz"),
791 ).RunTestWithBp(t, `
792 apex {
793 name: "com.android.art",
794 key: "com.android.art.key",
795 bootclasspath_fragments: ["art-bootclasspath-fragment"],
796 updatable: false,
797 }
798
799 apex_key {
800 name: "com.android.art.key",
801 public_key: "com.android.art.avbpubkey",
802 private_key: "com.android.art.pem",
803 }
804
805 java_library {
806 name: "baz",
807 apex_available: [
808 "com.android.art",
809 ],
810 srcs: ["b.java"],
811 compile_dex: true,
812 }
813
814 java_sdk_library {
815 name: "quuz",
816 apex_available: [
817 "com.android.art",
818 ],
819 srcs: ["b.java"],
820 compile_dex: true,
821 public: {enabled: true},
822 system: {enabled: true},
823 test: {enabled: true},
824 module_lib: {enabled: true},
825 }
826
827 bootclasspath_fragment {
828 name: "art-bootclasspath-fragment",
829 image_name: "art",
830 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
831 contents: ["baz", "quuz"],
832 apex_available: [
833 "com.android.art",
834 ],
835 }
836
837 apex {
838 name: "myapex",
839 key: "myapex.key",
840 bootclasspath_fragments: [
841 "mybootclasspathfragment",
842 ],
843 updatable: false,
844 }
845
846 apex_key {
847 name: "myapex.key",
848 public_key: "testkey.avbpubkey",
849 private_key: "testkey.pem",
850 }
851
852 java_sdk_library {
853 name: "foo",
854 srcs: ["b.java"],
855 shared_library: false,
856 public: {enabled: true},
857 apex_available: [
858 "myapex",
859 ],
860 }
861
862 java_library {
863 name: "bar",
864 srcs: ["b.java"],
865 installable: true,
866 apex_available: [
867 "myapex",
868 ],
869 }
870
871 bootclasspath_fragment {
872 name: "mybootclasspathfragment",
873 contents: [
874 "foo",
875 "bar",
876 ],
877 apex_available: [
878 "myapex",
879 ],
880 fragments: [
881 {
882 apex: "com.android.art",
883 module: "art-bootclasspath-fragment",
884 },
885 ],
886 }
887 `)
888
889 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
890 "art-bootclasspath-fragment",
891 "bar",
892 "dex2oatd",
893 "foo",
894 })
895
896 fooStubs := getDexJarPath(result, "foo.stubs")
897 quuzPublicStubs := getDexJarPath(result, "quuz.stubs")
898 quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system")
899 quuzTestStubs := getDexJarPath(result, "quuz.stubs.test")
Paul Duffinb51db2e2021-06-21 14:08:08 +0100900 quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib")
Paul Duffin48b67412021-06-23 16:13:50 +0100901
902 // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags.
903 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
904
905 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
906 command := rule.RuleParams.Command
907 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
908
909 // Make sure that the quuz stubs are available for resolving references from the implementation
910 // boot dex jars provided by this module.
Paul Duffinb51db2e2021-06-21 14:08:08 +0100911 android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs)
Paul Duffin48b67412021-06-23 16:13:50 +0100912
913 // Make sure that the quuz stubs are available for resolving references from the different API
914 // stubs provided by this module.
915 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs)
916 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs)
917 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs)
918}
919
Paul Duffin5cca7c42021-05-26 10:16:01 +0100920// TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting
921// additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be
922// added to the hiddenapi list tool.
923func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) {
924 result := android.GroupFixturePreparers(
925 prepareForTestWithBootclasspathFragment,
926 prepareForTestWithArtApex,
927 prepareForTestWithMyapex,
928 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +0100929 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
930 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin5cca7c42021-05-26 10:16:01 +0100931 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
932 // is disabled.
933 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
934
935 java.PrepareForTestWithJavaSdkLibraryFiles,
936 java.FixtureWithLastReleaseApis("foo", "android-non-updatable"),
937 ).RunTestWithBp(t, `
938 java_sdk_library {
939 name: "android-non-updatable",
940 srcs: ["b.java"],
941 compile_dex: true,
942 public: {
943 enabled: true,
944 },
945 system: {
946 enabled: true,
947 },
948 test: {
949 enabled: true,
950 },
951 module_lib: {
952 enabled: true,
953 },
954 }
955
956 apex {
957 name: "com.android.art",
958 key: "com.android.art.key",
959 bootclasspath_fragments: ["art-bootclasspath-fragment"],
960 java_libs: [
961 "baz",
962 "quuz",
963 ],
964 updatable: false,
965 }
966
967 apex_key {
968 name: "com.android.art.key",
969 public_key: "com.android.art.avbpubkey",
970 private_key: "com.android.art.pem",
971 }
972
973 java_library {
974 name: "baz",
975 apex_available: [
976 "com.android.art",
977 ],
978 srcs: ["b.java"],
979 compile_dex: true,
980 }
981
982 java_library {
983 name: "quuz",
984 apex_available: [
985 "com.android.art",
986 ],
987 srcs: ["b.java"],
988 compile_dex: true,
989 }
990
991 bootclasspath_fragment {
992 name: "art-bootclasspath-fragment",
993 image_name: "art",
994 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
995 contents: ["baz", "quuz"],
996 apex_available: [
997 "com.android.art",
998 ],
999 }
1000
1001 apex {
1002 name: "myapex",
1003 key: "myapex.key",
1004 bootclasspath_fragments: [
1005 "mybootclasspathfragment",
1006 ],
1007 updatable: false,
1008 }
1009
1010 apex_key {
1011 name: "myapex.key",
1012 public_key: "testkey.avbpubkey",
1013 private_key: "testkey.pem",
1014 }
1015
1016 java_sdk_library {
1017 name: "foo",
1018 srcs: ["b.java"],
1019 shared_library: false,
1020 public: {enabled: true},
1021 apex_available: [
1022 "myapex",
1023 ],
1024 }
1025
1026 java_library {
1027 name: "bar",
1028 srcs: ["b.java"],
1029 installable: true,
1030 apex_available: [
1031 "myapex",
1032 ],
1033 }
1034
1035 bootclasspath_fragment {
1036 name: "mybootclasspathfragment",
1037 contents: [
1038 "foo",
1039 "bar",
1040 ],
1041 apex_available: [
1042 "myapex",
1043 ],
1044 additional_stubs: ["android-non-updatable"],
1045 fragments: [
1046 {
1047 apex: "com.android.art",
1048 module: "art-bootclasspath-fragment",
1049 },
1050 ],
1051 }
1052 `)
1053
1054 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1055 "android-non-updatable.stubs",
1056 "android-non-updatable.stubs.module_lib",
1057 "android-non-updatable.stubs.system",
1058 "android-non-updatable.stubs.test",
1059 "art-bootclasspath-fragment",
1060 "bar",
1061 "dex2oatd",
1062 "foo",
1063 })
1064
1065 nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs")
1066 nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system")
1067 nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test")
1068 nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib")
1069
1070 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1071 // API flags.
1072 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1073
1074 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1075 command := rule.RuleParams.Command
1076 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1077
1078 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1079 // the implementation boot dex jars provided by this module.
1080 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1081
1082 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1083 // the different API stubs provided by this module.
1084 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1085 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1086 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1087}
1088
1089// TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that
1090// setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable
1091// modules to be added to the hiddenapi list tool.
1092func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) {
1093 result := android.GroupFixturePreparers(
1094 prepareForTestWithBootclasspathFragment,
1095 java.PrepareForTestWithJavaDefaultModules,
1096 prepareForTestWithArtApex,
1097 prepareForTestWithMyapex,
1098 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +01001099 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
1100 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin5cca7c42021-05-26 10:16:01 +01001101 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
1102 // is disabled.
1103 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
1104
1105 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1106 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
1107 }),
1108
1109 java.PrepareForTestWithJavaSdkLibraryFiles,
1110 java.FixtureWithPrebuiltApis(map[string][]string{
1111 "current": {"android-non-updatable"},
1112 "30": {"foo"},
1113 }),
1114 ).RunTestWithBp(t, `
1115 apex {
1116 name: "com.android.art",
1117 key: "com.android.art.key",
1118 bootclasspath_fragments: ["art-bootclasspath-fragment"],
1119 java_libs: [
1120 "baz",
1121 "quuz",
1122 ],
1123 updatable: false,
1124 }
1125
1126 apex_key {
1127 name: "com.android.art.key",
1128 public_key: "com.android.art.avbpubkey",
1129 private_key: "com.android.art.pem",
1130 }
1131
1132 java_library {
1133 name: "baz",
1134 apex_available: [
1135 "com.android.art",
1136 ],
1137 srcs: ["b.java"],
1138 compile_dex: true,
1139 }
1140
1141 java_library {
1142 name: "quuz",
1143 apex_available: [
1144 "com.android.art",
1145 ],
1146 srcs: ["b.java"],
1147 compile_dex: true,
1148 }
1149
1150 bootclasspath_fragment {
1151 name: "art-bootclasspath-fragment",
1152 image_name: "art",
1153 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
1154 contents: ["baz", "quuz"],
1155 apex_available: [
1156 "com.android.art",
1157 ],
1158 }
1159
1160 apex {
1161 name: "myapex",
1162 key: "myapex.key",
1163 bootclasspath_fragments: [
1164 "mybootclasspathfragment",
1165 ],
1166 updatable: false,
1167 }
1168
1169 apex_key {
1170 name: "myapex.key",
1171 public_key: "testkey.avbpubkey",
1172 private_key: "testkey.pem",
1173 }
1174
1175 java_sdk_library {
1176 name: "foo",
1177 srcs: ["b.java"],
1178 shared_library: false,
1179 public: {enabled: true},
1180 apex_available: [
1181 "myapex",
1182 ],
1183 }
1184
1185 java_library {
1186 name: "bar",
1187 srcs: ["b.java"],
1188 installable: true,
1189 apex_available: [
1190 "myapex",
1191 ],
1192 }
1193
1194 bootclasspath_fragment {
1195 name: "mybootclasspathfragment",
1196 contents: [
1197 "foo",
1198 "bar",
1199 ],
1200 apex_available: [
1201 "myapex",
1202 ],
1203 additional_stubs: ["android-non-updatable"],
1204 fragments: [
1205 {
1206 apex: "com.android.art",
1207 module: "art-bootclasspath-fragment",
1208 },
1209 ],
1210 }
1211 `)
1212
1213 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1214 "art-bootclasspath-fragment",
1215 "bar",
1216 "dex2oatd",
1217 "foo",
1218 "prebuilt_sdk_module-lib_current_android-non-updatable",
1219 "prebuilt_sdk_public_current_android-non-updatable",
1220 "prebuilt_sdk_system_current_android-non-updatable",
1221 "prebuilt_sdk_test_current_android-non-updatable",
1222 })
1223
1224 nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable")
1225 nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable")
1226 nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable")
1227 nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable")
1228
1229 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1230 // API flags.
1231 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1232
1233 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1234 command := rule.RuleParams.Command
1235 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1236
1237 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1238 // the implementation boot dex jars provided by this module.
1239 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1240
1241 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1242 // the different API stubs provided by this module.
1243 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1244 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1245 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1246}
1247
Paul Duffina1d60252021-01-21 18:13:43 +00001248// TODO(b/177892522) - add test for host apex.