blob: 57905e559ba3fb7cc39832f564d5be8db430ebe6 [file] [log] [blame]
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7fa06962021-10-25 10:28:33 -04001package bp2build
2
3import (
Trevor Radcliffe58ea4512022-04-07 20:36:39 +00004 "fmt"
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7fa06962021-10-25 10:28:33 -04005 "testing"
6
7 "android/soong/cc"
8)
9
10func TestSharedPrebuiltLibrary(t *testing.T) {
11 runBp2BuildTestCaseSimple(t,
12 bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040013 description: "prebuilt library shared simple",
14 moduleTypeUnderTest: "cc_prebuilt_library_shared",
15 moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7fa06962021-10-25 10:28:33 -040016 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{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050026 makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{
27 "shared_library": `"libf.so"`,
28 }),
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7fa06962021-10-25 10:28:33 -040029 },
30 })
31}
32
33func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) {
34 runBp2BuildTestCaseSimple(t,
35 bp2buildTestCase{
Liz Kammerbe46fcc2021-11-01 15:32:43 -040036 description: "prebuilt library shared with arch variance",
37 moduleTypeUnderTest: "cc_prebuilt_library_shared",
38 moduleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory,
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7fa06962021-10-25 10:28:33 -040039 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{
Liz Kammer78cfdaa2021-11-08 12:56:31 -050053 makeBazelTarget("prebuilt_library_shared", "libtest", attrNameToString{
54 "shared_library": `select({
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7fa06962021-10-25 10:28:33 -040055 "//build/bazel/platforms/arch:arm": "libg.so",
56 "//build/bazel/platforms/arch:arm64": "libf.so",
57 "//conditions:default": None,
Liz Kammer78cfdaa2021-11-08 12:56:31 -050058 })`,
59 }),
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux7fa06962021-10-25 10:28:33 -040060 },
61 })
62}
Trevor Radcliffe58ea4512022-04-07 20:36:39 +000063
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}