aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/interpreter.py
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2016-12-07 07:03:15 +0530
committerJussi Pakkanen <jpakkane@gmail.com>2016-12-11 01:59:58 +0200
commit60716fcd6debd9f1ebca0091c945df16a3bd3715 (patch)
tree75b1444898aabcd90b9e4731f4eb1d56a078c790 /mesonbuild/interpreter.py
parentbe04aa2a0b00d123aae78da2448a216f7e3201b9 (diff)
downloadmeson-60716fcd6debd9f1ebca0091c945df16a3bd3715.zip
meson-60716fcd6debd9f1ebca0091c945df16a3bd3715.tar.gz
meson-60716fcd6debd9f1ebca0091c945df16a3bd3715.tar.bz2
Use universal_newlines=True for all Popen calls
Instead of adding it everywhere manually, create a wrapper called mesonlib.Popen_safe and use that everywhere that we call an executable and extract its output. This will also allow us to tweak it to do more/different things if needed for some locales and/or systems. Closes #1079
Diffstat (limited to 'mesonbuild/interpreter.py')
-rw-r--r--mesonbuild/interpreter.py21
1 files changed, 5 insertions, 16 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index 3d4f092..9454302 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -22,6 +22,7 @@ from . import optinterpreter
from . import compilers
from .wrap import wrap
from . import mesonlib
+from .mesonlib import Popen_safe
from .dependencies import InternalDependency, Dependency
from .interpreterbase import InterpreterBase
from .interpreterbase import check_stringlist, noPosargs, noKwargs, stringArgs
@@ -70,17 +71,8 @@ class RunProcess(InterpreterObject):
def __init__(self, command_array, source_dir, build_dir, subdir, in_builddir=False):
super().__init__()
- pc = self.run_command(command_array, source_dir, build_dir, subdir, in_builddir)
- (stdout, stderr) = pc.communicate()
+ pc, self.stdout, self.stderr = self.run_command(command_array, source_dir, build_dir, subdir, in_builddir)
self.returncode = pc.returncode
- if sys.stdout.encoding:
- self.stdout = stdout.decode(encoding=sys.stdout.encoding, errors='ignore').replace('\r\n', '\n')
- else:
- self.stdout = stdout.decode(errors='ignore').replace('\r\n', '\n')
- if sys.stderr.encoding:
- self.stderr = stderr.decode(encoding=sys.stderr.encoding, errors='ignore').replace('\r\n', '\n')
- else:
- self.stderr = stderr.decode(errors='ignore').replace('\r\n', '\n')
self.methods.update({'returncode' : self.returncode_method,
'stdout' : self.stdout_method,
'stderr' : self.stderr_method,
@@ -99,22 +91,19 @@ class RunProcess(InterpreterObject):
child_env.update(env)
mlog.debug('Running command:', ' '.join(command_array))
try:
- return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- env=child_env, cwd=cwd)
+ return Popen_safe(command_array, env=child_env, cwd=cwd)
except FileNotFoundError:
pass
# Was not a command, is a program in path?
exe = shutil.which(cmd_name)
if exe is not None:
command_array = [exe] + command_array[1:]
- return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- env=child_env, cwd=cwd)
+ return Popen_safe(command_array, env=child_env, cwd=cwd)
# No? Maybe it is a script in the source tree.
fullpath = os.path.join(source_dir, subdir, cmd_name)
command_array = [fullpath] + command_array[1:]
try:
- return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
- env=child_env, cwd=cwd)
+ return Popen_safe(command_array, env=child_env, cwd=cwd)
except FileNotFoundError:
raise InterpreterException('Could not execute command "%s".' % cmd_name)