blob: c59cd309543b61f5fd9f2475f0e35b64828a6a34 [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
Martin Stjernholm26ab8e82020-06-30 20:34:00 +010072func TestSdkCompileMultilibOverride(t *testing.T) {
73 result := testSdkWithCc(t, `
74 sdk {
75 name: "mysdk",
76 native_shared_libs: ["sdkmember"],
77 compile_multilib: "64",
78 }
79
80 cc_library_shared {
81 name: "sdkmember",
82 srcs: ["Test.cpp"],
83 stl: "none",
84 compile_multilib: "64",
85 }
86 `)
87
88 result.CheckSnapshot("mysdk", "",
89 checkAllCopyRules(`
90.intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> arm64/lib/sdkmember.so
91`))
92}
93
Paul Duffina80fdec2019-12-03 15:25:00 +000094func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000095 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000096 sdk {
97 name: "mysdk",
98 native_shared_libs: ["sdkmember"],
99 }
100
Paul Duffina0843f62019-12-13 19:50:38 +0000101 cc_library_shared {
102 name: "sdkmember",
Colin Crossf9aabd72020-02-15 11:29:50 -0800103 system_shared_libs: [],
Martin Stjernholmcc776012020-07-07 03:22:21 +0100104 stl: "none",
105 apex_available: ["mysdkapex"],
Paul Duffina0843f62019-12-13 19:50:38 +0000106 }
107
Paul Duffina80fdec2019-12-03 15:25:00 +0000108 sdk_snapshot {
109 name: "mysdk@1",
110 native_shared_libs: ["sdkmember_mysdk_1"],
111 }
112
113 sdk_snapshot {
114 name: "mysdk@2",
115 native_shared_libs: ["sdkmember_mysdk_2"],
116 }
117
118 cc_prebuilt_library_shared {
119 name: "sdkmember",
120 srcs: ["libfoo.so"],
121 prefer: false,
122 system_shared_libs: [],
123 stl: "none",
124 }
125
126 cc_prebuilt_library_shared {
127 name: "sdkmember_mysdk_1",
128 sdk_member_name: "sdkmember",
129 srcs: ["libfoo.so"],
130 system_shared_libs: [],
131 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000132 // TODO: remove //apex_available:platform
133 apex_available: [
134 "//apex_available:platform",
135 "myapex",
136 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000137 }
138
139 cc_prebuilt_library_shared {
140 name: "sdkmember_mysdk_2",
141 sdk_member_name: "sdkmember",
142 srcs: ["libfoo.so"],
143 system_shared_libs: [],
144 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000145 // TODO: remove //apex_available:platform
146 apex_available: [
147 "//apex_available:platform",
148 "myapex2",
149 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000150 }
151
152 cc_library_shared {
153 name: "mycpplib",
154 srcs: ["Test.cpp"],
155 shared_libs: ["sdkmember"],
156 system_shared_libs: [],
157 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000158 apex_available: [
159 "myapex",
160 "myapex2",
161 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000162 }
163
164 apex {
165 name: "myapex",
166 native_shared_libs: ["mycpplib"],
167 uses_sdks: ["mysdk@1"],
168 key: "myapex.key",
169 certificate: ":myapex.cert",
170 }
171
172 apex {
173 name: "myapex2",
174 native_shared_libs: ["mycpplib"],
175 uses_sdks: ["mysdk@2"],
176 key: "myapex.key",
177 certificate: ":myapex.cert",
178 }
Martin Stjernholmcc776012020-07-07 03:22:21 +0100179
180 apex {
181 name: "mysdkapex",
182 native_shared_libs: ["sdkmember"],
183 key: "myapex.key",
184 certificate: ":myapex.cert",
185 }
Paul Duffina80fdec2019-12-03 15:25:00 +0000186 `)
187
Colin Cross7113d202019-11-20 16:39:12 -0800188 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_myapex").Rule("toc").Output
189 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_myapex2").Rule("toc").Output
Paul Duffina80fdec2019-12-03 15:25:00 +0000190
Colin Cross7113d202019-11-20 16:39:12 -0800191 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex")
192 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex2")
Paul Duffina80fdec2019-12-03 15:25:00 +0000193
194 // Depending on the uses_sdks value, different libs are linked
195 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
196 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
197}
198
Paul Duffina0843f62019-12-13 19:50:38 +0000199// Make sure the sdk can use host specific cc libraries static/shared and both.
200func TestHostSdkWithCc(t *testing.T) {
201 testSdkWithCc(t, `
202 sdk {
203 name: "mysdk",
204 device_supported: false,
205 host_supported: true,
206 native_shared_libs: ["sdkshared"],
207 native_static_libs: ["sdkstatic"],
208 }
209
210 cc_library_host_shared {
211 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000212 stl: "none",
213 }
214
215 cc_library_host_static {
216 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000217 stl: "none",
218 }
219 `)
220}
221
222// Make sure the sdk can use cc libraries static/shared and both.
223func TestSdkWithCc(t *testing.T) {
224 testSdkWithCc(t, `
225 sdk {
226 name: "mysdk",
227 native_shared_libs: ["sdkshared", "sdkboth1"],
228 native_static_libs: ["sdkstatic", "sdkboth2"],
229 }
230
231 cc_library_shared {
232 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000233 stl: "none",
234 }
235
236 cc_library_static {
237 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000238 stl: "none",
239 }
240
241 cc_library {
242 name: "sdkboth1",
Paul Duffina0843f62019-12-13 19:50:38 +0000243 stl: "none",
244 }
245
246 cc_library {
247 name: "sdkboth2",
Paul Duffina0843f62019-12-13 19:50:38 +0000248 stl: "none",
249 }
250 `)
251}
252
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000253func TestSnapshotWithObject(t *testing.T) {
254 result := testSdkWithCc(t, `
255 sdk {
256 name: "mysdk",
257 native_objects: ["crtobj"],
258 }
259
260 cc_object {
261 name: "crtobj",
262 stl: "none",
263 }
264 `)
265
266 result.CheckSnapshot("mysdk", "",
267 checkAndroidBpContents(`
268// This is auto-generated. DO NOT EDIT.
269
270cc_prebuilt_object {
271 name: "mysdk_crtobj@current",
272 sdk_member_name: "crtobj",
273 stl: "none",
274 arch: {
275 arm64: {
276 srcs: ["arm64/lib/crtobj.o"],
277 },
278 arm: {
279 srcs: ["arm/lib/crtobj.o"],
280 },
281 },
282}
283
284cc_prebuilt_object {
285 name: "crtobj",
286 prefer: false,
287 stl: "none",
288 arch: {
289 arm64: {
290 srcs: ["arm64/lib/crtobj.o"],
291 },
292 arm: {
293 srcs: ["arm/lib/crtobj.o"],
294 },
295 },
296}
297
298sdk_snapshot {
299 name: "mysdk@current",
300 native_objects: ["mysdk_crtobj@current"],
301}
302`),
303 checkAllCopyRules(`
304.intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
305.intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
306`),
307 )
308}
309
Paul Duffinc62a5102019-12-11 18:34:15 +0000310func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
311 result := testSdkWithCc(t, `
312 sdk {
313 name: "mysdk",
314 native_shared_libs: ["mynativelib1", "mynativelib2"],
315 }
316
317 cc_library_shared {
318 name: "mynativelib1",
319 srcs: [
320 "Test.cpp",
321 ],
322 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000323 stl: "none",
324 }
325
326 cc_library_shared {
327 name: "mynativelib2",
328 srcs: [
329 "Test.cpp",
330 ],
331 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000332 stl: "none",
333 }
334 `)
335
Paul Duffin1356d8c2020-02-25 19:26:33 +0000336 result.CheckSnapshot("mysdk", "",
Paul Duffinc62a5102019-12-11 18:34:15 +0000337 checkAllCopyRules(`
338include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800339.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
340.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
341.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
342.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000343`),
344 )
345}
346
Paul Duffina7cd8c82019-12-11 20:00:57 +0000347// Verify that when the shared library has some common and some arch specific properties that the generated
348// snapshot is optimized properly.
349func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
350 result := testSdkWithCc(t, `
351 sdk {
352 name: "mysdk",
353 native_shared_libs: ["mynativelib"],
354 }
355
356 cc_library_shared {
357 name: "mynativelib",
358 srcs: [
359 "Test.cpp",
360 "aidl/foo/bar/Test.aidl",
361 ],
362 export_include_dirs: ["include"],
363 arch: {
364 arm64: {
365 export_system_include_dirs: ["arm64/include"],
366 },
367 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000368 stl: "none",
369 }
370 `)
371
Paul Duffin1356d8c2020-02-25 19:26:33 +0000372 result.CheckSnapshot("mysdk", "",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000373 checkAndroidBpContents(`
374// This is auto-generated. DO NOT EDIT.
375
376cc_prebuilt_library_shared {
377 name: "mysdk_mynativelib@current",
378 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000379 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000380 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000381 export_include_dirs: ["include/include"],
382 arch: {
383 arm64: {
384 srcs: ["arm64/lib/mynativelib.so"],
385 export_system_include_dirs: ["arm64/include/arm64/include"],
386 },
387 arm: {
388 srcs: ["arm/lib/mynativelib.so"],
389 },
390 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000391}
392
393cc_prebuilt_library_shared {
394 name: "mynativelib",
395 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000396 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000397 export_include_dirs: ["include/include"],
398 arch: {
399 arm64: {
400 srcs: ["arm64/lib/mynativelib.so"],
401 export_system_include_dirs: ["arm64/include/arm64/include"],
402 },
403 arm: {
404 srcs: ["arm/lib/mynativelib.so"],
405 },
406 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000407}
408
409sdk_snapshot {
410 name: "mysdk@current",
411 native_shared_libs: ["mysdk_mynativelib@current"],
412}
413`),
414 checkAllCopyRules(`
415include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800416.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000417arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800418.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000419 )
420}
421
Paul Duffin25ce04b2020-01-16 11:47:25 +0000422func TestSnapshotWithCcBinary(t *testing.T) {
423 result := testSdkWithCc(t, `
424 module_exports {
425 name: "mymodule_exports",
426 native_binaries: ["mynativebinary"],
427 }
428
429 cc_binary {
430 name: "mynativebinary",
431 srcs: [
432 "Test.cpp",
433 ],
434 compile_multilib: "both",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000435 }
436 `)
437
Paul Duffin1356d8c2020-02-25 19:26:33 +0000438 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000439 checkAndroidBpContents(`
440// This is auto-generated. DO NOT EDIT.
441
442cc_prebuilt_binary {
443 name: "mymodule_exports_mynativebinary@current",
444 sdk_member_name: "mynativebinary",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000445 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000446 compile_multilib: "both",
447 arch: {
448 arm64: {
449 srcs: ["arm64/bin/mynativebinary"],
450 },
451 arm: {
452 srcs: ["arm/bin/mynativebinary"],
453 },
454 },
455}
456
457cc_prebuilt_binary {
458 name: "mynativebinary",
459 prefer: false,
460 compile_multilib: "both",
461 arch: {
462 arm64: {
463 srcs: ["arm64/bin/mynativebinary"],
464 },
465 arm: {
466 srcs: ["arm/bin/mynativebinary"],
467 },
468 },
469}
470
471module_exports_snapshot {
472 name: "mymodule_exports@current",
473 native_binaries: ["mymodule_exports_mynativebinary@current"],
474}
475`),
476 checkAllCopyRules(`
477.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
478.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
479`),
480 )
481}
482
Paul Duffina04c1072020-03-02 10:16:35 +0000483func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
484 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
485 SkipIfNotLinux(t)
486
487 result := testSdkWithCc(t, `
488 module_exports {
489 name: "myexports",
490 device_supported: false,
491 host_supported: true,
492 native_binaries: ["mynativebinary"],
493 target: {
494 windows: {
495 enabled: true,
496 },
497 },
498 }
499
500 cc_binary {
501 name: "mynativebinary",
502 device_supported: false,
503 host_supported: true,
504 srcs: [
505 "Test.cpp",
506 ],
507 compile_multilib: "both",
Paul Duffina04c1072020-03-02 10:16:35 +0000508 stl: "none",
509 target: {
510 windows: {
511 enabled: true,
512 },
513 },
514 }
515 `)
516
517 result.CheckSnapshot("myexports", "",
518 checkAndroidBpContents(`
519// This is auto-generated. DO NOT EDIT.
520
521cc_prebuilt_binary {
522 name: "myexports_mynativebinary@current",
523 sdk_member_name: "mynativebinary",
524 device_supported: false,
525 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000526 installable: false,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100527 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000528 target: {
529 linux_glibc: {
530 compile_multilib: "both",
531 },
532 linux_glibc_x86_64: {
533 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
534 },
535 linux_glibc_x86: {
536 srcs: ["linux_glibc/x86/bin/mynativebinary"],
537 },
538 windows: {
539 compile_multilib: "64",
540 },
541 windows_x86_64: {
542 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
543 },
544 },
545}
546
547cc_prebuilt_binary {
548 name: "mynativebinary",
549 prefer: false,
550 device_supported: false,
551 host_supported: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100552 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000553 target: {
554 linux_glibc: {
555 compile_multilib: "both",
556 },
557 linux_glibc_x86_64: {
558 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
559 },
560 linux_glibc_x86: {
561 srcs: ["linux_glibc/x86/bin/mynativebinary"],
562 },
563 windows: {
564 compile_multilib: "64",
565 },
566 windows_x86_64: {
567 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
568 },
569 },
570}
571
572module_exports_snapshot {
573 name: "myexports@current",
574 device_supported: false,
575 host_supported: true,
576 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +0000577 target: {
578 windows: {
579 compile_multilib: "64",
580 },
581 },
Paul Duffina04c1072020-03-02 10:16:35 +0000582}
583`),
584 checkAllCopyRules(`
585.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
586.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
587.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
588`),
589 )
590}
591
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100592// Test that we support the necessary flags for the linker binary, which is
593// special in several ways.
594func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
595 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
596 SkipIfNotLinux(t)
597
598 result := testSdkWithCc(t, `
599 module_exports {
600 name: "mymodule_exports",
601 host_supported: true,
602 device_supported: false,
603 native_binaries: ["linker"],
604 }
605
606 cc_binary {
607 name: "linker",
608 host_supported: true,
609 static_executable: true,
610 nocrt: true,
611 stl: "none",
612 srcs: [
613 "Test.cpp",
614 ],
615 compile_multilib: "both",
616 }
617 `)
618
619 result.CheckSnapshot("mymodule_exports", "",
620 checkAndroidBpContents(`
621// This is auto-generated. DO NOT EDIT.
622
623cc_prebuilt_binary {
624 name: "mymodule_exports_linker@current",
625 sdk_member_name: "linker",
626 device_supported: false,
627 host_supported: true,
628 installable: false,
629 stl: "none",
630 static_executable: true,
631 nocrt: true,
632 compile_multilib: "both",
633 arch: {
634 x86_64: {
635 srcs: ["x86_64/bin/linker"],
636 },
637 x86: {
638 srcs: ["x86/bin/linker"],
639 },
640 },
641}
642
643cc_prebuilt_binary {
644 name: "linker",
645 prefer: false,
646 device_supported: false,
647 host_supported: true,
648 stl: "none",
649 static_executable: true,
650 nocrt: true,
651 compile_multilib: "both",
652 arch: {
653 x86_64: {
654 srcs: ["x86_64/bin/linker"],
655 },
656 x86: {
657 srcs: ["x86/bin/linker"],
658 },
659 },
660}
661
662module_exports_snapshot {
663 name: "mymodule_exports@current",
664 device_supported: false,
665 host_supported: true,
666 native_binaries: ["mymodule_exports_linker@current"],
667}
668`),
669 checkAllCopyRules(`
670.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
671.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
672`),
673 )
674}
675
Paul Duffin9ab556f2019-12-11 18:42:17 +0000676func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000677 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000678 sdk {
679 name: "mysdk",
680 native_shared_libs: ["mynativelib"],
681 }
682
683 cc_library_shared {
684 name: "mynativelib",
685 srcs: [
686 "Test.cpp",
687 "aidl/foo/bar/Test.aidl",
688 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000689 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000690 export_include_dirs: ["include"],
691 aidl: {
692 export_aidl_headers: true,
693 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000694 stl: "none",
695 }
696 `)
697
Paul Duffin1356d8c2020-02-25 19:26:33 +0000698 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000699 checkAndroidBpContents(`
700// This is auto-generated. DO NOT EDIT.
701
702cc_prebuilt_library_shared {
703 name: "mysdk_mynativelib@current",
704 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000705 apex_available: [
706 "apex1",
707 "apex2",
708 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000709 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000710 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000711 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000712 arch: {
713 arm64: {
714 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000715 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000716 },
717 arm: {
718 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000719 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000720 },
721 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000722}
723
724cc_prebuilt_library_shared {
725 name: "mynativelib",
726 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +0000727 apex_available: [
728 "apex1",
729 "apex2",
730 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +0000731 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000732 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000733 arch: {
734 arm64: {
735 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000736 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000737 },
738 arm: {
739 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000740 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000741 },
742 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000743}
744
745sdk_snapshot {
746 name: "mysdk@current",
747 native_shared_libs: ["mysdk_mynativelib@current"],
748}
749`),
750 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000751include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800752.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
753.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
754.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
755.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
756.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
757.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
758.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
759.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 +0000760`),
761 )
762}
763
Paul Duffin13f02712020-03-06 12:30:43 +0000764func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
765 result := testSdkWithCc(t, `
766 sdk {
767 name: "mysdk",
768 native_shared_libs: [
769 "mynativelib",
770 "myothernativelib",
771 "mysystemnativelib",
772 ],
773 }
774
775 cc_library {
776 name: "mysystemnativelib",
777 srcs: [
778 "Test.cpp",
779 ],
Paul Duffin13f02712020-03-06 12:30:43 +0000780 stl: "none",
781 }
782
783 cc_library_shared {
784 name: "myothernativelib",
785 srcs: [
786 "Test.cpp",
787 ],
788 system_shared_libs: [
789 // A reference to a library that is not an sdk member. Uses libm as that
790 // is in the default set of modules available to this test and so is available
791 // both here and also when the generated Android.bp file is tested in
792 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
793 // handles references to modules that are not sdk members.
794 "libm",
795 ],
796 stl: "none",
797 }
798
799 cc_library {
800 name: "mynativelib",
801 srcs: [
802 "Test.cpp",
803 ],
804 shared_libs: [
805 // A reference to another sdk member.
806 "myothernativelib",
807 ],
808 target: {
809 android: {
810 shared: {
811 shared_libs: [
812 // A reference to a library that is not an sdk member. The libc library
813 // is used here to check that the shared_libs property is handled correctly
814 // in a similar way to how libm is used to check system_shared_libs above.
815 "libc",
816 ],
817 },
818 },
819 },
Paul Duffin13f02712020-03-06 12:30:43 +0000820 stl: "none",
821 }
822 `)
823
824 result.CheckSnapshot("mysdk", "",
825 checkAndroidBpContents(`
826// This is auto-generated. DO NOT EDIT.
827
828cc_prebuilt_library_shared {
829 name: "mysdk_mynativelib@current",
830 sdk_member_name: "mynativelib",
831 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000832 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000833 shared_libs: [
834 "mysdk_myothernativelib@current",
835 "libc",
836 ],
837 arch: {
838 arm64: {
839 srcs: ["arm64/lib/mynativelib.so"],
840 },
841 arm: {
842 srcs: ["arm/lib/mynativelib.so"],
843 },
844 },
Paul Duffin13f02712020-03-06 12:30:43 +0000845}
846
847cc_prebuilt_library_shared {
848 name: "mynativelib",
849 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000850 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000851 shared_libs: [
852 "myothernativelib",
853 "libc",
854 ],
855 arch: {
856 arm64: {
857 srcs: ["arm64/lib/mynativelib.so"],
858 },
859 arm: {
860 srcs: ["arm/lib/mynativelib.so"],
861 },
862 },
Paul Duffin13f02712020-03-06 12:30:43 +0000863}
864
865cc_prebuilt_library_shared {
866 name: "mysdk_myothernativelib@current",
867 sdk_member_name: "myothernativelib",
868 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000869 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000870 system_shared_libs: ["libm"],
871 arch: {
872 arm64: {
873 srcs: ["arm64/lib/myothernativelib.so"],
874 },
875 arm: {
876 srcs: ["arm/lib/myothernativelib.so"],
877 },
878 },
Paul Duffin13f02712020-03-06 12:30:43 +0000879}
880
881cc_prebuilt_library_shared {
882 name: "myothernativelib",
883 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000884 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000885 system_shared_libs: ["libm"],
886 arch: {
887 arm64: {
888 srcs: ["arm64/lib/myothernativelib.so"],
889 },
890 arm: {
891 srcs: ["arm/lib/myothernativelib.so"],
892 },
893 },
Paul Duffin13f02712020-03-06 12:30:43 +0000894}
895
896cc_prebuilt_library_shared {
897 name: "mysdk_mysystemnativelib@current",
898 sdk_member_name: "mysystemnativelib",
899 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000900 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000901 arch: {
902 arm64: {
903 srcs: ["arm64/lib/mysystemnativelib.so"],
904 },
905 arm: {
906 srcs: ["arm/lib/mysystemnativelib.so"],
907 },
908 },
Paul Duffin13f02712020-03-06 12:30:43 +0000909}
910
911cc_prebuilt_library_shared {
912 name: "mysystemnativelib",
913 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000914 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000915 arch: {
916 arm64: {
917 srcs: ["arm64/lib/mysystemnativelib.so"],
918 },
919 arm: {
920 srcs: ["arm/lib/mysystemnativelib.so"],
921 },
922 },
Paul Duffin13f02712020-03-06 12:30:43 +0000923}
924
925sdk_snapshot {
926 name: "mysdk@current",
927 native_shared_libs: [
928 "mysdk_mynativelib@current",
929 "mysdk_myothernativelib@current",
930 "mysdk_mysystemnativelib@current",
931 ],
932}
933`),
934 checkAllCopyRules(`
935.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
936.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
937.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
938.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
939.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
940.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
941`),
942 )
943}
944
Paul Duffin9ab556f2019-12-11 18:42:17 +0000945func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000946 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
947 SkipIfNotLinux(t)
948
Paul Duffind835daa2019-11-30 17:49:09 +0000949 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000950 sdk {
951 name: "mysdk",
952 device_supported: false,
953 host_supported: true,
954 native_shared_libs: ["mynativelib"],
955 }
956
957 cc_library_shared {
958 name: "mynativelib",
959 device_supported: false,
960 host_supported: true,
961 srcs: [
962 "Test.cpp",
963 "aidl/foo/bar/Test.aidl",
964 ],
965 export_include_dirs: ["include"],
966 aidl: {
967 export_aidl_headers: true,
968 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000969 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +0000970 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +0000971 }
972 `)
973
Paul Duffin1356d8c2020-02-25 19:26:33 +0000974 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000975 checkAndroidBpContents(`
976// This is auto-generated. DO NOT EDIT.
977
978cc_prebuilt_library_shared {
979 name: "mysdk_mynativelib@current",
980 sdk_member_name: "mynativelib",
981 device_supported: false,
982 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000983 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +0000984 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000985 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000986 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000987 arch: {
988 x86_64: {
989 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000990 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000991 },
992 x86: {
993 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000994 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000995 },
996 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000997}
998
999cc_prebuilt_library_shared {
1000 name: "mynativelib",
1001 prefer: false,
1002 device_supported: false,
1003 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +00001004 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001005 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001006 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001007 arch: {
1008 x86_64: {
1009 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001010 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001011 },
1012 x86: {
1013 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001014 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001015 },
1016 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001017}
1018
1019sdk_snapshot {
1020 name: "mysdk@current",
1021 device_supported: false,
1022 host_supported: true,
1023 native_shared_libs: ["mysdk_mynativelib@current"],
1024}
1025`),
1026 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001027include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +00001028.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001029.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1030.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1031.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1032.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001033.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1034.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1035.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1036`),
1037 )
1038}
Paul Duffin9ab556f2019-12-11 18:42:17 +00001039
Paul Duffina04c1072020-03-02 10:16:35 +00001040func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
1041 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1042 SkipIfNotLinux(t)
1043
1044 result := testSdkWithCc(t, `
1045 sdk {
1046 name: "mysdk",
1047 device_supported: false,
1048 host_supported: true,
1049 native_shared_libs: ["mynativelib"],
1050 target: {
1051 windows: {
1052 enabled: true,
1053 },
1054 },
1055 }
1056
1057 cc_library_shared {
1058 name: "mynativelib",
1059 device_supported: false,
1060 host_supported: true,
1061 srcs: [
1062 "Test.cpp",
1063 ],
Paul Duffina04c1072020-03-02 10:16:35 +00001064 stl: "none",
1065 target: {
1066 windows: {
1067 enabled: true,
1068 },
1069 },
1070 }
1071 `)
1072
1073 result.CheckSnapshot("mysdk", "",
1074 checkAndroidBpContents(`
1075// This is auto-generated. DO NOT EDIT.
1076
1077cc_prebuilt_library_shared {
1078 name: "mysdk_mynativelib@current",
1079 sdk_member_name: "mynativelib",
1080 device_supported: false,
1081 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001082 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001083 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001084 target: {
1085 linux_glibc_x86_64: {
1086 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1087 },
1088 linux_glibc_x86: {
1089 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1090 },
1091 windows_x86_64: {
1092 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1093 },
1094 },
Paul Duffina04c1072020-03-02 10:16:35 +00001095}
1096
1097cc_prebuilt_library_shared {
1098 name: "mynativelib",
1099 prefer: false,
1100 device_supported: false,
1101 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001102 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001103 target: {
1104 linux_glibc_x86_64: {
1105 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1106 },
1107 linux_glibc_x86: {
1108 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1109 },
1110 windows_x86_64: {
1111 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1112 },
1113 },
Paul Duffina04c1072020-03-02 10:16:35 +00001114}
1115
1116sdk_snapshot {
1117 name: "mysdk@current",
1118 device_supported: false,
1119 host_supported: true,
1120 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +00001121 target: {
1122 windows: {
1123 compile_multilib: "64",
1124 },
1125 },
Paul Duffina04c1072020-03-02 10:16:35 +00001126}
1127`),
1128 checkAllCopyRules(`
1129.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1130.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1131.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1132`),
1133 )
1134}
1135
Paul Duffin9ab556f2019-12-11 18:42:17 +00001136func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1137 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001138 module_exports {
1139 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001140 native_static_libs: ["mynativelib"],
1141 }
1142
1143 cc_library_static {
1144 name: "mynativelib",
1145 srcs: [
1146 "Test.cpp",
1147 "aidl/foo/bar/Test.aidl",
1148 ],
1149 export_include_dirs: ["include"],
1150 aidl: {
1151 export_aidl_headers: true,
1152 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001153 stl: "none",
1154 }
1155 `)
1156
Paul Duffin1356d8c2020-02-25 19:26:33 +00001157 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001158 checkAndroidBpContents(`
1159// This is auto-generated. DO NOT EDIT.
1160
1161cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001162 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001163 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001164 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001165 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001166 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001167 arch: {
1168 arm64: {
1169 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001170 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001171 },
1172 arm: {
1173 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001174 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001175 },
1176 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001177}
1178
1179cc_prebuilt_library_static {
1180 name: "mynativelib",
1181 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001182 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001183 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001184 arch: {
1185 arm64: {
1186 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001187 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001188 },
1189 arm: {
1190 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001191 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001192 },
1193 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001194}
1195
Paul Duffine6029182019-12-16 17:43:48 +00001196module_exports_snapshot {
1197 name: "myexports@current",
1198 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001199}
1200`),
1201 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001202include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001203.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1204.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1205.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1206.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1207.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1208.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1209.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1210.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 +00001211`),
1212 )
1213}
1214
1215func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1216 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1217 SkipIfNotLinux(t)
1218
1219 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001220 module_exports {
1221 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001222 device_supported: false,
1223 host_supported: true,
1224 native_static_libs: ["mynativelib"],
1225 }
1226
1227 cc_library_static {
1228 name: "mynativelib",
1229 device_supported: false,
1230 host_supported: true,
1231 srcs: [
1232 "Test.cpp",
1233 "aidl/foo/bar/Test.aidl",
1234 ],
1235 export_include_dirs: ["include"],
1236 aidl: {
1237 export_aidl_headers: true,
1238 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001239 stl: "none",
1240 }
1241 `)
1242
Paul Duffin1356d8c2020-02-25 19:26:33 +00001243 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001244 checkAndroidBpContents(`
1245// This is auto-generated. DO NOT EDIT.
1246
1247cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001248 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001249 sdk_member_name: "mynativelib",
1250 device_supported: false,
1251 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001252 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001253 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001254 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001255 arch: {
1256 x86_64: {
1257 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001258 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001259 },
1260 x86: {
1261 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001262 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001263 },
1264 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001265}
1266
1267cc_prebuilt_library_static {
1268 name: "mynativelib",
1269 prefer: false,
1270 device_supported: false,
1271 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001272 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001273 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001274 arch: {
1275 x86_64: {
1276 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001277 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001278 },
1279 x86: {
1280 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001281 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001282 },
1283 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001284}
1285
Paul Duffine6029182019-12-16 17:43:48 +00001286module_exports_snapshot {
1287 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001288 device_supported: false,
1289 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001290 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001291}
1292`),
1293 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001294include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001295.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001296.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1297.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1298.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1299.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001300.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1301.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1302.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1303`),
1304 )
1305}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001306
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001307func TestSnapshotWithCcLibrary(t *testing.T) {
1308 result := testSdkWithCc(t, `
1309 module_exports {
1310 name: "myexports",
1311 native_libs: ["mynativelib"],
1312 }
1313
1314 cc_library {
1315 name: "mynativelib",
1316 srcs: [
1317 "Test.cpp",
1318 ],
1319 export_include_dirs: ["include"],
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001320 stl: "none",
1321 }
1322 `)
1323
1324 result.CheckSnapshot("myexports", "",
1325 checkAndroidBpContents(`
1326// This is auto-generated. DO NOT EDIT.
1327
1328cc_prebuilt_library {
1329 name: "myexports_mynativelib@current",
1330 sdk_member_name: "mynativelib",
1331 installable: false,
1332 stl: "none",
1333 export_include_dirs: ["include/include"],
1334 arch: {
1335 arm64: {
1336 static: {
1337 srcs: ["arm64/lib/mynativelib.a"],
1338 },
1339 shared: {
1340 srcs: ["arm64/lib/mynativelib.so"],
1341 },
1342 },
1343 arm: {
1344 static: {
1345 srcs: ["arm/lib/mynativelib.a"],
1346 },
1347 shared: {
1348 srcs: ["arm/lib/mynativelib.so"],
1349 },
1350 },
1351 },
1352}
1353
1354cc_prebuilt_library {
1355 name: "mynativelib",
1356 prefer: false,
1357 stl: "none",
1358 export_include_dirs: ["include/include"],
1359 arch: {
1360 arm64: {
1361 static: {
1362 srcs: ["arm64/lib/mynativelib.a"],
1363 },
1364 shared: {
1365 srcs: ["arm64/lib/mynativelib.so"],
1366 },
1367 },
1368 arm: {
1369 static: {
1370 srcs: ["arm/lib/mynativelib.a"],
1371 },
1372 shared: {
1373 srcs: ["arm/lib/mynativelib.so"],
1374 },
1375 },
1376 },
1377}
1378
1379module_exports_snapshot {
1380 name: "myexports@current",
1381 native_libs: ["myexports_mynativelib@current"],
1382}
1383`),
1384 checkAllCopyRules(`
1385include/Test.h -> include/include/Test.h
1386.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1387.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1388.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1389.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1390 )
1391}
1392
Paul Duffin13ad94f2020-02-19 16:19:27 +00001393func TestHostSnapshotWithMultiLib64(t *testing.T) {
1394 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1395 SkipIfNotLinux(t)
1396
1397 result := testSdkWithCc(t, `
1398 module_exports {
1399 name: "myexports",
1400 device_supported: false,
1401 host_supported: true,
1402 target: {
1403 host: {
1404 compile_multilib: "64",
1405 },
1406 },
1407 native_static_libs: ["mynativelib"],
1408 }
1409
1410 cc_library_static {
1411 name: "mynativelib",
1412 device_supported: false,
1413 host_supported: true,
1414 srcs: [
1415 "Test.cpp",
1416 "aidl/foo/bar/Test.aidl",
1417 ],
1418 export_include_dirs: ["include"],
1419 aidl: {
1420 export_aidl_headers: true,
1421 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001422 stl: "none",
1423 }
1424 `)
1425
Paul Duffin1356d8c2020-02-25 19:26:33 +00001426 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001427 checkAndroidBpContents(`
1428// This is auto-generated. DO NOT EDIT.
1429
1430cc_prebuilt_library_static {
1431 name: "myexports_mynativelib@current",
1432 sdk_member_name: "mynativelib",
1433 device_supported: false,
1434 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001435 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001436 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001437 export_include_dirs: ["include/include"],
1438 arch: {
1439 x86_64: {
1440 srcs: ["x86_64/lib/mynativelib.a"],
1441 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1442 },
1443 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001444}
1445
1446cc_prebuilt_library_static {
1447 name: "mynativelib",
1448 prefer: false,
1449 device_supported: false,
1450 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001451 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001452 export_include_dirs: ["include/include"],
1453 arch: {
1454 x86_64: {
1455 srcs: ["x86_64/lib/mynativelib.a"],
1456 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1457 },
1458 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001459}
1460
1461module_exports_snapshot {
1462 name: "myexports@current",
1463 device_supported: false,
1464 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001465 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin13ad94f2020-02-19 16:19:27 +00001466 target: {
Paul Duffin6a7e9532020-03-20 17:50:07 +00001467 linux_glibc: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001468 compile_multilib: "64",
1469 },
1470 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001471}`),
1472 checkAllCopyRules(`
1473include/Test.h -> include/include/Test.h
1474.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1475.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1476.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1477.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1478`),
1479 )
1480}
Paul Duffin91756d22020-02-21 16:29:57 +00001481
1482func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1483 result := testSdkWithCc(t, `
1484 sdk {
1485 name: "mysdk",
1486 native_header_libs: ["mynativeheaders"],
1487 }
1488
1489 cc_library_headers {
1490 name: "mynativeheaders",
1491 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001492 stl: "none",
1493 }
1494 `)
1495
Paul Duffin1356d8c2020-02-25 19:26:33 +00001496 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001497 checkAndroidBpContents(`
1498// This is auto-generated. DO NOT EDIT.
1499
1500cc_prebuilt_library_headers {
1501 name: "mysdk_mynativeheaders@current",
1502 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001503 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001504 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001505}
1506
1507cc_prebuilt_library_headers {
1508 name: "mynativeheaders",
1509 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001510 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001511 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001512}
1513
1514sdk_snapshot {
1515 name: "mysdk@current",
1516 native_header_libs: ["mysdk_mynativeheaders@current"],
1517}
1518`),
1519 checkAllCopyRules(`
1520include/Test.h -> include/include/Test.h
1521`),
1522 )
1523}
1524
1525func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1526 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1527 SkipIfNotLinux(t)
1528
1529 result := testSdkWithCc(t, `
1530 sdk {
1531 name: "mysdk",
1532 device_supported: false,
1533 host_supported: true,
1534 native_header_libs: ["mynativeheaders"],
1535 }
1536
1537 cc_library_headers {
1538 name: "mynativeheaders",
1539 device_supported: false,
1540 host_supported: true,
1541 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001542 stl: "none",
1543 }
1544 `)
1545
Paul Duffin1356d8c2020-02-25 19:26:33 +00001546 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001547 checkAndroidBpContents(`
1548// This is auto-generated. DO NOT EDIT.
1549
1550cc_prebuilt_library_headers {
1551 name: "mysdk_mynativeheaders@current",
1552 sdk_member_name: "mynativeheaders",
1553 device_supported: false,
1554 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001555 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001556 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001557}
1558
1559cc_prebuilt_library_headers {
1560 name: "mynativeheaders",
1561 prefer: false,
1562 device_supported: false,
1563 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001564 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001565 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001566}
1567
1568sdk_snapshot {
1569 name: "mysdk@current",
1570 device_supported: false,
1571 host_supported: true,
1572 native_header_libs: ["mysdk_mynativeheaders@current"],
1573}
1574`),
1575 checkAllCopyRules(`
1576include/Test.h -> include/include/Test.h
1577`),
1578 )
1579}
Paul Duffina04c1072020-03-02 10:16:35 +00001580
1581func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1582 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1583 SkipIfNotLinux(t)
1584
1585 result := testSdkWithCc(t, `
1586 sdk {
1587 name: "mysdk",
1588 host_supported: true,
1589 native_header_libs: ["mynativeheaders"],
1590 }
1591
1592 cc_library_headers {
1593 name: "mynativeheaders",
1594 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00001595 stl: "none",
1596 export_system_include_dirs: ["include"],
1597 target: {
1598 android: {
1599 export_include_dirs: ["include-android"],
1600 },
1601 host: {
1602 export_include_dirs: ["include-host"],
1603 },
1604 },
1605 }
1606 `)
1607
1608 result.CheckSnapshot("mysdk", "",
1609 checkAndroidBpContents(`
1610// This is auto-generated. DO NOT EDIT.
1611
1612cc_prebuilt_library_headers {
1613 name: "mysdk_mynativeheaders@current",
1614 sdk_member_name: "mynativeheaders",
1615 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001616 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001617 export_system_include_dirs: ["include/include"],
1618 target: {
1619 android: {
1620 export_include_dirs: ["include/include-android"],
1621 },
1622 linux_glibc: {
1623 export_include_dirs: ["include/include-host"],
1624 },
1625 },
Paul Duffina04c1072020-03-02 10:16:35 +00001626}
1627
1628cc_prebuilt_library_headers {
1629 name: "mynativeheaders",
1630 prefer: false,
1631 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001632 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001633 export_system_include_dirs: ["include/include"],
1634 target: {
1635 android: {
1636 export_include_dirs: ["include/include-android"],
1637 },
1638 linux_glibc: {
1639 export_include_dirs: ["include/include-host"],
1640 },
1641 },
Paul Duffina04c1072020-03-02 10:16:35 +00001642}
1643
1644sdk_snapshot {
1645 name: "mysdk@current",
1646 host_supported: true,
1647 native_header_libs: ["mysdk_mynativeheaders@current"],
1648}
1649`),
1650 checkAllCopyRules(`
1651include/Test.h -> include/include/Test.h
1652include-android/AndroidTest.h -> include/include-android/AndroidTest.h
1653include-host/HostTest.h -> include/include-host/HostTest.h
1654`),
1655 )
1656}
Martin Stjernholm10566a02020-03-24 01:19:52 +00001657
1658func TestSystemSharedLibPropagation(t *testing.T) {
Martin Stjernholm66a06942020-03-26 17:39:30 +00001659 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1660 SkipIfNotLinux(t)
1661
Martin Stjernholm10566a02020-03-24 01:19:52 +00001662 result := testSdkWithCc(t, `
1663 sdk {
1664 name: "mysdk",
1665 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
1666 }
1667
1668 cc_library {
1669 name: "sslnil",
1670 host_supported: true,
1671 }
1672
1673 cc_library {
1674 name: "sslempty",
1675 system_shared_libs: [],
1676 }
1677
1678 cc_library {
1679 name: "sslnonempty",
1680 system_shared_libs: ["sslnil"],
1681 }
1682 `)
1683
1684 result.CheckSnapshot("mysdk", "",
1685 checkAndroidBpContents(`
1686// This is auto-generated. DO NOT EDIT.
1687
1688cc_prebuilt_library_shared {
1689 name: "mysdk_sslnil@current",
1690 sdk_member_name: "sslnil",
1691 installable: false,
1692 arch: {
1693 arm64: {
1694 srcs: ["arm64/lib/sslnil.so"],
1695 },
1696 arm: {
1697 srcs: ["arm/lib/sslnil.so"],
1698 },
1699 },
1700}
1701
1702cc_prebuilt_library_shared {
1703 name: "sslnil",
1704 prefer: false,
1705 arch: {
1706 arm64: {
1707 srcs: ["arm64/lib/sslnil.so"],
1708 },
1709 arm: {
1710 srcs: ["arm/lib/sslnil.so"],
1711 },
1712 },
1713}
1714
1715cc_prebuilt_library_shared {
1716 name: "mysdk_sslempty@current",
1717 sdk_member_name: "sslempty",
1718 installable: false,
1719 system_shared_libs: [],
1720 arch: {
1721 arm64: {
1722 srcs: ["arm64/lib/sslempty.so"],
1723 },
1724 arm: {
1725 srcs: ["arm/lib/sslempty.so"],
1726 },
1727 },
1728}
1729
1730cc_prebuilt_library_shared {
1731 name: "sslempty",
1732 prefer: false,
1733 system_shared_libs: [],
1734 arch: {
1735 arm64: {
1736 srcs: ["arm64/lib/sslempty.so"],
1737 },
1738 arm: {
1739 srcs: ["arm/lib/sslempty.so"],
1740 },
1741 },
1742}
1743
1744cc_prebuilt_library_shared {
1745 name: "mysdk_sslnonempty@current",
1746 sdk_member_name: "sslnonempty",
1747 installable: false,
1748 system_shared_libs: ["mysdk_sslnil@current"],
1749 arch: {
1750 arm64: {
1751 srcs: ["arm64/lib/sslnonempty.so"],
1752 },
1753 arm: {
1754 srcs: ["arm/lib/sslnonempty.so"],
1755 },
1756 },
1757}
1758
1759cc_prebuilt_library_shared {
1760 name: "sslnonempty",
1761 prefer: false,
1762 system_shared_libs: ["sslnil"],
1763 arch: {
1764 arm64: {
1765 srcs: ["arm64/lib/sslnonempty.so"],
1766 },
1767 arm: {
1768 srcs: ["arm/lib/sslnonempty.so"],
1769 },
1770 },
1771}
1772
1773sdk_snapshot {
1774 name: "mysdk@current",
1775 native_shared_libs: [
1776 "mysdk_sslnil@current",
1777 "mysdk_sslempty@current",
1778 "mysdk_sslnonempty@current",
1779 ],
1780}
1781`))
1782
1783 result = testSdkWithCc(t, `
1784 sdk {
1785 name: "mysdk",
1786 host_supported: true,
1787 native_shared_libs: ["sslvariants"],
1788 }
1789
1790 cc_library {
1791 name: "sslvariants",
1792 host_supported: true,
1793 target: {
1794 android: {
1795 system_shared_libs: [],
1796 },
1797 },
1798 }
1799 `)
1800
1801 result.CheckSnapshot("mysdk", "",
1802 checkAndroidBpContents(`
1803// This is auto-generated. DO NOT EDIT.
1804
1805cc_prebuilt_library_shared {
1806 name: "mysdk_sslvariants@current",
1807 sdk_member_name: "sslvariants",
1808 host_supported: true,
1809 installable: false,
1810 target: {
1811 android: {
1812 system_shared_libs: [],
1813 },
1814 android_arm64: {
1815 srcs: ["android/arm64/lib/sslvariants.so"],
1816 },
1817 android_arm: {
1818 srcs: ["android/arm/lib/sslvariants.so"],
1819 },
1820 linux_glibc_x86_64: {
1821 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1822 },
1823 linux_glibc_x86: {
1824 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1825 },
1826 },
1827}
1828
1829cc_prebuilt_library_shared {
1830 name: "sslvariants",
1831 prefer: false,
1832 host_supported: true,
1833 target: {
1834 android: {
1835 system_shared_libs: [],
1836 },
1837 android_arm64: {
1838 srcs: ["android/arm64/lib/sslvariants.so"],
1839 },
1840 android_arm: {
1841 srcs: ["android/arm/lib/sslvariants.so"],
1842 },
1843 linux_glibc_x86_64: {
1844 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1845 },
1846 linux_glibc_x86: {
1847 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1848 },
1849 },
1850}
1851
1852sdk_snapshot {
1853 name: "mysdk@current",
1854 host_supported: true,
1855 native_shared_libs: ["mysdk_sslvariants@current"],
1856}
1857`))
1858}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001859
1860func TestStubsLibrary(t *testing.T) {
1861 result := testSdkWithCc(t, `
1862 sdk {
1863 name: "mysdk",
1864 native_shared_libs: ["stubslib"],
1865 }
1866
1867 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001868 name: "internaldep",
1869 }
1870
1871 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001872 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001873 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001874 stubs: {
1875 symbol_file: "some/where/stubslib.map.txt",
1876 versions: ["1", "2", "3"],
1877 },
1878 }
1879 `)
1880
1881 result.CheckSnapshot("mysdk", "",
1882 checkAndroidBpContents(`
1883// This is auto-generated. DO NOT EDIT.
1884
1885cc_prebuilt_library_shared {
1886 name: "mysdk_stubslib@current",
1887 sdk_member_name: "stubslib",
1888 installable: false,
1889 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001890 versions: ["3"],
1891 },
1892 arch: {
1893 arm64: {
1894 srcs: ["arm64/lib/stubslib.so"],
1895 },
1896 arm: {
1897 srcs: ["arm/lib/stubslib.so"],
1898 },
1899 },
1900}
1901
1902cc_prebuilt_library_shared {
1903 name: "stubslib",
1904 prefer: false,
1905 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001906 versions: ["3"],
1907 },
1908 arch: {
1909 arm64: {
1910 srcs: ["arm64/lib/stubslib.so"],
1911 },
1912 arm: {
1913 srcs: ["arm/lib/stubslib.so"],
1914 },
1915 },
1916}
1917
1918sdk_snapshot {
1919 name: "mysdk@current",
1920 native_shared_libs: ["mysdk_stubslib@current"],
1921}
1922`))
1923}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01001924
1925func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
1926 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1927 SkipIfNotLinux(t)
1928
1929 result := testSdkWithCc(t, `
1930 sdk {
1931 name: "mysdk",
1932 host_supported: true,
1933 native_shared_libs: ["stubslib"],
1934 }
1935
1936 cc_library {
1937 name: "internaldep",
1938 host_supported: true,
1939 }
1940
1941 cc_library {
1942 name: "stubslib",
1943 host_supported: true,
1944 shared_libs: ["internaldep"],
1945 stubs: {
1946 symbol_file: "some/where/stubslib.map.txt",
1947 versions: ["1", "2", "3"],
1948 },
1949 }
1950 `)
1951
1952 result.CheckSnapshot("mysdk", "",
1953 checkAndroidBpContents(`
1954// This is auto-generated. DO NOT EDIT.
1955
1956cc_prebuilt_library_shared {
1957 name: "mysdk_stubslib@current",
1958 sdk_member_name: "stubslib",
1959 host_supported: true,
1960 installable: false,
1961 stubs: {
1962 versions: ["3"],
1963 },
1964 target: {
1965 android_arm64: {
1966 srcs: ["android/arm64/lib/stubslib.so"],
1967 },
1968 android_arm: {
1969 srcs: ["android/arm/lib/stubslib.so"],
1970 },
1971 linux_glibc_x86_64: {
1972 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
1973 },
1974 linux_glibc_x86: {
1975 srcs: ["linux_glibc/x86/lib/stubslib.so"],
1976 },
1977 },
1978}
1979
1980cc_prebuilt_library_shared {
1981 name: "stubslib",
1982 prefer: false,
1983 host_supported: true,
1984 stubs: {
1985 versions: ["3"],
1986 },
1987 target: {
1988 android_arm64: {
1989 srcs: ["android/arm64/lib/stubslib.so"],
1990 },
1991 android_arm: {
1992 srcs: ["android/arm/lib/stubslib.so"],
1993 },
1994 linux_glibc_x86_64: {
1995 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
1996 },
1997 linux_glibc_x86: {
1998 srcs: ["linux_glibc/x86/lib/stubslib.so"],
1999 },
2000 },
2001}
2002
2003sdk_snapshot {
2004 name: "mysdk@current",
2005 host_supported: true,
2006 native_shared_libs: ["mysdk_stubslib@current"],
2007}
2008`))
2009}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002010
2011func TestUniqueHostSoname(t *testing.T) {
2012 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
2013 SkipIfNotLinux(t)
2014
2015 result := testSdkWithCc(t, `
2016 sdk {
2017 name: "mysdk",
2018 host_supported: true,
2019 native_shared_libs: ["mylib"],
2020 }
2021
2022 cc_library {
2023 name: "mylib",
2024 host_supported: true,
2025 unique_host_soname: true,
2026 }
2027 `)
2028
2029 result.CheckSnapshot("mysdk", "",
2030 checkAndroidBpContents(`
2031// This is auto-generated. DO NOT EDIT.
2032
2033cc_prebuilt_library_shared {
2034 name: "mysdk_mylib@current",
2035 sdk_member_name: "mylib",
2036 host_supported: true,
2037 installable: false,
2038 unique_host_soname: true,
2039 target: {
2040 android_arm64: {
2041 srcs: ["android/arm64/lib/mylib.so"],
2042 },
2043 android_arm: {
2044 srcs: ["android/arm/lib/mylib.so"],
2045 },
2046 linux_glibc_x86_64: {
2047 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2048 },
2049 linux_glibc_x86: {
2050 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2051 },
2052 },
2053}
2054
2055cc_prebuilt_library_shared {
2056 name: "mylib",
2057 prefer: false,
2058 host_supported: true,
2059 unique_host_soname: true,
2060 target: {
2061 android_arm64: {
2062 srcs: ["android/arm64/lib/mylib.so"],
2063 },
2064 android_arm: {
2065 srcs: ["android/arm/lib/mylib.so"],
2066 },
2067 linux_glibc_x86_64: {
2068 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2069 },
2070 linux_glibc_x86: {
2071 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2072 },
2073 },
2074}
2075
2076sdk_snapshot {
2077 name: "mysdk@current",
2078 host_supported: true,
2079 native_shared_libs: ["mysdk_mylib@current"],
2080}
2081`),
2082 checkAllCopyRules(`
2083.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2084.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2085.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2086.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2087`),
2088 )
2089}