blob: 7048a15b7cd5d6b6b4866ccb8bcb2e512324d1a0 [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 Duffin8eb45732022-10-04 19:03:31 +010020 "strings"
Paul Duffin4a1d4512021-03-18 10:12:26 +000021 "testing"
22
23 "android/soong/android"
Paul Duffina57835e2021-04-19 13:23:06 +010024 "android/soong/java"
Paul Duffin4a1d4512021-03-18 10:12:26 +000025)
Paul Duffinf7f65da2021-03-10 15:00:46 +000026
Paul Duffin7c475152021-06-09 16:17:58 +010027// fixtureAddPlatformBootclasspathForBootclasspathFragment adds a platform_bootclasspath module that
28// references the bootclasspath fragment.
29func fixtureAddPlatformBootclasspathForBootclasspathFragment(apex, fragment string) android.FixturePreparer {
Jiakai Zhangb8796202023-03-06 19:16:48 +000030 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 {
Paul Duffin7c475152021-06-09 16:17:58 +010035 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 },
Jiakai Zhangb8796202023-03-06 19:16:48 +000045 %s
Paul Duffin7c475152021-06-09 16:17:58 +010046 ],
47 }
Jiakai Zhangb8796202023-03-06 19:16:48 +000048 `, apex, fragment, extraFragments)),
Paul Duffin7c475152021-06-09 16:17:58 +010049 android.FixtureAddFile("frameworks/base/config/boot-profile.txt", nil),
Jiakai Zhang49b1eb62021-11-26 18:09:27 +000050 android.FixtureAddFile("frameworks/base/config/boot-image-profile.txt", nil),
Paul Duffinc8ead412021-06-07 19:28:15 +010051 android.FixtureAddFile("build/soong/scripts/check_boot_jars/package_allowed_list.txt", nil),
Paul Duffin7c475152021-06-09 16:17:58 +010052 )
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
Paul Duffina57835e2021-04-19 13:23:06 +010074func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
75 result := android.GroupFixturePreparers(
76 prepareForSdkTestWithJava,
Jiakai Zhangb95998b2023-05-11 16:39:27 +010077 java.PrepareForTestWithDexpreopt,
Paul Duffina57835e2021-04-19 13:23:06 +010078 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 }),
Paul Duffin023dba02021-04-22 01:45:29 +010086
Paul Duffin7c475152021-06-09 16:17:58 +010087 // Add a platform_bootclasspath that depends on the fragment.
Jiakai Zhangb8796202023-03-06 19:16:48 +000088 fixtureAddPlatformBootclasspathForBootclasspathFragmentWithExtra(
Jiakai Zhangb69e8952023-07-11 14:31:22 +010089 "com.android.art", "art-bootclasspath-fragment", java.ApexBootJarFragmentsForPlatformBootclasspath),
Paul Duffin023dba02021-04-22 01:45:29 +010090
Paul Duffin8eb45732022-10-04 19:03:31 +010091 java.PrepareForBootImageConfigTest,
Jiakai Zhangb8796202023-03-06 19:16:48 +000092 java.PrepareApexBootJarConfigsAndModules,
Paul Duffina57835e2021-04-19 13:23:06 +010093 android.FixtureWithRootAndroidBp(`
94 sdk {
95 name: "mysdk",
Jiakai Zhangb69e8952023-07-11 14:31:22 +010096 bootclasspath_fragments: ["art-bootclasspath-fragment"],
Paul Duffina57835e2021-04-19 13:23:06 +010097 }
98
99 apex {
100 name: "com.android.art",
101 key: "com.android.art.key",
102 bootclasspath_fragments: [
Jiakai Zhangb69e8952023-07-11 14:31:22 +0100103 "art-bootclasspath-fragment",
Paul Duffina57835e2021-04-19 13:23:06 +0100104 ],
105 updatable: false,
106 }
107
108 bootclasspath_fragment {
Jiakai Zhangb69e8952023-07-11 14:31:22 +0100109 name: "art-bootclasspath-fragment",
Paul Duffina57835e2021-04-19 13:23:06 +0100110 image_name: "art",
Paul Duffin8eb45732022-10-04 19:03:31 +0100111 contents: ["core1", "core2"],
Paul Duffina57835e2021-04-19 13:23:06 +0100112 apex_available: ["com.android.art"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100113 hidden_api: {
114 split_packages: ["*"],
115 },
Paul Duffina57835e2021-04-19 13:23:06 +0100116 }
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 {
Paul Duffin8eb45732022-10-04 19:03:31 +0100125 name: "core1",
Paul Duffina57835e2021-04-19 13:23:06 +0100126 srcs: ["Test.java"],
127 system_modules: "none",
128 sdk_version: "none",
129 compile_dex: true,
130 apex_available: ["com.android.art"],
131 }
Paul Duffin8eb45732022-10-04 19:03:31 +0100132
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`),
Paul Duffina57835e2021-04-19 13:23:06 +0100142 ).RunTest(t)
143
Paul Duffin7c475152021-06-09 16:17:58 +0100144 // A preparer to update the test fixture used when processing an unpackage snapshot.
Jiakai Zhangb69e8952023-07-11 14:31:22 +0100145 preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("com.android.art", "art-bootclasspath-fragment")
Paul Duffin023dba02021-04-22 01:45:29 +0100146
Paul Duffin8eb45732022-10-04 19:03:31 +0100147 // Check that source on its own configures the bootImageConfig correctly.
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100148 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")
Paul Duffin8eb45732022-10-04 19:03:31 +0100150
Paul Duffina57835e2021-04-19 13:23:06 +0100151 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinb01ac4b2022-05-24 20:10:05 +0000152 checkAndroidBpContents(`
Paul Duffina57835e2021-04-19 13:23:06 +0100153// This is auto-generated. DO NOT EDIT.
154
Spandan Dasa5e26d32024-03-06 14:04:36 +0000155apex_contributions_defaults {
156 name: "mysdk.contributions",
157 contents: [],
158}
159
Paul Duffina57835e2021-04-19 13:23:06 +0100160prebuilt_bootclasspath_fragment {
Jiakai Zhangb69e8952023-07-11 14:31:22 +0100161 name: "art-bootclasspath-fragment",
Paul Duffina57835e2021-04-19 13:23:06 +0100162 prefer: false,
163 visibility: ["//visibility:public"],
164 apex_available: ["com.android.art"],
165 image_name: "art",
Paul Duffin8eb45732022-10-04 19:03:31 +0100166 contents: [
167 "core1",
168 "core2",
169 ],
Paul Duffinda286f42021-06-29 11:59:23 +0100170 hidden_api: {
Paul Duffinda286f42021-06-29 11:59:23 +0100171 annotation_flags: "hiddenapi/annotation-flags.csv",
172 metadata: "hiddenapi/metadata.csv",
173 index: "hiddenapi/index.csv",
Paul Duffin8d007e92021-07-22 12:00:49 +0100174 signature_patterns: "hiddenapi/signature-patterns.csv",
Paul Duffin191be3a2021-08-10 16:14:16 +0100175 filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
176 filtered_flags: "hiddenapi/filtered-flags.csv",
Paul Duffinda286f42021-06-29 11:59:23 +0100177 },
Paul Duffina57835e2021-04-19 13:23:06 +0100178}
179
180java_import {
Paul Duffin8eb45732022-10-04 19:03:31 +0100181 name: "core1",
Paul Duffina57835e2021-04-19 13:23:06 +0100182 prefer: false,
183 visibility: ["//visibility:public"],
184 apex_available: ["com.android.art"],
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000185 jars: ["java_boot_libs/snapshot/jars/are/invalid/core1.jar"],
Paul Duffin8eb45732022-10-04 19:03:31 +0100186}
187
188java_import {
189 name: "core2",
190 prefer: false,
191 visibility: ["//visibility:public"],
192 apex_available: ["com.android.art"],
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000193 jars: ["java_boot_libs/snapshot/jars/are/invalid/core2.jar"],
Paul Duffina57835e2021-04-19 13:23:06 +0100194}
Spandan Dasa5e26d32024-03-06 14:04:36 +0000195
Paul Duffina57835e2021-04-19 13:23:06 +0100196`),
Paul Duffina57835e2021-04-19 13:23:06 +0100197 checkAllCopyRules(`
Jiakai Zhangb69e8952023-07-11 14:31:22 +0100198.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
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000204.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
Paul Duffinda286f42021-06-29 11:59:23 +0100206 `),
Paul Duffin7c475152021-06-09 16:17:58 +0100207 snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
Paul Duffinc8ead412021-06-07 19:28:15 +0100208
209 // Check the behavior of the snapshot without the source.
210 snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) {
Paul Duffin8eb45732022-10-04 19:03:31 +0100211 // Make sure that the boot jars package check rule includes the dex jars retrieved from the prebuilt apex.
212 checkBootJarsPackageCheckRule(t, result,
Jiakai Zhangb8796202023-03-06 19:16:48 +0000213 append(
214 []string{
Spandan Das3576e762024-01-03 18:57:03 +0000215 "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",
Jiakai Zhangb8796202023-03-06 19:16:48 +0000217 "out/soong/.intermediates/default/java/framework/android_common/aligned/framework.jar",
218 },
219 java.ApexBootJarDexJarPaths...,
220 )...,
221 )
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100222 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")
Paul Duffinc8ead412021-06-07 19:28:15 +0100224 }),
225
Paul Duffin7c475152021-06-09 16:17:58 +0100226 snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
Paul Duffin8eb45732022-10-04 19:03:31 +0100227
228 // Check the behavior of the snapshot when the source is preferred.
229 snapshotTestChecker(checkSnapshotWithSourcePreferred, func(t *testing.T, result *android.TestResult) {
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100230 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")
Paul Duffin8eb45732022-10-04 19:03:31 +0100232 }),
233
Paul Duffin7c475152021-06-09 16:17:58 +0100234 snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
Paul Duffin8eb45732022-10-04 19:03:31 +0100235
236 // Check the behavior of the snapshot when it is preferred.
237 snapshotTestChecker(checkSnapshotPreferredWithSource, func(t *testing.T, result *android.TestResult) {
Jiakai Zhangcb13b5d2023-07-13 11:03:38 +0100238 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")
Paul Duffin8eb45732022-10-04 19:03:31 +0100240 }),
Paul Duffina57835e2021-04-19 13:23:06 +0100241 )
Paul Duffinc8ead412021-06-07 19:28:15 +0100242
Paul Duffin8eb45732022-10-04 19:03:31 +0100243 // Make sure that the boot jars package check rule includes the dex jars created from the source.
244 checkBootJarsPackageCheckRule(t, result,
Jiakai Zhangb8796202023-03-06 19:16:48 +0000245 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 )
Paul Duffinc8ead412021-06-07 19:28:15 +0100254}
255
256// checkBootJarsPackageCheckRule checks that the supplied module is an input to the boot jars
257// package check rule.
Paul Duffin8eb45732022-10-04 19:03:31 +0100258func checkBootJarsPackageCheckRule(t *testing.T, result *android.TestResult, expectedModules ...string) {
259 t.Helper()
Paul Duffinc8ead412021-06-07 19:28:15 +0100260 platformBcp := result.ModuleForTests("platform-bootclasspath", "android_common")
261 bootJarsCheckRule := platformBcp.Rule("boot_jars_package_check")
262 command := bootJarsCheckRule.RuleParams.Command
Paul Duffin8eb45732022-10-04 19:03:31 +0100263 expectedCommandArgs := " build/soong/scripts/check_boot_jars/package_allowed_list.txt " + strings.Join(expectedModules, " ") + " &&"
Paul Duffinc8ead412021-06-07 19:28:15 +0100264 android.AssertStringDoesContain(t, "boot jars package check", command, expectedCommandArgs)
Paul Duffina57835e2021-04-19 13:23:06 +0100265}
266
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000267func testSnapshotWithBootClasspathFragment_Contents(t *testing.T, sdk string, copyRules string) {
Paul Duffin4a1d4512021-03-18 10:12:26 +0000268 result := android.GroupFixturePreparers(
269 prepareForSdkTestWithJava,
Paul Duffin895c7142021-04-25 13:40:15 +0100270 java.PrepareForTestWithJavaDefaultModules,
271 java.PrepareForTestWithJavaSdkLibraryFiles,
Paul Duffina10bd3c2021-05-12 13:46:54 +0100272 java.FixtureWithLastReleaseApis("mysdklibrary", "myothersdklibrary", "mycoreplatform"),
satayevd604b212021-07-21 14:23:52 +0100273 java.FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:myothersdklibrary"),
Paul Duffin7c475152021-06-09 16:17:58 +0100274 prepareForSdkTestWithApex,
275
276 // Add a platform_bootclasspath that depends on the fragment.
277 fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
278
Jihoon Kangf55a5f72024-01-08 08:56:20 +0000279 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
280 variables.BuildFlags = map[string]string{
281 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
282 }
283 }),
Spandan Das81fe4d12024-05-15 18:43:47 +0000284 // 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 }),
Jihoon Kangf55a5f72024-01-08 08:56:20 +0000297
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000298 android.FixtureWithRootAndroidBp(sdk+`
Paul Duffin7c475152021-06-09 16:17:58 +0100299 apex {
300 name: "myapex",
301 key: "myapex.key",
302 min_sdk_version: "2",
303 bootclasspath_fragments: ["mybootclasspathfragment"],
304 }
305
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100306 bootclasspath_fragment {
307 name: "mybootclasspathfragment",
Paul Duffin7c475152021-06-09 16:17:58 +0100308 apex_available: ["myapex"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100309 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 ],
Paul Duffin895c7142021-04-25 13:40:15 +0100315 api: {
316 stub_libs: ["mysdklibrary"],
317 },
318 core_platform_api: {
Paul Duffina10bd3c2021-05-12 13:46:54 +0100319 // This should be automatically added to the sdk_snapshot as a java_sdk_libs module.
Paul Duffin895c7142021-04-25 13:40:15 +0100320 stub_libs: ["mycoreplatform"],
321 },
Paul Duffin9fd56472022-03-31 15:42:30 +0100322 hidden_api: {
323 split_packages: ["*"],
324 },
Paul Duffina57835e2021-04-19 13:23:06 +0100325 }
326
327 java_library {
328 name: "mybootlib",
Paul Duffin7c475152021-06-09 16:17:58 +0100329 apex_available: ["myapex"],
Paul Duffina57835e2021-04-19 13:23:06 +0100330 srcs: ["Test.java"],
331 system_modules: "none",
332 sdk_version: "none",
Paul Duffin7c475152021-06-09 16:17:58 +0100333 min_sdk_version: "2",
Paul Duffina57835e2021-04-19 13:23:06 +0100334 compile_dex: true,
Paul Duffin7c475152021-06-09 16:17:58 +0100335 permitted_packages: ["mybootlib"],
Paul Duffin4a1d4512021-03-18 10:12:26 +0000336 }
Paul Duffin895c7142021-04-25 13:40:15 +0100337
338 java_sdk_library {
339 name: "mysdklibrary",
Paul Duffin7c475152021-06-09 16:17:58 +0100340 apex_available: ["myapex"],
Paul Duffin895c7142021-04-25 13:40:15 +0100341 srcs: ["Test.java"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100342 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100343 public: {enabled: true},
Paul Duffin7c475152021-06-09 16:17:58 +0100344 min_sdk_version: "2",
Paul Duffin895c7142021-04-25 13:40:15 +0100345 }
346
347 java_sdk_library {
Paul Duffina10bd3c2021-05-12 13:46:54 +0100348 name: "myothersdklibrary",
Paul Duffin7c475152021-06-09 16:17:58 +0100349 apex_available: ["myapex"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100350 srcs: ["Test.java"],
Paul Duffinea8f8082021-06-24 13:25:57 +0100351 compile_dex: true,
Paul Duffina10bd3c2021-05-12 13:46:54 +0100352 public: {enabled: true},
Paul Duffin7c475152021-06-09 16:17:58 +0100353 min_sdk_version: "2",
354 permitted_packages: ["myothersdklibrary"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100355 }
356
357 java_sdk_library {
Paul Duffin895c7142021-04-25 13:40:15 +0100358 name: "mycoreplatform",
Paul Duffin7c475152021-06-09 16:17:58 +0100359 apex_available: ["myapex"],
Paul Duffin895c7142021-04-25 13:40:15 +0100360 srcs: ["Test.java"],
Paul Duffinea8f8082021-06-24 13:25:57 +0100361 compile_dex: true,
Paul Duffin895c7142021-04-25 13:40:15 +0100362 public: {enabled: true},
Paul Duffin7c475152021-06-09 16:17:58 +0100363 min_sdk_version: "2",
Paul Duffin895c7142021-04-25 13:40:15 +0100364 }
Paul Duffin4a1d4512021-03-18 10:12:26 +0000365 `),
366 ).RunTest(t)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000367
Paul Duffin7c475152021-06-09 16:17:58 +0100368 // A preparer to update the test fixture used when processing an unpackage snapshot.
369 preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")
370
Paul Duffin36474d32021-03-12 12:19:43 +0000371 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinb01ac4b2022-05-24 20:10:05 +0000372 checkAndroidBpContents(`
Paul Duffinf7f65da2021-03-10 15:00:46 +0000373// This is auto-generated. DO NOT EDIT.
374
Spandan Dasa5e26d32024-03-06 14:04:36 +0000375apex_contributions_defaults {
376 name: "mysdk.contributions",
377 contents: [
378 "prebuilt_myothersdklibrary",
379 "prebuilt_mysdklibrary",
380 "prebuilt_mycoreplatform",
381 ],
382}
383
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100384prebuilt_bootclasspath_fragment {
385 name: "mybootclasspathfragment",
Paul Duffinf7f65da2021-03-10 15:00:46 +0000386 prefer: false,
387 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100388 apex_available: ["myapex"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100389 contents: [
390 "mybootlib",
391 "myothersdklibrary",
392 ],
Paul Duffin895c7142021-04-25 13:40:15 +0100393 api: {
394 stub_libs: ["mysdklibrary"],
395 },
396 core_platform_api: {
397 stub_libs: ["mycoreplatform"],
398 },
Paul Duffin2fef1362021-04-15 13:32:00 +0100399 hidden_api: {
Paul Duffin2fef1362021-04-15 13:32:00 +0100400 annotation_flags: "hiddenapi/annotation-flags.csv",
401 metadata: "hiddenapi/metadata.csv",
402 index: "hiddenapi/index.csv",
Paul Duffin8d007e92021-07-22 12:00:49 +0100403 signature_patterns: "hiddenapi/signature-patterns.csv",
Paul Duffin191be3a2021-08-10 16:14:16 +0100404 filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
405 filtered_flags: "hiddenapi/filtered-flags.csv",
Paul Duffin2fef1362021-04-15 13:32:00 +0100406 },
Paul Duffina57835e2021-04-19 13:23:06 +0100407}
408
409java_import {
410 name: "mybootlib",
411 prefer: false,
412 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100413 apex_available: ["myapex"],
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000414 jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"],
Paul Duffinbb638eb2022-11-26 13:36:38 +0000415 min_sdk_version: "2",
Paul Duffin869de142021-07-15 14:14:41 +0100416 permitted_packages: ["mybootlib"],
Paul Duffinf7f65da2021-03-10 15:00:46 +0000417}
Paul Duffin895c7142021-04-25 13:40:15 +0100418
419java_sdk_library_import {
Paul Duffina10bd3c2021-05-12 13:46:54 +0100420 name: "myothersdklibrary",
421 prefer: false,
422 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100423 apex_available: ["myapex"],
Paul Duffinea8f8082021-06-24 13:25:57 +0100424 shared_library: true,
425 compile_dex: true,
Paul Duffin869de142021-07-15 14:14:41 +0100426 permitted_packages: ["myothersdklibrary"],
Paul Duffina10bd3c2021-05-12 13:46:54 +0100427 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 {
Paul Duffin895c7142021-04-25 13:40:15 +0100437 name: "mysdklibrary",
438 prefer: false,
439 visibility: ["//visibility:public"],
Paul Duffin7c475152021-06-09 16:17:58 +0100440 apex_available: ["myapex"],
Paul Duffinf4600f62021-05-13 22:34:45 +0100441 shared_library: false,
Paul Duffin895c7142021-04-25 13:40:15 +0100442 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"],
Paul Duffin7c475152021-06-09 16:17:58 +0100455 apex_available: ["myapex"],
Paul Duffinea8f8082021-06-24 13:25:57 +0100456 shared_library: true,
457 compile_dex: true,
Paul Duffin895c7142021-04-25 13:40:15 +0100458 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}
Paul Duffina10bd3c2021-05-12 13:46:54 +0100466 `),
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000467 checkAllCopyRules(copyRules),
Paul Duffin7c475152021-06-09 16:17:58 +0100468 snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
Paul Duffind061d402021-06-07 21:36:01 +0100469 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)
Paul Duffin630b11e2021-07-15 13:35:26 +0100490
Paul Duffin8d007e92021-07-22 12:00:49 +0100491 rule = module.Output("out/soong/hiddenapi/hiddenapi-flags.csv.valid")
Paul Duffin280bae62021-07-20 18:03:53 +0100492 android.AssertStringDoesContain(t, "verify-overlaps", rule.RuleParams.Command, " snapshot/hiddenapi/filtered-flags.csv:snapshot/hiddenapi/signature-patterns.csv ")
Paul Duffind061d402021-06-07 21:36:01 +0100493 }),
Paul Duffin7c475152021-06-09 16:17:58 +0100494 snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
Paul Duffin8d007e92021-07-22 12:00:49 +0100495 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")
Paul Duffin280bae62021-07-20 18:03:53 +0100498 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 ")
Paul Duffin8d007e92021-07-22 12:00:49 +0100499 }),
Paul Duffin7c475152021-06-09 16:17:58 +0100500 snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
501 )
Paul Duffinf7f65da2021-03-10 15:00:46 +0000502}
Paul Duffin04b4a192021-03-18 11:05:31 +0000503
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000504func 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
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000525.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
Jihoon Kangf55a5f72024-01-08 08:56:20 +0000526.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
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000535`)
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
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000545.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
Jihoon Kangf55a5f72024-01-08 08:56:20 +0000546.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
Paul Duffin4e7d1c42022-05-13 13:12:19 +0000555`
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
Paul Duffin51227d82021-05-18 12:54:27 +0100587// 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"),
satayevabcd5972021-08-06 17:49:46 +0100595 java.FixtureConfigureApexBootJars("someapex:mysdklibrary", "myotherapex:myotherlib"),
Paul Duffin51227d82021-05-18 12:54:27 +0100596 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 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100619 hidden_api: {
620 split_packages: ["*"],
621 },
Paul Duffin51227d82021-05-18 12:54:27 +0100622 }
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 ],
Paul Duffin9fd56472022-03-31 15:42:30 +0100651 hidden_api: {
652 split_packages: ["*"],
653 },
Paul Duffin51227d82021-05-18 12:54:27 +0100654 }
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", "",
Paul Duffinb01ac4b2022-05-24 20:10:05 +0000670 checkAndroidBpContents(`
Paul Duffin51227d82021-05-18 12:54:27 +0100671// This is auto-generated. DO NOT EDIT.
672
Spandan Dasa5e26d32024-03-06 14:04:36 +0000673apex_contributions_defaults {
674 name: "mysdk.contributions",
675 contents: ["prebuilt_mysdklibrary"],
676}
677
Paul Duffin51227d82021-05-18 12:54:27 +0100678prebuilt_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: {
Paul Duffin51227d82021-05-18 12:54:27 +0100691 annotation_flags: "hiddenapi/annotation-flags.csv",
692 metadata: "hiddenapi/metadata.csv",
693 index: "hiddenapi/index.csv",
Paul Duffin8d007e92021-07-22 12:00:49 +0100694 signature_patterns: "hiddenapi/signature-patterns.csv",
Paul Duffin191be3a2021-08-10 16:14:16 +0100695 filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
696 filtered_flags: "hiddenapi/filtered-flags.csv",
Paul Duffin51227d82021-05-18 12:54:27 +0100697 },
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
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100721// Test that bootclasspath_fragment works with sdk.
722func TestBasicSdkWithBootclasspathFragment(t *testing.T) {
Paul Duffin04b4a192021-03-18 11:05:31 +0000723 android.GroupFixturePreparers(
724 prepareForSdkTestWithApex,
725 prepareForSdkTestWithJava,
Paul Duffin80e7f732022-11-25 12:31:31 +0000726 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 }),
Paul Duffin04b4a192021-03-18 11:05:31 +0000735 android.FixtureWithRootAndroidBp(`
736 sdk {
737 name: "mysdk",
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100738 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000739 }
740
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100741 bootclasspath_fragment {
742 name: "mybootclasspathfragment",
Paul Duffin04b4a192021-03-18 11:05:31 +0000743 image_name: "art",
Paul Duffin8018e502021-05-21 19:28:09 +0100744 contents: ["mybootlib"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000745 apex_available: ["myapex"],
Paul Duffin9fd56472022-03-31 15:42:30 +0100746 hidden_api: {
747 split_packages: ["*"],
748 },
Paul Duffin04b4a192021-03-18 11:05:31 +0000749 }
750
Paul Duffin8018e502021-05-21 19:28:09 +0100751 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
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100761 prebuilt_bootclasspath_fragment {
Paul Duffin80e7f732022-11-25 12:31:31 +0000762 name: "mybootclasspathfragment",
Paul Duffin04b4a192021-03-18 11:05:31 +0000763 prefer: false,
764 visibility: ["//visibility:public"],
765 apex_available: [
766 "myapex",
767 ],
768 image_name: "art",
Paul Duffin80e7f732022-11-25 12:31:31 +0000769 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 },
Paul Duffin8018e502021-05-21 19:28:09 +0100778 }
779
780 java_import {
Paul Duffin80e7f732022-11-25 12:31:31 +0000781 name: "mybootlib",
Paul Duffin8018e502021-05-21 19:28:09 +0100782 visibility: ["//visibility:public"],
783 apex_available: ["com.android.art"],
784 jars: ["java/mybootlib.jar"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000785 }
786 `),
787 ).RunTest(t)
788}
Paul Duffin7c955552021-04-19 13:23:53 +0100789
790func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
791 result := android.GroupFixturePreparers(
792 prepareForSdkTestWithJava,
Paul Duffin475daaf2021-05-13 00:57:55 +0100793 java.PrepareForTestWithJavaDefaultModules,
794 java.PrepareForTestWithJavaSdkLibraryFiles,
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000795 java.FixtureWithLastReleaseApis("mysdklibrary", "mynewlibrary"),
796 java.FixtureConfigureApexBootJars("myapex:mybootlib", "myapex:mynewlibrary"),
Paul Duffin475daaf2021-05-13 00:57:55 +0100797 prepareForSdkTestWithApex,
Paul Duffin7c475152021-06-09 16:17:58 +0100798
799 // Add a platform_bootclasspath that depends on the fragment.
800 fixtureAddPlatformBootclasspathForBootclasspathFragment("myapex", "mybootclasspathfragment"),
801
Jihoon Kangf55a5f72024-01-08 08:56:20 +0000802 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
803 variables.BuildFlags = map[string]string{
804 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
805 }
806 }),
807
Paul Duffin7c955552021-04-19 13:23:53 +0100808 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,
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000817 "my-new-max-target-q.txt": nil,
Paul Duffin7c955552021-04-19 13:23:53 +0100818 }.AddToFixture(),
819 android.FixtureWithRootAndroidBp(`
820 sdk {
821 name: "mysdk",
822 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin7c955552021-04-19 13:23:53 +0100823 }
824
Paul Duffin475daaf2021-05-13 00:57:55 +0100825 apex {
826 name: "myapex",
827 key: "myapex.key",
828 min_sdk_version: "1",
829 bootclasspath_fragments: ["mybootclasspathfragment"],
830 }
831
Paul Duffin7c955552021-04-19 13:23:53 +0100832 bootclasspath_fragment {
833 name: "mybootclasspathfragment",
Paul Duffin475daaf2021-05-13 00:57:55 +0100834 apex_available: ["myapex"],
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000835 contents: ["mybootlib", "mynewlibrary"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100836 api: {
837 stub_libs: ["mysdklibrary"],
838 },
Paul Duffin7c955552021-04-19 13:23:53 +0100839 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 ],
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000864 split_packages: ["sdklibrary"],
865 package_prefixes: ["sdklibrary.all.mine"],
866 single_packages: ["sdklibrary.mine"],
Paul Duffin7c955552021-04-19 13:23:53 +0100867 },
868 }
869
870 java_library {
871 name: "mybootlib",
Paul Duffin475daaf2021-05-13 00:57:55 +0100872 apex_available: ["myapex"],
Paul Duffin7c955552021-04-19 13:23:53 +0100873 srcs: ["Test.java"],
874 system_modules: "none",
875 sdk_version: "none",
Paul Duffin475daaf2021-05-13 00:57:55 +0100876 min_sdk_version: "1",
Paul Duffin7c955552021-04-19 13:23:53 +0100877 compile_dex: true,
Paul Duffin7c475152021-06-09 16:17:58 +0100878 permitted_packages: ["mybootlib"],
Paul Duffin7c955552021-04-19 13:23:53 +0100879 }
Paul Duffin475daaf2021-05-13 00:57:55 +0100880
881 java_sdk_library {
882 name: "mysdklibrary",
883 srcs: ["Test.java"],
884 compile_dex: true,
885 public: {enabled: true},
Paul Duffin869de142021-07-15 14:14:41 +0100886 permitted_packages: ["mysdklibrary"],
Spandan Das91455082023-03-02 04:41:35 +0000887 min_sdk_version: "current",
Paul Duffin475daaf2021-05-13 00:57:55 +0100888 }
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000889
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 }
Paul Duffin7c955552021-04-19 13:23:53 +0100907 `),
908 ).RunTest(t)
909
Paul Duffin7c475152021-06-09 16:17:58 +0100910 // A preparer to update the test fixture used when processing an unpackage snapshot.
911 preparerForSnapshot := fixtureAddPrebuiltApexForBootclasspathFragment("myapex", "mybootclasspathfragment")
912
Paul Duffin7c955552021-04-19 13:23:53 +0100913 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinb01ac4b2022-05-24 20:10:05 +0000914 checkAndroidBpContents(`
Paul Duffin7c955552021-04-19 13:23:53 +0100915// This is auto-generated. DO NOT EDIT.
916
Spandan Dasa5e26d32024-03-06 14:04:36 +0000917apex_contributions_defaults {
918 name: "mysdk.contributions",
919 contents: [
920 "prebuilt_mynewlibrary",
921 "prebuilt_mysdklibrary",
922 ],
923}
924
Paul Duffin7c955552021-04-19 13:23:53 +0100925prebuilt_bootclasspath_fragment {
926 name: "mybootclasspathfragment",
927 prefer: false,
928 visibility: ["//visibility:public"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100929 apex_available: ["myapex"],
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000930 contents: [
931 "mybootlib",
932 "mynewlibrary",
933 ],
Paul Duffin475daaf2021-05-13 00:57:55 +0100934 api: {
935 stub_libs: ["mysdklibrary"],
936 },
Paul Duffin7c955552021-04-19 13:23:53 +0100937 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"],
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000941 max_target_q: [
942 "hiddenapi/my-max-target-q.txt",
943 "hiddenapi/my-new-max-target-q.txt",
944 ],
Paul Duffin7c955552021-04-19 13:23:53 +0100945 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"],
Paul Duffin2fef1362021-04-15 13:32:00 +0100949 annotation_flags: "hiddenapi/annotation-flags.csv",
950 metadata: "hiddenapi/metadata.csv",
951 index: "hiddenapi/index.csv",
Paul Duffin8d007e92021-07-22 12:00:49 +0100952 signature_patterns: "hiddenapi/signature-patterns.csv",
Paul Duffin191be3a2021-08-10 16:14:16 +0100953 filtered_stub_flags: "hiddenapi/filtered-stub-flags.csv",
954 filtered_flags: "hiddenapi/filtered-flags.csv",
Paul Duffin7c955552021-04-19 13:23:53 +0100955 },
956}
957
958java_import {
959 name: "mybootlib",
960 prefer: false,
961 visibility: ["//visibility:public"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100962 apex_available: ["myapex"],
Paul Duffin7ed6ff82022-11-21 10:57:30 +0000963 jars: ["java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar"],
Paul Duffinbb638eb2022-11-26 13:36:38 +0000964 min_sdk_version: "1",
Paul Duffin869de142021-07-15 14:14:41 +0100965 permitted_packages: ["mybootlib"],
Paul Duffin7c955552021-04-19 13:23:53 +0100966}
Paul Duffin475daaf2021-05-13 00:57:55 +0100967
968java_sdk_library_import {
Paul Duffin3f1ae0b2022-07-27 16:27:42 +0000969 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 {
Paul Duffin475daaf2021-05-13 00:57:55 +0100986 name: "mysdklibrary",
987 prefer: false,
988 visibility: ["//visibility:public"],
989 apex_available: ["//apex_available:platform"],
990 shared_library: true,
991 compile_dex: true,
Paul Duffin869de142021-07-15 14:14:41 +0100992 permitted_packages: ["mysdklibrary"],
Paul Duffin475daaf2021-05-13 00:57:55 +0100993 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}
Paul Duffin7c955552021-04-19 13:23:53 +01001001`),
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
Paul Duffin3f1ae0b2022-07-27 16:27:42 +00001007my-new-max-target-q.txt -> hiddenapi/my-new-max-target-q.txt
Paul Duffin7c955552021-04-19 13:23:53 +01001008my-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
Paul Duffin2fef1362021-04-15 13:32:00 +01001012.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
Paul Duffin8d007e92021-07-22 12:00:49 +01001015.intermediates/mybootclasspathfragment/android_common/modular-hiddenapi/signature-patterns.csv -> hiddenapi/signature-patterns.csv
Paul Duffin280bae62021-07-20 18:03:53 +01001016.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
Paul Duffin7ed6ff82022-11-21 10:57:30 +00001018.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/mybootlib.jar
Jihoon Kangf55a5f72024-01-08 08:56:20 +00001019.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
Paul Duffin7c955552021-04-19 13:23:53 +01001025`),
Paul Duffin7c475152021-06-09 16:17:58 +01001026 snapshotTestPreparer(checkSnapshotWithoutSource, preparerForSnapshot),
1027 snapshotTestPreparer(checkSnapshotWithSourcePreferred, preparerForSnapshot),
1028 snapshotTestPreparer(checkSnapshotPreferredWithSource, preparerForSnapshot),
Paul Duffin7c955552021-04-19 13:23:53 +01001029 )
1030}
Paul Duffin1938dba2022-07-26 23:53:00 +00001031
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 }),
Spandan Dasa5e26d32024-03-06 14:04:36 +00001052 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1053 variables.Platform_version_active_codenames = []string{"VanillaIceCream"}
1054 }),
Paul Duffin1938dba2022-07-26 23:53:00 +00001055
Jihoon Kangbd093452023-12-26 19:08:01 +00001056 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1057 variables.BuildFlags = map[string]string{
1058 "RELEASE_HIDDEN_API_EXPORTABLE_STUBS": "true",
1059 }
1060 }),
1061
Paul Duffin1938dba2022-07-26 23:53:00 +00001062 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")
Jihoon Kanga3a05462024-04-05 00:36:44 +00001111 android.AssertPathsRelativeToTopEquals(t, "stub flags inputs", android.SortedUniqueStrings(expectedStubFlagsInputs), android.SortedUniquePaths(rule.Implicits))
Paul Duffin1938dba2022-07-26 23:53:00 +00001112
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
Jihoon Kangf55a5f72024-01-08 08:56:20 +00001160.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
Paul Duffin1938dba2022-07-26 23:53:00 +00001163`
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{
Jihoon Kangbd093452023-12-26 19:08:01 +00001168 "out/soong/.intermediates/mysdklibrary.stubs.exportable/android_common/dex/mysdklibrary.stubs.exportable.jar",
Jihoon Kanga3a05462024-04-05 00:36:44 +00001169 "out/soong/.intermediates/mysdklibrary.impl/android_common/aligned/mysdklibrary.jar",
Paul Duffin1938dba2022-07-26 23:53:00 +00001170 }
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
Jihoon Kangf55a5f72024-01-08 08:56:20 +00001238.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
Paul Duffin1938dba2022-07-26 23:53:00 +00001244`
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{
Jihoon Kangbd093452023-12-26 19:08:01 +00001249 "out/soong/.intermediates/mynewsdklibrary.stubs.exportable/android_common/dex/mynewsdklibrary.stubs.exportable.jar",
Jihoon Kanga3a05462024-04-05 00:36:44 +00001250 "out/soong/.intermediates/mynewsdklibrary.impl/android_common/aligned/mynewsdklibrary.jar",
Jihoon Kangbd093452023-12-26 19:08:01 +00001251 "out/soong/.intermediates/mysdklibrary.stubs.exportable/android_common/dex/mysdklibrary.stubs.exportable.jar",
Jihoon Kanga3a05462024-04-05 00:36:44 +00001252 "out/soong/.intermediates/mysdklibrary.impl/android_common/aligned/mysdklibrary.jar",
Paul Duffin1938dba2022-07-26 23:53:00 +00001253 }
1254
1255 testSnapshotWithBootClasspathFragment_MinSdkVersion(t, "Tiramisu",
1256 expectedSnapshot, expectedCopyRules, expectedStubFlagsInputs, "")
1257 })
1258}
Sam Delmerico35881362023-06-30 14:40:10 -04001259
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 }),
Spandan Dasa5e26d32024-03-06 14:04:36 +00001273 android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
1274 variables.Platform_version_active_codenames = []string{"VanillaIceCream"}
1275 }),
Sam Delmerico35881362023-06-30 14:40:10 -04001276 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}