]> git.lizzy.rs Git - rust.git/blob - src/etc/maketest.py
Auto merge of #31684 - tmiasko:alternate-stack, r=alexcrichton
[rust.git] / src / etc / maketest.py
1 # Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 import subprocess
12 import os
13 import sys
14
15 target_triple = sys.argv[14]
16
17 def normalize_path(v):
18     """msys1/msys2 automatically converts `/abs/path1:/abs/path2` into
19     `c:\real\abs\path1;c:\real\abs\path2` (semicolons) if shell thinks
20     the value is list of paths.
21     (if there is only one path, it becomes `c:/real/abs/path`.)
22     this causes great confusion and error: shell and Makefile doesn't like
23     windows paths so it is really error-prone. revert it for peace."""
24     v = v.replace('\\', '/')
25     # c:/path -> /c/path
26     # "c:/path" -> "/c/path"
27     start = v.find(':/')
28     while start != -1:
29         v = v[:start - 1] + '/' + v[start - 1:start] + v[start + 1:]
30         start = v.find(':/')
31     return v
32
33
34 def putenv(name, value):
35     if os.name == 'nt':
36         value = normalize_path(value)
37     os.putenv(name, value)
38
39
40 def convert_path_spec(name, value):
41     if os.name == 'nt' and name != 'PATH':
42         value = ":".join(normalize_path(v) for v in value.split(";"))
43     return value
44
45 make = sys.argv[2]
46 putenv('RUSTC', os.path.abspath(sys.argv[3]))
47 putenv('TMPDIR', os.path.abspath(sys.argv[4]))
48 putenv('CC', sys.argv[5] + ' ' + sys.argv[6])
49 putenv('CFLAGS', sys.argv[6])
50 putenv('RUSTDOC', os.path.abspath(sys.argv[7]))
51 filt = sys.argv[8]
52 putenv('LD_LIB_PATH_ENVVAR', sys.argv[9])
53 putenv('HOST_RPATH_DIR', os.path.abspath(sys.argv[10]))
54 putenv('TARGET_RPATH_DIR', os.path.abspath(sys.argv[11]))
55 putenv('RUST_BUILD_STAGE', sys.argv[12])
56 putenv('S', os.path.abspath(sys.argv[13]))
57 putenv('RUSTFLAGS', sys.argv[15])
58 putenv('LLVM_COMPONENTS', sys.argv[16])
59 putenv('LLVM_CXXFLAGS', sys.argv[17])
60 putenv('CXX', sys.argv[18])
61 putenv('PYTHON', sys.executable)
62 os.putenv('TARGET', target_triple)
63
64 if 'msvc' in target_triple:
65     os.putenv('IS_MSVC', '1')
66
67 if filt not in sys.argv[1]:
68     sys.exit(0)
69 print('maketest: ' + os.path.basename(os.path.dirname(sys.argv[1])))
70
71 path = sys.argv[1]
72 if path[-1] == '/':
73     # msys1 has a bug that `make` fails to include `../tools.mk` (parent dir)
74     # if `-C path` option is given and `path` is absolute directory with
75     # trailing slash (`c:/path/to/test/`).
76     # the easist workaround is to remove the slash (`c:/path/to/test`).
77     # msys2 seems to fix this problem.
78     path = path[:-1]
79
80 proc = subprocess.Popen([make, '-C', path],
81                         stdout=subprocess.PIPE,
82                         stderr=subprocess.PIPE)
83 out, err = proc.communicate()
84 i = proc.wait()
85
86 if i != 0:
87     print """\
88 ----- %s --------------------
89 ------ stdout ---------------------------------------------
90 %s
91 ------ stderr ---------------------------------------------
92 %s
93 ------        ---------------------------------------------
94 """ % (sys.argv[1], out, err)
95
96     sys.exit(i)