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 = android.MockFS{
25	"Test.cpp":                        nil,
26	"myinclude/Test.h":                nil,
27	"myinclude-android/AndroidTest.h": nil,
28	"myinclude-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) *android.TestResult {
36	t.Helper()
37	return testSdkWithFs(t, bp, ccTestFs)
38}
39
40// Contains tests for SDK members provided by the cc package.
41
42func TestSingleDeviceOsAssumption(t *testing.T) {
43	// Mock a module with DeviceSupported() == true.
44	s := &sdk{}
45	android.InitAndroidArchModule(s, android.DeviceSupported, android.MultilibCommon)
46
47	osTypes := s.getPossibleOsTypes()
48	if len(osTypes) != 1 {
49		// The snapshot generation assumes there is a single device OS. If more are
50		// added it might need to disable them by default, like it does for host
51		// OS'es.
52		t.Errorf("expected a single device OS, got %v", osTypes)
53	}
54}
55
56func TestSdkIsCompileMultilibBoth(t *testing.T) {
57	result := testSdkWithCc(t, `
58		sdk {
59			name: "mysdk",
60			native_shared_libs: ["sdkmember"],
61		}
62
63		cc_library_shared {
64			name: "sdkmember",
65			srcs: ["Test.cpp"],
66			stl: "none",
67		}
68	`)
69
70	armOutput := result.Module("sdkmember", "android_arm_armv7-a-neon_shared").(*cc.Module).OutputFile()
71	arm64Output := result.Module("sdkmember", "android_arm64_armv8-a_shared").(*cc.Module).OutputFile()
72
73	var inputs []string
74	buildParams := result.Module("mysdk", android.CommonOS.Name).BuildParamsForTests()
75	for _, bp := range buildParams {
76		if bp.Input != nil {
77			inputs = append(inputs, bp.Input.String())
78		}
79	}
80
81	// ensure that both 32/64 outputs are inputs of the sdk snapshot
82	ensureListContains(t, inputs, armOutput.String())
83	ensureListContains(t, inputs, arm64Output.String())
84}
85
86func TestSdkCompileMultilibOverride(t *testing.T) {
87	result := testSdkWithCc(t, `
88		sdk {
89			name: "mysdk",
90			host_supported: true,
91			native_shared_libs: ["sdkmember"],
92			compile_multilib: "64",
93		}
94
95		cc_library_shared {
96			name: "sdkmember",
97			host_supported: true,
98			srcs: ["Test.cpp"],
99			stl: "none",
100			compile_multilib: "64",
101		}
102	`)
103
104	CheckSnapshot(t, result, "mysdk", "",
105		checkUnversionedAndroidBpContents(`
106// This is auto-generated. DO NOT EDIT.
107
108cc_prebuilt_library_shared {
109    name: "sdkmember",
110    prefer: false,
111    visibility: ["//visibility:public"],
112    apex_available: ["//apex_available:platform"],
113    host_supported: true,
114    stl: "none",
115    compile_multilib: "64",
116    target: {
117        host: {
118            enabled: false,
119        },
120        android_arm64: {
121            srcs: ["android/arm64/lib/sdkmember.so"],
122        },
123        linux_glibc_x86_64: {
124            enabled: true,
125            srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
126        },
127    },
128}
129`),
130		checkVersionedAndroidBpContents(`
131// This is auto-generated. DO NOT EDIT.
132
133cc_prebuilt_library_shared {
134    name: "mysdk_sdkmember@current",
135    sdk_member_name: "sdkmember",
136    visibility: ["//visibility:public"],
137    apex_available: ["//apex_available:platform"],
138    host_supported: true,
139    installable: false,
140    stl: "none",
141    compile_multilib: "64",
142    target: {
143        host: {
144            enabled: false,
145        },
146        android_arm64: {
147            srcs: ["android/arm64/lib/sdkmember.so"],
148        },
149        linux_glibc_x86_64: {
150            enabled: true,
151            srcs: ["linux_glibc/x86_64/lib/sdkmember.so"],
152        },
153    },
154}
155
156sdk_snapshot {
157    name: "mysdk@current",
158    visibility: ["//visibility:public"],
159    host_supported: true,
160    compile_multilib: "64",
161    native_shared_libs: ["mysdk_sdkmember@current"],
162    target: {
163        host: {
164            enabled: false,
165        },
166        linux_glibc_x86_64: {
167            enabled: true,
168        },
169    },
170}
171`),
172		checkAllCopyRules(`
173.intermediates/sdkmember/android_arm64_armv8-a_shared/sdkmember.so -> android/arm64/lib/sdkmember.so
174.intermediates/sdkmember/linux_glibc_x86_64_shared/sdkmember.so -> linux_glibc/x86_64/lib/sdkmember.so
175`))
176}
177
178func TestBasicSdkWithCc(t *testing.T) {
179	result := testSdkWithCc(t, `
180		sdk {
181			name: "mysdk",
182			native_shared_libs: ["sdkmember"],
183		}
184
185		cc_library_shared {
186			name: "sdkmember",
187			system_shared_libs: [],
188			stl: "none",
189			apex_available: ["mysdkapex"],
190		}
191
192		sdk_snapshot {
193			name: "mysdk@1",
194			native_shared_libs: ["sdkmember_mysdk@1"],
195		}
196
197		sdk_snapshot {
198			name: "mysdk@2",
199			native_shared_libs: ["sdkmember_mysdk@2"],
200		}
201
202		cc_prebuilt_library_shared {
203			name: "sdkmember",
204			srcs: ["libfoo.so"],
205			prefer: false,
206			system_shared_libs: [],
207			stl: "none",
208		}
209
210		cc_prebuilt_library_shared {
211			name: "sdkmember_mysdk@1",
212			sdk_member_name: "sdkmember",
213			srcs: ["libfoo.so"],
214			system_shared_libs: [],
215			stl: "none",
216			// TODO: remove //apex_available:platform
217			apex_available: [
218				"//apex_available:platform",
219				"myapex",
220			],
221		}
222
223		cc_prebuilt_library_shared {
224			name: "sdkmember_mysdk@2",
225			sdk_member_name: "sdkmember",
226			srcs: ["libfoo.so"],
227			system_shared_libs: [],
228			stl: "none",
229			// TODO: remove //apex_available:platform
230			apex_available: [
231				"//apex_available:platform",
232				"myapex2",
233			],
234		}
235
236		cc_library_shared {
237			name: "mycpplib",
238			srcs: ["Test.cpp"],
239			shared_libs: ["sdkmember"],
240			system_shared_libs: [],
241			stl: "none",
242			apex_available: [
243				"myapex",
244				"myapex2",
245			],
246		}
247
248		apex {
249			name: "myapex",
250			native_shared_libs: ["mycpplib"],
251			uses_sdks: ["mysdk@1"],
252			key: "myapex.key",
253			certificate: ":myapex.cert",
254			updatable: false,
255		}
256
257		apex {
258			name: "myapex2",
259			native_shared_libs: ["mycpplib"],
260			uses_sdks: ["mysdk@2"],
261			key: "myapex.key",
262			certificate: ":myapex.cert",
263			updatable: false,
264		}
265
266		apex {
267			name: "mysdkapex",
268			native_shared_libs: ["sdkmember"],
269			key: "myapex.key",
270			certificate: ":myapex.cert",
271			updatable: false,
272		}
273	`)
274
275	sdkMemberV1 := result.ModuleForTests("sdkmember_mysdk@1", "android_arm64_armv8-a_shared_apex10000_mysdk_1").Rule("toc").Output
276	sdkMemberV2 := result.ModuleForTests("sdkmember_mysdk@2", "android_arm64_armv8-a_shared_apex10000_mysdk_2").Rule("toc").Output
277
278	cpplibForMyApex := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_apex10000_mysdk_1")
279	cpplibForMyApex2 := result.ModuleForTests("mycpplib", "android_arm64_armv8-a_shared_apex10000_mysdk_2")
280
281	// Depending on the uses_sdks value, different libs are linked
282	ensureListContains(t, pathsToStrings(cpplibForMyApex.Rule("ld").Implicits), sdkMemberV1.String())
283	ensureListContains(t, pathsToStrings(cpplibForMyApex2.Rule("ld").Implicits), sdkMemberV2.String())
284}
285
286// Make sure the sdk can use host specific cc libraries static/shared and both.
287func TestHostSdkWithCc(t *testing.T) {
288	testSdkWithCc(t, `
289		sdk {
290			name: "mysdk",
291			device_supported: false,
292			host_supported: true,
293			native_shared_libs: ["sdkshared"],
294			native_static_libs: ["sdkstatic"],
295		}
296
297		cc_library_host_shared {
298			name: "sdkshared",
299			stl: "none",
300		}
301
302		cc_library_host_static {
303			name: "sdkstatic",
304			stl: "none",
305		}
306	`)
307}
308
309// Make sure the sdk can use cc libraries static/shared and both.
310func TestSdkWithCc(t *testing.T) {
311	testSdkWithCc(t, `
312		sdk {
313			name: "mysdk",
314			native_shared_libs: ["sdkshared", "sdkboth1"],
315			native_static_libs: ["sdkstatic", "sdkboth2"],
316		}
317
318		cc_library_shared {
319			name: "sdkshared",
320			stl: "none",
321		}
322
323		cc_library_static {
324			name: "sdkstatic",
325			stl: "none",
326		}
327
328		cc_library {
329			name: "sdkboth1",
330			stl: "none",
331		}
332
333		cc_library {
334			name: "sdkboth2",
335			stl: "none",
336		}
337	`)
338}
339
340func TestSnapshotWithObject(t *testing.T) {
341	result := testSdkWithCc(t, `
342		sdk {
343			name: "mysdk",
344			native_objects: ["crtobj"],
345		}
346
347		cc_object {
348			name: "crtobj",
349			stl: "none",
350			sanitize: {
351				never: true,
352			},
353		}
354	`)
355
356	CheckSnapshot(t, result, "mysdk", "",
357		checkUnversionedAndroidBpContents(`
358// This is auto-generated. DO NOT EDIT.
359
360cc_prebuilt_object {
361    name: "crtobj",
362    prefer: false,
363    visibility: ["//visibility:public"],
364    apex_available: ["//apex_available:platform"],
365    stl: "none",
366    compile_multilib: "both",
367    sanitize: {
368        never: true,
369    },
370    arch: {
371        arm64: {
372            srcs: ["arm64/lib/crtobj.o"],
373        },
374        arm: {
375            srcs: ["arm/lib/crtobj.o"],
376        },
377    },
378}
379`),
380		// Make sure that the generated sdk_snapshot uses the native_objects property.
381		checkVersionedAndroidBpContents(`
382// This is auto-generated. DO NOT EDIT.
383
384cc_prebuilt_object {
385    name: "mysdk_crtobj@current",
386    sdk_member_name: "crtobj",
387    visibility: ["//visibility:public"],
388    apex_available: ["//apex_available:platform"],
389    stl: "none",
390    compile_multilib: "both",
391    sanitize: {
392        never: true,
393    },
394    arch: {
395        arm64: {
396            srcs: ["arm64/lib/crtobj.o"],
397        },
398        arm: {
399            srcs: ["arm/lib/crtobj.o"],
400        },
401    },
402}
403
404sdk_snapshot {
405    name: "mysdk@current",
406    visibility: ["//visibility:public"],
407    native_objects: ["mysdk_crtobj@current"],
408}
409`),
410		checkAllCopyRules(`
411.intermediates/crtobj/android_arm64_armv8-a/crtobj.o -> arm64/lib/crtobj.o
412.intermediates/crtobj/android_arm_armv7-a-neon/crtobj.o -> arm/lib/crtobj.o
413`),
414	)
415}
416
417func TestSnapshotWithCcDuplicateHeaders(t *testing.T) {
418	result := testSdkWithCc(t, `
419		sdk {
420			name: "mysdk",
421			native_shared_libs: ["mynativelib1", "mynativelib2"],
422		}
423
424		cc_library_shared {
425			name: "mynativelib1",
426			srcs: [
427				"Test.cpp",
428			],
429			export_include_dirs: ["myinclude"],
430			stl: "none",
431		}
432
433		cc_library_shared {
434			name: "mynativelib2",
435			srcs: [
436				"Test.cpp",
437			],
438			export_include_dirs: ["myinclude"],
439			stl: "none",
440		}
441	`)
442
443	CheckSnapshot(t, result, "mysdk", "",
444		checkAllCopyRules(`
445myinclude/Test.h -> include/myinclude/Test.h
446.intermediates/mynativelib1/android_arm64_armv8-a_shared/mynativelib1.so -> arm64/lib/mynativelib1.so
447.intermediates/mynativelib1/android_arm_armv7-a-neon_shared/mynativelib1.so -> arm/lib/mynativelib1.so
448.intermediates/mynativelib2/android_arm64_armv8-a_shared/mynativelib2.so -> arm64/lib/mynativelib2.so
449.intermediates/mynativelib2/android_arm_armv7-a-neon_shared/mynativelib2.so -> arm/lib/mynativelib2.so
450`),
451	)
452}
453
454func TestSnapshotWithCcExportGeneratedHeaders(t *testing.T) {
455	result := testSdkWithCc(t, `
456		sdk {
457			name: "mysdk",
458			native_shared_libs: ["mynativelib"],
459		}
460
461		cc_library_shared {
462			name: "mynativelib",
463			srcs: [
464				"Test.cpp",
465			],
466			generated_headers: [
467				"generated_foo",
468			],
469			export_generated_headers: [
470				"generated_foo",
471			],
472			export_include_dirs: ["myinclude"],
473			stl: "none",
474		}
475
476		genrule {
477			name: "generated_foo",
478			cmd: "generate-foo",
479			out: [
480				"generated_foo/protos/foo/bar.h",
481			],
482			export_include_dirs: [
483				".",
484				"protos",
485			],
486		}
487	`)
488
489	// TODO(b/183322862): Remove this and fix the issue.
490	errorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(`module source path "snapshot/include_gen/generated_foo/gen/protos" does not exist`)
491
492	CheckSnapshot(t, result, "mysdk", "",
493		checkUnversionedAndroidBpContents(`
494// This is auto-generated. DO NOT EDIT.
495
496cc_prebuilt_library_shared {
497    name: "mynativelib",
498    prefer: false,
499    visibility: ["//visibility:public"],
500    apex_available: ["//apex_available:platform"],
501    stl: "none",
502    compile_multilib: "both",
503    export_include_dirs: [
504        "include/myinclude",
505        "include_gen/generated_foo/gen",
506        "include_gen/generated_foo/gen/protos",
507    ],
508    arch: {
509        arm64: {
510            srcs: ["arm64/lib/mynativelib.so"],
511        },
512        arm: {
513            srcs: ["arm/lib/mynativelib.so"],
514        },
515    },
516}
517`),
518		checkAllCopyRules(`
519myinclude/Test.h -> include/myinclude/Test.h
520.intermediates/generated_foo/gen/generated_foo/protos/foo/bar.h -> include_gen/generated_foo/gen/generated_foo/protos/foo/bar.h
521.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
522.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
523`),
524		snapshotTestErrorHandler(checkSnapshotWithoutSource, errorHandler),
525		snapshotTestErrorHandler(checkSnapshotWithSourcePreferred, errorHandler),
526		snapshotTestErrorHandler(checkSnapshotPreferredWithSource, errorHandler),
527	)
528}
529
530// Verify that when the shared library has some common and some arch specific
531// properties that the generated snapshot is optimized properly. Substruct
532// handling is tested with the sanitize clauses (but note there's a lot of
533// built-in logic in sanitize.go that can affect those flags).
534func TestSnapshotWithCcSharedLibraryCommonProperties(t *testing.T) {
535	result := testSdkWithCc(t, `
536		sdk {
537			name: "mysdk",
538			native_shared_libs: ["mynativelib"],
539		}
540
541		cc_library_shared {
542			name: "mynativelib",
543			srcs: [
544				"Test.cpp",
545				"aidl/foo/bar/Test.aidl",
546			],
547			export_include_dirs: ["myinclude"],
548			sanitize: {
549				fuzzer: false,
550				integer_overflow: true,
551				diag: { undefined: false },
552			},
553			arch: {
554				arm64: {
555					export_system_include_dirs: ["arm64/include"],
556					sanitize: {
557						integer_overflow: false,
558					},
559				},
560			},
561			stl: "none",
562		}
563	`)
564
565	CheckSnapshot(t, result, "mysdk", "",
566		checkUnversionedAndroidBpContents(`
567// This is auto-generated. DO NOT EDIT.
568
569cc_prebuilt_library_shared {
570    name: "mynativelib",
571    prefer: false,
572    visibility: ["//visibility:public"],
573    apex_available: ["//apex_available:platform"],
574    stl: "none",
575    compile_multilib: "both",
576    export_include_dirs: ["include/myinclude"],
577    sanitize: {
578        fuzzer: false,
579        diag: {
580            undefined: false,
581        },
582    },
583    arch: {
584        arm64: {
585            srcs: ["arm64/lib/mynativelib.so"],
586            export_system_include_dirs: ["arm64/include/arm64/include"],
587            sanitize: {
588                integer_overflow: false,
589            },
590        },
591        arm: {
592            srcs: ["arm/lib/mynativelib.so"],
593            sanitize: {
594                integer_overflow: true,
595            },
596        },
597    },
598}
599`),
600		checkAllCopyRules(`
601myinclude/Test.h -> include/myinclude/Test.h
602.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
603arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
604.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so`),
605	)
606}
607
608func TestSnapshotWithCcBinary(t *testing.T) {
609	result := testSdkWithCc(t, `
610		module_exports {
611			name: "mymodule_exports",
612			native_binaries: ["mynativebinary"],
613		}
614
615		cc_binary {
616			name: "mynativebinary",
617			srcs: [
618				"Test.cpp",
619			],
620			compile_multilib: "both",
621		}
622	`)
623
624	CheckSnapshot(t, result, "mymodule_exports", "",
625		checkUnversionedAndroidBpContents(`
626// This is auto-generated. DO NOT EDIT.
627
628cc_prebuilt_binary {
629    name: "mynativebinary",
630    prefer: false,
631    visibility: ["//visibility:public"],
632    apex_available: ["//apex_available:platform"],
633    compile_multilib: "both",
634    arch: {
635        arm64: {
636            srcs: ["arm64/bin/mynativebinary"],
637        },
638        arm: {
639            srcs: ["arm/bin/mynativebinary"],
640        },
641    },
642}
643`),
644		// Make sure that the generated sdk_snapshot uses the native_binaries property.
645		checkVersionedAndroidBpContents(`
646// This is auto-generated. DO NOT EDIT.
647
648cc_prebuilt_binary {
649    name: "mymodule_exports_mynativebinary@current",
650    sdk_member_name: "mynativebinary",
651    visibility: ["//visibility:public"],
652    apex_available: ["//apex_available:platform"],
653    installable: false,
654    compile_multilib: "both",
655    arch: {
656        arm64: {
657            srcs: ["arm64/bin/mynativebinary"],
658        },
659        arm: {
660            srcs: ["arm/bin/mynativebinary"],
661        },
662    },
663}
664
665module_exports_snapshot {
666    name: "mymodule_exports@current",
667    visibility: ["//visibility:public"],
668    native_binaries: ["mymodule_exports_mynativebinary@current"],
669}
670`),
671		checkAllCopyRules(`
672.intermediates/mynativebinary/android_arm64_armv8-a/mynativebinary -> arm64/bin/mynativebinary
673.intermediates/mynativebinary/android_arm_armv7-a-neon/mynativebinary -> arm/bin/mynativebinary
674`),
675	)
676}
677
678func TestMultipleHostOsTypesSnapshotWithCcBinary(t *testing.T) {
679	result := testSdkWithCc(t, `
680		module_exports {
681			name: "myexports",
682			device_supported: false,
683			host_supported: true,
684			native_binaries: ["mynativebinary"],
685			target: {
686				windows: {
687					enabled: true,
688				},
689			},
690		}
691
692		cc_binary {
693			name: "mynativebinary",
694			device_supported: false,
695			host_supported: true,
696			srcs: [
697				"Test.cpp",
698			],
699			compile_multilib: "both",
700			stl: "none",
701			target: {
702				windows: {
703					enabled: true,
704				},
705			},
706		}
707	`)
708
709	CheckSnapshot(t, result, "myexports", "",
710		checkUnversionedAndroidBpContents(`
711// This is auto-generated. DO NOT EDIT.
712
713cc_prebuilt_binary {
714    name: "mynativebinary",
715    prefer: false,
716    visibility: ["//visibility:public"],
717    apex_available: ["//apex_available:platform"],
718    device_supported: false,
719    host_supported: true,
720    stl: "none",
721    target: {
722        host: {
723            enabled: false,
724        },
725        linux_glibc: {
726            compile_multilib: "both",
727        },
728        linux_glibc_x86_64: {
729            enabled: true,
730            srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
731        },
732        linux_glibc_x86: {
733            enabled: true,
734            srcs: ["linux_glibc/x86/bin/mynativebinary"],
735        },
736        windows: {
737            compile_multilib: "64",
738        },
739        windows_x86_64: {
740            enabled: true,
741            srcs: ["windows/x86_64/bin/mynativebinary.exe"],
742        },
743    },
744}
745`),
746		checkVersionedAndroidBpContents(`
747// This is auto-generated. DO NOT EDIT.
748
749cc_prebuilt_binary {
750    name: "myexports_mynativebinary@current",
751    sdk_member_name: "mynativebinary",
752    visibility: ["//visibility:public"],
753    apex_available: ["//apex_available:platform"],
754    device_supported: false,
755    host_supported: true,
756    installable: false,
757    stl: "none",
758    target: {
759        host: {
760            enabled: false,
761        },
762        linux_glibc: {
763            compile_multilib: "both",
764        },
765        linux_glibc_x86_64: {
766            enabled: true,
767            srcs: ["linux_glibc/x86_64/bin/mynativebinary"],
768        },
769        linux_glibc_x86: {
770            enabled: true,
771            srcs: ["linux_glibc/x86/bin/mynativebinary"],
772        },
773        windows: {
774            compile_multilib: "64",
775        },
776        windows_x86_64: {
777            enabled: true,
778            srcs: ["windows/x86_64/bin/mynativebinary.exe"],
779        },
780    },
781}
782
783module_exports_snapshot {
784    name: "myexports@current",
785    visibility: ["//visibility:public"],
786    device_supported: false,
787    host_supported: true,
788    native_binaries: ["myexports_mynativebinary@current"],
789    target: {
790        windows: {
791            compile_multilib: "64",
792        },
793        host: {
794            enabled: false,
795        },
796        linux_glibc_x86_64: {
797            enabled: true,
798        },
799        linux_glibc_x86: {
800            enabled: true,
801        },
802        windows_x86_64: {
803            enabled: true,
804        },
805    },
806}
807`),
808		checkAllCopyRules(`
809.intermediates/mynativebinary/linux_glibc_x86_64/mynativebinary -> linux_glibc/x86_64/bin/mynativebinary
810.intermediates/mynativebinary/linux_glibc_x86/mynativebinary -> linux_glibc/x86/bin/mynativebinary
811.intermediates/mynativebinary/windows_x86_64/mynativebinary.exe -> windows/x86_64/bin/mynativebinary.exe
812`),
813	)
814}
815
816func TestSnapshotWithSingleHostOsType(t *testing.T) {
817	result := android.GroupFixturePreparers(
818		prepareForSdkTest,
819		ccTestFs.AddToFixture(),
820		cc.PrepareForTestOnLinuxBionic,
821		android.FixtureModifyConfig(func(config android.Config) {
822			config.Targets[android.LinuxBionic] = []android.Target{
823				{android.LinuxBionic, android.Arch{ArchType: android.X86_64}, android.NativeBridgeDisabled, "", "", false},
824			}
825		}),
826	).RunTestWithBp(t, `
827		cc_defaults {
828			name: "mydefaults",
829			device_supported: false,
830			host_supported: true,
831			compile_multilib: "64",
832			target: {
833				host: {
834					enabled: false,
835				},
836				linux_bionic: {
837					enabled: true,
838				},
839			},
840		}
841
842		module_exports {
843			name: "myexports",
844			defaults: ["mydefaults"],
845			native_shared_libs: ["mynativelib"],
846			native_binaries: ["mynativebinary"],
847			compile_multilib: "64",  // The built-in default in sdk.go overrides mydefaults.
848		}
849
850		cc_library {
851			name: "mynativelib",
852			defaults: ["mydefaults"],
853			srcs: [
854				"Test.cpp",
855			],
856			stl: "none",
857		}
858
859		cc_binary {
860			name: "mynativebinary",
861			defaults: ["mydefaults"],
862			srcs: [
863				"Test.cpp",
864			],
865			stl: "none",
866		}
867	`)
868
869	CheckSnapshot(t, result, "myexports", "",
870		checkUnversionedAndroidBpContents(`
871// This is auto-generated. DO NOT EDIT.
872
873cc_prebuilt_binary {
874    name: "mynativebinary",
875    prefer: false,
876    visibility: ["//visibility:public"],
877    apex_available: ["//apex_available:platform"],
878    device_supported: false,
879    host_supported: true,
880    stl: "none",
881    compile_multilib: "64",
882    target: {
883        host: {
884            enabled: false,
885        },
886        linux_bionic_x86_64: {
887            enabled: true,
888            srcs: ["x86_64/bin/mynativebinary"],
889        },
890    },
891}
892
893cc_prebuilt_library_shared {
894    name: "mynativelib",
895    prefer: false,
896    visibility: ["//visibility:public"],
897    apex_available: ["//apex_available:platform"],
898    device_supported: false,
899    host_supported: true,
900    stl: "none",
901    compile_multilib: "64",
902    target: {
903        host: {
904            enabled: false,
905        },
906        linux_bionic_x86_64: {
907            enabled: true,
908            srcs: ["x86_64/lib/mynativelib.so"],
909        },
910    },
911}
912`),
913		checkVersionedAndroidBpContents(`
914// This is auto-generated. DO NOT EDIT.
915
916cc_prebuilt_binary {
917    name: "myexports_mynativebinary@current",
918    sdk_member_name: "mynativebinary",
919    visibility: ["//visibility:public"],
920    apex_available: ["//apex_available:platform"],
921    device_supported: false,
922    host_supported: true,
923    installable: false,
924    stl: "none",
925    compile_multilib: "64",
926    target: {
927        host: {
928            enabled: false,
929        },
930        linux_bionic_x86_64: {
931            enabled: true,
932            srcs: ["x86_64/bin/mynativebinary"],
933        },
934    },
935}
936
937cc_prebuilt_library_shared {
938    name: "myexports_mynativelib@current",
939    sdk_member_name: "mynativelib",
940    visibility: ["//visibility:public"],
941    apex_available: ["//apex_available:platform"],
942    device_supported: false,
943    host_supported: true,
944    installable: false,
945    stl: "none",
946    compile_multilib: "64",
947    target: {
948        host: {
949            enabled: false,
950        },
951        linux_bionic_x86_64: {
952            enabled: true,
953            srcs: ["x86_64/lib/mynativelib.so"],
954        },
955    },
956}
957
958module_exports_snapshot {
959    name: "myexports@current",
960    visibility: ["//visibility:public"],
961    device_supported: false,
962    host_supported: true,
963    compile_multilib: "64",
964    native_binaries: ["myexports_mynativebinary@current"],
965    native_shared_libs: ["myexports_mynativelib@current"],
966    target: {
967        host: {
968            enabled: false,
969        },
970        linux_bionic_x86_64: {
971            enabled: true,
972        },
973    },
974}
975`),
976		checkAllCopyRules(`
977.intermediates/mynativebinary/linux_bionic_x86_64/mynativebinary -> x86_64/bin/mynativebinary
978.intermediates/mynativelib/linux_bionic_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
979`),
980	)
981}
982
983// Test that we support the necessary flags for the linker binary, which is
984// special in several ways.
985func TestSnapshotWithCcStaticNocrtBinary(t *testing.T) {
986	result := testSdkWithCc(t, `
987		module_exports {
988			name: "mymodule_exports",
989			host_supported: true,
990			device_supported: false,
991			native_binaries: ["linker"],
992		}
993
994		cc_binary {
995			name: "linker",
996			host_supported: true,
997			static_executable: true,
998			nocrt: true,
999			stl: "none",
1000			srcs: [
1001				"Test.cpp",
1002			],
1003			compile_multilib: "both",
1004		}
1005	`)
1006
1007	CheckSnapshot(t, result, "mymodule_exports", "",
1008		checkUnversionedAndroidBpContents(`
1009// This is auto-generated. DO NOT EDIT.
1010
1011cc_prebuilt_binary {
1012    name: "linker",
1013    prefer: false,
1014    visibility: ["//visibility:public"],
1015    apex_available: ["//apex_available:platform"],
1016    device_supported: false,
1017    host_supported: true,
1018    stl: "none",
1019    compile_multilib: "both",
1020    static_executable: true,
1021    nocrt: true,
1022    target: {
1023        host: {
1024            enabled: false,
1025        },
1026        linux_glibc_x86_64: {
1027            enabled: true,
1028            srcs: ["x86_64/bin/linker"],
1029        },
1030        linux_glibc_x86: {
1031            enabled: true,
1032            srcs: ["x86/bin/linker"],
1033        },
1034    },
1035}
1036`),
1037		checkVersionedAndroidBpContents(`
1038// This is auto-generated. DO NOT EDIT.
1039
1040cc_prebuilt_binary {
1041    name: "mymodule_exports_linker@current",
1042    sdk_member_name: "linker",
1043    visibility: ["//visibility:public"],
1044    apex_available: ["//apex_available:platform"],
1045    device_supported: false,
1046    host_supported: true,
1047    installable: false,
1048    stl: "none",
1049    compile_multilib: "both",
1050    static_executable: true,
1051    nocrt: true,
1052    target: {
1053        host: {
1054            enabled: false,
1055        },
1056        linux_glibc_x86_64: {
1057            enabled: true,
1058            srcs: ["x86_64/bin/linker"],
1059        },
1060        linux_glibc_x86: {
1061            enabled: true,
1062            srcs: ["x86/bin/linker"],
1063        },
1064    },
1065}
1066
1067module_exports_snapshot {
1068    name: "mymodule_exports@current",
1069    visibility: ["//visibility:public"],
1070    device_supported: false,
1071    host_supported: true,
1072    native_binaries: ["mymodule_exports_linker@current"],
1073    target: {
1074        host: {
1075            enabled: false,
1076        },
1077        linux_glibc_x86_64: {
1078            enabled: true,
1079        },
1080        linux_glibc_x86: {
1081            enabled: true,
1082        },
1083    },
1084}
1085`),
1086		checkAllCopyRules(`
1087.intermediates/linker/linux_glibc_x86_64/linker -> x86_64/bin/linker
1088.intermediates/linker/linux_glibc_x86/linker -> x86/bin/linker
1089`),
1090	)
1091}
1092
1093func TestSnapshotWithCcSharedLibrary(t *testing.T) {
1094	result := testSdkWithCc(t, `
1095		sdk {
1096			name: "mysdk",
1097			native_shared_libs: ["mynativelib"],
1098		}
1099
1100		cc_library_shared {
1101			name: "mynativelib",
1102			srcs: [
1103				"Test.cpp",
1104				"aidl/foo/bar/Test.aidl",
1105			],
1106			apex_available: ["apex1", "apex2"],
1107			export_include_dirs: ["myinclude"],
1108			aidl: {
1109				export_aidl_headers: true,
1110			},
1111			stl: "none",
1112		}
1113	`)
1114
1115	CheckSnapshot(t, result, "mysdk", "",
1116		checkUnversionedAndroidBpContents(`
1117// This is auto-generated. DO NOT EDIT.
1118
1119cc_prebuilt_library_shared {
1120    name: "mynativelib",
1121    prefer: false,
1122    visibility: ["//visibility:public"],
1123    apex_available: [
1124        "apex1",
1125        "apex2",
1126    ],
1127    stl: "none",
1128    compile_multilib: "both",
1129    export_include_dirs: ["include/myinclude"],
1130    arch: {
1131        arm64: {
1132            srcs: ["arm64/lib/mynativelib.so"],
1133            export_include_dirs: ["arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl"],
1134        },
1135        arm: {
1136            srcs: ["arm/lib/mynativelib.so"],
1137            export_include_dirs: ["arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl"],
1138        },
1139    },
1140}
1141`),
1142		checkAllCopyRules(`
1143myinclude/Test.h -> include/myinclude/Test.h
1144.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1145.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/Test.h
1146.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BnTest.h
1147.intermediates/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_shared/gen/aidl/aidl/foo/bar/BpTest.h
1148.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
1149.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/Test.h
1150.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BnTest.h
1151.intermediates/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_shared/gen/aidl/aidl/foo/bar/BpTest.h
1152`),
1153	)
1154}
1155
1156func TestSnapshotWithCcSharedLibrarySharedLibs(t *testing.T) {
1157	result := testSdkWithCc(t, `
1158		sdk {
1159			name: "mysdk",
1160			native_shared_libs: [
1161				"mynativelib",
1162				"myothernativelib",
1163				"mysystemnativelib",
1164			],
1165		}
1166
1167		cc_library {
1168			name: "mysystemnativelib",
1169			srcs: [
1170				"Test.cpp",
1171			],
1172			stl: "none",
1173		}
1174
1175		cc_library_shared {
1176			name: "myothernativelib",
1177			srcs: [
1178				"Test.cpp",
1179			],
1180			system_shared_libs: [
1181				// A reference to a library that is not an sdk member. Uses libm as that
1182				// is in the default set of modules available to this test and so is available
1183				// both here and also when the generated Android.bp file is tested in
1184				// CheckSnapshot(). This ensures that the system_shared_libs property correctly
1185				// handles references to modules that are not sdk members.
1186				"libm",
1187			],
1188			stl: "none",
1189		}
1190
1191		cc_library {
1192			name: "mynativelib",
1193			srcs: [
1194				"Test.cpp",
1195			],
1196			shared_libs: [
1197				// A reference to another sdk member.
1198				"myothernativelib",
1199			],
1200			target: {
1201				android: {
1202					shared: {
1203						shared_libs: [
1204							// A reference to a library that is not an sdk member. The libc library
1205							// is used here to check that the shared_libs property is handled correctly
1206							// in a similar way to how libm is used to check system_shared_libs above.
1207							"libc",
1208						],
1209					},
1210				},
1211			},
1212			stl: "none",
1213		}
1214	`)
1215
1216	CheckSnapshot(t, result, "mysdk", "",
1217		checkUnversionedAndroidBpContents(`
1218// This is auto-generated. DO NOT EDIT.
1219
1220cc_prebuilt_library_shared {
1221    name: "mynativelib",
1222    prefer: false,
1223    visibility: ["//visibility:public"],
1224    apex_available: ["//apex_available:platform"],
1225    stl: "none",
1226    compile_multilib: "both",
1227    shared_libs: [
1228        "myothernativelib",
1229        "libc",
1230    ],
1231    arch: {
1232        arm64: {
1233            srcs: ["arm64/lib/mynativelib.so"],
1234        },
1235        arm: {
1236            srcs: ["arm/lib/mynativelib.so"],
1237        },
1238    },
1239}
1240
1241cc_prebuilt_library_shared {
1242    name: "myothernativelib",
1243    prefer: false,
1244    visibility: ["//visibility:public"],
1245    apex_available: ["//apex_available:platform"],
1246    stl: "none",
1247    compile_multilib: "both",
1248    system_shared_libs: ["libm"],
1249    arch: {
1250        arm64: {
1251            srcs: ["arm64/lib/myothernativelib.so"],
1252        },
1253        arm: {
1254            srcs: ["arm/lib/myothernativelib.so"],
1255        },
1256    },
1257}
1258
1259cc_prebuilt_library_shared {
1260    name: "mysystemnativelib",
1261    prefer: false,
1262    visibility: ["//visibility:public"],
1263    apex_available: ["//apex_available:platform"],
1264    stl: "none",
1265    compile_multilib: "both",
1266    arch: {
1267        arm64: {
1268            srcs: ["arm64/lib/mysystemnativelib.so"],
1269        },
1270        arm: {
1271            srcs: ["arm/lib/mysystemnativelib.so"],
1272        },
1273    },
1274}
1275`),
1276		checkAllCopyRules(`
1277.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1278.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
1279.intermediates/myothernativelib/android_arm64_armv8-a_shared/myothernativelib.so -> arm64/lib/myothernativelib.so
1280.intermediates/myothernativelib/android_arm_armv7-a-neon_shared/myothernativelib.so -> arm/lib/myothernativelib.so
1281.intermediates/mysystemnativelib/android_arm64_armv8-a_shared/mysystemnativelib.so -> arm64/lib/mysystemnativelib.so
1282.intermediates/mysystemnativelib/android_arm_armv7-a-neon_shared/mysystemnativelib.so -> arm/lib/mysystemnativelib.so
1283`),
1284	)
1285}
1286
1287func TestHostSnapshotWithCcSharedLibrary(t *testing.T) {
1288	result := testSdkWithCc(t, `
1289		sdk {
1290			name: "mysdk",
1291			device_supported: false,
1292			host_supported: true,
1293			native_shared_libs: ["mynativelib"],
1294		}
1295
1296		cc_library_shared {
1297			name: "mynativelib",
1298			device_supported: false,
1299			host_supported: true,
1300			srcs: [
1301				"Test.cpp",
1302				"aidl/foo/bar/Test.aidl",
1303			],
1304			export_include_dirs: ["myinclude"],
1305			aidl: {
1306				export_aidl_headers: true,
1307			},
1308			stl: "none",
1309			sdk_version: "minimum",
1310		}
1311	`)
1312
1313	CheckSnapshot(t, result, "mysdk", "",
1314		checkUnversionedAndroidBpContents(`
1315// This is auto-generated. DO NOT EDIT.
1316
1317cc_prebuilt_library_shared {
1318    name: "mynativelib",
1319    prefer: false,
1320    visibility: ["//visibility:public"],
1321    apex_available: ["//apex_available:platform"],
1322    device_supported: false,
1323    host_supported: true,
1324    sdk_version: "minimum",
1325    stl: "none",
1326    compile_multilib: "both",
1327    export_include_dirs: ["include/myinclude"],
1328    target: {
1329        host: {
1330            enabled: false,
1331        },
1332        linux_glibc_x86_64: {
1333            enabled: true,
1334            srcs: ["x86_64/lib/mynativelib.so"],
1335            export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl"],
1336        },
1337        linux_glibc_x86: {
1338            enabled: true,
1339            srcs: ["x86/lib/mynativelib.so"],
1340            export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl"],
1341        },
1342    },
1343}
1344`),
1345		checkVersionedAndroidBpContents(`
1346// This is auto-generated. DO NOT EDIT.
1347
1348cc_prebuilt_library_shared {
1349    name: "mysdk_mynativelib@current",
1350    sdk_member_name: "mynativelib",
1351    visibility: ["//visibility:public"],
1352    apex_available: ["//apex_available:platform"],
1353    device_supported: false,
1354    host_supported: true,
1355    installable: false,
1356    sdk_version: "minimum",
1357    stl: "none",
1358    compile_multilib: "both",
1359    export_include_dirs: ["include/myinclude"],
1360    target: {
1361        host: {
1362            enabled: false,
1363        },
1364        linux_glibc_x86_64: {
1365            enabled: true,
1366            srcs: ["x86_64/lib/mynativelib.so"],
1367            export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl"],
1368        },
1369        linux_glibc_x86: {
1370            enabled: true,
1371            srcs: ["x86/lib/mynativelib.so"],
1372            export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl"],
1373        },
1374    },
1375}
1376
1377sdk_snapshot {
1378    name: "mysdk@current",
1379    visibility: ["//visibility:public"],
1380    device_supported: false,
1381    host_supported: true,
1382    native_shared_libs: ["mysdk_mynativelib@current"],
1383    target: {
1384        host: {
1385            enabled: false,
1386        },
1387        linux_glibc_x86_64: {
1388            enabled: true,
1389        },
1390        linux_glibc_x86: {
1391            enabled: true,
1392        },
1393    },
1394}
1395`),
1396		checkAllCopyRules(`
1397myinclude/Test.h -> include/myinclude/Test.h
1398.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> x86_64/lib/mynativelib.so
1399.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/Test.h
1400.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BnTest.h
1401.intermediates/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_shared/gen/aidl/aidl/foo/bar/BpTest.h
1402.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> x86/lib/mynativelib.so
1403.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/Test.h
1404.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BnTest.h
1405.intermediates/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_shared/gen/aidl/aidl/foo/bar/BpTest.h
1406`),
1407	)
1408}
1409
1410func TestMultipleHostOsTypesSnapshotWithCcSharedLibrary(t *testing.T) {
1411	result := testSdkWithCc(t, `
1412		sdk {
1413			name: "mysdk",
1414			device_supported: false,
1415			host_supported: true,
1416			native_shared_libs: ["mynativelib"],
1417			target: {
1418				windows: {
1419					enabled: true,
1420				},
1421			},
1422		}
1423
1424		cc_library_shared {
1425			name: "mynativelib",
1426			device_supported: false,
1427			host_supported: true,
1428			srcs: [
1429				"Test.cpp",
1430			],
1431			stl: "none",
1432			target: {
1433				windows: {
1434					enabled: true,
1435				},
1436			},
1437		}
1438	`)
1439
1440	CheckSnapshot(t, result, "mysdk", "",
1441		checkUnversionedAndroidBpContents(`
1442// This is auto-generated. DO NOT EDIT.
1443
1444cc_prebuilt_library_shared {
1445    name: "mynativelib",
1446    prefer: false,
1447    visibility: ["//visibility:public"],
1448    apex_available: ["//apex_available:platform"],
1449    device_supported: false,
1450    host_supported: true,
1451    stl: "none",
1452    target: {
1453        host: {
1454            enabled: false,
1455        },
1456        linux_glibc: {
1457            compile_multilib: "both",
1458        },
1459        linux_glibc_x86_64: {
1460            enabled: true,
1461            srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1462        },
1463        linux_glibc_x86: {
1464            enabled: true,
1465            srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1466        },
1467        windows: {
1468            compile_multilib: "64",
1469        },
1470        windows_x86_64: {
1471            enabled: true,
1472            srcs: ["windows/x86_64/lib/mynativelib.dll"],
1473        },
1474    },
1475}
1476`),
1477		checkVersionedAndroidBpContents(`
1478// This is auto-generated. DO NOT EDIT.
1479
1480cc_prebuilt_library_shared {
1481    name: "mysdk_mynativelib@current",
1482    sdk_member_name: "mynativelib",
1483    visibility: ["//visibility:public"],
1484    apex_available: ["//apex_available:platform"],
1485    device_supported: false,
1486    host_supported: true,
1487    installable: false,
1488    stl: "none",
1489    target: {
1490        host: {
1491            enabled: false,
1492        },
1493        linux_glibc: {
1494            compile_multilib: "both",
1495        },
1496        linux_glibc_x86_64: {
1497            enabled: true,
1498            srcs: ["linux_glibc/x86_64/lib/mynativelib.so"],
1499        },
1500        linux_glibc_x86: {
1501            enabled: true,
1502            srcs: ["linux_glibc/x86/lib/mynativelib.so"],
1503        },
1504        windows: {
1505            compile_multilib: "64",
1506        },
1507        windows_x86_64: {
1508            enabled: true,
1509            srcs: ["windows/x86_64/lib/mynativelib.dll"],
1510        },
1511    },
1512}
1513
1514sdk_snapshot {
1515    name: "mysdk@current",
1516    visibility: ["//visibility:public"],
1517    device_supported: false,
1518    host_supported: true,
1519    native_shared_libs: ["mysdk_mynativelib@current"],
1520    target: {
1521        windows: {
1522            compile_multilib: "64",
1523        },
1524        host: {
1525            enabled: false,
1526        },
1527        linux_glibc_x86_64: {
1528            enabled: true,
1529        },
1530        linux_glibc_x86: {
1531            enabled: true,
1532        },
1533        windows_x86_64: {
1534            enabled: true,
1535        },
1536    },
1537}
1538`),
1539		checkAllCopyRules(`
1540.intermediates/mynativelib/linux_glibc_x86_64_shared/mynativelib.so -> linux_glibc/x86_64/lib/mynativelib.so
1541.intermediates/mynativelib/linux_glibc_x86_shared/mynativelib.so -> linux_glibc/x86/lib/mynativelib.so
1542.intermediates/mynativelib/windows_x86_64_shared/mynativelib.dll -> windows/x86_64/lib/mynativelib.dll
1543`),
1544	)
1545}
1546
1547func TestSnapshotWithCcStaticLibrary(t *testing.T) {
1548	result := testSdkWithCc(t, `
1549		module_exports {
1550			name: "myexports",
1551			native_static_libs: ["mynativelib"],
1552		}
1553
1554		cc_library_static {
1555			name: "mynativelib",
1556			srcs: [
1557				"Test.cpp",
1558				"aidl/foo/bar/Test.aidl",
1559			],
1560			export_include_dirs: ["myinclude"],
1561			aidl: {
1562				export_aidl_headers: true,
1563			},
1564			stl: "none",
1565		}
1566	`)
1567
1568	CheckSnapshot(t, result, "myexports", "",
1569		checkUnversionedAndroidBpContents(`
1570// This is auto-generated. DO NOT EDIT.
1571
1572cc_prebuilt_library_static {
1573    name: "mynativelib",
1574    prefer: false,
1575    visibility: ["//visibility:public"],
1576    apex_available: ["//apex_available:platform"],
1577    stl: "none",
1578    compile_multilib: "both",
1579    export_include_dirs: ["include/myinclude"],
1580    arch: {
1581        arm64: {
1582            srcs: ["arm64/lib/mynativelib.a"],
1583            export_include_dirs: ["arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl"],
1584        },
1585        arm: {
1586            srcs: ["arm/lib/mynativelib.a"],
1587            export_include_dirs: ["arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl"],
1588        },
1589    },
1590}
1591`),
1592		checkAllCopyRules(`
1593myinclude/Test.h -> include/myinclude/Test.h
1594.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1595.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/Test.h
1596.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BnTest.h
1597.intermediates/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm64/include_gen/mynativelib/android_arm64_armv8-a_static/gen/aidl/aidl/foo/bar/BpTest.h
1598.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1599.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/Test.h
1600.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BnTest.h
1601.intermediates/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h -> arm/include_gen/mynativelib/android_arm_armv7-a-neon_static/gen/aidl/aidl/foo/bar/BpTest.h
1602`),
1603	)
1604}
1605
1606func TestHostSnapshotWithCcStaticLibrary(t *testing.T) {
1607	result := testSdkWithCc(t, `
1608		module_exports {
1609			name: "myexports",
1610			device_supported: false,
1611			host_supported: true,
1612			native_static_libs: ["mynativelib"],
1613		}
1614
1615		cc_library_static {
1616			name: "mynativelib",
1617			device_supported: false,
1618			host_supported: true,
1619			srcs: [
1620				"Test.cpp",
1621				"aidl/foo/bar/Test.aidl",
1622			],
1623			export_include_dirs: ["myinclude"],
1624			aidl: {
1625				export_aidl_headers: true,
1626			},
1627			stl: "none",
1628		}
1629	`)
1630
1631	CheckSnapshot(t, result, "myexports", "",
1632		checkUnversionedAndroidBpContents(`
1633// This is auto-generated. DO NOT EDIT.
1634
1635cc_prebuilt_library_static {
1636    name: "mynativelib",
1637    prefer: false,
1638    visibility: ["//visibility:public"],
1639    apex_available: ["//apex_available:platform"],
1640    device_supported: false,
1641    host_supported: true,
1642    stl: "none",
1643    compile_multilib: "both",
1644    export_include_dirs: ["include/myinclude"],
1645    target: {
1646        host: {
1647            enabled: false,
1648        },
1649        linux_glibc_x86_64: {
1650            enabled: true,
1651            srcs: ["x86_64/lib/mynativelib.a"],
1652            export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl"],
1653        },
1654        linux_glibc_x86: {
1655            enabled: true,
1656            srcs: ["x86/lib/mynativelib.a"],
1657            export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl"],
1658        },
1659    },
1660}
1661`),
1662		checkVersionedAndroidBpContents(`
1663// This is auto-generated. DO NOT EDIT.
1664
1665cc_prebuilt_library_static {
1666    name: "myexports_mynativelib@current",
1667    sdk_member_name: "mynativelib",
1668    visibility: ["//visibility:public"],
1669    apex_available: ["//apex_available:platform"],
1670    device_supported: false,
1671    host_supported: true,
1672    installable: false,
1673    stl: "none",
1674    compile_multilib: "both",
1675    export_include_dirs: ["include/myinclude"],
1676    target: {
1677        host: {
1678            enabled: false,
1679        },
1680        linux_glibc_x86_64: {
1681            enabled: true,
1682            srcs: ["x86_64/lib/mynativelib.a"],
1683            export_include_dirs: ["x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl"],
1684        },
1685        linux_glibc_x86: {
1686            enabled: true,
1687            srcs: ["x86/lib/mynativelib.a"],
1688            export_include_dirs: ["x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl"],
1689        },
1690    },
1691}
1692
1693module_exports_snapshot {
1694    name: "myexports@current",
1695    visibility: ["//visibility:public"],
1696    device_supported: false,
1697    host_supported: true,
1698    native_static_libs: ["myexports_mynativelib@current"],
1699    target: {
1700        host: {
1701            enabled: false,
1702        },
1703        linux_glibc_x86_64: {
1704            enabled: true,
1705        },
1706        linux_glibc_x86: {
1707            enabled: true,
1708        },
1709    },
1710}
1711`),
1712		checkAllCopyRules(`
1713myinclude/Test.h -> include/myinclude/Test.h
1714.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1715.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h
1716.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h
1717.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h
1718.intermediates/mynativelib/linux_glibc_x86_static/mynativelib.a -> x86/lib/mynativelib.a
1719.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/Test.h
1720.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BnTest.h
1721.intermediates/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86/include_gen/mynativelib/linux_glibc_x86_static/gen/aidl/aidl/foo/bar/BpTest.h
1722`),
1723	)
1724}
1725
1726func TestSnapshotWithCcLibrary(t *testing.T) {
1727	result := testSdkWithCc(t, `
1728		module_exports {
1729			name: "myexports",
1730			native_libs: ["mynativelib"],
1731		}
1732
1733		cc_library {
1734			name: "mynativelib",
1735			srcs: [
1736				"Test.cpp",
1737			],
1738			export_include_dirs: ["myinclude"],
1739			stl: "none",
1740			recovery_available: true,
1741			vendor_available: true,
1742		}
1743	`)
1744
1745	CheckSnapshot(t, result, "myexports", "",
1746		checkUnversionedAndroidBpContents(`
1747// This is auto-generated. DO NOT EDIT.
1748
1749cc_prebuilt_library {
1750    name: "mynativelib",
1751    prefer: false,
1752    visibility: ["//visibility:public"],
1753    apex_available: ["//apex_available:platform"],
1754    recovery_available: true,
1755    vendor_available: true,
1756    stl: "none",
1757    compile_multilib: "both",
1758    export_include_dirs: ["include/myinclude"],
1759    arch: {
1760        arm64: {
1761            static: {
1762                srcs: ["arm64/lib/mynativelib.a"],
1763            },
1764            shared: {
1765                srcs: ["arm64/lib/mynativelib.so"],
1766            },
1767        },
1768        arm: {
1769            static: {
1770                srcs: ["arm/lib/mynativelib.a"],
1771            },
1772            shared: {
1773                srcs: ["arm/lib/mynativelib.so"],
1774            },
1775        },
1776    },
1777}
1778`),
1779		// Make sure that the generated sdk_snapshot uses the native_libs property.
1780		checkVersionedAndroidBpContents(`
1781// This is auto-generated. DO NOT EDIT.
1782
1783cc_prebuilt_library {
1784    name: "myexports_mynativelib@current",
1785    sdk_member_name: "mynativelib",
1786    visibility: ["//visibility:public"],
1787    apex_available: ["//apex_available:platform"],
1788    installable: false,
1789    recovery_available: true,
1790    vendor_available: true,
1791    stl: "none",
1792    compile_multilib: "both",
1793    export_include_dirs: ["include/myinclude"],
1794    arch: {
1795        arm64: {
1796            static: {
1797                srcs: ["arm64/lib/mynativelib.a"],
1798            },
1799            shared: {
1800                srcs: ["arm64/lib/mynativelib.so"],
1801            },
1802        },
1803        arm: {
1804            static: {
1805                srcs: ["arm/lib/mynativelib.a"],
1806            },
1807            shared: {
1808                srcs: ["arm/lib/mynativelib.so"],
1809            },
1810        },
1811    },
1812}
1813
1814module_exports_snapshot {
1815    name: "myexports@current",
1816    visibility: ["//visibility:public"],
1817    native_libs: ["myexports_mynativelib@current"],
1818}
1819`),
1820		checkAllCopyRules(`
1821myinclude/Test.h -> include/myinclude/Test.h
1822.intermediates/mynativelib/android_arm64_armv8-a_static/mynativelib.a -> arm64/lib/mynativelib.a
1823.intermediates/mynativelib/android_arm64_armv8-a_shared/mynativelib.so -> arm64/lib/mynativelib.so
1824.intermediates/mynativelib/android_arm_armv7-a-neon_static/mynativelib.a -> arm/lib/mynativelib.a
1825.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
1826`),
1827		// TODO(b/183315522): Remove this and fix the issue.
1828		snapshotTestErrorHandler(checkSnapshotPreferredWithSource, android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\Qunrecognized property "arch.arm.shared.export_include_dirs"\E`)),
1829	)
1830}
1831
1832func TestHostSnapshotWithMultiLib64(t *testing.T) {
1833	result := testSdkWithCc(t, `
1834		module_exports {
1835			name: "myexports",
1836			device_supported: false,
1837			host_supported: true,
1838			target: {
1839				host: {
1840					compile_multilib: "64",
1841				},
1842			},
1843			native_static_libs: ["mynativelib"],
1844		}
1845
1846		cc_library_static {
1847			name: "mynativelib",
1848			device_supported: false,
1849			host_supported: true,
1850			srcs: [
1851				"Test.cpp",
1852				"aidl/foo/bar/Test.aidl",
1853			],
1854			export_include_dirs: ["myinclude"],
1855			aidl: {
1856				export_aidl_headers: true,
1857			},
1858			stl: "none",
1859		}
1860	`)
1861
1862	CheckSnapshot(t, result, "myexports", "",
1863		checkUnversionedAndroidBpContents(`
1864// This is auto-generated. DO NOT EDIT.
1865
1866cc_prebuilt_library_static {
1867    name: "mynativelib",
1868    prefer: false,
1869    visibility: ["//visibility:public"],
1870    apex_available: ["//apex_available:platform"],
1871    device_supported: false,
1872    host_supported: true,
1873    stl: "none",
1874    compile_multilib: "64",
1875    export_include_dirs: [
1876        "include/myinclude",
1877        "include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl",
1878    ],
1879    target: {
1880        host: {
1881            enabled: false,
1882        },
1883        linux_glibc_x86_64: {
1884            enabled: true,
1885            srcs: ["x86_64/lib/mynativelib.a"],
1886        },
1887    },
1888}
1889`),
1890		checkVersionedAndroidBpContents(`
1891// This is auto-generated. DO NOT EDIT.
1892
1893cc_prebuilt_library_static {
1894    name: "myexports_mynativelib@current",
1895    sdk_member_name: "mynativelib",
1896    visibility: ["//visibility:public"],
1897    apex_available: ["//apex_available:platform"],
1898    device_supported: false,
1899    host_supported: true,
1900    installable: false,
1901    stl: "none",
1902    compile_multilib: "64",
1903    export_include_dirs: [
1904        "include/myinclude",
1905        "include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl",
1906    ],
1907    target: {
1908        host: {
1909            enabled: false,
1910        },
1911        linux_glibc_x86_64: {
1912            enabled: true,
1913            srcs: ["x86_64/lib/mynativelib.a"],
1914        },
1915    },
1916}
1917
1918module_exports_snapshot {
1919    name: "myexports@current",
1920    visibility: ["//visibility:public"],
1921    device_supported: false,
1922    host_supported: true,
1923    compile_multilib: "64",
1924    native_static_libs: ["myexports_mynativelib@current"],
1925    target: {
1926        host: {
1927            enabled: false,
1928        },
1929        linux_glibc_x86_64: {
1930            enabled: true,
1931        },
1932    },
1933}
1934`),
1935		checkAllCopyRules(`
1936myinclude/Test.h -> include/myinclude/Test.h
1937.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h
1938.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h
1939.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> include_gen/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h
1940.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
1941`),
1942	)
1943}
1944
1945func TestSnapshotWithCcHeadersLibrary(t *testing.T) {
1946	result := testSdkWithCc(t, `
1947		sdk {
1948			name: "mysdk",
1949			native_header_libs: ["mynativeheaders"],
1950		}
1951
1952		cc_library_headers {
1953			name: "mynativeheaders",
1954			export_include_dirs: ["myinclude"],
1955			stl: "none",
1956		}
1957	`)
1958
1959	CheckSnapshot(t, result, "mysdk", "",
1960		checkUnversionedAndroidBpContents(`
1961// This is auto-generated. DO NOT EDIT.
1962
1963cc_prebuilt_library_headers {
1964    name: "mynativeheaders",
1965    prefer: false,
1966    visibility: ["//visibility:public"],
1967    apex_available: ["//apex_available:platform"],
1968    stl: "none",
1969    compile_multilib: "both",
1970    export_include_dirs: ["include/myinclude"],
1971}
1972`),
1973		checkAllCopyRules(`
1974myinclude/Test.h -> include/myinclude/Test.h
1975`),
1976	)
1977}
1978
1979func TestHostSnapshotWithCcHeadersLibrary(t *testing.T) {
1980	result := testSdkWithCc(t, `
1981		sdk {
1982			name: "mysdk",
1983			device_supported: false,
1984			host_supported: true,
1985			native_header_libs: ["mynativeheaders"],
1986		}
1987
1988		cc_library_headers {
1989			name: "mynativeheaders",
1990			device_supported: false,
1991			host_supported: true,
1992			export_include_dirs: ["myinclude"],
1993			stl: "none",
1994		}
1995	`)
1996
1997	CheckSnapshot(t, result, "mysdk", "",
1998		checkUnversionedAndroidBpContents(`
1999// This is auto-generated. DO NOT EDIT.
2000
2001cc_prebuilt_library_headers {
2002    name: "mynativeheaders",
2003    prefer: false,
2004    visibility: ["//visibility:public"],
2005    apex_available: ["//apex_available:platform"],
2006    device_supported: false,
2007    host_supported: true,
2008    stl: "none",
2009    compile_multilib: "both",
2010    export_include_dirs: ["include/myinclude"],
2011    target: {
2012        host: {
2013            enabled: false,
2014        },
2015        linux_glibc_x86_64: {
2016            enabled: true,
2017        },
2018        linux_glibc_x86: {
2019            enabled: true,
2020        },
2021    },
2022}
2023`),
2024		checkVersionedAndroidBpContents(`
2025// This is auto-generated. DO NOT EDIT.
2026
2027cc_prebuilt_library_headers {
2028    name: "mysdk_mynativeheaders@current",
2029    sdk_member_name: "mynativeheaders",
2030    visibility: ["//visibility:public"],
2031    apex_available: ["//apex_available:platform"],
2032    device_supported: false,
2033    host_supported: true,
2034    stl: "none",
2035    compile_multilib: "both",
2036    export_include_dirs: ["include/myinclude"],
2037    target: {
2038        host: {
2039            enabled: false,
2040        },
2041        linux_glibc_x86_64: {
2042            enabled: true,
2043        },
2044        linux_glibc_x86: {
2045            enabled: true,
2046        },
2047    },
2048}
2049
2050sdk_snapshot {
2051    name: "mysdk@current",
2052    visibility: ["//visibility:public"],
2053    device_supported: false,
2054    host_supported: true,
2055    native_header_libs: ["mysdk_mynativeheaders@current"],
2056    target: {
2057        host: {
2058            enabled: false,
2059        },
2060        linux_glibc_x86_64: {
2061            enabled: true,
2062        },
2063        linux_glibc_x86: {
2064            enabled: true,
2065        },
2066    },
2067}
2068`),
2069		checkAllCopyRules(`
2070myinclude/Test.h -> include/myinclude/Test.h
2071`),
2072	)
2073}
2074
2075func TestDeviceAndHostSnapshotWithCcHeadersLibrary(t *testing.T) {
2076	result := testSdkWithCc(t, `
2077		sdk {
2078			name: "mysdk",
2079			host_supported: true,
2080			native_header_libs: ["mynativeheaders"],
2081		}
2082
2083		cc_library_headers {
2084			name: "mynativeheaders",
2085			host_supported: true,
2086			stl: "none",
2087			export_system_include_dirs: ["myinclude"],
2088			target: {
2089				android: {
2090					export_include_dirs: ["myinclude-android"],
2091				},
2092				host: {
2093					export_include_dirs: ["myinclude-host"],
2094				},
2095			},
2096		}
2097	`)
2098
2099	CheckSnapshot(t, result, "mysdk", "",
2100		checkUnversionedAndroidBpContents(`
2101// This is auto-generated. DO NOT EDIT.
2102
2103cc_prebuilt_library_headers {
2104    name: "mynativeheaders",
2105    prefer: false,
2106    visibility: ["//visibility:public"],
2107    apex_available: ["//apex_available:platform"],
2108    host_supported: true,
2109    stl: "none",
2110    compile_multilib: "both",
2111    export_system_include_dirs: ["common_os/include/myinclude"],
2112    target: {
2113        host: {
2114            enabled: false,
2115        },
2116        android: {
2117            export_include_dirs: ["android/include/myinclude-android"],
2118        },
2119        linux_glibc: {
2120            export_include_dirs: ["linux_glibc/include/myinclude-host"],
2121        },
2122        linux_glibc_x86_64: {
2123            enabled: true,
2124        },
2125        linux_glibc_x86: {
2126            enabled: true,
2127        },
2128    },
2129}
2130`),
2131		checkVersionedAndroidBpContents(`
2132// This is auto-generated. DO NOT EDIT.
2133
2134cc_prebuilt_library_headers {
2135    name: "mysdk_mynativeheaders@current",
2136    sdk_member_name: "mynativeheaders",
2137    visibility: ["//visibility:public"],
2138    apex_available: ["//apex_available:platform"],
2139    host_supported: true,
2140    stl: "none",
2141    compile_multilib: "both",
2142    export_system_include_dirs: ["common_os/include/myinclude"],
2143    target: {
2144        host: {
2145            enabled: false,
2146        },
2147        android: {
2148            export_include_dirs: ["android/include/myinclude-android"],
2149        },
2150        linux_glibc: {
2151            export_include_dirs: ["linux_glibc/include/myinclude-host"],
2152        },
2153        linux_glibc_x86_64: {
2154            enabled: true,
2155        },
2156        linux_glibc_x86: {
2157            enabled: true,
2158        },
2159    },
2160}
2161
2162sdk_snapshot {
2163    name: "mysdk@current",
2164    visibility: ["//visibility:public"],
2165    host_supported: true,
2166    native_header_libs: ["mysdk_mynativeheaders@current"],
2167    target: {
2168        host: {
2169            enabled: false,
2170        },
2171        linux_glibc_x86_64: {
2172            enabled: true,
2173        },
2174        linux_glibc_x86: {
2175            enabled: true,
2176        },
2177    },
2178}
2179`),
2180		checkAllCopyRules(`
2181myinclude/Test.h -> common_os/include/myinclude/Test.h
2182myinclude-android/AndroidTest.h -> android/include/myinclude-android/AndroidTest.h
2183myinclude-host/HostTest.h -> linux_glibc/include/myinclude-host/HostTest.h
2184`),
2185	)
2186}
2187
2188func TestSystemSharedLibPropagation(t *testing.T) {
2189	result := testSdkWithCc(t, `
2190		sdk {
2191			name: "mysdk",
2192			native_shared_libs: ["sslnil", "sslempty", "sslnonempty"],
2193		}
2194
2195		cc_library {
2196			name: "sslnil",
2197			host_supported: true,
2198		}
2199
2200		cc_library {
2201			name: "sslempty",
2202			system_shared_libs: [],
2203		}
2204
2205		cc_library {
2206			name: "sslnonempty",
2207			system_shared_libs: ["sslnil"],
2208		}
2209	`)
2210
2211	CheckSnapshot(t, result, "mysdk", "",
2212		checkUnversionedAndroidBpContents(`
2213// This is auto-generated. DO NOT EDIT.
2214
2215cc_prebuilt_library_shared {
2216    name: "sslnil",
2217    prefer: false,
2218    visibility: ["//visibility:public"],
2219    apex_available: ["//apex_available:platform"],
2220    compile_multilib: "both",
2221    arch: {
2222        arm64: {
2223            srcs: ["arm64/lib/sslnil.so"],
2224        },
2225        arm: {
2226            srcs: ["arm/lib/sslnil.so"],
2227        },
2228    },
2229}
2230
2231cc_prebuilt_library_shared {
2232    name: "sslempty",
2233    prefer: false,
2234    visibility: ["//visibility:public"],
2235    apex_available: ["//apex_available:platform"],
2236    compile_multilib: "both",
2237    system_shared_libs: [],
2238    arch: {
2239        arm64: {
2240            srcs: ["arm64/lib/sslempty.so"],
2241        },
2242        arm: {
2243            srcs: ["arm/lib/sslempty.so"],
2244        },
2245    },
2246}
2247
2248cc_prebuilt_library_shared {
2249    name: "sslnonempty",
2250    prefer: false,
2251    visibility: ["//visibility:public"],
2252    apex_available: ["//apex_available:platform"],
2253    compile_multilib: "both",
2254    system_shared_libs: ["sslnil"],
2255    arch: {
2256        arm64: {
2257            srcs: ["arm64/lib/sslnonempty.so"],
2258        },
2259        arm: {
2260            srcs: ["arm/lib/sslnonempty.so"],
2261        },
2262    },
2263}
2264`))
2265
2266	result = testSdkWithCc(t, `
2267		sdk {
2268			name: "mysdk",
2269			host_supported: true,
2270			native_shared_libs: ["sslvariants"],
2271		}
2272
2273		cc_library {
2274			name: "sslvariants",
2275			host_supported: true,
2276			target: {
2277				android: {
2278					system_shared_libs: [],
2279				},
2280			},
2281		}
2282	`)
2283
2284	CheckSnapshot(t, result, "mysdk", "",
2285		checkUnversionedAndroidBpContents(`
2286// This is auto-generated. DO NOT EDIT.
2287
2288cc_prebuilt_library_shared {
2289    name: "sslvariants",
2290    prefer: false,
2291    visibility: ["//visibility:public"],
2292    apex_available: ["//apex_available:platform"],
2293    host_supported: true,
2294    compile_multilib: "both",
2295    target: {
2296        host: {
2297            enabled: false,
2298        },
2299        android: {
2300            system_shared_libs: [],
2301        },
2302        android_arm64: {
2303            srcs: ["android/arm64/lib/sslvariants.so"],
2304        },
2305        android_arm: {
2306            srcs: ["android/arm/lib/sslvariants.so"],
2307        },
2308        linux_glibc_x86_64: {
2309            enabled: true,
2310            srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2311        },
2312        linux_glibc_x86: {
2313            enabled: true,
2314            srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2315        },
2316    },
2317}
2318`),
2319		checkVersionedAndroidBpContents(`
2320// This is auto-generated. DO NOT EDIT.
2321
2322cc_prebuilt_library_shared {
2323    name: "mysdk_sslvariants@current",
2324    sdk_member_name: "sslvariants",
2325    visibility: ["//visibility:public"],
2326    apex_available: ["//apex_available:platform"],
2327    host_supported: true,
2328    installable: false,
2329    compile_multilib: "both",
2330    target: {
2331        host: {
2332            enabled: false,
2333        },
2334        android: {
2335            system_shared_libs: [],
2336        },
2337        android_arm64: {
2338            srcs: ["android/arm64/lib/sslvariants.so"],
2339        },
2340        android_arm: {
2341            srcs: ["android/arm/lib/sslvariants.so"],
2342        },
2343        linux_glibc_x86_64: {
2344            enabled: true,
2345            srcs: ["linux_glibc/x86_64/lib/sslvariants.so"],
2346        },
2347        linux_glibc_x86: {
2348            enabled: true,
2349            srcs: ["linux_glibc/x86/lib/sslvariants.so"],
2350        },
2351    },
2352}
2353
2354sdk_snapshot {
2355    name: "mysdk@current",
2356    visibility: ["//visibility:public"],
2357    host_supported: true,
2358    native_shared_libs: ["mysdk_sslvariants@current"],
2359    target: {
2360        host: {
2361            enabled: false,
2362        },
2363        linux_glibc_x86_64: {
2364            enabled: true,
2365        },
2366        linux_glibc_x86: {
2367            enabled: true,
2368        },
2369    },
2370}
2371`))
2372}
2373
2374func TestStubsLibrary(t *testing.T) {
2375	result := testSdkWithCc(t, `
2376		sdk {
2377			name: "mysdk",
2378			native_shared_libs: ["stubslib"],
2379		}
2380
2381		cc_library {
2382			name: "internaldep",
2383		}
2384
2385		cc_library {
2386			name: "stubslib",
2387			shared_libs: ["internaldep"],
2388			stubs: {
2389				symbol_file: "some/where/stubslib.map.txt",
2390				versions: ["1", "2", "3"],
2391			},
2392		}
2393	`)
2394
2395	CheckSnapshot(t, result, "mysdk", "",
2396		checkUnversionedAndroidBpContents(`
2397// This is auto-generated. DO NOT EDIT.
2398
2399cc_prebuilt_library_shared {
2400    name: "stubslib",
2401    prefer: false,
2402    visibility: ["//visibility:public"],
2403    apex_available: ["//apex_available:platform"],
2404    compile_multilib: "both",
2405    stubs: {
2406        versions: [
2407            "1",
2408            "2",
2409            "3",
2410            "current",
2411        ],
2412    },
2413    arch: {
2414        arm64: {
2415            srcs: ["arm64/lib/stubslib.so"],
2416        },
2417        arm: {
2418            srcs: ["arm/lib/stubslib.so"],
2419        },
2420    },
2421}
2422`))
2423}
2424
2425func TestDeviceAndHostSnapshotWithStubsLibrary(t *testing.T) {
2426	result := testSdkWithCc(t, `
2427		sdk {
2428			name: "mysdk",
2429			host_supported: true,
2430			native_shared_libs: ["stubslib"],
2431		}
2432
2433		cc_library {
2434			name: "internaldep",
2435			host_supported: true,
2436		}
2437
2438		cc_library {
2439			name: "stubslib",
2440			host_supported: true,
2441			shared_libs: ["internaldep"],
2442			stubs: {
2443				symbol_file: "some/where/stubslib.map.txt",
2444				versions: ["1", "2", "3"],
2445			},
2446		}
2447	`)
2448
2449	CheckSnapshot(t, result, "mysdk", "",
2450		checkUnversionedAndroidBpContents(`
2451// This is auto-generated. DO NOT EDIT.
2452
2453cc_prebuilt_library_shared {
2454    name: "stubslib",
2455    prefer: false,
2456    visibility: ["//visibility:public"],
2457    apex_available: ["//apex_available:platform"],
2458    host_supported: true,
2459    compile_multilib: "both",
2460    stubs: {
2461        versions: [
2462            "1",
2463            "2",
2464            "3",
2465            "current",
2466        ],
2467    },
2468    target: {
2469        host: {
2470            enabled: false,
2471        },
2472        android_arm64: {
2473            srcs: ["android/arm64/lib/stubslib.so"],
2474        },
2475        android_arm: {
2476            srcs: ["android/arm/lib/stubslib.so"],
2477        },
2478        linux_glibc_x86_64: {
2479            enabled: true,
2480            srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2481        },
2482        linux_glibc_x86: {
2483            enabled: true,
2484            srcs: ["linux_glibc/x86/lib/stubslib.so"],
2485        },
2486    },
2487}
2488`),
2489		checkVersionedAndroidBpContents(`
2490// This is auto-generated. DO NOT EDIT.
2491
2492cc_prebuilt_library_shared {
2493    name: "mysdk_stubslib@current",
2494    sdk_member_name: "stubslib",
2495    visibility: ["//visibility:public"],
2496    apex_available: ["//apex_available:platform"],
2497    host_supported: true,
2498    installable: false,
2499    compile_multilib: "both",
2500    stubs: {
2501        versions: [
2502            "1",
2503            "2",
2504            "3",
2505            "current",
2506        ],
2507    },
2508    target: {
2509        host: {
2510            enabled: false,
2511        },
2512        android_arm64: {
2513            srcs: ["android/arm64/lib/stubslib.so"],
2514        },
2515        android_arm: {
2516            srcs: ["android/arm/lib/stubslib.so"],
2517        },
2518        linux_glibc_x86_64: {
2519            enabled: true,
2520            srcs: ["linux_glibc/x86_64/lib/stubslib.so"],
2521        },
2522        linux_glibc_x86: {
2523            enabled: true,
2524            srcs: ["linux_glibc/x86/lib/stubslib.so"],
2525        },
2526    },
2527}
2528
2529sdk_snapshot {
2530    name: "mysdk@current",
2531    visibility: ["//visibility:public"],
2532    host_supported: true,
2533    native_shared_libs: ["mysdk_stubslib@current"],
2534    target: {
2535        host: {
2536            enabled: false,
2537        },
2538        linux_glibc_x86_64: {
2539            enabled: true,
2540        },
2541        linux_glibc_x86: {
2542            enabled: true,
2543        },
2544    },
2545}
2546`))
2547}
2548
2549func TestUniqueHostSoname(t *testing.T) {
2550	result := testSdkWithCc(t, `
2551		sdk {
2552			name: "mysdk",
2553			host_supported: true,
2554			native_shared_libs: ["mylib"],
2555		}
2556
2557		cc_library {
2558			name: "mylib",
2559			host_supported: true,
2560			unique_host_soname: true,
2561		}
2562	`)
2563
2564	CheckSnapshot(t, result, "mysdk", "",
2565		checkUnversionedAndroidBpContents(`
2566// This is auto-generated. DO NOT EDIT.
2567
2568cc_prebuilt_library_shared {
2569    name: "mylib",
2570    prefer: false,
2571    visibility: ["//visibility:public"],
2572    apex_available: ["//apex_available:platform"],
2573    host_supported: true,
2574    unique_host_soname: true,
2575    compile_multilib: "both",
2576    target: {
2577        host: {
2578            enabled: false,
2579        },
2580        android_arm64: {
2581            srcs: ["android/arm64/lib/mylib.so"],
2582        },
2583        android_arm: {
2584            srcs: ["android/arm/lib/mylib.so"],
2585        },
2586        linux_glibc_x86_64: {
2587            enabled: true,
2588            srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2589        },
2590        linux_glibc_x86: {
2591            enabled: true,
2592            srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2593        },
2594    },
2595}
2596`),
2597		checkVersionedAndroidBpContents(`
2598// This is auto-generated. DO NOT EDIT.
2599
2600cc_prebuilt_library_shared {
2601    name: "mysdk_mylib@current",
2602    sdk_member_name: "mylib",
2603    visibility: ["//visibility:public"],
2604    apex_available: ["//apex_available:platform"],
2605    host_supported: true,
2606    installable: false,
2607    unique_host_soname: true,
2608    compile_multilib: "both",
2609    target: {
2610        host: {
2611            enabled: false,
2612        },
2613        android_arm64: {
2614            srcs: ["android/arm64/lib/mylib.so"],
2615        },
2616        android_arm: {
2617            srcs: ["android/arm/lib/mylib.so"],
2618        },
2619        linux_glibc_x86_64: {
2620            enabled: true,
2621            srcs: ["linux_glibc/x86_64/lib/mylib-host.so"],
2622        },
2623        linux_glibc_x86: {
2624            enabled: true,
2625            srcs: ["linux_glibc/x86/lib/mylib-host.so"],
2626        },
2627    },
2628}
2629
2630sdk_snapshot {
2631    name: "mysdk@current",
2632    visibility: ["//visibility:public"],
2633    host_supported: true,
2634    native_shared_libs: ["mysdk_mylib@current"],
2635    target: {
2636        host: {
2637            enabled: false,
2638        },
2639        linux_glibc_x86_64: {
2640            enabled: true,
2641        },
2642        linux_glibc_x86: {
2643            enabled: true,
2644        },
2645    },
2646}
2647`),
2648		checkAllCopyRules(`
2649.intermediates/mylib/android_arm64_armv8-a_shared/mylib.so -> android/arm64/lib/mylib.so
2650.intermediates/mylib/android_arm_armv7-a-neon_shared/mylib.so -> android/arm/lib/mylib.so
2651.intermediates/mylib/linux_glibc_x86_64_shared/mylib-host.so -> linux_glibc/x86_64/lib/mylib-host.so
2652.intermediates/mylib/linux_glibc_x86_shared/mylib-host.so -> linux_glibc/x86/lib/mylib-host.so
2653`),
2654	)
2655}
2656
2657func TestNoSanitizerMembers(t *testing.T) {
2658	result := testSdkWithCc(t, `
2659		sdk {
2660			name: "mysdk",
2661			native_shared_libs: ["mynativelib"],
2662		}
2663
2664		cc_library_shared {
2665			name: "mynativelib",
2666			srcs: ["Test.cpp"],
2667			export_include_dirs: ["myinclude"],
2668			arch: {
2669				arm64: {
2670					export_system_include_dirs: ["arm64/include"],
2671					sanitize: {
2672						hwaddress: true,
2673					},
2674				},
2675			},
2676		}
2677	`)
2678
2679	// Mixing the snapshot with the source (irrespective of which one is preferred) causes a problem
2680	// due to missing variants.
2681	// TODO(b/183204176): Remove this and fix the cause.
2682	snapshotWithSourceErrorHandler := android.FixtureExpectsAtLeastOneErrorMatchingPattern(`\QReplaceDependencies could not find identical variant {os:android,image:,arch:arm64_armv8-a,sdk:,link:shared,version:} for module mynativelib\E`)
2683
2684	CheckSnapshot(t, result, "mysdk", "",
2685		checkUnversionedAndroidBpContents(`
2686// This is auto-generated. DO NOT EDIT.
2687
2688cc_prebuilt_library_shared {
2689    name: "mynativelib",
2690    prefer: false,
2691    visibility: ["//visibility:public"],
2692    apex_available: ["//apex_available:platform"],
2693    compile_multilib: "both",
2694    export_include_dirs: ["include/myinclude"],
2695    arch: {
2696        arm64: {
2697            export_system_include_dirs: ["arm64/include/arm64/include"],
2698        },
2699        arm: {
2700            srcs: ["arm/lib/mynativelib.so"],
2701        },
2702    },
2703}
2704`),
2705		checkAllCopyRules(`
2706myinclude/Test.h -> include/myinclude/Test.h
2707arm64/include/Arm64Test.h -> arm64/include/arm64/include/Arm64Test.h
2708.intermediates/mynativelib/android_arm_armv7-a-neon_shared/mynativelib.so -> arm/lib/mynativelib.so
2709`),
2710		snapshotTestErrorHandler(checkSnapshotWithSourcePreferred, snapshotWithSourceErrorHandler),
2711		snapshotTestErrorHandler(checkSnapshotPreferredWithSource, snapshotWithSourceErrorHandler),
2712	)
2713}
2714