blob: ce828e1afb61069000e1480f1703a3320b8f6b08 [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"
Jiakai Zhang7d3c9e02021-12-13 17:19:05 +000019 "path"
Paul Duffince918b02021-06-07 14:33:47 +010020 "sort"
Paul Duffina1d60252021-01-21 18:13:43 +000021 "strings"
Paul Duffin3451e162021-01-20 15:16:56 +000022 "testing"
23
24 "android/soong/android"
Jiakai Zhang49b1eb62021-11-26 18:09:27 +000025 "android/soong/dexpreopt"
Paul Duffin3451e162021-01-20 15:16:56 +000026 "android/soong/java"
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +010027
Paul Duffin5cca7c42021-05-26 10:16:01 +010028 "github.com/google/blueprint/proptools"
Paul Duffin3451e162021-01-20 15:16:56 +000029)
30
Paul Duffin7771eba2021-04-23 14:25:28 +010031// Contains tests for bootclasspath_fragment logic from java/bootclasspath_fragment.go as the ART
32// bootclasspath_fragment requires modules from the ART apex.
Paul Duffin3451e162021-01-20 15:16:56 +000033
Paul Duffin94f19632021-04-20 12:40:07 +010034var prepareForTestWithBootclasspathFragment = android.GroupFixturePreparers(
Paul Duffin52bfaa42021-03-23 23:40:12 +000035 java.PrepareForTestWithDexpreopt,
36 PrepareForTestWithApexBuildComponents,
37)
38
39// Some additional files needed for the art apex.
Jiakai Zhang49b1eb62021-11-26 18:09:27 +000040var prepareForTestWithArtApex = android.GroupFixturePreparers(
41 android.FixtureMergeMockFs(android.MockFS{
42 "com.android.art.avbpubkey": nil,
43 "com.android.art.pem": nil,
44 "system/sepolicy/apex/com.android.art-file_contexts": nil,
45 }),
46 dexpreopt.FixtureSetBootImageProfiles("art/build/boot/boot-image-profile.txt"),
47)
Paul Duffin52bfaa42021-03-23 23:40:12 +000048
Paul Duffin94f19632021-04-20 12:40:07 +010049func TestBootclasspathFragments(t *testing.T) {
Paul Duffin52bfaa42021-03-23 23:40:12 +000050 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +010051 prepareForTestWithBootclasspathFragment,
Paul Duffin7771eba2021-04-23 14:25:28 +010052 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
Paul Duffin60264a02021-04-12 20:02:36 +010053 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz", "platform:foo", "platform:bar"),
Paul Duffin52bfaa42021-03-23 23:40:12 +000054 prepareForTestWithArtApex,
55
56 java.PrepareForTestWithJavaSdkLibraryFiles,
57 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin34d433a2021-03-09 14:13:25 +000058 ).RunTestWithBp(t, `
Paul Duffin3451e162021-01-20 15:16:56 +000059 java_sdk_library {
60 name: "foo",
61 srcs: ["b.java"],
Paul Duffin3451e162021-01-20 15:16:56 +000062 }
63
64 java_library {
65 name: "bar",
66 srcs: ["b.java"],
67 installable: true,
68 }
69
70 apex {
71 name: "com.android.art",
72 key: "com.android.art.key",
Paul Duffin58e0e762021-05-21 19:27:58 +010073 bootclasspath_fragments: ["art-bootclasspath-fragment"],
Paul Duffin3451e162021-01-20 15:16:56 +000074 java_libs: [
75 "baz",
76 "quuz",
77 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +000078 updatable: false,
Paul Duffin3451e162021-01-20 15:16:56 +000079 }
80
81 apex_key {
82 name: "com.android.art.key",
83 public_key: "com.android.art.avbpubkey",
84 private_key: "com.android.art.pem",
85 }
86
87 java_library {
88 name: "baz",
89 apex_available: [
90 "com.android.art",
91 ],
92 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +010093 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +000094 }
95
96 java_library {
97 name: "quuz",
98 apex_available: [
99 "com.android.art",
100 ],
101 srcs: ["b.java"],
Paul Duffine5218812021-06-07 13:28:19 +0100102 compile_dex: true,
Paul Duffin3451e162021-01-20 15:16:56 +0000103 }
Paul Duffin5bbfef82021-01-30 12:57:26 +0000104
Paul Duffin94f19632021-04-20 12:40:07 +0100105 bootclasspath_fragment {
106 name: "art-bootclasspath-fragment",
Paul Duffin5bbfef82021-01-30 12:57:26 +0000107 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100108 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
109 contents: ["baz", "quuz"],
Paul Duffinc7ef9892021-03-23 23:21:59 +0000110 apex_available: [
111 "com.android.art",
112 ],
Paul Duffin5bbfef82021-01-30 12:57:26 +0000113 }
Paul Duffin3451e162021-01-20 15:16:56 +0000114`,
Paul Duffin3451e162021-01-20 15:16:56 +0000115 )
116
Paul Duffin94f19632021-04-20 12:40:07 +0100117 // Make sure that the art-bootclasspath-fragment is using the correct configuration.
Paul Duffin58e0e762021-05-21 19:27:58 +0100118 checkBootclasspathFragment(t, result, "art-bootclasspath-fragment", "android_common_apex10000",
119 "com.android.art:baz,com.android.art:quuz", `
Paul Duffina1d60252021-01-21 18:13:43 +0000120test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.art
121test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.oat
122test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot.vdex
123test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.art
124test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.oat
125test_device/dex_artjars/android/apex/art_boot_images/javalib/arm/boot-quuz.vdex
126test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art
127test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.oat
128test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.vdex
129test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.art
130test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.oat
131test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot-quuz.vdex
132`)
Paul Duffin3451e162021-01-20 15:16:56 +0000133}
134
Paul Duffinf1b358c2021-05-17 07:38:47 +0100135func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
136 result := android.GroupFixturePreparers(
137 prepareForTestWithBootclasspathFragment,
138 // Configure some libraries in the art bootclasspath_fragment and platform_bootclasspath.
satayevabcd5972021-08-06 17:49:46 +0100139 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
140 java.FixtureConfigureApexBootJars("someapex:foo", "someapex:bar"),
Paul Duffinf1b358c2021-05-17 07:38:47 +0100141 prepareForTestWithArtApex,
142
143 java.PrepareForTestWithJavaSdkLibraryFiles,
144 java.FixtureWithLastReleaseApis("foo", "baz"),
145 ).RunTestWithBp(t, `
146 java_sdk_library {
147 name: "foo",
148 srcs: ["b.java"],
149 shared_library: false,
150 public: {
151 enabled: true,
152 },
153 system: {
154 enabled: true,
155 },
156 }
157
158 java_library {
159 name: "bar",
160 srcs: ["b.java"],
161 installable: true,
162 }
163
164 apex {
165 name: "com.android.art",
166 key: "com.android.art.key",
167 bootclasspath_fragments: ["art-bootclasspath-fragment"],
168 updatable: false,
169 }
170
171 apex_key {
172 name: "com.android.art.key",
173 public_key: "com.android.art.avbpubkey",
174 private_key: "com.android.art.pem",
175 }
176
177 java_sdk_library {
178 name: "baz",
179 apex_available: [
180 "com.android.art",
181 ],
182 srcs: ["b.java"],
183 shared_library: false,
184 public: {
185 enabled: true,
186 },
187 system: {
188 enabled: true,
189 },
190 test: {
191 enabled: true,
192 },
193 }
194
195 java_library {
196 name: "quuz",
197 apex_available: [
198 "com.android.art",
199 ],
200 srcs: ["b.java"],
201 compile_dex: true,
202 }
203
204 bootclasspath_fragment {
205 name: "art-bootclasspath-fragment",
206 image_name: "art",
207 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
208 contents: ["baz", "quuz"],
209 apex_available: [
210 "com.android.art",
211 ],
212 }
213
214 bootclasspath_fragment {
215 name: "other-bootclasspath-fragment",
216 contents: ["foo", "bar"],
217 fragments: [
218 {
219 apex: "com.android.art",
220 module: "art-bootclasspath-fragment",
221 },
222 ],
223 }
224`,
225 )
226
Paul Duffin31fad802021-06-18 18:14:25 +0100227 checkAPIScopeStubs := func(message string, info java.HiddenAPIInfo, apiScope *java.HiddenAPIScope, expectedPaths ...string) {
Paul Duffinf1b358c2021-05-17 07:38:47 +0100228 t.Helper()
Paul Duffin280a31a2021-06-27 20:28:29 +0100229 paths := info.TransitiveStubDexJarsByScope.StubDexJarsForScope(apiScope)
230 android.AssertPathsRelativeToTopEquals(t, fmt.Sprintf("%s %s", message, apiScope), expectedPaths, paths)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100231 }
232
233 // Check stub dex paths exported by art.
234 artFragment := result.Module("art-bootclasspath-fragment", "android_common")
235 artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
236
237 bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar"
238 bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar"
239 bazTestStubs := "out/soong/.intermediates/baz.stubs.test/android_common/dex/baz.stubs.test.jar"
240
Paul Duffin31fad802021-06-18 18:14:25 +0100241 checkAPIScopeStubs("art", artInfo, java.PublicHiddenAPIScope, bazPublicStubs)
242 checkAPIScopeStubs("art", artInfo, java.SystemHiddenAPIScope, bazSystemStubs)
243 checkAPIScopeStubs("art", artInfo, java.TestHiddenAPIScope, bazTestStubs)
244 checkAPIScopeStubs("art", artInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100245
246 // Check stub dex paths exported by other.
247 otherFragment := result.Module("other-bootclasspath-fragment", "android_common")
248 otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo)
249
250 fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar"
251 fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar"
252
Paul Duffin31fad802021-06-18 18:14:25 +0100253 checkAPIScopeStubs("other", otherInfo, java.PublicHiddenAPIScope, bazPublicStubs, fooPublicStubs)
254 checkAPIScopeStubs("other", otherInfo, java.SystemHiddenAPIScope, bazSystemStubs, fooSystemStubs)
255 checkAPIScopeStubs("other", otherInfo, java.TestHiddenAPIScope, bazTestStubs, fooSystemStubs)
256 checkAPIScopeStubs("other", otherInfo, java.CorePlatformHiddenAPIScope)
Paul Duffinf1b358c2021-05-17 07:38:47 +0100257}
258
Paul Duffin58e0e762021-05-21 19:27:58 +0100259func checkBootclasspathFragment(t *testing.T, result *android.TestResult, moduleName, variantName string, expectedConfiguredModules string, expectedBootclasspathFragmentFiles string) {
Paul Duffin3451e162021-01-20 15:16:56 +0000260 t.Helper()
261
Paul Duffin58e0e762021-05-21 19:27:58 +0100262 bootclasspathFragment := result.ModuleForTests(moduleName, variantName).Module().(*java.BootclasspathFragmentModule)
Paul Duffin3451e162021-01-20 15:16:56 +0000263
Paul Duffine946b322021-04-25 23:04:00 +0100264 bootclasspathFragmentInfo := result.ModuleProvider(bootclasspathFragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
265 modules := bootclasspathFragmentInfo.Modules()
Paul Duffin34d433a2021-03-09 14:13:25 +0000266 android.AssertStringEquals(t, "invalid modules for "+moduleName, expectedConfiguredModules, modules.String())
Paul Duffina1d60252021-01-21 18:13:43 +0000267
268 // Get a list of all the paths in the boot image sorted by arch type.
269 allPaths := []string{}
Paul Duffine946b322021-04-25 23:04:00 +0100270 bootImageFilesByArchType := bootclasspathFragmentInfo.AndroidBootImageFilesByArchType()
Paul Duffina1d60252021-01-21 18:13:43 +0000271 for _, archType := range android.ArchTypeList() {
272 if paths, ok := bootImageFilesByArchType[archType]; ok {
273 for _, path := range paths {
274 allPaths = append(allPaths, android.NormalizePathForTesting(path))
275 }
276 }
277 }
Paul Duffin3451e162021-01-20 15:16:56 +0000278
Paul Duffin94f19632021-04-20 12:40:07 +0100279 android.AssertTrimmedStringEquals(t, "invalid paths for "+moduleName, expectedBootclasspathFragmentFiles, strings.Join(allPaths, "\n"))
Paul Duffin3451e162021-01-20 15:16:56 +0000280}
Paul Duffina1d60252021-01-21 18:13:43 +0000281
Paul Duffin94f19632021-04-20 12:40:07 +0100282func TestBootclasspathFragmentInArtApex(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000283 commonPreparer := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100284 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000285 prepareForTestWithArtApex,
286
Paul Duffinba6afd02019-11-19 19:44:10 +0000287 android.FixtureWithRootAndroidBp(`
Paul Duffina1d60252021-01-21 18:13:43 +0000288 apex {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000289 name: "com.android.art",
290 key: "com.android.art.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100291 bootclasspath_fragments: [
292 "mybootclasspathfragment",
Paul Duffina1d60252021-01-21 18:13:43 +0000293 ],
Paul Duffin4d101b62021-03-24 15:42:20 +0000294 // bar (like foo) should be transitively included in this apex because it is part of the
Paul Duffin7771eba2021-04-23 14:25:28 +0100295 // mybootclasspathfragment bootclasspath_fragment. However, it is kept here to ensure that the
296 // apex dedups the files correctly.
Paul Duffin9ea71c02021-03-23 22:53:07 +0000297 java_libs: [
Paul Duffin9ea71c02021-03-23 22:53:07 +0000298 "bar",
299 ],
Mathew Inwoodf8dcf5e2021-02-16 11:40:16 +0000300 updatable: false,
Paul Duffina1d60252021-01-21 18:13:43 +0000301 }
302
303 apex_key {
Paul Duffin9ea71c02021-03-23 22:53:07 +0000304 name: "com.android.art.key",
Paul Duffina1d60252021-01-21 18:13:43 +0000305 public_key: "testkey.avbpubkey",
306 private_key: "testkey.pem",
307 }
308
309 java_library {
310 name: "foo",
311 srcs: ["b.java"],
312 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000313 apex_available: [
314 "com.android.art",
315 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000316 }
317
318 java_library {
319 name: "bar",
320 srcs: ["b.java"],
321 installable: true,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000322 apex_available: [
323 "com.android.art",
324 ],
Paul Duffina1d60252021-01-21 18:13:43 +0000325 }
326
Paul Duffin65898052021-04-20 22:47:03 +0100327 java_import {
328 name: "foo",
329 jars: ["foo.jar"],
330 apex_available: [
331 "com.android.art",
332 ],
Paul Duffine5218812021-06-07 13:28:19 +0100333 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100334 }
335
336 java_import {
337 name: "bar",
338 jars: ["bar.jar"],
339 apex_available: [
340 "com.android.art",
341 ],
Paul Duffine5218812021-06-07 13:28:19 +0100342 compile_dex: true,
Paul Duffin65898052021-04-20 22:47:03 +0100343 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000344 `),
345 )
Paul Duffin65898052021-04-20 22:47:03 +0100346
Paul Duffinba6afd02019-11-19 19:44:10 +0000347 contentsInsert := func(contents []string) string {
348 insert := ""
349 if contents != nil {
350 insert = fmt.Sprintf(`contents: ["%s"],`, strings.Join(contents, `", "`))
Paul Duffin396229f2021-03-18 18:30:31 +0000351 }
Paul Duffinba6afd02019-11-19 19:44:10 +0000352 return insert
353 }
Paul Duffina1d60252021-01-21 18:13:43 +0000354
Paul Duffinba6afd02019-11-19 19:44:10 +0000355 addSource := func(contents ...string) android.FixturePreparer {
356 text := fmt.Sprintf(`
357 bootclasspath_fragment {
358 name: "mybootclasspathfragment",
359 image_name: "art",
360 %s
361 apex_available: [
362 "com.android.art",
363 ],
364 }
365 `, contentsInsert(contents))
366
367 return android.FixtureAddTextFile("art/build/boot/Android.bp", text)
368 }
369
370 addPrebuilt := func(prefer bool, contents ...string) android.FixturePreparer {
371 text := fmt.Sprintf(`
Paul Duffince918b02021-06-07 14:33:47 +0100372 prebuilt_apex {
373 name: "com.android.art",
374 arch: {
375 arm64: {
376 src: "com.android.art-arm64.apex",
377 },
378 arm: {
379 src: "com.android.art-arm.apex",
380 },
381 },
382 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
383 }
384
Paul Duffinba6afd02019-11-19 19:44:10 +0000385 prebuilt_bootclasspath_fragment {
386 name: "mybootclasspathfragment",
387 image_name: "art",
388 %s
389 prefer: %t,
390 apex_available: [
391 "com.android.art",
392 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100393 hidden_api: {
394 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
395 metadata: "mybootclasspathfragment/metadata.csv",
396 index: "mybootclasspathfragment/index.csv",
397 stub_flags: "mybootclasspathfragment/stub-flags.csv",
398 all_flags: "mybootclasspathfragment/all-flags.csv",
399 },
Paul Duffinba6afd02019-11-19 19:44:10 +0000400 }
401 `, contentsInsert(contents), prefer)
402 return android.FixtureAddTextFile("prebuilts/module_sdk/art/Android.bp", text)
403 }
404
Paul Duffince918b02021-06-07 14:33:47 +0100405 t.Run("boot image files from source", func(t *testing.T) {
406 result := android.GroupFixturePreparers(
407 commonPreparer,
408
409 // Configure some libraries in the art bootclasspath_fragment that match the source
410 // bootclasspath_fragment's contents property.
411 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
412 addSource("foo", "bar"),
413 ).RunTest(t)
414
415 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
Jiakai Zhang49b1eb62021-11-26 18:09:27 +0000416 "etc/boot-image.prof",
Paul Duffince918b02021-06-07 14:33:47 +0100417 "etc/classpaths/bootclasspath.pb",
418 "javalib/arm/boot.art",
419 "javalib/arm/boot.oat",
420 "javalib/arm/boot.vdex",
421 "javalib/arm/boot-bar.art",
422 "javalib/arm/boot-bar.oat",
423 "javalib/arm/boot-bar.vdex",
424 "javalib/arm64/boot.art",
425 "javalib/arm64/boot.oat",
426 "javalib/arm64/boot.vdex",
427 "javalib/arm64/boot-bar.art",
428 "javalib/arm64/boot-bar.oat",
429 "javalib/arm64/boot-bar.vdex",
430 "javalib/bar.jar",
431 "javalib/foo.jar",
432 })
433
434 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
435 `bar`,
436 `com.android.art.key`,
437 `mybootclasspathfragment`,
438 })
439
440 // Make sure that the source bootclasspath_fragment copies its dex files to the predefined
441 // locations for the art image.
442 module := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
443 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
444 })
445
Jiakai Zhang7d3c9e02021-12-13 17:19:05 +0000446 t.Run("boot image disable generate profile", func(t *testing.T) {
447 result := android.GroupFixturePreparers(
448 commonPreparer,
449
450 // Configure some libraries in the art bootclasspath_fragment that match the source
451 // bootclasspath_fragment's contents property.
452 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
453 addSource("foo", "bar"),
454 dexpreopt.FixtureDisableGenerateProfile(true),
455 ).RunTest(t)
456
457 files := getFiles(t, result.TestContext, "com.android.art", "android_common_com.android.art_image")
458 for _, file := range files {
459 matched, _ := path.Match("etc/boot-image.prof", file.path)
460 android.AssertBoolEquals(t, "\"etc/boot-image.prof\" should not be in the APEX", matched, false)
461 }
462 })
463
Paul Duffince918b02021-06-07 14:33:47 +0100464 t.Run("boot image files with preferred prebuilt", func(t *testing.T) {
Paul Duffinba6afd02019-11-19 19:44:10 +0000465 result := android.GroupFixturePreparers(
466 commonPreparer,
467
468 // Configure some libraries in the art bootclasspath_fragment that match the source
469 // bootclasspath_fragment's contents property.
470 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
471 addSource("foo", "bar"),
472
473 // Make sure that a preferred prebuilt with consistent contents doesn't affect the apex.
474 addPrebuilt(true, "foo", "bar"),
475 ).RunTest(t)
476
477 ensureExactContents(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
Jiakai Zhang49b1eb62021-11-26 18:09:27 +0000478 "etc/boot-image.prof",
satayev227e7452021-05-20 21:35:06 +0100479 "etc/classpaths/bootclasspath.pb",
Paul Duffinba6afd02019-11-19 19:44:10 +0000480 "javalib/arm/boot.art",
481 "javalib/arm/boot.oat",
482 "javalib/arm/boot.vdex",
483 "javalib/arm/boot-bar.art",
484 "javalib/arm/boot-bar.oat",
485 "javalib/arm/boot-bar.vdex",
486 "javalib/arm64/boot.art",
487 "javalib/arm64/boot.oat",
488 "javalib/arm64/boot.vdex",
489 "javalib/arm64/boot-bar.art",
490 "javalib/arm64/boot-bar.oat",
491 "javalib/arm64/boot-bar.vdex",
492 "javalib/bar.jar",
493 "javalib/foo.jar",
494 })
495
496 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art_image", []string{
497 `bar`,
498 `com.android.art.key`,
499 `mybootclasspathfragment`,
Paul Duffince918b02021-06-07 14:33:47 +0100500 `prebuilt_com.android.art`,
Paul Duffinba6afd02019-11-19 19:44:10 +0000501 })
Paul Duffince918b02021-06-07 14:33:47 +0100502
503 // Make sure that the prebuilt bootclasspath_fragment copies its dex files to the predefined
504 // locations for the art image.
505 module := result.ModuleForTests("prebuilt_mybootclasspathfragment", "android_common_com.android.art")
506 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
Paul Duffina1d60252021-01-21 18:13:43 +0000507 })
Paul Duffin396229f2021-03-18 18:30:31 +0000508
Paul Duffinba6afd02019-11-19 19:44:10 +0000509 t.Run("source 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 source
514 // bootclasspath_fragment module's contents property.
515 java.FixtureConfigureBootJars("com.android.art:foo"),
516 addSource("foo", "bar"),
517 ).
518 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
519 RunTest(t)
520 })
521
522 t.Run("prebuilt with inconsistency between config and contents", func(t *testing.T) {
523 android.GroupFixturePreparers(
524 commonPreparer,
525
526 // Create an inconsistency between the ArtApexJars configuration and the art
527 // prebuilt_bootclasspath_fragment module's contents property.
528 java.FixtureConfigureBootJars("com.android.art:foo"),
529 addPrebuilt(false, "foo", "bar"),
530 ).
531 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
532 RunTest(t)
533 })
534
535 t.Run("preferred prebuilt with inconsistency between config and contents", func(t *testing.T) {
536 android.GroupFixturePreparers(
537 commonPreparer,
538
539 // Create an inconsistency between the ArtApexJars configuration and the art
540 // prebuilt_bootclasspath_fragment module's contents property.
541 java.FixtureConfigureBootJars("com.android.art:foo"),
542 addPrebuilt(true, "foo", "bar"),
543
544 // Source contents property is consistent with the config.
545 addSource("foo"),
546 ).
547 ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QArtApexJars configuration specifies []string{"foo"}, contents property specifies []string{"foo", "bar"}\E`)).
548 RunTest(t)
549 })
550
551 t.Run("source preferred and prebuilt with inconsistency between config and contents", func(t *testing.T) {
552 android.GroupFixturePreparers(
553 commonPreparer,
554
555 // Create an inconsistency between the ArtApexJars configuration and the art
556 // prebuilt_bootclasspath_fragment module's contents property.
557 java.FixtureConfigureBootJars("com.android.art:foo"),
558 addPrebuilt(false, "foo", "bar"),
559
560 // Source contents property is consistent with the config.
561 addSource("foo"),
562
563 // This should pass because while the prebuilt is inconsistent with the configuration it is
564 // not actually used.
565 ).RunTest(t)
Paul Duffin396229f2021-03-18 18:30:31 +0000566 })
Paul Duffina1d60252021-01-21 18:13:43 +0000567}
568
Paul Duffin94f19632021-04-20 12:40:07 +0100569func TestBootclasspathFragmentInPrebuiltArtApex(t *testing.T) {
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100570 preparers := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100571 prepareForTestWithBootclasspathFragment,
Paul Duffin9ea71c02021-03-23 22:53:07 +0000572 prepareForTestWithArtApex,
573
574 android.FixtureMergeMockFs(android.MockFS{
575 "com.android.art-arm64.apex": nil,
576 "com.android.art-arm.apex": nil,
577 }),
578
Paul Duffin7771eba2021-04-23 14:25:28 +0100579 // Configure some libraries in the art bootclasspath_fragment.
Paul Duffin60264a02021-04-12 20:02:36 +0100580 java.FixtureConfigureBootJars("com.android.art:foo", "com.android.art:bar"),
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100581 )
582
583 bp := `
Paul Duffin9ea71c02021-03-23 22:53:07 +0000584 prebuilt_apex {
585 name: "com.android.art",
586 arch: {
587 arm64: {
588 src: "com.android.art-arm64.apex",
589 },
590 arm: {
591 src: "com.android.art-arm.apex",
592 },
593 },
Paul Duffine5218812021-06-07 13:28:19 +0100594 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000595 }
596
597 java_import {
598 name: "foo",
599 jars: ["foo.jar"],
600 apex_available: [
601 "com.android.art",
602 ],
603 }
604
605 java_import {
606 name: "bar",
607 jars: ["bar.jar"],
608 apex_available: [
609 "com.android.art",
610 ],
611 }
612
Paul Duffin7771eba2021-04-23 14:25:28 +0100613 prebuilt_bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100614 name: "mybootclasspathfragment",
Paul Duffin9ea71c02021-03-23 22:53:07 +0000615 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100616 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
617 contents: ["foo", "bar"],
Paul Duffin9ea71c02021-03-23 22:53:07 +0000618 apex_available: [
619 "com.android.art",
620 ],
Paul Duffin54e41972021-07-19 13:23:40 +0100621 hidden_api: {
622 annotation_flags: "mybootclasspathfragment/annotation-flags.csv",
623 metadata: "mybootclasspathfragment/metadata.csv",
624 index: "mybootclasspathfragment/index.csv",
625 stub_flags: "mybootclasspathfragment/stub-flags.csv",
626 all_flags: "mybootclasspathfragment/all-flags.csv",
627 },
Paul Duffin9ea71c02021-03-23 22:53:07 +0000628 }
Paul Duffin9ea71c02021-03-23 22:53:07 +0000629
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100630 // A prebuilt apex with the same apex_name that shouldn't interfere when it isn't enabled.
631 prebuilt_apex {
632 name: "com.mycompany.android.art",
633 apex_name: "com.android.art",
634 %s
635 src: "com.mycompany.android.art.apex",
636 exported_bootclasspath_fragments: ["mybootclasspathfragment"],
637 }
638 `
639
640 t.Run("disabled alternative APEX", func(t *testing.T) {
641 result := preparers.RunTestWithBp(t, fmt.Sprintf(bp, "enabled: false,"))
642
643 java.CheckModuleDependencies(t, result.TestContext, "com.android.art", "android_common_com.android.art", []string{
644 `com.android.art.apex.selector`,
645 `prebuilt_mybootclasspathfragment`,
646 })
647
648 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_com.android.art", []string{
649 `com.android.art.deapexer`,
650 `dex2oatd`,
651 `prebuilt_bar`,
652 `prebuilt_foo`,
653 })
654
655 module := result.ModuleForTests("mybootclasspathfragment", "android_common_com.android.art")
656 checkCopiesToPredefinedLocationForArt(t, result.Config, module, "bar", "foo")
657
658 // Check that the right deapexer module was chosen for a boot image.
659 param := module.Output("out/soong/test_device/dex_artjars/android/apex/art_boot_images/javalib/arm64/boot.art")
660 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 +0000661 })
662
Martin Stjernholm43c44b02021-06-30 16:35:07 +0100663 t.Run("enabled alternative APEX", func(t *testing.T) {
664 preparers.ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
665 "Multiple installable prebuilt APEXes provide ambiguous deapexers: com.android.art and com.mycompany.android.art")).
666 RunTestWithBp(t, fmt.Sprintf(bp, ""))
Paul Duffin9ea71c02021-03-23 22:53:07 +0000667 })
Paul Duffince918b02021-06-07 14:33:47 +0100668}
669
670// checkCopiesToPredefinedLocationForArt checks that the supplied modules are copied to the
671// predefined locations of boot dex jars used as inputs for the ART boot image.
672func checkCopiesToPredefinedLocationForArt(t *testing.T, config android.Config, module android.TestingModule, modules ...string) {
673 t.Helper()
674 bootJarLocations := []string{}
675 for _, output := range module.AllOutputs() {
676 output = android.StringRelativeToTop(config, output)
677 if strings.HasPrefix(output, "out/soong/test_device/dex_artjars_input/") {
678 bootJarLocations = append(bootJarLocations, output)
679 }
680 }
681
682 sort.Strings(bootJarLocations)
683 expected := []string{}
684 for _, m := range modules {
685 expected = append(expected, fmt.Sprintf("out/soong/test_device/dex_artjars_input/%s.jar", m))
686 }
687 sort.Strings(expected)
688
689 android.AssertArrayString(t, "copies to predefined locations for art", expected, bootJarLocations)
Paul Duffin9ea71c02021-03-23 22:53:07 +0000690}
691
Paul Duffin94f19632021-04-20 12:40:07 +0100692func TestBootclasspathFragmentContentsNoName(t *testing.T) {
Paul Duffin82886d62021-03-24 01:34:57 +0000693 result := android.GroupFixturePreparers(
Paul Duffin94f19632021-04-20 12:40:07 +0100694 prepareForTestWithBootclasspathFragment,
Paul Duffin82886d62021-03-24 01:34:57 +0000695 prepareForTestWithMyapex,
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100696 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +0100697 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100698 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
699 // is disabled.
700 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
701
702 java.PrepareForTestWithJavaSdkLibraryFiles,
703 java.FixtureWithLastReleaseApis("foo"),
Paul Duffin82886d62021-03-24 01:34:57 +0000704 ).RunTestWithBp(t, `
705 apex {
706 name: "myapex",
707 key: "myapex.key",
Paul Duffin94f19632021-04-20 12:40:07 +0100708 bootclasspath_fragments: [
709 "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000710 ],
711 updatable: false,
712 }
713
714 apex_key {
715 name: "myapex.key",
716 public_key: "testkey.avbpubkey",
717 private_key: "testkey.pem",
718 }
719
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100720 java_sdk_library {
Paul Duffin82886d62021-03-24 01:34:57 +0000721 name: "foo",
722 srcs: ["b.java"],
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100723 shared_library: false,
724 public: {enabled: true},
Paul Duffin82886d62021-03-24 01:34:57 +0000725 apex_available: [
726 "myapex",
727 ],
728 }
729
730 java_library {
731 name: "bar",
732 srcs: ["b.java"],
733 installable: true,
734 apex_available: [
735 "myapex",
736 ],
737 }
738
Paul Duffin7771eba2021-04-23 14:25:28 +0100739 bootclasspath_fragment {
Paul Duffin94f19632021-04-20 12:40:07 +0100740 name: "mybootclasspathfragment",
Paul Duffin82886d62021-03-24 01:34:57 +0000741 contents: [
742 "foo",
743 "bar",
744 ],
745 apex_available: [
746 "myapex",
747 ],
748 }
749 `)
750
Paul Duffin4d101b62021-03-24 15:42:20 +0000751 ensureExactContents(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
752 // This does not include art, oat or vdex files as they are only included for the art boot
753 // image.
satayev227e7452021-05-20 21:35:06 +0100754 "etc/classpaths/bootclasspath.pb",
Paul Duffin4d101b62021-03-24 15:42:20 +0000755 "javalib/bar.jar",
756 "javalib/foo.jar",
757 })
Paul Duffin82886d62021-03-24 01:34:57 +0000758
759 java.CheckModuleDependencies(t, result.TestContext, "myapex", "android_common_myapex_image", []string{
760 `myapex.key`,
Paul Duffin94f19632021-04-20 12:40:07 +0100761 `mybootclasspathfragment`,
Paul Duffin82886d62021-03-24 01:34:57 +0000762 })
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100763
764 apex := result.ModuleForTests("myapex", "android_common_myapex_image")
765 apexRule := apex.Rule("apexRule")
766 copyCommands := apexRule.Args["copy_commands"]
767
768 // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
769 fragment := result.Module("mybootclasspathfragment", "android_common_apex10000")
770
771 info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo)
772
773 checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
774 module := result.Module(name, "android_common_apex10000")
Paul Duffin1a8010a2021-05-15 12:39:23 +0100775 dexJar, err := info.DexBootJarPathForContentModule(module)
776 if err != nil {
777 t.Error(err)
778 }
Paul Duffinf2fa0b52021-05-14 18:21:45 +0100779 android.AssertPathRelativeToTopEquals(t, name+" dex", expectedDexJar, dexJar)
780
781 expectedCopyCommand := fmt.Sprintf("&& cp -f %s out/soong/.intermediates/myapex/android_common_myapex_image/image.apex/javalib/%s.jar", expectedDexJar, name)
782 android.AssertStringDoesContain(t, name+" apex copy command", copyCommands, expectedCopyCommand)
783 }
784
Paul Duffin54c98f52021-05-15 08:54:30 +0100785 checkFragmentExportedDexJar("foo", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/foo.jar")
786 checkFragmentExportedDexJar("bar", "out/soong/.intermediates/mybootclasspathfragment/android_common_apex10000/hiddenapi-modular/encoded/bar.jar")
Paul Duffin82886d62021-03-24 01:34:57 +0000787}
788
Paul Duffin48b67412021-06-23 16:13:50 +0100789func getDexJarPath(result *android.TestResult, name string) string {
790 module := result.Module(name, "android_common")
Martin Stjernholm8be1e6d2021-09-15 03:34:04 +0100791 return module.(java.UsesLibraryDependency).DexJarBuildPath().Path().RelativeToTop().String()
Paul Duffin48b67412021-06-23 16:13:50 +0100792}
793
794// TestBootclasspathFragment_HiddenAPIList checks to make sure that the correct parameters are
795// passed to the hiddenapi list tool.
796func TestBootclasspathFragment_HiddenAPIList(t *testing.T) {
797 result := android.GroupFixturePreparers(
798 prepareForTestWithBootclasspathFragment,
799 prepareForTestWithArtApex,
800 prepareForTestWithMyapex,
801 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
802 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
satayevd604b212021-07-21 14:23:52 +0100803 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin48b67412021-06-23 16:13:50 +0100804 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
805 // is disabled.
806 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
807
808 java.PrepareForTestWithJavaSdkLibraryFiles,
809 java.FixtureWithLastReleaseApis("foo", "quuz"),
810 ).RunTestWithBp(t, `
811 apex {
812 name: "com.android.art",
813 key: "com.android.art.key",
814 bootclasspath_fragments: ["art-bootclasspath-fragment"],
815 updatable: false,
816 }
817
818 apex_key {
819 name: "com.android.art.key",
820 public_key: "com.android.art.avbpubkey",
821 private_key: "com.android.art.pem",
822 }
823
824 java_library {
825 name: "baz",
826 apex_available: [
827 "com.android.art",
828 ],
829 srcs: ["b.java"],
830 compile_dex: true,
831 }
832
833 java_sdk_library {
834 name: "quuz",
835 apex_available: [
836 "com.android.art",
837 ],
838 srcs: ["b.java"],
839 compile_dex: true,
840 public: {enabled: true},
841 system: {enabled: true},
842 test: {enabled: true},
843 module_lib: {enabled: true},
844 }
845
846 bootclasspath_fragment {
847 name: "art-bootclasspath-fragment",
848 image_name: "art",
849 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
850 contents: ["baz", "quuz"],
851 apex_available: [
852 "com.android.art",
853 ],
854 }
855
856 apex {
857 name: "myapex",
858 key: "myapex.key",
859 bootclasspath_fragments: [
860 "mybootclasspathfragment",
861 ],
862 updatable: false,
863 }
864
865 apex_key {
866 name: "myapex.key",
867 public_key: "testkey.avbpubkey",
868 private_key: "testkey.pem",
869 }
870
871 java_sdk_library {
872 name: "foo",
873 srcs: ["b.java"],
874 shared_library: false,
875 public: {enabled: true},
876 apex_available: [
877 "myapex",
878 ],
879 }
880
881 java_library {
882 name: "bar",
883 srcs: ["b.java"],
884 installable: true,
885 apex_available: [
886 "myapex",
887 ],
888 }
889
890 bootclasspath_fragment {
891 name: "mybootclasspathfragment",
892 contents: [
893 "foo",
894 "bar",
895 ],
896 apex_available: [
897 "myapex",
898 ],
899 fragments: [
900 {
901 apex: "com.android.art",
902 module: "art-bootclasspath-fragment",
903 },
904 ],
905 }
906 `)
907
908 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
909 "art-bootclasspath-fragment",
910 "bar",
911 "dex2oatd",
912 "foo",
913 })
914
915 fooStubs := getDexJarPath(result, "foo.stubs")
916 quuzPublicStubs := getDexJarPath(result, "quuz.stubs")
917 quuzSystemStubs := getDexJarPath(result, "quuz.stubs.system")
918 quuzTestStubs := getDexJarPath(result, "quuz.stubs.test")
Paul Duffinb51db2e2021-06-21 14:08:08 +0100919 quuzModuleLibStubs := getDexJarPath(result, "quuz.stubs.module_lib")
Paul Duffin48b67412021-06-23 16:13:50 +0100920
921 // Make sure that the fragment uses the quuz stub dex jars when generating the hidden API flags.
922 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
923
924 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
925 command := rule.RuleParams.Command
926 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
927
928 // Make sure that the quuz stubs are available for resolving references from the implementation
929 // boot dex jars provided by this module.
Paul Duffinb51db2e2021-06-21 14:08:08 +0100930 android.AssertStringDoesContain(t, "quuz widest", command, "--dependency-stub-dex="+quuzModuleLibStubs)
Paul Duffin48b67412021-06-23 16:13:50 +0100931
932 // Make sure that the quuz stubs are available for resolving references from the different API
933 // stubs provided by this module.
934 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+quuzPublicStubs+":"+fooStubs)
935 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+quuzSystemStubs+":"+fooStubs)
936 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+quuzTestStubs+":"+fooStubs)
937}
938
Paul Duffin5cca7c42021-05-26 10:16:01 +0100939// TestBootclasspathFragment_AndroidNonUpdatable checks to make sure that setting
940// additional_stubs: ["android-non-updatable"] causes the source android-non-updatable modules to be
941// added to the hiddenapi list tool.
942func TestBootclasspathFragment_AndroidNonUpdatable(t *testing.T) {
943 result := android.GroupFixturePreparers(
944 prepareForTestWithBootclasspathFragment,
945 prepareForTestWithArtApex,
946 prepareForTestWithMyapex,
947 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +0100948 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
949 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin5cca7c42021-05-26 10:16:01 +0100950 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
951 // is disabled.
952 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
953
954 java.PrepareForTestWithJavaSdkLibraryFiles,
955 java.FixtureWithLastReleaseApis("foo", "android-non-updatable"),
956 ).RunTestWithBp(t, `
957 java_sdk_library {
958 name: "android-non-updatable",
959 srcs: ["b.java"],
960 compile_dex: true,
961 public: {
962 enabled: true,
963 },
964 system: {
965 enabled: true,
966 },
967 test: {
968 enabled: true,
969 },
970 module_lib: {
971 enabled: true,
972 },
973 }
974
975 apex {
976 name: "com.android.art",
977 key: "com.android.art.key",
978 bootclasspath_fragments: ["art-bootclasspath-fragment"],
979 java_libs: [
980 "baz",
981 "quuz",
982 ],
983 updatable: false,
984 }
985
986 apex_key {
987 name: "com.android.art.key",
988 public_key: "com.android.art.avbpubkey",
989 private_key: "com.android.art.pem",
990 }
991
992 java_library {
993 name: "baz",
994 apex_available: [
995 "com.android.art",
996 ],
997 srcs: ["b.java"],
998 compile_dex: true,
999 }
1000
1001 java_library {
1002 name: "quuz",
1003 apex_available: [
1004 "com.android.art",
1005 ],
1006 srcs: ["b.java"],
1007 compile_dex: true,
1008 }
1009
1010 bootclasspath_fragment {
1011 name: "art-bootclasspath-fragment",
1012 image_name: "art",
1013 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
1014 contents: ["baz", "quuz"],
1015 apex_available: [
1016 "com.android.art",
1017 ],
1018 }
1019
1020 apex {
1021 name: "myapex",
1022 key: "myapex.key",
1023 bootclasspath_fragments: [
1024 "mybootclasspathfragment",
1025 ],
1026 updatable: false,
1027 }
1028
1029 apex_key {
1030 name: "myapex.key",
1031 public_key: "testkey.avbpubkey",
1032 private_key: "testkey.pem",
1033 }
1034
1035 java_sdk_library {
1036 name: "foo",
1037 srcs: ["b.java"],
1038 shared_library: false,
1039 public: {enabled: true},
1040 apex_available: [
1041 "myapex",
1042 ],
1043 }
1044
1045 java_library {
1046 name: "bar",
1047 srcs: ["b.java"],
1048 installable: true,
1049 apex_available: [
1050 "myapex",
1051 ],
1052 }
1053
1054 bootclasspath_fragment {
1055 name: "mybootclasspathfragment",
1056 contents: [
1057 "foo",
1058 "bar",
1059 ],
1060 apex_available: [
1061 "myapex",
1062 ],
1063 additional_stubs: ["android-non-updatable"],
1064 fragments: [
1065 {
1066 apex: "com.android.art",
1067 module: "art-bootclasspath-fragment",
1068 },
1069 ],
1070 }
1071 `)
1072
1073 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1074 "android-non-updatable.stubs",
1075 "android-non-updatable.stubs.module_lib",
1076 "android-non-updatable.stubs.system",
1077 "android-non-updatable.stubs.test",
1078 "art-bootclasspath-fragment",
1079 "bar",
1080 "dex2oatd",
1081 "foo",
1082 })
1083
1084 nonUpdatablePublicStubs := getDexJarPath(result, "android-non-updatable.stubs")
1085 nonUpdatableSystemStubs := getDexJarPath(result, "android-non-updatable.stubs.system")
1086 nonUpdatableTestStubs := getDexJarPath(result, "android-non-updatable.stubs.test")
1087 nonUpdatableModuleLibStubs := getDexJarPath(result, "android-non-updatable.stubs.module_lib")
1088
1089 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1090 // API flags.
1091 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1092
1093 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1094 command := rule.RuleParams.Command
1095 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1096
1097 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1098 // the implementation boot dex jars provided by this module.
1099 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1100
1101 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1102 // the different API stubs provided by this module.
1103 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1104 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1105 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1106}
1107
1108// TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks checks to make sure that
1109// setting additional_stubs: ["android-non-updatable"] causes the prebuilt android-non-updatable
1110// modules to be added to the hiddenapi list tool.
1111func TestBootclasspathFragment_AndroidNonUpdatable_AlwaysUsePrebuiltSdks(t *testing.T) {
1112 result := android.GroupFixturePreparers(
1113 prepareForTestWithBootclasspathFragment,
1114 java.PrepareForTestWithJavaDefaultModules,
1115 prepareForTestWithArtApex,
1116 prepareForTestWithMyapex,
1117 // Configure bootclasspath jars to ensure that hidden API encoding is performed on them.
satayevabcd5972021-08-06 17:49:46 +01001118 java.FixtureConfigureBootJars("com.android.art:baz", "com.android.art:quuz"),
1119 java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
Paul Duffin5cca7c42021-05-26 10:16:01 +01001120 // Make sure that the frameworks/base/Android.bp file exists as otherwise hidden API encoding
1121 // is disabled.
1122 android.FixtureAddTextFile("frameworks/base/Android.bp", ""),
1123
1124 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1125 variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
1126 }),
1127
1128 java.PrepareForTestWithJavaSdkLibraryFiles,
1129 java.FixtureWithPrebuiltApis(map[string][]string{
1130 "current": {"android-non-updatable"},
1131 "30": {"foo"},
1132 }),
1133 ).RunTestWithBp(t, `
1134 apex {
1135 name: "com.android.art",
1136 key: "com.android.art.key",
1137 bootclasspath_fragments: ["art-bootclasspath-fragment"],
1138 java_libs: [
1139 "baz",
1140 "quuz",
1141 ],
1142 updatable: false,
1143 }
1144
1145 apex_key {
1146 name: "com.android.art.key",
1147 public_key: "com.android.art.avbpubkey",
1148 private_key: "com.android.art.pem",
1149 }
1150
1151 java_library {
1152 name: "baz",
1153 apex_available: [
1154 "com.android.art",
1155 ],
1156 srcs: ["b.java"],
1157 compile_dex: true,
1158 }
1159
1160 java_library {
1161 name: "quuz",
1162 apex_available: [
1163 "com.android.art",
1164 ],
1165 srcs: ["b.java"],
1166 compile_dex: true,
1167 }
1168
1169 bootclasspath_fragment {
1170 name: "art-bootclasspath-fragment",
1171 image_name: "art",
1172 // Must match the "com.android.art:" entries passed to FixtureConfigureBootJars above.
1173 contents: ["baz", "quuz"],
1174 apex_available: [
1175 "com.android.art",
1176 ],
1177 }
1178
1179 apex {
1180 name: "myapex",
1181 key: "myapex.key",
1182 bootclasspath_fragments: [
1183 "mybootclasspathfragment",
1184 ],
1185 updatable: false,
1186 }
1187
1188 apex_key {
1189 name: "myapex.key",
1190 public_key: "testkey.avbpubkey",
1191 private_key: "testkey.pem",
1192 }
1193
1194 java_sdk_library {
1195 name: "foo",
1196 srcs: ["b.java"],
1197 shared_library: false,
1198 public: {enabled: true},
1199 apex_available: [
1200 "myapex",
1201 ],
1202 }
1203
1204 java_library {
1205 name: "bar",
1206 srcs: ["b.java"],
1207 installable: true,
1208 apex_available: [
1209 "myapex",
1210 ],
1211 }
1212
1213 bootclasspath_fragment {
1214 name: "mybootclasspathfragment",
1215 contents: [
1216 "foo",
1217 "bar",
1218 ],
1219 apex_available: [
1220 "myapex",
1221 ],
1222 additional_stubs: ["android-non-updatable"],
1223 fragments: [
1224 {
1225 apex: "com.android.art",
1226 module: "art-bootclasspath-fragment",
1227 },
1228 ],
1229 }
1230 `)
1231
1232 java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_apex10000", []string{
1233 "art-bootclasspath-fragment",
1234 "bar",
1235 "dex2oatd",
1236 "foo",
1237 "prebuilt_sdk_module-lib_current_android-non-updatable",
1238 "prebuilt_sdk_public_current_android-non-updatable",
1239 "prebuilt_sdk_system_current_android-non-updatable",
1240 "prebuilt_sdk_test_current_android-non-updatable",
1241 })
1242
1243 nonUpdatablePublicStubs := getDexJarPath(result, "sdk_public_current_android-non-updatable")
1244 nonUpdatableSystemStubs := getDexJarPath(result, "sdk_system_current_android-non-updatable")
1245 nonUpdatableTestStubs := getDexJarPath(result, "sdk_test_current_android-non-updatable")
1246 nonUpdatableModuleLibStubs := getDexJarPath(result, "sdk_module-lib_current_android-non-updatable")
1247
1248 // Make sure that the fragment uses the android-non-updatable modules when generating the hidden
1249 // API flags.
1250 fragment := result.ModuleForTests("mybootclasspathfragment", "android_common_apex10000")
1251
1252 rule := fragment.Rule("modularHiddenAPIStubFlagsFile")
1253 command := rule.RuleParams.Command
1254 android.AssertStringDoesContain(t, "check correct rule", command, "hiddenapi list")
1255
1256 // Make sure that the module_lib non-updatable stubs are available for resolving references from
1257 // the implementation boot dex jars provided by this module.
1258 android.AssertStringDoesContain(t, "android-non-updatable widest", command, "--dependency-stub-dex="+nonUpdatableModuleLibStubs)
1259
1260 // Make sure that the appropriate non-updatable stubs are available for resolving references from
1261 // the different API stubs provided by this module.
1262 android.AssertStringDoesContain(t, "public", command, "--public-stub-classpath="+nonUpdatablePublicStubs)
1263 android.AssertStringDoesContain(t, "system", command, "--system-stub-classpath="+nonUpdatableSystemStubs)
1264 android.AssertStringDoesContain(t, "test", command, "--test-stub-classpath="+nonUpdatableTestStubs)
1265}
1266
Paul Duffina1d60252021-01-21 18:13:43 +00001267// TODO(b/177892522) - add test for host apex.