Modernize Python3Dependency

Somehow I overlooked this class when adjusting everything else in c59ec874
et seq.

Update Python3Dependency so it has a _factory() method which returns a list
of constructors, depending on the method: kwarg, which integrates better
with the reporting in find_external_dependency()

This ensures the return of a PkgConfigDependency object, if the dependency
is found with pkgconfig, so we don't have to specifically implement
get_pkgconfig_variable() ourselves.
pull/4125/merge
Jon Turney 7 years ago committed by Nirbheek Chauhan
parent 07d2d88fa9
commit c54cd69015
  1. 57
      mesonbuild/dependencies/misc.py

@ -283,34 +283,29 @@ class Python3Dependency(ExternalDependency):
# We can only be sure that it is Python 3 at this point
self.version = '3'
self.pkgdep = None
if DependencyMethods.PKGCONFIG in self.methods:
try:
self.pkgdep = PkgConfigDependency('python3', environment, kwargs)
if self.pkgdep.found():
self.compile_args = self.pkgdep.get_compile_args()
self.link_args = self.pkgdep.get_link_args()
self.version = self.pkgdep.get_version()
self.is_found = True
self.pcdep = self.pkgdep
return
else:
self.pkgdep = None
except Exception:
pass
if not self.is_found:
if mesonlib.is_windows() and DependencyMethods.SYSCONFIG in self.methods:
self._find_libpy3_windows(environment)
elif mesonlib.is_osx() and DependencyMethods.EXTRAFRAMEWORK in self.methods:
# In OSX the Python 3 framework does not have a version
# number in its name.
# There is a python in /System/Library/Frameworks, but that's
# python 2, Python 3 will always bin in /Library
fw = ExtraFrameworkDependency(
'python', False, '/Library/Frameworks', self.env, self.language, kwargs)
if fw.found():
self.compile_args = fw.get_compile_args()
self.link_args = fw.get_link_args()
self.is_found = True
self._find_libpy3_windows(environment)
@classmethod
def _factory(cls, environment, kwargs):
methods = cls._process_method_kw(kwargs)
candidates = []
if DependencyMethods.PKGCONFIG in methods:
candidates.append(functools.partial(PkgConfigDependency, 'python3', environment, kwargs))
if DependencyMethods.SYSCONFIG in methods:
candidates.append(functools.partial(Python3Dependency, environment, kwargs))
if DependencyMethods.EXTRAFRAMEWORK in methods:
# In OSX the Python 3 framework does not have a version
# number in its name.
# There is a python in /System/Library/Frameworks, but that's
# python 2, Python 3 will always be in /Library
candidates.append(functools.partial(
ExtraFrameworkDependency, 'python', False, '/Library/Frameworks',
environment, kwargs.get('language', None), kwargs))
return candidates
@staticmethod
def get_windows_python_arch():
@ -402,12 +397,6 @@ class Python3Dependency(ExternalDependency):
else:
return [DependencyMethods.PKGCONFIG]
def get_pkgconfig_variable(self, variable_name, kwargs):
if self.pkgdep:
return self.pkgdep.get_pkgconfig_variable(variable_name, kwargs)
else:
return super().get_pkgconfig_variable(variable_name, kwargs)
class PcapDependency(ExternalDependency):

Loading…
Cancel
Save