Add a unittest for pkg-config file generation
This also tests that -lfoo is correctly added to libfoo.pc when the library name is 'libfoo' and name_prefix is ''
This commit is contained in:
parent
5e384b8396
commit
6ffae922cc
|
@ -87,6 +87,7 @@ class PkgConfigDependency(Dependency):
|
||||||
self.is_libtool = False
|
self.is_libtool = False
|
||||||
self.required = kwargs.get('required', True)
|
self.required = kwargs.get('required', True)
|
||||||
self.static = kwargs.get('static', False)
|
self.static = kwargs.get('static', False)
|
||||||
|
self.silent = kwargs.get('silent', False)
|
||||||
if not isinstance(self.static, bool):
|
if not isinstance(self.static, bool):
|
||||||
raise DependencyException('Static keyword must be boolean')
|
raise DependencyException('Static keyword must be boolean')
|
||||||
self.cargs = []
|
self.cargs = []
|
||||||
|
@ -132,14 +133,16 @@ class PkgConfigDependency(Dependency):
|
||||||
if not self.is_found:
|
if not self.is_found:
|
||||||
found_msg += [mlog.red('NO'), 'found {!r}'.format(self.modversion),
|
found_msg += [mlog.red('NO'), 'found {!r}'.format(self.modversion),
|
||||||
'but need {!r}'.format(self.version_requirement)]
|
'but need {!r}'.format(self.version_requirement)]
|
||||||
mlog.log(*found_msg)
|
if not self.silent:
|
||||||
|
mlog.log(*found_msg)
|
||||||
if self.required:
|
if self.required:
|
||||||
raise DependencyException(
|
raise DependencyException(
|
||||||
'Invalid version of a dependency, needed %s %s found %s.' %
|
'Invalid version of a dependency, needed %s %s found %s.' %
|
||||||
(name, self.version_requirement, self.modversion))
|
(name, self.version_requirement, self.modversion))
|
||||||
return
|
return
|
||||||
found_msg += [mlog.green('YES'), self.modversion]
|
found_msg += [mlog.green('YES'), self.modversion]
|
||||||
mlog.log(*found_msg)
|
if not self.silent:
|
||||||
|
mlog.log(*found_msg)
|
||||||
# Fetch cargs to be used while using this dependency
|
# Fetch cargs to be used while using this dependency
|
||||||
self._set_cargs()
|
self._set_cargs()
|
||||||
# Fetch the libraries and library paths needed for using this
|
# Fetch the libraries and library paths needed for using this
|
||||||
|
@ -214,14 +217,16 @@ class PkgConfigDependency(Dependency):
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
out = p.communicate()[0]
|
out = p.communicate()[0]
|
||||||
if p.returncode == 0:
|
if p.returncode == 0:
|
||||||
mlog.log('Found pkg-config:', mlog.bold(shutil.which('pkg-config')),
|
if not self.silent:
|
||||||
'(%s)' % out.decode().strip())
|
mlog.log('Found pkg-config:', mlog.bold(shutil.which('pkg-config')),
|
||||||
|
'(%s)' % out.decode().strip())
|
||||||
PkgConfigDependency.pkgconfig_found = True
|
PkgConfigDependency.pkgconfig_found = True
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
PkgConfigDependency.pkgconfig_found = False
|
PkgConfigDependency.pkgconfig_found = False
|
||||||
mlog.log('Found Pkg-config:', mlog.red('NO'))
|
if not self.silent:
|
||||||
|
mlog.log('Found Pkg-config:', mlog.red('NO'))
|
||||||
|
|
||||||
def found(self):
|
def found(self):
|
||||||
return self.is_found
|
return self.is_found
|
||||||
|
|
|
@ -18,6 +18,7 @@ import subprocess
|
||||||
import re, json
|
import re, json
|
||||||
import tempfile
|
import tempfile
|
||||||
from mesonbuild.environment import detect_ninja
|
from mesonbuild.environment import detect_ninja
|
||||||
|
from mesonbuild.dependencies import PkgConfigDependency
|
||||||
|
|
||||||
def get_soname(fname):
|
def get_soname(fname):
|
||||||
# HACK, fix to not use shell.
|
# HACK, fix to not use shell.
|
||||||
|
@ -28,6 +29,13 @@ def get_soname(fname):
|
||||||
if m is not None:
|
if m is not None:
|
||||||
return m.group(1)
|
return m.group(1)
|
||||||
|
|
||||||
|
class FakeEnvironment(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.cross_info = None
|
||||||
|
|
||||||
|
def is_cross_build(self):
|
||||||
|
return False
|
||||||
|
|
||||||
class LinuxlikeTests(unittest.TestCase):
|
class LinuxlikeTests(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
@ -38,9 +46,11 @@ class LinuxlikeTests(unittest.TestCase):
|
||||||
self.ninja_command = [detect_ninja(), '-C', self.builddir]
|
self.ninja_command = [detect_ninja(), '-C', self.builddir]
|
||||||
self.common_test_dir = os.path.join(src_root, 'test cases/common')
|
self.common_test_dir = os.path.join(src_root, 'test cases/common')
|
||||||
self.output = b''
|
self.output = b''
|
||||||
|
self.orig_env = os.environ.copy()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.builddir)
|
shutil.rmtree(self.builddir)
|
||||||
|
os.environ = self.orig_env
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def init(self, srcdir):
|
def init(self, srcdir):
|
||||||
|
@ -87,5 +97,16 @@ class LinuxlikeTests(unittest.TestCase):
|
||||||
compdb = self.get_compdb()
|
compdb = self.get_compdb()
|
||||||
self.assertTrue('-fPIC' not in compdb[0]['command'])
|
self.assertTrue('-fPIC' not in compdb[0]['command'])
|
||||||
|
|
||||||
|
def test_pkgconfig_gen(self):
|
||||||
|
testdir = os.path.join(self.common_test_dir, '51 pkgconfig-gen')
|
||||||
|
self.init(testdir)
|
||||||
|
env = FakeEnvironment()
|
||||||
|
kwargs = {'required': True, 'silent': True}
|
||||||
|
os.environ['PKG_CONFIG_LIBDIR'] = os.path.join(self.builddir, 'meson-private')
|
||||||
|
simple_dep = PkgConfigDependency('libfoo', env, kwargs)
|
||||||
|
self.assertTrue(simple_dep.found())
|
||||||
|
self.assertEqual(simple_dep.get_version(), '1.0')
|
||||||
|
self.assertTrue('-lfoo' in simple_dep.get_link_args())
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
usr/include/simple.h
|
usr/include/simple.h
|
||||||
usr/lib/pkgconfig/simple.pc
|
usr/lib/pkgconfig/simple.pc
|
||||||
|
usr/lib/pkgconfig/libfoo.pc
|
||||||
|
|
|
@ -15,5 +15,15 @@ pkgg.generate(
|
||||||
description : 'A simple demo library.',
|
description : 'A simple demo library.',
|
||||||
requires : 'glib-2.0', # Not really, but only here to test that this works.
|
requires : 'glib-2.0', # Not really, but only here to test that this works.
|
||||||
requires_private : ['gio-2.0', 'gobject-2.0'],
|
requires_private : ['gio-2.0', 'gobject-2.0'],
|
||||||
libraries_private : '-lz',
|
libraries_private : '-lz')
|
||||||
)
|
|
||||||
|
# Test that name_prefix='' and name='libfoo' results in '-lfoo'
|
||||||
|
lib2 = shared_library('libfoo', 'simple.c',
|
||||||
|
name_prefix : '',
|
||||||
|
version : libver)
|
||||||
|
|
||||||
|
pkgg.generate(
|
||||||
|
libraries : lib2,
|
||||||
|
name : 'libfoo',
|
||||||
|
version : libver,
|
||||||
|
description : 'A foo library.')
|
||||||
|
|
Loading…
Reference in New Issue