From 60716fcd6debd9f1ebca0091c945df16a3bd3715 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 7 Dec 2016 07:03:15 +0530 Subject: 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 --- mesonbuild/scripts/meson_exe.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'mesonbuild/scripts/meson_exe.py') diff --git a/mesonbuild/scripts/meson_exe.py b/mesonbuild/scripts/meson_exe.py index 3ea392690..d412e010a 100755 --- a/mesonbuild/scripts/meson_exe.py +++ b/mesonbuild/scripts/meson_exe.py @@ -21,7 +21,7 @@ import pickle import platform import subprocess -import mesonbuild +from ..mesonlib import MesonException, Popen_safe options = None @@ -45,7 +45,7 @@ def run_exe(exe): else: if exe.is_cross: if exe.exe_runner is None: - raise Exception('BUG: Trying to run cross-compiled exes with no wrapper') + raise AssertionError('BUG: Trying to run cross-compiled exes with no wrapper') else: cmd = [exe.exe_runner] + exe.fname else: @@ -55,17 +55,12 @@ def run_exe(exe): if len(exe.extra_paths) > 0: child_env['PATH'] = (os.pathsep.join(exe.extra_paths + ['']) + child_env['PATH']) - p = subprocess.Popen(cmd + exe.cmd_args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env=child_env, - cwd=exe.workdir) - stdout, stderr = p.communicate() + p, stdout, stderr = Popen_safe(cmd + exe.cmd_args, env=child_env, cwd=exe.workdir) if exe.capture and p.returncode == 0: - with open(exe.capture, 'wb') as output: + with open(exe.capture, 'w') as output: output.write(stdout) if stderr: - sys.stderr.buffer.write(stderr) + sys.stderr.write(stderr) return p.returncode def run(args): -- cgit v1.2.3