blob: 27a951865cc6ca82120c1abc6191a28f0fca2eac [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
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001199func TestSnapshotWithCcLibrary(t *testing.T) {
1200 result := testSdkWithCc(t, `
1201 module_exports {
1202 name: "myexports",
1203 native_libs: ["mynativelib"],
1204 }
1205
1206 cc_library {
1207 name: "mynativelib",
1208 srcs: [
1209 "Test.cpp",
1210 ],
1211 export_include_dirs: ["include"],
1212 system_shared_libs: [],
1213 stl: "none",
1214 }
1215 `)
1216
1217 result.CheckSnapshot("myexports", "",
1218 checkAndroidBpContents(`
1219// This is auto-generated. DO NOT EDIT.
1220
1221cc_prebuilt_library {
1222 name: "myexports_mynativelib@current",
1223 sdk_member_name: "mynativelib",
1224 installable: false,
1225 stl: "none",
1226 export_include_dirs: ["include/include"],
1227 arch: {
1228 arm64: {
1229 static: {
1230 srcs: ["arm64/lib/mynativelib.a"],
1231 },
1232 shared: {
1233 srcs: ["arm64/lib/mynativelib.so"],
1234 },
1235 },
1236 arm: {
1237 static: {
1238 srcs: ["arm/lib/mynativelib.a"],
1239 },
1240 shared: {
1241 srcs: ["arm/lib/mynativelib.so"],
1242 },
1243 },
1244 },
1245}
1246
1247cc_prebuilt_library {
1248 name: "mynativelib",
1249 prefer: false,
1250 stl: "none",
1251 export_include_dirs: ["include/include"],
1252 arch: {
1253 arm64: {
1254 static: {
1255 srcs: ["arm64/lib/mynativelib.a"],
1256 },
1257 shared: {
1258 srcs: ["arm64/lib/mynativelib.so"],
1259 },
1260 },
1261 arm: {
1262 static: {
1263 srcs: ["arm/lib/mynativelib.a"],
1264 },
1265 shared: {
1266 srcs: ["arm/lib/mynativelib.so"],
1267 },
1268 },
1269 },
1270}
1271
1272module_exports_snapshot {
1273 name: "myexports@current",
1274 native_libs: ["myexports_mynativelib@current"],
1275}
1276`),
1277 checkAllCopyRules(`
1278include/Test.h -> include/include/Test.h
1279.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1280.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1281.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1282.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1283 )
1284}
1285
Paul Duffin13ad94f2020-02-19 16:19:27 +00001286func TestHostSnapshotWithMultiLib64(t *testing.T) {
1287 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1288 SkipIfNotLinux(t)
1289
1290 result := testSdkWithCc(t, `
1291 module_exports {
1292 name: "myexports",
1293 device_supported: false,
1294 host_supported: true,
1295 target: {
1296 host: {
1297 compile_multilib: "64",
1298 },
1299 },
1300 native_static_libs: ["mynativelib"],
1301 }
1302
1303 cc_library_static {
1304 name: "mynativelib",
1305 device_supported: false,
1306 host_supported: true,
1307 srcs: [
1308 "Test.cpp",
1309 "aidl/foo/bar/Test.aidl",
1310 ],
1311 export_include_dirs: ["include"],
1312 aidl: {
1313 export_aidl_headers: true,
1314 },
1315 system_shared_libs: [],
1316 stl: "none",
1317 }
1318 `)
1319
Paul Duffin1356d8c2020-02-25 19:26:33 +00001320 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001321 checkAndroidBpContents(`
1322// This is auto-generated. DO NOT EDIT.
1323
1324cc_prebuilt_library_static {
1325 name: "myexports_mynativelib@current",
1326 sdk_member_name: "mynativelib",
1327 device_supported: false,
1328 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001329 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001330 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001331 export_include_dirs: ["include/include"],
1332 arch: {
1333 x86_64: {
1334 srcs: ["x86_64/lib/mynativelib.a"],
1335 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1336 },
1337 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001338}
1339
1340cc_prebuilt_library_static {
1341 name: "mynativelib",
1342 prefer: false,
1343 device_supported: false,
1344 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001345 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001346 export_include_dirs: ["include/include"],
1347 arch: {
1348 x86_64: {
1349 srcs: ["x86_64/lib/mynativelib.a"],
1350 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1351 },
1352 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001353}
1354
1355module_exports_snapshot {
1356 name: "myexports@current",
1357 device_supported: false,
1358 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001359 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin13ad94f2020-02-19 16:19:27 +00001360 target: {
1361 host: {
1362 compile_multilib: "64",
1363 },
1364 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001365}`),
1366 checkAllCopyRules(`
1367include/Test.h -> include/include/Test.h
1368.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1369.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1370.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1371.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1372`),
1373 )
1374}
Paul Duffin91756d22020-02-21 16:29:57 +00001375
1376func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1377 result := testSdkWithCc(t, `
1378 sdk {
1379 name: "mysdk",
1380 native_header_libs: ["mynativeheaders"],
1381 }
1382
1383 cc_library_headers {
1384 name: "mynativeheaders",
1385 export_include_dirs: ["include"],
1386 system_shared_libs: [],
1387 stl: "none",
1388 }
1389 `)
1390
Paul Duffin1356d8c2020-02-25 19:26:33 +00001391 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001392 checkAndroidBpContents(`
1393// This is auto-generated. DO NOT EDIT.
1394
1395cc_prebuilt_library_headers {
1396 name: "mysdk_mynativeheaders@current",
1397 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001398 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001399 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001400}
1401
1402cc_prebuilt_library_headers {
1403 name: "mynativeheaders",
1404 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001405 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001406 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001407}
1408
1409sdk_snapshot {
1410 name: "mysdk@current",
1411 native_header_libs: ["mysdk_mynativeheaders@current"],
1412}
1413`),
1414 checkAllCopyRules(`
1415include/Test.h -> include/include/Test.h
1416`),
1417 )
1418}
1419
1420func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1421 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1422 SkipIfNotLinux(t)
1423
1424 result := testSdkWithCc(t, `
1425 sdk {
1426 name: "mysdk",
1427 device_supported: false,
1428 host_supported: true,
1429 native_header_libs: ["mynativeheaders"],
1430 }
1431
1432 cc_library_headers {
1433 name: "mynativeheaders",
1434 device_supported: false,
1435 host_supported: true,
1436 export_include_dirs: ["include"],
1437 system_shared_libs: [],
1438 stl: "none",
1439 }
1440 `)
1441
Paul Duffin1356d8c2020-02-25 19:26:33 +00001442 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001443 checkAndroidBpContents(`
1444// This is auto-generated. DO NOT EDIT.
1445
1446cc_prebuilt_library_headers {
1447 name: "mysdk_mynativeheaders@current",
1448 sdk_member_name: "mynativeheaders",
1449 device_supported: false,
1450 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001451 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001452 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001453}
1454
1455cc_prebuilt_library_headers {
1456 name: "mynativeheaders",
1457 prefer: false,
1458 device_supported: false,
1459 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001460 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001461 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001462}
1463
1464sdk_snapshot {
1465 name: "mysdk@current",
1466 device_supported: false,
1467 host_supported: true,
1468 native_header_libs: ["mysdk_mynativeheaders@current"],
1469}
1470`),
1471 checkAllCopyRules(`
1472include/Test.h -> include/include/Test.h
1473`),
1474 )
1475}
Paul Duffina04c1072020-03-02 10:16:35 +00001476
1477func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1478 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1479 SkipIfNotLinux(t)
1480
1481 result := testSdkWithCc(t, `
1482 sdk {
1483 name: "mysdk",
1484 host_supported: true,
1485 native_header_libs: ["mynativeheaders"],
1486 }
1487
1488 cc_library_headers {
1489 name: "mynativeheaders",
1490 host_supported: true,
1491 system_shared_libs: [],
1492 stl: "none",
1493 export_system_include_dirs: ["include"],
1494 target: {
1495 android: {
1496 export_include_dirs: ["include-android"],
1497 },
1498 host: {
1499 export_include_dirs: ["include-host"],
1500 },
1501 },
1502 }
1503 `)
1504
1505 result.CheckSnapshot("mysdk", "",
1506 checkAndroidBpContents(`
1507// This is auto-generated. DO NOT EDIT.
1508
1509cc_prebuilt_library_headers {
1510 name: "mysdk_mynativeheaders@current",
1511 sdk_member_name: "mynativeheaders",
1512 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001513 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001514 export_system_include_dirs: ["include/include"],
1515 target: {
1516 android: {
1517 export_include_dirs: ["include/include-android"],
1518 },
1519 linux_glibc: {
1520 export_include_dirs: ["include/include-host"],
1521 },
1522 },
Paul Duffina04c1072020-03-02 10:16:35 +00001523}
1524
1525cc_prebuilt_library_headers {
1526 name: "mynativeheaders",
1527 prefer: false,
1528 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001529 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001530 export_system_include_dirs: ["include/include"],
1531 target: {
1532 android: {
1533 export_include_dirs: ["include/include-android"],
1534 },
1535 linux_glibc: {
1536 export_include_dirs: ["include/include-host"],
1537 },
1538 },
Paul Duffina04c1072020-03-02 10:16:35 +00001539}
1540
1541sdk_snapshot {
1542 name: "mysdk@current",
1543 host_supported: true,
1544 native_header_libs: ["mysdk_mynativeheaders@current"],
1545}
1546`),
1547 checkAllCopyRules(`
1548include/Test.h -> include/include/Test.h
1549include-android/AndroidTest.h -> include/include-android/AndroidTest.h
1550include-host/HostTest.h -> include/include-host/HostTest.h
1551`),
1552 )
1553}