Corentin Wallez | 76b49d5 | 2022-04-12 16:10:41 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 2 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | # Copyright 2022 The Dawn & Tint Authors |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 4 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 5 | # Redistribution and use in source and binary forms, with or without |
| 6 | # modification, are permitted provided that the following conditions are met: |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 7 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 8 | # 1. Redistributions of source code must retain the above copyright notice, this |
| 9 | # list of conditions and the following disclaimer. |
Austin Eng | 1cdea90 | 2022-03-24 00:21:55 +0000 | [diff] [blame] | 10 | # |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 11 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | # this list of conditions and the following disclaimer in the documentation |
| 13 | # and/or other materials provided with the distribution. |
| 14 | # |
| 15 | # 3. Neither the name of the copyright holder nor the names of its |
| 16 | # contributors may be used to endorse or promote products derived from |
| 17 | # this software without specific prior written permission. |
| 18 | # |
| 19 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 23 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 24 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 25 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 26 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 27 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 29 | |
| 30 | import subprocess |
| 31 | import sys |
| 32 | import os |
| 33 | |
| 34 | from dir_paths import node_dir |
| 35 | |
| 36 | try: |
| 37 | old_sys_path = sys.path |
| 38 | sys.path = [node_dir] + sys.path |
| 39 | |
| 40 | from node import GetBinaryPath as get_node_binary_path |
| 41 | finally: |
| 42 | sys.path = old_sys_path |
| 43 | |
| 44 | tsc = os.path.join(node_dir, 'node_modules', 'typescript', 'lib', 'tsc.js') |
| 45 | |
| 46 | |
| 47 | def run_tsc_ignore_errors(args): |
| 48 | cmd = [get_node_binary_path(), tsc] + args |
| 49 | process = subprocess.Popen(cmd, |
| 50 | cwd=os.getcwd(), |
| 51 | stdout=subprocess.PIPE, |
| 52 | stderr=subprocess.PIPE) |
| 53 | |
| 54 | stdout, stderr = process.communicate() |
| 55 | |
| 56 | # Typecheck errors go in stdout, not stderr. If we see something in stderr, raise an error. |
| 57 | if len(stderr): |
| 58 | raise RuntimeError('tsc \'%s\' failed\n%s' % (' '.join(cmd), stderr)) |
| 59 | |
| 60 | return stdout |
| 61 | |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | run_tsc_ignore_errors(sys.argv[1:]) |