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 ''
pull/899/head
Nirbheek Chauhan 8 years ago
parent 5e384b8396
commit 6ffae922cc
  1. 15
      mesonbuild/dependencies.py
  2. 21
      run_unittests.py
  3. 1
      test cases/common/51 pkgconfig-gen/installed_files.txt
  4. 14
      test cases/common/51 pkgconfig-gen/meson.build

@ -87,6 +87,7 @@ class PkgConfigDependency(Dependency):
self.is_libtool = False
self.required = kwargs.get('required', True)
self.static = kwargs.get('static', False)
self.silent = kwargs.get('silent', False)
if not isinstance(self.static, bool):
raise DependencyException('Static keyword must be boolean')
self.cargs = []
@ -132,14 +133,16 @@ class PkgConfigDependency(Dependency):
if not self.is_found:
found_msg += [mlog.red('NO'), 'found {!r}'.format(self.modversion),
'but need {!r}'.format(self.version_requirement)]
mlog.log(*found_msg)
if not self.silent:
mlog.log(*found_msg)
if self.required:
raise DependencyException(
'Invalid version of a dependency, needed %s %s found %s.' %
(name, self.version_requirement, self.modversion))
return
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
self._set_cargs()
# Fetch the libraries and library paths needed for using this
@ -214,14 +217,16 @@ class PkgConfigDependency(Dependency):
stderr=subprocess.PIPE)
out = p.communicate()[0]
if p.returncode == 0:
mlog.log('Found pkg-config:', mlog.bold(shutil.which('pkg-config')),
'(%s)' % out.decode().strip())
if not self.silent:
mlog.log('Found pkg-config:', mlog.bold(shutil.which('pkg-config')),
'(%s)' % out.decode().strip())
PkgConfigDependency.pkgconfig_found = True
return
except Exception:
pass
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):
return self.is_found

@ -18,6 +18,7 @@ import subprocess
import re, json
import tempfile
from mesonbuild.environment import detect_ninja
from mesonbuild.dependencies import PkgConfigDependency
def get_soname(fname):
# HACK, fix to not use shell.
@ -28,6 +29,13 @@ def get_soname(fname):
if m is not None:
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):
def setUp(self):
super().setUp()
@ -38,9 +46,11 @@ class LinuxlikeTests(unittest.TestCase):
self.ninja_command = [detect_ninja(), '-C', self.builddir]
self.common_test_dir = os.path.join(src_root, 'test cases/common')
self.output = b''
self.orig_env = os.environ.copy()
def tearDown(self):
shutil.rmtree(self.builddir)
os.environ = self.orig_env
super().tearDown()
def init(self, srcdir):
@ -87,5 +97,16 @@ class LinuxlikeTests(unittest.TestCase):
compdb = self.get_compdb()
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__':
unittest.main()

@ -1,2 +1,3 @@
usr/include/simple.h
usr/lib/pkgconfig/simple.pc
usr/lib/pkgconfig/libfoo.pc

@ -15,5 +15,15 @@ pkgg.generate(
description : 'A simple demo library.',
requires : 'glib-2.0', # Not really, but only here to test that this works.
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…
Cancel
Save