Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 1 | package bp2build |
| 2 | |
| 3 | import ( |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 4 | "fmt" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 5 | "testing" |
| 6 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 7 | "android/soong/android" |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 8 | "android/soong/python" |
| 9 | ) |
| 10 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 11 | // TODO(alexmarquez): Should be lifted into a generic Bp2Build file |
| 12 | type PythonLibBp2Build func(ctx android.TopDownMutatorContext) |
| 13 | |
| 14 | func TestPythonLibrary(t *testing.T) { |
| 15 | testPythonLib(t, "python_library", |
| 16 | python.PythonLibraryFactory, python.PythonLibraryBp2Build) |
| 17 | } |
| 18 | |
| 19 | func TestPythonLibraryHost(t *testing.T) { |
| 20 | testPythonLib(t, "python_library_host", |
| 21 | python.PythonLibraryHostFactory, python.PythonLibraryHostBp2Build) |
| 22 | } |
| 23 | |
| 24 | func testPythonLib(t *testing.T, modType string, |
| 25 | factory android.ModuleFactory, mutator PythonLibBp2Build) { |
| 26 | t.Helper() |
| 27 | // Simple |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 28 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 29 | description: fmt.Sprintf("simple %s converts to a native py_library", modType), |
| 30 | moduleTypeUnderTest: modType, |
| 31 | moduleTypeUnderTestFactory: factory, |
| 32 | moduleTypeUnderTestBp2BuildMutator: mutator, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 33 | filesystem: map[string]string{ |
| 34 | "a.py": "", |
| 35 | "b/c.py": "", |
| 36 | "b/d.py": "", |
| 37 | "b/e.py": "", |
| 38 | "files/data.txt": "", |
| 39 | }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 40 | blueprint: fmt.Sprintf(`%s { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 41 | name: "foo", |
| 42 | srcs: ["**/*.py"], |
| 43 | exclude_srcs: ["b/e.py"], |
| 44 | data: ["files/data.txt",], |
| 45 | bazel_module: { bp2build_available: true }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 46 | }`, modType), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 47 | expectedBazelTargets: []string{`py_library( |
| 48 | name = "foo", |
| 49 | data = ["files/data.txt"], |
| 50 | srcs = [ |
| 51 | "a.py", |
| 52 | "b/c.py", |
| 53 | "b/d.py", |
| 54 | ], |
| 55 | srcs_version = "PY3", |
| 56 | )`, |
| 57 | }, |
| 58 | }) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 59 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 60 | // PY2 |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 61 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 62 | description: fmt.Sprintf("py2 %s converts to a native py_library", modType), |
| 63 | moduleTypeUnderTest: modType, |
| 64 | moduleTypeUnderTestFactory: factory, |
| 65 | moduleTypeUnderTestBp2BuildMutator: mutator, |
| 66 | blueprint: fmt.Sprintf(`%s { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 67 | name: "foo", |
| 68 | srcs: ["a.py"], |
| 69 | version: { |
| 70 | py2: { |
| 71 | enabled: true, |
| 72 | }, |
| 73 | py3: { |
| 74 | enabled: false, |
| 75 | }, |
| 76 | }, |
| 77 | |
| 78 | bazel_module: { bp2build_available: true }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 79 | }`, modType), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 80 | expectedBazelTargets: []string{`py_library( |
| 81 | name = "foo", |
| 82 | srcs = ["a.py"], |
| 83 | srcs_version = "PY2", |
| 84 | )`, |
| 85 | }, |
| 86 | }) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 87 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 88 | // PY3 |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 89 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 90 | description: fmt.Sprintf("py3 %s converts to a native py_library", modType), |
| 91 | moduleTypeUnderTest: modType, |
| 92 | moduleTypeUnderTestFactory: factory, |
| 93 | moduleTypeUnderTestBp2BuildMutator: mutator, |
| 94 | blueprint: fmt.Sprintf(`%s { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 95 | name: "foo", |
| 96 | srcs: ["a.py"], |
| 97 | version: { |
| 98 | py2: { |
| 99 | enabled: false, |
| 100 | }, |
| 101 | py3: { |
| 102 | enabled: true, |
| 103 | }, |
| 104 | }, |
| 105 | |
| 106 | bazel_module: { bp2build_available: true }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 107 | }`, modType), |
| 108 | expectedBazelTargets: []string{`py_library( |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 109 | name = "foo", |
| 110 | srcs = ["a.py"], |
| 111 | srcs_version = "PY3", |
| 112 | )`, |
| 113 | }, |
| 114 | }) |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 115 | |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 116 | // Both |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 117 | runBp2BuildTestCaseSimple(t, bp2buildTestCase{ |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 118 | description: fmt.Sprintf("py2&3 %s converts to a native py_library", modType), |
| 119 | moduleTypeUnderTest: modType, |
| 120 | moduleTypeUnderTestFactory: factory, |
| 121 | moduleTypeUnderTestBp2BuildMutator: mutator, |
| 122 | blueprint: fmt.Sprintf(`%s { |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 123 | name: "foo", |
| 124 | srcs: ["a.py"], |
| 125 | version: { |
| 126 | py2: { |
| 127 | enabled: true, |
| 128 | }, |
| 129 | py3: { |
| 130 | enabled: true, |
| 131 | }, |
| 132 | }, |
| 133 | |
| 134 | bazel_module: { bp2build_available: true }, |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | dc212c0 | 2021-08-23 20:21:19 +0000 | [diff] [blame^] | 135 | }`, modType), |
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux | 0fc781c | 2021-08-19 19:21:30 +0000 | [diff] [blame] | 136 | expectedBazelTargets: []string{ |
| 137 | // srcs_version is PY2ANDPY3 by default. |
| 138 | `py_library( |
| 139 | name = "foo", |
| 140 | srcs = ["a.py"], |
| 141 | )`, |
| 142 | }, |
| 143 | }) |
| 144 | } |