pkgconfig generator: Add required version

pull/3319/head
Xavier Claessens 7 years ago committed by Jussi Pakkanen
parent f6f0784038
commit 8efd940092
  1. 56
      mesonbuild/modules/pkgconfig.py
  2. 14
      run_unittests.py
  3. 2
      test cases/common/51 pkgconfig-gen/dependencies/meson.build

@ -31,6 +31,7 @@ class DependenciesHelper:
self.priv_libs = [] self.priv_libs = []
self.priv_reqs = [] self.priv_reqs = []
self.cflags = [] self.cflags = []
self.version_reqs = {}
def add_pub_libs(self, libs): def add_pub_libs(self, libs):
libs, reqs, cflags = self._process_libs(libs, True) libs, reqs, cflags = self._process_libs(libs, True)
@ -57,12 +58,17 @@ class DependenciesHelper:
processed_reqs.append(obj.generated_pc) processed_reqs.append(obj.generated_pc)
elif hasattr(obj, 'pcdep'): elif hasattr(obj, 'pcdep'):
pcdeps = mesonlib.listify(obj.pcdep) pcdeps = mesonlib.listify(obj.pcdep)
processed_reqs += [i.name for i in pcdeps] for d in pcdeps:
processed_reqs += d.name
self.add_version_reqs(d.name, obj.version_reqs)
elif isinstance(obj, dependencies.PkgConfigDependency): elif isinstance(obj, dependencies.PkgConfigDependency):
if obj.found(): if obj.found():
processed_reqs.append(obj.name) processed_reqs.append(obj.name)
self.add_version_reqs(obj.name, obj.version_reqs)
elif isinstance(obj, str): elif isinstance(obj, str):
processed_reqs.append(obj) name, version_req = self.split_version_req(obj)
processed_reqs.append(name)
self.add_version_reqs(name, version_req)
elif isinstance(obj, dependencies.Dependency) and not obj.found(): elif isinstance(obj, dependencies.Dependency) and not obj.found():
pass pass
else: else:
@ -83,12 +89,15 @@ class DependenciesHelper:
for obj in libs: for obj in libs:
if hasattr(obj, 'pcdep'): if hasattr(obj, 'pcdep'):
pcdeps = mesonlib.listify(obj.pcdep) pcdeps = mesonlib.listify(obj.pcdep)
processed_reqs += [i.name for i in pcdeps] for d in pcdeps:
processed_reqs += d.name
self.add_version_reqs(d.name, obj.version_reqs)
elif hasattr(obj, 'generated_pc'): elif hasattr(obj, 'generated_pc'):
processed_reqs.append(obj.generated_pc) processed_reqs.append(obj.generated_pc)
elif isinstance(obj, dependencies.PkgConfigDependency): elif isinstance(obj, dependencies.PkgConfigDependency):
if obj.found(): if obj.found():
processed_reqs.append(obj.name) processed_reqs.append(obj.name)
self.add_version_reqs(obj.name, obj.version_reqs)
elif isinstance(obj, dependencies.ThreadDependency): elif isinstance(obj, dependencies.ThreadDependency):
processed_libs += obj.get_compiler().thread_link_flags(obj.env) processed_libs += obj.get_compiler().thread_link_flags(obj.env)
processed_cflags += obj.get_compiler().thread_flags(obj.env) processed_cflags += obj.get_compiler().thread_flags(obj.env)
@ -123,6 +132,36 @@ class DependenciesHelper:
return processed_libs, processed_reqs, processed_cflags return processed_libs, processed_reqs, processed_cflags
def add_version_reqs(self, name, version_reqs):
if version_reqs:
vreqs = self.version_reqs.get(name, [])
vreqs += mesonlib.stringlistify(version_reqs)
self.version_reqs[name] = vreqs
def split_version_req(self, s):
for op in ['>=', '<=', '!=', '==', '=', '>', '<']:
pos = s.find(op)
if pos > 0:
return s[0:pos].strip(), s[pos:].strip()
return s, None
def format_vreq(self, vreq):
# vreq are '>=1.0' and pkgconfig wants '>= 1.0'
for op in ['>=', '<=', '!=', '==', '=', '>', '<']:
if vreq.startswith(op):
return op + ' ' + vreq[len(op):]
return vreq
def format_reqs(self, reqs):
result = []
for name in reqs:
vreqs = self.version_reqs.get(name, None)
if vreqs:
result += [name + ' ' + self.format_vreq(vreq) for vreq in vreqs]
else:
result += [name]
return ', '.join(result)
def remove_dups(self): def remove_dups(self):
def _fn(xs): def _fn(xs):
# Remove duplicates whilst preserving original order # Remove duplicates whilst preserving original order
@ -207,11 +246,12 @@ class PkgConfigModule(ExtensionModule):
if len(url) > 0: if len(url) > 0:
ofile.write('URL: %s\n' % url) ofile.write('URL: %s\n' % url)
ofile.write('Version: %s\n' % version) ofile.write('Version: %s\n' % version)
if len(deps.pub_reqs) > 0: reqs_str = deps.format_reqs(deps.pub_reqs)
ofile.write('Requires: {}\n'.format(' '.join(deps.pub_reqs))) if len(reqs_str) > 0:
if len(deps.priv_reqs) > 0: ofile.write('Requires: {}\n'.format(reqs_str))
ofile.write( reqs_str = deps.format_reqs(deps.priv_reqs)
'Requires.private: {}\n'.format(' '.join(deps.priv_reqs))) if len(reqs_str) > 0:
ofile.write('Requires.private: {}\n'.format(reqs_str))
if len(conflicts) > 0: if len(conflicts) > 0:
ofile.write('Conflicts: {}\n'.format(' '.join(conflicts))) ofile.write('Conflicts: {}\n'.format(' '.join(conflicts)))

@ -2266,11 +2266,11 @@ class LinuxlikeTests(BasePlatformTests):
os.environ['PKG_CONFIG_LIBDIR'] = os.pathsep.join([privatedir1, privatedir2]) os.environ['PKG_CONFIG_LIBDIR'] = os.pathsep.join([privatedir1, privatedir2])
cmd = ['pkg-config', 'dependency-test'] cmd = ['pkg-config', 'dependency-test']
out = self._run(cmd + ['--print-requires']).strip().split() out = self._run(cmd + ['--print-requires']).strip().split('\n')
self.assertEqual(sorted(out), sorted(['libexposed'])) self.assertEqual(sorted(out), sorted(['libexposed']))
out = self._run(cmd + ['--print-requires-private']).strip().split() out = self._run(cmd + ['--print-requires-private']).strip().split('\n')
self.assertEqual(sorted(out), sorted(['libfoo'])) self.assertEqual(sorted(out), sorted(['libfoo >= 1.0']))
out = self._run(cmd + ['--cflags-only-other']).strip().split() out = self._run(cmd + ['--cflags-only-other']).strip().split()
self.assertEqual(sorted(out), sorted(['-pthread', '-DCUSTOM'])) self.assertEqual(sorted(out), sorted(['-pthread', '-DCUSTOM']))
@ -2286,12 +2286,12 @@ class LinuxlikeTests(BasePlatformTests):
'-lfoo'])) '-lfoo']))
cmd = ['pkg-config', 'requires-test'] cmd = ['pkg-config', 'requires-test']
out = self._run(cmd + ['--print-requires']).strip().split() out = self._run(cmd + ['--print-requires']).strip().split('\n')
self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo', 'libhello'])) self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo >= 1.0', 'libhello']))
cmd = ['pkg-config', 'requires-private-test'] cmd = ['pkg-config', 'requires-private-test']
out = self._run(cmd + ['--print-requires-private']).strip().split() out = self._run(cmd + ['--print-requires-private']).strip().split('\n')
self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo', 'libhello'])) self.assertEqual(sorted(out), sorted(['libexposed', 'libfoo >= 1.0', 'libhello']))
def test_pkg_unfound(self): def test_pkg_unfound(self):
testdir = os.path.join(self.unit_test_dir, '22 unfound pkgconfig') testdir = os.path.join(self.unit_test_dir, '22 unfound pkgconfig')

@ -14,7 +14,7 @@ pkgg.generate(libraries : exposed_lib,
) )
# Declare a few different Dependency objects # Declare a few different Dependency objects
pc_dep = dependency('libfoo') pc_dep = dependency('libfoo', version : '>=1.0')
notfound_dep = dependency('notfound', required : false) notfound_dep = dependency('notfound', required : false)
threads_dep = dependency('threads') threads_dep = dependency('threads')
custom_dep = declare_dependency(link_args : ['-lcustom'], compile_args : ['-DCUSTOM']) custom_dep = declare_dependency(link_args : ['-lcustom'], compile_args : ['-DCUSTOM'])

Loading…
Cancel
Save