summary refs log tree commit diff
path: root/src/etc/maketest.py
blob: f500de5e15d00c623784a62c8662c3ca0c2ab982 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
# file at the top-level directory of this distribution and at
# http://rust-lang.org/COPYRIGHT.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.

import subprocess
import os
import sys


def normalize_path(v):
    """msys1/msys2 automatically converts `/abs/path1:/abs/path2` into
    `c:\real\abs\path1;c:\real\abs\path2` (semicolons) if shell thinks
    the value is list of paths.
    (if there is only one path, it becomes `c:/real/abs/path`.)
    this causes great confusion and error: shell and Makefile doesn't like
    windows paths so it is really error-prone. revert it for peace."""
    v = v.replace('\\', '/')
    # c:/path -> /c/path
    if ':/' in v:
        v = '/' + v.replace(':/', '/')
    return v


def putenv(name, value):
    if os.name == 'nt':
        value = normalize_path(value)
    os.putenv(name, value)


def convert_path_spec(name, value):
    if os.name == 'nt' and name != 'PATH':
        value = ":".join(normalize_path(v) for v in value.split(";"))
    return value

make = sys.argv[2]
putenv('RUSTC', os.path.abspath(sys.argv[3]))
putenv('TMPDIR', os.path.abspath(sys.argv[4]))
putenv('CC', sys.argv[5])
putenv('RUSTDOC', os.path.abspath(sys.argv[6]))
filt = sys.argv[7]
putenv('LD_LIB_PATH_ENVVAR', sys.argv[8])
putenv('HOST_RPATH_DIR', os.path.abspath(sys.argv[9]))
putenv('TARGET_RPATH_DIR', os.path.abspath(sys.argv[10]))
putenv('RUST_BUILD_STAGE', sys.argv[11])
putenv('S', os.path.abspath(sys.argv[12]))
putenv('PYTHON', sys.executable)

if filt not in sys.argv[1]:
    sys.exit(0)
print('maketest: ' + os.path.basename(os.path.dirname(sys.argv[1])))

path = sys.argv[1]
if path[-1] == '/':
    # msys1 has a bug that `make` fails to include `../tools.mk` (parent dir)
    # if `-C path` option is given and `path` is absolute directory with
    # trailing slash (`c:/path/to/test/`).
    # the easist workaround is to remove the slash (`c:/path/to/test`).
    # msys2 seems to fix this problem.
    path = path[:-1]

proc = subprocess.Popen([make, '-C', path],
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)
out, err = proc.communicate()
i = proc.wait()

if i != 0:
    print """\
----- %s --------------------
------ stdout ---------------------------------------------
%s
------ stderr ---------------------------------------------
%s
------        ---------------------------------------------
""" % (sys.argv[1], out, err)

    sys.exit(i)