diff options
author | Simon Wörner <git@simon-woerner.de> | 2017-11-24 20:28:18 +0100 |
---|---|---|
committer | Simon Wörner <git@simon-woerner.de> | 2017-11-24 20:47:00 +0100 |
commit | f08b473c50550697fc401c8ff4b923aefdbd00fc (patch) | |
tree | b4ca726d32640430266d965296bbcfc256c7384d /python/mach_bootstrap.py | |
parent | 2374224cdfdf0bb4e8349646427e24e56d8955eb (diff) | |
download | servo-f08b473c50550697fc401c8ff4b923aefdbd00fc.tar.gz servo-f08b473c50550697fc401c8ff4b923aefdbd00fc.zip |
Redirect stdout and stderr to file to avoid deadlock
Diffstat (limited to 'python/mach_bootstrap.py')
-rw-r--r-- | python/mach_bootstrap.py | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/python/mach_bootstrap.py b/python/mach_bootstrap.py index 889a63f312c..4ea216540b9 100644 --- a/python/mach_bootstrap.py +++ b/python/mach_bootstrap.py @@ -8,7 +8,9 @@ import os import platform import sys from distutils.spawn import find_executable -from subprocess import PIPE, Popen +from subprocess import Popen +import shutil +from tempfile import TemporaryFile SEARCH_PATHS = [ os.path.join("python", "tidy"), @@ -101,6 +103,25 @@ def _get_virtualenv_script_dir(): return "bin" +def _process_exec(args): + with TemporaryFile() as out: + with TemporaryFile() as err: + process = Popen(args, stdout=out, stderr=err) + process.wait() + if process.returncode: + print('"%s" failed with error code %d:' % ('" "'.join(args), process.returncode)) + + print('Output:') + out.seek(0) + shutil.copyfileobj(out, sys.stdout) + + print('Error:') + err.seek(0) + shutil.copyfileobj(err, sys.stdout) + + sys.exit() + + def wpt_path(is_firefox, topdir, *paths): if is_firefox: rel = os.path.join("..", "testing", "web-platform") @@ -135,16 +156,8 @@ def _activate_virtualenv(topdir, is_firefox): if not virtualenv: sys.exit("Python virtualenv is not installed. Please install it prior to running mach.") - process = Popen( - [virtualenv, "-p", python, "--system-site-packages", virtualenv_path], - stdout=PIPE, - stderr=PIPE - ) - process.wait() - if process.returncode: - out, err = process.communicate() - print('Python virtualenv failed to execute properly:') - sys.exit('Output: %s\nError: %s' % (out, err)) + _process_exec([virtualenv, "-p", python, "--system-site-packages", virtualenv_path]) + # We want to upgrade pip when virtualenv created for the first time need_pip_upgrade = True @@ -174,12 +187,7 @@ def _activate_virtualenv(topdir, is_firefox): if not pip: sys.exit("Python pip is either not installed or not found in virtualenv.") - process = Popen([pip, "install", "-q", "-I", "-U", "pip"], stdout=PIPE, stderr=PIPE) - process.wait() - if process.returncode: - out, err = process.communicate() - print('Pip failed to upgrade itself properly:') - sys.exit('Output: %s\nError: %s' % (out, err)) + _process_exec([pip, "install", "-q", "-I", "-U", "pip"]) for req_rel_path in requirements_paths: req_path = os.path.join(topdir, req_rel_path) @@ -196,12 +204,7 @@ def _activate_virtualenv(topdir, is_firefox): if not pip: sys.exit("Python pip is either not installed or not found in virtualenv.") - process = Popen([pip, "install", "-q", "-I", "-r", req_path], stdout=PIPE, stderr=PIPE) - process.wait() - if process.returncode: - out, err = process.communicate() - print('Pip failed to execute properly:') - sys.exit('Output: %s\nError: %s' % (out, err)) + _process_exec([pip, "install", "-q", "-I", "-r", req_path]) open(marker_path, 'w').close() |