diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-18 13:41:56 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2016-12-18 13:41:56 +0530 |
commit | ade1f695a6105f2e39299e707b5f2e1120e37f0d (patch) | |
tree | fba5a8f27c5838a1d749dc8b85d1381619015159 | |
parent | ef2c2eeed1f30a4eace485a6a5e401bb60d6fcd9 (diff) | |
download | meson-ade1f695a6105f2e39299e707b5f2e1120e37f0d.zip meson-ade1f695a6105f2e39299e707b5f2e1120e37f0d.tar.gz meson-ade1f695a6105f2e39299e707b5f2e1120e37f0d.tar.bz2 |
Fix detection of pkg-config on all platforms
a) Don't search for pkg-config if we're only cross-compiling
b) Don't unconditionally error out while cross-compiling if the
specified pkg-config is not found and the dependency is optional
c) Use the pkg-config binary that was found in check_pkgconfig for the
actual testing
d) Use shutil.which on the found pkg-config only if it finds it.
Sometimes shutil.which fails to find it, for instance on Windows
with absolute paths.
-rw-r--r-- | mesonbuild/dependencies.py | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py index 9ef1649..20556e2 100644 --- a/mesonbuild/dependencies.py +++ b/mesonbuild/dependencies.py @@ -92,7 +92,7 @@ class InternalDependency(Dependency): return self.version class PkgConfigDependency(Dependency): - pkgconfig_found = None + pkgbin = None def __init__(self, name, environment, kwargs): Dependency.__init__(self, 'pkgconfig') @@ -109,36 +109,40 @@ class PkgConfigDependency(Dependency): else: want_cross = environment.is_cross_build() self.name = name - if PkgConfigDependency.pkgconfig_found is None: - self.check_pkgconfig() + + # When finding dependencies for cross-compiling, we don't care about + # the 'native' pkg-config + if want_cross: + if 'pkgconfig' not in env.cross_info.config['binaries']: + if self.required: + raise DependencyException('Pkg-config binary missing from cross file') + else: + pkgbin = environment.cross_info.config['binaries']['pkgconfig'] + # Only search for the native pkg-config the first time and + # store the result in the class definition + elif PkgConfigDependency.pkgbin is None: + PkgConfigDependency.pkgbin = self.check_pkgconfig() self.is_found = False - if not PkgConfigDependency.pkgconfig_found: + if not self.pkgbin: if self.required: raise DependencyException('Pkg-config not found.') return - if environment.is_cross_build() and want_cross: - if "pkgconfig" not in environment.cross_info.config["binaries"]: - raise DependencyException('Pkg-config binary missing from cross file.') - pkgbin = environment.cross_info.config["binaries"]['pkgconfig'] + if want_cross: self.type_string = 'Cross' else: - evar = 'PKG_CONFIG' - if evar in os.environ: - pkgbin = os.environ[evar].strip() - else: - pkgbin = 'pkg-config' self.type_string = 'Native' - mlog.debug('Determining dependency %s with pkg-config executable %s.' % (name, pkgbin)) - self.pkgbin = pkgbin + mlog.debug('Determining dependency {!r} with pkg-config executable ' + '{!r}'.format(name, self.pkgbin)) ret, self.modversion = self._call_pkgbin(['--modversion', name]) if ret != 0: if self.required: - raise DependencyException('%s dependency %s not found.' % (self.type_string, name)) + raise DependencyException('{} dependency {!r} not found' + ''.format(self.type_string, name)) self.modversion = 'none' return - found_msg = ['%s dependency' % self.type_string, mlog.bold(name), 'found:'] + found_msg = [self.type_string + ' dependency', mlog.bold(name), 'found:'] self.version_reqs = kwargs.get('version', None) if self.version_reqs is None: self.is_found = True @@ -236,24 +240,30 @@ class PkgConfigDependency(Dependency): return self.libs def check_pkgconfig(self): + evar = 'PKG_CONFIG' + if evar in os.environ: + pkgbin = os.environ[evar].strip() + else: + pkgbin = 'pkg-config' try: - evar = 'PKG_CONFIG' - if evar in os.environ: - pkgbin = os.environ[evar].strip() - else: - pkgbin = 'pkg-config' p, out = Popen_safe([pkgbin, '--version'])[0:2] - if p.returncode == 0: - if not self.silent: - mlog.log('Found pkg-config:', mlog.bold(shutil.which(pkgbin)), - '(%s)' % out.strip()) - PkgConfigDependency.pkgconfig_found = True - return + if p.returncode != 0: + # Set to False instead of None to signify that we've already + # searched for it and not found it + pkgbin = False except (FileNotFoundError, PermissionError): - pass - PkgConfigDependency.pkgconfig_found = False + pkgbin = False + if pkgbin and not os.path.isabs(pkgbin) and shutil.which(pkgbin): + # Sometimes shutil.which fails where Popen succeeds, so + # only find the abs path if it can be found by shutil.which + pkgbin = shutil.which(pkgbin) if not self.silent: - mlog.log('Found Pkg-config:', mlog.red('NO')) + if pkgbin: + mlog.log('Found pkg-config:', mlog.bold(pkgbin), + '(%s)' % out.strip()) + else: + mlog.log('Found Pkg-config:', mlog.red('NO')) + return pkgbin def found(self): return self.is_found |