aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers.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/compilers.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/compilers.py')
-rw-r--r--mesonbuild/compilers.py34
1 files changed, 9 insertions, 25 deletions
diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py
index 7b9adde..2ee4aac 100644
--- a/mesonbuild/compilers.py
+++ b/mesonbuild/compilers.py
@@ -18,7 +18,7 @@ import subprocess, os.path
import tempfile
from .import mesonlib
from . import mlog
-from .mesonlib import MesonException, version_compare
+from .mesonlib import MesonException, version_compare, Popen_safe
from . import coredata
"""This file contains the data files of all compilers Meson knows
@@ -457,12 +457,7 @@ class Compiler():
mlog.debug('Working directory: ', tmpdirname)
mlog.debug('Command line: ', ' '.join(commands), '\n')
mlog.debug('Code:\n', code)
- p = subprocess.Popen(commands, cwd=tmpdirname,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- (stde, stdo) = p.communicate()
- stde = stde.decode()
- stdo = stdo.decode()
+ p, stdo, stde = Popen_safe(commands, cwd=tmpdirname)
mlog.debug('Compiler stdout:\n', stdo)
mlog.debug('Compiler stderr:\n', stde)
@@ -600,9 +595,7 @@ class CCompiler(Compiler):
return ['-shared']
def get_library_dirs(self):
- output = subprocess.Popen(self.exelist + ['--print-search-dirs'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
- (stdo, _) = output.communicate()
- stdo = stdo.decode('utf-8')
+ stdo = Popen_safe(self.exelist + ['--print-search-dirs'])[1]
for line in stdo.split('\n'):
if line.startswith('libraries:'):
libstr = line.split('=', 1)[1]
@@ -659,10 +652,7 @@ class CCompiler(Compiler):
ofile.write(code)
# Compile sanity check
cmdlist = self.exelist + extra_flags + [source_name] + self.get_output_args(binary_name)
- pc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=work_dir)
- (stdo, stde) = pc.communicate()
- stdo = stdo.decode()
- stde = stde.decode()
+ pc, stdo, stde = Popen_safe(cmdlist, cwd=work_dir)
mlog.debug('Sanity check compiler command line:', ' '.join(cmdlist))
mlog.debug('Sanity check compile stdout:')
mlog.debug(stdo)
@@ -806,15 +796,11 @@ int main () {{
else:
cmdlist = p.output_name
try:
- pe = subprocess.Popen(cmdlist, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+ pe, so, se = Popen_safe(cmdlist)
except Exception as e:
mlog.debug('Could not run: %s (error: %s)\n' % (cmdlist, e))
return RunResult(False)
- (so, se) = pe.communicate()
- so = so.decode()
- se = se.decode()
mlog.debug('Program stdout:\n')
mlog.debug(so)
mlog.debug('Program stderr:\n')
@@ -1931,7 +1917,7 @@ class VisualStudioCCompiler(CCompiler):
# understand and you can't tell it to error out on those.
# http://stackoverflow.com/questions/15259720/how-can-i-make-the-microsoft-c-compiler-treat-unknown-flags-as-errors-rather-t
def has_argument(self, arg, env):
- warning_text = b'9002'
+ warning_text = '9002'
code = 'int i;\n'
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
os.close(fd)
@@ -1944,8 +1930,7 @@ class VisualStudioCCompiler(CCompiler):
mlog.debug('Running VS compile:')
mlog.debug('Command line: ', ' '.join(commands))
mlog.debug('Code:\n', code)
- p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (stde, stdo) = p.communicate()
+ p, stdo, stde = Popen_safe(commands, cwd=os.path.split(srcname)[0])
if p.returncode != 0:
raise MesonException('Compiling test app failed.')
return not(warning_text in stde or warning_text in stdo)
@@ -2614,10 +2599,9 @@ class ArLinker():
def __init__(self, exelist):
self.exelist = exelist
self.id = 'ar'
- pc = subprocess.Popen(self.exelist + ['-h'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
- (stdo, _) = pc.communicate()
+ pc, stdo = Popen_safe(self.exelist + ['-h'])[0:2]
# Enable deterministic builds if they are available.
- if b'[D]' in stdo:
+ if '[D]' in stdo:
self.std_args = ['csrD']
else:
self.std_args = ['csr']