Compare commits

...

3 Commits

Author SHA1 Message Date
Marvin Scholz 2fe75ab31d dependencies/pkgconfig: Log pkg-config exceptions 5 years ago
Marvin Scholz 273d6e75ea dependencies/pkgconfig: Fix error reporting 5 years ago
Marvin Scholz fc86339b39 dependencies/pkgconfig: Fix found state ignoring errors 5 years ago
  1. 44
      mesonbuild/dependencies/base.py
  2. 8
      run_unittests.py

@ -645,16 +645,19 @@ class PkgConfigDependency(ExternalDependency):
mlog.debug('Determining dependency {!r} with pkg-config executable ' mlog.debug('Determining dependency {!r} with pkg-config executable '
'{!r}'.format(name, self.pkgbin.get_path())) '{!r}'.format(name, self.pkgbin.get_path()))
ret, self.version = self._call_pkgbin(['--modversion', name]) ret, self.version, _ = self._call_pkgbin(['--modversion', name])
if ret != 0: if ret != 0:
return return
self.is_found = True
try: try:
# Fetch cargs to be used while using this dependency # Fetch cargs to be used while using this dependency
self._set_cargs() self._set_cargs()
# Fetch the libraries and library paths needed for using this # Fetch the libraries and library paths needed for using this
self._set_libs() self._set_libs()
except DependencyException as e: except DependencyException as e:
mlog.debug("pkg-config error with '%s': %s" % (name, e))
if self.required: if self.required:
raise raise
else: else:
@ -663,8 +666,6 @@ class PkgConfigDependency(ExternalDependency):
self.is_found = False self.is_found = False
self.reason = e self.reason = e
self.is_found = True
def __repr__(self): def __repr__(self):
s = '<{0} {1}: {2} {3}>' s = '<{0} {1}: {2} {3}>'
return s.format(self.__class__.__name__, self.name, self.is_found, return s.format(self.__class__.__name__, self.name, self.is_found,
@ -672,11 +673,11 @@ class PkgConfigDependency(ExternalDependency):
def _call_pkgbin_real(self, args, env): def _call_pkgbin_real(self, args, env):
cmd = self.pkgbin.get_command() + args cmd = self.pkgbin.get_command() + args
p, out = Popen_safe(cmd, env=env)[0:2] p, out, err = Popen_safe(cmd, env=env)
rc, out = p.returncode, out.strip() rc, out, err = p.returncode, out.strip(), err.strip()
call = ' '.join(cmd) call = ' '.join(cmd)
mlog.debug("Called `{}` -> {}\n{}".format(call, rc, out)) mlog.debug("Called `{}` -> {}\n{}".format(call, rc, out))
return rc, out return rc, out, err
def _call_pkgbin(self, args, env=None): def _call_pkgbin(self, args, env=None):
# Always copy the environment since we're going to modify it # Always copy the environment since we're going to modify it
@ -741,10 +742,10 @@ class PkgConfigDependency(ExternalDependency):
# so don't allow pkg-config to suppress -I flags for system paths # so don't allow pkg-config to suppress -I flags for system paths
env = os.environ.copy() env = os.environ.copy()
env['PKG_CONFIG_ALLOW_SYSTEM_CFLAGS'] = '1' env['PKG_CONFIG_ALLOW_SYSTEM_CFLAGS'] = '1'
ret, out = self._call_pkgbin(['--cflags', self.name], env=env) ret, out, err = self._call_pkgbin(['--cflags', self.name], env=env)
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%s\n' %
(self.name, out)) (self.name, err))
self.compile_args = self._convert_mingw_paths(self._split_args(out)) self.compile_args = self._convert_mingw_paths(self._split_args(out))
def _search_libs(self, out, out_raw, out_all): def _search_libs(self, out, out_raw, out_all):
@ -910,20 +911,21 @@ class PkgConfigDependency(ExternalDependency):
# paths so we can do manual searching with cc.find_library() later. # paths so we can do manual searching with cc.find_library() later.
env = os.environ.copy() env = os.environ.copy()
env['PKG_CONFIG_ALLOW_SYSTEM_LIBS'] = '1' env['PKG_CONFIG_ALLOW_SYSTEM_LIBS'] = '1'
ret, out = self._call_pkgbin(libcmd, env=env) ret, out, err = self._call_pkgbin(libcmd, env=env)
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%s\n' %
(self.name, out)) (self.name, err))
# Also get the 'raw' output without -Lfoo system paths for adding -L # Also get the 'raw' output without -Lfoo system paths for adding -L
# args with -lfoo when a library can't be found, and also in # args with -lfoo when a library can't be found, and also in
# gnome.generate_gir + gnome.gtkdoc which need -L -l arguments. # gnome.generate_gir + gnome.gtkdoc which need -L -l arguments.
ret, out_raw = self._call_pkgbin(libcmd) ret, out_raw, err_raw = 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%s\n' %
(self.name, out_raw)) (self.name, err_raw))
ret, out_all = self._call_pkgbin(libcmd_all) ret, out_all, err_all = self._call_pkgbin(libcmd_all)
if ret != 0: if ret != 0:
mlog.warning('Could not determine complete list of dependencies for %s' % self.name) mlog.warning('Could not determine complete list of dependencies for %s:\n%s\n' %
(self.name, err_all))
self.link_args, self.raw_link_args = self._search_libs(out, out_raw, out_all) self.link_args, self.raw_link_args = self._search_libs(out, out_raw, out_all)
def get_pkgconfig_variable(self, variable_name, kwargs): def get_pkgconfig_variable(self, variable_name, kwargs):
@ -939,19 +941,19 @@ class PkgConfigDependency(ExternalDependency):
options = ['--define-variable=' + '='.join(definition)] + options options = ['--define-variable=' + '='.join(definition)] + options
ret, out = self._call_pkgbin(options) ret, out, err = self._call_pkgbin(options)
variable = '' variable = ''
if ret != 0: if ret != 0:
if self.required: if self.required:
raise DependencyException('dependency %s not found.' % raise DependencyException('dependency %s not found:\n%s\n' %
(self.name)) (self.name, err))
else: else:
variable = out.strip() variable = out.strip()
# pkg-config doesn't distinguish between empty and non-existent variables # pkg-config doesn't distinguish between empty and non-existent variables
# use the variable list to check for variable existence # use the variable list to check for variable existence
if not variable: if not variable:
ret, out = self._call_pkgbin(['--print-variables', self.name]) ret, out, _ = self._call_pkgbin(['--print-variables', self.name])
if not re.search(r'^' + variable_name + r'$', out, re.MULTILINE): if not re.search(r'^' + variable_name + r'$', out, re.MULTILINE):
if 'default' in kwargs: if 'default' in kwargs:
variable = kwargs['default'] variable = kwargs['default']

@ -860,13 +860,13 @@ class InternalTests(unittest.TestCase):
def fake_call_pkgbin(self, args, env=None): def fake_call_pkgbin(self, args, env=None):
if '--libs' not in args: if '--libs' not in args:
return 0, '' return 0, '', ''
if args[0] == 'foo': if args[0] == 'foo':
return 0, '-L{} -lfoo -L{} -lbar'.format(p2.as_posix(), p1.as_posix()) return 0, '-L{} -lfoo -L{} -lbar'.format(p2.as_posix(), p1.as_posix()), ''
if args[0] == 'bar': if args[0] == 'bar':
return 0, '-L{} -lbar'.format(p2.as_posix()) return 0, '-L{} -lbar'.format(p2.as_posix()), ''
if args[0] == 'internal': if args[0] == 'internal':
return 0, '-L{} -lpthread -lm -lc -lrt -ldl'.format(p1.as_posix()) return 0, '-L{} -lpthread -lm -lc -lrt -ldl'.format(p1.as_posix()), ''
old_call = PkgConfigDependency._call_pkgbin old_call = PkgConfigDependency._call_pkgbin
old_check = PkgConfigDependency.check_pkgconfig old_check = PkgConfigDependency.check_pkgconfig

Loading…
Cancel
Save