mirror of
https://github.com/imputnet/helium.git
synced 2026-08-20 00:57:32 +02:00
Backport subprocess.run from Python 3.5 for use with 3.4. Fixes #97
Fix bison setup on Windows. See #89
This commit is contained in:
+1
-1
@@ -53,7 +53,7 @@ For maximum portability, the build configuration will generate x86 binaries.
|
||||
* These files are portable.
|
||||
* [gperf from GNUWin32](http://gnuwin32.sourceforge.net/packages/gperf.htm)
|
||||
* [bison from GNUWin32](http://gnuwin32.sourceforge.net/packages/bison.htm)
|
||||
* Get the Binaries, Developer files, and Dependencies
|
||||
* Get the Binaries, Developer files, Sources, and Dependencies
|
||||
|
||||
### Setting up the build environment
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import tarfile
|
||||
import urllib.request
|
||||
import shutil
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
class BuilderException(Exception):
|
||||
'''buildlib Builder exception for distinguishing errors'''
|
||||
@@ -161,3 +162,54 @@ def download_if_needed(logger, file_path, url, force_download):
|
||||
shutil.copyfileobj(response, file_obj)
|
||||
else:
|
||||
logger.info("{} already exists. Skipping download.".format(str(file_path)))
|
||||
|
||||
# This is a port of run() from https://hg.python.org/cpython/file/3.5/Lib/subprocess.py#l662
|
||||
# TODO: Delete this when Python 3.5 is required
|
||||
def subprocess_run(*popenargs, input=None, timeout=None, check=False, **kwargs):
|
||||
"""Run command with arguments and return a CompletedProcess instance.
|
||||
|
||||
The returned instance will have attributes args, returncode, stdout and
|
||||
stderr. By default, stdout and stderr are not captured, and those attributes
|
||||
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.
|
||||
|
||||
If check is True and the exit code was non-zero, it raises a
|
||||
CalledProcessError. The CalledProcessError object will have the return code
|
||||
in the returncode attribute, and output & stderr attributes if those streams
|
||||
were captured.
|
||||
|
||||
If timeout is given, and the process takes too long, a TimeoutExpired
|
||||
exception will be raised.
|
||||
|
||||
There is an optional argument "input", allowing you to
|
||||
pass a string to the subprocess's stdin. If you use this argument
|
||||
you may not also use the Popen constructor's "stdin" argument, as
|
||||
it will be used internally.
|
||||
|
||||
The other arguments are the same as for the Popen constructor.
|
||||
|
||||
If universal_newlines=True is passed, the "input" argument must be a
|
||||
string and stdout/stderr in the returned object will be strings rather than
|
||||
bytes.
|
||||
"""
|
||||
if input is not None:
|
||||
if 'stdin' in kwargs:
|
||||
raise ValueError('stdin and input arguments may not both be used.')
|
||||
kwargs['stdin'] = subprocess.PIPE
|
||||
|
||||
with subprocess.Popen(*popenargs, **kwargs) as process:
|
||||
try:
|
||||
stdout, stderr = process.communicate(input, timeout=timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
process.kill()
|
||||
stdout, stderr = process.communicate()
|
||||
raise subprocess.TimeoutExpired(process.args, timeout, output=stdout,
|
||||
stderr=stderr)
|
||||
except:
|
||||
process.kill()
|
||||
process.wait()
|
||||
raise
|
||||
retcode = process.poll()
|
||||
if check and retcode:
|
||||
raise subprocess.CalledProcessError(retcode, process.args,
|
||||
output=stdout, stderr=stderr)
|
||||
return subprocess.CompletedProcess(process.args, retcode, stdout, stderr)
|
||||
|
||||
+2
-2
@@ -84,11 +84,11 @@ class Builder:
|
||||
@staticmethod
|
||||
def _run_subprocess(*args, append_environ=None, **kwargs):
|
||||
if append_environ is None:
|
||||
return subprocess.run(*args, **kwargs)
|
||||
return _util.subprocess_run(*args, **kwargs)
|
||||
else:
|
||||
new_env = dict(os.environ)
|
||||
new_env.update(append_environ)
|
||||
return subprocess.run(*args, env=new_env, **kwargs)
|
||||
return _util.subprocess_run(*args, env=new_env, **kwargs)
|
||||
|
||||
def __init__(self, version_configfile=pathlib.Path("version.ini"), chromium_version=None,
|
||||
release_revision=None, build_dir=pathlib.Path("build"), logger=None):
|
||||
|
||||
Reference in New Issue
Block a user