2
0
mirror of https://gitlab.com/ita1024/waf.git synced 2024-11-16 23:19:50 +01:00

make check_swig_version similar to check_python_version

This commit is contained in:
Daniel Bartel 2016-06-20 21:38:46 +02:00
parent bf05bac08a
commit 2241db8557

View File

@ -161,16 +161,51 @@ def i_file(self, node):
tsk.outdir = outdir
@conf
def check_swig_version(self):
"""Returns a tuple representing the swig version, like (1,3,28)"""
reg_swig = re.compile(r'SWIG Version\s(.*)', re.M)
swig_out = self.cmd_and_log(self.env.SWIG + ['-version'])
def check_swig_version(conf, minver=None):
"""
Check if the swig tool is found matching a given minimum version.
minver should be a tuple, eg. to check for swig >= 1.3.28 pass (1,3,28) as minver.
swigver = tuple([int(s) for s in reg_swig.findall(swig_out)[0].split('.')])
self.env['SWIG_VERSION'] = swigver
msg = 'Checking for swig version'
self.msg(msg, '.'.join(map(str, swigver)))
return swigver
If successful, SWIG_VERSION is defined as 'MAJOR.MINOR'
(eg. '1.3') of the actual swig version found.
:param minver: minimum version
:type minver: tuple of int
:return: swig version
:rtype: tuple of int
"""
assert minver is None or isinstance(minver, tuple)
swigbin = conf.env['SWIG']
if not swigbin:
conf.fatal('could not find the swig executable')
# Get swig version string
cmd = swigbin + ['-version']
Logs.debug('swig: Running swig command %r', cmd)
reg_swig = re.compile(r'SWIG Version\s(.*)', re.M)
swig_out = conf.cmd_and_log(cmd)
swigver_tuple = tuple([int(s) for s in reg_swig.findall(swig_out)[0].split('.')])
# Compare swig version with the minimum required
result = (minver is None) or (swigver_tuple >= minver)
if result:
# Define useful environment variables
swigver = '.'.join([str(x) for x in swigver_tuple[:2]])
conf.env['SWIG_VERSION'] = swigver
# Feedback
swigver_full = '.'.join(map(str, swigver_tuple[:3]))
if minver is None:
conf.msg('Checking for swig version', swigver_full)
else:
minver_str = '.'.join(map(str, minver))
conf.msg('Checking for swig version', swigver_full, ">= %s" % (minver_str,) and 'GREEN' or 'YELLOW')
if not result:
conf.fatal('The swig version is too old, expecting %r' % (minver,))
return swigver_tuple
def configure(conf):
conf.find_program('swig', var='SWIG')