blob: 1f28ed39a40486a0ae0693cf9ffd05fc78e1397f [file] [log] [blame]
Paul Duffinf7f65da2021-03-10 15:00:46 +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 sdk
16
Paul Duffin4a1d4512021-03-18 10:12:26 +000017import (
Paul Duffin7c475152021-06-09 16:17:58 +010018 "fmt"
19 "path/filepath"
Paul Duffin4a1d4512021-03-18 10:12:26 +000020 "testing"
21
22 "android/soong/android"
Paul Duffina57835e2021-04-19 13:23:06 +010023 "android/soong/java"
Paul Duffin4a1d4512021-03-18 10:12:26 +000024)
Paul Duffinf7f65da2021-03-10 15:00:46 +000025
Paul Duffin7c475152021-06-09 16:17:58 +010026// fixtureAddPlatformBootclasspathForBootclasspathFragment adds a platform_bootclasspath module that
27// references the bootclasspath fragment.
28func fixtureAddPlatformBootclasspathForBootclasspathFragment(apex, fragment string) android.FixturePreparer {
29 return android.GroupFixturePreparers(
30 // Add a platform_bootclasspath module.
31 android.FixtureAddTextFile("frameworks/base/boot/Android.bp", fmt.Sprintf(`
32 platform_bootclasspath {
33 name: "platform-bootclasspath",
34 fragments: [
35 {
36 apex: "%s",
37 module: "%s",
38 },
39 ],
40 }
41 `, apex, fragment)),
42 android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil),
Paul Duffinc8ead412021-06-07 19:28:15 +010043 android.FixtureAddFile("build/soong/scripts/check_boot_jars/package_allowed_list.txt", nil),
Paul Duffin7c475152021-06-09 16:17:58 +010044 )
45}
46
47// fixtureAddPrebuiltApexForBootclasspathFragment adds a prebuilt_apex that exports the fragment.
48func fixtureAddPrebuiltApexForBootclasspathFragment(apex, fragment string) android.FixturePreparer {
49 apexFile := fmt.Sprintf("%s.apex", apex)
50 dir := "prebuilts/apex"
51 return android.GroupFixturePreparers(
52 // A preparer to add a prebuilt apex to the test fixture.
53 android.FixtureAddTextFile(filepath.Join(dir, "Android.bp"), fmt.Sprintf(`
54 prebuilt_apex {
55 name: "%s",
56 src: "%s",
57 exported_bootclasspath_fragments: [
58 "%s",
59 ],
60 }
61 `, apex, apexFile, fragment)),
62 android.FixtureAddFile(filepath.Join(dir, apexFile), nil),
63 )
64}
65
Paul Duffina57835e2021-04-19 13:23:06 +010066func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
67 result := android.GroupFixturePreparers(
68 prepareForSdkTestWithJava,
Paul Duffin023dba02021-04-22 01:45:29 +010069 java.PrepareForTestWithJavaDefaultModules,
Paul Duffina57835e2021-04-19 13:23:06 +010070 prepareForSdkTestWithApex,
71
72 // Some additional files needed for the art apex.
73 android.FixtureMergeMockFs(android.MockFS{
74 "com.android.art.avbpubkey": nil,
75 "com.android.art.pem": nil,
76 "system/sepolicy/apex/com.android.art-file_contexts": nil,
77 }),
Paul Duffin023dba02021-04-22 01:45:29 +010078
Paul Duffin7c475152021-06-09 16:17:58 +010079 // Add a platform_bootclasspath that depends on the fragment.
80 fixtureAddPlatformBootclasspathForBootclasspathFragment("com.android.art", "mybootclasspathfragment"),
Paul Duffin023dba02021-04-22 01:45:29 +010081
Paul Duffina57835e2021-04-19 13:23:06 +010082 java.FixtureConfigureBootJars("com.android.art:mybootlib"),
83 android.FixtureWithRootAndroidBp(`
84 sdk {
85 name: "mysdk",
86 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffina57835e2021-04-19 13:23:06 +010087 }
88
89 apex {
90 name: "com.android.art",
91 key: "com.android.art.key",
92 bootclasspath_fragments: [
93 "mybootclasspathfragment",
94 ],
95 updatable: false,
96 }
97
98 bootclasspath_fragment {
99 name: "mybootclasspathfragment",
100 image_name: "art",
Paul Duffinf23bc472021-04-27 12:42:20 +0100101 contents: ["mybootlib"],
Paul Duffina57835e2021-04-19 13:23:06 +0100102 apex_available: ["com.android.art"],
103 }
104
105 apex_key {
106 name: "com.android.art.key",
107 public_key: "com.android.art.avbpubkey",
108 private_key: "com.android.art.pem",
109 }
110
111 java_library {
112 name: "mybootlib",
113 srcs: ["Test.java"],
114 system_modules: "none",
115 sdk_version: "none",
116 compile_dex: true,
117 apex_available: ["com.android.art"],
118 }
119 `),
120 ).RunTest(t)
121
Paul Duffin7c475152021-06-09 16:17:58 +0100122 // A preparer to update the test fixture used when processing an unpackage snapshot.
123 preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "mybootclasspathfragment")
Paul Duffin023dba02021-04-22 01:45:29 +0100124
Paul Duffina57835e2021-04-19 13:23:06 +0100125 CheckSnapshot(t, result, "mysdk", "",
126 checkUnversionedAndroidBpContents(`
127// This is auto-generated. DO NOT EDIT.
128
129prebuilt_bootclasspath_fragment {
130 name: "mybootclasspathfragment",
131 prefer: false,
132 visibility: ["//visibility:public"],
133 apex_available: ["com.android.art"],
134 image_name: "art",
Paul Duffin2dc665b2021-04-23 16:58:51 +0100135 contents: ["mybootlib"],
Paul Duffina57835e2021-04-19 13:23:06 +0100136}
137
138java_import {
139 name: "mybootlib",
140 prefer: false,
141 visibility: ["//visibility:public"],
142 apex_available: ["com.android.art"],
143 jars: ["java/mybootlib.jar"],
144}
145`),
146 checkVersionedAndroidBpContents(`
147// This is auto-generated. DO NOT EDIT.
148
149prebuilt_bootclasspath_fragment {
150 name: "mysdk_mybootclasspathfragment@current",
151 sdk_member_name: "mybootclasspathfragment",
152 visibility: ["//visibility:public"],
153 apex_available: ["com.android.art"],
154 image_name: "art",
Paul Duffin2dc665b2021-04-23 16:58:51 +0100155 contents: ["mysdk_mybootlib@current"],
Paul Duffina57835e2021-04-19 13:23:06 +0100156}
157
158java_import {
159 name: "mysdk_mybootlib@current",
160 sdk_member_name: "mybootlib",
161 visibility: ["//visibility:public"],
162 apex_available: ["com.android.art"],
163 jars: ["java/mybootlib.jar"],
164}
165
166sdk_snapshot {
167 name: "mysdk@current",
168 visibility: ["//visibility:public"],
169 bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
170 java_boot_libs: ["mysdk_mybootlib@current"],
171}
172`),
173 checkAllCopyRules(`
174.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
175`),
Paul Duffin7c475152021-06-09 16:17:58 +0100176 snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
Paul Duffinc8ead412021-06-07 19:28:15 +0100177
178 // Check the behavior of the snapshot without the source.
179 snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) {
180 // Make sure that the boot jars package check rule includes the dex jar retrieved from the prebuilt apex.
181 checkBootJarsPackageCheckRule(t, result, "out/soong/.intermediates/prebuilts/apex/com.android.art.deapexer/android_common/deapexer/javalib/mybootlib.jar")
182 }),
183
Paul Duffin7c475152021-06-09 16:17:58 +0100184 snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
185 snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
Paul Duffina57835e2021-04-19 13:23:06 +0100186 )
Paul Duffinc8ead412021-06-07 19:28:15 +0100187
188 // Make sure that the boot jars package check rule includes the dex jar created from the source.
189 checkBootJarsPackageCheckRule(t, result, "out/soong/.intermediates/mybootlib/android_common_apex10000/aligned/mybootlib.jar")
190}
191
192// checkBootJarsPackageCheckRule checks that the supplied module is an input to the boot jars
193// package check rule.
194func checkBootJarsPackageCheckRule(t *testing.T, result *android.TestResult, expectedModule string) {
195 platformBcp := result.ModuleForTests("platform-bootclasspath", "android_common")
196 bootJarsCheckRule := platformBcp.Rule("boot_jars_package_check")
197 command := bootJarsCheckRule.RuleParams.Command
198 expectedCommandArgs := " out/soong/host/linux-x86/bin/dexdump build/soong/scripts/check_boot_jars/package_allowed_list.txt " + expectedModule + " &&"
199 android.AssertStringDoesContain(t, "boot jars package check", command, expectedCommandArgs)
Paul Duffina57835e2021-04-19 13:23:06 +0100200}
201
202func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
Paul Duffin4a1d4512021-03-18 10:12:26 +0000203 result := android.GroupFixturePreparers(
204 prepareForSdkTestWithJava,
Paul Duffin895c7142021-04-25 13:40:15 +0100205 java.PrepareForTestWithJavaDefaultModules,
206 java.PrepareForTestWithJavaSdkLibraryFiles,
Paul Duffina10bd3c2021-05-12 13:46:54 +0100207 java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
Paul Duffin7c475152021-06-09 16:17:58 +0100208 java.FixtureConfigureUpdatableBootJars("myapex:mybootlib", "myapex:myothersdklibrary"),
209 prepareForSdkTestWithApex,
210
211 // Add a platform_bootclasspath that depends on the fragment.
212 fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
213
Paul Duffin4a1d4512021-03-18 10:12:26 +0000214 android.FixtureWithRootAndroidBp(`
215 sdk {
216 name: "mysdk",
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100217 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100218 java_sdk_libs: [
219 // This is not strictly needed as it should be automatically added to the sdk_snapshot as
220 // a java_sdk_libs module because it is used in the mybootclasspathfragment's
221 // api.stub_libs property. However, it is specified here to ensure that duplicates are
222 // correctly deduped.
223 "mysdklibrary",
224 ],
Paul Duffin4a1d4512021-03-18 10:12:26 +0000225 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000226
Paul Duffin7c475152021-06-09 16:17:58 +0100227 apex {
228 name: "myapex",
229 key: "myapex.key",
230 min_sdk_version: "2",
231 bootclasspath_fragments: ["mybootclasspathfragment"],
232 }
233
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100234 bootclasspath_fragment {
235 name: "mybootclasspathfragment",
Paul Duffin7c475152021-06-09 16:17:58 +0100236 apex_available: ["myapex"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100237 contents: [
238 // This should be automatically added to the sdk_snapshot as a java_boot_libs module.
239 "mybootlib",
240 // This should be automatically added to the sdk_snapshot as a java_sdk_libs module.
241 "myothersdklibrary",
242 ],
Paul Duffin895c7142021-04-25 13:40:15 +0100243 api: {
244 stub_libs: ["mysdklibrary"],
245 },
246 core_platform_api: {
Paul Duffina10bd3c2021-05-12 13:46:54 +0100247 // This should be automatically added to the sdk_snapshot as a java_sdk_libs module.
Paul Duffin895c7142021-04-25 13:40:15 +0100248 stub_libs: ["mycoreplatform"],
249 },
Paul Duffina57835e2021-04-19 13:23:06 +0100250 }
251
252 java_library {
253 name: "mybootlib",
Paul Duffin7c475152021-06-09 16:17:58 +0100254 apex_available: ["myapex"],
Paul Duffina57835e2021-04-19 13:23:06 +0100255 srcs: ["Test.java"],
256 system_modules: "none",
257 sdk_version: "none",
Paul Duffin7c475152021-06-09 16:17:58 +0100258 min_sdk_version: "2",
Paul Duffina57835e2021-04-19 13:23:06 +0100259 compile_dex: true,
Paul Duffin7c475152021-06-09 16:17:58 +0100260 permitted_packages: ["mybootlib"],
Paul Duffin4a1d4512021-03-18 10:12:26 +0000261 }
Paul Duffin895c7142021-04-25 13:40:15 +0100262
263 java_sdk_library {
264 name: "mysdklibrary",
Paul Duffin7c475152021-06-09 16:17:58 +0100265 apex_available: ["myapex"],
Paul Duffin895c7142021-04-25 13:40:15 +0100266 srcs: ["Test.java"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100267 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100268 public: {enabled: true},
Paul Duffin7c475152021-06-09 16:17:58 +0100269 min_sdk_version: "2",
Paul Duffin895c7142021-04-25 13:40:15 +0100270 }
271
272 java_sdk_library {
Paul Duffina10bd3c2021-05-12 13:46:54 +0100273 name: "myothersdklibrary",
Paul Duffin7c475152021-06-09 16:17:58 +0100274 apex_available: ["myapex"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100275 srcs: ["Test.java"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100276 shared_library: false,
Paul Duffina10bd3c2021-05-12 13:46:54 +0100277 public: {enabled: true},
Paul Duffin7c475152021-06-09 16:17:58 +0100278 min_sdk_version: "2",
279 permitted_packages: ["myothersdklibrary"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100280 }
281
282 java_sdk_library {
Paul Duffin895c7142021-04-25 13:40:15 +0100283 name: "mycoreplatform",
Paul Duffin7c475152021-06-09 16:17:58 +0100284 apex_available: ["myapex"],
Paul Duffin895c7142021-04-25 13:40:15 +0100285 srcs: ["Test.java"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100286 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100287 public: {enabled: true},
Paul Duffin7c475152021-06-09 16:17:58 +0100288 min_sdk_version: "2",
Paul Duffin895c7142021-04-25 13:40:15 +0100289 }
Paul Duffin4a1d4512021-03-18 10:12:26 +0000290 `),
291 ).RunTest(t)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000292
Paul Duffin7c475152021-06-09 16:17:58 +0100293 // A preparer to update the test fixture used when processing an unpackage snapshot.
294 preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")
295
Paul Duffin36474d32021-03-12 12:19:43 +0000296 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinf7f65da2021-03-10 15:00:46 +0000297 checkUnversionedAndroidBpContents(`
298// This is auto-generated. DO NOT EDIT.
299
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100300prebuilt_bootclasspath_fragment {
301 name: "mybootclasspathfragment",
Paul Duffinf7f65da2021-03-10 15:00:46 +0000302 prefer: false,
303 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100304 apex_available: ["myapex"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100305 contents: [
306 "mybootlib",
307 "myothersdklibrary",
308 ],
Paul Duffin895c7142021-04-25 13:40:15 +0100309 api: {
310 stub_libs: ["mysdklibrary"],
311 },
312 core_platform_api: {
313 stub_libs: ["mycoreplatform"],
314 },
Paul Duffin2fef1362021-04-15 13:32:00 +0100315 hidden_api: {
316 stub_flags: "hiddenapi/stub-flags.csv",
317 annotation_flags: "hiddenapi/annotation-flags.csv",
318 metadata: "hiddenapi/metadata.csv",
319 index: "hiddenapi/index.csv",
320 all_flags: "hiddenapi/all-flags.csv",
321 },
Paul Duffina57835e2021-04-19 13:23:06 +0100322}
323
324java_import {
325 name: "mybootlib",
326 prefer: false,
327 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100328 apex_available: ["myapex"],
Paul Duffina57835e2021-04-19 13:23:06 +0100329 jars: ["java/mybootlib.jar"],
Paul Duffinf7f65da2021-03-10 15:00:46 +0000330}
Paul Duffin895c7142021-04-25 13:40:15 +0100331
332java_sdk_library_import {
Paul Duffina10bd3c2021-05-12 13:46:54 +0100333 name: "myothersdklibrary",
334 prefer: false,
335 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100336 apex_available: ["myapex"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100337 shared_library: false,
Paul Duffina10bd3c2021-05-12 13:46:54 +0100338 public: {
339 jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
340 stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
341 current_api: "sdk_library/public/myothersdklibrary.txt",
342 removed_api: "sdk_library/public/myothersdklibrary-removed.txt",
343 sdk_version: "current",
344 },
345}
346
347java_sdk_library_import {
Paul Duffin895c7142021-04-25 13:40:15 +0100348 name: "mysdklibrary",
349 prefer: false,
350 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100351 apex_available: ["myapex"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100352 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100353 public: {
354 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
355 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
356 current_api: "sdk_library/public/mysdklibrary.txt",
357 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
358 sdk_version: "current",
359 },
360}
361
362java_sdk_library_import {
363 name: "mycoreplatform",
364 prefer: false,
365 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100366 apex_available: ["myapex"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100367 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100368 public: {
369 jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
370 stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
371 current_api: "sdk_library/public/mycoreplatform.txt",
372 removed_api: "sdk_library/public/mycoreplatform-removed.txt",
373 sdk_version: "current",
374 },
375}
Paul Duffina10bd3c2021-05-12 13:46:54 +0100376 `),
Paul Duffinf7f65da2021-03-10 15:00:46 +0000377 checkVersionedAndroidBpContents(`
378// This is auto-generated. DO NOT EDIT.
379
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100380prebuilt_bootclasspath_fragment {
381 name: "mysdk_mybootclasspathfragment@current",
382 sdk_member_name: "mybootclasspathfragment",
Paul Duffinf7f65da2021-03-10 15:00:46 +0000383 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100384 apex_available: ["myapex"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100385 contents: [
386 "mysdk_mybootlib@current",
387 "mysdk_myothersdklibrary@current",
388 ],
Paul Duffin895c7142021-04-25 13:40:15 +0100389 api: {
390 stub_libs: ["mysdk_mysdklibrary@current"],
391 },
392 core_platform_api: {
393 stub_libs: ["mysdk_mycoreplatform@current"],
394 },
Paul Duffin2fef1362021-04-15 13:32:00 +0100395 hidden_api: {
396 stub_flags: "hiddenapi/stub-flags.csv",
397 annotation_flags: "hiddenapi/annotation-flags.csv",
398 metadata: "hiddenapi/metadata.csv",
399 index: "hiddenapi/index.csv",
400 all_flags: "hiddenapi/all-flags.csv",
401 },
Paul Duffina57835e2021-04-19 13:23:06 +0100402}
403
404java_import {
405 name: "mysdk_mybootlib@current",
406 sdk_member_name: "mybootlib",
407 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100408 apex_available: ["myapex"],
Paul Duffina57835e2021-04-19 13:23:06 +0100409 jars: ["java/mybootlib.jar"],
Paul Duffinf7f65da2021-03-10 15:00:46 +0000410}
411
Paul Duffin895c7142021-04-25 13:40:15 +0100412java_sdk_library_import {
Paul Duffina10bd3c2021-05-12 13:46:54 +0100413 name: "mysdk_myothersdklibrary@current",
414 sdk_member_name: "myothersdklibrary",
415 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100416 apex_available: ["myapex"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100417 shared_library: false,
Paul Duffina10bd3c2021-05-12 13:46:54 +0100418 public: {
419 jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
420 stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
421 current_api: "sdk_library/public/myothersdklibrary.txt",
422 removed_api: "sdk_library/public/myothersdklibrary-removed.txt",
423 sdk_version: "current",
424 },
425}
426
427java_sdk_library_import {
Paul Duffin895c7142021-04-25 13:40:15 +0100428 name: "mysdk_mysdklibrary@current",
429 sdk_member_name: "mysdklibrary",
430 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100431 apex_available: ["myapex"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100432 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100433 public: {
434 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
435 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
436 current_api: "sdk_library/public/mysdklibrary.txt",
437 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
438 sdk_version: "current",
439 },
440}
441
442java_sdk_library_import {
443 name: "mysdk_mycoreplatform@current",
444 sdk_member_name: "mycoreplatform",
445 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100446 apex_available: ["myapex"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100447 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100448 public: {
449 jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
450 stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
451 current_api: "sdk_library/public/mycoreplatform.txt",
452 removed_api: "sdk_library/public/mycoreplatform-removed.txt",
453 sdk_version: "current",
454 },
455}
456
Paul Duffinf7f65da2021-03-10 15:00:46 +0000457sdk_snapshot {
458 name: "mysdk@current",
459 visibility: ["//visibility:public"],
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100460 bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
Paul Duffina57835e2021-04-19 13:23:06 +0100461 java_boot_libs: ["mysdk_mybootlib@current"],
Paul Duffin895c7142021-04-25 13:40:15 +0100462 java_sdk_libs: [
Paul Duffina10bd3c2021-05-12 13:46:54 +0100463 "mysdk_myothersdklibrary@current",
Paul Duffin895c7142021-04-25 13:40:15 +0100464 "mysdk_mysdklibrary@current",
465 "mysdk_mycoreplatform@current",
466 ],
Paul Duffinf7f65da2021-03-10 15:00:46 +0000467}
Paul Duffina10bd3c2021-05-12 13:46:54 +0100468 `),
Paul Duffina57835e2021-04-19 13:23:06 +0100469 checkAllCopyRules(`
Paul Duffin2fef1362021-04-15 13:32:00 +0100470.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv
471.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
472.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
473.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
474.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv
Paul Duffina57835e2021-04-19 13:23:06 +0100475.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
Paul Duffina10bd3c2021-05-12 13:46:54 +0100476.intermediates/myothersdklibrary.stubs/android_common/javac/myothersdklibrary.stubs.jar -> sdk_library/public/myothersdklibrary-stubs.jar
477.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt
478.intermediates/myothersdklibrary.stubs.source/android_common/metalava/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt
Paul Duffin895c7142021-04-25 13:40:15 +0100479.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
480.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
481.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
482.intermediates/mycoreplatform.stubs/android_common/javac/mycoreplatform.stubs.jar -> sdk_library/public/mycoreplatform-stubs.jar
483.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt
484.intermediates/mycoreplatform.stubs.source/android_common/metalava/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt
Paul Duffin7c475152021-06-09 16:17:58 +0100485`),
486 snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
487 snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
488 snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
489 )
Paul Duffinf7f65da2021-03-10 15:00:46 +0000490}
Paul Duffin04b4a192021-03-18 11:05:31 +0000491
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100492// Test that bootclasspath_fragment works with sdk.
493func TestBasicSdkWithBootclasspathFragment(t *testing.T) {
Paul Duffin04b4a192021-03-18 11:05:31 +0000494 android.GroupFixturePreparers(
495 prepareForSdkTestWithApex,
496 prepareForSdkTestWithJava,
Paul Duffin8018e502021-05-21 19:28:09 +0100497 android.FixtureAddFile("java/mybootlib.jar", nil),
Paul Duffin04b4a192021-03-18 11:05:31 +0000498 android.FixtureWithRootAndroidBp(`
499 sdk {
500 name: "mysdk",
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100501 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000502 }
503
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100504 bootclasspath_fragment {
505 name: "mybootclasspathfragment",
Paul Duffin04b4a192021-03-18 11:05:31 +0000506 image_name: "art",
Paul Duffin8018e502021-05-21 19:28:09 +0100507 contents: ["mybootlib"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000508 apex_available: ["myapex"],
509 }
510
Paul Duffin8018e502021-05-21 19:28:09 +0100511 java_library {
512 name: "mybootlib",
513 apex_available: ["myapex"],
514 srcs: ["Test.java"],
515 system_modules: "none",
516 sdk_version: "none",
517 min_sdk_version: "1",
518 compile_dex: true,
519 }
520
Paul Duffin04b4a192021-03-18 11:05:31 +0000521 sdk_snapshot {
522 name: "mysdk@1",
Paul Duffin8018e502021-05-21 19:28:09 +0100523 bootclasspath_fragments: ["mysdk_mybootclasspathfragment@1"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000524 }
525
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100526 prebuilt_bootclasspath_fragment {
Paul Duffin8018e502021-05-21 19:28:09 +0100527 name: "mysdk_mybootclasspathfragment@1",
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100528 sdk_member_name: "mybootclasspathfragment",
Paul Duffin04b4a192021-03-18 11:05:31 +0000529 prefer: false,
530 visibility: ["//visibility:public"],
531 apex_available: [
532 "myapex",
533 ],
534 image_name: "art",
Paul Duffin8018e502021-05-21 19:28:09 +0100535 contents: ["mysdk_mybootlib@1"],
536 }
537
538 java_import {
539 name: "mysdk_mybootlib@1",
540 sdk_member_name: "mybootlib",
541 visibility: ["//visibility:public"],
542 apex_available: ["com.android.art"],
543 jars: ["java/mybootlib.jar"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000544 }
545 `),
546 ).RunTest(t)
547}
Paul Duffin7c955552021-04-19 13:23:53 +0100548
549func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
550 result := android.GroupFixturePreparers(
551 prepareForSdkTestWithJava,
Paul Duffin475daaf2021-05-13 00:57:55 +0100552 java.PrepareForTestWithJavaDefaultModules,
553 java.PrepareForTestWithJavaSdkLibraryFiles,
554 java.FixtureWithLastReleaseApis("mysdklibrary"),
Paul Duffin7c475152021-06-09 16:17:58 +0100555 java.FixtureConfigureUpdatableBootJars("myapex:mybootlib"),
Paul Duffin475daaf2021-05-13 00:57:55 +0100556 prepareForSdkTestWithApex,
Paul Duffin7c475152021-06-09 16:17:58 +0100557
558 // Add a platform_bootclasspath that depends on the fragment.
559 fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
560
Paul Duffin7c955552021-04-19 13:23:53 +0100561 android.MockFS{
562 "my-blocked.txt": nil,
563 "my-max-target-o-low-priority.txt": nil,
564 "my-max-target-p.txt": nil,
565 "my-max-target-q.txt": nil,
566 "my-max-target-r-low-priority.txt": nil,
567 "my-removed.txt": nil,
568 "my-unsupported-packages.txt": nil,
569 "my-unsupported.txt": nil,
570 }.AddToFixture(),
571 android.FixtureWithRootAndroidBp(`
572 sdk {
573 name: "mysdk",
574 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin7c955552021-04-19 13:23:53 +0100575 }
576
Paul Duffin475daaf2021-05-13 00:57:55 +0100577 apex {
578 name: "myapex",
579 key: "myapex.key",
580 min_sdk_version: "1",
581 bootclasspath_fragments: ["mybootclasspathfragment"],
582 }
583
Paul Duffin7c955552021-04-19 13:23:53 +0100584 bootclasspath_fragment {
585 name: "mybootclasspathfragment",
Paul Duffin475daaf2021-05-13 00:57:55 +0100586 apex_available: ["myapex"],
Paul Duffin7c955552021-04-19 13:23:53 +0100587 contents: ["mybootlib"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100588 api: {
589 stub_libs: ["mysdklibrary"],
590 },
Paul Duffin7c955552021-04-19 13:23:53 +0100591 hidden_api: {
592 unsupported: [
593 "my-unsupported.txt",
594 ],
595 removed: [
596 "my-removed.txt",
597 ],
598 max_target_r_low_priority: [
599 "my-max-target-r-low-priority.txt",
600 ],
601 max_target_q: [
602 "my-max-target-q.txt",
603 ],
604 max_target_p: [
605 "my-max-target-p.txt",
606 ],
607 max_target_o_low_priority: [
608 "my-max-target-o-low-priority.txt",
609 ],
610 blocked: [
611 "my-blocked.txt",
612 ],
613 unsupported_packages: [
614 "my-unsupported-packages.txt",
615 ],
616 },
617 }
618
619 java_library {
620 name: "mybootlib",
Paul Duffin475daaf2021-05-13 00:57:55 +0100621 apex_available: ["myapex"],
Paul Duffin7c955552021-04-19 13:23:53 +0100622 srcs: ["Test.java"],
623 system_modules: "none",
624 sdk_version: "none",
Paul Duffin475daaf2021-05-13 00:57:55 +0100625 min_sdk_version: "1",
Paul Duffin7c955552021-04-19 13:23:53 +0100626 compile_dex: true,
Paul Duffin7c475152021-06-09 16:17:58 +0100627 permitted_packages: ["mybootlib"],
Paul Duffin7c955552021-04-19 13:23:53 +0100628 }
Paul Duffin475daaf2021-05-13 00:57:55 +0100629
630 java_sdk_library {
631 name: "mysdklibrary",
632 srcs: ["Test.java"],
633 compile_dex: true,
634 public: {enabled: true},
635 }
Paul Duffin7c955552021-04-19 13:23:53 +0100636 `),
637 ).RunTest(t)
638
Paul Duffin7c475152021-06-09 16:17:58 +0100639 // A preparer to update the test fixture used when processing an unpackage snapshot.
640 preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")
641
Paul Duffin7c955552021-04-19 13:23:53 +0100642 CheckSnapshot(t, result, "mysdk", "",
643 checkUnversionedAndroidBpContents(`
644// This is auto-generated. DO NOT EDIT.
645
646prebuilt_bootclasspath_fragment {
647 name: "mybootclasspathfragment",
648 prefer: false,
649 visibility: ["//visibility:public"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100650 apex_available: ["myapex"],
Paul Duffin7c955552021-04-19 13:23:53 +0100651 contents: ["mybootlib"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100652 api: {
653 stub_libs: ["mysdklibrary"],
654 },
Paul Duffin7c955552021-04-19 13:23:53 +0100655 hidden_api: {
656 unsupported: ["hiddenapi/my-unsupported.txt"],
657 removed: ["hiddenapi/my-removed.txt"],
658 max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"],
659 max_target_q: ["hiddenapi/my-max-target-q.txt"],
660 max_target_p: ["hiddenapi/my-max-target-p.txt"],
661 max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"],
662 blocked: ["hiddenapi/my-blocked.txt"],
663 unsupported_packages: ["hiddenapi/my-unsupported-packages.txt"],
Paul Duffin2fef1362021-04-15 13:32:00 +0100664 stub_flags: "hiddenapi/stub-flags.csv",
665 annotation_flags: "hiddenapi/annotation-flags.csv",
666 metadata: "hiddenapi/metadata.csv",
667 index: "hiddenapi/index.csv",
668 all_flags: "hiddenapi/all-flags.csv",
Paul Duffin7c955552021-04-19 13:23:53 +0100669 },
670}
671
672java_import {
673 name: "mybootlib",
674 prefer: false,
675 visibility: ["//visibility:public"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100676 apex_available: ["myapex"],
Paul Duffin7c955552021-04-19 13:23:53 +0100677 jars: ["java/mybootlib.jar"],
678}
Paul Duffin475daaf2021-05-13 00:57:55 +0100679
680java_sdk_library_import {
681 name: "mysdklibrary",
682 prefer: false,
683 visibility: ["//visibility:public"],
684 apex_available: ["//apex_available:platform"],
685 shared_library: true,
686 compile_dex: true,
687 public: {
688 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
689 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
690 current_api: "sdk_library/public/mysdklibrary.txt",
691 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
692 sdk_version: "current",
693 },
694}
Paul Duffin7c955552021-04-19 13:23:53 +0100695`),
696 checkAllCopyRules(`
697my-unsupported.txt -> hiddenapi/my-unsupported.txt
698my-removed.txt -> hiddenapi/my-removed.txt
699my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt
700my-max-target-q.txt -> hiddenapi/my-max-target-q.txt
701my-max-target-p.txt -> hiddenapi/my-max-target-p.txt
702my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt
703my-blocked.txt -> hiddenapi/my-blocked.txt
704my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt
Paul Duffin2fef1362021-04-15 13:32:00 +0100705.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/stub-flags.csv -> hiddenapi/stub-flags.csv
706.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
707.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
708.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
709.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/all-flags.csv -> hiddenapi/all-flags.csv
Paul Duffin7c955552021-04-19 13:23:53 +0100710.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
Paul Duffin475daaf2021-05-13 00:57:55 +0100711.intermediates/mysdklibrary.stubs/android_common/javac/mysdklibrary.stubs.jar -> sdk_library/public/mysdklibrary-stubs.jar
712.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
713.intermediates/mysdklibrary.stubs.source/android_common/metalava/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
Paul Duffin7c955552021-04-19 13:23:53 +0100714`),
Paul Duffin7c475152021-06-09 16:17:58 +0100715 snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
716 snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
717 snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
Paul Duffin7c955552021-04-19 13:23:53 +0100718 )
719}