• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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
17import (
18	"fmt"
19	"path/filepath"
20	"strings"
21	"testing"
22
23	"android/soong/android"
24	"android/soong/java"
25)
26
27// fixtureAddPlatformBootclasspathForBootclasspathFragment adds a platform_bootclasspath module that
28// references the bootclasspath fragment.
29func fixtureAddPlatformBootclasspathForBootclasspathFragment(apex, fragment string) android.FixturePreparer {
30	return fixtureAddPlatformBootclasspathForBootclasspathFragmentWithExtra(apex, fragment, "")
31}
32
33// fixtureAddPlatformBootclasspathForBootclasspathFragmentWithExtra is the same as above, but also adds extra fragments.
34func fixtureAddPlatformBootclasspathForBootclasspathFragmentWithExtra(apex, fragment, extraFragments string) android.FixturePreparer {
35	return android.GroupFixturePreparers(
36		// Add a platform_bootclasspath module.
37		android.FixtureAddTextFile("frameworks/base/boot/Android.bp", fmt.Sprintf(`
38			platform_bootclasspath {
39				name: "platform-bootclasspath",
40				fragments: [
41					{
42						apex: "%s",
43						module: "%s",
44					},
45					%s
46				],
47			}
48		`, apex, fragment, extraFragments)),
49		android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil),
50		android.FixtureAddFile("frameworks/base/config/boot-image-profile.txt", nil),
51		android.FixtureAddFile("build/soong/scripts/check_boot_jars/package_allowed_list.txt", nil),
52	)
53}
54
55// fixtureAddPrebuiltApexForBootclasspathFragment adds a prebuilt_apex that exports the fragment.
56func fixtureAddPrebuiltApexForBootclasspathFragment(apex, fragment string) android.FixturePreparer {
57	apexFile := fmt.Sprintf("%s.apex", apex)
58	dir := "prebuilts/apex"
59	return android.GroupFixturePreparers(
60		// A preparer to add a prebuilt apex to the test fixture.
61		android.FixtureAddTextFile(filepath.Join(dir, "Android.bp"), fmt.Sprintf(`
62			prebuilt_apex {
63				name: "%s",
64				src: "%s",
65				exported_bootclasspath_fragments: [
66					"%s",
67				],
68			}
69		`, apex, apexFile, fragment)),
70		android.FixtureAddFile(filepath.Join(dir, apexFile), nil),
71	)
72}
73
74func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
75	result := android.GroupFixturePreparers(
76		prepareForSdkTestWithJava,
77		java.PrepareForTestWithDexpreopt,
78		prepareForSdkTestWithApex,
79
80		// Some additional files needed for the art apex.
81		android.FixtureMergeMockFs(android.MockFS{
82			"com.android.art.avbpubkey":                          nil,
83			"com.android.art.pem":                                nil,
84			"system/sepolicy/apex/com.android.art-file_contexts": nil,
85		}),
86
87		// Add a platform_bootclasspath that depends on the fragment.
88		fixtureAddPlatformBootclasspathForBootclasspathFragmentWithExtra(
89			"com.android.art", "art-bootclasspath-fragment", java.ApexBootJarFragmentsForPlatformBootclasspath),
90
91		java.PrepareForBootImageConfigTest,
92		java.PrepareApexBootJarConfigsAndModules,
93		android.FixtureWithRootAndroidBp(`
94			sdk {
95				name: "mysdk",
96				bootclasspath_fragments: ["art-bootclasspath-fragment"],
97			}
98
99			apex {
100				name: "com.android.art",
101				key: "com.android.art.key",
102				bootclasspath_fragments: [
103					"art-bootclasspath-fragment",
104				],
105				updatable: false,
106			}
107
108			bootclasspath_fragment {
109				name: "art-bootclasspath-fragment",
110				image_name: "art",
111				contents: ["core1", "core2"],
112				apex_available: ["com.android.art"],
113				hidden_api: {
114					split_packages: ["*"],
115				},
116			}
117
118			apex_key {
119				name: "com.android.art.key",
120				public_key: "com.android.art.avbpubkey",
121				private_key: "com.android.art.pem",
122			}
123
124			java_library {
125				name: "core1",
126				srcs: ["Test.java"],
127				system_modules: "none",
128				sdk_version: "none",
129				compile_dex: true,
130				apex_available: ["com.android.art"],
131			}
132
133			java_library {
134				name: "core2",
135				srcs: ["Test.java"],
136				system_modules: "none",
137				sdk_version: "none",
138				compile_dex: true,
139				apex_available: ["com.android.art"],
140			}
141`),
142	).RunTest(t)
143
144	// A preparer to update the test fixture used when processing an unpackage snapshot.
145	preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "art-bootclasspath-fragment")
146
147	// Check that source on its own configures the bootImageConfig correctly.
148	java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
149	java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
150
151	CheckSnapshot(t, result, "mysdk", "",
152		checkAndroidBpContents(`
153// This is auto-generated. DO NOT EDIT.
154
155apex_contributions_defaults {
156    name: "mysdk.contributions",
157    contents: [],
158}
159
160prebuilt_bootclasspath_fragment {
161    name: "art-bootclasspath-fragment",
162    prefer: false,
163    visibility: ["//visibility:public"],
164    apex_available: ["com.android.art"],
165    image_name: "art",
166    contents: [
167        "core1",
168        "core2",
169    ],
170    hidden_api: {
171        annotation_flags: "hiddenapi/annotation-flags.csv",
172        metadata: "hiddenapi/metadata.csv",
173        index: "hiddenapi/index.csv",
174        signature_patterns: "hiddenapi/signature-patterns.csv",
175        filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
176        filtered_flags: "hiddenapi/filtered-flags.csv",
177    },
178}
179
180java_import {
181    name: "core1",
182    prefer: false,
183    visibility: ["//visibility:public"],
184    apex_available: ["com.android.art"],
185    jars: ["java_boot_libs/snapshot/jars/are/invalid/core1.jar"],
186}
187
188java_import {
189    name: "core2",
190    prefer: false,
191    visibility: ["//visibility:public"],
192    apex_available: ["com.android.art"],
193    jars: ["java_boot_libs/snapshot/jars/are/invalid/core2.jar"],
194}
195
196`),
197		checkAllCopyRules(`
198.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
199.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
200.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
201.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
202.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
203.intermediates/art-bootclasspath-fragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
204.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/core1.jar
205.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/core2.jar
206		`),
207		snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
208
209		// Check the behavior of the snapshot without the source.
210		snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) {
211			// Make sure that the boot jars package check rule includes the dex jars retrieved from the prebuilt apex.
212			checkBootJarsPackageCheckRule(t, result,
213				append(
214					[]string{
215						"out/soong/.intermediates/prebuilts/apex/prebuilt_com.android.art.deapexer/android_common/deapexer/javalib/core1.jar",
216						"out/soong/.intermediates/prebuilts/apex/prebuilt_com.android.art.deapexer/android_common/deapexer/javalib/core2.jar",
217						"out/soong/.intermediates/default/java/framework/android_common/aligned/framework.jar",
218					},
219					java.ApexBootJarDexJarPaths...,
220				)...,
221			)
222			java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
223			java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
224		}),
225
226		snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
227
228		// Check the behavior of the snapshot when the source is preferred.
229		snapshotTestChecker(checkSnapshotWithSourcePreferred, func(t *testing.T, result *android.TestResult) {
230			java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
231			java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
232		}),
233
234		snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
235
236		// Check the behavior of the snapshot when it is preferred.
237		snapshotTestChecker(checkSnapshotPreferredWithSource, func(t *testing.T, result *android.TestResult) {
238			java.CheckMutatedArtBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
239			java.CheckMutatedFrameworkBootImageConfig(t, result, "out/soong/.intermediates/default/java/dex_bootjars/android_common/meta_lic")
240		}),
241	)
242
243	// Make sure that the boot jars package check rule includes the dex jars created from the source.
244	checkBootJarsPackageCheckRule(t, result,
245		append(
246			[]string{
247				"out/soong/.intermediates/core1/android_common_apex10000/aligned/core1.jar",
248				"out/soong/.intermediates/core2/android_common_apex10000/aligned/core2.jar",
249				"out/soong/.intermediates/default/java/framework/android_common/aligned/framework.jar",
250			},
251			java.ApexBootJarDexJarPaths...,
252		)...,
253	)
254}
255
256// checkBootJarsPackageCheckRule checks that the supplied module is an input to the boot jars
257// package check rule.
258func checkBootJarsPackageCheckRule(t *testing.T, result *android.TestResult, expectedModules ...string) {
259	t.Helper()
260	platformBcp := result.ModuleForTests("platform-bootclasspath", "android_common")
261	bootJarsCheckRule := platformBcp.Rule("boot_jars_package_check")
262	command := bootJarsCheckRule.RuleParams.Command
263	expectedCommandArgs := " build/soong/scripts/check_boot_jars/package_allowed_list.txt " + strings.Join(expectedModules, " ") + " &&"
264	android.AssertStringDoesContain(t, "boot jars package check", command, expectedCommandArgs)
265}
266
267func testSnapshotWithBootClasspathFragment_Contents(t *testing.T, sdk string, copyRules string) {
268	result := android.GroupFixturePreparers(
269		prepareForSdkTestWithJava,
270		java.PrepareForTestWithJavaDefaultModules,
271		java.PrepareForTestWithJavaSdkLibraryFiles,
272		java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
273		java.FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:myothersdklibrary"),
274		prepareForSdkTestWithApex,
275
276		// Add a platform_bootclasspath that depends on the fragment.
277		fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
278
279		android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
280			variables.BuildFlags = map[string]string{
281				"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
282			}
283		}),
284		// Make sure that we have atleast one platform library so that we can check the monolithic hiddenapi
285		// file creation.
286		java.FixtureConfigureBootJars("platform:foo"),
287		android.FixtureModifyMockFS(func(fs android.MockFS) {
288			fs["platform/Android.bp"] = []byte(`
289		java_library {
290			name: "foo",
291			srcs: ["Test.java"],
292			compile_dex: true,
293		}
294		`)
295			fs["platform/Test.java"] = nil
296		}),
297
298		android.FixtureWithRootAndroidBp(sdk+`
299			apex {
300				name: "myapex",
301				key: "myapex.key",
302				min_sdk_version: "2",
303				bootclasspath_fragments: ["mybootclasspathfragment"],
304			}
305
306			bootclasspath_fragment {
307				name: "mybootclasspathfragment",
308				apex_available: ["myapex"],
309				contents: [
310					// This should be automatically added to the sdk_snapshot as a java_boot_libs module.
311					"mybootlib",
312					// This should be automatically added to the sdk_snapshot as a java_sdk_libs module.
313					"myothersdklibrary",
314				],
315				api: {
316					stub_libs: ["mysdklibrary"],
317				},
318				core_platform_api: {
319					// This should be automatically added to the sdk_snapshot as a java_sdk_libs module.
320					stub_libs: ["mycoreplatform"],
321				},
322				hidden_api: {
323					split_packages: ["*"],
324				},
325			}
326
327			java_library {
328				name: "mybootlib",
329				apex_available: ["myapex"],
330				srcs: ["Test.java"],
331				system_modules: "none",
332				sdk_version: "none",
333				min_sdk_version: "2",
334				compile_dex: true,
335				permitted_packages: ["mybootlib"],
336			}
337
338			java_sdk_library {
339				name: "mysdklibrary",
340				apex_available: ["myapex"],
341				srcs: ["Test.java"],
342				shared_library: false,
343				public: {enabled: true},
344				min_sdk_version: "2",
345			}
346
347			java_sdk_library {
348				name: "myothersdklibrary",
349				apex_available: ["myapex"],
350				srcs: ["Test.java"],
351				compile_dex: true,
352				public: {enabled: true},
353				min_sdk_version: "2",
354				permitted_packages: ["myothersdklibrary"],
355			}
356
357			java_sdk_library {
358				name: "mycoreplatform",
359				apex_available: ["myapex"],
360				srcs: ["Test.java"],
361				compile_dex: true,
362				public: {enabled: true},
363				min_sdk_version: "2",
364			}
365		`),
366	).RunTest(t)
367
368	// A preparer to update the test fixture used when processing an unpackage snapshot.
369	preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")
370
371	CheckSnapshot(t, result, "mysdk", "",
372		checkAndroidBpContents(`
373// This is auto-generated. DO NOT EDIT.
374
375apex_contributions_defaults {
376    name: "mysdk.contributions",
377    contents: [
378        "prebuilt_myothersdklibrary",
379        "prebuilt_mysdklibrary",
380        "prebuilt_mycoreplatform",
381    ],
382}
383
384prebuilt_bootclasspath_fragment {
385    name: "mybootclasspathfragment",
386    prefer: false,
387    visibility: ["//visibility:public"],
388    apex_available: ["myapex"],
389    contents: [
390        "mybootlib",
391        "myothersdklibrary",
392    ],
393    api: {
394        stub_libs: ["mysdklibrary"],
395    },
396    core_platform_api: {
397        stub_libs: ["mycoreplatform"],
398    },
399    hidden_api: {
400        annotation_flags: "hiddenapi/annotation-flags.csv",
401        metadata: "hiddenapi/metadata.csv",
402        index: "hiddenapi/index.csv",
403        signature_patterns: "hiddenapi/signature-patterns.csv",
404        filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
405        filtered_flags: "hiddenapi/filtered-flags.csv",
406    },
407}
408
409java_import {
410    name: "mybootlib",
411    prefer: false,
412    visibility: ["//visibility:public"],
413    apex_available: ["myapex"],
414    jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"],
415    min_sdk_version: "2",
416    permitted_packages: ["mybootlib"],
417}
418
419java_sdk_library_import {
420    name: "myothersdklibrary",
421    prefer: false,
422    visibility: ["//visibility:public"],
423    apex_available: ["myapex"],
424    shared_library: true,
425    compile_dex: true,
426    permitted_packages: ["myothersdklibrary"],
427    public: {
428        jars: ["sdk_library/public/myothersdklibrary-stubs.jar"],
429        stub_srcs: ["sdk_library/public/myothersdklibrary_stub_sources"],
430        current_api: "sdk_library/public/myothersdklibrary.txt",
431        removed_api: "sdk_library/public/myothersdklibrary-removed.txt",
432        sdk_version: "current",
433    },
434}
435
436java_sdk_library_import {
437    name: "mysdklibrary",
438    prefer: false,
439    visibility: ["//visibility:public"],
440    apex_available: ["myapex"],
441    shared_library: false,
442    public: {
443        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
444        stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
445        current_api: "sdk_library/public/mysdklibrary.txt",
446        removed_api: "sdk_library/public/mysdklibrary-removed.txt",
447        sdk_version: "current",
448    },
449}
450
451java_sdk_library_import {
452    name: "mycoreplatform",
453    prefer: false,
454    visibility: ["//visibility:public"],
455    apex_available: ["myapex"],
456    shared_library: true,
457    compile_dex: true,
458    public: {
459        jars: ["sdk_library/public/mycoreplatform-stubs.jar"],
460        stub_srcs: ["sdk_library/public/mycoreplatform_stub_sources"],
461        current_api: "sdk_library/public/mycoreplatform.txt",
462        removed_api: "sdk_library/public/mycoreplatform-removed.txt",
463        sdk_version: "current",
464    },
465}
466		`),
467		checkAllCopyRules(copyRules),
468		snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
469		snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) {
470			module := result.ModuleForTests("platform-bootclasspath", "android_common")
471			var rule android.TestingBuildParams
472			rule = module.Output("out/soong/hiddenapi/hiddenapi-flags.csv")
473			java.CheckHiddenAPIRuleInputs(t, "monolithic flags", `
474				out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/annotation-flags-from-classes.csv
475        out/soong/hiddenapi/hiddenapi-stub-flags.txt
476        snapshot/hiddenapi/annotation-flags.csv
477			`, rule)
478
479			rule = module.Output("out/soong/hiddenapi/hiddenapi-unsupported.csv")
480			java.CheckHiddenAPIRuleInputs(t, "monolithic metadata", `
481				out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/metadata-from-classes.csv
482        snapshot/hiddenapi/metadata.csv
483			`, rule)
484
485			rule = module.Output("out/soong/hiddenapi/hiddenapi-index.csv")
486			java.CheckHiddenAPIRuleInputs(t, "monolithic index", `
487				out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv
488        snapshot/hiddenapi/index.csv
489			`, rule)
490
491			rule = module.Output("out/soong/hiddenapi/hiddenapi-flags.csv.valid")
492			android.AssertStringDoesContain(t, "verify-overlaps", rule.RuleParams.Command, " snapshot/hiddenapi/filtered-flags.csv:snapshot/hiddenapi/signature-patterns.csv ")
493		}),
494		snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
495		snapshotTestChecker(checkSnapshotWithSourcePreferred, func(t *testing.T, result *android.TestResult) {
496			module := result.ModuleForTests("platform-bootclasspath", "android_common")
497			rule := module.Output("out/soong/hiddenapi/hiddenapi-flags.csv.valid")
498			android.AssertStringDoesContain(t, "verify-overlaps", rule.RuleParams.Command, " out/soong/.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv:out/soong/.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv ")
499		}),
500		snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
501	)
502}
503
504func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
505	t.Run("added-directly", func(t *testing.T) {
506		testSnapshotWithBootClasspathFragment_Contents(t, `
507			sdk {
508				name: "mysdk",
509				bootclasspath_fragments: ["mybootclasspathfragment"],
510				java_sdk_libs: [
511					// This is not strictly needed as it should be automatically added to the sdk_snapshot as
512					// a java_sdk_libs module because it is used in the mybootclasspathfragment's
513					// api.stub_libs property. However, it is specified here to ensure that duplicates are
514					// correctly deduped.
515					"mysdklibrary",
516				],
517			}
518		`, `
519.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
520.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
521.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
522.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
523.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
524.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
525.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
526.intermediates/myothersdklibrary.stubs.exportable/android_common/combined/myothersdklibrary.stubs.exportable.jar -> sdk_library/public/myothersdklibrary-stubs.jar
527.intermediates/myothersdklibrary.stubs.source/android_common/exportable/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt
528.intermediates/myothersdklibrary.stubs.source/android_common/exportable/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt
529.intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar
530.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
531.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
532.intermediates/mycoreplatform.stubs.exportable/android_common/combined/mycoreplatform.stubs.exportable.jar -> sdk_library/public/mycoreplatform-stubs.jar
533.intermediates/mycoreplatform.stubs.source/android_common/exportable/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt
534.intermediates/mycoreplatform.stubs.source/android_common/exportable/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt
535`)
536	})
537
538	copyBootclasspathFragmentFromApexVariantRules := `
539.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
540.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
541.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv
542.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
543.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
544.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
545.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
546.intermediates/myothersdklibrary.stubs.exportable/android_common/combined/myothersdklibrary.stubs.exportable.jar -> sdk_library/public/myothersdklibrary-stubs.jar
547.intermediates/myothersdklibrary.stubs.source/android_common/exportable/myothersdklibrary.stubs.source_api.txt -> sdk_library/public/myothersdklibrary.txt
548.intermediates/myothersdklibrary.stubs.source/android_common/exportable/myothersdklibrary.stubs.source_removed.txt -> sdk_library/public/myothersdklibrary-removed.txt
549.intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar
550.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
551.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
552.intermediates/mycoreplatform.stubs.exportable/android_common/combined/mycoreplatform.stubs.exportable.jar -> sdk_library/public/mycoreplatform-stubs.jar
553.intermediates/mycoreplatform.stubs.source/android_common/exportable/mycoreplatform.stubs.source_api.txt -> sdk_library/public/mycoreplatform.txt
554.intermediates/mycoreplatform.stubs.source/android_common/exportable/mycoreplatform.stubs.source_removed.txt -> sdk_library/public/mycoreplatform-removed.txt
555`
556	t.Run("added-via-apex", func(t *testing.T) {
557		testSnapshotWithBootClasspathFragment_Contents(t, `
558			sdk {
559				name: "mysdk",
560				apexes: ["myapex"],
561			}
562		`, copyBootclasspathFragmentFromApexVariantRules)
563	})
564
565	t.Run("added-directly-and-indirectly", func(t *testing.T) {
566		testSnapshotWithBootClasspathFragment_Contents(t, `
567			sdk {
568				name: "mysdk",
569				apexes: ["myapex"],
570				// This is not strictly needed as it should be automatically added to the sdk_snapshot as
571				// a bootclasspath_fragments module because it is used in the myapex's
572				// bootclasspath_fragments property. However, it is specified here to ensure that duplicates
573				// are correctly deduped.
574				bootclasspath_fragments: ["mybootclasspathfragment"],
575				java_sdk_libs: [
576					// This is not strictly needed as it should be automatically added to the sdk_snapshot as
577					// a java_sdk_libs module because it is used in the mybootclasspathfragment's
578					// api.stub_libs property. However, it is specified here to ensure that duplicates are
579					// correctly deduped.
580					"mysdklibrary",
581				],
582			}
583		`, copyBootclasspathFragmentFromApexVariantRules)
584	})
585}
586
587// TestSnapshotWithBootClasspathFragment_Fragments makes sure that the fragments property of a
588// bootclasspath_fragment is correctly output to the sdk snapshot.
589func TestSnapshotWithBootClasspathFragment_Fragments(t *testing.T) {
590	result := android.GroupFixturePreparers(
591		prepareForSdkTestWithJava,
592		java.PrepareForTestWithJavaDefaultModules,
593		java.PrepareForTestWithJavaSdkLibraryFiles,
594		java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary"),
595		java.FixtureConfigureApexBootJars("someapex:mysdklibrary", "myotherapex:myotherlib"),
596		prepareForSdkTestWithApex,
597
598		// Some additional files needed for the myotherapex.
599		android.FixtureMergeMockFs(android.MockFS{
600			"system/sepolicy/apex/myotherapex-file_contexts": nil,
601			"myotherapex/apex_manifest.json":                 nil,
602			"myotherapex/Test.java":                          nil,
603		}),
604
605		android.FixtureAddTextFile("myotherapex/Android.bp", `
606			apex {
607				name: "myotherapex",
608				key: "myapex.key",
609				min_sdk_version: "2",
610				bootclasspath_fragments: ["myotherbootclasspathfragment"],
611			}
612
613			bootclasspath_fragment {
614				name: "myotherbootclasspathfragment",
615				apex_available: ["myotherapex"],
616				contents: [
617					"myotherlib",
618				],
619				hidden_api: {
620					split_packages: ["*"],
621				},
622			}
623
624			java_library {
625				name: "myotherlib",
626				apex_available: ["myotherapex"],
627				srcs: ["Test.java"],
628				min_sdk_version: "2",
629				permitted_packages: ["myothersdklibrary"],
630				compile_dex: true,
631			}
632		`),
633
634		android.FixtureWithRootAndroidBp(`
635			sdk {
636				name: "mysdk",
637				bootclasspath_fragments: ["mybootclasspathfragment"],
638			}
639
640			bootclasspath_fragment {
641				name: "mybootclasspathfragment",
642				contents: [
643					"mysdklibrary",
644				],
645				fragments: [
646					{
647						apex: "myotherapex",
648						module: "myotherbootclasspathfragment"
649					},
650				],
651				hidden_api: {
652					split_packages: ["*"],
653				},
654			}
655
656			java_sdk_library {
657				name: "mysdklibrary",
658				srcs: ["Test.java"],
659				shared_library: false,
660				public: {enabled: true},
661				min_sdk_version: "2",
662			}
663		`),
664	).RunTest(t)
665
666	// A preparer to update the test fixture used when processing an unpackage snapshot.
667	preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")
668
669	CheckSnapshot(t, result, "mysdk", "",
670		checkAndroidBpContents(`
671// This is auto-generated. DO NOT EDIT.
672
673apex_contributions_defaults {
674    name: "mysdk.contributions",
675    contents: ["prebuilt_mysdklibrary"],
676}
677
678prebuilt_bootclasspath_fragment {
679    name: "mybootclasspathfragment",
680    prefer: false,
681    visibility: ["//visibility:public"],
682    apex_available: ["//apex_available:platform"],
683    contents: ["mysdklibrary"],
684    fragments: [
685        {
686            apex: "myotherapex",
687            module: "myotherbootclasspathfragment",
688        },
689    ],
690    hidden_api: {
691        annotation_flags: "hiddenapi/annotation-flags.csv",
692        metadata: "hiddenapi/metadata.csv",
693        index: "hiddenapi/index.csv",
694        signature_patterns: "hiddenapi/signature-patterns.csv",
695        filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
696        filtered_flags: "hiddenapi/filtered-flags.csv",
697    },
698}
699
700java_sdk_library_import {
701    name: "mysdklibrary",
702    prefer: false,
703    visibility: ["//visibility:public"],
704    apex_available: ["//apex_available:platform"],
705    shared_library: false,
706    public: {
707        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
708        stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
709        current_api: "sdk_library/public/mysdklibrary.txt",
710        removed_api: "sdk_library/public/mysdklibrary-removed.txt",
711        sdk_version: "current",
712    },
713}
714		`),
715		snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
716		snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
717		snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
718	)
719}
720
721// Test that bootclasspath_fragment works with sdk.
722func TestBasicSdkWithBootclasspathFragment(t *testing.T) {
723	android.GroupFixturePreparers(
724		prepareForSdkTestWithApex,
725		prepareForSdkTestWithJava,
726		android.FixtureMergeMockFs(android.MockFS{
727			"java/mybootlib.jar":                nil,
728			"hiddenapi/annotation-flags.csv":    nil,
729			"hiddenapi/index.csv":               nil,
730			"hiddenapi/metadata.csv":            nil,
731			"hiddenapi/signature-patterns.csv":  nil,
732			"hiddenapi/filtered-stub-flags.csv": nil,
733			"hiddenapi/filtered-flags.csv":      nil,
734		}),
735		android.FixtureWithRootAndroidBp(`
736		sdk {
737			name: "mysdk",
738			bootclasspath_fragments: ["mybootclasspathfragment"],
739		}
740
741		bootclasspath_fragment {
742			name: "mybootclasspathfragment",
743			image_name: "art",
744			contents: ["mybootlib"],
745			apex_available: ["myapex"],
746			hidden_api: {
747				split_packages: ["*"],
748			},
749		}
750
751		java_library {
752			name: "mybootlib",
753			apex_available: ["myapex"],
754			srcs: ["Test.java"],
755			system_modules: "none",
756			sdk_version: "none",
757			min_sdk_version: "1",
758			compile_dex: true,
759		}
760
761		prebuilt_bootclasspath_fragment {
762			name: "mybootclasspathfragment",
763			prefer: false,
764			visibility: ["//visibility:public"],
765			apex_available: [
766				"myapex",
767			],
768			image_name: "art",
769			contents: ["mybootlib"],
770			hidden_api: {
771				annotation_flags: "hiddenapi/annotation-flags.csv",
772				metadata: "hiddenapi/metadata.csv",
773				index: "hiddenapi/index.csv",
774				signature_patterns: "hiddenapi/signature-patterns.csv",
775				filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
776				filtered_flags: "hiddenapi/filtered-flags.csv",
777			},
778		}
779
780		java_import {
781			name: "mybootlib",
782			visibility: ["//visibility:public"],
783			apex_available: ["com.android.art"],
784			jars: ["java/mybootlib.jar"],
785		}
786	`),
787	).RunTest(t)
788}
789
790func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
791	result := android.GroupFixturePreparers(
792		prepareForSdkTestWithJava,
793		java.PrepareForTestWithJavaDefaultModules,
794		java.PrepareForTestWithJavaSdkLibraryFiles,
795		java.FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"),
796		java.FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"),
797		prepareForSdkTestWithApex,
798
799		// Add a platform_bootclasspath that depends on the fragment.
800		fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
801
802		android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
803			variables.BuildFlags = map[string]string{
804				"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
805			}
806		}),
807
808		android.MockFS{
809			"my-blocked.txt":                   nil,
810			"my-max-target-o-low-priority.txt": nil,
811			"my-max-target-p.txt":              nil,
812			"my-max-target-q.txt":              nil,
813			"my-max-target-r-low-priority.txt": nil,
814			"my-removed.txt":                   nil,
815			"my-unsupported-packages.txt":      nil,
816			"my-unsupported.txt":               nil,
817			"my-new-max-target-q.txt":          nil,
818		}.AddToFixture(),
819		android.FixtureWithRootAndroidBp(`
820			sdk {
821				name: "mysdk",
822				bootclasspath_fragments: ["mybootclasspathfragment"],
823			}
824
825			apex {
826				name: "myapex",
827				key: "myapex.key",
828				min_sdk_version: "1",
829				bootclasspath_fragments: ["mybootclasspathfragment"],
830			}
831
832			bootclasspath_fragment {
833				name: "mybootclasspathfragment",
834				apex_available: ["myapex"],
835				contents: ["mybootlib", "mynewlibrary"],
836				api: {
837					stub_libs: ["mysdklibrary"],
838				},
839				hidden_api: {
840					unsupported: [
841							"my-unsupported.txt",
842					],
843					removed: [
844							"my-removed.txt",
845					],
846					max_target_r_low_priority: [
847							"my-max-target-r-low-priority.txt",
848					],
849					max_target_q: [
850							"my-max-target-q.txt",
851					],
852					max_target_p: [
853							"my-max-target-p.txt",
854					],
855					max_target_o_low_priority: [
856							"my-max-target-o-low-priority.txt",
857					],
858					blocked: [
859							"my-blocked.txt",
860					],
861					unsupported_packages: [
862							"my-unsupported-packages.txt",
863					],
864					split_packages: ["sdklibrary"],
865					package_prefixes: ["sdklibrary.all.mine"],
866					single_packages: ["sdklibrary.mine"],
867				},
868			}
869
870			java_library {
871				name: "mybootlib",
872				apex_available: ["myapex"],
873				srcs: ["Test.java"],
874				system_modules: "none",
875				sdk_version: "none",
876				min_sdk_version: "1",
877				compile_dex: true,
878				permitted_packages: ["mybootlib"],
879			}
880
881			java_sdk_library {
882				name: "mysdklibrary",
883				srcs: ["Test.java"],
884				compile_dex: true,
885				public: {enabled: true},
886				permitted_packages: ["mysdklibrary"],
887				min_sdk_version: "current",
888			}
889
890			java_sdk_library {
891				name: "mynewlibrary",
892				apex_available: ["myapex"],
893				srcs: ["Test.java"],
894				min_sdk_version: "10",
895				compile_dex: true,
896				public: {enabled: true},
897				permitted_packages: ["mysdklibrary"],
898				hidden_api: {
899					max_target_q: [
900							"my-new-max-target-q.txt",
901					],
902					split_packages: ["sdklibrary", "newlibrary"],
903					package_prefixes: ["newlibrary.all.mine"],
904					single_packages: ["newlibrary.mine"],
905				},
906			}
907		`),
908	).RunTest(t)
909
910	// A preparer to update the test fixture used when processing an unpackage snapshot.
911	preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")
912
913	CheckSnapshot(t, result, "mysdk", "",
914		checkAndroidBpContents(`
915// This is auto-generated. DO NOT EDIT.
916
917apex_contributions_defaults {
918    name: "mysdk.contributions",
919    contents: [
920        "prebuilt_mynewlibrary",
921        "prebuilt_mysdklibrary",
922    ],
923}
924
925prebuilt_bootclasspath_fragment {
926    name: "mybootclasspathfragment",
927    prefer: false,
928    visibility: ["//visibility:public"],
929    apex_available: ["myapex"],
930    contents: [
931        "mybootlib",
932        "mynewlibrary",
933    ],
934    api: {
935        stub_libs: ["mysdklibrary"],
936    },
937    hidden_api: {
938        unsupported: ["hiddenapi/my-unsupported.txt"],
939        removed: ["hiddenapi/my-removed.txt"],
940        max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"],
941        max_target_q: [
942            "hiddenapi/my-max-target-q.txt",
943            "hiddenapi/my-new-max-target-q.txt",
944        ],
945        max_target_p: ["hiddenapi/my-max-target-p.txt"],
946        max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"],
947        blocked: ["hiddenapi/my-blocked.txt"],
948        unsupported_packages: ["hiddenapi/my-unsupported-packages.txt"],
949        annotation_flags: "hiddenapi/annotation-flags.csv",
950        metadata: "hiddenapi/metadata.csv",
951        index: "hiddenapi/index.csv",
952        signature_patterns: "hiddenapi/signature-patterns.csv",
953        filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
954        filtered_flags: "hiddenapi/filtered-flags.csv",
955    },
956}
957
958java_import {
959    name: "mybootlib",
960    prefer: false,
961    visibility: ["//visibility:public"],
962    apex_available: ["myapex"],
963    jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"],
964    min_sdk_version: "1",
965    permitted_packages: ["mybootlib"],
966}
967
968java_sdk_library_import {
969    name: "mynewlibrary",
970    prefer: false,
971    visibility: ["//visibility:public"],
972    apex_available: ["myapex"],
973    shared_library: true,
974    compile_dex: true,
975    permitted_packages: ["mysdklibrary"],
976    public: {
977        jars: ["sdk_library/public/mynewlibrary-stubs.jar"],
978        stub_srcs: ["sdk_library/public/mynewlibrary_stub_sources"],
979        current_api: "sdk_library/public/mynewlibrary.txt",
980        removed_api: "sdk_library/public/mynewlibrary-removed.txt",
981        sdk_version: "current",
982    },
983}
984
985java_sdk_library_import {
986    name: "mysdklibrary",
987    prefer: false,
988    visibility: ["//visibility:public"],
989    apex_available: ["//apex_available:platform"],
990    shared_library: true,
991    compile_dex: true,
992    permitted_packages: ["mysdklibrary"],
993    public: {
994        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
995        stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
996        current_api: "sdk_library/public/mysdklibrary.txt",
997        removed_api: "sdk_library/public/mysdklibrary-removed.txt",
998        sdk_version: "current",
999    },
1000}
1001`),
1002		checkAllCopyRules(`
1003my-unsupported.txt -> hiddenapi/my-unsupported.txt
1004my-removed.txt -> hiddenapi/my-removed.txt
1005my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt
1006my-max-target-q.txt -> hiddenapi/my-max-target-q.txt
1007my-new-max-target-q.txt -> hiddenapi/my-new-max-target-q.txt
1008my-max-target-p.txt -> hiddenapi/my-max-target-p.txt
1009my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt
1010my-blocked.txt -> hiddenapi/my-blocked.txt
1011my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt
1012.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
1013.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
1014.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/index.csv -> hiddenapi/index.csv
1015.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
1016.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
1017.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
1018.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
1019.intermediates/mynewlibrary.stubs.exportable/android_common/combined/mynewlibrary.stubs.exportable.jar -> sdk_library/public/mynewlibrary-stubs.jar
1020.intermediates/mynewlibrary.stubs.source/android_common/exportable/mynewlibrary.stubs.source_api.txt -> sdk_library/public/mynewlibrary.txt
1021.intermediates/mynewlibrary.stubs.source/android_common/exportable/mynewlibrary.stubs.source_removed.txt -> sdk_library/public/mynewlibrary-removed.txt
1022.intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar
1023.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
1024.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
1025`),
1026		snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
1027		snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
1028		snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
1029	)
1030}
1031
1032func testSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T, targetBuildRelease string,
1033	expectedSdkSnapshot string,
1034	expectedCopyRules string,
1035	expectedStubFlagsInputs []string,
1036	suffix string) {
1037
1038	result := android.GroupFixturePreparers(
1039		prepareForSdkTestWithJava,
1040		java.PrepareForTestWithJavaDefaultModules,
1041		java.PrepareForTestWithJavaSdkLibraryFiles,
1042		java.FixtureWithLastReleaseApis("mysdklibrary", "mynewsdklibrary"),
1043		java.FixtureConfigureApexBootJars("myapex:mysdklibrary", "myapex:mynewsdklibrary"),
1044		prepareForSdkTestWithApex,
1045
1046		// Add a platform_bootclasspath that depends on the fragment.
1047		fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
1048
1049		android.FixtureMergeEnv(map[string]string{
1050			"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease,
1051		}),
1052		android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1053			variables.Platform_version_active_codenames = []string{"VanillaIceCream"}
1054		}),
1055
1056		android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1057			variables.BuildFlags = map[string]string{
1058				"RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
1059			}
1060		}),
1061
1062		android.FixtureWithRootAndroidBp(`
1063			sdk {
1064				name: "mysdk",
1065				apexes: ["myapex"],
1066			}
1067
1068			apex {
1069				name: "myapex",
1070				key: "myapex.key",
1071				min_sdk_version: "S",
1072				bootclasspath_fragments: ["mybootclasspathfragment"],
1073			}
1074
1075			bootclasspath_fragment {
1076				name: "mybootclasspathfragment",
1077				apex_available: ["myapex"],
1078				contents: [
1079					"mysdklibrary",
1080					"mynewsdklibrary",
1081				],
1082
1083				hidden_api: {
1084					split_packages: [],
1085				},
1086			}
1087
1088			java_sdk_library {
1089				name: "mysdklibrary",
1090				apex_available: ["myapex"],
1091				srcs: ["Test.java"],
1092				shared_library: false,
1093				public: {enabled: true},
1094				min_sdk_version: "S",
1095			}
1096
1097			java_sdk_library {
1098				name: "mynewsdklibrary",
1099				apex_available: ["myapex"],
1100				srcs: ["Test.java"],
1101				compile_dex: true,
1102				public: {enabled: true},
1103				min_sdk_version: "Tiramisu",
1104				permitted_packages: ["mynewsdklibrary"],
1105			}
1106		`),
1107	).RunTest(t)
1108
1109	bcpf := result.ModuleForTests("mybootclasspathfragment", "android_common")
1110	rule := bcpf.Output("out/soong/.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi" + suffix + "/stub-flags.csv")
1111	android.AssertPathsRelativeToTopEquals(t, "stub flags inputs", android.SortedUniqueStrings(expectedStubFlagsInputs), android.SortedUniquePaths(rule.Implicits))
1112
1113	CheckSnapshot(t, result, "mysdk", "",
1114		checkAndroidBpContents(expectedSdkSnapshot),
1115		checkAllCopyRules(expectedCopyRules),
1116	)
1117}
1118
1119func TestSnapshotWithBootClasspathFragment_MinSdkVersion(t *testing.T) {
1120	t.Run("target S build", func(t *testing.T) {
1121		expectedSnapshot := `
1122// This is auto-generated. DO NOT EDIT.
1123
1124prebuilt_bootclasspath_fragment {
1125    name: "mybootclasspathfragment",
1126    prefer: false,
1127    visibility: ["//visibility:public"],
1128    apex_available: ["myapex"],
1129    contents: ["mysdklibrary"],
1130    hidden_api: {
1131        annotation_flags: "hiddenapi/annotation-flags.csv",
1132        metadata: "hiddenapi/metadata.csv",
1133        index: "hiddenapi/index.csv",
1134        stub_flags: "hiddenapi/stub-flags.csv",
1135        all_flags: "hiddenapi/all-flags.csv",
1136    },
1137}
1138
1139java_sdk_library_import {
1140    name: "mysdklibrary",
1141    prefer: false,
1142    visibility: ["//visibility:public"],
1143    apex_available: ["myapex"],
1144    shared_library: false,
1145    public: {
1146        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
1147        stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
1148        current_api: "sdk_library/public/mysdklibrary.txt",
1149        removed_api: "sdk_library/public/mysdklibrary-removed.txt",
1150        sdk_version: "current",
1151    },
1152}
1153`
1154		expectedCopyRules := `
1155.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/annotation-flags.csv -> hiddenapi/annotation-flags.csv
1156.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/metadata.csv -> hiddenapi/metadata.csv
1157.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/index.csv -> hiddenapi/index.csv
1158.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/stub-flags.csv -> hiddenapi/stub-flags.csv
1159.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi-for-sdk-snapshot/all-flags.csv -> hiddenapi/all-flags.csv
1160.intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar
1161.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
1162.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
1163`
1164
1165		// On S the stub flags should only be generated from mysdklibrary as mynewsdklibrary is not part
1166		// of the snapshot.
1167		expectedStubFlagsInputs := []string{
1168			"out/soong/.intermediates/mysdklibrary.stubs.exportable/android_common/dex/mysdklibrary.stubs.exportable.jar",
1169			"out/soong/.intermediates/mysdklibrary.impl/android_common/aligned/mysdklibrary.jar",
1170		}
1171
1172		testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "S",
1173			expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "-for-sdk-snapshot")
1174	})
1175
1176	t.Run("target-Tiramisu-build", func(t *testing.T) {
1177		expectedSnapshot := `
1178// This is auto-generated. DO NOT EDIT.
1179
1180prebuilt_bootclasspath_fragment {
1181    name: "mybootclasspathfragment",
1182    prefer: false,
1183    visibility: ["//visibility:public"],
1184    apex_available: ["myapex"],
1185    contents: [
1186        "mysdklibrary",
1187        "mynewsdklibrary",
1188    ],
1189    hidden_api: {
1190        annotation_flags: "hiddenapi/annotation-flags.csv",
1191        metadata: "hiddenapi/metadata.csv",
1192        index: "hiddenapi/index.csv",
1193        signature_patterns: "hiddenapi/signature-patterns.csv",
1194        filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
1195        filtered_flags: "hiddenapi/filtered-flags.csv",
1196    },
1197}
1198
1199java_sdk_library_import {
1200    name: "mysdklibrary",
1201    prefer: false,
1202    visibility: ["//visibility:public"],
1203    apex_available: ["myapex"],
1204    shared_library: false,
1205    public: {
1206        jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
1207        stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
1208        current_api: "sdk_library/public/mysdklibrary.txt",
1209        removed_api: "sdk_library/public/mysdklibrary-removed.txt",
1210        sdk_version: "current",
1211    },
1212}
1213
1214java_sdk_library_import {
1215    name: "mynewsdklibrary",
1216    prefer: false,
1217    visibility: ["//visibility:public"],
1218    apex_available: ["myapex"],
1219    shared_library: true,
1220    compile_dex: true,
1221    permitted_packages: ["mynewsdklibrary"],
1222    public: {
1223        jars: ["sdk_library/public/mynewsdklibrary-stubs.jar"],
1224        stub_srcs: ["sdk_library/public/mynewsdklibrary_stub_sources"],
1225        current_api: "sdk_library/public/mynewsdklibrary.txt",
1226        removed_api: "sdk_library/public/mynewsdklibrary-removed.txt",
1227        sdk_version: "current",
1228    },
1229}
1230`
1231		expectedCopyRules := `
1232.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/annotation-flags.csv -> hiddenapi/annotation-flags.csv
1233.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/metadata.csv -> hiddenapi/metadata.csv
1234.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/index.csv -> hiddenapi/index.csv
1235.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
1236.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-stub-flags.csv -> hiddenapi/filtered-stub-flags.csv
1237.intermediates/mybootclasspathfragment/android_common_myapex/modular-hiddenapi/filtered-flags.csv -> hiddenapi/filtered-flags.csv
1238.intermediates/mysdklibrary.stubs.exportable/android_common/combined/mysdklibrary.stubs.exportable.jar -> sdk_library/public/mysdklibrary-stubs.jar
1239.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_api.txt -> sdk_library/public/mysdklibrary.txt
1240.intermediates/mysdklibrary.stubs.source/android_common/exportable/mysdklibrary.stubs.source_removed.txt -> sdk_library/public/mysdklibrary-removed.txt
1241.intermediates/mynewsdklibrary.stubs.exportable/android_common/combined/mynewsdklibrary.stubs.exportable.jar -> sdk_library/public/mynewsdklibrary-stubs.jar
1242.intermediates/mynewsdklibrary.stubs.source/android_common/exportable/mynewsdklibrary.stubs.source_api.txt -> sdk_library/public/mynewsdklibrary.txt
1243.intermediates/mynewsdklibrary.stubs.source/android_common/exportable/mynewsdklibrary.stubs.source_removed.txt -> sdk_library/public/mynewsdklibrary-removed.txt
1244`
1245
1246		// On tiramisu the stub flags should be generated from both mynewsdklibrary and mysdklibrary as
1247		// they are both part of the snapshot.
1248		expectedStubFlagsInputs := []string{
1249			"out/soong/.intermediates/mynewsdklibrary.stubs.exportable/android_common/dex/mynewsdklibrary.stubs.exportable.jar",
1250			"out/soong/.intermediates/mynewsdklibrary.impl/android_common/aligned/mynewsdklibrary.jar",
1251			"out/soong/.intermediates/mysdklibrary.stubs.exportable/android_common/dex/mysdklibrary.stubs.exportable.jar",
1252			"out/soong/.intermediates/mysdklibrary.impl/android_common/aligned/mysdklibrary.jar",
1253		}
1254
1255		testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "Tiramisu",
1256			expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "")
1257	})
1258}
1259
1260func TestSnapshotWithEmptyBootClasspathFragment(t *testing.T) {
1261	result := android.GroupFixturePreparers(
1262		prepareForSdkTestWithJava,
1263		java.PrepareForTestWithJavaDefaultModules,
1264		java.PrepareForTestWithJavaSdkLibraryFiles,
1265		java.FixtureWithLastReleaseApis("mysdklibrary", "mynewsdklibrary"),
1266		java.FixtureConfigureApexBootJars("myapex:mysdklibrary", "myapex:mynewsdklibrary"),
1267		prepareForSdkTestWithApex,
1268		// Add a platform_bootclasspath that depends on the fragment.
1269		fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
1270		android.FixtureMergeEnv(map[string]string{
1271			"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S",
1272		}),
1273		android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1274			variables.Platform_version_active_codenames = []string{"VanillaIceCream"}
1275		}),
1276		android.FixtureWithRootAndroidBp(`
1277			sdk {
1278				name: "mysdk",
1279				apexes: ["myapex"],
1280			}
1281			apex {
1282				name: "myapex",
1283				key: "myapex.key",
1284				min_sdk_version: "S",
1285				bootclasspath_fragments: ["mybootclasspathfragment"],
1286			}
1287			bootclasspath_fragment {
1288				name: "mybootclasspathfragment",
1289				apex_available: ["myapex"],
1290				contents: ["mysdklibrary", "mynewsdklibrary"],
1291				hidden_api: {
1292					split_packages: [],
1293				},
1294			}
1295			java_sdk_library {
1296				name: "mysdklibrary",
1297				apex_available: ["myapex"],
1298				srcs: ["Test.java"],
1299				shared_library: false,
1300				public: {enabled: true},
1301				min_sdk_version: "Tiramisu",
1302			}
1303			java_sdk_library {
1304				name: "mynewsdklibrary",
1305				apex_available: ["myapex"],
1306				srcs: ["Test.java"],
1307				compile_dex: true,
1308				public: {enabled: true},
1309				min_sdk_version: "Tiramisu",
1310				permitted_packages: ["mynewsdklibrary"],
1311			}
1312		`),
1313	).RunTest(t)
1314
1315	CheckSnapshot(t, result, "mysdk", "", checkAndroidBpContents(`// This is auto-generated. DO NOT EDIT.`))
1316}
1317