blob: 7db56c4c7f0486da3f7d53a05455cda85a01ea9b [file] [log] [blame]
Paul Duffina80fdec2019-12-03 15:25:00 +00001// Copyright (C) 2019 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 "testing"
19
Paul Duffin1356d8c2020-02-25 19:26:33 +000020 "android/soong/android"
Paul Duffina80fdec2019-12-03 15:25:00 +000021 "android/soong/cc"
22)
23
Paul Duffind835daa2019-11-30 17:49:09 +000024func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
25 t.Helper()
26
27 fs := map[string][]byte{
Paul Duffina04c1072020-03-02 10:16:35 +000028 "Test.cpp": nil,
29 "include/Test.h": nil,
30 "include-android/AndroidTest.h": nil,
31 "include-host/HostTest.h": nil,
32 "arm64/include/Arm64Test.h": nil,
33 "libfoo.so": nil,
34 "aidl/foo/bar/Test.aidl": nil,
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +010035 "some/where/stubslib.map.txt": nil,
Paul Duffind835daa2019-11-30 17:49:09 +000036 }
37 return testSdkWithFs(t, bp, fs)
38}
39
Paul Duffina80fdec2019-12-03 15:25:00 +000040// Contains tests for SDK members provided by the cc package.
41
42func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000043 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000044 sdk {
45 name: "mysdk",
46 native_shared_libs: ["sdkmember"],
47 }
48
49 cc_library_shared {
50 name: "sdkmember",
51 srcs: ["Test.cpp"],
Paul Duffina80fdec2019-12-03 15:25:00 +000052 stl: "none",
53 }
54 `)
55
Colin Cross7113d202019-11-20 16:39:12 -080056 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
57 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
Paul Duffina80fdec2019-12-03 15:25:00 +000058
59 var inputs []string
Paul Duffin1356d8c2020-02-25 19:26:33 +000060 buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
Paul Duffina80fdec2019-12-03 15:25:00 +000061 for _, bp := range buildParams {
62 if bp.Input != nil {
63 inputs = append(inputs, bp.Input.String())
64 }
65 }
66
67 // ensure that both 32/64 outputs are inputs of the sdk snapshot
68 ensureListContains(t, inputs, armOutput.String())
69 ensureListContains(t, inputs, arm64Output.String())
70}
71
72func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000073 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000074 sdk {
75 name: "mysdk",
76 native_shared_libs: ["sdkmember"],
77 }
78
Paul Duffina0843f62019-12-13 19:50:38 +000079 cc_library_shared {
80 name: "sdkmember",
Colin Crossf9aabd72020-02-15 11:29:50 -080081 system_shared_libs: [],
Martin Stjernholmcc776012020-07-07 03:22:21 +010082 stl: "none",
83 apex_available: ["mysdkapex"],
Paul Duffina0843f62019-12-13 19:50:38 +000084 }
85
Paul Duffina80fdec2019-12-03 15:25:00 +000086 sdk_snapshot {
87 name: "mysdk@1",
88 native_shared_libs: ["sdkmember_mysdk_1"],
89 }
90
91 sdk_snapshot {
92 name: "mysdk@2",
93 native_shared_libs: ["sdkmember_mysdk_2"],
94 }
95
96 cc_prebuilt_library_shared {
97 name: "sdkmember",
98 srcs: ["libfoo.so"],
99 prefer: false,
100 system_shared_libs: [],
101 stl: "none",
102 }
103
104 cc_prebuilt_library_shared {
105 name: "sdkmember_mysdk_1",
106 sdk_member_name: "sdkmember",
107 srcs: ["libfoo.so"],
108 system_shared_libs: [],
109 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000110 // TODO: remove //apex_available:platform
111 apex_available: [
112 "//apex_available:platform",
113 "myapex",
114 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000115 }
116
117 cc_prebuilt_library_shared {
118 name: "sdkmember_mysdk_2",
119 sdk_member_name: "sdkmember",
120 srcs: ["libfoo.so"],
121 system_shared_libs: [],
122 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000123 // TODO: remove //apex_available:platform
124 apex_available: [
125 "//apex_available:platform",
126 "myapex2",
127 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000128 }
129
130 cc_library_shared {
131 name: "mycpplib",
132 srcs: ["Test.cpp"],
133 shared_libs: ["sdkmember"],
134 system_shared_libs: [],
135 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000136 apex_available: [
137 "myapex",
138 "myapex2",
139 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000140 }
141
142 apex {
143 name: "myapex",
144 native_shared_libs: ["mycpplib"],
145 uses_sdks: ["mysdk@1"],
146 key: "myapex.key",
147 certificate: ":myapex.cert",
148 }
149
150 apex {
151 name: "myapex2",
152 native_shared_libs: ["mycpplib"],
153 uses_sdks: ["mysdk@2"],
154 key: "myapex.key",
155 certificate: ":myapex.cert",
156 }
Martin Stjernholmcc776012020-07-07 03:22:21 +0100157
158 apex {
159 name: "mysdkapex",
160 native_shared_libs: ["sdkmember"],
161 key: "myapex.key",
162 certificate: ":myapex.cert",
163 }
Paul Duffina80fdec2019-12-03 15:25:00 +0000164 `)
165
Colin Cross7113d202019-11-20 16:39:12 -0800166 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_myapex").Rule("toc").Output
167 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_myapex2").Rule("toc").Output
Paul Duffina80fdec2019-12-03 15:25:00 +0000168
Colin Cross7113d202019-11-20 16:39:12 -0800169 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex")
170 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex2")
Paul Duffina80fdec2019-12-03 15:25:00 +0000171
172 // Depending on the uses_sdks value, different libs are linked
173 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
174 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
175}
176
Paul Duffina0843f62019-12-13 19:50:38 +0000177// Make sure the sdk can use host specific cc libraries static/shared and both.
178func TestHostSdkWithCc(t *testing.T) {
179 testSdkWithCc(t, `
180 sdk {
181 name: "mysdk",
182 device_supported: false,
183 host_supported: true,
184 native_shared_libs: ["sdkshared"],
185 native_static_libs: ["sdkstatic"],
186 }
187
188 cc_library_host_shared {
189 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000190 stl: "none",
191 }
192
193 cc_library_host_static {
194 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000195 stl: "none",
196 }
197 `)
198}
199
200// Make sure the sdk can use cc libraries static/shared and both.
201func TestSdkWithCc(t *testing.T) {
202 testSdkWithCc(t, `
203 sdk {
204 name: "mysdk",
205 native_shared_libs: ["sdkshared", "sdkboth1"],
206 native_static_libs: ["sdkstatic", "sdkboth2"],
207 }
208
209 cc_library_shared {
210 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000211 stl: "none",
212 }
213
214 cc_library_static {
215 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000216 stl: "none",
217 }
218
219 cc_library {
220 name: "sdkboth1",
Paul Duffina0843f62019-12-13 19:50:38 +0000221 stl: "none",
222 }
223
224 cc_library {
225 name: "sdkboth2",
Paul Duffina0843f62019-12-13 19:50:38 +0000226 stl: "none",
227 }
228 `)
229}
230
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000231func TestSnapshotWithObject(t *testing.T) {
232 result := testSdkWithCc(t, `
233 sdk {
234 name: "mysdk",
235 native_objects: ["crtobj"],
236 }
237
238 cc_object {
239 name: "crtobj",
240 stl: "none",
241 }
242 `)
243
244 result.CheckSnapshot("mysdk", "",
245 checkAndroidBpContents(`
246// This is auto-generated. DO NOT EDIT.
247
248cc_prebuilt_object {
249 name: "mysdk_crtobj@current",
250 sdk_member_name: "crtobj",
251 stl: "none",
252 arch: {
253 arm64: {
254 srcs: ["arm64/lib/crtobj.o"],
255 },
256 arm: {
257 srcs: ["arm/lib/crtobj.o"],
258 },
259 },
260}
261
262cc_prebuilt_object {
263 name: "crtobj",
264 prefer: false,
265 stl: "none",
266 arch: {
267 arm64: {
268 srcs: ["arm64/lib/crtobj.o"],
269 },
270 arm: {
271 srcs: ["arm/lib/crtobj.o"],
272 },
273 },
274}
275
276sdk_snapshot {
277 name: "mysdk@current",
278 native_objects: ["mysdk_crtobj@current"],
279}
280`),
281 checkAllCopyRules(`
282.intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
283.intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
284`),
285 )
286}
287
Paul Duffinc62a5102019-12-11 18:34:15 +0000288func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
289 result := testSdkWithCc(t, `
290 sdk {
291 name: "mysdk",
292 native_shared_libs: ["mynativelib1", "mynativelib2"],
293 }
294
295 cc_library_shared {
296 name: "mynativelib1",
297 srcs: [
298 "Test.cpp",
299 ],
300 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000301 stl: "none",
302 }
303
304 cc_library_shared {
305 name: "mynativelib2",
306 srcs: [
307 "Test.cpp",
308 ],
309 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000310 stl: "none",
311 }
312 `)
313
Paul Duffin1356d8c2020-02-25 19:26:33 +0000314 result.CheckSnapshot("mysdk", "",
Paul Duffinc62a5102019-12-11 18:34:15 +0000315 checkAllCopyRules(`
316include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800317.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
318.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
319.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
320.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000321`),
322 )
323}
324
Paul Duffina7cd8c82019-12-11 20:00:57 +0000325// Verify that when the shared library has some common and some arch specific properties that the generated
326// snapshot is optimized properly.
327func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
328 result := testSdkWithCc(t, `
329 sdk {
330 name: "mysdk",
331 native_shared_libs: ["mynativelib"],
332 }
333
334 cc_library_shared {
335 name: "mynativelib",
336 srcs: [
337 "Test.cpp",
338 "aidl/foo/bar/Test.aidl",
339 ],
340 export_include_dirs: ["include"],
341 arch: {
342 arm64: {
343 export_system_include_dirs: ["arm64/include"],
344 },
345 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000346 stl: "none",
347 }
348 `)
349
Paul Duffin1356d8c2020-02-25 19:26:33 +0000350 result.CheckSnapshot("mysdk", "",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000351 checkAndroidBpContents(`
352// This is auto-generated. DO NOT EDIT.
353
354cc_prebuilt_library_shared {
355 name: "mysdk_mynativelib@current",
356 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000357 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000358 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000359 export_include_dirs: ["include/include"],
360 arch: {
361 arm64: {
362 srcs: ["arm64/lib/mynativelib.so"],
363 export_system_include_dirs: ["arm64/include/arm64/include"],
364 },
365 arm: {
366 srcs: ["arm/lib/mynativelib.so"],
367 },
368 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000369}
370
371cc_prebuilt_library_shared {
372 name: "mynativelib",
373 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000374 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000375 export_include_dirs: ["include/include"],
376 arch: {
377 arm64: {
378 srcs: ["arm64/lib/mynativelib.so"],
379 export_system_include_dirs: ["arm64/include/arm64/include"],
380 },
381 arm: {
382 srcs: ["arm/lib/mynativelib.so"],
383 },
384 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000385}
386
387sdk_snapshot {
388 name: "mysdk@current",
389 native_shared_libs: ["mysdk_mynativelib@current"],
390}
391`),
392 checkAllCopyRules(`
393include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800394.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000395arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800396.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000397 )
398}
399
Paul Duffin25ce04b2020-01-16 11:47:25 +0000400func TestSnapshotWithCcBinary(t *testing.T) {
401 result := testSdkWithCc(t, `
402 module_exports {
403 name: "mymodule_exports",
404 native_binaries: ["mynativebinary"],
405 }
406
407 cc_binary {
408 name: "mynativebinary",
409 srcs: [
410 "Test.cpp",
411 ],
412 compile_multilib: "both",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000413 }
414 `)
415
Paul Duffin1356d8c2020-02-25 19:26:33 +0000416 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000417 checkAndroidBpContents(`
418// This is auto-generated. DO NOT EDIT.
419
420cc_prebuilt_binary {
421 name: "mymodule_exports_mynativebinary@current",
422 sdk_member_name: "mynativebinary",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000423 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000424 compile_multilib: "both",
425 arch: {
426 arm64: {
427 srcs: ["arm64/bin/mynativebinary"],
428 },
429 arm: {
430 srcs: ["arm/bin/mynativebinary"],
431 },
432 },
433}
434
435cc_prebuilt_binary {
436 name: "mynativebinary",
437 prefer: false,
438 compile_multilib: "both",
439 arch: {
440 arm64: {
441 srcs: ["arm64/bin/mynativebinary"],
442 },
443 arm: {
444 srcs: ["arm/bin/mynativebinary"],
445 },
446 },
447}
448
449module_exports_snapshot {
450 name: "mymodule_exports@current",
451 native_binaries: ["mymodule_exports_mynativebinary@current"],
452}
453`),
454 checkAllCopyRules(`
455.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
456.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
457`),
458 )
459}
460
Paul Duffina04c1072020-03-02 10:16:35 +0000461func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
462 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
463 SkipIfNotLinux(t)
464
465 result := testSdkWithCc(t, `
466 module_exports {
467 name: "myexports",
468 device_supported: false,
469 host_supported: true,
470 native_binaries: ["mynativebinary"],
471 target: {
472 windows: {
473 enabled: true,
474 },
475 },
476 }
477
478 cc_binary {
479 name: "mynativebinary",
480 device_supported: false,
481 host_supported: true,
482 srcs: [
483 "Test.cpp",
484 ],
485 compile_multilib: "both",
Paul Duffina04c1072020-03-02 10:16:35 +0000486 stl: "none",
487 target: {
488 windows: {
489 enabled: true,
490 },
491 },
492 }
493 `)
494
495 result.CheckSnapshot("myexports", "",
496 checkAndroidBpContents(`
497// This is auto-generated. DO NOT EDIT.
498
499cc_prebuilt_binary {
500 name: "myexports_mynativebinary@current",
501 sdk_member_name: "mynativebinary",
502 device_supported: false,
503 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000504 installable: false,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100505 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000506 target: {
507 linux_glibc: {
508 compile_multilib: "both",
509 },
510 linux_glibc_x86_64: {
511 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
512 },
513 linux_glibc_x86: {
514 srcs: ["linux_glibc/x86/bin/mynativebinary"],
515 },
516 windows: {
517 compile_multilib: "64",
518 },
519 windows_x86_64: {
520 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
521 },
522 },
523}
524
525cc_prebuilt_binary {
526 name: "mynativebinary",
527 prefer: false,
528 device_supported: false,
529 host_supported: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100530 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000531 target: {
532 linux_glibc: {
533 compile_multilib: "both",
534 },
535 linux_glibc_x86_64: {
536 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
537 },
538 linux_glibc_x86: {
539 srcs: ["linux_glibc/x86/bin/mynativebinary"],
540 },
541 windows: {
542 compile_multilib: "64",
543 },
544 windows_x86_64: {
545 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
546 },
547 },
548}
549
550module_exports_snapshot {
551 name: "myexports@current",
552 device_supported: false,
553 host_supported: true,
554 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +0000555 target: {
556 windows: {
557 compile_multilib: "64",
558 },
559 },
Paul Duffina04c1072020-03-02 10:16:35 +0000560}
561`),
562 checkAllCopyRules(`
563.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
564.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
565.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
566`),
567 )
568}
569
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100570// Test that we support the necessary flags for the linker binary, which is
571// special in several ways.
572func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
573 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
574 SkipIfNotLinux(t)
575
576 result := testSdkWithCc(t, `
577 module_exports {
578 name: "mymodule_exports",
579 host_supported: true,
580 device_supported: false,
581 native_binaries: ["linker"],
582 }
583
584 cc_binary {
585 name: "linker",
586 host_supported: true,
587 static_executable: true,
588 nocrt: true,
589 stl: "none",
590 srcs: [
591 "Test.cpp",
592 ],
593 compile_multilib: "both",
594 }
595 `)
596
597 result.CheckSnapshot("mymodule_exports", "",
598 checkAndroidBpContents(`
599// This is auto-generated. DO NOT EDIT.
600
601cc_prebuilt_binary {
602 name: "mymodule_exports_linker@current",
603 sdk_member_name: "linker",
604 device_supported: false,
605 host_supported: true,
606 installable: false,
607 stl: "none",
608 static_executable: true,
609 nocrt: true,
610 compile_multilib: "both",
611 arch: {
612 x86_64: {
613 srcs: ["x86_64/bin/linker"],
614 },
615 x86: {
616 srcs: ["x86/bin/linker"],
617 },
618 },
619}
620
621cc_prebuilt_binary {
622 name: "linker",
623 prefer: false,
624 device_supported: false,
625 host_supported: true,
626 stl: "none",
627 static_executable: true,
628 nocrt: true,
629 compile_multilib: "both",
630 arch: {
631 x86_64: {
632 srcs: ["x86_64/bin/linker"],
633 },
634 x86: {
635 srcs: ["x86/bin/linker"],
636 },
637 },
638}
639
640module_exports_snapshot {
641 name: "mymodule_exports@current",
642 device_supported: false,
643 host_supported: true,
644 native_binaries: ["mymodule_exports_linker@current"],
645}
646`),
647 checkAllCopyRules(`
648.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
649.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
650`),
651 )
652}
653
Paul Duffin9ab556f2019-12-11 18:42:17 +0000654func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000655 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000656 sdk {
657 name: "mysdk",
658 native_shared_libs: ["mynativelib"],
659 }
660
661 cc_library_shared {
662 name: "mynativelib",
663 srcs: [
664 "Test.cpp",
665 "aidl/foo/bar/Test.aidl",
666 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000667 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000668 export_include_dirs: ["include"],
669 aidl: {
670 export_aidl_headers: true,
671 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000672 stl: "none",
673 }
674 `)
675
Paul Duffin1356d8c2020-02-25 19:26:33 +0000676 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000677 checkAndroidBpContents(`
678// This is auto-generated. DO NOT EDIT.
679
680cc_prebuilt_library_shared {
681 name: "mysdk_mynativelib@current",
682 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000683 apex_available: [
684 "apex1",
685 "apex2",
686 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000687 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000688 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000689 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000690 arch: {
691 arm64: {
692 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000693 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000694 },
695 arm: {
696 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000697 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000698 },
699 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000700}
701
702cc_prebuilt_library_shared {
703 name: "mynativelib",
704 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +0000705 apex_available: [
706 "apex1",
707 "apex2",
708 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +0000709 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000710 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000711 arch: {
712 arm64: {
713 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000714 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000715 },
716 arm: {
717 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000718 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000719 },
720 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000721}
722
723sdk_snapshot {
724 name: "mysdk@current",
725 native_shared_libs: ["mysdk_mynativelib@current"],
726}
727`),
728 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000729include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800730.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
731.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
732.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
733.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
734.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
735.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
736.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
737.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
Paul Duffina80fdec2019-12-03 15:25:00 +0000738`),
739 )
740}
741
Paul Duffin13f02712020-03-06 12:30:43 +0000742func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
743 result := testSdkWithCc(t, `
744 sdk {
745 name: "mysdk",
746 native_shared_libs: [
747 "mynativelib",
748 "myothernativelib",
749 "mysystemnativelib",
750 ],
751 }
752
753 cc_library {
754 name: "mysystemnativelib",
755 srcs: [
756 "Test.cpp",
757 ],
Paul Duffin13f02712020-03-06 12:30:43 +0000758 stl: "none",
759 }
760
761 cc_library_shared {
762 name: "myothernativelib",
763 srcs: [
764 "Test.cpp",
765 ],
766 system_shared_libs: [
767 // A reference to a library that is not an sdk member. Uses libm as that
768 // is in the default set of modules available to this test and so is available
769 // both here and also when the generated Android.bp file is tested in
770 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
771 // handles references to modules that are not sdk members.
772 "libm",
773 ],
774 stl: "none",
775 }
776
777 cc_library {
778 name: "mynativelib",
779 srcs: [
780 "Test.cpp",
781 ],
782 shared_libs: [
783 // A reference to another sdk member.
784 "myothernativelib",
785 ],
786 target: {
787 android: {
788 shared: {
789 shared_libs: [
790 // A reference to a library that is not an sdk member. The libc library
791 // is used here to check that the shared_libs property is handled correctly
792 // in a similar way to how libm is used to check system_shared_libs above.
793 "libc",
794 ],
795 },
796 },
797 },
Paul Duffin13f02712020-03-06 12:30:43 +0000798 stl: "none",
799 }
800 `)
801
802 result.CheckSnapshot("mysdk", "",
803 checkAndroidBpContents(`
804// This is auto-generated. DO NOT EDIT.
805
806cc_prebuilt_library_shared {
807 name: "mysdk_mynativelib@current",
808 sdk_member_name: "mynativelib",
809 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000810 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000811 shared_libs: [
812 "mysdk_myothernativelib@current",
813 "libc",
814 ],
815 arch: {
816 arm64: {
817 srcs: ["arm64/lib/mynativelib.so"],
818 },
819 arm: {
820 srcs: ["arm/lib/mynativelib.so"],
821 },
822 },
Paul Duffin13f02712020-03-06 12:30:43 +0000823}
824
825cc_prebuilt_library_shared {
826 name: "mynativelib",
827 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000828 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000829 shared_libs: [
830 "myothernativelib",
831 "libc",
832 ],
833 arch: {
834 arm64: {
835 srcs: ["arm64/lib/mynativelib.so"],
836 },
837 arm: {
838 srcs: ["arm/lib/mynativelib.so"],
839 },
840 },
Paul Duffin13f02712020-03-06 12:30:43 +0000841}
842
843cc_prebuilt_library_shared {
844 name: "mysdk_myothernativelib@current",
845 sdk_member_name: "myothernativelib",
846 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000847 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000848 system_shared_libs: ["libm"],
849 arch: {
850 arm64: {
851 srcs: ["arm64/lib/myothernativelib.so"],
852 },
853 arm: {
854 srcs: ["arm/lib/myothernativelib.so"],
855 },
856 },
Paul Duffin13f02712020-03-06 12:30:43 +0000857}
858
859cc_prebuilt_library_shared {
860 name: "myothernativelib",
861 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000862 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000863 system_shared_libs: ["libm"],
864 arch: {
865 arm64: {
866 srcs: ["arm64/lib/myothernativelib.so"],
867 },
868 arm: {
869 srcs: ["arm/lib/myothernativelib.so"],
870 },
871 },
Paul Duffin13f02712020-03-06 12:30:43 +0000872}
873
874cc_prebuilt_library_shared {
875 name: "mysdk_mysystemnativelib@current",
876 sdk_member_name: "mysystemnativelib",
877 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000878 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000879 arch: {
880 arm64: {
881 srcs: ["arm64/lib/mysystemnativelib.so"],
882 },
883 arm: {
884 srcs: ["arm/lib/mysystemnativelib.so"],
885 },
886 },
Paul Duffin13f02712020-03-06 12:30:43 +0000887}
888
889cc_prebuilt_library_shared {
890 name: "mysystemnativelib",
891 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000892 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000893 arch: {
894 arm64: {
895 srcs: ["arm64/lib/mysystemnativelib.so"],
896 },
897 arm: {
898 srcs: ["arm/lib/mysystemnativelib.so"],
899 },
900 },
Paul Duffin13f02712020-03-06 12:30:43 +0000901}
902
903sdk_snapshot {
904 name: "mysdk@current",
905 native_shared_libs: [
906 "mysdk_mynativelib@current",
907 "mysdk_myothernativelib@current",
908 "mysdk_mysystemnativelib@current",
909 ],
910}
911`),
912 checkAllCopyRules(`
913.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
914.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
915.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
916.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
917.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
918.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
919`),
920 )
921}
922
Paul Duffin9ab556f2019-12-11 18:42:17 +0000923func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000924 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
925 SkipIfNotLinux(t)
926
Paul Duffind835daa2019-11-30 17:49:09 +0000927 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000928 sdk {
929 name: "mysdk",
930 device_supported: false,
931 host_supported: true,
932 native_shared_libs: ["mynativelib"],
933 }
934
935 cc_library_shared {
936 name: "mynativelib",
937 device_supported: false,
938 host_supported: true,
939 srcs: [
940 "Test.cpp",
941 "aidl/foo/bar/Test.aidl",
942 ],
943 export_include_dirs: ["include"],
944 aidl: {
945 export_aidl_headers: true,
946 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000947 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +0000948 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +0000949 }
950 `)
951
Paul Duffin1356d8c2020-02-25 19:26:33 +0000952 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000953 checkAndroidBpContents(`
954// This is auto-generated. DO NOT EDIT.
955
956cc_prebuilt_library_shared {
957 name: "mysdk_mynativelib@current",
958 sdk_member_name: "mynativelib",
959 device_supported: false,
960 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000961 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +0000962 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000963 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000964 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000965 arch: {
966 x86_64: {
967 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000968 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000969 },
970 x86: {
971 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000972 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000973 },
974 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000975}
976
977cc_prebuilt_library_shared {
978 name: "mynativelib",
979 prefer: false,
980 device_supported: false,
981 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +0000982 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000983 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000984 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000985 arch: {
986 x86_64: {
987 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000988 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000989 },
990 x86: {
991 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000992 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000993 },
994 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000995}
996
997sdk_snapshot {
998 name: "mysdk@current",
999 device_supported: false,
1000 host_supported: true,
1001 native_shared_libs: ["mysdk_mynativelib@current"],
1002}
1003`),
1004 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001005include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +00001006.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001007.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1008.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1009.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1010.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001011.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1012.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1013.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1014`),
1015 )
1016}
Paul Duffin9ab556f2019-12-11 18:42:17 +00001017
Paul Duffina04c1072020-03-02 10:16:35 +00001018func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
1019 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1020 SkipIfNotLinux(t)
1021
1022 result := testSdkWithCc(t, `
1023 sdk {
1024 name: "mysdk",
1025 device_supported: false,
1026 host_supported: true,
1027 native_shared_libs: ["mynativelib"],
1028 target: {
1029 windows: {
1030 enabled: true,
1031 },
1032 },
1033 }
1034
1035 cc_library_shared {
1036 name: "mynativelib",
1037 device_supported: false,
1038 host_supported: true,
1039 srcs: [
1040 "Test.cpp",
1041 ],
Paul Duffina04c1072020-03-02 10:16:35 +00001042 stl: "none",
1043 target: {
1044 windows: {
1045 enabled: true,
1046 },
1047 },
1048 }
1049 `)
1050
1051 result.CheckSnapshot("mysdk", "",
1052 checkAndroidBpContents(`
1053// This is auto-generated. DO NOT EDIT.
1054
1055cc_prebuilt_library_shared {
1056 name: "mysdk_mynativelib@current",
1057 sdk_member_name: "mynativelib",
1058 device_supported: false,
1059 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001060 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001061 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001062 target: {
1063 linux_glibc_x86_64: {
1064 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1065 },
1066 linux_glibc_x86: {
1067 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1068 },
1069 windows_x86_64: {
1070 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1071 },
1072 },
Paul Duffina04c1072020-03-02 10:16:35 +00001073}
1074
1075cc_prebuilt_library_shared {
1076 name: "mynativelib",
1077 prefer: false,
1078 device_supported: false,
1079 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001080 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001081 target: {
1082 linux_glibc_x86_64: {
1083 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1084 },
1085 linux_glibc_x86: {
1086 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1087 },
1088 windows_x86_64: {
1089 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1090 },
1091 },
Paul Duffina04c1072020-03-02 10:16:35 +00001092}
1093
1094sdk_snapshot {
1095 name: "mysdk@current",
1096 device_supported: false,
1097 host_supported: true,
1098 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +00001099 target: {
1100 windows: {
1101 compile_multilib: "64",
1102 },
1103 },
Paul Duffina04c1072020-03-02 10:16:35 +00001104}
1105`),
1106 checkAllCopyRules(`
1107.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1108.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1109.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1110`),
1111 )
1112}
1113
Paul Duffin9ab556f2019-12-11 18:42:17 +00001114func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1115 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001116 module_exports {
1117 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001118 native_static_libs: ["mynativelib"],
1119 }
1120
1121 cc_library_static {
1122 name: "mynativelib",
1123 srcs: [
1124 "Test.cpp",
1125 "aidl/foo/bar/Test.aidl",
1126 ],
1127 export_include_dirs: ["include"],
1128 aidl: {
1129 export_aidl_headers: true,
1130 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001131 stl: "none",
1132 }
1133 `)
1134
Paul Duffin1356d8c2020-02-25 19:26:33 +00001135 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001136 checkAndroidBpContents(`
1137// This is auto-generated. DO NOT EDIT.
1138
1139cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001140 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001141 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001142 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001143 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001144 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001145 arch: {
1146 arm64: {
1147 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001148 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001149 },
1150 arm: {
1151 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001152 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001153 },
1154 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001155}
1156
1157cc_prebuilt_library_static {
1158 name: "mynativelib",
1159 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001160 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001161 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001162 arch: {
1163 arm64: {
1164 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001165 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001166 },
1167 arm: {
1168 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001169 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001170 },
1171 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001172}
1173
Paul Duffine6029182019-12-16 17:43:48 +00001174module_exports_snapshot {
1175 name: "myexports@current",
1176 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001177}
1178`),
1179 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001180include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001181.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1182.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1183.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1184.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1185.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1186.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1187.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1188.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BpTest.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001189`),
1190 )
1191}
1192
1193func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1194 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1195 SkipIfNotLinux(t)
1196
1197 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001198 module_exports {
1199 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001200 device_supported: false,
1201 host_supported: true,
1202 native_static_libs: ["mynativelib"],
1203 }
1204
1205 cc_library_static {
1206 name: "mynativelib",
1207 device_supported: false,
1208 host_supported: true,
1209 srcs: [
1210 "Test.cpp",
1211 "aidl/foo/bar/Test.aidl",
1212 ],
1213 export_include_dirs: ["include"],
1214 aidl: {
1215 export_aidl_headers: true,
1216 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001217 stl: "none",
1218 }
1219 `)
1220
Paul Duffin1356d8c2020-02-25 19:26:33 +00001221 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001222 checkAndroidBpContents(`
1223// This is auto-generated. DO NOT EDIT.
1224
1225cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001226 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001227 sdk_member_name: "mynativelib",
1228 device_supported: false,
1229 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001230 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001231 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001232 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001233 arch: {
1234 x86_64: {
1235 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001236 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001237 },
1238 x86: {
1239 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001240 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001241 },
1242 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001243}
1244
1245cc_prebuilt_library_static {
1246 name: "mynativelib",
1247 prefer: false,
1248 device_supported: false,
1249 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001250 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001251 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001252 arch: {
1253 x86_64: {
1254 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001255 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001256 },
1257 x86: {
1258 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001259 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001260 },
1261 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001262}
1263
Paul Duffine6029182019-12-16 17:43:48 +00001264module_exports_snapshot {
1265 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001266 device_supported: false,
1267 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001268 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001269}
1270`),
1271 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001272include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001273.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001274.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1275.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1276.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1277.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001278.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1279.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1280.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1281`),
1282 )
1283}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001284
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001285func TestSnapshotWithCcLibrary(t *testing.T) {
1286 result := testSdkWithCc(t, `
1287 module_exports {
1288 name: "myexports",
1289 native_libs: ["mynativelib"],
1290 }
1291
1292 cc_library {
1293 name: "mynativelib",
1294 srcs: [
1295 "Test.cpp",
1296 ],
1297 export_include_dirs: ["include"],
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001298 stl: "none",
1299 }
1300 `)
1301
1302 result.CheckSnapshot("myexports", "",
1303 checkAndroidBpContents(`
1304// This is auto-generated. DO NOT EDIT.
1305
1306cc_prebuilt_library {
1307 name: "myexports_mynativelib@current",
1308 sdk_member_name: "mynativelib",
1309 installable: false,
1310 stl: "none",
1311 export_include_dirs: ["include/include"],
1312 arch: {
1313 arm64: {
1314 static: {
1315 srcs: ["arm64/lib/mynativelib.a"],
1316 },
1317 shared: {
1318 srcs: ["arm64/lib/mynativelib.so"],
1319 },
1320 },
1321 arm: {
1322 static: {
1323 srcs: ["arm/lib/mynativelib.a"],
1324 },
1325 shared: {
1326 srcs: ["arm/lib/mynativelib.so"],
1327 },
1328 },
1329 },
1330}
1331
1332cc_prebuilt_library {
1333 name: "mynativelib",
1334 prefer: false,
1335 stl: "none",
1336 export_include_dirs: ["include/include"],
1337 arch: {
1338 arm64: {
1339 static: {
1340 srcs: ["arm64/lib/mynativelib.a"],
1341 },
1342 shared: {
1343 srcs: ["arm64/lib/mynativelib.so"],
1344 },
1345 },
1346 arm: {
1347 static: {
1348 srcs: ["arm/lib/mynativelib.a"],
1349 },
1350 shared: {
1351 srcs: ["arm/lib/mynativelib.so"],
1352 },
1353 },
1354 },
1355}
1356
1357module_exports_snapshot {
1358 name: "myexports@current",
1359 native_libs: ["myexports_mynativelib@current"],
1360}
1361`),
1362 checkAllCopyRules(`
1363include/Test.h -> include/include/Test.h
1364.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1365.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1366.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1367.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1368 )
1369}
1370
Paul Duffin13ad94f2020-02-19 16:19:27 +00001371func TestHostSnapshotWithMultiLib64(t *testing.T) {
1372 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1373 SkipIfNotLinux(t)
1374
1375 result := testSdkWithCc(t, `
1376 module_exports {
1377 name: "myexports",
1378 device_supported: false,
1379 host_supported: true,
1380 target: {
1381 host: {
1382 compile_multilib: "64",
1383 },
1384 },
1385 native_static_libs: ["mynativelib"],
1386 }
1387
1388 cc_library_static {
1389 name: "mynativelib",
1390 device_supported: false,
1391 host_supported: true,
1392 srcs: [
1393 "Test.cpp",
1394 "aidl/foo/bar/Test.aidl",
1395 ],
1396 export_include_dirs: ["include"],
1397 aidl: {
1398 export_aidl_headers: true,
1399 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001400 stl: "none",
1401 }
1402 `)
1403
Paul Duffin1356d8c2020-02-25 19:26:33 +00001404 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001405 checkAndroidBpContents(`
1406// This is auto-generated. DO NOT EDIT.
1407
1408cc_prebuilt_library_static {
1409 name: "myexports_mynativelib@current",
1410 sdk_member_name: "mynativelib",
1411 device_supported: false,
1412 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001413 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001414 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001415 export_include_dirs: ["include/include"],
1416 arch: {
1417 x86_64: {
1418 srcs: ["x86_64/lib/mynativelib.a"],
1419 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1420 },
1421 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001422}
1423
1424cc_prebuilt_library_static {
1425 name: "mynativelib",
1426 prefer: false,
1427 device_supported: false,
1428 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001429 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001430 export_include_dirs: ["include/include"],
1431 arch: {
1432 x86_64: {
1433 srcs: ["x86_64/lib/mynativelib.a"],
1434 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1435 },
1436 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001437}
1438
1439module_exports_snapshot {
1440 name: "myexports@current",
1441 device_supported: false,
1442 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001443 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin13ad94f2020-02-19 16:19:27 +00001444 target: {
Paul Duffin6a7e9532020-03-20 17:50:07 +00001445 linux_glibc: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001446 compile_multilib: "64",
1447 },
1448 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001449}`),
1450 checkAllCopyRules(`
1451include/Test.h -> include/include/Test.h
1452.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1453.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1454.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1455.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1456`),
1457 )
1458}
Paul Duffin91756d22020-02-21 16:29:57 +00001459
1460func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1461 result := testSdkWithCc(t, `
1462 sdk {
1463 name: "mysdk",
1464 native_header_libs: ["mynativeheaders"],
1465 }
1466
1467 cc_library_headers {
1468 name: "mynativeheaders",
1469 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001470 stl: "none",
1471 }
1472 `)
1473
Paul Duffin1356d8c2020-02-25 19:26:33 +00001474 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001475 checkAndroidBpContents(`
1476// This is auto-generated. DO NOT EDIT.
1477
1478cc_prebuilt_library_headers {
1479 name: "mysdk_mynativeheaders@current",
1480 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001481 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001482 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001483}
1484
1485cc_prebuilt_library_headers {
1486 name: "mynativeheaders",
1487 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001488 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001489 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001490}
1491
1492sdk_snapshot {
1493 name: "mysdk@current",
1494 native_header_libs: ["mysdk_mynativeheaders@current"],
1495}
1496`),
1497 checkAllCopyRules(`
1498include/Test.h -> include/include/Test.h
1499`),
1500 )
1501}
1502
1503func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1504 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1505 SkipIfNotLinux(t)
1506
1507 result := testSdkWithCc(t, `
1508 sdk {
1509 name: "mysdk",
1510 device_supported: false,
1511 host_supported: true,
1512 native_header_libs: ["mynativeheaders"],
1513 }
1514
1515 cc_library_headers {
1516 name: "mynativeheaders",
1517 device_supported: false,
1518 host_supported: true,
1519 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001520 stl: "none",
1521 }
1522 `)
1523
Paul Duffin1356d8c2020-02-25 19:26:33 +00001524 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001525 checkAndroidBpContents(`
1526// This is auto-generated. DO NOT EDIT.
1527
1528cc_prebuilt_library_headers {
1529 name: "mysdk_mynativeheaders@current",
1530 sdk_member_name: "mynativeheaders",
1531 device_supported: false,
1532 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001533 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001534 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001535}
1536
1537cc_prebuilt_library_headers {
1538 name: "mynativeheaders",
1539 prefer: false,
1540 device_supported: false,
1541 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001542 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001543 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001544}
1545
1546sdk_snapshot {
1547 name: "mysdk@current",
1548 device_supported: false,
1549 host_supported: true,
1550 native_header_libs: ["mysdk_mynativeheaders@current"],
1551}
1552`),
1553 checkAllCopyRules(`
1554include/Test.h -> include/include/Test.h
1555`),
1556 )
1557}
Paul Duffina04c1072020-03-02 10:16:35 +00001558
1559func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1560 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1561 SkipIfNotLinux(t)
1562
1563 result := testSdkWithCc(t, `
1564 sdk {
1565 name: "mysdk",
1566 host_supported: true,
1567 native_header_libs: ["mynativeheaders"],
1568 }
1569
1570 cc_library_headers {
1571 name: "mynativeheaders",
1572 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00001573 stl: "none",
1574 export_system_include_dirs: ["include"],
1575 target: {
1576 android: {
1577 export_include_dirs: ["include-android"],
1578 },
1579 host: {
1580 export_include_dirs: ["include-host"],
1581 },
1582 },
1583 }
1584 `)
1585
1586 result.CheckSnapshot("mysdk", "",
1587 checkAndroidBpContents(`
1588// This is auto-generated. DO NOT EDIT.
1589
1590cc_prebuilt_library_headers {
1591 name: "mysdk_mynativeheaders@current",
1592 sdk_member_name: "mynativeheaders",
1593 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001594 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001595 export_system_include_dirs: ["include/include"],
1596 target: {
1597 android: {
1598 export_include_dirs: ["include/include-android"],
1599 },
1600 linux_glibc: {
1601 export_include_dirs: ["include/include-host"],
1602 },
1603 },
Paul Duffina04c1072020-03-02 10:16:35 +00001604}
1605
1606cc_prebuilt_library_headers {
1607 name: "mynativeheaders",
1608 prefer: false,
1609 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001610 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001611 export_system_include_dirs: ["include/include"],
1612 target: {
1613 android: {
1614 export_include_dirs: ["include/include-android"],
1615 },
1616 linux_glibc: {
1617 export_include_dirs: ["include/include-host"],
1618 },
1619 },
Paul Duffina04c1072020-03-02 10:16:35 +00001620}
1621
1622sdk_snapshot {
1623 name: "mysdk@current",
1624 host_supported: true,
1625 native_header_libs: ["mysdk_mynativeheaders@current"],
1626}
1627`),
1628 checkAllCopyRules(`
1629include/Test.h -> include/include/Test.h
1630include-android/AndroidTest.h -> include/include-android/AndroidTest.h
1631include-host/HostTest.h -> include/include-host/HostTest.h
1632`),
1633 )
1634}
Martin Stjernholm10566a02020-03-24 01:19:52 +00001635
1636func TestSystemSharedLibPropagation(t *testing.T) {
Martin Stjernholm66a06942020-03-26 17:39:30 +00001637 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1638 SkipIfNotLinux(t)
1639
Martin Stjernholm10566a02020-03-24 01:19:52 +00001640 result := testSdkWithCc(t, `
1641 sdk {
1642 name: "mysdk",
1643 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
1644 }
1645
1646 cc_library {
1647 name: "sslnil",
1648 host_supported: true,
1649 }
1650
1651 cc_library {
1652 name: "sslempty",
1653 system_shared_libs: [],
1654 }
1655
1656 cc_library {
1657 name: "sslnonempty",
1658 system_shared_libs: ["sslnil"],
1659 }
1660 `)
1661
1662 result.CheckSnapshot("mysdk", "",
1663 checkAndroidBpContents(`
1664// This is auto-generated. DO NOT EDIT.
1665
1666cc_prebuilt_library_shared {
1667 name: "mysdk_sslnil@current",
1668 sdk_member_name: "sslnil",
1669 installable: false,
1670 arch: {
1671 arm64: {
1672 srcs: ["arm64/lib/sslnil.so"],
1673 },
1674 arm: {
1675 srcs: ["arm/lib/sslnil.so"],
1676 },
1677 },
1678}
1679
1680cc_prebuilt_library_shared {
1681 name: "sslnil",
1682 prefer: false,
1683 arch: {
1684 arm64: {
1685 srcs: ["arm64/lib/sslnil.so"],
1686 },
1687 arm: {
1688 srcs: ["arm/lib/sslnil.so"],
1689 },
1690 },
1691}
1692
1693cc_prebuilt_library_shared {
1694 name: "mysdk_sslempty@current",
1695 sdk_member_name: "sslempty",
1696 installable: false,
1697 system_shared_libs: [],
1698 arch: {
1699 arm64: {
1700 srcs: ["arm64/lib/sslempty.so"],
1701 },
1702 arm: {
1703 srcs: ["arm/lib/sslempty.so"],
1704 },
1705 },
1706}
1707
1708cc_prebuilt_library_shared {
1709 name: "sslempty",
1710 prefer: false,
1711 system_shared_libs: [],
1712 arch: {
1713 arm64: {
1714 srcs: ["arm64/lib/sslempty.so"],
1715 },
1716 arm: {
1717 srcs: ["arm/lib/sslempty.so"],
1718 },
1719 },
1720}
1721
1722cc_prebuilt_library_shared {
1723 name: "mysdk_sslnonempty@current",
1724 sdk_member_name: "sslnonempty",
1725 installable: false,
1726 system_shared_libs: ["mysdk_sslnil@current"],
1727 arch: {
1728 arm64: {
1729 srcs: ["arm64/lib/sslnonempty.so"],
1730 },
1731 arm: {
1732 srcs: ["arm/lib/sslnonempty.so"],
1733 },
1734 },
1735}
1736
1737cc_prebuilt_library_shared {
1738 name: "sslnonempty",
1739 prefer: false,
1740 system_shared_libs: ["sslnil"],
1741 arch: {
1742 arm64: {
1743 srcs: ["arm64/lib/sslnonempty.so"],
1744 },
1745 arm: {
1746 srcs: ["arm/lib/sslnonempty.so"],
1747 },
1748 },
1749}
1750
1751sdk_snapshot {
1752 name: "mysdk@current",
1753 native_shared_libs: [
1754 "mysdk_sslnil@current",
1755 "mysdk_sslempty@current",
1756 "mysdk_sslnonempty@current",
1757 ],
1758}
1759`))
1760
1761 result = testSdkWithCc(t, `
1762 sdk {
1763 name: "mysdk",
1764 host_supported: true,
1765 native_shared_libs: ["sslvariants"],
1766 }
1767
1768 cc_library {
1769 name: "sslvariants",
1770 host_supported: true,
1771 target: {
1772 android: {
1773 system_shared_libs: [],
1774 },
1775 },
1776 }
1777 `)
1778
1779 result.CheckSnapshot("mysdk", "",
1780 checkAndroidBpContents(`
1781// This is auto-generated. DO NOT EDIT.
1782
1783cc_prebuilt_library_shared {
1784 name: "mysdk_sslvariants@current",
1785 sdk_member_name: "sslvariants",
1786 host_supported: true,
1787 installable: false,
1788 target: {
1789 android: {
1790 system_shared_libs: [],
1791 },
1792 android_arm64: {
1793 srcs: ["android/arm64/lib/sslvariants.so"],
1794 },
1795 android_arm: {
1796 srcs: ["android/arm/lib/sslvariants.so"],
1797 },
1798 linux_glibc_x86_64: {
1799 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1800 },
1801 linux_glibc_x86: {
1802 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1803 },
1804 },
1805}
1806
1807cc_prebuilt_library_shared {
1808 name: "sslvariants",
1809 prefer: false,
1810 host_supported: true,
1811 target: {
1812 android: {
1813 system_shared_libs: [],
1814 },
1815 android_arm64: {
1816 srcs: ["android/arm64/lib/sslvariants.so"],
1817 },
1818 android_arm: {
1819 srcs: ["android/arm/lib/sslvariants.so"],
1820 },
1821 linux_glibc_x86_64: {
1822 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1823 },
1824 linux_glibc_x86: {
1825 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1826 },
1827 },
1828}
1829
1830sdk_snapshot {
1831 name: "mysdk@current",
1832 host_supported: true,
1833 native_shared_libs: ["mysdk_sslvariants@current"],
1834}
1835`))
1836}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001837
1838func TestStubsLibrary(t *testing.T) {
1839 result := testSdkWithCc(t, `
1840 sdk {
1841 name: "mysdk",
1842 native_shared_libs: ["stubslib"],
1843 }
1844
1845 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001846 name: "internaldep",
1847 }
1848
1849 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001850 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001851 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001852 stubs: {
1853 symbol_file: "some/where/stubslib.map.txt",
1854 versions: ["1", "2", "3"],
1855 },
1856 }
1857 `)
1858
1859 result.CheckSnapshot("mysdk", "",
1860 checkAndroidBpContents(`
1861// This is auto-generated. DO NOT EDIT.
1862
1863cc_prebuilt_library_shared {
1864 name: "mysdk_stubslib@current",
1865 sdk_member_name: "stubslib",
1866 installable: false,
1867 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001868 versions: ["3"],
1869 },
1870 arch: {
1871 arm64: {
1872 srcs: ["arm64/lib/stubslib.so"],
1873 },
1874 arm: {
1875 srcs: ["arm/lib/stubslib.so"],
1876 },
1877 },
1878}
1879
1880cc_prebuilt_library_shared {
1881 name: "stubslib",
1882 prefer: false,
1883 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001884 versions: ["3"],
1885 },
1886 arch: {
1887 arm64: {
1888 srcs: ["arm64/lib/stubslib.so"],
1889 },
1890 arm: {
1891 srcs: ["arm/lib/stubslib.so"],
1892 },
1893 },
1894}
1895
1896sdk_snapshot {
1897 name: "mysdk@current",
1898 native_shared_libs: ["mysdk_stubslib@current"],
1899}
1900`))
1901}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01001902
1903func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
1904 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1905 SkipIfNotLinux(t)
1906
1907 result := testSdkWithCc(t, `
1908 sdk {
1909 name: "mysdk",
1910 host_supported: true,
1911 native_shared_libs: ["stubslib"],
1912 }
1913
1914 cc_library {
1915 name: "internaldep",
1916 host_supported: true,
1917 }
1918
1919 cc_library {
1920 name: "stubslib",
1921 host_supported: true,
1922 shared_libs: ["internaldep"],
1923 stubs: {
1924 symbol_file: "some/where/stubslib.map.txt",
1925 versions: ["1", "2", "3"],
1926 },
1927 }
1928 `)
1929
1930 result.CheckSnapshot("mysdk", "",
1931 checkAndroidBpContents(`
1932// This is auto-generated. DO NOT EDIT.
1933
1934cc_prebuilt_library_shared {
1935 name: "mysdk_stubslib@current",
1936 sdk_member_name: "stubslib",
1937 host_supported: true,
1938 installable: false,
1939 stubs: {
1940 versions: ["3"],
1941 },
1942 target: {
1943 android_arm64: {
1944 srcs: ["android/arm64/lib/stubslib.so"],
1945 },
1946 android_arm: {
1947 srcs: ["android/arm/lib/stubslib.so"],
1948 },
1949 linux_glibc_x86_64: {
1950 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
1951 },
1952 linux_glibc_x86: {
1953 srcs: ["linux_glibc/x86/lib/stubslib.so"],
1954 },
1955 },
1956}
1957
1958cc_prebuilt_library_shared {
1959 name: "stubslib",
1960 prefer: false,
1961 host_supported: true,
1962 stubs: {
1963 versions: ["3"],
1964 },
1965 target: {
1966 android_arm64: {
1967 srcs: ["android/arm64/lib/stubslib.so"],
1968 },
1969 android_arm: {
1970 srcs: ["android/arm/lib/stubslib.so"],
1971 },
1972 linux_glibc_x86_64: {
1973 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
1974 },
1975 linux_glibc_x86: {
1976 srcs: ["linux_glibc/x86/lib/stubslib.so"],
1977 },
1978 },
1979}
1980
1981sdk_snapshot {
1982 name: "mysdk@current",
1983 host_supported: true,
1984 native_shared_libs: ["mysdk_stubslib@current"],
1985}
1986`))
1987}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01001988
1989func TestUniqueHostSoname(t *testing.T) {
1990 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1991 SkipIfNotLinux(t)
1992
1993 result := testSdkWithCc(t, `
1994 sdk {
1995 name: "mysdk",
1996 host_supported: true,
1997 native_shared_libs: ["mylib"],
1998 }
1999
2000 cc_library {
2001 name: "mylib",
2002 host_supported: true,
2003 unique_host_soname: true,
2004 }
2005 `)
2006
2007 result.CheckSnapshot("mysdk", "",
2008 checkAndroidBpContents(`
2009// This is auto-generated. DO NOT EDIT.
2010
2011cc_prebuilt_library_shared {
2012 name: "mysdk_mylib@current",
2013 sdk_member_name: "mylib",
2014 host_supported: true,
2015 installable: false,
2016 unique_host_soname: true,
2017 target: {
2018 android_arm64: {
2019 srcs: ["android/arm64/lib/mylib.so"],
2020 },
2021 android_arm: {
2022 srcs: ["android/arm/lib/mylib.so"],
2023 },
2024 linux_glibc_x86_64: {
2025 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2026 },
2027 linux_glibc_x86: {
2028 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2029 },
2030 },
2031}
2032
2033cc_prebuilt_library_shared {
2034 name: "mylib",
2035 prefer: false,
2036 host_supported: true,
2037 unique_host_soname: true,
2038 target: {
2039 android_arm64: {
2040 srcs: ["android/arm64/lib/mylib.so"],
2041 },
2042 android_arm: {
2043 srcs: ["android/arm/lib/mylib.so"],
2044 },
2045 linux_glibc_x86_64: {
2046 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2047 },
2048 linux_glibc_x86: {
2049 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2050 },
2051 },
2052}
2053
2054sdk_snapshot {
2055 name: "mysdk@current",
2056 host_supported: true,
2057 native_shared_libs: ["mysdk_mylib@current"],
2058}
2059`),
2060 checkAllCopyRules(`
2061.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2062.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2063.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2064.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2065`),
2066 )
2067}