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 | # |
| 3 | # Copyright 2022 The Dawn Authors |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
Kai Ninomiya | 5c780d7 | 2022-03-17 21:43:17 +0000 | [diff] [blame] | 16 | |
| 17 | import subprocess |
| 18 | import sys |
| 19 | import os |
| 20 | |
| 21 | from dir_paths import node_dir |
| 22 | |
| 23 | try: |
| 24 | old_sys_path = sys.path |
| 25 | sys.path = [node_dir] + sys.path |
| 26 | |
| 27 | from node import GetBinaryPath as get_node_binary_path |
| 28 | finally: |
| 29 | sys.path = old_sys_path |
| 30 | |
| 31 | tsc = os.path.join(node_dir, 'node_modules', 'typescript', 'lib', 'tsc.js') |
| 32 | |
| 33 | |
| 34 | def run_tsc_ignore_errors(args): |
| 35 | cmd = [get_node_binary_path(), tsc] + args |
| 36 | process = subprocess.Popen(cmd, |
| 37 | cwd=os.getcwd(), |
| 38 | stdout=subprocess.PIPE, |
| 39 | stderr=subprocess.PIPE) |
| 40 | |
| 41 | stdout, stderr = process.communicate() |
| 42 | |
| 43 | # Typecheck errors go in stdout, not stderr. If we see something in stderr, raise an error. |
| 44 | if len(stderr): |
| 45 | raise RuntimeError('tsc \'%s\' failed\n%s' % (' '.join(cmd), stderr)) |
| 46 | |
| 47 | return stdout |
| 48 | |
| 49 | |
| 50 | if __name__ == '__main__': |
| 51 | run_tsc_ignore_errors(sys.argv[1:]) |