diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-07 07:03:15 +0530 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-12-11 01:59:58 +0200 |
commit | 60716fcd6debd9f1ebca0091c945df16a3bd3715 (patch) | |
tree | 75b1444898aabcd90b9e4731f4eb1d56a078c790 /mesonbuild/modules | |
parent | be04aa2a0b00d123aae78da2448a216f7e3201b9 (diff) | |
download | meson-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/modules')
-rw-r--r-- | mesonbuild/modules/gnome.py | 6 | ||||
-rw-r--r-- | mesonbuild/modules/qt4.py | 26 | ||||
-rw-r--r-- | mesonbuild/modules/qt5.py | 26 |
3 files changed, 22 insertions, 36 deletions
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 5751406..caf162f 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -20,7 +20,7 @@ import os import sys import copy import subprocess -from ..mesonlib import MesonException +from ..mesonlib import MesonException, Popen_safe from .. import dependencies from .. import mlog from .. import mesonlib @@ -197,9 +197,7 @@ can not be used with the current version of glib-compiled-resources, due to cmd += ['--sourcedir', os.path.join(state.subdir, source_dir)] cmd += ['--sourcedir', state.subdir] # Current dir - pc = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True, - cwd=state.environment.get_source_dir()) - (stdout, _) = pc.communicate() + pc, stdout = Popen_safe(cmd, cwd=state.environment.get_source_dir())[0:2] if pc.returncode != 0: mlog.warning('glib-compile-resources has failed to get the dependencies for {}'.format(cmd[1])) raise subprocess.CalledProcessError(pc.returncode, cmd) diff --git a/mesonbuild/modules/qt4.py b/mesonbuild/modules/qt4.py index 5108baa..ab285fb 100644 --- a/mesonbuild/modules/qt4.py +++ b/mesonbuild/modules/qt4.py @@ -15,7 +15,7 @@ import os, subprocess from .. import mlog from .. import build -from ..mesonlib import MesonException +from ..mesonlib import MesonException, Popen_safe from ..dependencies import Qt4Dependency import xml.etree.ElementTree as ET @@ -37,11 +37,9 @@ class Qt4Module(): # Moc and rcc return a non-zero result when doing so. # What kind of an idiot thought that was a good idea? if self.moc.found(): - mp = subprocess.Popen(self.moc.get_command() + ['-v'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdout, stderr) = mp.communicate() - stdout = stdout.decode().strip() - stderr = stderr.decode().strip() + stdout, stderr = Popen_safe(self.moc.get_command() + ['-v'])[1:3] + stdout = stdout.strip() + stderr = stderr.strip() if 'Qt Meta' in stderr: moc_ver = stderr else: @@ -52,11 +50,9 @@ class Qt4Module(): else: mlog.log(' moc:', mlog.red('NO')) if self.uic.found(): - up = subprocess.Popen(self.uic.get_command() + ['-v'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdout, stderr) = up.communicate() - stdout = stdout.decode().strip() - stderr = stderr.decode().strip() + stdout, stderr = Popen_safe(self.uic.get_command() + ['-v'])[1:3] + stdout = stdout.strip() + stderr = stderr.strip() if 'version 4.' in stderr: uic_ver = stderr else: @@ -67,11 +63,9 @@ class Qt4Module(): else: mlog.log(' uic:', mlog.red('NO')) if self.rcc.found(): - rp = subprocess.Popen(self.rcc.get_command() + ['-v'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdout, stderr) = rp.communicate() - stdout = stdout.decode().strip() - stderr = stderr.decode().strip() + stdout, stderr = Popen_safe(self.rcc.get_command() + ['-v'])[1:3] + stdout = stdout.strip() + stderr = stderr.strip() if 'version 4.' in stderr: rcc_ver = stderr else: diff --git a/mesonbuild/modules/qt5.py b/mesonbuild/modules/qt5.py index 52ad155..56c6269 100644 --- a/mesonbuild/modules/qt5.py +++ b/mesonbuild/modules/qt5.py @@ -15,7 +15,7 @@ import os, subprocess from .. import mlog from .. import build -from ..mesonlib import MesonException +from ..mesonlib import MesonException, Popen_safe from ..dependencies import Qt5Dependency import xml.etree.ElementTree as ET @@ -37,11 +37,9 @@ class Qt5Module(): # Moc and rcc return a non-zero result when doing so. # What kind of an idiot thought that was a good idea? if self.moc.found(): - mp = subprocess.Popen(self.moc.get_command() + ['-v'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdout, stderr) = mp.communicate() - stdout = stdout.decode().strip() - stderr = stderr.decode().strip() + stdout, stderr = Popen_safe(self.moc.get_command() + ['-v'])[1:3] + stdout = stdout.strip() + stderr = stderr.strip() if 'Qt 5' in stderr: moc_ver = stderr elif '5.' in stdout: @@ -54,11 +52,9 @@ class Qt5Module(): else: mlog.log(' moc:', mlog.red('NO')) if self.uic.found(): - up = subprocess.Popen(self.uic.get_command() + ['-v'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdout, stderr) = up.communicate() - stdout = stdout.decode().strip() - stderr = stderr.decode().strip() + stdout, stderr = Popen_safe(self.uic.get_command() + ['-v'])[1:3] + stdout = stdout.strip() + stderr = stderr.strip() if 'version 5.' in stderr: uic_ver = stderr elif '5.' in stdout: @@ -71,11 +67,9 @@ class Qt5Module(): else: mlog.log(' uic:', mlog.red('NO')) if self.rcc.found(): - rp = subprocess.Popen(self.rcc.get_command() + ['-v'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdout, stderr) = rp.communicate() - stdout = stdout.decode().strip() - stderr = stderr.decode().strip() + stdout, stderr = Popen_safe(self.rcc.get_command() + ['-v'])[1:3] + stdout = stdout.strip() + stderr = stderr.strip() if 'version 5.' in stderr: rcc_ver = stderr elif '5.' in stdout: |