Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 4 | "testing" |
| 5 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 560cb66 | 2021-08-26 20:13:29 +0000 | [diff] [blame] | 6 | "android/soong/android" |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 7 | "android/soong/python" |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 8 | ) |
| 9 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 560cb66 | 2021-08-26 20:13:29 +0000 | [diff] [blame] | 10 | func runBp2BuildTestCaseWithLibs(t *testing.T, tc bp2buildTestCase) { |
| 11 | runBp2BuildTestCase(t, func(ctx android.RegistrationContext) { |
| 12 | ctx.RegisterModuleType("python_library", python.PythonLibraryFactory) |
| 13 | ctx.RegisterModuleType("python_library_host", python.PythonLibraryHostFactory) |
| 14 | }, tc) |
| 15 | } |
| 16 | |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 17 | func TestPythonBinaryHostSimple(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 560cb66 | 2021-08-26 20:13:29 +0000 | [diff] [blame] | 18 | runBp2BuildTestCaseWithLibs(t, bp2buildTestCase{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 19 | description: "simple python_binary_host converts to a native py_binary", |
| 20 | moduleTypeUnderTest: "python_binary_host", |
| 21 | moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, |
| 22 | moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build, |
| 23 | filesystem: map[string]string{ |
| 24 | "a.py": "", |
| 25 | "b/c.py": "", |
| 26 | "b/d.py": "", |
| 27 | "b/e.py": "", |
| 28 | "files/data.txt": "", |
| 29 | }, |
| 30 | blueprint: `python_binary_host { |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 31 | name: "foo", |
| 32 | main: "a.py", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 33 | srcs: ["**/*.py"], |
| 34 | exclude_srcs: ["b/e.py"], |
| 35 | data: ["files/data.txt",], |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 560cb66 | 2021-08-26 20:13:29 +0000 | [diff] [blame] | 36 | libs: ["bar"], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 37 | bazel_module: { bp2build_available: true }, |
| 38 | } |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 560cb66 | 2021-08-26 20:13:29 +0000 | [diff] [blame] | 39 | python_library_host { |
| 40 | name: "bar", |
| 41 | srcs: ["b/e.py"], |
| 42 | bazel_module: { bp2build_available: true }, |
| 43 | }`, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 44 | expectedBazelTargets: []string{`py_binary( |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 45 | name = "foo", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 46 | data = ["files/data.txt"], |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 560cb66 | 2021-08-26 20:13:29 +0000 | [diff] [blame] | 47 | deps = [":bar"], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 48 | main = "a.py", |
| 49 | srcs = [ |
| 50 | "a.py", |
| 51 | "b/c.py", |
| 52 | "b/d.py", |
| 53 | ], |
| 54 | )`, |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 55 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 56 | }) |
| 57 | } |
| 58 | |
| 59 | func TestPythonBinaryHostPy2(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ce0a07e | 2021-08-23 16:17:32 +0000 | [diff] [blame] | 60 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 61 | description: "py2 python_binary_host", |
| 62 | moduleTypeUnderTest: "python_binary_host", |
| 63 | moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, |
| 64 | moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build, |
| 65 | blueprint: `python_binary_host { |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 66 | name: "foo", |
| 67 | srcs: ["a.py"], |
| 68 | version: { |
| 69 | py2: { |
| 70 | enabled: true, |
| 71 | }, |
| 72 | py3: { |
| 73 | enabled: false, |
| 74 | }, |
| 75 | }, |
| 76 | |
| 77 | bazel_module: { bp2build_available: true }, |
| 78 | } |
| 79 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 80 | expectedBazelTargets: []string{`py_binary( |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 81 | name = "foo", |
| 82 | python_version = "PY2", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 83 | srcs = ["a.py"], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 84 | )`, |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 85 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 86 | }) |
| 87 | } |
| 88 | |
| 89 | func TestPythonBinaryHostPy3(t *testing.T) { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | ce0a07e | 2021-08-23 16:17:32 +0000 | [diff] [blame] | 90 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 91 | description: "py3 python_binary_host", |
| 92 | moduleTypeUnderTest: "python_binary_host", |
| 93 | moduleTypeUnderTestFactory: python.PythonBinaryHostFactory, |
| 94 | moduleTypeUnderTestBp2BuildMutator: python.PythonBinaryBp2Build, |
| 95 | blueprint: `python_binary_host { |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 96 | name: "foo", |
| 97 | srcs: ["a.py"], |
| 98 | version: { |
| 99 | py2: { |
| 100 | enabled: false, |
| 101 | }, |
| 102 | py3: { |
| 103 | enabled: true, |
| 104 | }, |
| 105 | }, |
| 106 | |
| 107 | bazel_module: { bp2build_available: true }, |
| 108 | } |
| 109 | `, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 110 | expectedBazelTargets: []string{ |
| 111 | // python_version is PY3 by default. |
| 112 | `py_binary( |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 113 | name = "foo", |
Jingwen Chen | b4628eb | 2021-04-08 14:40:57 +0000 | [diff] [blame] | 114 | srcs = ["a.py"], |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 115 | )`, |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 116 | }, |
Lukacs T. Berki | c1cc3b9 | 2021-05-21 09:37:00 +0200 | [diff] [blame] | 117 | }) |
Jingwen Chen | 13b9b42 | 2021-03-08 07:32:28 -0500 | [diff] [blame] | 118 | } |