blob: bba111b08987c7463e841316f30058d73e16b665 [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
Paul Duffinc62a5102019-12-11 18:34:15 +0000228func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
229 result := testSdkWithCc(t, `
230 sdk {
231 name: "mysdk",
232 native_shared_libs: ["mynativelib1", "mynativelib2"],
233 }
234
235 cc_library_shared {
236 name: "mynativelib1",
237 srcs: [
238 "Test.cpp",
239 ],
240 export_include_dirs: ["include"],
241 system_shared_libs: [],
242 stl: "none",
243 }
244
245 cc_library_shared {
246 name: "mynativelib2",
247 srcs: [
248 "Test.cpp",
249 ],
250 export_include_dirs: ["include"],
251 system_shared_libs: [],
252 stl: "none",
253 }
254 `)
255
Paul Duffin1356d8c2020-02-25 19:26:33 +0000256 result.CheckSnapshot("mysdk", "",
Paul Duffinc62a5102019-12-11 18:34:15 +0000257 checkAllCopyRules(`
258include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800259.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
260.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
261.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
262.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000263`),
264 )
265}
266
Paul Duffina7cd8c82019-12-11 20:00:57 +0000267// Verify that when the shared library has some common and some arch specific properties that the generated
268// snapshot is optimized properly.
269func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
270 result := testSdkWithCc(t, `
271 sdk {
272 name: "mysdk",
273 native_shared_libs: ["mynativelib"],
274 }
275
276 cc_library_shared {
277 name: "mynativelib",
278 srcs: [
279 "Test.cpp",
280 "aidl/foo/bar/Test.aidl",
281 ],
282 export_include_dirs: ["include"],
283 arch: {
284 arm64: {
285 export_system_include_dirs: ["arm64/include"],
286 },
287 },
288 system_shared_libs: [],
289 stl: "none",
290 }
291 `)
292
Paul Duffin1356d8c2020-02-25 19:26:33 +0000293 result.CheckSnapshot("mysdk", "",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000294 checkAndroidBpContents(`
295// This is auto-generated. DO NOT EDIT.
296
297cc_prebuilt_library_shared {
298 name: "mysdk_mynativelib@current",
299 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000300 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000301 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000302 export_include_dirs: ["include/include"],
303 arch: {
304 arm64: {
305 srcs: ["arm64/lib/mynativelib.so"],
306 export_system_include_dirs: ["arm64/include/arm64/include"],
307 },
308 arm: {
309 srcs: ["arm/lib/mynativelib.so"],
310 },
311 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000312}
313
314cc_prebuilt_library_shared {
315 name: "mynativelib",
316 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000317 stl: "none",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000318 export_include_dirs: ["include/include"],
319 arch: {
320 arm64: {
321 srcs: ["arm64/lib/mynativelib.so"],
322 export_system_include_dirs: ["arm64/include/arm64/include"],
323 },
324 arm: {
325 srcs: ["arm/lib/mynativelib.so"],
326 },
327 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000328}
329
330sdk_snapshot {
331 name: "mysdk@current",
332 native_shared_libs: ["mysdk_mynativelib@current"],
333}
334`),
335 checkAllCopyRules(`
336include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800337.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000338arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800339.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000340 )
341}
342
Paul Duffin25ce04b2020-01-16 11:47:25 +0000343func TestSnapshotWithCcBinary(t *testing.T) {
344 result := testSdkWithCc(t, `
345 module_exports {
346 name: "mymodule_exports",
347 native_binaries: ["mynativebinary"],
348 }
349
350 cc_binary {
351 name: "mynativebinary",
352 srcs: [
353 "Test.cpp",
354 ],
355 compile_multilib: "both",
356 system_shared_libs: [],
357 stl: "none",
358 }
359 `)
360
Paul Duffin1356d8c2020-02-25 19:26:33 +0000361 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000362 checkAndroidBpContents(`
363// This is auto-generated. DO NOT EDIT.
364
365cc_prebuilt_binary {
366 name: "mymodule_exports_mynativebinary@current",
367 sdk_member_name: "mynativebinary",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000368 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000369 compile_multilib: "both",
370 arch: {
371 arm64: {
372 srcs: ["arm64/bin/mynativebinary"],
373 },
374 arm: {
375 srcs: ["arm/bin/mynativebinary"],
376 },
377 },
378}
379
380cc_prebuilt_binary {
381 name: "mynativebinary",
382 prefer: false,
383 compile_multilib: "both",
384 arch: {
385 arm64: {
386 srcs: ["arm64/bin/mynativebinary"],
387 },
388 arm: {
389 srcs: ["arm/bin/mynativebinary"],
390 },
391 },
392}
393
394module_exports_snapshot {
395 name: "mymodule_exports@current",
396 native_binaries: ["mymodule_exports_mynativebinary@current"],
397}
398`),
399 checkAllCopyRules(`
400.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
401.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
402`),
403 )
404}
405
Paul Duffina04c1072020-03-02 10:16:35 +0000406func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
407 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
408 SkipIfNotLinux(t)
409
410 result := testSdkWithCc(t, `
411 module_exports {
412 name: "myexports",
413 device_supported: false,
414 host_supported: true,
415 native_binaries: ["mynativebinary"],
416 target: {
417 windows: {
418 enabled: true,
419 },
420 },
421 }
422
423 cc_binary {
424 name: "mynativebinary",
425 device_supported: false,
426 host_supported: true,
427 srcs: [
428 "Test.cpp",
429 ],
430 compile_multilib: "both",
431 system_shared_libs: [],
432 stl: "none",
433 target: {
434 windows: {
435 enabled: true,
436 },
437 },
438 }
439 `)
440
441 result.CheckSnapshot("myexports", "",
442 checkAndroidBpContents(`
443// This is auto-generated. DO NOT EDIT.
444
445cc_prebuilt_binary {
446 name: "myexports_mynativebinary@current",
447 sdk_member_name: "mynativebinary",
448 device_supported: false,
449 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000450 installable: false,
Paul Duffina04c1072020-03-02 10:16:35 +0000451 target: {
452 linux_glibc: {
453 compile_multilib: "both",
454 },
455 linux_glibc_x86_64: {
456 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
457 },
458 linux_glibc_x86: {
459 srcs: ["linux_glibc/x86/bin/mynativebinary"],
460 },
461 windows: {
462 compile_multilib: "64",
463 },
464 windows_x86_64: {
465 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
466 },
467 },
468}
469
470cc_prebuilt_binary {
471 name: "mynativebinary",
472 prefer: false,
473 device_supported: false,
474 host_supported: true,
475 target: {
476 linux_glibc: {
477 compile_multilib: "both",
478 },
479 linux_glibc_x86_64: {
480 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
481 },
482 linux_glibc_x86: {
483 srcs: ["linux_glibc/x86/bin/mynativebinary"],
484 },
485 windows: {
486 compile_multilib: "64",
487 },
488 windows_x86_64: {
489 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
490 },
491 },
492}
493
494module_exports_snapshot {
495 name: "myexports@current",
496 device_supported: false,
497 host_supported: true,
498 native_binaries: ["myexports_mynativebinary@current"],
499}
500`),
501 checkAllCopyRules(`
502.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
503.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
504.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
505`),
506 )
507}
508
Paul Duffin9ab556f2019-12-11 18:42:17 +0000509func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000510 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000511 sdk {
512 name: "mysdk",
513 native_shared_libs: ["mynativelib"],
514 }
515
516 cc_library_shared {
517 name: "mynativelib",
518 srcs: [
519 "Test.cpp",
520 "aidl/foo/bar/Test.aidl",
521 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000522 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000523 export_include_dirs: ["include"],
524 aidl: {
525 export_aidl_headers: true,
526 },
527 system_shared_libs: [],
528 stl: "none",
529 }
530 `)
531
Paul Duffin1356d8c2020-02-25 19:26:33 +0000532 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000533 checkAndroidBpContents(`
534// This is auto-generated. DO NOT EDIT.
535
536cc_prebuilt_library_shared {
537 name: "mysdk_mynativelib@current",
538 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000539 apex_available: [
540 "apex1",
541 "apex2",
542 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000543 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000544 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000545 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000546 arch: {
547 arm64: {
548 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000549 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000550 },
551 arm: {
552 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000553 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000554 },
555 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000556}
557
558cc_prebuilt_library_shared {
559 name: "mynativelib",
560 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +0000561 apex_available: [
562 "apex1",
563 "apex2",
564 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +0000565 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000566 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000567 arch: {
568 arm64: {
569 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000570 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000571 },
572 arm: {
573 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000574 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000575 },
576 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000577}
578
579sdk_snapshot {
580 name: "mysdk@current",
581 native_shared_libs: ["mysdk_mynativelib@current"],
582}
583`),
584 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000585include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800586.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
587.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
588.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
589.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
590.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
591.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
592.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
593.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 +0000594`),
595 )
596}
597
Paul Duffin13f02712020-03-06 12:30:43 +0000598func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
599 result := testSdkWithCc(t, `
600 sdk {
601 name: "mysdk",
602 native_shared_libs: [
603 "mynativelib",
604 "myothernativelib",
605 "mysystemnativelib",
606 ],
607 }
608
609 cc_library {
610 name: "mysystemnativelib",
611 srcs: [
612 "Test.cpp",
613 ],
614 system_shared_libs: [],
615 stl: "none",
616 }
617
618 cc_library_shared {
619 name: "myothernativelib",
620 srcs: [
621 "Test.cpp",
622 ],
623 system_shared_libs: [
624 // A reference to a library that is not an sdk member. Uses libm as that
625 // is in the default set of modules available to this test and so is available
626 // both here and also when the generated Android.bp file is tested in
627 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
628 // handles references to modules that are not sdk members.
629 "libm",
630 ],
631 stl: "none",
632 }
633
634 cc_library {
635 name: "mynativelib",
636 srcs: [
637 "Test.cpp",
638 ],
639 shared_libs: [
640 // A reference to another sdk member.
641 "myothernativelib",
642 ],
643 target: {
644 android: {
645 shared: {
646 shared_libs: [
647 // A reference to a library that is not an sdk member. The libc library
648 // is used here to check that the shared_libs property is handled correctly
649 // in a similar way to how libm is used to check system_shared_libs above.
650 "libc",
651 ],
652 },
653 },
654 },
655 system_shared_libs: [],
656 stl: "none",
657 }
658 `)
659
660 result.CheckSnapshot("mysdk", "",
661 checkAndroidBpContents(`
662// This is auto-generated. DO NOT EDIT.
663
664cc_prebuilt_library_shared {
665 name: "mysdk_mynativelib@current",
666 sdk_member_name: "mynativelib",
667 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000668 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000669 shared_libs: [
670 "mysdk_myothernativelib@current",
671 "libc",
672 ],
673 arch: {
674 arm64: {
675 srcs: ["arm64/lib/mynativelib.so"],
676 },
677 arm: {
678 srcs: ["arm/lib/mynativelib.so"],
679 },
680 },
Paul Duffin13f02712020-03-06 12:30:43 +0000681}
682
683cc_prebuilt_library_shared {
684 name: "mynativelib",
685 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000686 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000687 shared_libs: [
688 "myothernativelib",
689 "libc",
690 ],
691 arch: {
692 arm64: {
693 srcs: ["arm64/lib/mynativelib.so"],
694 },
695 arm: {
696 srcs: ["arm/lib/mynativelib.so"],
697 },
698 },
Paul Duffin13f02712020-03-06 12:30:43 +0000699}
700
701cc_prebuilt_library_shared {
702 name: "mysdk_myothernativelib@current",
703 sdk_member_name: "myothernativelib",
704 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000705 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000706 system_shared_libs: ["libm"],
707 arch: {
708 arm64: {
709 srcs: ["arm64/lib/myothernativelib.so"],
710 },
711 arm: {
712 srcs: ["arm/lib/myothernativelib.so"],
713 },
714 },
Paul Duffin13f02712020-03-06 12:30:43 +0000715}
716
717cc_prebuilt_library_shared {
718 name: "myothernativelib",
719 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000720 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000721 system_shared_libs: ["libm"],
722 arch: {
723 arm64: {
724 srcs: ["arm64/lib/myothernativelib.so"],
725 },
726 arm: {
727 srcs: ["arm/lib/myothernativelib.so"],
728 },
729 },
Paul Duffin13f02712020-03-06 12:30:43 +0000730}
731
732cc_prebuilt_library_shared {
733 name: "mysdk_mysystemnativelib@current",
734 sdk_member_name: "mysystemnativelib",
735 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000736 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000737 arch: {
738 arm64: {
739 srcs: ["arm64/lib/mysystemnativelib.so"],
740 },
741 arm: {
742 srcs: ["arm/lib/mysystemnativelib.so"],
743 },
744 },
Paul Duffin13f02712020-03-06 12:30:43 +0000745}
746
747cc_prebuilt_library_shared {
748 name: "mysystemnativelib",
749 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000750 stl: "none",
Paul Duffin13f02712020-03-06 12:30:43 +0000751 arch: {
752 arm64: {
753 srcs: ["arm64/lib/mysystemnativelib.so"],
754 },
755 arm: {
756 srcs: ["arm/lib/mysystemnativelib.so"],
757 },
758 },
Paul Duffin13f02712020-03-06 12:30:43 +0000759}
760
761sdk_snapshot {
762 name: "mysdk@current",
763 native_shared_libs: [
764 "mysdk_mynativelib@current",
765 "mysdk_myothernativelib@current",
766 "mysdk_mysystemnativelib@current",
767 ],
768}
769`),
770 checkAllCopyRules(`
771.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
772.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
773.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
774.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
775.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
776.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
777`),
778 )
779}
780
Paul Duffin9ab556f2019-12-11 18:42:17 +0000781func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +0000782 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
783 SkipIfNotLinux(t)
784
Paul Duffind835daa2019-11-30 17:49:09 +0000785 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000786 sdk {
787 name: "mysdk",
788 device_supported: false,
789 host_supported: true,
790 native_shared_libs: ["mynativelib"],
791 }
792
793 cc_library_shared {
794 name: "mynativelib",
795 device_supported: false,
796 host_supported: true,
797 srcs: [
798 "Test.cpp",
799 "aidl/foo/bar/Test.aidl",
800 ],
801 export_include_dirs: ["include"],
802 aidl: {
803 export_aidl_headers: true,
804 },
805 system_shared_libs: [],
806 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +0000807 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +0000808 }
809 `)
810
Paul Duffin1356d8c2020-02-25 19:26:33 +0000811 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000812 checkAndroidBpContents(`
813// This is auto-generated. DO NOT EDIT.
814
815cc_prebuilt_library_shared {
816 name: "mysdk_mynativelib@current",
817 sdk_member_name: "mynativelib",
818 device_supported: false,
819 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000820 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +0000821 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000822 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000823 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000824 arch: {
825 x86_64: {
826 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000827 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000828 },
829 x86: {
830 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000831 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000832 },
833 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000834}
835
836cc_prebuilt_library_shared {
837 name: "mynativelib",
838 prefer: false,
839 device_supported: false,
840 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +0000841 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +0000842 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000843 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000844 arch: {
845 x86_64: {
846 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000847 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000848 },
849 x86: {
850 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000851 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000852 },
853 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000854}
855
856sdk_snapshot {
857 name: "mysdk@current",
858 device_supported: false,
859 host_supported: true,
860 native_shared_libs: ["mysdk_mynativelib@current"],
861}
862`),
863 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000864include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +0000865.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000866.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
867.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
868.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
869.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +0000870.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
871.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
872.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
873`),
874 )
875}
Paul Duffin9ab556f2019-12-11 18:42:17 +0000876
Paul Duffina04c1072020-03-02 10:16:35 +0000877func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
878 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
879 SkipIfNotLinux(t)
880
881 result := testSdkWithCc(t, `
882 sdk {
883 name: "mysdk",
884 device_supported: false,
885 host_supported: true,
886 native_shared_libs: ["mynativelib"],
887 target: {
888 windows: {
889 enabled: true,
890 },
891 },
892 }
893
894 cc_library_shared {
895 name: "mynativelib",
896 device_supported: false,
897 host_supported: true,
898 srcs: [
899 "Test.cpp",
900 ],
901 system_shared_libs: [],
902 stl: "none",
903 target: {
904 windows: {
905 enabled: true,
906 },
907 },
908 }
909 `)
910
911 result.CheckSnapshot("mysdk", "",
912 checkAndroidBpContents(`
913// This is auto-generated. DO NOT EDIT.
914
915cc_prebuilt_library_shared {
916 name: "mysdk_mynativelib@current",
917 sdk_member_name: "mynativelib",
918 device_supported: false,
919 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000920 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000921 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000922 target: {
923 linux_glibc_x86_64: {
924 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
925 },
926 linux_glibc_x86: {
927 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
928 },
929 windows_x86_64: {
930 srcs: ["windows/x86_64/lib/mynativelib.dll"],
931 },
932 },
Paul Duffina04c1072020-03-02 10:16:35 +0000933}
934
935cc_prebuilt_library_shared {
936 name: "mynativelib",
937 prefer: false,
938 device_supported: false,
939 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000940 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000941 target: {
942 linux_glibc_x86_64: {
943 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
944 },
945 linux_glibc_x86: {
946 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
947 },
948 windows_x86_64: {
949 srcs: ["windows/x86_64/lib/mynativelib.dll"],
950 },
951 },
Paul Duffina04c1072020-03-02 10:16:35 +0000952}
953
954sdk_snapshot {
955 name: "mysdk@current",
956 device_supported: false,
957 host_supported: true,
958 native_shared_libs: ["mysdk_mynativelib@current"],
959}
960`),
961 checkAllCopyRules(`
962.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
963.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
964.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
965`),
966 )
967}
968
Paul Duffin9ab556f2019-12-11 18:42:17 +0000969func TestSnapshotWithCcStaticLibrary(t *testing.T) {
970 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +0000971 module_exports {
972 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000973 native_static_libs: ["mynativelib"],
974 }
975
976 cc_library_static {
977 name: "mynativelib",
978 srcs: [
979 "Test.cpp",
980 "aidl/foo/bar/Test.aidl",
981 ],
982 export_include_dirs: ["include"],
983 aidl: {
984 export_aidl_headers: true,
985 },
986 system_shared_libs: [],
987 stl: "none",
988 }
989 `)
990
Paul Duffin1356d8c2020-02-25 19:26:33 +0000991 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000992 checkAndroidBpContents(`
993// This is auto-generated. DO NOT EDIT.
994
995cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +0000996 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +0000997 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000998 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000999 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001000 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001001 arch: {
1002 arm64: {
1003 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001004 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001005 },
1006 arm: {
1007 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001008 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001009 },
1010 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001011}
1012
1013cc_prebuilt_library_static {
1014 name: "mynativelib",
1015 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001016 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001017 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001018 arch: {
1019 arm64: {
1020 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001021 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001022 },
1023 arm: {
1024 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001025 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001026 },
1027 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001028}
1029
Paul Duffine6029182019-12-16 17:43:48 +00001030module_exports_snapshot {
1031 name: "myexports@current",
1032 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001033}
1034`),
1035 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001036include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001037.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1038.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1039.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1040.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1041.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1042.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1043.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1044.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 +00001045`),
1046 )
1047}
1048
1049func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1050 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1051 SkipIfNotLinux(t)
1052
1053 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001054 module_exports {
1055 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001056 device_supported: false,
1057 host_supported: true,
1058 native_static_libs: ["mynativelib"],
1059 }
1060
1061 cc_library_static {
1062 name: "mynativelib",
1063 device_supported: false,
1064 host_supported: true,
1065 srcs: [
1066 "Test.cpp",
1067 "aidl/foo/bar/Test.aidl",
1068 ],
1069 export_include_dirs: ["include"],
1070 aidl: {
1071 export_aidl_headers: true,
1072 },
1073 system_shared_libs: [],
1074 stl: "none",
1075 }
1076 `)
1077
Paul Duffin1356d8c2020-02-25 19:26:33 +00001078 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001079 checkAndroidBpContents(`
1080// This is auto-generated. DO NOT EDIT.
1081
1082cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001083 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001084 sdk_member_name: "mynativelib",
1085 device_supported: false,
1086 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001087 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001088 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001089 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001090 arch: {
1091 x86_64: {
1092 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001093 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001094 },
1095 x86: {
1096 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001097 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001098 },
1099 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001100}
1101
1102cc_prebuilt_library_static {
1103 name: "mynativelib",
1104 prefer: false,
1105 device_supported: false,
1106 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001107 stl: "none",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001108 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001109 arch: {
1110 x86_64: {
1111 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001112 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001113 },
1114 x86: {
1115 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001116 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001117 },
1118 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001119}
1120
Paul Duffine6029182019-12-16 17:43:48 +00001121module_exports_snapshot {
1122 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001123 device_supported: false,
1124 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001125 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001126}
1127`),
1128 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001129include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001130.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001131.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1132.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1133.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1134.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001135.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1136.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1137.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1138`),
1139 )
1140}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001141
1142func TestHostSnapshotWithMultiLib64(t *testing.T) {
1143 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1144 SkipIfNotLinux(t)
1145
1146 result := testSdkWithCc(t, `
1147 module_exports {
1148 name: "myexports",
1149 device_supported: false,
1150 host_supported: true,
1151 target: {
1152 host: {
1153 compile_multilib: "64",
1154 },
1155 },
1156 native_static_libs: ["mynativelib"],
1157 }
1158
1159 cc_library_static {
1160 name: "mynativelib",
1161 device_supported: false,
1162 host_supported: true,
1163 srcs: [
1164 "Test.cpp",
1165 "aidl/foo/bar/Test.aidl",
1166 ],
1167 export_include_dirs: ["include"],
1168 aidl: {
1169 export_aidl_headers: true,
1170 },
1171 system_shared_libs: [],
1172 stl: "none",
1173 }
1174 `)
1175
Paul Duffin1356d8c2020-02-25 19:26:33 +00001176 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001177 checkAndroidBpContents(`
1178// This is auto-generated. DO NOT EDIT.
1179
1180cc_prebuilt_library_static {
1181 name: "myexports_mynativelib@current",
1182 sdk_member_name: "mynativelib",
1183 device_supported: false,
1184 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001185 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001186 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001187 export_include_dirs: ["include/include"],
1188 arch: {
1189 x86_64: {
1190 srcs: ["x86_64/lib/mynativelib.a"],
1191 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1192 },
1193 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001194}
1195
1196cc_prebuilt_library_static {
1197 name: "mynativelib",
1198 prefer: false,
1199 device_supported: false,
1200 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001201 stl: "none",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001202 export_include_dirs: ["include/include"],
1203 arch: {
1204 x86_64: {
1205 srcs: ["x86_64/lib/mynativelib.a"],
1206 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1207 },
1208 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001209}
1210
1211module_exports_snapshot {
1212 name: "myexports@current",
1213 device_supported: false,
1214 host_supported: true,
1215 target: {
1216 host: {
1217 compile_multilib: "64",
1218 },
1219 },
1220 native_static_libs: ["myexports_mynativelib@current"],
1221}`),
1222 checkAllCopyRules(`
1223include/Test.h -> include/include/Test.h
1224.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1225.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1226.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1227.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1228`),
1229 )
1230}
Paul Duffin91756d22020-02-21 16:29:57 +00001231
1232func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1233 result := testSdkWithCc(t, `
1234 sdk {
1235 name: "mysdk",
1236 native_header_libs: ["mynativeheaders"],
1237 }
1238
1239 cc_library_headers {
1240 name: "mynativeheaders",
1241 export_include_dirs: ["include"],
1242 system_shared_libs: [],
1243 stl: "none",
1244 }
1245 `)
1246
Paul Duffin1356d8c2020-02-25 19:26:33 +00001247 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001248 checkAndroidBpContents(`
1249// This is auto-generated. DO NOT EDIT.
1250
1251cc_prebuilt_library_headers {
1252 name: "mysdk_mynativeheaders@current",
1253 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001254 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001255 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001256}
1257
1258cc_prebuilt_library_headers {
1259 name: "mynativeheaders",
1260 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001261 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001262 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001263}
1264
1265sdk_snapshot {
1266 name: "mysdk@current",
1267 native_header_libs: ["mysdk_mynativeheaders@current"],
1268}
1269`),
1270 checkAllCopyRules(`
1271include/Test.h -> include/include/Test.h
1272`),
1273 )
1274}
1275
1276func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1277 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1278 SkipIfNotLinux(t)
1279
1280 result := testSdkWithCc(t, `
1281 sdk {
1282 name: "mysdk",
1283 device_supported: false,
1284 host_supported: true,
1285 native_header_libs: ["mynativeheaders"],
1286 }
1287
1288 cc_library_headers {
1289 name: "mynativeheaders",
1290 device_supported: false,
1291 host_supported: true,
1292 export_include_dirs: ["include"],
1293 system_shared_libs: [],
1294 stl: "none",
1295 }
1296 `)
1297
Paul Duffin1356d8c2020-02-25 19:26:33 +00001298 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001299 checkAndroidBpContents(`
1300// This is auto-generated. DO NOT EDIT.
1301
1302cc_prebuilt_library_headers {
1303 name: "mysdk_mynativeheaders@current",
1304 sdk_member_name: "mynativeheaders",
1305 device_supported: false,
1306 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001307 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001308 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001309}
1310
1311cc_prebuilt_library_headers {
1312 name: "mynativeheaders",
1313 prefer: false,
1314 device_supported: false,
1315 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001316 stl: "none",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001317 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001318}
1319
1320sdk_snapshot {
1321 name: "mysdk@current",
1322 device_supported: false,
1323 host_supported: true,
1324 native_header_libs: ["mysdk_mynativeheaders@current"],
1325}
1326`),
1327 checkAllCopyRules(`
1328include/Test.h -> include/include/Test.h
1329`),
1330 )
1331}
Paul Duffina04c1072020-03-02 10:16:35 +00001332
1333func TestDeviceAndHostSnapshotWithCcHeadersLibrary(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 host_supported: true,
1341 native_header_libs: ["mynativeheaders"],
1342 }
1343
1344 cc_library_headers {
1345 name: "mynativeheaders",
1346 host_supported: true,
1347 system_shared_libs: [],
1348 stl: "none",
1349 export_system_include_dirs: ["include"],
1350 target: {
1351 android: {
1352 export_include_dirs: ["include-android"],
1353 },
1354 host: {
1355 export_include_dirs: ["include-host"],
1356 },
1357 },
1358 }
1359 `)
1360
1361 result.CheckSnapshot("mysdk", "",
1362 checkAndroidBpContents(`
1363// This is auto-generated. DO NOT EDIT.
1364
1365cc_prebuilt_library_headers {
1366 name: "mysdk_mynativeheaders@current",
1367 sdk_member_name: "mynativeheaders",
1368 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001369 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001370 export_system_include_dirs: ["include/include"],
1371 target: {
1372 android: {
1373 export_include_dirs: ["include/include-android"],
1374 },
1375 linux_glibc: {
1376 export_include_dirs: ["include/include-host"],
1377 },
1378 },
Paul Duffina04c1072020-03-02 10:16:35 +00001379}
1380
1381cc_prebuilt_library_headers {
1382 name: "mynativeheaders",
1383 prefer: false,
1384 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001385 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001386 export_system_include_dirs: ["include/include"],
1387 target: {
1388 android: {
1389 export_include_dirs: ["include/include-android"],
1390 },
1391 linux_glibc: {
1392 export_include_dirs: ["include/include-host"],
1393 },
1394 },
Paul Duffina04c1072020-03-02 10:16:35 +00001395}
1396
1397sdk_snapshot {
1398 name: "mysdk@current",
1399 host_supported: true,
1400 native_header_libs: ["mysdk_mynativeheaders@current"],
1401}
1402`),
1403 checkAllCopyRules(`
1404include/Test.h -> include/include/Test.h
1405include-android/AndroidTest.h -> include/include-android/AndroidTest.h
1406include-host/HostTest.h -> include/include-host/HostTest.h
1407`),
1408 )
1409}