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