blob: 0ce4351eb9f1be846df04c422fe0f5977822c772 [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 (
18 "testing"
19
20 "android/soong/android"
Paul Duffina57835e2021-04-19 13:23:06 +010021 "android/soong/java"
Paul Duffin4a1d4512021-03-18 10:12:26 +000022)
Paul Duffinf7f65da2021-03-10 15:00:46 +000023
Paul Duffina57835e2021-04-19 13:23:06 +010024func TestSnapshotWithBootclasspathFragment_ImageName(t *testing.T) {
25 result := android.GroupFixturePreparers(
26 prepareForSdkTestWithJava,
27 prepareForSdkTestWithApex,
28
29 // Some additional files needed for the art apex.
30 android.FixtureMergeMockFs(android.MockFS{
31 "com.android.art.avbpubkey": nil,
32 "com.android.art.pem": nil,
33 "system/sepolicy/apex/com.android.art-file_contexts": nil,
34 }),
35 java.FixtureConfigureBootJars("com.android.art:mybootlib"),
36 android.FixtureWithRootAndroidBp(`
37 sdk {
38 name: "mysdk",
39 bootclasspath_fragments: ["mybootclasspathfragment"],
40 java_boot_libs: ["mybootlib"],
41 }
42
43 apex {
44 name: "com.android.art",
45 key: "com.android.art.key",
46 bootclasspath_fragments: [
47 "mybootclasspathfragment",
48 ],
49 updatable: false,
50 }
51
52 bootclasspath_fragment {
53 name: "mybootclasspathfragment",
54 image_name: "art",
55 apex_available: ["com.android.art"],
56 }
57
58 apex_key {
59 name: "com.android.art.key",
60 public_key: "com.android.art.avbpubkey",
61 private_key: "com.android.art.pem",
62 }
63
64 java_library {
65 name: "mybootlib",
66 srcs: ["Test.java"],
67 system_modules: "none",
68 sdk_version: "none",
69 compile_dex: true,
70 apex_available: ["com.android.art"],
71 }
72 `),
73 ).RunTest(t)
74
75 CheckSnapshot(t, result, "mysdk", "",
76 checkUnversionedAndroidBpContents(`
77// This is auto-generated. DO NOT EDIT.
78
79prebuilt_bootclasspath_fragment {
80 name: "mybootclasspathfragment",
81 prefer: false,
82 visibility: ["//visibility:public"],
83 apex_available: ["com.android.art"],
84 image_name: "art",
85}
86
87java_import {
88 name: "mybootlib",
89 prefer: false,
90 visibility: ["//visibility:public"],
91 apex_available: ["com.android.art"],
92 jars: ["java/mybootlib.jar"],
93}
94`),
95 checkVersionedAndroidBpContents(`
96// This is auto-generated. DO NOT EDIT.
97
98prebuilt_bootclasspath_fragment {
99 name: "mysdk_mybootclasspathfragment@current",
100 sdk_member_name: "mybootclasspathfragment",
101 visibility: ["//visibility:public"],
102 apex_available: ["com.android.art"],
103 image_name: "art",
104}
105
106java_import {
107 name: "mysdk_mybootlib@current",
108 sdk_member_name: "mybootlib",
109 visibility: ["//visibility:public"],
110 apex_available: ["com.android.art"],
111 jars: ["java/mybootlib.jar"],
112}
113
114sdk_snapshot {
115 name: "mysdk@current",
116 visibility: ["//visibility:public"],
117 bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
118 java_boot_libs: ["mysdk_mybootlib@current"],
119}
120`),
121 checkAllCopyRules(`
122.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
123`),
124 snapshotTestPreparer(checkSnapshotPreferredWithSource, android.GroupFixturePreparers(
125 android.FixtureAddTextFile("prebuilts/apex/Android.bp", `
126 prebuilt_apex {
127 name: "com.android.art",
128 src: "art.apex",
129 exported_java_libs: [
130 "mybootlib",
131 ],
132 }
133 `),
134 android.FixtureAddFile("prebuilts/apex/art.apex", nil),
135 ),
136 ),
137 )
138}
139
140func TestSnapshotWithBootClasspathFragment_Contents(t *testing.T) {
Paul Duffin4a1d4512021-03-18 10:12:26 +0000141 result := android.GroupFixturePreparers(
142 prepareForSdkTestWithJava,
143 android.FixtureWithRootAndroidBp(`
144 sdk {
145 name: "mysdk",
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100146 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffina57835e2021-04-19 13:23:06 +0100147 java_boot_libs: ["mybootlib"],
Paul Duffin4a1d4512021-03-18 10:12:26 +0000148 }
Paul Duffinf7f65da2021-03-10 15:00:46 +0000149
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100150 bootclasspath_fragment {
151 name: "mybootclasspathfragment",
Paul Duffina57835e2021-04-19 13:23:06 +0100152 contents: ["mybootlib"],
153 }
154
155 java_library {
156 name: "mybootlib",
157 srcs: ["Test.java"],
158 system_modules: "none",
159 sdk_version: "none",
160 compile_dex: true,
Paul Duffin4a1d4512021-03-18 10:12:26 +0000161 }
162 `),
163 ).RunTest(t)
Paul Duffinf7f65da2021-03-10 15:00:46 +0000164
Paul Duffin36474d32021-03-12 12:19:43 +0000165 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinf7f65da2021-03-10 15:00:46 +0000166 checkUnversionedAndroidBpContents(`
167// This is auto-generated. DO NOT EDIT.
168
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100169prebuilt_bootclasspath_fragment {
170 name: "mybootclasspathfragment",
Paul Duffinf7f65da2021-03-10 15:00:46 +0000171 prefer: false,
172 visibility: ["//visibility:public"],
173 apex_available: ["//apex_available:platform"],
Paul Duffina57835e2021-04-19 13:23:06 +0100174 contents: ["mybootlib"],
175}
176
177java_import {
178 name: "mybootlib",
179 prefer: false,
180 visibility: ["//visibility:public"],
181 apex_available: ["//apex_available:platform"],
182 jars: ["java/mybootlib.jar"],
Paul Duffinf7f65da2021-03-10 15:00:46 +0000183}
184`),
185 checkVersionedAndroidBpContents(`
186// This is auto-generated. DO NOT EDIT.
187
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100188prebuilt_bootclasspath_fragment {
189 name: "mysdk_mybootclasspathfragment@current",
190 sdk_member_name: "mybootclasspathfragment",
Paul Duffinf7f65da2021-03-10 15:00:46 +0000191 visibility: ["//visibility:public"],
192 apex_available: ["//apex_available:platform"],
Paul Duffina57835e2021-04-19 13:23:06 +0100193 contents: ["mysdk_mybootlib@current"],
194}
195
196java_import {
197 name: "mysdk_mybootlib@current",
198 sdk_member_name: "mybootlib",
199 visibility: ["//visibility:public"],
200 apex_available: ["//apex_available:platform"],
201 jars: ["java/mybootlib.jar"],
Paul Duffinf7f65da2021-03-10 15:00:46 +0000202}
203
204sdk_snapshot {
205 name: "mysdk@current",
206 visibility: ["//visibility:public"],
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100207 bootclasspath_fragments: ["mysdk_mybootclasspathfragment@current"],
Paul Duffina57835e2021-04-19 13:23:06 +0100208 java_boot_libs: ["mysdk_mybootlib@current"],
Paul Duffinf7f65da2021-03-10 15:00:46 +0000209}
210`),
Paul Duffina57835e2021-04-19 13:23:06 +0100211 checkAllCopyRules(`
212.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
213`))
Paul Duffinf7f65da2021-03-10 15:00:46 +0000214}
Paul Duffin04b4a192021-03-18 11:05:31 +0000215
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100216// Test that bootclasspath_fragment works with sdk.
217func TestBasicSdkWithBootclasspathFragment(t *testing.T) {
Paul Duffin04b4a192021-03-18 11:05:31 +0000218 android.GroupFixturePreparers(
219 prepareForSdkTestWithApex,
220 prepareForSdkTestWithJava,
221 android.FixtureWithRootAndroidBp(`
222 sdk {
223 name: "mysdk",
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100224 bootclasspath_fragments: ["mybootclasspathfragment"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000225 }
226
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100227 bootclasspath_fragment {
228 name: "mybootclasspathfragment",
Paul Duffin04b4a192021-03-18 11:05:31 +0000229 image_name: "art",
230 apex_available: ["myapex"],
231 }
232
233 sdk_snapshot {
234 name: "mysdk@1",
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100235 bootclasspath_fragments: ["mybootclasspathfragment_mysdk_1"],
Paul Duffin04b4a192021-03-18 11:05:31 +0000236 }
237
Paul Duffin0b28a8d2021-04-21 23:38:34 +0100238 prebuilt_bootclasspath_fragment {
239 name: "mybootclasspathfragment_mysdk_1",
240 sdk_member_name: "mybootclasspathfragment",
Paul Duffin04b4a192021-03-18 11:05:31 +0000241 prefer: false,
242 visibility: ["//visibility:public"],
243 apex_available: [
244 "myapex",
245 ],
246 image_name: "art",
247 }
248 `),
249 ).RunTest(t)
250}
Paul Duffin7c955552021-04-19 13:23:53 +0100251
252func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) {
253 result := android.GroupFixturePreparers(
254 prepareForSdkTestWithJava,
255 android.MockFS{
256 "my-blocked.txt": nil,
257 "my-max-target-o-low-priority.txt": nil,
258 "my-max-target-p.txt": nil,
259 "my-max-target-q.txt": nil,
260 "my-max-target-r-low-priority.txt": nil,
261 "my-removed.txt": nil,
262 "my-unsupported-packages.txt": nil,
263 "my-unsupported.txt": nil,
264 }.AddToFixture(),
265 android.FixtureWithRootAndroidBp(`
266 sdk {
267 name: "mysdk",
268 bootclasspath_fragments: ["mybootclasspathfragment"],
269 java_boot_libs: ["mybootlib"],
270 }
271
272 bootclasspath_fragment {
273 name: "mybootclasspathfragment",
274 contents: ["mybootlib"],
275 hidden_api: {
276 unsupported: [
277 "my-unsupported.txt",
278 ],
279 removed: [
280 "my-removed.txt",
281 ],
282 max_target_r_low_priority: [
283 "my-max-target-r-low-priority.txt",
284 ],
285 max_target_q: [
286 "my-max-target-q.txt",
287 ],
288 max_target_p: [
289 "my-max-target-p.txt",
290 ],
291 max_target_o_low_priority: [
292 "my-max-target-o-low-priority.txt",
293 ],
294 blocked: [
295 "my-blocked.txt",
296 ],
297 unsupported_packages: [
298 "my-unsupported-packages.txt",
299 ],
300 },
301 }
302
303 java_library {
304 name: "mybootlib",
305 srcs: ["Test.java"],
306 system_modules: "none",
307 sdk_version: "none",
308 compile_dex: true,
309 }
310 `),
311 ).RunTest(t)
312
313 CheckSnapshot(t, result, "mysdk", "",
314 checkUnversionedAndroidBpContents(`
315// This is auto-generated. DO NOT EDIT.
316
317prebuilt_bootclasspath_fragment {
318 name: "mybootclasspathfragment",
319 prefer: false,
320 visibility: ["//visibility:public"],
321 apex_available: ["//apex_available:platform"],
322 contents: ["mybootlib"],
323 hidden_api: {
324 unsupported: ["hiddenapi/my-unsupported.txt"],
325 removed: ["hiddenapi/my-removed.txt"],
326 max_target_r_low_priority: ["hiddenapi/my-max-target-r-low-priority.txt"],
327 max_target_q: ["hiddenapi/my-max-target-q.txt"],
328 max_target_p: ["hiddenapi/my-max-target-p.txt"],
329 max_target_o_low_priority: ["hiddenapi/my-max-target-o-low-priority.txt"],
330 blocked: ["hiddenapi/my-blocked.txt"],
331 unsupported_packages: ["hiddenapi/my-unsupported-packages.txt"],
332 },
333}
334
335java_import {
336 name: "mybootlib",
337 prefer: false,
338 visibility: ["//visibility:public"],
339 apex_available: ["//apex_available:platform"],
340 jars: ["java/mybootlib.jar"],
341}
342`),
343 checkAllCopyRules(`
344my-unsupported.txt -> hiddenapi/my-unsupported.txt
345my-removed.txt -> hiddenapi/my-removed.txt
346my-max-target-r-low-priority.txt -> hiddenapi/my-max-target-r-low-priority.txt
347my-max-target-q.txt -> hiddenapi/my-max-target-q.txt
348my-max-target-p.txt -> hiddenapi/my-max-target-p.txt
349my-max-target-o-low-priority.txt -> hiddenapi/my-max-target-o-low-priority.txt
350my-blocked.txt -> hiddenapi/my-blocked.txt
351my-unsupported-packages.txt -> hiddenapi/my-unsupported-packages.txt
352.intermediates/mybootlib/android_common/javac/mybootlib.jar -> java/mybootlib.jar
353`),
354 )
355}