blob: 497f14bde2e62b848135a8eff997e06e7a7e1a76 [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
Martin Stjernholm7feceb22020-07-11 04:33:29 +010024var ccTestFs = map[string][]byte{
25 "Test.cpp": nil,
26 "include/Test.h": nil,
27 "include-android/AndroidTest.h": nil,
28 "include-host/HostTest.h": nil,
29 "arm64/include/Arm64Test.h": nil,
30 "libfoo.so": nil,
31 "aidl/foo/bar/Test.aidl": nil,
32 "some/where/stubslib.map.txt": nil,
33}
34
Paul Duffind835daa2019-11-30 17:49:09 +000035func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
36 t.Helper()
Martin Stjernholm7feceb22020-07-11 04:33:29 +010037 return testSdkWithFs(t, bp, ccTestFs)
Paul Duffind835daa2019-11-30 17:49:09 +000038}
39
Paul Duffina80fdec2019-12-03 15:25:00 +000040// Contains tests for SDK members provided by the cc package.
41
42func TestSdkIsCompileMultilibBoth(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +000043 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +000044 sdk {
45 name: "mysdk",
46 native_shared_libs: ["sdkmember"],
47 }
48
49 cc_library_shared {
50 name: "sdkmember",
51 srcs: ["Test.cpp"],
Paul Duffina80fdec2019-12-03 15:25:00 +000052 stl: "none",
53 }
54 `)
55
Colin Cross7113d202019-11-20 16:39:12 -080056 armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
57 arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
Paul Duffina80fdec2019-12-03 15:25:00 +000058
59 var inputs []string
Paul Duffin1356d8c2020-02-25 19:26:33 +000060 buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
Paul Duffina80fdec2019-12-03 15:25:00 +000061 for _, bp := range buildParams {
62 if bp.Input != nil {
63 inputs = append(inputs, bp.Input.String())
64 }
65 }
66
67 // ensure that both 32/64 outputs are inputs of the sdk snapshot
68 ensureListContains(t, inputs, armOutput.String())
69 ensureListContains(t, inputs, arm64Output.String())
70}
71
Martin Stjernholm26ab8e82020-06-30 20:34:00 +010072func TestSdkCompileMultilibOverride(t *testing.T) {
73 result := testSdkWithCc(t, `
74 sdk {
75 name: "mysdk",
Martin Stjernholm89238f42020-07-10 00:14:03 +010076 device_supported: false,
77 host_supported: true,
Martin Stjernholm26ab8e82020-06-30 20:34:00 +010078 native_shared_libs: ["sdkmember"],
79 compile_multilib: "64",
80 }
81
82 cc_library_shared {
83 name: "sdkmember",
Martin Stjernholm89238f42020-07-10 00:14:03 +010084 device_supported: false,
85 host_supported: true,
Martin Stjernholm26ab8e82020-06-30 20:34:00 +010086 srcs: ["Test.cpp"],
87 stl: "none",
88 compile_multilib: "64",
89 }
90 `)
91
92 result.CheckSnapshot("mysdk", "",
Martin Stjernholm89238f42020-07-10 00:14:03 +010093 checkAndroidBpContents(`
94// This is auto-generated. DO NOT EDIT.
95
96cc_prebuilt_library_shared {
97 name: "mysdk_sdkmember@current",
98 sdk_member_name: "sdkmember",
99 device_supported: false,
100 host_supported: true,
101 installable: false,
102 stl: "none",
103 compile_multilib: "64",
104 arch: {
105 x86_64: {
106 srcs: ["x86_64/lib/sdkmember.so"],
107 },
108 },
109}
110
111cc_prebuilt_library_shared {
112 name: "sdkmember",
113 prefer: false,
114 device_supported: false,
115 host_supported: true,
116 stl: "none",
117 compile_multilib: "64",
118 arch: {
119 x86_64: {
120 srcs: ["x86_64/lib/sdkmember.so"],
121 },
122 },
123}
124
125sdk_snapshot {
126 name: "mysdk@current",
127 device_supported: false,
128 host_supported: true,
129 native_shared_libs: ["mysdk_sdkmember@current"],
130 target: {
131 linux_glibc: {
132 compile_multilib: "64",
133 },
134 },
135}
136`),
Martin Stjernholm26ab8e82020-06-30 20:34:00 +0100137 checkAllCopyRules(`
Martin Stjernholm89238f42020-07-10 00:14:03 +0100138.intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> x86_64/lib/sdkmember.so
Martin Stjernholm26ab8e82020-06-30 20:34:00 +0100139`))
140}
141
Paul Duffina80fdec2019-12-03 15:25:00 +0000142func TestBasicSdkWithCc(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000143 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000144 sdk {
145 name: "mysdk",
146 native_shared_libs: ["sdkmember"],
147 }
148
Paul Duffina0843f62019-12-13 19:50:38 +0000149 cc_library_shared {
150 name: "sdkmember",
Colin Crossf9aabd72020-02-15 11:29:50 -0800151 system_shared_libs: [],
Martin Stjernholmcc776012020-07-07 03:22:21 +0100152 stl: "none",
153 apex_available: ["mysdkapex"],
Paul Duffina0843f62019-12-13 19:50:38 +0000154 }
155
Paul Duffina80fdec2019-12-03 15:25:00 +0000156 sdk_snapshot {
157 name: "mysdk@1",
158 native_shared_libs: ["sdkmember_mysdk_1"],
159 }
160
161 sdk_snapshot {
162 name: "mysdk@2",
163 native_shared_libs: ["sdkmember_mysdk_2"],
164 }
165
166 cc_prebuilt_library_shared {
167 name: "sdkmember",
168 srcs: ["libfoo.so"],
169 prefer: false,
170 system_shared_libs: [],
171 stl: "none",
172 }
173
174 cc_prebuilt_library_shared {
175 name: "sdkmember_mysdk_1",
176 sdk_member_name: "sdkmember",
177 srcs: ["libfoo.so"],
178 system_shared_libs: [],
179 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000180 // TODO: remove //apex_available:platform
181 apex_available: [
182 "//apex_available:platform",
183 "myapex",
184 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000185 }
186
187 cc_prebuilt_library_shared {
188 name: "sdkmember_mysdk_2",
189 sdk_member_name: "sdkmember",
190 srcs: ["libfoo.so"],
191 system_shared_libs: [],
192 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000193 // TODO: remove //apex_available:platform
194 apex_available: [
195 "//apex_available:platform",
196 "myapex2",
197 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000198 }
199
200 cc_library_shared {
201 name: "mycpplib",
202 srcs: ["Test.cpp"],
203 shared_libs: ["sdkmember"],
204 system_shared_libs: [],
205 stl: "none",
Anton Hanssoneec79eb2020-01-10 15:12:39 +0000206 apex_available: [
207 "myapex",
208 "myapex2",
209 ],
Paul Duffina80fdec2019-12-03 15:25:00 +0000210 }
211
212 apex {
213 name: "myapex",
214 native_shared_libs: ["mycpplib"],
215 uses_sdks: ["mysdk@1"],
216 key: "myapex.key",
217 certificate: ":myapex.cert",
218 }
219
220 apex {
221 name: "myapex2",
222 native_shared_libs: ["mycpplib"],
223 uses_sdks: ["mysdk@2"],
224 key: "myapex.key",
225 certificate: ":myapex.cert",
226 }
Martin Stjernholmcc776012020-07-07 03:22:21 +0100227
228 apex {
229 name: "mysdkapex",
230 native_shared_libs: ["sdkmember"],
231 key: "myapex.key",
232 certificate: ":myapex.cert",
233 }
Paul Duffina80fdec2019-12-03 15:25:00 +0000234 `)
235
Colin Cross7113d202019-11-20 16:39:12 -0800236 sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk_1", "android_arm64_armv8-a_shared_myapex").Rule("toc").Output
237 sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk_2", "android_arm64_armv8-a_shared_myapex2").Rule("toc").Output
Paul Duffina80fdec2019-12-03 15:25:00 +0000238
Colin Cross7113d202019-11-20 16:39:12 -0800239 cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex")
240 cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex2")
Paul Duffina80fdec2019-12-03 15:25:00 +0000241
242 // Depending on the uses_sdks value, different libs are linked
243 ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
244 ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
245}
246
Paul Duffina0843f62019-12-13 19:50:38 +0000247// Make sure the sdk can use host specific cc libraries static/shared and both.
248func TestHostSdkWithCc(t *testing.T) {
249 testSdkWithCc(t, `
250 sdk {
251 name: "mysdk",
252 device_supported: false,
253 host_supported: true,
254 native_shared_libs: ["sdkshared"],
255 native_static_libs: ["sdkstatic"],
256 }
257
258 cc_library_host_shared {
259 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000260 stl: "none",
261 }
262
263 cc_library_host_static {
264 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000265 stl: "none",
266 }
267 `)
268}
269
270// Make sure the sdk can use cc libraries static/shared and both.
271func TestSdkWithCc(t *testing.T) {
272 testSdkWithCc(t, `
273 sdk {
274 name: "mysdk",
275 native_shared_libs: ["sdkshared", "sdkboth1"],
276 native_static_libs: ["sdkstatic", "sdkboth2"],
277 }
278
279 cc_library_shared {
280 name: "sdkshared",
Paul Duffina0843f62019-12-13 19:50:38 +0000281 stl: "none",
282 }
283
284 cc_library_static {
285 name: "sdkstatic",
Paul Duffina0843f62019-12-13 19:50:38 +0000286 stl: "none",
287 }
288
289 cc_library {
290 name: "sdkboth1",
Paul Duffina0843f62019-12-13 19:50:38 +0000291 stl: "none",
292 }
293
294 cc_library {
295 name: "sdkboth2",
Paul Duffina0843f62019-12-13 19:50:38 +0000296 stl: "none",
297 }
298 `)
299}
300
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000301func TestSnapshotWithObject(t *testing.T) {
302 result := testSdkWithCc(t, `
303 sdk {
304 name: "mysdk",
305 native_objects: ["crtobj"],
306 }
307
308 cc_object {
309 name: "crtobj",
310 stl: "none",
311 }
312 `)
313
314 result.CheckSnapshot("mysdk", "",
315 checkAndroidBpContents(`
316// This is auto-generated. DO NOT EDIT.
317
318cc_prebuilt_object {
319 name: "mysdk_crtobj@current",
320 sdk_member_name: "crtobj",
321 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100322 compile_multilib: "both",
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000323 arch: {
324 arm64: {
325 srcs: ["arm64/lib/crtobj.o"],
326 },
327 arm: {
328 srcs: ["arm/lib/crtobj.o"],
329 },
330 },
331}
332
333cc_prebuilt_object {
334 name: "crtobj",
335 prefer: false,
336 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100337 compile_multilib: "both",
Martin Stjernholmcd07bce2020-03-10 22:37:59 +0000338 arch: {
339 arm64: {
340 srcs: ["arm64/lib/crtobj.o"],
341 },
342 arm: {
343 srcs: ["arm/lib/crtobj.o"],
344 },
345 },
346}
347
348sdk_snapshot {
349 name: "mysdk@current",
350 native_objects: ["mysdk_crtobj@current"],
351}
352`),
353 checkAllCopyRules(`
354.intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
355.intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
356`),
357 )
358}
359
Paul Duffinc62a5102019-12-11 18:34:15 +0000360func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
361 result := testSdkWithCc(t, `
362 sdk {
363 name: "mysdk",
364 native_shared_libs: ["mynativelib1", "mynativelib2"],
365 }
366
367 cc_library_shared {
368 name: "mynativelib1",
369 srcs: [
370 "Test.cpp",
371 ],
372 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000373 stl: "none",
374 }
375
376 cc_library_shared {
377 name: "mynativelib2",
378 srcs: [
379 "Test.cpp",
380 ],
381 export_include_dirs: ["include"],
Paul Duffinc62a5102019-12-11 18:34:15 +0000382 stl: "none",
383 }
384 `)
385
Paul Duffin1356d8c2020-02-25 19:26:33 +0000386 result.CheckSnapshot("mysdk", "",
Paul Duffinc62a5102019-12-11 18:34:15 +0000387 checkAllCopyRules(`
388include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800389.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
390.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
391.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
392.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
Paul Duffinc62a5102019-12-11 18:34:15 +0000393`),
394 )
395}
396
Paul Duffina7cd8c82019-12-11 20:00:57 +0000397// Verify that when the shared library has some common and some arch specific properties that the generated
398// snapshot is optimized properly.
399func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
400 result := testSdkWithCc(t, `
401 sdk {
402 name: "mysdk",
403 native_shared_libs: ["mynativelib"],
404 }
405
406 cc_library_shared {
407 name: "mynativelib",
408 srcs: [
409 "Test.cpp",
410 "aidl/foo/bar/Test.aidl",
411 ],
412 export_include_dirs: ["include"],
413 arch: {
414 arm64: {
415 export_system_include_dirs: ["arm64/include"],
416 },
417 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000418 stl: "none",
419 }
420 `)
421
Paul Duffin1356d8c2020-02-25 19:26:33 +0000422 result.CheckSnapshot("mysdk", "",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000423 checkAndroidBpContents(`
424// This is auto-generated. DO NOT EDIT.
425
426cc_prebuilt_library_shared {
427 name: "mysdk_mynativelib@current",
428 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000429 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000430 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100431 compile_multilib: "both",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000432 export_include_dirs: ["include/include"],
433 arch: {
434 arm64: {
435 srcs: ["arm64/lib/mynativelib.so"],
436 export_system_include_dirs: ["arm64/include/arm64/include"],
437 },
438 arm: {
439 srcs: ["arm/lib/mynativelib.so"],
440 },
441 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000442}
443
444cc_prebuilt_library_shared {
445 name: "mynativelib",
446 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000447 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100448 compile_multilib: "both",
Paul Duffina7cd8c82019-12-11 20:00:57 +0000449 export_include_dirs: ["include/include"],
450 arch: {
451 arm64: {
452 srcs: ["arm64/lib/mynativelib.so"],
453 export_system_include_dirs: ["arm64/include/arm64/include"],
454 },
455 arm: {
456 srcs: ["arm/lib/mynativelib.so"],
457 },
458 },
Paul Duffina7cd8c82019-12-11 20:00:57 +0000459}
460
461sdk_snapshot {
462 name: "mysdk@current",
463 native_shared_libs: ["mysdk_mynativelib@current"],
464}
465`),
466 checkAllCopyRules(`
467include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800468.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
Paul Duffina7cd8c82019-12-11 20:00:57 +0000469arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800470.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
Paul Duffina7cd8c82019-12-11 20:00:57 +0000471 )
472}
473
Paul Duffin25ce04b2020-01-16 11:47:25 +0000474func TestSnapshotWithCcBinary(t *testing.T) {
475 result := testSdkWithCc(t, `
476 module_exports {
477 name: "mymodule_exports",
478 native_binaries: ["mynativebinary"],
479 }
480
481 cc_binary {
482 name: "mynativebinary",
483 srcs: [
484 "Test.cpp",
485 ],
486 compile_multilib: "both",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000487 }
488 `)
489
Paul Duffin1356d8c2020-02-25 19:26:33 +0000490 result.CheckSnapshot("mymodule_exports", "",
Paul Duffin25ce04b2020-01-16 11:47:25 +0000491 checkAndroidBpContents(`
492// This is auto-generated. DO NOT EDIT.
493
494cc_prebuilt_binary {
495 name: "mymodule_exports_mynativebinary@current",
496 sdk_member_name: "mynativebinary",
Paul Duffin0cb37b92020-03-04 14:52:46 +0000497 installable: false,
Paul Duffin25ce04b2020-01-16 11:47:25 +0000498 compile_multilib: "both",
499 arch: {
500 arm64: {
501 srcs: ["arm64/bin/mynativebinary"],
502 },
503 arm: {
504 srcs: ["arm/bin/mynativebinary"],
505 },
506 },
507}
508
509cc_prebuilt_binary {
510 name: "mynativebinary",
511 prefer: false,
512 compile_multilib: "both",
513 arch: {
514 arm64: {
515 srcs: ["arm64/bin/mynativebinary"],
516 },
517 arm: {
518 srcs: ["arm/bin/mynativebinary"],
519 },
520 },
521}
522
523module_exports_snapshot {
524 name: "mymodule_exports@current",
525 native_binaries: ["mymodule_exports_mynativebinary@current"],
526}
527`),
528 checkAllCopyRules(`
529.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
530.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
531`),
532 )
533}
534
Paul Duffina04c1072020-03-02 10:16:35 +0000535func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +0000536 result := testSdkWithCc(t, `
537 module_exports {
538 name: "myexports",
539 device_supported: false,
540 host_supported: true,
541 native_binaries: ["mynativebinary"],
542 target: {
543 windows: {
544 enabled: true,
545 },
546 },
547 }
548
549 cc_binary {
550 name: "mynativebinary",
551 device_supported: false,
552 host_supported: true,
553 srcs: [
554 "Test.cpp",
555 ],
556 compile_multilib: "both",
Paul Duffina04c1072020-03-02 10:16:35 +0000557 stl: "none",
558 target: {
559 windows: {
560 enabled: true,
561 },
562 },
563 }
564 `)
565
566 result.CheckSnapshot("myexports", "",
567 checkAndroidBpContents(`
568// This is auto-generated. DO NOT EDIT.
569
570cc_prebuilt_binary {
571 name: "myexports_mynativebinary@current",
572 sdk_member_name: "mynativebinary",
573 device_supported: false,
574 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000575 installable: false,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100576 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000577 target: {
578 linux_glibc: {
579 compile_multilib: "both",
580 },
581 linux_glibc_x86_64: {
582 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
583 },
584 linux_glibc_x86: {
585 srcs: ["linux_glibc/x86/bin/mynativebinary"],
586 },
587 windows: {
588 compile_multilib: "64",
589 },
590 windows_x86_64: {
591 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
592 },
593 },
594}
595
596cc_prebuilt_binary {
597 name: "mynativebinary",
598 prefer: false,
599 device_supported: false,
600 host_supported: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100601 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000602 target: {
603 linux_glibc: {
604 compile_multilib: "both",
605 },
606 linux_glibc_x86_64: {
607 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
608 },
609 linux_glibc_x86: {
610 srcs: ["linux_glibc/x86/bin/mynativebinary"],
611 },
612 windows: {
613 compile_multilib: "64",
614 },
615 windows_x86_64: {
616 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
617 },
618 },
619}
620
621module_exports_snapshot {
622 name: "myexports@current",
623 device_supported: false,
624 host_supported: true,
625 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +0000626 target: {
627 windows: {
628 compile_multilib: "64",
629 },
630 },
Paul Duffina04c1072020-03-02 10:16:35 +0000631}
632`),
633 checkAllCopyRules(`
634.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
635.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
636.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
637`),
638 )
639}
640
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100641// Test that we support the necessary flags for the linker binary, which is
642// special in several ways.
643func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100644 result := testSdkWithCc(t, `
645 module_exports {
646 name: "mymodule_exports",
647 host_supported: true,
648 device_supported: false,
649 native_binaries: ["linker"],
650 }
651
652 cc_binary {
653 name: "linker",
654 host_supported: true,
655 static_executable: true,
656 nocrt: true,
657 stl: "none",
658 srcs: [
659 "Test.cpp",
660 ],
661 compile_multilib: "both",
662 }
663 `)
664
665 result.CheckSnapshot("mymodule_exports", "",
666 checkAndroidBpContents(`
667// This is auto-generated. DO NOT EDIT.
668
669cc_prebuilt_binary {
670 name: "mymodule_exports_linker@current",
671 sdk_member_name: "linker",
672 device_supported: false,
673 host_supported: true,
674 installable: false,
675 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100676 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100677 static_executable: true,
678 nocrt: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100679 arch: {
680 x86_64: {
681 srcs: ["x86_64/bin/linker"],
682 },
683 x86: {
684 srcs: ["x86/bin/linker"],
685 },
686 },
687}
688
689cc_prebuilt_binary {
690 name: "linker",
691 prefer: false,
692 device_supported: false,
693 host_supported: true,
694 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100695 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100696 static_executable: true,
697 nocrt: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100698 arch: {
699 x86_64: {
700 srcs: ["x86_64/bin/linker"],
701 },
702 x86: {
703 srcs: ["x86/bin/linker"],
704 },
705 },
706}
707
708module_exports_snapshot {
709 name: "mymodule_exports@current",
710 device_supported: false,
711 host_supported: true,
712 native_binaries: ["mymodule_exports_linker@current"],
713}
714`),
715 checkAllCopyRules(`
716.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
717.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
718`),
719 )
720}
721
Paul Duffin9ab556f2019-12-11 18:42:17 +0000722func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000723 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000724 sdk {
725 name: "mysdk",
726 native_shared_libs: ["mynativelib"],
727 }
728
729 cc_library_shared {
730 name: "mynativelib",
731 srcs: [
732 "Test.cpp",
733 "aidl/foo/bar/Test.aidl",
734 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000735 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000736 export_include_dirs: ["include"],
737 aidl: {
738 export_aidl_headers: true,
739 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000740 stl: "none",
741 }
742 `)
743
Paul Duffin1356d8c2020-02-25 19:26:33 +0000744 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000745 checkAndroidBpContents(`
746// This is auto-generated. DO NOT EDIT.
747
748cc_prebuilt_library_shared {
749 name: "mysdk_mynativelib@current",
750 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000751 apex_available: [
752 "apex1",
753 "apex2",
754 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000755 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000756 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100757 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000758 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000759 arch: {
760 arm64: {
761 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000762 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000763 },
764 arm: {
765 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000766 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000767 },
768 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000769}
770
771cc_prebuilt_library_shared {
772 name: "mynativelib",
773 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +0000774 apex_available: [
775 "apex1",
776 "apex2",
777 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +0000778 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100779 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000780 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000781 arch: {
782 arm64: {
783 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000784 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000785 },
786 arm: {
787 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000788 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000789 },
790 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000791}
792
793sdk_snapshot {
794 name: "mysdk@current",
795 native_shared_libs: ["mysdk_mynativelib@current"],
796}
797`),
798 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000799include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800800.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
801.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
802.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
803.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
804.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
805.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
806.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
807.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 +0000808`),
809 )
810}
811
Paul Duffin13f02712020-03-06 12:30:43 +0000812func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
813 result := testSdkWithCc(t, `
814 sdk {
815 name: "mysdk",
816 native_shared_libs: [
817 "mynativelib",
818 "myothernativelib",
819 "mysystemnativelib",
820 ],
821 }
822
823 cc_library {
824 name: "mysystemnativelib",
825 srcs: [
826 "Test.cpp",
827 ],
Paul Duffin13f02712020-03-06 12:30:43 +0000828 stl: "none",
829 }
830
831 cc_library_shared {
832 name: "myothernativelib",
833 srcs: [
834 "Test.cpp",
835 ],
836 system_shared_libs: [
837 // A reference to a library that is not an sdk member. Uses libm as that
838 // is in the default set of modules available to this test and so is available
839 // both here and also when the generated Android.bp file is tested in
840 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
841 // handles references to modules that are not sdk members.
842 "libm",
843 ],
844 stl: "none",
845 }
846
847 cc_library {
848 name: "mynativelib",
849 srcs: [
850 "Test.cpp",
851 ],
852 shared_libs: [
853 // A reference to another sdk member.
854 "myothernativelib",
855 ],
856 target: {
857 android: {
858 shared: {
859 shared_libs: [
860 // A reference to a library that is not an sdk member. The libc library
861 // is used here to check that the shared_libs property is handled correctly
862 // in a similar way to how libm is used to check system_shared_libs above.
863 "libc",
864 ],
865 },
866 },
867 },
Paul Duffin13f02712020-03-06 12:30:43 +0000868 stl: "none",
869 }
870 `)
871
872 result.CheckSnapshot("mysdk", "",
873 checkAndroidBpContents(`
874// This is auto-generated. DO NOT EDIT.
875
876cc_prebuilt_library_shared {
877 name: "mysdk_mynativelib@current",
878 sdk_member_name: "mynativelib",
879 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000880 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100881 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000882 shared_libs: [
883 "mysdk_myothernativelib@current",
884 "libc",
885 ],
886 arch: {
887 arm64: {
888 srcs: ["arm64/lib/mynativelib.so"],
889 },
890 arm: {
891 srcs: ["arm/lib/mynativelib.so"],
892 },
893 },
Paul Duffin13f02712020-03-06 12:30:43 +0000894}
895
896cc_prebuilt_library_shared {
897 name: "mynativelib",
898 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000899 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100900 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000901 shared_libs: [
902 "myothernativelib",
903 "libc",
904 ],
905 arch: {
906 arm64: {
907 srcs: ["arm64/lib/mynativelib.so"],
908 },
909 arm: {
910 srcs: ["arm/lib/mynativelib.so"],
911 },
912 },
Paul Duffin13f02712020-03-06 12:30:43 +0000913}
914
915cc_prebuilt_library_shared {
916 name: "mysdk_myothernativelib@current",
917 sdk_member_name: "myothernativelib",
918 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000919 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100920 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000921 system_shared_libs: ["libm"],
922 arch: {
923 arm64: {
924 srcs: ["arm64/lib/myothernativelib.so"],
925 },
926 arm: {
927 srcs: ["arm/lib/myothernativelib.so"],
928 },
929 },
Paul Duffin13f02712020-03-06 12:30:43 +0000930}
931
932cc_prebuilt_library_shared {
933 name: "myothernativelib",
934 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000935 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100936 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000937 system_shared_libs: ["libm"],
938 arch: {
939 arm64: {
940 srcs: ["arm64/lib/myothernativelib.so"],
941 },
942 arm: {
943 srcs: ["arm/lib/myothernativelib.so"],
944 },
945 },
Paul Duffin13f02712020-03-06 12:30:43 +0000946}
947
948cc_prebuilt_library_shared {
949 name: "mysdk_mysystemnativelib@current",
950 sdk_member_name: "mysystemnativelib",
951 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000952 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100953 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000954 arch: {
955 arm64: {
956 srcs: ["arm64/lib/mysystemnativelib.so"],
957 },
958 arm: {
959 srcs: ["arm/lib/mysystemnativelib.so"],
960 },
961 },
Paul Duffin13f02712020-03-06 12:30:43 +0000962}
963
964cc_prebuilt_library_shared {
965 name: "mysystemnativelib",
966 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000967 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +0100968 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000969 arch: {
970 arm64: {
971 srcs: ["arm64/lib/mysystemnativelib.so"],
972 },
973 arm: {
974 srcs: ["arm/lib/mysystemnativelib.so"],
975 },
976 },
Paul Duffin13f02712020-03-06 12:30:43 +0000977}
978
979sdk_snapshot {
980 name: "mysdk@current",
981 native_shared_libs: [
982 "mysdk_mynativelib@current",
983 "mysdk_myothernativelib@current",
984 "mysdk_mysystemnativelib@current",
985 ],
986}
987`),
988 checkAllCopyRules(`
989.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
990.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
991.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
992.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
993.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
994.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
995`),
996 )
997}
998
Paul Duffin9ab556f2019-12-11 18:42:17 +0000999func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +00001000 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +00001001 sdk {
1002 name: "mysdk",
1003 device_supported: false,
1004 host_supported: true,
1005 native_shared_libs: ["mynativelib"],
1006 }
1007
1008 cc_library_shared {
1009 name: "mynativelib",
1010 device_supported: false,
1011 host_supported: true,
1012 srcs: [
1013 "Test.cpp",
1014 "aidl/foo/bar/Test.aidl",
1015 ],
1016 export_include_dirs: ["include"],
1017 aidl: {
1018 export_aidl_headers: true,
1019 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001020 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +00001021 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +00001022 }
1023 `)
1024
Paul Duffin1356d8c2020-02-25 19:26:33 +00001025 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +00001026 checkAndroidBpContents(`
1027// This is auto-generated. DO NOT EDIT.
1028
1029cc_prebuilt_library_shared {
1030 name: "mysdk_mynativelib@current",
1031 sdk_member_name: "mynativelib",
1032 device_supported: false,
1033 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001034 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +00001035 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001036 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001037 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001038 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001039 arch: {
1040 x86_64: {
1041 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001042 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001043 },
1044 x86: {
1045 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001046 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001047 },
1048 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001049}
1050
1051cc_prebuilt_library_shared {
1052 name: "mynativelib",
1053 prefer: false,
1054 device_supported: false,
1055 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +00001056 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001057 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001058 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001059 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001060 arch: {
1061 x86_64: {
1062 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001063 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001064 },
1065 x86: {
1066 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001067 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001068 },
1069 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001070}
1071
1072sdk_snapshot {
1073 name: "mysdk@current",
1074 device_supported: false,
1075 host_supported: true,
1076 native_shared_libs: ["mysdk_mynativelib@current"],
1077}
1078`),
1079 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001080include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +00001081.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001082.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1083.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1084.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1085.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001086.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1087.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1088.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1089`),
1090 )
1091}
Paul Duffin9ab556f2019-12-11 18:42:17 +00001092
Paul Duffina04c1072020-03-02 10:16:35 +00001093func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00001094 result := testSdkWithCc(t, `
1095 sdk {
1096 name: "mysdk",
1097 device_supported: false,
1098 host_supported: true,
1099 native_shared_libs: ["mynativelib"],
1100 target: {
1101 windows: {
1102 enabled: true,
1103 },
1104 },
1105 }
1106
1107 cc_library_shared {
1108 name: "mynativelib",
1109 device_supported: false,
1110 host_supported: true,
1111 srcs: [
1112 "Test.cpp",
1113 ],
Paul Duffina04c1072020-03-02 10:16:35 +00001114 stl: "none",
1115 target: {
1116 windows: {
1117 enabled: true,
1118 },
1119 },
1120 }
1121 `)
1122
1123 result.CheckSnapshot("mysdk", "",
1124 checkAndroidBpContents(`
1125// This is auto-generated. DO NOT EDIT.
1126
1127cc_prebuilt_library_shared {
1128 name: "mysdk_mynativelib@current",
1129 sdk_member_name: "mynativelib",
1130 device_supported: false,
1131 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001132 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001133 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001134 target: {
Martin Stjernholm89238f42020-07-10 00:14:03 +01001135 linux_glibc: {
1136 compile_multilib: "both",
1137 },
Paul Duffina04c1072020-03-02 10:16:35 +00001138 linux_glibc_x86_64: {
1139 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1140 },
1141 linux_glibc_x86: {
1142 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1143 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001144 windows: {
1145 compile_multilib: "64",
1146 },
Paul Duffina04c1072020-03-02 10:16:35 +00001147 windows_x86_64: {
1148 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1149 },
1150 },
Paul Duffina04c1072020-03-02 10:16:35 +00001151}
1152
1153cc_prebuilt_library_shared {
1154 name: "mynativelib",
1155 prefer: false,
1156 device_supported: false,
1157 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001158 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001159 target: {
Martin Stjernholm89238f42020-07-10 00:14:03 +01001160 linux_glibc: {
1161 compile_multilib: "both",
1162 },
Paul Duffina04c1072020-03-02 10:16:35 +00001163 linux_glibc_x86_64: {
1164 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1165 },
1166 linux_glibc_x86: {
1167 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1168 },
Martin Stjernholm89238f42020-07-10 00:14:03 +01001169 windows: {
1170 compile_multilib: "64",
1171 },
Paul Duffina04c1072020-03-02 10:16:35 +00001172 windows_x86_64: {
1173 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1174 },
1175 },
Paul Duffina04c1072020-03-02 10:16:35 +00001176}
1177
1178sdk_snapshot {
1179 name: "mysdk@current",
1180 device_supported: false,
1181 host_supported: true,
1182 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +00001183 target: {
1184 windows: {
1185 compile_multilib: "64",
1186 },
1187 },
Paul Duffina04c1072020-03-02 10:16:35 +00001188}
1189`),
1190 checkAllCopyRules(`
1191.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1192.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1193.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1194`),
1195 )
1196}
1197
Paul Duffin9ab556f2019-12-11 18:42:17 +00001198func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1199 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001200 module_exports {
1201 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001202 native_static_libs: ["mynativelib"],
1203 }
1204
1205 cc_library_static {
1206 name: "mynativelib",
1207 srcs: [
1208 "Test.cpp",
1209 "aidl/foo/bar/Test.aidl",
1210 ],
1211 export_include_dirs: ["include"],
1212 aidl: {
1213 export_aidl_headers: true,
1214 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001215 stl: "none",
1216 }
1217 `)
1218
Paul Duffin1356d8c2020-02-25 19:26:33 +00001219 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001220 checkAndroidBpContents(`
1221// This is auto-generated. DO NOT EDIT.
1222
1223cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001224 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001225 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001226 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001227 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001228 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001229 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001230 arch: {
1231 arm64: {
1232 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001233 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001234 },
1235 arm: {
1236 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001237 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001238 },
1239 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001240}
1241
1242cc_prebuilt_library_static {
1243 name: "mynativelib",
1244 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001245 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001246 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001247 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001248 arch: {
1249 arm64: {
1250 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001251 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001252 },
1253 arm: {
1254 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001255 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001256 },
1257 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001258}
1259
Paul Duffine6029182019-12-16 17:43:48 +00001260module_exports_snapshot {
1261 name: "myexports@current",
1262 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001263}
1264`),
1265 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001266include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001267.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1268.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1269.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1270.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1271.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1272.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1273.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1274.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 +00001275`),
1276 )
1277}
1278
1279func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
Paul Duffin9ab556f2019-12-11 18:42:17 +00001280 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001281 module_exports {
1282 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001283 device_supported: false,
1284 host_supported: true,
1285 native_static_libs: ["mynativelib"],
1286 }
1287
1288 cc_library_static {
1289 name: "mynativelib",
1290 device_supported: false,
1291 host_supported: true,
1292 srcs: [
1293 "Test.cpp",
1294 "aidl/foo/bar/Test.aidl",
1295 ],
1296 export_include_dirs: ["include"],
1297 aidl: {
1298 export_aidl_headers: true,
1299 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001300 stl: "none",
1301 }
1302 `)
1303
Paul Duffin1356d8c2020-02-25 19:26:33 +00001304 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001305 checkAndroidBpContents(`
1306// This is auto-generated. DO NOT EDIT.
1307
1308cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001309 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001310 sdk_member_name: "mynativelib",
1311 device_supported: false,
1312 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001313 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001314 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001315 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001316 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001317 arch: {
1318 x86_64: {
1319 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001320 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001321 },
1322 x86: {
1323 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001324 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001325 },
1326 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001327}
1328
1329cc_prebuilt_library_static {
1330 name: "mynativelib",
1331 prefer: false,
1332 device_supported: false,
1333 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001334 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001335 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001336 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001337 arch: {
1338 x86_64: {
1339 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001340 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001341 },
1342 x86: {
1343 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001344 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001345 },
1346 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001347}
1348
Paul Duffine6029182019-12-16 17:43:48 +00001349module_exports_snapshot {
1350 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001351 device_supported: false,
1352 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001353 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001354}
1355`),
1356 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001357include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001358.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001359.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1360.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1361.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1362.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001363.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1364.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1365.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1366`),
1367 )
1368}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001369
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001370func TestSnapshotWithCcLibrary(t *testing.T) {
1371 result := testSdkWithCc(t, `
1372 module_exports {
1373 name: "myexports",
1374 native_libs: ["mynativelib"],
1375 }
1376
1377 cc_library {
1378 name: "mynativelib",
1379 srcs: [
1380 "Test.cpp",
1381 ],
1382 export_include_dirs: ["include"],
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001383 stl: "none",
1384 }
1385 `)
1386
1387 result.CheckSnapshot("myexports", "",
1388 checkAndroidBpContents(`
1389// This is auto-generated. DO NOT EDIT.
1390
1391cc_prebuilt_library {
1392 name: "myexports_mynativelib@current",
1393 sdk_member_name: "mynativelib",
1394 installable: false,
1395 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001396 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001397 export_include_dirs: ["include/include"],
1398 arch: {
1399 arm64: {
1400 static: {
1401 srcs: ["arm64/lib/mynativelib.a"],
1402 },
1403 shared: {
1404 srcs: ["arm64/lib/mynativelib.so"],
1405 },
1406 },
1407 arm: {
1408 static: {
1409 srcs: ["arm/lib/mynativelib.a"],
1410 },
1411 shared: {
1412 srcs: ["arm/lib/mynativelib.so"],
1413 },
1414 },
1415 },
1416}
1417
1418cc_prebuilt_library {
1419 name: "mynativelib",
1420 prefer: false,
1421 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001422 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001423 export_include_dirs: ["include/include"],
1424 arch: {
1425 arm64: {
1426 static: {
1427 srcs: ["arm64/lib/mynativelib.a"],
1428 },
1429 shared: {
1430 srcs: ["arm64/lib/mynativelib.so"],
1431 },
1432 },
1433 arm: {
1434 static: {
1435 srcs: ["arm/lib/mynativelib.a"],
1436 },
1437 shared: {
1438 srcs: ["arm/lib/mynativelib.so"],
1439 },
1440 },
1441 },
1442}
1443
1444module_exports_snapshot {
1445 name: "myexports@current",
1446 native_libs: ["myexports_mynativelib@current"],
1447}
1448`),
1449 checkAllCopyRules(`
1450include/Test.h -> include/include/Test.h
1451.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1452.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1453.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1454.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1455 )
1456}
1457
Paul Duffin13ad94f2020-02-19 16:19:27 +00001458func TestHostSnapshotWithMultiLib64(t *testing.T) {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001459 result := testSdkWithCc(t, `
1460 module_exports {
1461 name: "myexports",
1462 device_supported: false,
1463 host_supported: true,
1464 target: {
1465 host: {
1466 compile_multilib: "64",
1467 },
1468 },
1469 native_static_libs: ["mynativelib"],
1470 }
1471
1472 cc_library_static {
1473 name: "mynativelib",
1474 device_supported: false,
1475 host_supported: true,
1476 srcs: [
1477 "Test.cpp",
1478 "aidl/foo/bar/Test.aidl",
1479 ],
1480 export_include_dirs: ["include"],
1481 aidl: {
1482 export_aidl_headers: true,
1483 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001484 stl: "none",
1485 }
1486 `)
1487
Paul Duffin1356d8c2020-02-25 19:26:33 +00001488 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001489 checkAndroidBpContents(`
1490// This is auto-generated. DO NOT EDIT.
1491
1492cc_prebuilt_library_static {
1493 name: "myexports_mynativelib@current",
1494 sdk_member_name: "mynativelib",
1495 device_supported: false,
1496 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001497 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001498 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001499 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001500 export_include_dirs: ["include/include"],
1501 arch: {
1502 x86_64: {
1503 srcs: ["x86_64/lib/mynativelib.a"],
1504 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1505 },
1506 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001507}
1508
1509cc_prebuilt_library_static {
1510 name: "mynativelib",
1511 prefer: false,
1512 device_supported: false,
1513 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001514 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001515 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001516 export_include_dirs: ["include/include"],
1517 arch: {
1518 x86_64: {
1519 srcs: ["x86_64/lib/mynativelib.a"],
1520 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1521 },
1522 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001523}
1524
1525module_exports_snapshot {
1526 name: "myexports@current",
1527 device_supported: false,
1528 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001529 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin13ad94f2020-02-19 16:19:27 +00001530 target: {
Paul Duffin6a7e9532020-03-20 17:50:07 +00001531 linux_glibc: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001532 compile_multilib: "64",
1533 },
1534 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001535}`),
1536 checkAllCopyRules(`
1537include/Test.h -> include/include/Test.h
1538.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1539.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1540.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1541.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1542`),
1543 )
1544}
Paul Duffin91756d22020-02-21 16:29:57 +00001545
1546func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1547 result := testSdkWithCc(t, `
1548 sdk {
1549 name: "mysdk",
1550 native_header_libs: ["mynativeheaders"],
1551 }
1552
1553 cc_library_headers {
1554 name: "mynativeheaders",
1555 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001556 stl: "none",
1557 }
1558 `)
1559
Paul Duffin1356d8c2020-02-25 19:26:33 +00001560 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001561 checkAndroidBpContents(`
1562// This is auto-generated. DO NOT EDIT.
1563
1564cc_prebuilt_library_headers {
1565 name: "mysdk_mynativeheaders@current",
1566 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001567 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001568 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001569 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001570}
1571
1572cc_prebuilt_library_headers {
1573 name: "mynativeheaders",
1574 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001575 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001576 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001577 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001578}
1579
1580sdk_snapshot {
1581 name: "mysdk@current",
1582 native_header_libs: ["mysdk_mynativeheaders@current"],
1583}
1584`),
1585 checkAllCopyRules(`
1586include/Test.h -> include/include/Test.h
1587`),
1588 )
1589}
1590
1591func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffin91756d22020-02-21 16:29:57 +00001592 result := testSdkWithCc(t, `
1593 sdk {
1594 name: "mysdk",
1595 device_supported: false,
1596 host_supported: true,
1597 native_header_libs: ["mynativeheaders"],
1598 }
1599
1600 cc_library_headers {
1601 name: "mynativeheaders",
1602 device_supported: false,
1603 host_supported: true,
1604 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001605 stl: "none",
1606 }
1607 `)
1608
Paul Duffin1356d8c2020-02-25 19:26:33 +00001609 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001610 checkAndroidBpContents(`
1611// This is auto-generated. DO NOT EDIT.
1612
1613cc_prebuilt_library_headers {
1614 name: "mysdk_mynativeheaders@current",
1615 sdk_member_name: "mynativeheaders",
1616 device_supported: false,
1617 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001618 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001619 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001620 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001621}
1622
1623cc_prebuilt_library_headers {
1624 name: "mynativeheaders",
1625 prefer: false,
1626 device_supported: false,
1627 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001628 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001629 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001630 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001631}
1632
1633sdk_snapshot {
1634 name: "mysdk@current",
1635 device_supported: false,
1636 host_supported: true,
1637 native_header_libs: ["mysdk_mynativeheaders@current"],
1638}
1639`),
1640 checkAllCopyRules(`
1641include/Test.h -> include/include/Test.h
1642`),
1643 )
1644}
Paul Duffina04c1072020-03-02 10:16:35 +00001645
1646func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
Paul Duffina04c1072020-03-02 10:16:35 +00001647 result := testSdkWithCc(t, `
1648 sdk {
1649 name: "mysdk",
1650 host_supported: true,
1651 native_header_libs: ["mynativeheaders"],
1652 }
1653
1654 cc_library_headers {
1655 name: "mynativeheaders",
1656 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00001657 stl: "none",
1658 export_system_include_dirs: ["include"],
1659 target: {
1660 android: {
1661 export_include_dirs: ["include-android"],
1662 },
1663 host: {
1664 export_include_dirs: ["include-host"],
1665 },
1666 },
1667 }
1668 `)
1669
1670 result.CheckSnapshot("mysdk", "",
1671 checkAndroidBpContents(`
1672// This is auto-generated. DO NOT EDIT.
1673
1674cc_prebuilt_library_headers {
1675 name: "mysdk_mynativeheaders@current",
1676 sdk_member_name: "mynativeheaders",
1677 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001678 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001679 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01001680 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00001681 target: {
1682 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001683 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00001684 },
1685 linux_glibc: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001686 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00001687 },
1688 },
Paul Duffina04c1072020-03-02 10:16:35 +00001689}
1690
1691cc_prebuilt_library_headers {
1692 name: "mynativeheaders",
1693 prefer: false,
1694 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001695 stl: "none",
Martin Stjernholm89238f42020-07-10 00:14:03 +01001696 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01001697 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00001698 target: {
1699 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001700 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00001701 },
1702 linux_glibc: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001703 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00001704 },
1705 },
Paul Duffina04c1072020-03-02 10:16:35 +00001706}
1707
1708sdk_snapshot {
1709 name: "mysdk@current",
1710 host_supported: true,
1711 native_header_libs: ["mysdk_mynativeheaders@current"],
1712}
1713`),
1714 checkAllCopyRules(`
Paul Duffined62b9c2020-06-16 16:12:50 +01001715include/Test.h -> common_os/include/include/Test.h
1716include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
1717include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
Paul Duffina04c1072020-03-02 10:16:35 +00001718`),
1719 )
1720}
Martin Stjernholm10566a02020-03-24 01:19:52 +00001721
1722func TestSystemSharedLibPropagation(t *testing.T) {
1723 result := testSdkWithCc(t, `
1724 sdk {
1725 name: "mysdk",
1726 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
1727 }
1728
1729 cc_library {
1730 name: "sslnil",
1731 host_supported: true,
1732 }
1733
1734 cc_library {
1735 name: "sslempty",
1736 system_shared_libs: [],
1737 }
1738
1739 cc_library {
1740 name: "sslnonempty",
1741 system_shared_libs: ["sslnil"],
1742 }
1743 `)
1744
1745 result.CheckSnapshot("mysdk", "",
1746 checkAndroidBpContents(`
1747// This is auto-generated. DO NOT EDIT.
1748
1749cc_prebuilt_library_shared {
1750 name: "mysdk_sslnil@current",
1751 sdk_member_name: "sslnil",
1752 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001753 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001754 arch: {
1755 arm64: {
1756 srcs: ["arm64/lib/sslnil.so"],
1757 },
1758 arm: {
1759 srcs: ["arm/lib/sslnil.so"],
1760 },
1761 },
1762}
1763
1764cc_prebuilt_library_shared {
1765 name: "sslnil",
1766 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001767 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001768 arch: {
1769 arm64: {
1770 srcs: ["arm64/lib/sslnil.so"],
1771 },
1772 arm: {
1773 srcs: ["arm/lib/sslnil.so"],
1774 },
1775 },
1776}
1777
1778cc_prebuilt_library_shared {
1779 name: "mysdk_sslempty@current",
1780 sdk_member_name: "sslempty",
1781 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001782 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001783 system_shared_libs: [],
1784 arch: {
1785 arm64: {
1786 srcs: ["arm64/lib/sslempty.so"],
1787 },
1788 arm: {
1789 srcs: ["arm/lib/sslempty.so"],
1790 },
1791 },
1792}
1793
1794cc_prebuilt_library_shared {
1795 name: "sslempty",
1796 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001797 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001798 system_shared_libs: [],
1799 arch: {
1800 arm64: {
1801 srcs: ["arm64/lib/sslempty.so"],
1802 },
1803 arm: {
1804 srcs: ["arm/lib/sslempty.so"],
1805 },
1806 },
1807}
1808
1809cc_prebuilt_library_shared {
1810 name: "mysdk_sslnonempty@current",
1811 sdk_member_name: "sslnonempty",
1812 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001813 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001814 system_shared_libs: ["mysdk_sslnil@current"],
1815 arch: {
1816 arm64: {
1817 srcs: ["arm64/lib/sslnonempty.so"],
1818 },
1819 arm: {
1820 srcs: ["arm/lib/sslnonempty.so"],
1821 },
1822 },
1823}
1824
1825cc_prebuilt_library_shared {
1826 name: "sslnonempty",
1827 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001828 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001829 system_shared_libs: ["sslnil"],
1830 arch: {
1831 arm64: {
1832 srcs: ["arm64/lib/sslnonempty.so"],
1833 },
1834 arm: {
1835 srcs: ["arm/lib/sslnonempty.so"],
1836 },
1837 },
1838}
1839
1840sdk_snapshot {
1841 name: "mysdk@current",
1842 native_shared_libs: [
1843 "mysdk_sslnil@current",
1844 "mysdk_sslempty@current",
1845 "mysdk_sslnonempty@current",
1846 ],
1847}
1848`))
1849
1850 result = testSdkWithCc(t, `
1851 sdk {
1852 name: "mysdk",
1853 host_supported: true,
1854 native_shared_libs: ["sslvariants"],
1855 }
1856
1857 cc_library {
1858 name: "sslvariants",
1859 host_supported: true,
1860 target: {
1861 android: {
1862 system_shared_libs: [],
1863 },
1864 },
1865 }
1866 `)
1867
1868 result.CheckSnapshot("mysdk", "",
1869 checkAndroidBpContents(`
1870// This is auto-generated. DO NOT EDIT.
1871
1872cc_prebuilt_library_shared {
1873 name: "mysdk_sslvariants@current",
1874 sdk_member_name: "sslvariants",
1875 host_supported: true,
1876 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001877 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001878 target: {
1879 android: {
1880 system_shared_libs: [],
1881 },
1882 android_arm64: {
1883 srcs: ["android/arm64/lib/sslvariants.so"],
1884 },
1885 android_arm: {
1886 srcs: ["android/arm/lib/sslvariants.so"],
1887 },
1888 linux_glibc_x86_64: {
1889 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1890 },
1891 linux_glibc_x86: {
1892 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1893 },
1894 },
1895}
1896
1897cc_prebuilt_library_shared {
1898 name: "sslvariants",
1899 prefer: false,
1900 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001901 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001902 target: {
1903 android: {
1904 system_shared_libs: [],
1905 },
1906 android_arm64: {
1907 srcs: ["android/arm64/lib/sslvariants.so"],
1908 },
1909 android_arm: {
1910 srcs: ["android/arm/lib/sslvariants.so"],
1911 },
1912 linux_glibc_x86_64: {
1913 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1914 },
1915 linux_glibc_x86: {
1916 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1917 },
1918 },
1919}
1920
1921sdk_snapshot {
1922 name: "mysdk@current",
1923 host_supported: true,
1924 native_shared_libs: ["mysdk_sslvariants@current"],
1925}
1926`))
1927}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001928
1929func TestStubsLibrary(t *testing.T) {
1930 result := testSdkWithCc(t, `
1931 sdk {
1932 name: "mysdk",
1933 native_shared_libs: ["stubslib"],
1934 }
1935
1936 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001937 name: "internaldep",
1938 }
1939
1940 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001941 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001942 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001943 stubs: {
1944 symbol_file: "some/where/stubslib.map.txt",
1945 versions: ["1", "2", "3"],
1946 },
1947 }
1948 `)
1949
1950 result.CheckSnapshot("mysdk", "",
1951 checkAndroidBpContents(`
1952// This is auto-generated. DO NOT EDIT.
1953
1954cc_prebuilt_library_shared {
1955 name: "mysdk_stubslib@current",
1956 sdk_member_name: "stubslib",
1957 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001958 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001959 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001960 versions: ["3"],
1961 },
1962 arch: {
1963 arm64: {
1964 srcs: ["arm64/lib/stubslib.so"],
1965 },
1966 arm: {
1967 srcs: ["arm/lib/stubslib.so"],
1968 },
1969 },
1970}
1971
1972cc_prebuilt_library_shared {
1973 name: "stubslib",
1974 prefer: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01001975 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001976 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001977 versions: ["3"],
1978 },
1979 arch: {
1980 arm64: {
1981 srcs: ["arm64/lib/stubslib.so"],
1982 },
1983 arm: {
1984 srcs: ["arm/lib/stubslib.so"],
1985 },
1986 },
1987}
1988
1989sdk_snapshot {
1990 name: "mysdk@current",
1991 native_shared_libs: ["mysdk_stubslib@current"],
1992}
1993`))
1994}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01001995
1996func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
Paul Duffin7a1f7f32020-05-04 15:32:08 +01001997 result := testSdkWithCc(t, `
1998 sdk {
1999 name: "mysdk",
2000 host_supported: true,
2001 native_shared_libs: ["stubslib"],
2002 }
2003
2004 cc_library {
2005 name: "internaldep",
2006 host_supported: true,
2007 }
2008
2009 cc_library {
2010 name: "stubslib",
2011 host_supported: true,
2012 shared_libs: ["internaldep"],
2013 stubs: {
2014 symbol_file: "some/where/stubslib.map.txt",
2015 versions: ["1", "2", "3"],
2016 },
2017 }
2018 `)
2019
2020 result.CheckSnapshot("mysdk", "",
2021 checkAndroidBpContents(`
2022// This is auto-generated. DO NOT EDIT.
2023
2024cc_prebuilt_library_shared {
2025 name: "mysdk_stubslib@current",
2026 sdk_member_name: "stubslib",
2027 host_supported: true,
2028 installable: false,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002029 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002030 stubs: {
2031 versions: ["3"],
2032 },
2033 target: {
2034 android_arm64: {
2035 srcs: ["android/arm64/lib/stubslib.so"],
2036 },
2037 android_arm: {
2038 srcs: ["android/arm/lib/stubslib.so"],
2039 },
2040 linux_glibc_x86_64: {
2041 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2042 },
2043 linux_glibc_x86: {
2044 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2045 },
2046 },
2047}
2048
2049cc_prebuilt_library_shared {
2050 name: "stubslib",
2051 prefer: false,
2052 host_supported: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002053 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002054 stubs: {
2055 versions: ["3"],
2056 },
2057 target: {
2058 android_arm64: {
2059 srcs: ["android/arm64/lib/stubslib.so"],
2060 },
2061 android_arm: {
2062 srcs: ["android/arm/lib/stubslib.so"],
2063 },
2064 linux_glibc_x86_64: {
2065 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2066 },
2067 linux_glibc_x86: {
2068 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2069 },
2070 },
2071}
2072
2073sdk_snapshot {
2074 name: "mysdk@current",
2075 host_supported: true,
2076 native_shared_libs: ["mysdk_stubslib@current"],
2077}
2078`))
2079}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002080
2081func TestUniqueHostSoname(t *testing.T) {
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002082 result := testSdkWithCc(t, `
2083 sdk {
2084 name: "mysdk",
2085 host_supported: true,
2086 native_shared_libs: ["mylib"],
2087 }
2088
2089 cc_library {
2090 name: "mylib",
2091 host_supported: true,
2092 unique_host_soname: true,
2093 }
2094 `)
2095
2096 result.CheckSnapshot("mysdk", "",
2097 checkAndroidBpContents(`
2098// This is auto-generated. DO NOT EDIT.
2099
2100cc_prebuilt_library_shared {
2101 name: "mysdk_mylib@current",
2102 sdk_member_name: "mylib",
2103 host_supported: true,
2104 installable: false,
2105 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002106 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002107 target: {
2108 android_arm64: {
2109 srcs: ["android/arm64/lib/mylib.so"],
2110 },
2111 android_arm: {
2112 srcs: ["android/arm/lib/mylib.so"],
2113 },
2114 linux_glibc_x86_64: {
2115 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2116 },
2117 linux_glibc_x86: {
2118 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2119 },
2120 },
2121}
2122
2123cc_prebuilt_library_shared {
2124 name: "mylib",
2125 prefer: false,
2126 host_supported: true,
2127 unique_host_soname: true,
Martin Stjernholm89238f42020-07-10 00:14:03 +01002128 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002129 target: {
2130 android_arm64: {
2131 srcs: ["android/arm64/lib/mylib.so"],
2132 },
2133 android_arm: {
2134 srcs: ["android/arm/lib/mylib.so"],
2135 },
2136 linux_glibc_x86_64: {
2137 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2138 },
2139 linux_glibc_x86: {
2140 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2141 },
2142 },
2143}
2144
2145sdk_snapshot {
2146 name: "mysdk@current",
2147 host_supported: true,
2148 native_shared_libs: ["mysdk_mylib@current"],
2149}
2150`),
2151 checkAllCopyRules(`
2152.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2153.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2154.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2155.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2156`),
2157 )
2158}