Merge pull request #2187 from centricular/fix-pcap-dependency

Fix pcap dependency, str.strip() now takes an argument, add cc.get_return_value()
pull/2367/head
Jussi Pakkanen 8 years ago committed by GitHub
commit bea6b1a6f6
  1. 4
      docs/markdown/Reference-manual.md
  2. 28
      mesonbuild/compilers/c.py
  3. 19
      mesonbuild/dependencies/misc.py
  4. 2
      mesonbuild/interpreter.py
  5. 27
      mesonbuild/interpreterbase.py
  6. 2
      run_project_tests.py
  7. 7
      test cases/common/42 string operations/meson.build
  8. 3
      test cases/frameworks/19 pcap/meson.build

@ -1440,7 +1440,9 @@ are immutable, all operations return their results as a new string.
- `startswith(string)` returns true if string starts with the string
specified as the argument
- `strip()` removes whitespace at the beginning and end of the string
- `strip()` removes whitespace at the beginning and end of the string
*(added 0.43.0)* optionally can take one positional string argument,
and all characters in that string will be stripped
- `to_int` returns the string converted to an integer (error if string
is not a number)

@ -482,6 +482,34 @@ class CCompiler(Compiler):
# minus the extra newline at the end
return p.stdo.split(delim + '\n')[-1][:-1]
def get_return_value(self, fname, rtype, prefix, env, extra_args, dependencies):
if rtype == 'string':
fmt = '%s'
cast = '(char*)'
elif rtype == 'int':
fmt = '%lli'
cast = '(long long int)'
else:
raise AssertionError('BUG: Unknown return type {!r}'.format(rtype))
fargs = {'prefix': prefix, 'f': fname, 'cast': cast, 'fmt': fmt}
code = '''{prefix}
#include <stdio.h>
int main(int argc, char *argv[]) {{
printf ("{fmt}", {cast} {f}());
}}'''.format(**fargs)
res = self.run(code, env, extra_args, dependencies)
if not res.compiled:
m = 'Could not get return value of {}()'
raise EnvironmentException(m.format(fname))
if rtype == 'string':
return res.stdout
elif rtype == 'int':
try:
return int(res.stdout.strip())
except:
m = 'Return value of {}() is not an int'
raise EnvironmentException(m.format(fname))
@staticmethod
def _no_prototype_templ():
"""

@ -575,6 +575,7 @@ class Python3Dependency(ExternalDependency):
else:
return [DependencyMethods.PKGCONFIG]
class PcapDependency(ExternalDependency):
def __init__(self, environment, kwargs):
super().__init__('pcap', environment, None, kwargs)
@ -598,23 +599,12 @@ class PcapDependency(ExternalDependency):
self.compile_args = stdo.strip().split()
stdo = Popen_safe(['pcap-config', '--libs'])[1]
self.link_args = stdo.strip().split()
self.version = '0'
self.version = self.get_pcap_lib_version()
self.is_found = True
mlog.log('Dependency', mlog.bold('pcap'), 'found:',
mlog.green('YES'), '(%s)' % pcapconf)
return
mlog.debug('Could not find pcap-config binary, trying next.')
if DependencyMethods.EXTRAFRAMEWORK in self.methods:
if mesonlib.is_osx():
fwdep = ExtraFrameworkDependency('pcap', False, None, self.env,
self.language, kwargs)
if fwdep.found():
self.is_found = True
self.compile_args = fwdep.get_compile_args()
self.link_args = fwdep.get_link_args()
self.version = '2' # FIXME
return
mlog.log('Dependency', mlog.bold('pcap'), 'found:', mlog.red('NO'))
def get_methods(self):
if mesonlib.is_osx():
@ -622,6 +612,11 @@ class PcapDependency(ExternalDependency):
else:
return [DependencyMethods.PKGCONFIG, DependencyMethods.PCAPCONFIG]
def get_pcap_lib_version(self):
return self.compiler.get_return_value('pcap_lib_version', 'string',
'#include <pcap.h>', self.env, [], [self])
class CupsDependency(ExternalDependency):
def __init__(self, environment, kwargs):
super().__init__('cups', environment, None, kwargs)

@ -881,7 +881,7 @@ class CompilerHolder(InterpreterObject):
extra_args = self.determine_args(kwargs)
deps = self.determine_dependencies(kwargs)
value = self.compiler.get_define(element, prefix, self.environment, extra_args, deps)
mlog.log('Checking for value of define "%s": %s' % (element, value))
mlog.log('Fetching value of define "%s": %s' % (element, value))
return value
def compiles_method(self, args, kwargs):

@ -450,9 +450,25 @@ class InterpreterBase:
else:
raise InterpreterException('Unknown method "%s" for an integer.' % method_name)
@staticmethod
def _get_one_string_posarg(posargs, method_name):
if len(posargs) > 1:
m = '{}() must have zero or one arguments'
raise InterpreterException(m.format(method_name))
elif len(posargs) == 1:
s = posargs[0]
if not isinstance(s, str):
m = '{}() argument must be a string'
raise InterpreterException(m.format(method_name))
return s
return None
def string_method_call(self, obj, method_name, args):
(posargs, _) = self.reduce_arguments(args)
if method_name == 'strip':
s = self._get_one_string_posarg(posargs, 'strip')
if s is not None:
return obj.strip(s)
return obj.strip()
elif method_name == 'format':
return self.format_string(obj, args)
@ -463,15 +479,10 @@ class InterpreterBase:
elif method_name == 'underscorify':
return re.sub(r'[^a-zA-Z0-9]', '_', obj)
elif method_name == 'split':
if len(posargs) > 1:
raise InterpreterException('Split() must have at most one argument.')
elif len(posargs) == 1:
s = posargs[0]
if not isinstance(s, str):
raise InterpreterException('Split() argument must be a string')
s = self._get_one_string_posarg(posargs, 'split')
if s is not None:
return obj.split(s)
else:
return obj.split()
return obj.split()
elif method_name == 'startswith' or method_name == 'contains' or method_name == 'endswith':
s = posargs[0]
if not isinstance(s, str):

@ -585,7 +585,7 @@ def check_file(fname):
with open(fname, 'rb') as f:
lines = f.readlines()
for line in lines:
if b'\t' in line:
if line.startswith(b'\t'):
print("File %s contains a literal tab on line %d. Only spaces are permitted." % (fname, linenum))
sys.exit(1)
if b'\r' in line:

@ -67,3 +67,10 @@ assert(not version_number.version_compare('!=1.2.8'), 'Version_compare neq broke
assert(version_number.version_compare('<2.0'), 'Version_compare major less broken')
assert(version_number.version_compare('>0.9'), 'Version_compare major greater broken')
assert(' spaces tabs '.strip() == 'spaces tabs', 'Spaces and tabs badly stripped')
assert('''
multiline string '''.strip() == '''multiline string''', 'Newlines badly stripped')
assert('"1.1.20"'.strip('"') == '1.1.20', '" badly stripped')
assert('"1.1.20"'.strip('".') == '1.1.20', '". badly stripped')
assert('"1.1.20" '.strip('" ') == '1.1.20', '". badly stripped')

@ -2,6 +2,9 @@ project('pcap test', 'c')
pcap_dep = dependency('pcap', version : '>=1.0')
pcap_ver = pcap_dep.version()
assert(pcap_ver.split('.').length() > 1, 'pcap version is "@0@"'.format(pcap_ver))
e = executable('pcap_prog', 'pcap_prog.c', dependencies : pcap_dep)
test('pcaptest', e)

Loading…
Cancel
Save