Can specify version requirements to dependencies.

pull/34/head
Jussi Pakkanen 10 years ago
parent 526c86d92f
commit cd757db899
  1. 21
      dependencies.py
  2. 30
      mesonlib.py
  3. 2
      test cases/linuxlike/1 pkg-config/meson.build

@ -72,7 +72,8 @@ class Dependency():
class PkgConfigDependency(Dependency):
pkgconfig_found = None
def __init__(self, name, required):
def __init__(self, name, kwargs):
required = kwargs.get('required', True)
Dependency.__init__(self)
self.name = name
if PkgConfigDependency.pkgconfig_found is None:
@ -92,9 +93,19 @@ class PkgConfigDependency(Dependency):
self.cargs = []
self.libs = []
else:
mlog.log('Dependency', mlog.bold(name), 'found:', mlog.green('YES'))
self.is_found = True
self.modversion = out.decode().strip()
mlog.log('Dependency', mlog.bold(name), 'found:', mlog.green('YES'), self.modversion)
version_requirement = kwargs.get('version', None)
if version_requirement is None:
self.is_found = True
else:
if not isinstance(version_requirement, str):
raise DependencyException('Version argument must be string.')
self.is_found = mesonlib.version_compare(self.modversion, version_requirement)
if not self.is_found and required:
raise DependencyException('Invalid version of a dependency, needed %s %s found %s.' % (name, version_requirement, self.modversion))
if not self.is_found:
return
p = subprocess.Popen(['pkg-config', '--cflags', name], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out = p.communicate()[0]
@ -521,7 +532,7 @@ class Qt5Dependency(Dependency):
if isinstance(mods, str):
mods = [mods]
for module in mods:
self.modules.append(PkgConfigDependency('Qt5' + module, False))
self.modules.append(PkgConfigDependency('Qt5' + module, kwargs))
if len(self.modules) == 0:
raise DependencyException('No Qt5 modules specified.')
if not qt5toolinfo_printed:
@ -795,7 +806,7 @@ def find_external_dependency(name, kwargs):
pkg_exc = None
pkgdep = None
try:
pkgdep = PkgConfigDependency(name, required)
pkgdep = PkgConfigDependency(name, kwargs)
if pkgdep.found():
return pkgdep
except Exception as e:

@ -14,7 +14,7 @@
"""A library of random helper functionality."""
import platform, subprocess
import platform, subprocess, operator
def is_osx():
return platform.system().lower() == 'darwin'
@ -41,3 +41,31 @@ def exe_exists(arglist):
except FileNotFoundError:
pass
return False
def version_compare(vstr1, vstr2):
if vstr2.startswith('>='):
cmpop = operator.ge
vstr2 = vstr2[2:]
elif vstr2.startswith('<='):
cmpop = operator.le
vstr2 = vstr2[2:]
elif vstr2.startswith('!='):
cmpop = operator.ne
vstr2 = vstr2[2:]
elif vstr2.startswith('=='):
cmpop = operator.eq
vstr2 = vstr2[2:]
elif vstr2.startswith('='):
cmpop = operator.eq
vstr2 = vstr2[1:]
elif vstr2.startswith('>'):
cmpop = operator.gt
vstr2 = vstr2[1:]
elif vstr2.startswith('<'):
cmpop = operator.lt
vstr2 = vstr2[1:]
else:
cmpop = operator.eq
varr1 = [int(x) for x in vstr1.split('.')]
varr2 = [int(x) for x in vstr2.split('.')]
return cmpop(varr1, varr2)

@ -2,7 +2,7 @@ project('external dependency', 'c')
# Zlib is probably on all dev machines.
dep = dependency('zlib')
dep = dependency('zlib', version : '>=1.2.8')
exe = executable('zlibprog', 'prog.c', dependencies : dep)
test('zlibtest', exe)

Loading…
Cancel
Save