Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 4 | "fmt" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 5 | "testing" |
| 6 | |
| 7 | "android/soong/cc" |
| 8 | ) |
| 9 | |
| 10 | func TestSharedPrebuiltLibrary(t *testing.T) { |
Trevor Radcliffe | 1b4b2d9 | 2022-09-01 18:57:01 +0000 | [diff] [blame] | 11 | RunBp2BuildTestCaseSimple(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 12 | Bp2buildTestCase{ |
| 13 | Description: "prebuilt library shared simple", |
| 14 | ModuleTypeUnderTest: "cc_prebuilt_library_shared", |
| 15 | ModuleTypeUnderTestFactory: cc.PrebuiltSharedLibraryFactory, |
| 16 | Filesystem: map[string]string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 17 | "libf.so": "", |
| 18 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 19 | Blueprint: ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 20 | cc_prebuilt_library_shared { |
| 21 | name: "libtest", |
| 22 | srcs: ["libf.so"], |
| 23 | bazel_module: { bp2build_available: true }, |
| 24 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 25 | ExpectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 26 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 27 | "shared_library": `"libf.so"`, |
| 28 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 29 | }, |
| 30 | }) |
| 31 | } |
| 32 | |
| 33 | func TestSharedPrebuiltLibraryWithArchVariance(t *testing.T) { |
Trevor Radcliffe | 1b4b2d9 | 2022-09-01 18:57:01 +0000 | [diff] [blame] | 34 | RunBp2BuildTestCaseSimple(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 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{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 40 | "libf.so": "", |
| 41 | "libg.so": "", |
| 42 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 43 | Blueprint: ` |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 44 | cc_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 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 52 | ExpectedBazelTargets: []string{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | c5184ec | 2022-10-17 14:48:57 +0000 | [diff] [blame] | 53 | MakeBazelTarget("cc_prebuilt_library_shared", "libtest", AttrNameToString{ |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 54 | "shared_library": `select({ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 55 | "//build/bazel/platforms/arch:arm": "libg.so", |
| 56 | "//build/bazel/platforms/arch:arm64": "libf.so", |
| 57 | "//conditions:default": None, |
Liz Kammer | 78cfdaa | 2021-11-08 12:56:31 -0500 | [diff] [blame] | 58 | })`, |
| 59 | }), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 7fa0696 | 2021-10-25 10:28:33 -0400 | [diff] [blame] | 60 | }, |
| 61 | }) |
| 62 | } |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 63 | |
| 64 | func TestSharedPrebuiltLibrarySharedStanzaFails(t *testing.T) { |
Trevor Radcliffe | 1b4b2d9 | 2022-09-01 18:57:01 +0000 | [diff] [blame] | 65 | RunBp2BuildTestCaseSimple(t, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 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{ |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 71 | "libf.so": "", |
| 72 | "libg.so": "", |
| 73 | }, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 74 | Blueprint: ` |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 75 | cc_prebuilt_library_shared { |
| 76 | name: "libtest", |
| 77 | srcs: ["libf.so"], |
| 78 | shared: { |
| 79 | srcs: ["libg.so"], |
| 80 | }, |
| 81 | bazel_module: { bp2build_available: true}, |
| 82 | }`, |
Sam Delmerico | 3177a6e | 2022-06-21 19:28:33 +0000 | [diff] [blame] | 83 | ExpectedErr: fmt.Errorf("Expected at most one source file"), |
Trevor Radcliffe | 58ea451 | 2022-04-07 20:36:39 +0000 | [diff] [blame] | 84 | }) |
| 85 | } |