Add test for pkgconfig generation and usage.

This builds a project with pkg-config file, installs it and then
builds a second project that uses that dependency and runs the result.
pull/3251/head
Jussi Pakkanen 7 years ago
parent a20c5ccd13
commit d532650b0d
  1. 28
      run_unittests.py
  2. 7
      test cases/unit/24 pkgconfig usage/dependee/meson.build
  3. 6
      test cases/unit/24 pkgconfig usage/dependee/pkguser.c
  4. 24
      test cases/unit/24 pkgconfig usage/dependency/meson.build
  5. 7
      test cases/unit/24 pkgconfig usage/dependency/pkgdep.c
  6. 3
      test cases/unit/24 pkgconfig usage/dependency/pkgdep.h
  7. 3
      test cases/unit/24 pkgconfig usage/dependency/privatelib.c

@ -585,10 +585,11 @@ class BasePlatformTests(unittest.TestCase):
def run_tests(self):
self._run(self.test_command, workdir=self.builddir)
def install(self):
def install(self, *, use_destdir=True):
if self.backend is not Backend.ninja:
raise unittest.SkipTest('{!r} backend can\'t install files'.format(self.backend.name))
os.environ['DESTDIR'] = self.installdir
if use_destdir:
os.environ['DESTDIR'] = self.installdir
self._run(self.install_command, workdir=self.builddir)
def uninstall(self):
@ -2712,6 +2713,29 @@ endian = 'little'
self.build()
mesonbuild.modules.gnome.native_glib_version = None
@unittest.skipIf(shutil.which('pkg-config') is None, 'Pkg-config not found.')
def test_pkgconfig_usage(self):
testdir1 = os.path.join(self.unit_test_dir, '24 pkgconfig usage/dependency')
testdir2 = os.path.join(self.unit_test_dir, '24 pkgconfig usage/dependee')
with tempfile.TemporaryDirectory() as tempdirname:
self.init(testdir1, ['--prefix=' + tempdirname, '--libdir=lib'], default_args=False)
self.install(use_destdir=False)
shutil.rmtree(self.builddir)
os.mkdir(self.builddir)
pkg_dir = os.path.join(tempdirname, 'lib/pkgconfig')
self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'libpkgdep.pc')))
lib_dir = os.path.join(tempdirname, 'lib')
os.environ['PKG_CONFIG_PATH'] = pkg_dir
self.init(testdir2)
self.build()
myenv = os.environ.copy()
myenv['LD_LIBRARY_PATH'] = lib_dir
self.assertTrue(os.path.isdir(lib_dir))
self.assertTrue(os.path.isfile(os.path.join(lib_dir, 'libpkgdep.so')))
test_exe = os.path.join(self.builddir, 'pkguser')
self.assertTrue(os.path.isfile(test_exe))
subprocess.check_call(test_exe, env=myenv)
class LinuxArmCrossCompileTests(BasePlatformTests):
'''

@ -0,0 +1,7 @@
project('pkgconfig user', 'c')
pkgdep = dependency('libpkgdep')
executable('pkguser', 'pkguser.c',
dependencies : pkgdep)

@ -0,0 +1,6 @@
#include<pkgdep.h>
int main(int argc, char **argv) {
int res = pkgdep();
return res != 99;
}

@ -0,0 +1,24 @@
project('pkgconfig dep', 'c',
version : '1.0.0')
# This is not used in the code, only to check that it does not
# leak out to --libs.
glib_dep = dependency('glib-2.0')
pkgconfig = import('pkgconfig')
intlib = static_library('libpkgdep-int', 'privatelib.c')
intdep = declare_dependency(link_with : intlib)
lib = shared_library('pkgdep', 'pkgdep.c',
dependencies : [glib_dep, intdep],
install : true)
install_headers('pkgdep.h')
pkgconfig.generate(
filebase : 'libpkgdep',
name : 'Libpkgdep',
description : 'Sample pkgconfig dependency library',
version : meson.project_version(),
libraries : lib)

@ -0,0 +1,7 @@
#include<pkgdep.h>
int internal_thingy();
int pkgdep() {
return internal_thingy();
}

@ -0,0 +1,3 @@
int internal_thingy() {
return 99;
}
Loading…
Cancel
Save