blob: 6727b4bf03b898484b938aaf90c9ceaf8216266e [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"],
556}
557`),
558 checkAllCopyRules(`
559.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
560.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
561.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
562`),
563 )
564}
565
Paul Duffin9ab556f2019-12-11 18:42:17 +0000566func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000567 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000568 sdk {
569 name: "mysdk",
570 native_shared_libs: ["mynativelib"],
571 }
572
573 cc_library_shared {
574 name: "mynativelib",
575 srcs: [
576 "Test.cpp",
577 "aidl/foo/bar/Test.aidl",
578 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000579 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000580 export_include_dirs: ["include"],
581 aidl: {
582 export_aidl_headers: true,
583 },
584 system_shared_libs: [],
585 stl: "none",
586 }
587 `)
588
Paul Duffin1356d8c2020-02-25 19:26:33 +0000589 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000590 checkAndroidBpContents(`
591// This is auto-generated. DO NOT EDIT.
592
593cc_prebuilt_library_shared {
594 name: "mysdk_mynativelib@current",
595 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000596 apex_available: [
597 "apex1",
598 "apex2",
599 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000600 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000601 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000602 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000603 arch: {
604 arm64: {
605 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000606 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000607 },
608 arm: {
609 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000610 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000611 },
612 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000613}
614
615cc_prebuilt_library_shared {
616 name: "mynativelib",
617 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +0000618 apex_available: [
619 "apex1",
620 "apex2",
621 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +0000622 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000623 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000624 arch: {
625 arm64: {
626 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000627 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000628 },
629 arm: {
630 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000631 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000632 },
633 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000634}
635
636sdk_snapshot {
637 name: "mysdk@current",
638 native_shared_libs: ["mysdk_mynativelib@current"],
639}
640`),
641 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000642include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800643.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
644.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
645.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
646.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
647.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
648.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
649.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
650.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 +0000651`),
652 )
653}
654
Paul Duffin13f02712020-03-06 12:30:43 +0000655func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
656 result := testSdkWithCc(t, `
657 sdk {
658 name: "mysdk",
659 native_shared_libs: [
660 "mynativelib",
661 "myothernativelib",
662 "mysystemnativelib",
663 ],
664 }
665
666 cc_library {
667 name: "mysystemnativelib",
668 srcs: [
669 "Test.cpp",
670 ],
671 system_shared_libs: [],
672 stl: "none",
673 }
674
675 cc_library_shared {
676 name: "myothernativelib",
677 srcs: [
678 "Test.cpp",
679 ],
680 system_shared_libs: [
681 // A reference to a library that is not an sdk member. Uses libm as that
682 // is in the default set of modules available to this test and so is available
683 // both here and also when the generated Android.bp file is tested in
684 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
685 // handles references to modules that are not sdk members.
686 "libm",
687 ],
688 stl: "none",
689 }
690
691 cc_library {
692 name: "mynativelib",
693 srcs: [
694 "Test.cpp",
695 ],
696 shared_libs: [
697 // A reference to another sdk member.
698 "myothernativelib",
699 ],
700 target: {
701 android: {
702 shared: {
703 shared_libs: [
704 // A reference to a library that is not an sdk member. The libc library
705 // is used here to check that the shared_libs property is handled correctly
706 // in a similar way to how libm is used to check system_shared_libs above.
707 "libc",
708 ],
709 },
710 },
711 },
712 system_shared_libs: [],
713 stl: "none",
714 }
715 `)
716
717 result.CheckSnapshot("mysdk", "",
718 checkAndroidBpContents(`
719// This is auto-generated. DO NOT EDIT.
720
721cc_prebuilt_library_shared {
722 name: "mysdk_mynativelib@current",
723 sdk_member_name: "mynativelib",
724 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000725 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000726 shared_libs: [
727 "mysdk_myothernativelib@current",
728 "libc",
729 ],
730 arch: {
731 arm64: {
732 srcs: ["arm64/lib/mynativelib.so"],
733 },
734 arm: {
735 srcs: ["arm/lib/mynativelib.so"],
736 },
737 },
Paul Duffin13f02712020-03-06 12:30:43 +0000738}
739
740cc_prebuilt_library_shared {
741 name: "mynativelib",
742 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000743 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000744 shared_libs: [
745 "myothernativelib",
746 "libc",
747 ],
748 arch: {
749 arm64: {
750 srcs: ["arm64/lib/mynativelib.so"],
751 },
752 arm: {
753 srcs: ["arm/lib/mynativelib.so"],
754 },
755 },
Paul Duffin13f02712020-03-06 12:30:43 +0000756}
757
758cc_prebuilt_library_shared {
759 name: "mysdk_myothernativelib@current",
760 sdk_member_name: "myothernativelib",
761 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000762 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000763 system_shared_libs: ["libm"],
764 arch: {
765 arm64: {
766 srcs: ["arm64/lib/myothernativelib.so"],
767 },
768 arm: {
769 srcs: ["arm/lib/myothernativelib.so"],
770 },
771 },
Paul Duffin13f02712020-03-06 12:30:43 +0000772}
773
774cc_prebuilt_library_shared {
775 name: "myothernativelib",
776 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000777 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000778 system_shared_libs: ["libm"],
779 arch: {
780 arm64: {
781 srcs: ["arm64/lib/myothernativelib.so"],
782 },
783 arm: {
784 srcs: ["arm/lib/myothernativelib.so"],
785 },
786 },
Paul Duffin13f02712020-03-06 12:30:43 +0000787}
788
789cc_prebuilt_library_shared {
790 name: "mysdk_mysystemnativelib@current",
791 sdk_member_name: "mysystemnativelib",
792 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000793 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000794 arch: {
795 arm64: {
796 srcs: ["arm64/lib/mysystemnativelib.so"],
797 },
798 arm: {
799 srcs: ["arm/lib/mysystemnativelib.so"],
800 },
801 },
Paul Duffin13f02712020-03-06 12:30:43 +0000802}
803
804cc_prebuilt_library_shared {
805 name: "mysystemnativelib",
806 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000807 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000808 arch: {
809 arm64: {
810 srcs: ["arm64/lib/mysystemnativelib.so"],
811 },
812 arm: {
813 srcs: ["arm/lib/mysystemnativelib.so"],
814 },
815 },
Paul Duffin13f02712020-03-06 12:30:43 +0000816}
817
818sdk_snapshot {
819 name: "mysdk@current",
820 native_shared_libs: [
821 "mysdk_mynativelib@current",
822 "mysdk_myothernativelib@current",
823 "mysdk_mysystemnativelib@current",
824 ],
825}
826`),
827 checkAllCopyRules(`
828.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
829.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
830.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
831.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
832.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
833.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
834`),
835 )
836}
837
Paul Duffin9ab556f2019-12-11 18:42:17 +0000838func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000839 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
840 SkipIfNotLinux(t)
841
Paul Duffind835daa2019-11-30 17:49:09 +0000842 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000843 sdk {
844 name: "mysdk",
845 device_supported: false,
846 host_supported: true,
847 native_shared_libs: ["mynativelib"],
848 }
849
850 cc_library_shared {
851 name: "mynativelib",
852 device_supported: false,
853 host_supported: true,
854 srcs: [
855 "Test.cpp",
856 "aidl/foo/bar/Test.aidl",
857 ],
858 export_include_dirs: ["include"],
859 aidl: {
860 export_aidl_headers: true,
861 },
862 system_shared_libs: [],
863 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +0000864 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +0000865 }
866 `)
867
Paul Duffin1356d8c2020-02-25 19:26:33 +0000868 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000869 checkAndroidBpContents(`
870// This is auto-generated. DO NOT EDIT.
871
872cc_prebuilt_library_shared {
873 name: "mysdk_mynativelib@current",
874 sdk_member_name: "mynativelib",
875 device_supported: false,
876 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000877 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +0000878 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000879 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000880 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000881 arch: {
882 x86_64: {
883 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000884 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000885 },
886 x86: {
887 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000888 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000889 },
890 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000891}
892
893cc_prebuilt_library_shared {
894 name: "mynativelib",
895 prefer: false,
896 device_supported: false,
897 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +0000898 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000899 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000900 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000901 arch: {
902 x86_64: {
903 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000904 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000905 },
906 x86: {
907 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000908 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000909 },
910 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000911}
912
913sdk_snapshot {
914 name: "mysdk@current",
915 device_supported: false,
916 host_supported: true,
917 native_shared_libs: ["mysdk_mynativelib@current"],
918}
919`),
920 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000921include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +0000922.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000923.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
924.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
925.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
926.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000927.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
928.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
929.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
930`),
931 )
932}
Paul Duffin9ab556f2019-12-11 18:42:17 +0000933
Paul Duffina04c1072020-03-02 10:16:35 +0000934func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
935 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
936 SkipIfNotLinux(t)
937
938 result := testSdkWithCc(t, `
939 sdk {
940 name: "mysdk",
941 device_supported: false,
942 host_supported: true,
943 native_shared_libs: ["mynativelib"],
944 target: {
945 windows: {
946 enabled: true,
947 },
948 },
949 }
950
951 cc_library_shared {
952 name: "mynativelib",
953 device_supported: false,
954 host_supported: true,
955 srcs: [
956 "Test.cpp",
957 ],
958 system_shared_libs: [],
959 stl: "none",
960 target: {
961 windows: {
962 enabled: true,
963 },
964 },
965 }
966 `)
967
968 result.CheckSnapshot("mysdk", "",
969 checkAndroidBpContents(`
970// This is auto-generated. DO NOT EDIT.
971
972cc_prebuilt_library_shared {
973 name: "mysdk_mynativelib@current",
974 sdk_member_name: "mynativelib",
975 device_supported: false,
976 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000977 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000978 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000979 target: {
980 linux_glibc_x86_64: {
981 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
982 },
983 linux_glibc_x86: {
984 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
985 },
986 windows_x86_64: {
987 srcs: ["windows/x86_64/lib/mynativelib.dll"],
988 },
989 },
Paul Duffina04c1072020-03-02 10:16:35 +0000990}
991
992cc_prebuilt_library_shared {
993 name: "mynativelib",
994 prefer: false,
995 device_supported: false,
996 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000997 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000998 target: {
999 linux_glibc_x86_64: {
1000 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1001 },
1002 linux_glibc_x86: {
1003 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1004 },
1005 windows_x86_64: {
1006 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1007 },
1008 },
Paul Duffina04c1072020-03-02 10:16:35 +00001009}
1010
1011sdk_snapshot {
1012 name: "mysdk@current",
1013 device_supported: false,
1014 host_supported: true,
1015 native_shared_libs: ["mysdk_mynativelib@current"],
1016}
1017`),
1018 checkAllCopyRules(`
1019.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1020.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1021.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1022`),
1023 )
1024}
1025
Paul Duffin9ab556f2019-12-11 18:42:17 +00001026func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1027 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001028 module_exports {
1029 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001030 native_static_libs: ["mynativelib"],
1031 }
1032
1033 cc_library_static {
1034 name: "mynativelib",
1035 srcs: [
1036 "Test.cpp",
1037 "aidl/foo/bar/Test.aidl",
1038 ],
1039 export_include_dirs: ["include"],
1040 aidl: {
1041 export_aidl_headers: true,
1042 },
1043 system_shared_libs: [],
1044 stl: "none",
1045 }
1046 `)
1047
Paul Duffin1356d8c2020-02-25 19:26:33 +00001048 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001049 checkAndroidBpContents(`
1050// This is auto-generated. DO NOT EDIT.
1051
1052cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001053 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001054 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001055 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001056 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001057 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001058 arch: {
1059 arm64: {
1060 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001061 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001062 },
1063 arm: {
1064 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001065 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001066 },
1067 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001068}
1069
1070cc_prebuilt_library_static {
1071 name: "mynativelib",
1072 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001073 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001074 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001075 arch: {
1076 arm64: {
1077 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001078 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001079 },
1080 arm: {
1081 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001082 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001083 },
1084 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001085}
1086
Paul Duffine6029182019-12-16 17:43:48 +00001087module_exports_snapshot {
1088 name: "myexports@current",
1089 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001090}
1091`),
1092 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001093include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001094.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1095.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1096.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1097.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1098.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1099.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1100.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1101.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 +00001102`),
1103 )
1104}
1105
1106func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1107 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1108 SkipIfNotLinux(t)
1109
1110 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001111 module_exports {
1112 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001113 device_supported: false,
1114 host_supported: true,
1115 native_static_libs: ["mynativelib"],
1116 }
1117
1118 cc_library_static {
1119 name: "mynativelib",
1120 device_supported: false,
1121 host_supported: true,
1122 srcs: [
1123 "Test.cpp",
1124 "aidl/foo/bar/Test.aidl",
1125 ],
1126 export_include_dirs: ["include"],
1127 aidl: {
1128 export_aidl_headers: true,
1129 },
1130 system_shared_libs: [],
1131 stl: "none",
1132 }
1133 `)
1134
Paul Duffin1356d8c2020-02-25 19:26:33 +00001135 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001136 checkAndroidBpContents(`
1137// This is auto-generated. DO NOT EDIT.
1138
1139cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001140 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001141 sdk_member_name: "mynativelib",
1142 device_supported: false,
1143 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001144 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001145 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001146 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001147 arch: {
1148 x86_64: {
1149 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001150 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001151 },
1152 x86: {
1153 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001154 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001155 },
1156 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001157}
1158
1159cc_prebuilt_library_static {
1160 name: "mynativelib",
1161 prefer: false,
1162 device_supported: false,
1163 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001164 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001165 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001166 arch: {
1167 x86_64: {
1168 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001169 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001170 },
1171 x86: {
1172 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001173 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001174 },
1175 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001176}
1177
Paul Duffine6029182019-12-16 17:43:48 +00001178module_exports_snapshot {
1179 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001180 device_supported: false,
1181 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001182 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001183}
1184`),
1185 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001186include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001187.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001188.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1189.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1190.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1191.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001192.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1193.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1194.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1195`),
1196 )
1197}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001198
1199func TestHostSnapshotWithMultiLib64(t *testing.T) {
1200 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1201 SkipIfNotLinux(t)
1202
1203 result := testSdkWithCc(t, `
1204 module_exports {
1205 name: "myexports",
1206 device_supported: false,
1207 host_supported: true,
1208 target: {
1209 host: {
1210 compile_multilib: "64",
1211 },
1212 },
1213 native_static_libs: ["mynativelib"],
1214 }
1215
1216 cc_library_static {
1217 name: "mynativelib",
1218 device_supported: false,
1219 host_supported: true,
1220 srcs: [
1221 "Test.cpp",
1222 "aidl/foo/bar/Test.aidl",
1223 ],
1224 export_include_dirs: ["include"],
1225 aidl: {
1226 export_aidl_headers: true,
1227 },
1228 system_shared_libs: [],
1229 stl: "none",
1230 }
1231 `)
1232
Paul Duffin1356d8c2020-02-25 19:26:33 +00001233 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001234 checkAndroidBpContents(`
1235// This is auto-generated. DO NOT EDIT.
1236
1237cc_prebuilt_library_static {
1238 name: "myexports_mynativelib@current",
1239 sdk_member_name: "mynativelib",
1240 device_supported: false,
1241 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001242 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001243 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001244 export_include_dirs: ["include/include"],
1245 arch: {
1246 x86_64: {
1247 srcs: ["x86_64/lib/mynativelib.a"],
1248 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1249 },
1250 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001251}
1252
1253cc_prebuilt_library_static {
1254 name: "mynativelib",
1255 prefer: false,
1256 device_supported: false,
1257 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001258 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001259 export_include_dirs: ["include/include"],
1260 arch: {
1261 x86_64: {
1262 srcs: ["x86_64/lib/mynativelib.a"],
1263 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1264 },
1265 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001266}
1267
1268module_exports_snapshot {
1269 name: "myexports@current",
1270 device_supported: false,
1271 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001272 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin13ad94f2020-02-19 16:19:27 +00001273 target: {
1274 host: {
1275 compile_multilib: "64",
1276 },
1277 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001278}`),
1279 checkAllCopyRules(`
1280include/Test.h -> include/include/Test.h
1281.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1282.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1283.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1284.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1285`),
1286 )
1287}
Paul Duffin91756d22020-02-21 16:29:57 +00001288
1289func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1290 result := testSdkWithCc(t, `
1291 sdk {
1292 name: "mysdk",
1293 native_header_libs: ["mynativeheaders"],
1294 }
1295
1296 cc_library_headers {
1297 name: "mynativeheaders",
1298 export_include_dirs: ["include"],
1299 system_shared_libs: [],
1300 stl: "none",
1301 }
1302 `)
1303
Paul Duffin1356d8c2020-02-25 19:26:33 +00001304 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001305 checkAndroidBpContents(`
1306// This is auto-generated. DO NOT EDIT.
1307
1308cc_prebuilt_library_headers {
1309 name: "mysdk_mynativeheaders@current",
1310 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001311 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001312 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001313}
1314
1315cc_prebuilt_library_headers {
1316 name: "mynativeheaders",
1317 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001318 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001319 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001320}
1321
1322sdk_snapshot {
1323 name: "mysdk@current",
1324 native_header_libs: ["mysdk_mynativeheaders@current"],
1325}
1326`),
1327 checkAllCopyRules(`
1328include/Test.h -> include/include/Test.h
1329`),
1330 )
1331}
1332
1333func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1334 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1335 SkipIfNotLinux(t)
1336
1337 result := testSdkWithCc(t, `
1338 sdk {
1339 name: "mysdk",
1340 device_supported: false,
1341 host_supported: true,
1342 native_header_libs: ["mynativeheaders"],
1343 }
1344
1345 cc_library_headers {
1346 name: "mynativeheaders",
1347 device_supported: false,
1348 host_supported: true,
1349 export_include_dirs: ["include"],
1350 system_shared_libs: [],
1351 stl: "none",
1352 }
1353 `)
1354
Paul Duffin1356d8c2020-02-25 19:26:33 +00001355 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001356 checkAndroidBpContents(`
1357// This is auto-generated. DO NOT EDIT.
1358
1359cc_prebuilt_library_headers {
1360 name: "mysdk_mynativeheaders@current",
1361 sdk_member_name: "mynativeheaders",
1362 device_supported: false,
1363 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001364 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001365 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001366}
1367
1368cc_prebuilt_library_headers {
1369 name: "mynativeheaders",
1370 prefer: false,
1371 device_supported: false,
1372 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001373 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001374 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001375}
1376
1377sdk_snapshot {
1378 name: "mysdk@current",
1379 device_supported: false,
1380 host_supported: true,
1381 native_header_libs: ["mysdk_mynativeheaders@current"],
1382}
1383`),
1384 checkAllCopyRules(`
1385include/Test.h -> include/include/Test.h
1386`),
1387 )
1388}
Paul Duffina04c1072020-03-02 10:16:35 +00001389
1390func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1391 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1392 SkipIfNotLinux(t)
1393
1394 result := testSdkWithCc(t, `
1395 sdk {
1396 name: "mysdk",
1397 host_supported: true,
1398 native_header_libs: ["mynativeheaders"],
1399 }
1400
1401 cc_library_headers {
1402 name: "mynativeheaders",
1403 host_supported: true,
1404 system_shared_libs: [],
1405 stl: "none",
1406 export_system_include_dirs: ["include"],
1407 target: {
1408 android: {
1409 export_include_dirs: ["include-android"],
1410 },
1411 host: {
1412 export_include_dirs: ["include-host"],
1413 },
1414 },
1415 }
1416 `)
1417
1418 result.CheckSnapshot("mysdk", "",
1419 checkAndroidBpContents(`
1420// This is auto-generated. DO NOT EDIT.
1421
1422cc_prebuilt_library_headers {
1423 name: "mysdk_mynativeheaders@current",
1424 sdk_member_name: "mynativeheaders",
1425 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001426 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001427 export_system_include_dirs: ["include/include"],
1428 target: {
1429 android: {
1430 export_include_dirs: ["include/include-android"],
1431 },
1432 linux_glibc: {
1433 export_include_dirs: ["include/include-host"],
1434 },
1435 },
Paul Duffina04c1072020-03-02 10:16:35 +00001436}
1437
1438cc_prebuilt_library_headers {
1439 name: "mynativeheaders",
1440 prefer: false,
1441 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001442 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001443 export_system_include_dirs: ["include/include"],
1444 target: {
1445 android: {
1446 export_include_dirs: ["include/include-android"],
1447 },
1448 linux_glibc: {
1449 export_include_dirs: ["include/include-host"],
1450 },
1451 },
Paul Duffina04c1072020-03-02 10:16:35 +00001452}
1453
1454sdk_snapshot {
1455 name: "mysdk@current",
1456 host_supported: true,
1457 native_header_libs: ["mysdk_mynativeheaders@current"],
1458}
1459`),
1460 checkAllCopyRules(`
1461include/Test.h -> include/include/Test.h
1462include-android/AndroidTest.h -> include/include-android/AndroidTest.h
1463include-host/HostTest.h -> include/include-host/HostTest.h
1464`),
1465 )
1466}