• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1package bp2build
2
3import (
4	"fmt"
5	"testing"
6
7	"android/soong/cc"
8)
9
10func TestSharedPrebuiltLibrary(t *testing.T) {
11	runBp2BuildTestCaseSimple(t,
12		bp2buildTestCase{
13			description:                "prebuilt library shared simple",
14			moduleTypeUnderTest:        "cc_prebuilt_library_shared",
15			moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
16			filesystem: map[string]string{
17				"libf.so": "",
18			},
19			blueprint: `
20cc_prebuilt_library_shared {
21	name: "libtest",
22	srcs: ["libf.so"],
23	bazel_module: { bp2build_available: true },
24}`,
25			expectedBazelTargets: []string{
26				makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{
27					"shared_library": `"libf.so"`,
28				}),
29			},
30		})
31}
32
33func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) {
34	runBp2BuildTestCaseSimple(t,
35		bp2buildTestCase{
36			description:                "prebuilt library shared with arch variance",
37			moduleTypeUnderTest:        "cc_prebuilt_library_shared",
38			moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
39			filesystem: map[string]string{
40				"libf.so": "",
41				"libg.so": "",
42			},
43			blueprint: `
44cc_prebuilt_library_shared {
45	name: "libtest",
46	arch: {
47		arm64: { srcs: ["libf.so"], },
48		arm: { srcs: ["libg.so"], },
49	},
50	bazel_module: { bp2build_available: true },
51}`,
52			expectedBazelTargets: []string{
53				makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{
54					"shared_library": `select({
55        "//build/bazel/platforms/arch:arm": "libg.so",
56        "//build/bazel/platforms/arch:arm64": "libf.so",
57        "//conditions:default": None,
58    })`,
59				}),
60			},
61		})
62}
63
64func TestSharedPrebuiltLibrarySharedStanzaFails(t *testing.T) {
65	runBp2BuildTestCaseSimple(t,
66		bp2buildTestCase{
67			description:                "prebuilt library shared with shared stanza fails because multiple sources",
68			moduleTypeUnderTest:        "cc_prebuilt_library_shared",
69			moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
70			filesystem: map[string]string{
71				"libf.so": "",
72				"libg.so": "",
73			},
74			blueprint: `
75cc_prebuilt_library_shared {
76	name: "libtest",
77	srcs: ["libf.so"],
78	shared: {
79		srcs: ["libg.so"],
80	},
81	bazel_module: { bp2build_available: true},
82}`,
83			expectedErr: fmt.Errorf("Expected at most one source file"),
84		})
85}
86