]> git.lizzy.rs Git - rust.git/blob - src/etc/maketest.py
Auto merge of #27239 - apasel422:issue-19102, r=huonw
[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
16 def normalize_path(v):
17     """msys1/msys2 automatically converts `/abs/path1:/abs/path2` into
18     `c:\real\abs\path1;c:\real\abs\path2` (semicolons) if shell thinks
19     the value is list of paths.
20     (if there is only one path, it becomes `c:/real/abs/path`.)
21     this causes great confusion and error: shell and Makefile doesn't like
22     windows paths so it is really error-prone. revert it for peace."""
23     v = v.replace('\\', '/')
24     # c:/path -> /c/path
25     if ':/' in v:
26         v = '/' + v.replace(':/', '/')
27     return v
28
29
30 def putenv(name, value):
31     if os.name == 'nt':
32         value = normalize_path(value)
33     os.putenv(name, value)
34
35
36 def convert_path_spec(name, value):
37     if os.name == 'nt' and name != 'PATH':
38         value = ":".join(normalize_path(v) for v in value.split(";"))
39     return value
40
41 make = sys.argv[2]
42 putenv('RUSTC', os.path.abspath(sys.argv[3]))
43 putenv('TMPDIR', os.path.abspath(sys.argv[4]))
44 putenv('CC', sys.argv[5] + ' ' + sys.argv[6])
45 putenv('RUSTDOC', os.path.abspath(sys.argv[7]))
46 filt = sys.argv[8]
47 putenv('LD_LIB_PATH_ENVVAR', sys.argv[9])
48 putenv('HOST_RPATH_DIR', os.path.abspath(sys.argv[10]))
49 putenv('TARGET_RPATH_DIR', os.path.abspath(sys.argv[11]))
50 putenv('RUST_BUILD_STAGE', sys.argv[12])
51 putenv('S', os.path.abspath(sys.argv[13]))
52 putenv('PYTHON', sys.executable)
53
54 if filt not in sys.argv[1]:
55     sys.exit(0)
56 print('maketest: ' + os.path.basename(os.path.dirname(sys.argv[1])))
57
58 path = sys.argv[1]
59 if path[-1] == '/':
60     # msys1 has a bug that `make` fails to include `../tools.mk` (parent dir)
61     # if `-C path` option is given and `path` is absolute directory with
62     # trailing slash (`c:/path/to/test/`).
63     # the easist workaround is to remove the slash (`c:/path/to/test`).
64     # msys2 seems to fix this problem.
65     path = path[:-1]
66
67 proc = subprocess.Popen([make, '-C', path],
68                         stdout=subprocess.PIPE,
69                         stderr=subprocess.PIPE)
70 out, err = proc.communicate()
71 i = proc.wait()
72
73 if i != 0:
74     print """\
75 ----- %s --------------------
76 ------ stdout ---------------------------------------------
77 %s
78 ------ stderr ---------------------------------------------
79 %s
80 ------        ---------------------------------------------
81 """ % (sys.argv[1], out, err)
82
83     sys.exit(i)