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