1// 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
20	"android/soong/android"
21	"android/soong/cc"
22)
23
24var 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
35func testSdkWithCc(t *testing.T, bp string) *testSdkResult {
36	t.Helper()
37	return testSdkWithFs(t, bp, ccTestFs)
38}
39
40// Contains tests for SDK members provided by the cc package.
41
42func TestSdkIsCompileMultilibBoth(t *testing.T) {
43	result := testSdkWithCc(t, `
44		sdk {
45			name: "mysdk",
46			native_shared_libs: ["sdkmember"],
47		}
48
49		cc_library_shared {
50			name: "sdkmember",
51			srcs: ["Test.cpp"],
52			stl: "none",
53		}
54	`)
55
56	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()
58
59	var inputs []string
60	buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
61	for _, bp := range buildParams {
62		if bp.Input != nil {
63			inputs = append(inputs, bp.Input.String())
64		}
65	}
66
67	// ensure that both 32/64 outputs are inputs of the sdk snapshot
68	ensureListContains(t, inputs, armOutput.String())
69	ensureListContains(t, inputs, arm64Output.String())
70}
71
72func TestSdkCompileMultilibOverride(t *testing.T) {
73	result := testSdkWithCc(t, `
74		sdk {
75			name: "mysdk",
76			device_supported: false,
77			host_supported: true,
78			native_shared_libs: ["sdkmember"],
79			compile_multilib: "64",
80		}
81
82		cc_library_shared {
83			name: "sdkmember",
84			device_supported: false,
85			host_supported: true,
86			srcs: ["Test.cpp"],
87			stl: "none",
88			compile_multilib: "64",
89		}
90	`)
91
92	result.CheckSnapshot("mysdk", "",
93		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`),
137		checkAllCopyRules(`
138.intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> x86_64/lib/sdkmember.so
139`))
140}
141
142func TestBasicSdkWithCc(t *testing.T) {
143	result := testSdkWithCc(t, `
144		sdk {
145			name: "mysdk",
146			native_shared_libs: ["sdkmember"],
147		}
148
149		cc_library_shared {
150			name: "sdkmember",
151			system_shared_libs: [],
152			stl: "none",
153			apex_available: ["mysdkapex"],
154		}
155
156		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",
180			// TODO: remove //apex_available:platform
181			apex_available: [
182				"//apex_available:platform",
183				"myapex",
184			],
185		}
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",
193			// TODO: remove //apex_available:platform
194			apex_available: [
195				"//apex_available:platform",
196				"myapex2",
197			],
198		}
199
200		cc_library_shared {
201			name: "mycpplib",
202			srcs: ["Test.cpp"],
203			shared_libs: ["sdkmember"],
204			system_shared_libs: [],
205			stl: "none",
206			apex_available: [
207				"myapex",
208				"myapex2",
209			],
210		}
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		}
227
228		apex {
229			name: "mysdkapex",
230			native_shared_libs: ["sdkmember"],
231			key: "myapex.key",
232			certificate: ":myapex.cert",
233		}
234	`)
235
236	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
238
239	cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex")
240	cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_myapex2")
241
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
247// 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",
260			stl: "none",
261		}
262
263		cc_library_host_static {
264			name: "sdkstatic",
265			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",
281			stl: "none",
282		}
283
284		cc_library_static {
285			name: "sdkstatic",
286			stl: "none",
287		}
288
289		cc_library {
290			name: "sdkboth1",
291			stl: "none",
292		}
293
294		cc_library {
295			name: "sdkboth2",
296			stl: "none",
297		}
298	`)
299}
300
301func 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",
322    compile_multilib: "both",
323    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",
337    compile_multilib: "both",
338    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
360func 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"],
373			stl: "none",
374		}
375
376		cc_library_shared {
377			name: "mynativelib2",
378			srcs: [
379				"Test.cpp",
380			],
381			export_include_dirs: ["include"],
382			stl: "none",
383		}
384	`)
385
386	result.CheckSnapshot("mysdk", "",
387		checkAllCopyRules(`
388include/Test.h -> include/include/Test.h
389.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
393`),
394	)
395}
396
397// 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			},
418			stl: "none",
419		}
420	`)
421
422	result.CheckSnapshot("mysdk", "",
423		checkAndroidBpContents(`
424// This is auto-generated. DO NOT EDIT.
425
426cc_prebuilt_library_shared {
427    name: "mysdk_mynativelib@current",
428    sdk_member_name: "mynativelib",
429    installable: false,
430    stl: "none",
431    compile_multilib: "both",
432    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    },
442}
443
444cc_prebuilt_library_shared {
445    name: "mynativelib",
446    prefer: false,
447    stl: "none",
448    compile_multilib: "both",
449    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    },
459}
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
468.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
469arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
470.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
471	)
472}
473
474func 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",
487		}
488	`)
489
490	result.CheckSnapshot("mymodule_exports", "",
491		checkAndroidBpContents(`
492// This is auto-generated. DO NOT EDIT.
493
494cc_prebuilt_binary {
495    name: "mymodule_exports_mynativebinary@current",
496    sdk_member_name: "mynativebinary",
497    installable: false,
498    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
535func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
536	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",
557			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,
575    installable: false,
576    stl: "none",
577    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,
601    stl: "none",
602    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"],
626    target: {
627        windows: {
628            compile_multilib: "64",
629        },
630    },
631}
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
641// Test that we support the necessary flags for the linker binary, which is
642// special in several ways.
643func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
644	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",
676    compile_multilib: "both",
677    static_executable: true,
678    nocrt: true,
679    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",
695    compile_multilib: "both",
696    static_executable: true,
697    nocrt: true,
698    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
722func TestSnapshotWithCcSharedLibrary(t *testing.T) {
723	result := testSdkWithCc(t, `
724		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			],
735			apex_available: ["apex1", "apex2"],
736			export_include_dirs: ["include"],
737			aidl: {
738				export_aidl_headers: true,
739			},
740			stl: "none",
741		}
742	`)
743
744	result.CheckSnapshot("mysdk", "",
745		checkAndroidBpContents(`
746// This is auto-generated. DO NOT EDIT.
747
748cc_prebuilt_library_shared {
749    name: "mysdk_mynativelib@current",
750    sdk_member_name: "mynativelib",
751    apex_available: [
752        "apex1",
753        "apex2",
754    ],
755    installable: false,
756    stl: "none",
757    compile_multilib: "both",
758    export_include_dirs: ["include/include"],
759    arch: {
760        arm64: {
761            srcs: ["arm64/lib/mynativelib.so"],
762            export_include_dirs: ["arm64/include_gen/mynativelib"],
763        },
764        arm: {
765            srcs: ["arm/lib/mynativelib.so"],
766            export_include_dirs: ["arm/include_gen/mynativelib"],
767        },
768    },
769}
770
771cc_prebuilt_library_shared {
772    name: "mynativelib",
773    prefer: false,
774    apex_available: [
775        "apex1",
776        "apex2",
777    ],
778    stl: "none",
779    compile_multilib: "both",
780    export_include_dirs: ["include/include"],
781    arch: {
782        arm64: {
783            srcs: ["arm64/lib/mynativelib.so"],
784            export_include_dirs: ["arm64/include_gen/mynativelib"],
785        },
786        arm: {
787            srcs: ["arm/lib/mynativelib.so"],
788            export_include_dirs: ["arm/include_gen/mynativelib"],
789        },
790    },
791}
792
793sdk_snapshot {
794    name: "mysdk@current",
795    native_shared_libs: ["mysdk_mynativelib@current"],
796}
797`),
798		checkAllCopyRules(`
799include/Test.h -> include/include/Test.h
800.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
808`),
809	)
810}
811
812func 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			],
828			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			},
868			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,
880    stl: "none",
881    compile_multilib: "both",
882    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    },
894}
895
896cc_prebuilt_library_shared {
897    name: "mynativelib",
898    prefer: false,
899    stl: "none",
900    compile_multilib: "both",
901    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    },
913}
914
915cc_prebuilt_library_shared {
916    name: "mysdk_myothernativelib@current",
917    sdk_member_name: "myothernativelib",
918    installable: false,
919    stl: "none",
920    compile_multilib: "both",
921    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    },
930}
931
932cc_prebuilt_library_shared {
933    name: "myothernativelib",
934    prefer: false,
935    stl: "none",
936    compile_multilib: "both",
937    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    },
946}
947
948cc_prebuilt_library_shared {
949    name: "mysdk_mysystemnativelib@current",
950    sdk_member_name: "mysystemnativelib",
951    installable: false,
952    stl: "none",
953    compile_multilib: "both",
954    arch: {
955        arm64: {
956            srcs: ["arm64/lib/mysystemnativelib.so"],
957        },
958        arm: {
959            srcs: ["arm/lib/mysystemnativelib.so"],
960        },
961    },
962}
963
964cc_prebuilt_library_shared {
965    name: "mysystemnativelib",
966    prefer: false,
967    stl: "none",
968    compile_multilib: "both",
969    arch: {
970        arm64: {
971            srcs: ["arm64/lib/mysystemnativelib.so"],
972        },
973        arm: {
974            srcs: ["arm/lib/mysystemnativelib.so"],
975        },
976    },
977}
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
999func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
1000	result := testSdkWithCc(t, `
1001		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			},
1020			stl: "none",
1021			sdk_version: "minimum",
1022		}
1023	`)
1024
1025	result.CheckSnapshot("mysdk", "",
1026		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,
1034    installable: false,
1035    sdk_version: "minimum",
1036    stl: "none",
1037    compile_multilib: "both",
1038    export_include_dirs: ["include/include"],
1039    arch: {
1040        x86_64: {
1041            srcs: ["x86_64/lib/mynativelib.so"],
1042            export_include_dirs: ["x86_64/include_gen/mynativelib"],
1043        },
1044        x86: {
1045            srcs: ["x86/lib/mynativelib.so"],
1046            export_include_dirs: ["x86/include_gen/mynativelib"],
1047        },
1048    },
1049}
1050
1051cc_prebuilt_library_shared {
1052    name: "mynativelib",
1053    prefer: false,
1054    device_supported: false,
1055    host_supported: true,
1056    sdk_version: "minimum",
1057    stl: "none",
1058    compile_multilib: "both",
1059    export_include_dirs: ["include/include"],
1060    arch: {
1061        x86_64: {
1062            srcs: ["x86_64/lib/mynativelib.so"],
1063            export_include_dirs: ["x86_64/include_gen/mynativelib"],
1064        },
1065        x86: {
1066            srcs: ["x86/lib/mynativelib.so"],
1067            export_include_dirs: ["x86/include_gen/mynativelib"],
1068        },
1069    },
1070}
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(`
1080include/Test.h -> include/include/Test.h
1081.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
1082.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
1086.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}
1092
1093func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
1094	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			],
1114			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,
1132    installable: false,
1133    stl: "none",
1134    target: {
1135        linux_glibc: {
1136            compile_multilib: "both",
1137        },
1138        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        },
1144        windows: {
1145            compile_multilib: "64",
1146        },
1147        windows_x86_64: {
1148            srcs: ["windows/x86_64/lib/mynativelib.dll"],
1149        },
1150    },
1151}
1152
1153cc_prebuilt_library_shared {
1154    name: "mynativelib",
1155    prefer: false,
1156    device_supported: false,
1157    host_supported: true,
1158    stl: "none",
1159    target: {
1160        linux_glibc: {
1161            compile_multilib: "both",
1162        },
1163        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        },
1169        windows: {
1170            compile_multilib: "64",
1171        },
1172        windows_x86_64: {
1173            srcs: ["windows/x86_64/lib/mynativelib.dll"],
1174        },
1175    },
1176}
1177
1178sdk_snapshot {
1179    name: "mysdk@current",
1180    device_supported: false,
1181    host_supported: true,
1182    native_shared_libs: ["mysdk_mynativelib@current"],
1183    target: {
1184        windows: {
1185            compile_multilib: "64",
1186        },
1187    },
1188}
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
1198func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1199	result := testSdkWithCc(t, `
1200		module_exports {
1201			name: "myexports",
1202			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			},
1215			stl: "none",
1216		}
1217	`)
1218
1219	result.CheckSnapshot("myexports", "",
1220		checkAndroidBpContents(`
1221// This is auto-generated. DO NOT EDIT.
1222
1223cc_prebuilt_library_static {
1224    name: "myexports_mynativelib@current",
1225    sdk_member_name: "mynativelib",
1226    installable: false,
1227    stl: "none",
1228    compile_multilib: "both",
1229    export_include_dirs: ["include/include"],
1230    arch: {
1231        arm64: {
1232            srcs: ["arm64/lib/mynativelib.a"],
1233            export_include_dirs: ["arm64/include_gen/mynativelib"],
1234        },
1235        arm: {
1236            srcs: ["arm/lib/mynativelib.a"],
1237            export_include_dirs: ["arm/include_gen/mynativelib"],
1238        },
1239    },
1240}
1241
1242cc_prebuilt_library_static {
1243    name: "mynativelib",
1244    prefer: false,
1245    stl: "none",
1246    compile_multilib: "both",
1247    export_include_dirs: ["include/include"],
1248    arch: {
1249        arm64: {
1250            srcs: ["arm64/lib/mynativelib.a"],
1251            export_include_dirs: ["arm64/include_gen/mynativelib"],
1252        },
1253        arm: {
1254            srcs: ["arm/lib/mynativelib.a"],
1255            export_include_dirs: ["arm/include_gen/mynativelib"],
1256        },
1257    },
1258}
1259
1260module_exports_snapshot {
1261    name: "myexports@current",
1262    native_static_libs: ["myexports_mynativelib@current"],
1263}
1264`),
1265		checkAllCopyRules(`
1266include/Test.h -> include/include/Test.h
1267.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
1275`),
1276	)
1277}
1278
1279func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1280	result := testSdkWithCc(t, `
1281		module_exports {
1282			name: "myexports",
1283			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			},
1300			stl: "none",
1301		}
1302	`)
1303
1304	result.CheckSnapshot("myexports", "",
1305		checkAndroidBpContents(`
1306// This is auto-generated. DO NOT EDIT.
1307
1308cc_prebuilt_library_static {
1309    name: "myexports_mynativelib@current",
1310    sdk_member_name: "mynativelib",
1311    device_supported: false,
1312    host_supported: true,
1313    installable: false,
1314    stl: "none",
1315    compile_multilib: "both",
1316    export_include_dirs: ["include/include"],
1317    arch: {
1318        x86_64: {
1319            srcs: ["x86_64/lib/mynativelib.a"],
1320            export_include_dirs: ["x86_64/include_gen/mynativelib"],
1321        },
1322        x86: {
1323            srcs: ["x86/lib/mynativelib.a"],
1324            export_include_dirs: ["x86/include_gen/mynativelib"],
1325        },
1326    },
1327}
1328
1329cc_prebuilt_library_static {
1330    name: "mynativelib",
1331    prefer: false,
1332    device_supported: false,
1333    host_supported: true,
1334    stl: "none",
1335    compile_multilib: "both",
1336    export_include_dirs: ["include/include"],
1337    arch: {
1338        x86_64: {
1339            srcs: ["x86_64/lib/mynativelib.a"],
1340            export_include_dirs: ["x86_64/include_gen/mynativelib"],
1341        },
1342        x86: {
1343            srcs: ["x86/lib/mynativelib.a"],
1344            export_include_dirs: ["x86/include_gen/mynativelib"],
1345        },
1346    },
1347}
1348
1349module_exports_snapshot {
1350    name: "myexports@current",
1351    device_supported: false,
1352    host_supported: true,
1353    native_static_libs: ["myexports_mynativelib@current"],
1354}
1355`),
1356		checkAllCopyRules(`
1357include/Test.h -> include/include/Test.h
1358.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1359.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
1363.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}
1369
1370func 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"],
1383			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",
1396    compile_multilib: "both",
1397    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",
1422    compile_multilib: "both",
1423    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
1458func TestHostSnapshotWithMultiLib64(t *testing.T) {
1459	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			},
1484			stl: "none",
1485		}
1486	`)
1487
1488	result.CheckSnapshot("myexports", "",
1489		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,
1497    installable: false,
1498    stl: "none",
1499    compile_multilib: "64",
1500    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    },
1507}
1508
1509cc_prebuilt_library_static {
1510    name: "mynativelib",
1511    prefer: false,
1512    device_supported: false,
1513    host_supported: true,
1514    stl: "none",
1515    compile_multilib: "64",
1516    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    },
1523}
1524
1525module_exports_snapshot {
1526    name: "myexports@current",
1527    device_supported: false,
1528    host_supported: true,
1529    native_static_libs: ["myexports_mynativelib@current"],
1530    target: {
1531        linux_glibc: {
1532            compile_multilib: "64",
1533        },
1534    },
1535}`),
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}
1545
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"],
1556			stl: "none",
1557		}
1558	`)
1559
1560	result.CheckSnapshot("mysdk", "",
1561		checkAndroidBpContents(`
1562// This is auto-generated. DO NOT EDIT.
1563
1564cc_prebuilt_library_headers {
1565    name: "mysdk_mynativeheaders@current",
1566    sdk_member_name: "mynativeheaders",
1567    stl: "none",
1568    compile_multilib: "both",
1569    export_include_dirs: ["include/include"],
1570}
1571
1572cc_prebuilt_library_headers {
1573    name: "mynativeheaders",
1574    prefer: false,
1575    stl: "none",
1576    compile_multilib: "both",
1577    export_include_dirs: ["include/include"],
1578}
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) {
1592	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"],
1605			stl: "none",
1606		}
1607	`)
1608
1609	result.CheckSnapshot("mysdk", "",
1610		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,
1618    stl: "none",
1619    compile_multilib: "both",
1620    export_include_dirs: ["include/include"],
1621}
1622
1623cc_prebuilt_library_headers {
1624    name: "mynativeheaders",
1625    prefer: false,
1626    device_supported: false,
1627    host_supported: true,
1628    stl: "none",
1629    compile_multilib: "both",
1630    export_include_dirs: ["include/include"],
1631}
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}
1645
1646func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1647	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,
1657			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,
1678    stl: "none",
1679    compile_multilib: "both",
1680    export_system_include_dirs: ["common_os/include/include"],
1681    target: {
1682        android: {
1683            export_include_dirs: ["android/include/include-android"],
1684        },
1685        linux_glibc: {
1686            export_include_dirs: ["linux_glibc/include/include-host"],
1687        },
1688    },
1689}
1690
1691cc_prebuilt_library_headers {
1692    name: "mynativeheaders",
1693    prefer: false,
1694    host_supported: true,
1695    stl: "none",
1696    compile_multilib: "both",
1697    export_system_include_dirs: ["common_os/include/include"],
1698    target: {
1699        android: {
1700            export_include_dirs: ["android/include/include-android"],
1701        },
1702        linux_glibc: {
1703            export_include_dirs: ["linux_glibc/include/include-host"],
1704        },
1705    },
1706}
1707
1708sdk_snapshot {
1709    name: "mysdk@current",
1710    host_supported: true,
1711    native_header_libs: ["mysdk_mynativeheaders@current"],
1712}
1713`),
1714		checkAllCopyRules(`
1715include/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
1718`),
1719	)
1720}
1721
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,
1753    compile_multilib: "both",
1754    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,
1767    compile_multilib: "both",
1768    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,
1782    compile_multilib: "both",
1783    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,
1797    compile_multilib: "both",
1798    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,
1813    compile_multilib: "both",
1814    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,
1828    compile_multilib: "both",
1829    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,
1877    compile_multilib: "both",
1878    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,
1901    compile_multilib: "both",
1902    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}
1928
1929func TestStubsLibrary(t *testing.T) {
1930	result := testSdkWithCc(t, `
1931		sdk {
1932			name: "mysdk",
1933			native_shared_libs: ["stubslib"],
1934		}
1935
1936		cc_library {
1937			name: "internaldep",
1938		}
1939
1940		cc_library {
1941			name: "stubslib",
1942			shared_libs: ["internaldep"],
1943			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,
1958    compile_multilib: "both",
1959    stubs: {
1960        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,
1975    compile_multilib: "both",
1976    stubs: {
1977        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}
1995
1996func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
1997	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,
2029    compile_multilib: "both",
2030    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,
2053    compile_multilib: "both",
2054    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}
2080
2081func TestUniqueHostSoname(t *testing.T) {
2082	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,
2106    compile_multilib: "both",
2107    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,
2128    compile_multilib: "both",
2129    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}
2159