blob: 25d2a86a0e648e8a0b9466dda3adac282a57c718 [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,
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +010035 "some/where/stubslib.map.txt": nil,
Paul Duffind835daa2019-11-30 17:49:09 +000036 }
37 return testSdkWithFs(t, bp, fs)
38}
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 Stjernholm1e9c2672020-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 Stjernholm1e9c2672020-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 Stjernholm1e9c2672020-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 Stjernholm1e9c2672020-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 Stjernholm1e9c2672020-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 Stjernholm1e9c2672020-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 Stjernholm1e9c2672020-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 Stjernholm1e9c2672020-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) {
536 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
537 SkipIfNotLinux(t)
538
539 result := testSdkWithCc(t, `
540 module_exports {
541 name: "myexports",
542 device_supported: false,
543 host_supported: true,
544 native_binaries: ["mynativebinary"],
545 target: {
546 windows: {
547 enabled: true,
548 },
549 },
550 }
551
552 cc_binary {
553 name: "mynativebinary",
554 device_supported: false,
555 host_supported: true,
556 srcs: [
557 "Test.cpp",
558 ],
559 compile_multilib: "both",
Paul Duffina04c1072020-03-02 10:16:35 +0000560 stl: "none",
561 target: {
562 windows: {
563 enabled: true,
564 },
565 },
566 }
567 `)
568
569 result.CheckSnapshot("myexports", "",
570 checkAndroidBpContents(`
571// This is auto-generated. DO NOT EDIT.
572
573cc_prebuilt_binary {
574 name: "myexports_mynativebinary@current",
575 sdk_member_name: "mynativebinary",
576 device_supported: false,
577 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +0000578 installable: false,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100579 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000580 target: {
581 linux_glibc: {
582 compile_multilib: "both",
583 },
584 linux_glibc_x86_64: {
585 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
586 },
587 linux_glibc_x86: {
588 srcs: ["linux_glibc/x86/bin/mynativebinary"],
589 },
590 windows: {
591 compile_multilib: "64",
592 },
593 windows_x86_64: {
594 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
595 },
596 },
597}
598
599cc_prebuilt_binary {
600 name: "mynativebinary",
601 prefer: false,
602 device_supported: false,
603 host_supported: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100604 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +0000605 target: {
606 linux_glibc: {
607 compile_multilib: "both",
608 },
609 linux_glibc_x86_64: {
610 srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
611 },
612 linux_glibc_x86: {
613 srcs: ["linux_glibc/x86/bin/mynativebinary"],
614 },
615 windows: {
616 compile_multilib: "64",
617 },
618 windows_x86_64: {
619 srcs: ["windows/x86_64/bin/mynativebinary.exe"],
620 },
621 },
622}
623
624module_exports_snapshot {
625 name: "myexports@current",
626 device_supported: false,
627 host_supported: true,
628 native_binaries: ["myexports_mynativebinary@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +0000629 target: {
630 windows: {
631 compile_multilib: "64",
632 },
633 },
Paul Duffina04c1072020-03-02 10:16:35 +0000634}
635`),
636 checkAllCopyRules(`
637.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
638.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
639.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
640`),
641 )
642}
643
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100644// Test that we support the necessary flags for the linker binary, which is
645// special in several ways.
646func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
647 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
648 SkipIfNotLinux(t)
649
650 result := testSdkWithCc(t, `
651 module_exports {
652 name: "mymodule_exports",
653 host_supported: true,
654 device_supported: false,
655 native_binaries: ["linker"],
656 }
657
658 cc_binary {
659 name: "linker",
660 host_supported: true,
661 static_executable: true,
662 nocrt: true,
663 stl: "none",
664 srcs: [
665 "Test.cpp",
666 ],
667 compile_multilib: "both",
668 }
669 `)
670
671 result.CheckSnapshot("mymodule_exports", "",
672 checkAndroidBpContents(`
673// This is auto-generated. DO NOT EDIT.
674
675cc_prebuilt_binary {
676 name: "mymodule_exports_linker@current",
677 sdk_member_name: "linker",
678 device_supported: false,
679 host_supported: true,
680 installable: false,
681 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100682 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100683 static_executable: true,
684 nocrt: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100685 arch: {
686 x86_64: {
687 srcs: ["x86_64/bin/linker"],
688 },
689 x86: {
690 srcs: ["x86/bin/linker"],
691 },
692 },
693}
694
695cc_prebuilt_binary {
696 name: "linker",
697 prefer: false,
698 device_supported: false,
699 host_supported: true,
700 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100701 compile_multilib: "both",
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100702 static_executable: true,
703 nocrt: true,
Martin Stjernholm7130fab2020-05-28 22:58:01 +0100704 arch: {
705 x86_64: {
706 srcs: ["x86_64/bin/linker"],
707 },
708 x86: {
709 srcs: ["x86/bin/linker"],
710 },
711 },
712}
713
714module_exports_snapshot {
715 name: "mymodule_exports@current",
716 device_supported: false,
717 host_supported: true,
718 native_binaries: ["mymodule_exports_linker@current"],
719}
720`),
721 checkAllCopyRules(`
722.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
723.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
724`),
725 )
726}
727
Paul Duffin9ab556f2019-12-11 18:42:17 +0000728func TestSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffind835daa2019-11-30 17:49:09 +0000729 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +0000730 sdk {
731 name: "mysdk",
732 native_shared_libs: ["mynativelib"],
733 }
734
735 cc_library_shared {
736 name: "mynativelib",
737 srcs: [
738 "Test.cpp",
739 "aidl/foo/bar/Test.aidl",
740 ],
Paul Duffinbefa4b92020-03-04 14:22:45 +0000741 apex_available: ["apex1", "apex2"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000742 export_include_dirs: ["include"],
743 aidl: {
744 export_aidl_headers: true,
745 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000746 stl: "none",
747 }
748 `)
749
Paul Duffin1356d8c2020-02-25 19:26:33 +0000750 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +0000751 checkAndroidBpContents(`
752// This is auto-generated. DO NOT EDIT.
753
754cc_prebuilt_library_shared {
755 name: "mysdk_mynativelib@current",
756 sdk_member_name: "mynativelib",
Paul Duffinbefa4b92020-03-04 14:22:45 +0000757 apex_available: [
758 "apex1",
759 "apex2",
760 ],
Paul Duffin0cb37b92020-03-04 14:52:46 +0000761 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000762 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100763 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000764 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000765 arch: {
766 arm64: {
767 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000768 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000769 },
770 arm: {
771 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000772 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000773 },
774 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000775}
776
777cc_prebuilt_library_shared {
778 name: "mynativelib",
779 prefer: false,
Paul Duffinbefa4b92020-03-04 14:22:45 +0000780 apex_available: [
781 "apex1",
782 "apex2",
783 ],
Paul Duffin0174d8d2020-03-11 18:42:08 +0000784 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100785 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000786 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000787 arch: {
788 arm64: {
789 srcs: ["arm64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000790 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000791 },
792 arm: {
793 srcs: ["arm/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000794 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +0000795 },
796 },
Paul Duffina80fdec2019-12-03 15:25:00 +0000797}
798
799sdk_snapshot {
800 name: "mysdk@current",
801 native_shared_libs: ["mysdk_mynativelib@current"],
802}
803`),
804 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +0000805include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -0800806.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
807.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
808.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
809.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
810.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
811.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
812.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
813.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 +0000814`),
815 )
816}
817
Paul Duffin13f02712020-03-06 12:30:43 +0000818func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
819 result := testSdkWithCc(t, `
820 sdk {
821 name: "mysdk",
822 native_shared_libs: [
823 "mynativelib",
824 "myothernativelib",
825 "mysystemnativelib",
826 ],
827 }
828
829 cc_library {
830 name: "mysystemnativelib",
831 srcs: [
832 "Test.cpp",
833 ],
Paul Duffin13f02712020-03-06 12:30:43 +0000834 stl: "none",
835 }
836
837 cc_library_shared {
838 name: "myothernativelib",
839 srcs: [
840 "Test.cpp",
841 ],
842 system_shared_libs: [
843 // A reference to a library that is not an sdk member. Uses libm as that
844 // is in the default set of modules available to this test and so is available
845 // both here and also when the generated Android.bp file is tested in
846 // CheckSnapshot(). This ensures that the system_shared_libs property correctly
847 // handles references to modules that are not sdk members.
848 "libm",
849 ],
850 stl: "none",
851 }
852
853 cc_library {
854 name: "mynativelib",
855 srcs: [
856 "Test.cpp",
857 ],
858 shared_libs: [
859 // A reference to another sdk member.
860 "myothernativelib",
861 ],
862 target: {
863 android: {
864 shared: {
865 shared_libs: [
866 // A reference to a library that is not an sdk member. The libc library
867 // is used here to check that the shared_libs property is handled correctly
868 // in a similar way to how libm is used to check system_shared_libs above.
869 "libc",
870 ],
871 },
872 },
873 },
Paul Duffin13f02712020-03-06 12:30:43 +0000874 stl: "none",
875 }
876 `)
877
878 result.CheckSnapshot("mysdk", "",
879 checkAndroidBpContents(`
880// This is auto-generated. DO NOT EDIT.
881
882cc_prebuilt_library_shared {
883 name: "mysdk_mynativelib@current",
884 sdk_member_name: "mynativelib",
885 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000886 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100887 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000888 shared_libs: [
889 "mysdk_myothernativelib@current",
890 "libc",
891 ],
892 arch: {
893 arm64: {
894 srcs: ["arm64/lib/mynativelib.so"],
895 },
896 arm: {
897 srcs: ["arm/lib/mynativelib.so"],
898 },
899 },
Paul Duffin13f02712020-03-06 12:30:43 +0000900}
901
902cc_prebuilt_library_shared {
903 name: "mynativelib",
904 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000905 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100906 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000907 shared_libs: [
908 "myothernativelib",
909 "libc",
910 ],
911 arch: {
912 arm64: {
913 srcs: ["arm64/lib/mynativelib.so"],
914 },
915 arm: {
916 srcs: ["arm/lib/mynativelib.so"],
917 },
918 },
Paul Duffin13f02712020-03-06 12:30:43 +0000919}
920
921cc_prebuilt_library_shared {
922 name: "mysdk_myothernativelib@current",
923 sdk_member_name: "myothernativelib",
924 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000925 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100926 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000927 system_shared_libs: ["libm"],
928 arch: {
929 arm64: {
930 srcs: ["arm64/lib/myothernativelib.so"],
931 },
932 arm: {
933 srcs: ["arm/lib/myothernativelib.so"],
934 },
935 },
Paul Duffin13f02712020-03-06 12:30:43 +0000936}
937
938cc_prebuilt_library_shared {
939 name: "myothernativelib",
940 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000941 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100942 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000943 system_shared_libs: ["libm"],
944 arch: {
945 arm64: {
946 srcs: ["arm64/lib/myothernativelib.so"],
947 },
948 arm: {
949 srcs: ["arm/lib/myothernativelib.so"],
950 },
951 },
Paul Duffin13f02712020-03-06 12:30:43 +0000952}
953
954cc_prebuilt_library_shared {
955 name: "mysdk_mysystemnativelib@current",
956 sdk_member_name: "mysystemnativelib",
957 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000958 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100959 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000960 arch: {
961 arm64: {
962 srcs: ["arm64/lib/mysystemnativelib.so"],
963 },
964 arm: {
965 srcs: ["arm/lib/mysystemnativelib.so"],
966 },
967 },
Paul Duffin13f02712020-03-06 12:30:43 +0000968}
969
970cc_prebuilt_library_shared {
971 name: "mysystemnativelib",
972 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +0000973 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +0100974 compile_multilib: "both",
Paul Duffin13f02712020-03-06 12:30:43 +0000975 arch: {
976 arm64: {
977 srcs: ["arm64/lib/mysystemnativelib.so"],
978 },
979 arm: {
980 srcs: ["arm/lib/mysystemnativelib.so"],
981 },
982 },
Paul Duffin13f02712020-03-06 12:30:43 +0000983}
984
985sdk_snapshot {
986 name: "mysdk@current",
987 native_shared_libs: [
988 "mysdk_mynativelib@current",
989 "mysdk_myothernativelib@current",
990 "mysdk_mysystemnativelib@current",
991 ],
992}
993`),
994 checkAllCopyRules(`
995.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
996.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
997.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
998.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
999.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
1000.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
1001`),
1002 )
1003}
1004
Paul Duffin9ab556f2019-12-11 18:42:17 +00001005func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
Paul Duffina80fdec2019-12-03 15:25:00 +00001006 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1007 SkipIfNotLinux(t)
1008
Paul Duffind835daa2019-11-30 17:49:09 +00001009 result := testSdkWithCc(t, `
Paul Duffina80fdec2019-12-03 15:25:00 +00001010 sdk {
1011 name: "mysdk",
1012 device_supported: false,
1013 host_supported: true,
1014 native_shared_libs: ["mynativelib"],
1015 }
1016
1017 cc_library_shared {
1018 name: "mynativelib",
1019 device_supported: false,
1020 host_supported: true,
1021 srcs: [
1022 "Test.cpp",
1023 "aidl/foo/bar/Test.aidl",
1024 ],
1025 export_include_dirs: ["include"],
1026 aidl: {
1027 export_aidl_headers: true,
1028 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001029 stl: "none",
Paul Duffin0c394f32020-03-05 14:09:58 +00001030 sdk_version: "minimum",
Paul Duffina80fdec2019-12-03 15:25:00 +00001031 }
1032 `)
1033
Paul Duffin1356d8c2020-02-25 19:26:33 +00001034 result.CheckSnapshot("mysdk", "",
Paul Duffina80fdec2019-12-03 15:25:00 +00001035 checkAndroidBpContents(`
1036// This is auto-generated. DO NOT EDIT.
1037
1038cc_prebuilt_library_shared {
1039 name: "mysdk_mynativelib@current",
1040 sdk_member_name: "mynativelib",
1041 device_supported: false,
1042 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001043 installable: false,
Paul Duffin0c394f32020-03-05 14:09:58 +00001044 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001045 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001046 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001047 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001048 arch: {
1049 x86_64: {
1050 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001051 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001052 },
1053 x86: {
1054 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001055 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001056 },
1057 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001058}
1059
1060cc_prebuilt_library_shared {
1061 name: "mynativelib",
1062 prefer: false,
1063 device_supported: false,
1064 host_supported: true,
Paul Duffin0c394f32020-03-05 14:09:58 +00001065 sdk_version: "minimum",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001066 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001067 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001068 export_include_dirs: ["include/include"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001069 arch: {
1070 x86_64: {
1071 srcs: ["x86_64/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001072 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001073 },
1074 x86: {
1075 srcs: ["x86/lib/mynativelib.so"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001076 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffina80fdec2019-12-03 15:25:00 +00001077 },
1078 },
Paul Duffina80fdec2019-12-03 15:25:00 +00001079}
1080
1081sdk_snapshot {
1082 name: "mysdk@current",
1083 device_supported: false,
1084 host_supported: true,
1085 native_shared_libs: ["mysdk_mynativelib@current"],
1086}
1087`),
1088 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001089include/Test.h -> include/include/Test.h
Paul Duffina80fdec2019-12-03 15:25:00 +00001090.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001091.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1092.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1093.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1094.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
Paul Duffina80fdec2019-12-03 15:25:00 +00001095.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1096.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1097.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1098`),
1099 )
1100}
Paul Duffin9ab556f2019-12-11 18:42:17 +00001101
Paul Duffina04c1072020-03-02 10:16:35 +00001102func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
1103 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1104 SkipIfNotLinux(t)
1105
1106 result := testSdkWithCc(t, `
1107 sdk {
1108 name: "mysdk",
1109 device_supported: false,
1110 host_supported: true,
1111 native_shared_libs: ["mynativelib"],
1112 target: {
1113 windows: {
1114 enabled: true,
1115 },
1116 },
1117 }
1118
1119 cc_library_shared {
1120 name: "mynativelib",
1121 device_supported: false,
1122 host_supported: true,
1123 srcs: [
1124 "Test.cpp",
1125 ],
Paul Duffina04c1072020-03-02 10:16:35 +00001126 stl: "none",
1127 target: {
1128 windows: {
1129 enabled: true,
1130 },
1131 },
1132 }
1133 `)
1134
1135 result.CheckSnapshot("mysdk", "",
1136 checkAndroidBpContents(`
1137// This is auto-generated. DO NOT EDIT.
1138
1139cc_prebuilt_library_shared {
1140 name: "mysdk_mynativelib@current",
1141 sdk_member_name: "mynativelib",
1142 device_supported: false,
1143 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001144 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001145 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001146 target: {
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001147 linux_glibc: {
1148 compile_multilib: "both",
1149 },
Paul Duffina04c1072020-03-02 10:16:35 +00001150 linux_glibc_x86_64: {
1151 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1152 },
1153 linux_glibc_x86: {
1154 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1155 },
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001156 windows: {
1157 compile_multilib: "64",
1158 },
Paul Duffina04c1072020-03-02 10:16:35 +00001159 windows_x86_64: {
1160 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1161 },
1162 },
Paul Duffina04c1072020-03-02 10:16:35 +00001163}
1164
1165cc_prebuilt_library_shared {
1166 name: "mynativelib",
1167 prefer: false,
1168 device_supported: false,
1169 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001170 stl: "none",
Paul Duffina04c1072020-03-02 10:16:35 +00001171 target: {
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001172 linux_glibc: {
1173 compile_multilib: "both",
1174 },
Paul Duffina04c1072020-03-02 10:16:35 +00001175 linux_glibc_x86_64: {
1176 srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1177 },
1178 linux_glibc_x86: {
1179 srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1180 },
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001181 windows: {
1182 compile_multilib: "64",
1183 },
Paul Duffina04c1072020-03-02 10:16:35 +00001184 windows_x86_64: {
1185 srcs: ["windows/x86_64/lib/mynativelib.dll"],
1186 },
1187 },
Paul Duffina04c1072020-03-02 10:16:35 +00001188}
1189
1190sdk_snapshot {
1191 name: "mysdk@current",
1192 device_supported: false,
1193 host_supported: true,
1194 native_shared_libs: ["mysdk_mynativelib@current"],
Paul Duffin6a7e9532020-03-20 17:50:07 +00001195 target: {
1196 windows: {
1197 compile_multilib: "64",
1198 },
1199 },
Paul Duffina04c1072020-03-02 10:16:35 +00001200}
1201`),
1202 checkAllCopyRules(`
1203.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1204.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1205.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1206`),
1207 )
1208}
1209
Paul Duffin9ab556f2019-12-11 18:42:17 +00001210func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1211 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001212 module_exports {
1213 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001214 native_static_libs: ["mynativelib"],
1215 }
1216
1217 cc_library_static {
1218 name: "mynativelib",
1219 srcs: [
1220 "Test.cpp",
1221 "aidl/foo/bar/Test.aidl",
1222 ],
1223 export_include_dirs: ["include"],
1224 aidl: {
1225 export_aidl_headers: true,
1226 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001227 stl: "none",
1228 }
1229 `)
1230
Paul Duffin1356d8c2020-02-25 19:26:33 +00001231 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001232 checkAndroidBpContents(`
1233// This is auto-generated. DO NOT EDIT.
1234
1235cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001236 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001237 sdk_member_name: "mynativelib",
Paul Duffin0cb37b92020-03-04 14:52:46 +00001238 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001239 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001240 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001241 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001242 arch: {
1243 arm64: {
1244 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001245 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001246 },
1247 arm: {
1248 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001249 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001250 },
1251 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001252}
1253
1254cc_prebuilt_library_static {
1255 name: "mynativelib",
1256 prefer: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001257 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001258 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001259 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001260 arch: {
1261 arm64: {
1262 srcs: ["arm64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001263 export_include_dirs: ["arm64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001264 },
1265 arm: {
1266 srcs: ["arm/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001267 export_include_dirs: ["arm/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001268 },
1269 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001270}
1271
Paul Duffine6029182019-12-16 17:43:48 +00001272module_exports_snapshot {
1273 name: "myexports@current",
1274 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001275}
1276`),
1277 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001278include/Test.h -> include/include/Test.h
Colin Cross7113d202019-11-20 16:39:12 -08001279.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1280.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/aidl/foo/bar/Test.h
1281.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1282.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1283.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1284.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/aidl/foo/bar/Test.h
1285.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1286.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 +00001287`),
1288 )
1289}
1290
1291func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1292 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1293 SkipIfNotLinux(t)
1294
1295 result := testSdkWithCc(t, `
Paul Duffine6029182019-12-16 17:43:48 +00001296 module_exports {
1297 name: "myexports",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001298 device_supported: false,
1299 host_supported: true,
1300 native_static_libs: ["mynativelib"],
1301 }
1302
1303 cc_library_static {
1304 name: "mynativelib",
1305 device_supported: false,
1306 host_supported: true,
1307 srcs: [
1308 "Test.cpp",
1309 "aidl/foo/bar/Test.aidl",
1310 ],
1311 export_include_dirs: ["include"],
1312 aidl: {
1313 export_aidl_headers: true,
1314 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001315 stl: "none",
1316 }
1317 `)
1318
Paul Duffin1356d8c2020-02-25 19:26:33 +00001319 result.CheckSnapshot("myexports", "",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001320 checkAndroidBpContents(`
1321// This is auto-generated. DO NOT EDIT.
1322
1323cc_prebuilt_library_static {
Paul Duffine6029182019-12-16 17:43:48 +00001324 name: "myexports_mynativelib@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001325 sdk_member_name: "mynativelib",
1326 device_supported: false,
1327 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001328 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001329 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001330 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001331 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001332 arch: {
1333 x86_64: {
1334 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001335 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001336 },
1337 x86: {
1338 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001339 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001340 },
1341 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001342}
1343
1344cc_prebuilt_library_static {
1345 name: "mynativelib",
1346 prefer: false,
1347 device_supported: false,
1348 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001349 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001350 compile_multilib: "both",
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001351 export_include_dirs: ["include/include"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001352 arch: {
1353 x86_64: {
1354 srcs: ["x86_64/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001355 export_include_dirs: ["x86_64/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001356 },
1357 x86: {
1358 srcs: ["x86/lib/mynativelib.a"],
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001359 export_include_dirs: ["x86/include_gen/mynativelib"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001360 },
1361 },
Paul Duffin9ab556f2019-12-11 18:42:17 +00001362}
1363
Paul Duffine6029182019-12-16 17:43:48 +00001364module_exports_snapshot {
1365 name: "myexports@current",
Paul Duffin9ab556f2019-12-11 18:42:17 +00001366 device_supported: false,
1367 host_supported: true,
Paul Duffine6029182019-12-16 17:43:48 +00001368 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin9ab556f2019-12-11 18:42:17 +00001369}
1370`),
1371 checkAllCopyRules(`
Paul Duffin57b9e1d2019-12-13 00:03:35 +00001372include/Test.h -> include/include/Test.h
Paul Duffin9ab556f2019-12-11 18:42:17 +00001373.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001374.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1375.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1376.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1377.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
Paul Duffin9ab556f2019-12-11 18:42:17 +00001378.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/aidl/foo/bar/Test.h
1379.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1380.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1381`),
1382 )
1383}
Paul Duffin13ad94f2020-02-19 16:19:27 +00001384
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001385func TestSnapshotWithCcLibrary(t *testing.T) {
1386 result := testSdkWithCc(t, `
1387 module_exports {
1388 name: "myexports",
1389 native_libs: ["mynativelib"],
1390 }
1391
1392 cc_library {
1393 name: "mynativelib",
1394 srcs: [
1395 "Test.cpp",
1396 ],
1397 export_include_dirs: ["include"],
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001398 stl: "none",
1399 }
1400 `)
1401
1402 result.CheckSnapshot("myexports", "",
1403 checkAndroidBpContents(`
1404// This is auto-generated. DO NOT EDIT.
1405
1406cc_prebuilt_library {
1407 name: "myexports_mynativelib@current",
1408 sdk_member_name: "mynativelib",
1409 installable: false,
1410 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001411 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001412 export_include_dirs: ["include/include"],
1413 arch: {
1414 arm64: {
1415 static: {
1416 srcs: ["arm64/lib/mynativelib.a"],
1417 },
1418 shared: {
1419 srcs: ["arm64/lib/mynativelib.so"],
1420 },
1421 },
1422 arm: {
1423 static: {
1424 srcs: ["arm/lib/mynativelib.a"],
1425 },
1426 shared: {
1427 srcs: ["arm/lib/mynativelib.so"],
1428 },
1429 },
1430 },
1431}
1432
1433cc_prebuilt_library {
1434 name: "mynativelib",
1435 prefer: false,
1436 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001437 compile_multilib: "both",
Paul Duffin9b76c0b2020-03-12 10:24:35 +00001438 export_include_dirs: ["include/include"],
1439 arch: {
1440 arm64: {
1441 static: {
1442 srcs: ["arm64/lib/mynativelib.a"],
1443 },
1444 shared: {
1445 srcs: ["arm64/lib/mynativelib.so"],
1446 },
1447 },
1448 arm: {
1449 static: {
1450 srcs: ["arm/lib/mynativelib.a"],
1451 },
1452 shared: {
1453 srcs: ["arm/lib/mynativelib.so"],
1454 },
1455 },
1456 },
1457}
1458
1459module_exports_snapshot {
1460 name: "myexports@current",
1461 native_libs: ["myexports_mynativelib@current"],
1462}
1463`),
1464 checkAllCopyRules(`
1465include/Test.h -> include/include/Test.h
1466.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1467.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1468.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1469.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
1470 )
1471}
1472
Paul Duffin13ad94f2020-02-19 16:19:27 +00001473func TestHostSnapshotWithMultiLib64(t *testing.T) {
1474 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1475 SkipIfNotLinux(t)
1476
1477 result := testSdkWithCc(t, `
1478 module_exports {
1479 name: "myexports",
1480 device_supported: false,
1481 host_supported: true,
1482 target: {
1483 host: {
1484 compile_multilib: "64",
1485 },
1486 },
1487 native_static_libs: ["mynativelib"],
1488 }
1489
1490 cc_library_static {
1491 name: "mynativelib",
1492 device_supported: false,
1493 host_supported: true,
1494 srcs: [
1495 "Test.cpp",
1496 "aidl/foo/bar/Test.aidl",
1497 ],
1498 export_include_dirs: ["include"],
1499 aidl: {
1500 export_aidl_headers: true,
1501 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001502 stl: "none",
1503 }
1504 `)
1505
Paul Duffin1356d8c2020-02-25 19:26:33 +00001506 result.CheckSnapshot("myexports", "",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001507 checkAndroidBpContents(`
1508// This is auto-generated. DO NOT EDIT.
1509
1510cc_prebuilt_library_static {
1511 name: "myexports_mynativelib@current",
1512 sdk_member_name: "mynativelib",
1513 device_supported: false,
1514 host_supported: true,
Paul Duffin0cb37b92020-03-04 14:52:46 +00001515 installable: false,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001516 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001517 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001518 export_include_dirs: ["include/include"],
1519 arch: {
1520 x86_64: {
1521 srcs: ["x86_64/lib/mynativelib.a"],
1522 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1523 },
1524 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001525}
1526
1527cc_prebuilt_library_static {
1528 name: "mynativelib",
1529 prefer: false,
1530 device_supported: false,
1531 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001532 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001533 compile_multilib: "64",
Paul Duffin13ad94f2020-02-19 16:19:27 +00001534 export_include_dirs: ["include/include"],
1535 arch: {
1536 x86_64: {
1537 srcs: ["x86_64/lib/mynativelib.a"],
1538 export_include_dirs: ["x86_64/include_gen/mynativelib"],
1539 },
1540 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001541}
1542
1543module_exports_snapshot {
1544 name: "myexports@current",
1545 device_supported: false,
1546 host_supported: true,
Paul Duffin07ef3cb2020-03-11 18:17:42 +00001547 native_static_libs: ["myexports_mynativelib@current"],
Paul Duffin13ad94f2020-02-19 16:19:27 +00001548 target: {
Paul Duffin6a7e9532020-03-20 17:50:07 +00001549 linux_glibc: {
Paul Duffin13ad94f2020-02-19 16:19:27 +00001550 compile_multilib: "64",
1551 },
1552 },
Paul Duffin13ad94f2020-02-19 16:19:27 +00001553}`),
1554 checkAllCopyRules(`
1555include/Test.h -> include/include/Test.h
1556.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1557.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
1558.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
1559.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
1560`),
1561 )
1562}
Paul Duffin91756d22020-02-21 16:29:57 +00001563
1564func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1565 result := testSdkWithCc(t, `
1566 sdk {
1567 name: "mysdk",
1568 native_header_libs: ["mynativeheaders"],
1569 }
1570
1571 cc_library_headers {
1572 name: "mynativeheaders",
1573 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001574 stl: "none",
1575 }
1576 `)
1577
Paul Duffin1356d8c2020-02-25 19:26:33 +00001578 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001579 checkAndroidBpContents(`
1580// This is auto-generated. DO NOT EDIT.
1581
1582cc_prebuilt_library_headers {
1583 name: "mysdk_mynativeheaders@current",
1584 sdk_member_name: "mynativeheaders",
Paul Duffin91756d22020-02-21 16:29:57 +00001585 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001586 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001587 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001588}
1589
1590cc_prebuilt_library_headers {
1591 name: "mynativeheaders",
1592 prefer: false,
Paul Duffin91756d22020-02-21 16:29:57 +00001593 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001594 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001595 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001596}
1597
1598sdk_snapshot {
1599 name: "mysdk@current",
1600 native_header_libs: ["mysdk_mynativeheaders@current"],
1601}
1602`),
1603 checkAllCopyRules(`
1604include/Test.h -> include/include/Test.h
1605`),
1606 )
1607}
1608
1609func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1610 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1611 SkipIfNotLinux(t)
1612
1613 result := testSdkWithCc(t, `
1614 sdk {
1615 name: "mysdk",
1616 device_supported: false,
1617 host_supported: true,
1618 native_header_libs: ["mynativeheaders"],
1619 }
1620
1621 cc_library_headers {
1622 name: "mynativeheaders",
1623 device_supported: false,
1624 host_supported: true,
1625 export_include_dirs: ["include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001626 stl: "none",
1627 }
1628 `)
1629
Paul Duffin1356d8c2020-02-25 19:26:33 +00001630 result.CheckSnapshot("mysdk", "",
Paul Duffin91756d22020-02-21 16:29:57 +00001631 checkAndroidBpContents(`
1632// This is auto-generated. DO NOT EDIT.
1633
1634cc_prebuilt_library_headers {
1635 name: "mysdk_mynativeheaders@current",
1636 sdk_member_name: "mynativeheaders",
1637 device_supported: false,
1638 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001639 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001640 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001641 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001642}
1643
1644cc_prebuilt_library_headers {
1645 name: "mynativeheaders",
1646 prefer: false,
1647 device_supported: false,
1648 host_supported: true,
Paul Duffin91756d22020-02-21 16:29:57 +00001649 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001650 compile_multilib: "both",
Paul Duffin0174d8d2020-03-11 18:42:08 +00001651 export_include_dirs: ["include/include"],
Paul Duffin91756d22020-02-21 16:29:57 +00001652}
1653
1654sdk_snapshot {
1655 name: "mysdk@current",
1656 device_supported: false,
1657 host_supported: true,
1658 native_header_libs: ["mysdk_mynativeheaders@current"],
1659}
1660`),
1661 checkAllCopyRules(`
1662include/Test.h -> include/include/Test.h
1663`),
1664 )
1665}
Paul Duffina04c1072020-03-02 10:16:35 +00001666
1667func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1668 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1669 SkipIfNotLinux(t)
1670
1671 result := testSdkWithCc(t, `
1672 sdk {
1673 name: "mysdk",
1674 host_supported: true,
1675 native_header_libs: ["mynativeheaders"],
1676 }
1677
1678 cc_library_headers {
1679 name: "mynativeheaders",
1680 host_supported: true,
Paul Duffina04c1072020-03-02 10:16:35 +00001681 stl: "none",
1682 export_system_include_dirs: ["include"],
1683 target: {
1684 android: {
1685 export_include_dirs: ["include-android"],
1686 },
1687 host: {
1688 export_include_dirs: ["include-host"],
1689 },
1690 },
1691 }
1692 `)
1693
1694 result.CheckSnapshot("mysdk", "",
1695 checkAndroidBpContents(`
1696// This is auto-generated. DO NOT EDIT.
1697
1698cc_prebuilt_library_headers {
1699 name: "mysdk_mynativeheaders@current",
1700 sdk_member_name: "mynativeheaders",
1701 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001702 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001703 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01001704 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00001705 target: {
1706 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001707 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00001708 },
1709 linux_glibc: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001710 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00001711 },
1712 },
Paul Duffina04c1072020-03-02 10:16:35 +00001713}
1714
1715cc_prebuilt_library_headers {
1716 name: "mynativeheaders",
1717 prefer: false,
1718 host_supported: true,
Paul Duffin0174d8d2020-03-11 18:42:08 +00001719 stl: "none",
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001720 compile_multilib: "both",
Paul Duffined62b9c2020-06-16 16:12:50 +01001721 export_system_include_dirs: ["common_os/include/include"],
Paul Duffina04c1072020-03-02 10:16:35 +00001722 target: {
1723 android: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001724 export_include_dirs: ["android/include/include-android"],
Paul Duffina04c1072020-03-02 10:16:35 +00001725 },
1726 linux_glibc: {
Paul Duffined62b9c2020-06-16 16:12:50 +01001727 export_include_dirs: ["linux_glibc/include/include-host"],
Paul Duffina04c1072020-03-02 10:16:35 +00001728 },
1729 },
Paul Duffina04c1072020-03-02 10:16:35 +00001730}
1731
1732sdk_snapshot {
1733 name: "mysdk@current",
1734 host_supported: true,
1735 native_header_libs: ["mysdk_mynativeheaders@current"],
1736}
1737`),
1738 checkAllCopyRules(`
Paul Duffined62b9c2020-06-16 16:12:50 +01001739include/Test.h -> common_os/include/include/Test.h
1740include-android/AndroidTest.h -> android/include/include-android/AndroidTest.h
1741include-host/HostTest.h -> linux_glibc/include/include-host/HostTest.h
Paul Duffina04c1072020-03-02 10:16:35 +00001742`),
1743 )
1744}
Martin Stjernholm10566a02020-03-24 01:19:52 +00001745
1746func TestSystemSharedLibPropagation(t *testing.T) {
Martin Stjernholm66a06942020-03-26 17:39:30 +00001747 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
1748 SkipIfNotLinux(t)
1749
Martin Stjernholm10566a02020-03-24 01:19:52 +00001750 result := testSdkWithCc(t, `
1751 sdk {
1752 name: "mysdk",
1753 native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
1754 }
1755
1756 cc_library {
1757 name: "sslnil",
1758 host_supported: true,
1759 }
1760
1761 cc_library {
1762 name: "sslempty",
1763 system_shared_libs: [],
1764 }
1765
1766 cc_library {
1767 name: "sslnonempty",
1768 system_shared_libs: ["sslnil"],
1769 }
1770 `)
1771
1772 result.CheckSnapshot("mysdk", "",
1773 checkAndroidBpContents(`
1774// This is auto-generated. DO NOT EDIT.
1775
1776cc_prebuilt_library_shared {
1777 name: "mysdk_sslnil@current",
1778 sdk_member_name: "sslnil",
1779 installable: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001780 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001781 arch: {
1782 arm64: {
1783 srcs: ["arm64/lib/sslnil.so"],
1784 },
1785 arm: {
1786 srcs: ["arm/lib/sslnil.so"],
1787 },
1788 },
1789}
1790
1791cc_prebuilt_library_shared {
1792 name: "sslnil",
1793 prefer: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001794 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001795 arch: {
1796 arm64: {
1797 srcs: ["arm64/lib/sslnil.so"],
1798 },
1799 arm: {
1800 srcs: ["arm/lib/sslnil.so"],
1801 },
1802 },
1803}
1804
1805cc_prebuilt_library_shared {
1806 name: "mysdk_sslempty@current",
1807 sdk_member_name: "sslempty",
1808 installable: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001809 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001810 system_shared_libs: [],
1811 arch: {
1812 arm64: {
1813 srcs: ["arm64/lib/sslempty.so"],
1814 },
1815 arm: {
1816 srcs: ["arm/lib/sslempty.so"],
1817 },
1818 },
1819}
1820
1821cc_prebuilt_library_shared {
1822 name: "sslempty",
1823 prefer: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001824 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001825 system_shared_libs: [],
1826 arch: {
1827 arm64: {
1828 srcs: ["arm64/lib/sslempty.so"],
1829 },
1830 arm: {
1831 srcs: ["arm/lib/sslempty.so"],
1832 },
1833 },
1834}
1835
1836cc_prebuilt_library_shared {
1837 name: "mysdk_sslnonempty@current",
1838 sdk_member_name: "sslnonempty",
1839 installable: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001840 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001841 system_shared_libs: ["mysdk_sslnil@current"],
1842 arch: {
1843 arm64: {
1844 srcs: ["arm64/lib/sslnonempty.so"],
1845 },
1846 arm: {
1847 srcs: ["arm/lib/sslnonempty.so"],
1848 },
1849 },
1850}
1851
1852cc_prebuilt_library_shared {
1853 name: "sslnonempty",
1854 prefer: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001855 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001856 system_shared_libs: ["sslnil"],
1857 arch: {
1858 arm64: {
1859 srcs: ["arm64/lib/sslnonempty.so"],
1860 },
1861 arm: {
1862 srcs: ["arm/lib/sslnonempty.so"],
1863 },
1864 },
1865}
1866
1867sdk_snapshot {
1868 name: "mysdk@current",
1869 native_shared_libs: [
1870 "mysdk_sslnil@current",
1871 "mysdk_sslempty@current",
1872 "mysdk_sslnonempty@current",
1873 ],
1874}
1875`))
1876
1877 result = testSdkWithCc(t, `
1878 sdk {
1879 name: "mysdk",
1880 host_supported: true,
1881 native_shared_libs: ["sslvariants"],
1882 }
1883
1884 cc_library {
1885 name: "sslvariants",
1886 host_supported: true,
1887 target: {
1888 android: {
1889 system_shared_libs: [],
1890 },
1891 },
1892 }
1893 `)
1894
1895 result.CheckSnapshot("mysdk", "",
1896 checkAndroidBpContents(`
1897// This is auto-generated. DO NOT EDIT.
1898
1899cc_prebuilt_library_shared {
1900 name: "mysdk_sslvariants@current",
1901 sdk_member_name: "sslvariants",
1902 host_supported: true,
1903 installable: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001904 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001905 target: {
1906 android: {
1907 system_shared_libs: [],
1908 },
1909 android_arm64: {
1910 srcs: ["android/arm64/lib/sslvariants.so"],
1911 },
1912 android_arm: {
1913 srcs: ["android/arm/lib/sslvariants.so"],
1914 },
1915 linux_glibc_x86_64: {
1916 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1917 },
1918 linux_glibc_x86: {
1919 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1920 },
1921 },
1922}
1923
1924cc_prebuilt_library_shared {
1925 name: "sslvariants",
1926 prefer: false,
1927 host_supported: true,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001928 compile_multilib: "both",
Martin Stjernholm10566a02020-03-24 01:19:52 +00001929 target: {
1930 android: {
1931 system_shared_libs: [],
1932 },
1933 android_arm64: {
1934 srcs: ["android/arm64/lib/sslvariants.so"],
1935 },
1936 android_arm: {
1937 srcs: ["android/arm/lib/sslvariants.so"],
1938 },
1939 linux_glibc_x86_64: {
1940 srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
1941 },
1942 linux_glibc_x86: {
1943 srcs: ["linux_glibc/x86/lib/sslvariants.so"],
1944 },
1945 },
1946}
1947
1948sdk_snapshot {
1949 name: "mysdk@current",
1950 host_supported: true,
1951 native_shared_libs: ["mysdk_sslvariants@current"],
1952}
1953`))
1954}
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001955
1956func TestStubsLibrary(t *testing.T) {
1957 result := testSdkWithCc(t, `
1958 sdk {
1959 name: "mysdk",
1960 native_shared_libs: ["stubslib"],
1961 }
1962
1963 cc_library {
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001964 name: "internaldep",
1965 }
1966
1967 cc_library {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001968 name: "stubslib",
Martin Stjernholmcc330d62020-04-21 20:45:35 +01001969 shared_libs: ["internaldep"],
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001970 stubs: {
1971 symbol_file: "some/where/stubslib.map.txt",
1972 versions: ["1", "2", "3"],
1973 },
1974 }
1975 `)
1976
1977 result.CheckSnapshot("mysdk", "",
1978 checkAndroidBpContents(`
1979// This is auto-generated. DO NOT EDIT.
1980
1981cc_prebuilt_library_shared {
1982 name: "mysdk_stubslib@current",
1983 sdk_member_name: "stubslib",
1984 installable: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01001985 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001986 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01001987 versions: ["3"],
1988 },
1989 arch: {
1990 arm64: {
1991 srcs: ["arm64/lib/stubslib.so"],
1992 },
1993 arm: {
1994 srcs: ["arm/lib/stubslib.so"],
1995 },
1996 },
1997}
1998
1999cc_prebuilt_library_shared {
2000 name: "stubslib",
2001 prefer: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01002002 compile_multilib: "both",
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002003 stubs: {
Martin Stjernholmc5dd4f72020-04-01 20:38:01 +01002004 versions: ["3"],
2005 },
2006 arch: {
2007 arm64: {
2008 srcs: ["arm64/lib/stubslib.so"],
2009 },
2010 arm: {
2011 srcs: ["arm/lib/stubslib.so"],
2012 },
2013 },
2014}
2015
2016sdk_snapshot {
2017 name: "mysdk@current",
2018 native_shared_libs: ["mysdk_stubslib@current"],
2019}
2020`))
2021}
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002022
2023func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
2024 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
2025 SkipIfNotLinux(t)
2026
2027 result := testSdkWithCc(t, `
2028 sdk {
2029 name: "mysdk",
2030 host_supported: true,
2031 native_shared_libs: ["stubslib"],
2032 }
2033
2034 cc_library {
2035 name: "internaldep",
2036 host_supported: true,
2037 }
2038
2039 cc_library {
2040 name: "stubslib",
2041 host_supported: true,
2042 shared_libs: ["internaldep"],
2043 stubs: {
2044 symbol_file: "some/where/stubslib.map.txt",
2045 versions: ["1", "2", "3"],
2046 },
2047 }
2048 `)
2049
2050 result.CheckSnapshot("mysdk", "",
2051 checkAndroidBpContents(`
2052// This is auto-generated. DO NOT EDIT.
2053
2054cc_prebuilt_library_shared {
2055 name: "mysdk_stubslib@current",
2056 sdk_member_name: "stubslib",
2057 host_supported: true,
2058 installable: false,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01002059 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002060 stubs: {
2061 versions: ["3"],
2062 },
2063 target: {
2064 android_arm64: {
2065 srcs: ["android/arm64/lib/stubslib.so"],
2066 },
2067 android_arm: {
2068 srcs: ["android/arm/lib/stubslib.so"],
2069 },
2070 linux_glibc_x86_64: {
2071 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2072 },
2073 linux_glibc_x86: {
2074 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2075 },
2076 },
2077}
2078
2079cc_prebuilt_library_shared {
2080 name: "stubslib",
2081 prefer: false,
2082 host_supported: true,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01002083 compile_multilib: "both",
Paul Duffin7a1f7f32020-05-04 15:32:08 +01002084 stubs: {
2085 versions: ["3"],
2086 },
2087 target: {
2088 android_arm64: {
2089 srcs: ["android/arm64/lib/stubslib.so"],
2090 },
2091 android_arm: {
2092 srcs: ["android/arm/lib/stubslib.so"],
2093 },
2094 linux_glibc_x86_64: {
2095 srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2096 },
2097 linux_glibc_x86: {
2098 srcs: ["linux_glibc/x86/lib/stubslib.so"],
2099 },
2100 },
2101}
2102
2103sdk_snapshot {
2104 name: "mysdk@current",
2105 host_supported: true,
2106 native_shared_libs: ["mysdk_stubslib@current"],
2107}
2108`))
2109}
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002110
2111func TestUniqueHostSoname(t *testing.T) {
2112 // b/145598135 - Generating host snapshots for anything other than linux is not supported.
2113 SkipIfNotLinux(t)
2114
2115 result := testSdkWithCc(t, `
2116 sdk {
2117 name: "mysdk",
2118 host_supported: true,
2119 native_shared_libs: ["mylib"],
2120 }
2121
2122 cc_library {
2123 name: "mylib",
2124 host_supported: true,
2125 unique_host_soname: true,
2126 }
2127 `)
2128
2129 result.CheckSnapshot("mysdk", "",
2130 checkAndroidBpContents(`
2131// This is auto-generated. DO NOT EDIT.
2132
2133cc_prebuilt_library_shared {
2134 name: "mysdk_mylib@current",
2135 sdk_member_name: "mylib",
2136 host_supported: true,
2137 installable: false,
2138 unique_host_soname: true,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01002139 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002140 target: {
2141 android_arm64: {
2142 srcs: ["android/arm64/lib/mylib.so"],
2143 },
2144 android_arm: {
2145 srcs: ["android/arm/lib/mylib.so"],
2146 },
2147 linux_glibc_x86_64: {
2148 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2149 },
2150 linux_glibc_x86: {
2151 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2152 },
2153 },
2154}
2155
2156cc_prebuilt_library_shared {
2157 name: "mylib",
2158 prefer: false,
2159 host_supported: true,
2160 unique_host_soname: true,
Martin Stjernholm1e9c2672020-07-10 00:14:03 +01002161 compile_multilib: "both",
Martin Stjernholm47ed3522020-06-17 22:52:25 +01002162 target: {
2163 android_arm64: {
2164 srcs: ["android/arm64/lib/mylib.so"],
2165 },
2166 android_arm: {
2167 srcs: ["android/arm/lib/mylib.so"],
2168 },
2169 linux_glibc_x86_64: {
2170 srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2171 },
2172 linux_glibc_x86: {
2173 srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2174 },
2175 },
2176}
2177
2178sdk_snapshot {
2179 name: "mysdk@current",
2180 host_supported: true,
2181 native_shared_libs: ["mysdk_mylib@current"],
2182}
2183`),
2184 checkAllCopyRules(`
2185.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2186.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2187.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2188.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2189`),
2190 )
2191}