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
pull/1095/head
Nirbheek Chauhan 8 years ago committed by Jussi Pakkanen
parent be04aa2a0b
commit 60716fcd6d
  1. 20
      mesonbuild/backend/ninjabackend.py
  2. 34
      mesonbuild/compilers.py
  3. 82
      mesonbuild/dependencies.py
  4. 69
      mesonbuild/environment.py
  5. 21
      mesonbuild/interpreter.py
  6. 7
      mesonbuild/mesonlib.py
  7. 6
      mesonbuild/modules/gnome.py
  8. 26
      mesonbuild/modules/qt4.py
  9. 26
      mesonbuild/modules/qt5.py
  10. 14
      mesonbuild/scripts/gtkdochelper.py
  11. 15
      mesonbuild/scripts/meson_exe.py
  12. 8
      mesonbuild/scripts/meson_install.py
  13. 18
      mesonbuild/scripts/symbolextractor.py

@ -18,7 +18,7 @@ from .. import build
from .. import mlog from .. import mlog
from .. import dependencies from .. import dependencies
from .. import compilers from .. import compilers
from ..mesonlib import File, MesonException, get_compiler_for_source from ..mesonlib import File, MesonException, get_compiler_for_source, Popen_safe
from .backends import InstallData from .backends import InstallData
from ..build import InvalidArguments from ..build import InvalidArguments
import os, sys, pickle, re import os, sys, pickle, re
@ -159,18 +159,14 @@ class NinjaBackend(backends.Backend):
int dummy; int dummy;
''') ''')
pc = subprocess.Popen(['cl', '/showIncludes', '/c', 'incdetect.c'], pc, stdo = Popen_safe(['cl', '/showIncludes', '/c', 'incdetect.c'],
stdout=subprocess.PIPE, cwd=self.environment.get_scratch_dir())[0:2]
stderr=subprocess.PIPE,
cwd=self.environment.get_scratch_dir())
(stdo, _) = pc.communicate() for line in stdo.split('\n'):
if line.endswith('stdio.h'):
for line in stdo.split(b'\r\n'): matchstr = ':'.join(line.split(':')[0:2]) + ':'
if line.endswith(b'stdio.h'): with open(tempfilename, 'a') as binfile:
matchstr = b':'.join(line.split(b':')[0:2]) + b':' binfile.write('msvc_deps_prefix = ' + matchstr + '\n')
with open(tempfilename, 'ab') as binfile:
binfile.write(b'msvc_deps_prefix = ' + matchstr + b'\r\n')
return open(tempfilename, 'a') return open(tempfilename, 'a')
raise MesonException('Could not determine vs dep dependency prefix string.') raise MesonException('Could not determine vs dep dependency prefix string.')

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

@ -23,7 +23,7 @@ import re
import os, stat, glob, subprocess, shutil import os, stat, glob, subprocess, shutil
import sysconfig import sysconfig
from collections import OrderedDict from collections import OrderedDict
from . mesonlib import MesonException, version_compare, version_compare_many from . mesonlib import MesonException, version_compare, version_compare_many, Popen_safe
from . import mlog from . import mlog
from . import mesonlib from . import mesonlib
from .environment import detect_cpu_family, for_windows from .environment import detect_cpu_family, for_windows
@ -170,17 +170,14 @@ class PkgConfigDependency(Dependency):
self._set_libs() self._set_libs()
def _call_pkgbin(self, args): def _call_pkgbin(self, args):
p = subprocess.Popen([self.pkgbin] + args, p, out = Popen_safe([self.pkgbin] + args, env=os.environ)[0:2]
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env=os.environ, universal_newlines=True)
out = p.communicate()[0]
return (p.returncode, out.strip()) return (p.returncode, out.strip())
def _set_cargs(self): def _set_cargs(self):
ret, out = self._call_pkgbin(['--cflags', self.name]) ret, out = self._call_pkgbin(['--cflags', self.name])
if ret != 0: if ret != 0:
raise DependencyException('Could not generate cargs for %s:\n\n%s' % \ raise DependencyException('Could not generate cargs for %s:\n\n%s' % \
(self.name, out.decode(errors='ignore'))) (self.name, out))
self.cargs = out.split() self.cargs = out.split()
def _set_libs(self): def _set_libs(self):
@ -190,7 +187,7 @@ class PkgConfigDependency(Dependency):
ret, out = self._call_pkgbin(libcmd) ret, out = self._call_pkgbin(libcmd)
if ret != 0: if ret != 0:
raise DependencyException('Could not generate libs for %s:\n\n%s' % \ raise DependencyException('Could not generate libs for %s:\n\n%s' % \
(self.name, out.decode(errors='ignore'))) (self.name, out))
self.libs = [] self.libs = []
for lib in out.split(): for lib in out.split():
if lib.endswith(".la"): if lib.endswith(".la"):
@ -238,13 +235,11 @@ class PkgConfigDependency(Dependency):
pkgbin = os.environ[evar].strip() pkgbin = os.environ[evar].strip()
else: else:
pkgbin = 'pkg-config' pkgbin = 'pkg-config'
p = subprocess.Popen([pkgbin, '--version'], stdout=subprocess.PIPE, p, out = Popen_safe([pkgbin, '--version'])[0:2]
stderr=subprocess.PIPE)
out = p.communicate()[0]
if p.returncode == 0: if p.returncode == 0:
if not self.silent: if not self.silent:
mlog.log('Found pkg-config:', mlog.bold(shutil.which(pkgbin)), mlog.log('Found pkg-config:', mlog.bold(shutil.which(pkgbin)),
'(%s)' % out.decode().strip()) '(%s)' % out.strip())
PkgConfigDependency.pkgconfig_found = True PkgConfigDependency.pkgconfig_found = True
return return
except (FileNotFoundError, PermissionError): except (FileNotFoundError, PermissionError):
@ -303,16 +298,13 @@ class WxDependency(Dependency):
mlog.log("Neither wx-config-3.0 nor wx-config found; can't detect dependency") mlog.log("Neither wx-config-3.0 nor wx-config found; can't detect dependency")
return return
p = subprocess.Popen([self.wxc, '--version'], p, out = Popen_safe([self.wxc, '--version'])[0:2]
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
mlog.log('Dependency wxwidgets found:', mlog.red('NO')) mlog.log('Dependency wxwidgets found:', mlog.red('NO'))
self.cargs = [] self.cargs = []
self.libs = [] self.libs = []
else: else:
self.modversion = out.decode().strip() self.modversion = out.strip()
version_req = kwargs.get('version', None) version_req = kwargs.get('version', None)
if version_req is not None: if version_req is not None:
if not version_compare(self.modversion, version_req, strict=True): if not version_compare(self.modversion, version_req, strict=True):
@ -324,20 +316,15 @@ class WxDependency(Dependency):
self.requested_modules = self.get_requested(kwargs) self.requested_modules = self.get_requested(kwargs)
# wx-config seems to have a cflags as well but since it requires C++, # wx-config seems to have a cflags as well but since it requires C++,
# this should be good, at least for now. # this should be good, at least for now.
p = subprocess.Popen([self.wxc, '--cxxflags'], p, out = Popen_safe([self.wxc, '--cxxflags'])[0:2]
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
raise DependencyException('Could not generate cargs for wxwidgets.') raise DependencyException('Could not generate cargs for wxwidgets.')
self.cargs = out.decode().split() self.cargs = out.split()
p = subprocess.Popen([self.wxc, '--libs'] + self.requested_modules, p, out = Popen_safe([self.wxc, '--libs'] + self.requested_modules)[0:2]
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out = p.communicate()[0]
if p.returncode != 0: if p.returncode != 0:
raise DependencyException('Could not generate libs for wxwidgets.') raise DependencyException('Could not generate libs for wxwidgets.')
self.libs = out.decode().split() self.libs = out.split()
def get_requested(self, kwargs): def get_requested(self, kwargs):
modules = 'modules' modules = 'modules'
@ -363,12 +350,10 @@ class WxDependency(Dependency):
def check_wxconfig(self): def check_wxconfig(self):
for wxc in ['wx-config-3.0', 'wx-config']: for wxc in ['wx-config-3.0', 'wx-config']:
try: try:
p = subprocess.Popen([wxc, '--version'], stdout=subprocess.PIPE, p, out = Popen_safe([wxc, '--version'])[0:2]
stderr=subprocess.PIPE)
out = p.communicate()[0]
if p.returncode == 0: if p.returncode == 0:
mlog.log('Found wx-config:', mlog.bold(shutil.which(wxc)), mlog.log('Found wx-config:', mlog.bold(shutil.which(wxc)),
'(%s)' % out.decode().strip()) '(%s)' % out.strip())
self.wxc = wxc self.wxc = wxc
WxDependency.wx_found = True WxDependency.wx_found = True
return return
@ -943,10 +928,7 @@ class QtBaseDependency(Dependency):
if not self.qmake.found(): if not self.qmake.found():
continue continue
# Check that the qmake is for qt5 # Check that the qmake is for qt5
pc = subprocess.Popen(self.qmake.fullpath + ['-v'], pc, stdo = Popen_safe(self.qmake.fullpath + ['-v'])[0:2]
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True)
stdo = pc.communicate()[0]
if pc.returncode != 0: if pc.returncode != 0:
continue continue
if not 'Qt version ' + self.qtver in stdo: if not 'Qt version ' + self.qtver in stdo:
@ -959,9 +941,7 @@ class QtBaseDependency(Dependency):
return return
self.version = re.search(self.qtver + '(\.\d+)+', stdo).group(0) self.version = re.search(self.qtver + '(\.\d+)+', stdo).group(0)
# Query library path, header path, and binary path # Query library path, header path, and binary path
stdo = subprocess.Popen(self.qmake.fullpath + ['-query'], stdo = Popen_safe(self.qmake.fullpath + ['-query'])[1]
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True).communicate()[0]
qvars = {} qvars = {}
for line in stdo.split('\n'): for line in stdo.split('\n'):
line = line.strip() line = line.strip()
@ -1051,9 +1031,7 @@ class GnuStepDependency(Dependency):
def detect(self): def detect(self):
confprog = 'gnustep-config' confprog = 'gnustep-config'
try: try:
gp = subprocess.Popen([confprog, '--help'], gp = Popen_safe([confprog, '--help'])[0]
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
gp.communicate()
except (FileNotFoundError, PermissionError): except (FileNotFoundError, PermissionError):
self.args = None self.args = None
mlog.log('Dependency GnuStep found:', mlog.red('NO'), '(no gnustep-config)') mlog.log('Dependency GnuStep found:', mlog.red('NO'), '(no gnustep-config)')
@ -1066,20 +1044,12 @@ class GnuStepDependency(Dependency):
arg = '--gui-libs' arg = '--gui-libs'
else: else:
arg = '--base-libs' arg = '--base-libs'
fp = subprocess.Popen([confprog, '--objc-flags'], fp, flagtxt, flagerr = Popen_safe([confprog, '--objc-flags'])
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(flagtxt, flagerr) = fp.communicate()
flagtxt = flagtxt.decode()
flagerr = flagerr.decode()
if fp.returncode != 0: if fp.returncode != 0:
raise DependencyException('Error getting objc-args: %s %s' % (flagtxt, flagerr)) raise DependencyException('Error getting objc-args: %s %s' % (flagtxt, flagerr))
args = flagtxt.split() args = flagtxt.split()
self.args = self.filter_arsg(args) self.args = self.filter_arsg(args)
fp = subprocess.Popen([confprog, arg], fp, libtxt, liberr = Popen_safe([confprog, arg])
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(libtxt, liberr) = fp.communicate()
libtxt = libtxt.decode()
liberr = liberr.decode()
if fp.returncode != 0: if fp.returncode != 0:
raise DependencyException('Error getting objc-lib args: %s %s' % (libtxt, liberr)) raise DependencyException('Error getting objc-lib args: %s %s' % (libtxt, liberr))
self.libs = self.weird_filter(libtxt.split()) self.libs = self.weird_filter(libtxt.split())
@ -1184,16 +1154,10 @@ class SDL2Dependency(Dependency):
pass pass
sdlconf = shutil.which('sdl2-config') sdlconf = shutil.which('sdl2-config')
if sdlconf: if sdlconf:
pc = subprocess.Popen(['sdl2-config', '--cflags'], pc, stdo = Popen_safe(['sdl2-config', '--cflags'])[0:2]
stdout=subprocess.PIPE, self.cargs = stdo.strip().split()
stderr=subprocess.DEVNULL) pc, stdo = Popen_safe(['sdl2-config', '--libs'])[0:2]
(stdo, _) = pc.communicate() self.linkargs = stdo.strip().split()
self.cargs = stdo.decode().strip().split()
pc = subprocess.Popen(['sdl2-config', '--libs'],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL)
(stdo, _) = pc.communicate()
self.linkargs = stdo.decode().strip().split()
self.is_found = True self.is_found = True
mlog.log('Dependency', mlog.bold('sdl2'), 'found:', mlog.green('YES'), '(%s)' % sdlconf) mlog.log('Dependency', mlog.bold('sdl2'), 'found:', mlog.green('YES'), '(%s)' % sdlconf)
self.version = '2' # FIXME self.version = '2' # FIXME

@ -17,6 +17,7 @@ from . import coredata
from . import mesonlib from . import mesonlib
from . import mlog from . import mlog
from .compilers import * from .compilers import *
from .mesonlib import Popen_safe
import configparser import configparser
import shutil import shutil
@ -42,11 +43,10 @@ def find_coverage_tools():
def detect_ninja(): def detect_ninja():
for n in ['ninja', 'ninja-build']: for n in ['ninja', 'ninja-build']:
try: try:
p = subprocess.Popen([n, '--version'], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL) p, version = Popen_safe([n, '--version'])[0:2]
except (FileNotFoundError, PermissionError): except (FileNotFoundError, PermissionError):
# Doesn't exist in PATH or isn't executable # Doesn't exist in PATH or isn't executable
continue continue
version = p.communicate()[0].decode(errors='ignore')
# Perhaps we should add a way for the caller to know the failure mode # Perhaps we should add a way for the caller to know the failure mode
# (not found or too old) # (not found or too old)
if p.returncode == 0 and mesonlib.version_compare(version, ">=1.6"): if p.returncode == 0 and mesonlib.version_compare(version, ">=1.6"):
@ -306,9 +306,7 @@ class Environment():
# Arguments to output compiler pre-processor defines to stdout # Arguments to output compiler pre-processor defines to stdout
# gcc, g++, and gfortran all support these arguments # gcc, g++, and gfortran all support these arguments
args = compiler + ['-E', '-dM', '-'] args = compiler + ['-E', '-dM', '-']
p = subprocess.Popen(args, universal_newlines=True, p, output = Popen_safe(args, write='', stdin=subprocess.PIPE)[0:2]
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
output = p.communicate('')[0]
if p.returncode != 0: if p.returncode != 0:
raise EnvironmentException('Unable to detect GNU compiler type:\n' + output) raise EnvironmentException('Unable to detect GNU compiler type:\n' + output)
# Parse several lines of the type: # Parse several lines of the type:
@ -372,14 +370,10 @@ class Environment():
arg = '/?' arg = '/?'
else: else:
arg = '--version' arg = '--version'
p = subprocess.Popen([compiler, arg], stdout=subprocess.PIPE, p, out, err = Popen_safe([compiler, arg])
stderr=subprocess.PIPE)
except OSError as e: except OSError as e:
popen_exceptions[' '.join([compiler, arg])] = e popen_exceptions[' '.join([compiler, arg])] = e
continue continue
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'Free Software Foundation' in out: if 'Free Software Foundation' in out:
defines = self.get_gnu_compiler_defines([compiler]) defines = self.get_gnu_compiler_defines([compiler])
@ -428,15 +422,10 @@ class Environment():
for compiler in compilers: for compiler in compilers:
for arg in ['--version', '-V']: for arg in ['--version', '-V']:
try: try:
p = subprocess.Popen([compiler, arg], p, out, err = Popen_safe([compiler, arg])
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except OSError as e: except OSError as e:
popen_exceptions[' '.join([compiler, arg])] = e popen_exceptions[' '.join([compiler, arg])] = e
continue continue
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
version = search_version(out) version = search_version(out)
@ -512,15 +501,10 @@ class Environment():
else: else:
arg = '--version' arg = '--version'
try: try:
p = subprocess.Popen([compiler, arg], p, out, err = Popen_safe([compiler, arg])
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
except OSError as e: except OSError as e:
popen_exceptions[' '.join([compiler, arg])] = e popen_exceptions[' '.join([compiler, arg])] = e
continue continue
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'Free Software Foundation' in out: if 'Free Software Foundation' in out:
defines = self.get_gnu_compiler_defines([compiler]) defines = self.get_gnu_compiler_defines([compiler])
@ -559,12 +543,9 @@ class Environment():
is_cross = False is_cross = False
exe_wrap = None exe_wrap = None
try: try:
p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out, err = Popen_safe(exelist + ['--version'])
except OSError: except OSError:
raise EnvironmentException('Could not execute ObjC compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute ObjC compiler "%s"' % ' '.join(exelist))
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'Free Software Foundation' in out: if 'Free Software Foundation' in out:
defines = self.get_gnu_compiler_defines(exelist) defines = self.get_gnu_compiler_defines(exelist)
@ -587,12 +568,9 @@ class Environment():
is_cross = False is_cross = False
exe_wrap = None exe_wrap = None
try: try:
p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out, err = Popen_safe(exelist + ['--version'])
except OSError: except OSError:
raise EnvironmentException('Could not execute ObjC++ compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute ObjC++ compiler "%s"' % ' '.join(exelist))
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'Free Software Foundation' in out: if 'Free Software Foundation' in out:
defines = self.get_gnu_compiler_defines(exelist) defines = self.get_gnu_compiler_defines(exelist)
@ -604,12 +582,9 @@ class Environment():
def detect_java_compiler(self): def detect_java_compiler(self):
exelist = ['javac'] exelist = ['javac']
try: try:
p = subprocess.Popen(exelist + ['-version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out, err = Popen_safe(exelist + ['-version'])
except OSError: except OSError:
raise EnvironmentException('Could not execute Java compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute Java compiler "%s"' % ' '.join(exelist))
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
version = search_version(err) version = search_version(err)
if 'javac' in err: if 'javac' in err:
return JavaCompiler(exelist, version) return JavaCompiler(exelist, version)
@ -618,12 +593,9 @@ class Environment():
def detect_cs_compiler(self): def detect_cs_compiler(self):
exelist = ['mcs'] exelist = ['mcs']
try: try:
p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out, err = Popen_safe(exelist + ['--version'])
except OSError: except OSError:
raise EnvironmentException('Could not execute C# compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute C# compiler "%s"' % ' '.join(exelist))
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'Mono' in out: if 'Mono' in out:
return MonoCompiler(exelist, version) return MonoCompiler(exelist, version)
@ -632,11 +604,9 @@ class Environment():
def detect_vala_compiler(self): def detect_vala_compiler(self):
exelist = ['valac'] exelist = ['valac']
try: try:
p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out = Popen_safe(exelist + ['--version'])[0:2]
except OSError: except OSError:
raise EnvironmentException('Could not execute Vala compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute Vala compiler "%s"' % ' '.join(exelist))
(out, _) = p.communicate()
out = out.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'Vala' in out: if 'Vala' in out:
return ValaCompiler(exelist, version) return ValaCompiler(exelist, version)
@ -645,11 +615,9 @@ class Environment():
def detect_rust_compiler(self): def detect_rust_compiler(self):
exelist = ['rustc'] exelist = ['rustc']
try: try:
p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out = Popen_safe(exelist + ['--version'])[0:2]
except OSError: except OSError:
raise EnvironmentException('Could not execute Rust compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute Rust compiler "%s"' % ' '.join(exelist))
(out, _) = p.communicate()
out = out.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'rustc' in out: if 'rustc' in out:
return RustCompiler(exelist, version) return RustCompiler(exelist, version)
@ -679,11 +647,9 @@ class Environment():
raise EnvironmentException('Could not find any supported D compiler.') raise EnvironmentException('Could not find any supported D compiler.')
try: try:
p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out = Popen_safe(exelist + ['--version'])[0:2]
except OSError: except OSError:
raise EnvironmentException('Could not execute D compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute D compiler "%s"' % ' '.join(exelist))
(out, _) = p.communicate()
out = out.decode(errors='ignore')
version = search_version(out) version = search_version(out)
if 'LLVM D compiler' in out: if 'LLVM D compiler' in out:
return LLVMDCompiler(exelist, version, is_cross) return LLVMDCompiler(exelist, version, is_cross)
@ -696,11 +662,9 @@ class Environment():
def detect_swift_compiler(self): def detect_swift_compiler(self):
exelist = ['swiftc'] exelist = ['swiftc']
try: try:
p = subprocess.Popen(exelist + ['-v'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, _, err = Popen_safe(exelist + ['-v'])
except OSError: except OSError:
raise EnvironmentException('Could not execute Swift compiler "%s"' % ' '.join(exelist)) raise EnvironmentException('Could not execute Swift compiler "%s"' % ' '.join(exelist))
(_, err) = p.communicate()
err = err.decode(errors='ignore')
version = search_version(err) version = search_version(err)
if 'Swift' in err: if 'Swift' in err:
return SwiftCompiler(exelist, version) return SwiftCompiler(exelist, version)
@ -723,12 +687,9 @@ class Environment():
else: else:
arg = '--version' arg = '--version'
try: try:
p = subprocess.Popen([linker, arg], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p, out, err = Popen_safe([linker, arg])
except OSError: except OSError:
raise EnvironmentException('Could not execute static linker "%s".' % linker) raise EnvironmentException('Could not execute static linker "%s".' % linker)
(out, err) = p.communicate()
out = out.decode(errors='ignore')
err = err.decode(errors='ignore')
if '/OUT:' in out or '/OUT:' in err: if '/OUT:' in out or '/OUT:' in err:
return VisualStudioLinker([linker]) return VisualStudioLinker([linker])
if p.returncode == 0: if p.returncode == 0:

@ -22,6 +22,7 @@ from . import optinterpreter
from . import compilers from . import compilers
from .wrap import wrap from .wrap import wrap
from . import mesonlib from . import mesonlib
from .mesonlib import Popen_safe
from .dependencies import InternalDependency, Dependency from .dependencies import InternalDependency, Dependency
from .interpreterbase import InterpreterBase from .interpreterbase import InterpreterBase
from .interpreterbase import check_stringlist, noPosargs, noKwargs, stringArgs 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): def __init__(self, command_array, source_dir, build_dir, subdir, in_builddir=False):
super().__init__() super().__init__()
pc = self.run_command(command_array, source_dir, build_dir, subdir, in_builddir) pc, self.stdout, self.stderr = self.run_command(command_array, source_dir, build_dir, subdir, in_builddir)
(stdout, stderr) = pc.communicate()
self.returncode = pc.returncode 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, self.methods.update({'returncode' : self.returncode_method,
'stdout' : self.stdout_method, 'stdout' : self.stdout_method,
'stderr' : self.stderr_method, 'stderr' : self.stderr_method,
@ -99,22 +91,19 @@ class RunProcess(InterpreterObject):
child_env.update(env) child_env.update(env)
mlog.debug('Running command:', ' '.join(command_array)) mlog.debug('Running command:', ' '.join(command_array))
try: try:
return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE, return Popen_safe(command_array, env=child_env, cwd=cwd)
env=child_env, cwd=cwd)
except FileNotFoundError: except FileNotFoundError:
pass pass
# Was not a command, is a program in path? # Was not a command, is a program in path?
exe = shutil.which(cmd_name) exe = shutil.which(cmd_name)
if exe is not None: if exe is not None:
command_array = [exe] + command_array[1:] command_array = [exe] + command_array[1:]
return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE, return Popen_safe(command_array, env=child_env, cwd=cwd)
env=child_env, cwd=cwd)
# No? Maybe it is a script in the source tree. # No? Maybe it is a script in the source tree.
fullpath = os.path.join(source_dir, subdir, cmd_name) fullpath = os.path.join(source_dir, subdir, cmd_name)
command_array = [fullpath] + command_array[1:] command_array = [fullpath] + command_array[1:]
try: try:
return subprocess.Popen(command_array, stdout=subprocess.PIPE, stderr=subprocess.PIPE, return Popen_safe(command_array, env=child_env, cwd=cwd)
env=child_env, cwd=cwd)
except FileNotFoundError: except FileNotFoundError:
raise InterpreterException('Could not execute command "%s".' % cmd_name) raise InterpreterException('Could not execute command "%s".' % cmd_name)

@ -385,3 +385,10 @@ def expand_arguments(args):
print(e) print(e)
return None return None
return expended_args return expended_args
def Popen_safe(args, write=None, stderr=subprocess.PIPE, **kwargs):
p = subprocess.Popen(args, universal_newlines=True,
stdout=subprocess.PIPE,
stderr=stderr, **kwargs)
o, e = p.communicate(write)
return (p, o, e)

@ -20,7 +20,7 @@ import os
import sys import sys
import copy import copy
import subprocess import subprocess
from ..mesonlib import MesonException from ..mesonlib import MesonException, Popen_safe
from .. import dependencies from .. import dependencies
from .. import mlog from .. import mlog
from .. import mesonlib 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', os.path.join(state.subdir, source_dir)]
cmd += ['--sourcedir', state.subdir] # Current dir cmd += ['--sourcedir', state.subdir] # Current dir
pc = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True, pc, stdout = Popen_safe(cmd, cwd=state.environment.get_source_dir())[0:2]
cwd=state.environment.get_source_dir())
(stdout, _) = pc.communicate()
if pc.returncode != 0: if pc.returncode != 0:
mlog.warning('glib-compile-resources has failed to get the dependencies for {}'.format(cmd[1])) mlog.warning('glib-compile-resources has failed to get the dependencies for {}'.format(cmd[1]))
raise subprocess.CalledProcessError(pc.returncode, cmd) raise subprocess.CalledProcessError(pc.returncode, cmd)

@ -15,7 +15,7 @@
import os, subprocess import os, subprocess
from .. import mlog from .. import mlog
from .. import build from .. import build
from ..mesonlib import MesonException from ..mesonlib import MesonException, Popen_safe
from ..dependencies import Qt4Dependency from ..dependencies import Qt4Dependency
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -37,11 +37,9 @@ class Qt4Module():
# Moc and rcc return a non-zero result when doing so. # Moc and rcc return a non-zero result when doing so.
# What kind of an idiot thought that was a good idea? # What kind of an idiot thought that was a good idea?
if self.moc.found(): if self.moc.found():
mp = subprocess.Popen(self.moc.get_command() + ['-v'], stdout, stderr = Popen_safe(self.moc.get_command() + ['-v'])[1:3]
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = stdout.strip()
(stdout, stderr) = mp.communicate() stderr = stderr.strip()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'Qt Meta' in stderr: if 'Qt Meta' in stderr:
moc_ver = stderr moc_ver = stderr
else: else:
@ -52,11 +50,9 @@ class Qt4Module():
else: else:
mlog.log(' moc:', mlog.red('NO')) mlog.log(' moc:', mlog.red('NO'))
if self.uic.found(): if self.uic.found():
up = subprocess.Popen(self.uic.get_command() + ['-v'], stdout, stderr = Popen_safe(self.uic.get_command() + ['-v'])[1:3]
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = stdout.strip()
(stdout, stderr) = up.communicate() stderr = stderr.strip()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'version 4.' in stderr: if 'version 4.' in stderr:
uic_ver = stderr uic_ver = stderr
else: else:
@ -67,11 +63,9 @@ class Qt4Module():
else: else:
mlog.log(' uic:', mlog.red('NO')) mlog.log(' uic:', mlog.red('NO'))
if self.rcc.found(): if self.rcc.found():
rp = subprocess.Popen(self.rcc.get_command() + ['-v'], stdout, stderr = Popen_safe(self.rcc.get_command() + ['-v'])[1:3]
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = stdout.strip()
(stdout, stderr) = rp.communicate() stderr = stderr.strip()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'version 4.' in stderr: if 'version 4.' in stderr:
rcc_ver = stderr rcc_ver = stderr
else: else:

@ -15,7 +15,7 @@
import os, subprocess import os, subprocess
from .. import mlog from .. import mlog
from .. import build from .. import build
from ..mesonlib import MesonException from ..mesonlib import MesonException, Popen_safe
from ..dependencies import Qt5Dependency from ..dependencies import Qt5Dependency
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -37,11 +37,9 @@ class Qt5Module():
# Moc and rcc return a non-zero result when doing so. # Moc and rcc return a non-zero result when doing so.
# What kind of an idiot thought that was a good idea? # What kind of an idiot thought that was a good idea?
if self.moc.found(): if self.moc.found():
mp = subprocess.Popen(self.moc.get_command() + ['-v'], stdout, stderr = Popen_safe(self.moc.get_command() + ['-v'])[1:3]
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = stdout.strip()
(stdout, stderr) = mp.communicate() stderr = stderr.strip()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'Qt 5' in stderr: if 'Qt 5' in stderr:
moc_ver = stderr moc_ver = stderr
elif '5.' in stdout: elif '5.' in stdout:
@ -54,11 +52,9 @@ class Qt5Module():
else: else:
mlog.log(' moc:', mlog.red('NO')) mlog.log(' moc:', mlog.red('NO'))
if self.uic.found(): if self.uic.found():
up = subprocess.Popen(self.uic.get_command() + ['-v'], stdout, stderr = Popen_safe(self.uic.get_command() + ['-v'])[1:3]
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = stdout.strip()
(stdout, stderr) = up.communicate() stderr = stderr.strip()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'version 5.' in stderr: if 'version 5.' in stderr:
uic_ver = stderr uic_ver = stderr
elif '5.' in stdout: elif '5.' in stdout:
@ -71,11 +67,9 @@ class Qt5Module():
else: else:
mlog.log(' uic:', mlog.red('NO')) mlog.log(' uic:', mlog.red('NO'))
if self.rcc.found(): if self.rcc.found():
rp = subprocess.Popen(self.rcc.get_command() + ['-v'], stdout, stderr = Popen_safe(self.rcc.get_command() + ['-v'])[1:3]
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = stdout.strip()
(stdout, stderr) = rp.communicate() stderr = stderr.strip()
stdout = stdout.decode().strip()
stderr = stderr.decode().strip()
if 'version 5.' in stderr: if 'version 5.' in stderr:
rcc_ver = stderr rcc_ver = stderr
elif '5.' in stdout: elif '5.' in stdout:

@ -17,7 +17,7 @@ import sys, os
import subprocess import subprocess
import shutil import shutil
import argparse import argparse
from ..mesonlib import MesonException from ..mesonlib import MesonException, Popen_safe
from . import destdir_join from . import destdir_join
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -46,15 +46,13 @@ parser.add_argument('--mode', dest='mode', default='')
parser.add_argument('--installdir', dest='install_dir') parser.add_argument('--installdir', dest='install_dir')
def gtkdoc_run_check(cmd, cwd): def gtkdoc_run_check(cmd, cwd):
p = subprocess.Popen(cmd, cwd=cwd, # Put stderr into stdout since we want to print it out anyway.
stdout=subprocess.PIPE, stderr=subprocess.PIPE) # This preserves the order of messages.
(stde, stdo) = p.communicate() p, out = Popen_safe(cmd, cwd=cwd, stderr=subprocess.STDOUT)[0:2]
if p.returncode != 0: if p.returncode != 0:
err_msg = ["{!r} failed with status {:d}".format(cmd[0], p.returncode)] err_msg = ["{!r} failed with status {:d}".format(cmd[0], p.returncode)]
if stde: if out:
err_msg.append(stde.decode(errors='ignore')) err_msg.append(out)
if stdo:
err_msg.append(stdo.decode(errors='ignore'))
raise MesonException('\n'.join(err_msg)) raise MesonException('\n'.join(err_msg))
def build_gtkdoc(source_root, build_root, doc_subdir, src_subdirs, def build_gtkdoc(source_root, build_root, doc_subdir, src_subdirs,

@ -21,7 +21,7 @@ import pickle
import platform import platform
import subprocess import subprocess
import mesonbuild from ..mesonlib import MesonException, Popen_safe
options = None options = None
@ -45,7 +45,7 @@ def run_exe(exe):
else: else:
if exe.is_cross: if exe.is_cross:
if exe.exe_runner is None: 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: else:
cmd = [exe.exe_runner] + exe.fname cmd = [exe.exe_runner] + exe.fname
else: else:
@ -55,17 +55,12 @@ def run_exe(exe):
if len(exe.extra_paths) > 0: if len(exe.extra_paths) > 0:
child_env['PATH'] = (os.pathsep.join(exe.extra_paths + ['']) + child_env['PATH'] = (os.pathsep.join(exe.extra_paths + ['']) +
child_env['PATH']) child_env['PATH'])
p = subprocess.Popen(cmd + exe.cmd_args, p, stdout, stderr = Popen_safe(cmd + exe.cmd_args, env=child_env, cwd=exe.workdir)
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=child_env,
cwd=exe.workdir)
stdout, stderr = p.communicate()
if exe.capture and p.returncode == 0: if exe.capture and p.returncode == 0:
with open(exe.capture, 'wb') as output: with open(exe.capture, 'w') as output:
output.write(stdout) output.write(stdout)
if stderr: if stderr:
sys.stderr.buffer.write(stderr) sys.stderr.write(stderr)
return p.returncode return p.returncode
def run(args): def run(args):

@ -18,6 +18,7 @@ import sys, pickle, os, shutil, subprocess, gzip, platform
from glob import glob from glob import glob
from . import depfixer from . import depfixer
from . import destdir_join from . import destdir_join
from ..mesonlib import MesonException, Popen_safe
install_log_file = None install_log_file = None
@ -205,12 +206,11 @@ def install_targets(d):
do_copy(fname, outname) do_copy(fname, outname)
if should_strip: if should_strip:
print('Stripping target') print('Stripping target')
ps = subprocess.Popen(['strip', outname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) ps, stdo, stde = Popen_safe(['strip', outname])
(stdo, stde) = ps.communicate()
if ps.returncode != 0: if ps.returncode != 0:
print('Could not strip file.\n') print('Could not strip file.\n')
print('Stdout:\n%s\n' % stdo.decode()) print('Stdout:\n%s\n' % stdo)
print('Stderr:\n%s\n' % stde.decode()) print('Stderr:\n%s\n' % stde)
sys.exit(1) sys.exit(1)
printed_symlink_error = False printed_symlink_error = False
for alias in aliases: for alias in aliases:

@ -23,7 +23,8 @@
# http://cgit.freedesktop.org/libreoffice/core/commit/?id=3213cd54b76bc80a6f0516aac75a48ff3b2ad67c # http://cgit.freedesktop.org/libreoffice/core/commit/?id=3213cd54b76bc80a6f0516aac75a48ff3b2ad67c
import os, sys, subprocess import os, sys, subprocess
from mesonbuild import mesonlib from .. import mesonlib
from ..mesonlib import MesonException, Popen_safe
import argparse import argparse
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
@ -59,23 +60,21 @@ def linux_syms(libfilename, outfilename):
nmbin = os.environ[evar].strip() nmbin = os.environ[evar].strip()
else: else:
nmbin = 'nm' nmbin = 'nm'
pe = subprocess.Popen([readelfbin, '-d', libfilename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) pe, output = Popen_safe([readelfbin, '-d', libfilename])[0:2]
output = pe.communicate()[0].decode()
if pe.returncode != 0: if pe.returncode != 0:
raise RuntimeError('Readelf does not work') raise RuntimeError('Readelf does not work')
result = [x for x in output.split('\n') if 'SONAME' in x] result = [x for x in output.split('\n') if 'SONAME' in x]
assert(len(result) <= 1) assert(len(result) <= 1)
pnm = subprocess.Popen([nmbin, '--dynamic', '--extern-only', '--defined-only', '--format=posix', libfilename], pnm, output = Popen_safe([nmbin, '--dynamic', '--extern-only',
stdout=subprocess.PIPE, stderr=subprocess.PIPE) '--defined-only', '--format=posix',
output = pnm.communicate()[0].decode() libfilename])[0:2]
if pnm.returncode != 0: if pnm.returncode != 0:
raise RuntimeError('nm does not work.') raise RuntimeError('nm does not work.')
result += [' '.join(x.split()[0:2]) for x in output.split('\n') if len(x) > 0] result += [' '.join(x.split()[0:2]) for x in output.split('\n') if len(x) > 0]
write_if_changed('\n'.join(result) + '\n', outfilename) write_if_changed('\n'.join(result) + '\n', outfilename)
def osx_syms(libfilename, outfilename): def osx_syms(libfilename, outfilename):
pe = subprocess.Popen(['otool', '-l', libfilename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) pe, output = Popen_safe(['otool', '-l', libfilename])[0:2]
output = pe.communicate()[0].decode()
if pe.returncode != 0: if pe.returncode != 0:
raise RuntimeError('Otool does not work.') raise RuntimeError('Otool does not work.')
arr = output.split('\n') arr = output.split('\n')
@ -84,8 +83,7 @@ def osx_syms(libfilename, outfilename):
match = i match = i
break break
result = [arr[match+2], arr[match+5]] # Libreoffice stores all 5 lines but the others seem irrelevant. result = [arr[match+2], arr[match+5]] # Libreoffice stores all 5 lines but the others seem irrelevant.
pnm = subprocess.Popen(['nm', '-g', '-P', libfilename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) pnm, output = Popen_safe(['nm', '-g', '-P', libfilename])[0:2]
output = pnm.communicate()[0].decode()
if pnm.returncode != 0: if pnm.returncode != 0:
raise RuntimeError('nm does not work.') raise RuntimeError('nm does not work.')
result += [' '.join(x.split()[0:2]) for x in output.split('\n') if len(x) > 0 and not x.endswith('U')] result += [' '.join(x.split()[0:2]) for x in output.split('\n') if len(x) > 0 and not x.endswith('U')]

Loading…
Cancel
Save