blob: 01323afe8fef014463c2b897855b7f720553e08f [file] [log] [blame]
Corentin Wallez76b49d52022-04-12 16:10:41 +00001#!/usr/bin/env python3
Austin Eng1cdea902022-03-24 00:21:55 +00002#
Austin Engcc2516a2023-10-17 20:57:54 +00003# Copyright 2022 The Dawn & Tint Authors
Austin Eng1cdea902022-03-24 00:21:55 +00004#
Austin Engcc2516a2023-10-17 20:57:54 +00005# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions are met:
Austin Eng1cdea902022-03-24 00:21:55 +00007#
Austin Engcc2516a2023-10-17 20:57:54 +00008# 1. Redistributions of source code must retain the above copyright notice, this
9# list of conditions and the following disclaimer.
Austin Eng1cdea902022-03-24 00:21:55 +000010#
Austin Engcc2516a2023-10-17 20:57:54 +000011# 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 Ninomiya5c780d72022-03-17 21:43:17 +000029
30import subprocess
31import sys
32import os
33
34from dir_paths import node_dir
35
36try:
37 old_sys_path = sys.path
38 sys.path = [node_dir] + sys.path
39
40 from node import GetBinaryPath as get_node_binary_path
41finally:
42 sys.path = old_sys_path
43
44tsc = os.path.join(node_dir, 'node_modules', 'typescript', 'lib', 'tsc.js')
45
46
47def 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
63if __name__ == '__main__':
64 run_tsc_ignore_errors(sys.argv[1:])