blob: ca40afd04946b98666d4f503646deb9685133003 [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,
Paul Duffind835daa2019-11-30 17:49:09 +000035 }
36 return testSdkWithFs(t, bp, fs)
37}
38
Paul Duffina80fdec2019-12-03 15:25:00 +000039// Contains tests for SDK members provided by the cc package.
40
41func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000042 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000043 sdk {
44 name: "mysdk",
45 native_shared_libs: ["sdkmember"],
46 }
47
48 cc_library_shared {
49 name: "sdkmember",
50 srcs: ["Test.cpp"],
51 system_shared_libs: [],
52 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: [],
Paul Duffina0843f62019-12-13 19:50:38 +000082 }
83
Paul Duffina80fdec2019-12-03 15:25:00 +000084 sdk_snapshot {
85 name: "mysdk@1",
86 native_shared_libs: ["sdkmember_mysdk_1"],
87 }
88
89 sdk_snapshot {
90 name: "mysdk@2",
91 native_shared_libs: ["sdkmember_mysdk_2"],
92 }
93
94 cc_prebuilt_library_shared {
95 name: "sdkmember",
96 srcs: ["libfoo.so"],
97 prefer: false,
98 system_shared_libs: [],
99 stl: "none",
100 }
101
102 cc_prebuilt_library_shared {
103 name: "sdkmember_mysdk_1",
104 sdk_member_name: "sdkmember",
105 srcs: ["libfoo.so"],
106 system_shared_libs: [],
107 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000108 // TODO: remove //apex_available:platform
109 apex_available: [
110 "//apex_available:platform",
111 "myapex",
112 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000113 }
114
115 cc_prebuilt_library_shared {
116 name: "sdkmember_mysdk_2",
117 sdk_member_name: "sdkmember",
118 srcs: ["libfoo.so"],
119 system_shared_libs: [],
120 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000121 // TODO: remove //apex_available:platform
122 apex_available: [
123 "//apex_available:platform",
124 "myapex2",
125 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000126 }
127
128 cc_library_shared {
129 name: "mycpplib",
130 srcs: ["Test.cpp"],
131 shared_libs: ["sdkmember"],
132 system_shared_libs: [],
133 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000134 apex_available: [
135 "myapex",
136 "myapex2",
137 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000138 }
139
140 apex {
141 name: "myapex",
142 native_shared_libs: ["mycpplib"],
143 uses_sdks: ["mysdk@1"],
144 key: "myapex.key",
145 certificate: ":myapex.cert",
146 }
147
148 apex {
149 name: "myapex2",
150 native_shared_libs: ["mycpplib"],
151 uses_sdks: ["mysdk@2"],
152 key: "myapex.key",
153 certificate: ":myapex.cert",
154 }
155 `)
156
Colin Cross7113d202019-11-20 16:39:12 -0800157 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_myapex").Rule("toc").Output
158 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_myapex2").Rule("toc").Output
Paul Duffina80fdec2019-12-03 15:25:00 +0000159
Colin Cross7113d202019-11-20 16:39:12 -0800160 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex")
161 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex2")
Paul Duffina80fdec2019-12-03 15:25:00 +0000162
163 // Depending on the uses_sdks value, different libs are linked
164 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
165 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
166}
167
Paul Duffina0843f62019-12-13 19:50:38 +0000168// Make sure the sdk can use host specific cc libraries static/shared and both.
169func TestHostSdkWithCc(t *testing.T) {
170 testSdkWithCc(t, `
171 sdk {
172 name: "mysdk",
173 device_supported: false,
174 host_supported: true,
175 native_shared_libs: ["sdkshared"],
176 native_static_libs: ["sdkstatic"],
177 }
178
179 cc_library_host_shared {
180 name: "sdkshared",
181 system_shared_libs: [],
182 stl: "none",
183 }
184
185 cc_library_host_static {
186 name: "sdkstatic",
187 system_shared_libs: [],
188 stl: "none",
189 }
190 `)
191}
192
193// Make sure the sdk can use cc libraries static/shared and both.
194func TestSdkWithCc(t *testing.T) {
195 testSdkWithCc(t, `
196 sdk {
197 name: "mysdk",
198 native_shared_libs: ["sdkshared", "sdkboth1"],
199 native_static_libs: ["sdkstatic", "sdkboth2"],
200 }
201
202 cc_library_shared {
203 name: "sdkshared",
204 system_shared_libs: [],
205 stl: "none",
206 }
207
208 cc_library_static {
209 name: "sdkstatic",
210 system_shared_libs: [],
211 stl: "none",
212 }
213
214 cc_library {
215 name: "sdkboth1",
216 system_shared_libs: [],
217 stl: "none",
218 }
219
220 cc_library {
221 name: "sdkboth2",
222 system_shared_libs: [],
223 stl: "none",
224 }
225 `)
226}
227
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000228func TestSnapshotWithObject(t *testing.T) {
229 result := testSdkWithCc(t, `
230 sdk {
231 name: "mysdk",
232 native_objects: ["crtobj"],
233 }
234
235 cc_object {
236 name: "crtobj",
237 stl: "none",
238 }
239 `)
240
241 result.CheckSnapshot("mysdk", "",
242 checkAndroidBpContents(`
243// This is auto-generated. DO NOT EDIT.
244
245cc_prebuilt_object {
246 name: "mysdk_crtobj@current",
247 sdk_member_name: "crtobj",
248 stl: "none",
249 arch: {
250 arm64: {
251 srcs: ["arm64/lib/crtobj.o"],
252 },
253 arm: {
254 srcs: ["arm/lib/crtobj.o"],
255 },
256 },
257}
258
259cc_prebuilt_object {
260 name: "crtobj",
261 prefer: false,
262 stl: "none",
263 arch: {
264 arm64: {
265 srcs: ["arm64/lib/crtobj.o"],
266 },
267 arm: {
268 srcs: ["arm/lib/crtobj.o"],
269 },
270 },
271}
272
273sdk_snapshot {
274 name: "mysdk@current",
275 native_objects: ["mysdk_crtobj@current"],
276}
277`),
278 checkAllCopyRules(`
279.intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
280.intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
281`),
282 )
283}
284
Paul Duffinc62a5102019-12-11 18:34:15 +0000285func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
286 result := testSdkWithCc(t, `
287 sdk {
288 name: "mysdk",
289 native_shared_libs: ["mynativelib1", "mynativelib2"],
290 }
291
292 cc_library_shared {
293 name: "mynativelib1",
294 srcs: [
295 "Test.cpp",
296 ],
297 export_include_dirs: ["include"],
298 system_shared_libs: [],
299 stl: "none",
300 }
301
302 cc_library_shared {
303 name: "mynativelib2",
304 srcs: [
305 "Test.cpp",
306 ],
307 export_include_dirs: ["include"],
308 system_shared_libs: [],
309 stl: "none",
310 }
311 `)
312
Paul Duffin1356d8c2020-02-25 19:26:33 +0000313 result.CheckSnapshot("mysdk", "",
Paul Duffinc62a5102019-12-11 18:34:15 +0000314 checkAllCopyRules(`
315include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800316.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
317.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
318.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
319.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000320`),
321 )
322}
323
Paul Duffina7cd8c82019-12-11 20:00:57 +0000324// Verify that when the shared library has some common and some arch specific properties that the generated
325// snapshot is optimized properly.
326func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
327 result := testSdkWithCc(t, `
328 sdk {
329 name: "mysdk",
330 native_shared_libs: ["mynativelib"],
331 }
332
333 cc_library_shared {
334 name: "mynativelib",
335 srcs: [
336 "Test.cpp",
337 "aidl/foo/bar/Test.aidl",
338 ],
339 export_include_dirs: ["include"],
340 arch: {
341 arm64: {
342 export_system_include_dirs: ["arm64/include"],
343 },
344 },
345 system_shared_libs: [],
346 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",
413 system_shared_libs: [],
414 stl: "none",
415 }
416 `)
417
Paul Duffin1356d8c2020-02-25 19:26:33 +0000418 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000419 checkAndroidBpContents(`
420// This is auto-generated. DO NOT EDIT.
421
422cc_prebuilt_binary {
423 name: "mymodule_exports_mynativebinary@current",
424 sdk_member_name: "mynativebinary",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000425 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000426 compile_multilib: "both",
427 arch: {
428 arm64: {
429 srcs: ["arm64/bin/mynativebinary"],
430 },
431 arm: {
432 srcs: ["arm/bin/mynativebinary"],
433 },
434 },
435}
436
437cc_prebuilt_binary {
438 name: "mynativebinary",
439 prefer: false,
440 compile_multilib: "both",
441 arch: {
442 arm64: {
443 srcs: ["arm64/bin/mynativebinary"],
444 },
445 arm: {
446 srcs: ["arm/bin/mynativebinary"],
447 },
448 },
449}
450
451module_exports_snapshot {
452 name: "mymodule_exports@current",
453 native_binaries: ["mymodule_exports_mynativebinary@current"],
454}
455`),
456 checkAllCopyRules(`
457.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
458.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
459`),
460 )
461}
462
Paul Duffina04c1072020-03-02 10:16:35 +0000463func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
464 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
465 SkipIfNotLinux(t)
466
467 result := testSdkWithCc(t, `
468 module_exports {
469 name: "myexports",
470 device_supported: false,
471 host_supported: true,
472 native_binaries: ["mynativebinary"],
473 target: {
474 windows: {
475 enabled: true,
476 },
477 },
478 }
479
480 cc_binary {
481 name: "mynativebinary",
482 device_supported: false,
483 host_supported: true,
484 srcs: [
485 "Test.cpp",
486 ],
487 compile_multilib: "both",
488 system_shared_libs: [],
489 stl: "none",
490 target: {
491 windows: {
492 enabled: true,
493 },
494 },
495 }
496 `)
497
498 result.CheckSnapshot("myexports", "",
499 checkAndroidBpContents(`
500// This is auto-generated. DO NOT EDIT.
501
502cc_prebuilt_binary {
503 name: "myexports_mynativebinary@current",
504 sdk_member_name: "mynativebinary",
505 device_supported: false,
506 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000507 installable: false,
Paul Duffina04c1072020-03-02 10:16:35 +0000508 target: {
509 linux_glibc: {
510 compile_multilib: "both",
511 },
512 linux_glibc_x86_64: {
513 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
514 },
515 linux_glibc_x86: {
516 srcs: ["linux_glibc/x86/bin/mynativebinary"],
517 },
518 windows: {
519 compile_multilib: "64",
520 },
521 windows_x86_64: {
522 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
523 },
524 },
525}
526
527cc_prebuilt_binary {
528 name: "mynativebinary",
529 prefer: false,
530 device_supported: false,
531 host_supported: true,
532 target: {
533 linux_glibc: {
534 compile_multilib: "both",
535 },
536 linux_glibc_x86_64: {
537 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
538 },
539 linux_glibc_x86: {
540 srcs: ["linux_glibc/x86/bin/mynativebinary"],
541 },
542 windows: {
543 compile_multilib: "64",
544 },
545 windows_x86_64: {
546 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
547 },
548 },
549}
550
551module_exports_snapshot {
552 name: "myexports@current",
553 device_supported: false,
554 host_supported: true,
555 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +0000556 target: {
557 windows: {
558 compile_multilib: "64",
559 },
560 },
Paul Duffina04c1072020-03-02 10:16:35 +0000561}
562`),
563 checkAllCopyRules(`
564.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
565.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
566.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
567`),
568 )
569}
570
Paul Duffin9ab556f2019-12-11 18:42:17 +0000571func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000572 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000573 sdk {
574 name: "mysdk",
575 native_shared_libs: ["mynativelib"],
576 }
577
578 cc_library_shared {
579 name: "mynativelib",
580 srcs: [
581 "Test.cpp",
582 "aidl/foo/bar/Test.aidl",
583 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000584 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000585 export_include_dirs: ["include"],
586 aidl: {
587 export_aidl_headers: true,
588 },
589 system_shared_libs: [],
590 stl: "none",
591 }
592 `)
593
Paul Duffin1356d8c2020-02-25 19:26:33 +0000594 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000595 checkAndroidBpContents(`
596// This is auto-generated. DO NOT EDIT.
597
598cc_prebuilt_library_shared {
599 name: "mysdk_mynativelib@current",
600 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000601 apex_available: [
602 "apex1",
603 "apex2",
604 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000605 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000606 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000607 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000608 arch: {
609 arm64: {
610 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000611 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000612 },
613 arm: {
614 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000615 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000616 },
617 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000618}
619
620cc_prebuilt_library_shared {
621 name: "mynativelib",
622 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +0000623 apex_available: [
624 "apex1",
625 "apex2",
626 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +0000627 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000628 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000629 arch: {
630 arm64: {
631 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000632 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000633 },
634 arm: {
635 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000636 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000637 },
638 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000639}
640
641sdk_snapshot {
642 name: "mysdk@current",
643 native_shared_libs: ["mysdk_mynativelib@current"],
644}
645`),
646 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000647include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800648.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
649.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
650.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
651.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
652.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
653.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
654.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
655.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 +0000656`),
657 )
658}
659
Paul Duffin13f02712020-03-06 12:30:43 +0000660func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
661 result := testSdkWithCc(t, `
662 sdk {
663 name: "mysdk",
664 native_shared_libs: [
665 "mynativelib",
666 "myothernativelib",
667 "mysystemnativelib",
668 ],
669 }
670
671 cc_library {
672 name: "mysystemnativelib",
673 srcs: [
674 "Test.cpp",
675 ],
676 system_shared_libs: [],
677 stl: "none",
678 }
679
680 cc_library_shared {
681 name: "myothernativelib",
682 srcs: [
683 "Test.cpp",
684 ],
685 system_shared_libs: [
686 // A reference to a library that is not an sdk member. Uses libm as that
687 // is in the default set of modules available to this test and so is available
688 // both here and also when the generated Android.bp file is tested in
689 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
690 // handles references to modules that are not sdk members.
691 "libm",
692 ],
693 stl: "none",
694 }
695
696 cc_library {
697 name: "mynativelib",
698 srcs: [
699 "Test.cpp",
700 ],
701 shared_libs: [
702 // A reference to another sdk member.
703 "myothernativelib",
704 ],
705 target: {
706 android: {
707 shared: {
708 shared_libs: [
709 // A reference to a library that is not an sdk member. The libc library
710 // is used here to check that the shared_libs property is handled correctly
711 // in a similar way to how libm is used to check system_shared_libs above.
712 "libc",
713 ],
714 },
715 },
716 },
717 system_shared_libs: [],
718 stl: "none",
719 }
720 `)
721
722 result.CheckSnapshot("mysdk", "",
723 checkAndroidBpContents(`
724// This is auto-generated. DO NOT EDIT.
725
726cc_prebuilt_library_shared {
727 name: "mysdk_mynativelib@current",
728 sdk_member_name: "mynativelib",
729 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000730 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000731 shared_libs: [
732 "mysdk_myothernativelib@current",
733 "libc",
734 ],
735 arch: {
736 arm64: {
737 srcs: ["arm64/lib/mynativelib.so"],
738 },
739 arm: {
740 srcs: ["arm/lib/mynativelib.so"],
741 },
742 },
Paul Duffin13f02712020-03-06 12:30:43 +0000743}
744
745cc_prebuilt_library_shared {
746 name: "mynativelib",
747 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000748 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000749 shared_libs: [
750 "myothernativelib",
751 "libc",
752 ],
753 arch: {
754 arm64: {
755 srcs: ["arm64/lib/mynativelib.so"],
756 },
757 arm: {
758 srcs: ["arm/lib/mynativelib.so"],
759 },
760 },
Paul Duffin13f02712020-03-06 12:30:43 +0000761}
762
763cc_prebuilt_library_shared {
764 name: "mysdk_myothernativelib@current",
765 sdk_member_name: "myothernativelib",
766 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000767 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000768 system_shared_libs: ["libm"],
769 arch: {
770 arm64: {
771 srcs: ["arm64/lib/myothernativelib.so"],
772 },
773 arm: {
774 srcs: ["arm/lib/myothernativelib.so"],
775 },
776 },
Paul Duffin13f02712020-03-06 12:30:43 +0000777}
778
779cc_prebuilt_library_shared {
780 name: "myothernativelib",
781 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000782 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000783 system_shared_libs: ["libm"],
784 arch: {
785 arm64: {
786 srcs: ["arm64/lib/myothernativelib.so"],
787 },
788 arm: {
789 srcs: ["arm/lib/myothernativelib.so"],
790 },
791 },
Paul Duffin13f02712020-03-06 12:30:43 +0000792}
793
794cc_prebuilt_library_shared {
795 name: "mysdk_mysystemnativelib@current",
796 sdk_member_name: "mysystemnativelib",
797 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000798 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000799 arch: {
800 arm64: {
801 srcs: ["arm64/lib/mysystemnativelib.so"],
802 },
803 arm: {
804 srcs: ["arm/lib/mysystemnativelib.so"],
805 },
806 },
Paul Duffin13f02712020-03-06 12:30:43 +0000807}
808
809cc_prebuilt_library_shared {
810 name: "mysystemnativelib",
811 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000812 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000813 arch: {
814 arm64: {
815 srcs: ["arm64/lib/mysystemnativelib.so"],
816 },
817 arm: {
818 srcs: ["arm/lib/mysystemnativelib.so"],
819 },
820 },
Paul Duffin13f02712020-03-06 12:30:43 +0000821}
822
823sdk_snapshot {
824 name: "mysdk@current",
825 native_shared_libs: [
826 "mysdk_mynativelib@current",
827 "mysdk_myothernativelib@current",
828 "mysdk_mysystemnativelib@current",
829 ],
830}
831`),
832 checkAllCopyRules(`
833.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
834.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
835.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
836.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
837.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
838.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
839`),
840 )
841}
842
Paul Duffin9ab556f2019-12-11 18:42:17 +0000843func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000844 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
845 SkipIfNotLinux(t)
846
Paul Duffind835daa2019-11-30 17:49:09 +0000847 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000848 sdk {
849 name: "mysdk",
850 device_supported: false,
851 host_supported: true,
852 native_shared_libs: ["mynativelib"],
853 }
854
855 cc_library_shared {
856 name: "mynativelib",
857 device_supported: false,
858 host_supported: true,
859 srcs: [
860 "Test.cpp",
861 "aidl/foo/bar/Test.aidl",
862 ],
863 export_include_dirs: ["include"],
864 aidl: {
865 export_aidl_headers: true,
866 },
867 system_shared_libs: [],
868 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +0000869 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +0000870 }
871 `)
872
Paul Duffin1356d8c2020-02-25 19:26:33 +0000873 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000874 checkAndroidBpContents(`
875// This is auto-generated. DO NOT EDIT.
876
877cc_prebuilt_library_shared {
878 name: "mysdk_mynativelib@current",
879 sdk_member_name: "mynativelib",
880 device_supported: false,
881 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000882 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +0000883 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000884 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000885 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000886 arch: {
887 x86_64: {
888 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000889 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000890 },
891 x86: {
892 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000893 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000894 },
895 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000896}
897
898cc_prebuilt_library_shared {
899 name: "mynativelib",
900 prefer: false,
901 device_supported: false,
902 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +0000903 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000904 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000905 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000906 arch: {
907 x86_64: {
908 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000909 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000910 },
911 x86: {
912 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000913 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000914 },
915 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000916}
917
918sdk_snapshot {
919 name: "mysdk@current",
920 device_supported: false,
921 host_supported: true,
922 native_shared_libs: ["mysdk_mynativelib@current"],
923}
924`),
925 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000926include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +0000927.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000928.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
929.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
930.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
931.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000932.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
933.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
934.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
935`),
936 )
937}
Paul Duffin9ab556f2019-12-11 18:42:17 +0000938
Paul Duffina04c1072020-03-02 10:16:35 +0000939func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
940 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
941 SkipIfNotLinux(t)
942
943 result := testSdkWithCc(t, `
944 sdk {
945 name: "mysdk",
946 device_supported: false,
947 host_supported: true,
948 native_shared_libs: ["mynativelib"],
949 target: {
950 windows: {
951 enabled: true,
952 },
953 },
954 }
955
956 cc_library_shared {
957 name: "mynativelib",
958 device_supported: false,
959 host_supported: true,
960 srcs: [
961 "Test.cpp",
962 ],
963 system_shared_libs: [],
964 stl: "none",
965 target: {
966 windows: {
967 enabled: true,
968 },
969 },
970 }
971 `)
972
973 result.CheckSnapshot("mysdk", "",
974 checkAndroidBpContents(`
975// This is auto-generated. DO NOT EDIT.
976
977cc_prebuilt_library_shared {
978 name: "mysdk_mynativelib@current",
979 sdk_member_name: "mynativelib",
980 device_supported: false,
981 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000982 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000983 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000984 target: {
985 linux_glibc_x86_64: {
986 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
987 },
988 linux_glibc_x86: {
989 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
990 },
991 windows_x86_64: {
992 srcs: ["windows/x86_64/lib/mynativelib.dll"],
993 },
994 },
Paul Duffina04c1072020-03-02 10:16:35 +0000995}
996
997cc_prebuilt_library_shared {
998 name: "mynativelib",
999 prefer: false,
1000 device_supported: false,
1001 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001002 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001003 target: {
1004 linux_glibc_x86_64: {
1005 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1006 },
1007 linux_glibc_x86: {
1008 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1009 },
1010 windows_x86_64: {
1011 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1012 },
1013 },
Paul Duffina04c1072020-03-02 10:16:35 +00001014}
1015
1016sdk_snapshot {
1017 name: "mysdk@current",
1018 device_supported: false,
1019 host_supported: true,
1020 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +00001021 target: {
1022 windows: {
1023 compile_multilib: "64",
1024 },
1025 },
Paul Duffina04c1072020-03-02 10:16:35 +00001026}
1027`),
1028 checkAllCopyRules(`
1029.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1030.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1031.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1032`),
1033 )
1034}
1035
Paul Duffin9ab556f2019-12-11 18:42:17 +00001036func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1037 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001038 module_exports {
1039 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001040 native_static_libs: ["mynativelib"],
1041 }
1042
1043 cc_library_static {
1044 name: "mynativelib",
1045 srcs: [
1046 "Test.cpp",
1047 "aidl/foo/bar/Test.aidl",
1048 ],
1049 export_include_dirs: ["include"],
1050 aidl: {
1051 export_aidl_headers: true,
1052 },
1053 system_shared_libs: [],
1054 stl: "none",
1055 }
1056 `)
1057
Paul Duffin1356d8c2020-02-25 19:26:33 +00001058 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001059 checkAndroidBpContents(`
1060// This is auto-generated. DO NOT EDIT.
1061
1062cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001063 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001064 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001065 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001066 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001067 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001068 arch: {
1069 arm64: {
1070 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001071 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001072 },
1073 arm: {
1074 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001075 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001076 },
1077 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001078}
1079
1080cc_prebuilt_library_static {
1081 name: "mynativelib",
1082 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001083 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001084 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001085 arch: {
1086 arm64: {
1087 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001088 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001089 },
1090 arm: {
1091 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001092 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001093 },
1094 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001095}
1096
Paul Duffine6029182019-12-16 17:43:48 +00001097module_exports_snapshot {
1098 name: "myexports@current",
1099 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001100}
1101`),
1102 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001103include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001104.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1105.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1106.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1107.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1108.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1109.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1110.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1111.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 +00001112`),
1113 )
1114}
1115
1116func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1117 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1118 SkipIfNotLinux(t)
1119
1120 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001121 module_exports {
1122 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001123 device_supported: false,
1124 host_supported: true,
1125 native_static_libs: ["mynativelib"],
1126 }
1127
1128 cc_library_static {
1129 name: "mynativelib",
1130 device_supported: false,
1131 host_supported: true,
1132 srcs: [
1133 "Test.cpp",
1134 "aidl/foo/bar/Test.aidl",
1135 ],
1136 export_include_dirs: ["include"],
1137 aidl: {
1138 export_aidl_headers: true,
1139 },
1140 system_shared_libs: [],
1141 stl: "none",
1142 }
1143 `)
1144
Paul Duffin1356d8c2020-02-25 19:26:33 +00001145 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001146 checkAndroidBpContents(`
1147// This is auto-generated. DO NOT EDIT.
1148
1149cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001150 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001151 sdk_member_name: "mynativelib",
1152 device_supported: false,
1153 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001154 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001155 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001156 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001157 arch: {
1158 x86_64: {
1159 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001160 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001161 },
1162 x86: {
1163 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001164 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001165 },
1166 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001167}
1168
1169cc_prebuilt_library_static {
1170 name: "mynativelib",
1171 prefer: false,
1172 device_supported: false,
1173 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001174 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001175 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001176 arch: {
1177 x86_64: {
1178 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001179 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001180 },
1181 x86: {
1182 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001183 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001184 },
1185 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001186}
1187
Paul Duffine6029182019-12-16 17:43:48 +00001188module_exports_snapshot {
1189 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001190 device_supported: false,
1191 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001192 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001193}
1194`),
1195 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001196include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001197.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001198.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1199.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1200.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1201.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001202.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1203.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1204.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1205`),
1206 )
1207}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001208
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001209func TestSnapshotWithCcLibrary(t *testing.T) {
1210 result := testSdkWithCc(t, `
1211 module_exports {
1212 name: "myexports",
1213 native_libs: ["mynativelib"],
1214 }
1215
1216 cc_library {
1217 name: "mynativelib",
1218 srcs: [
1219 "Test.cpp",
1220 ],
1221 export_include_dirs: ["include"],
1222 system_shared_libs: [],
1223 stl: "none",
1224 }
1225 `)
1226
1227 result.CheckSnapshot("myexports", "",
1228 checkAndroidBpContents(`
1229// This is auto-generated. DO NOT EDIT.
1230
1231cc_prebuilt_library {
1232 name: "myexports_mynativelib@current",
1233 sdk_member_name: "mynativelib",
1234 installable: false,
1235 stl: "none",
1236 export_include_dirs: ["include/include"],
1237 arch: {
1238 arm64: {
1239 static: {
1240 srcs: ["arm64/lib/mynativelib.a"],
1241 },
1242 shared: {
1243 srcs: ["arm64/lib/mynativelib.so"],
1244 },
1245 },
1246 arm: {
1247 static: {
1248 srcs: ["arm/lib/mynativelib.a"],
1249 },
1250 shared: {
1251 srcs: ["arm/lib/mynativelib.so"],
1252 },
1253 },
1254 },
1255}
1256
1257cc_prebuilt_library {
1258 name: "mynativelib",
1259 prefer: false,
1260 stl: "none",
1261 export_include_dirs: ["include/include"],
1262 arch: {
1263 arm64: {
1264 static: {
1265 srcs: ["arm64/lib/mynativelib.a"],
1266 },
1267 shared: {
1268 srcs: ["arm64/lib/mynativelib.so"],
1269 },
1270 },
1271 arm: {
1272 static: {
1273 srcs: ["arm/lib/mynativelib.a"],
1274 },
1275 shared: {
1276 srcs: ["arm/lib/mynativelib.so"],
1277 },
1278 },
1279 },
1280}
1281
1282module_exports_snapshot {
1283 name: "myexports@current",
1284 native_libs: ["myexports_mynativelib@current"],
1285}
1286`),
1287 checkAllCopyRules(`
1288include/Test.h -> include/include/Test.h
1289.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1290.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1291.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1292.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1293 )
1294}
1295
Paul Duffin13ad94f2020-02-19 16:19:27 +00001296func TestHostSnapshotWithMultiLib64(t *testing.T) {
1297 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1298 SkipIfNotLinux(t)
1299
1300 result := testSdkWithCc(t, `
1301 module_exports {
1302 name: "myexports",
1303 device_supported: false,
1304 host_supported: true,
1305 target: {
1306 host: {
1307 compile_multilib: "64",
1308 },
1309 },
1310 native_static_libs: ["mynativelib"],
1311 }
1312
1313 cc_library_static {
1314 name: "mynativelib",
1315 device_supported: false,
1316 host_supported: true,
1317 srcs: [
1318 "Test.cpp",
1319 "aidl/foo/bar/Test.aidl",
1320 ],
1321 export_include_dirs: ["include"],
1322 aidl: {
1323 export_aidl_headers: true,
1324 },
1325 system_shared_libs: [],
1326 stl: "none",
1327 }
1328 `)
1329
Paul Duffin1356d8c2020-02-25 19:26:33 +00001330 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001331 checkAndroidBpContents(`
1332// This is auto-generated. DO NOT EDIT.
1333
1334cc_prebuilt_library_static {
1335 name: "myexports_mynativelib@current",
1336 sdk_member_name: "mynativelib",
1337 device_supported: false,
1338 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001339 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001340 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001341 export_include_dirs: ["include/include"],
1342 arch: {
1343 x86_64: {
1344 srcs: ["x86_64/lib/mynativelib.a"],
1345 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1346 },
1347 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001348}
1349
1350cc_prebuilt_library_static {
1351 name: "mynativelib",
1352 prefer: false,
1353 device_supported: false,
1354 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001355 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001356 export_include_dirs: ["include/include"],
1357 arch: {
1358 x86_64: {
1359 srcs: ["x86_64/lib/mynativelib.a"],
1360 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1361 },
1362 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001363}
1364
1365module_exports_snapshot {
1366 name: "myexports@current",
1367 device_supported: false,
1368 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001369 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin13ad94f2020-02-19 16:19:27 +00001370 target: {
Paul Duffin6a7e9532020-03-20 17:50:07 +00001371 linux_glibc: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001372 compile_multilib: "64",
1373 },
1374 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001375}`),
1376 checkAllCopyRules(`
1377include/Test.h -> include/include/Test.h
1378.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1379.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1380.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1381.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1382`),
1383 )
1384}
Paul Duffin91756d22020-02-21 16:29:57 +00001385
1386func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1387 result := testSdkWithCc(t, `
1388 sdk {
1389 name: "mysdk",
1390 native_header_libs: ["mynativeheaders"],
1391 }
1392
1393 cc_library_headers {
1394 name: "mynativeheaders",
1395 export_include_dirs: ["include"],
1396 system_shared_libs: [],
1397 stl: "none",
1398 }
1399 `)
1400
Paul Duffin1356d8c2020-02-25 19:26:33 +00001401 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001402 checkAndroidBpContents(`
1403// This is auto-generated. DO NOT EDIT.
1404
1405cc_prebuilt_library_headers {
1406 name: "mysdk_mynativeheaders@current",
1407 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001408 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001409 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001410}
1411
1412cc_prebuilt_library_headers {
1413 name: "mynativeheaders",
1414 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001415 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001416 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001417}
1418
1419sdk_snapshot {
1420 name: "mysdk@current",
1421 native_header_libs: ["mysdk_mynativeheaders@current"],
1422}
1423`),
1424 checkAllCopyRules(`
1425include/Test.h -> include/include/Test.h
1426`),
1427 )
1428}
1429
1430func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1431 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1432 SkipIfNotLinux(t)
1433
1434 result := testSdkWithCc(t, `
1435 sdk {
1436 name: "mysdk",
1437 device_supported: false,
1438 host_supported: true,
1439 native_header_libs: ["mynativeheaders"],
1440 }
1441
1442 cc_library_headers {
1443 name: "mynativeheaders",
1444 device_supported: false,
1445 host_supported: true,
1446 export_include_dirs: ["include"],
1447 system_shared_libs: [],
1448 stl: "none",
1449 }
1450 `)
1451
Paul Duffin1356d8c2020-02-25 19:26:33 +00001452 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001453 checkAndroidBpContents(`
1454// This is auto-generated. DO NOT EDIT.
1455
1456cc_prebuilt_library_headers {
1457 name: "mysdk_mynativeheaders@current",
1458 sdk_member_name: "mynativeheaders",
1459 device_supported: false,
1460 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001461 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001462 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001463}
1464
1465cc_prebuilt_library_headers {
1466 name: "mynativeheaders",
1467 prefer: false,
1468 device_supported: false,
1469 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001470 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001471 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001472}
1473
1474sdk_snapshot {
1475 name: "mysdk@current",
1476 device_supported: false,
1477 host_supported: true,
1478 native_header_libs: ["mysdk_mynativeheaders@current"],
1479}
1480`),
1481 checkAllCopyRules(`
1482include/Test.h -> include/include/Test.h
1483`),
1484 )
1485}
Paul Duffina04c1072020-03-02 10:16:35 +00001486
1487func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1488 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1489 SkipIfNotLinux(t)
1490
1491 result := testSdkWithCc(t, `
1492 sdk {
1493 name: "mysdk",
1494 host_supported: true,
1495 native_header_libs: ["mynativeheaders"],
1496 }
1497
1498 cc_library_headers {
1499 name: "mynativeheaders",
1500 host_supported: true,
1501 system_shared_libs: [],
1502 stl: "none",
1503 export_system_include_dirs: ["include"],
1504 target: {
1505 android: {
1506 export_include_dirs: ["include-android"],
1507 },
1508 host: {
1509 export_include_dirs: ["include-host"],
1510 },
1511 },
1512 }
1513 `)
1514
1515 result.CheckSnapshot("mysdk", "",
1516 checkAndroidBpContents(`
1517// This is auto-generated. DO NOT EDIT.
1518
1519cc_prebuilt_library_headers {
1520 name: "mysdk_mynativeheaders@current",
1521 sdk_member_name: "mynativeheaders",
1522 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001523 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001524 export_system_include_dirs: ["include/include"],
1525 target: {
1526 android: {
1527 export_include_dirs: ["include/include-android"],
1528 },
1529 linux_glibc: {
1530 export_include_dirs: ["include/include-host"],
1531 },
1532 },
Paul Duffina04c1072020-03-02 10:16:35 +00001533}
1534
1535cc_prebuilt_library_headers {
1536 name: "mynativeheaders",
1537 prefer: false,
1538 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001539 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001540 export_system_include_dirs: ["include/include"],
1541 target: {
1542 android: {
1543 export_include_dirs: ["include/include-android"],
1544 },
1545 linux_glibc: {
1546 export_include_dirs: ["include/include-host"],
1547 },
1548 },
Paul Duffina04c1072020-03-02 10:16:35 +00001549}
1550
1551sdk_snapshot {
1552 name: "mysdk@current",
1553 host_supported: true,
1554 native_header_libs: ["mysdk_mynativeheaders@current"],
1555}
1556`),
1557 checkAllCopyRules(`
1558include/Test.h -> include/include/Test.h
1559include-android/AndroidTest.h -> include/include-android/AndroidTest.h
1560include-host/HostTest.h -> include/include-host/HostTest.h
1561`),
1562 )
1563}