From d532650b0d7fb8bb062d852a8fdecd10be00ce21 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 16 Mar 2018 23:52:45 +0200 Subject: 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. --- run_unittests.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index 9c7b16b..1e8bec4 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -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): ''' -- cgit v1.1 From c385f7973777e0e7b7e4694d69d6584e2ceae69f Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 17 Mar 2018 00:37:05 +0200 Subject: Do not leak out private dependencies for shared libraries. --- run_unittests.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index 1e8bec4..44d5c9d 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -2726,6 +2726,13 @@ endian = 'little' 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 + # Private internal libraries must not leak out. + pkg_out = subprocess.check_output(['pkg-config', '--static', '--libs', 'libpkgdep']) + self.assertFalse(b'libpkgdep-int' in pkg_out, 'Internal library leaked out.') + # Dependencies must not leak to cflags when building only a shared library. + pkg_out = subprocess.check_output(['pkg-config', '--cflags', 'libpkgdep']) + self.assertFalse(b'glib' in pkg_out, 'Internal dependency leaked to headers.') + # Test that the result is usable. self.init(testdir2) self.build() myenv = os.environ.copy() -- cgit v1.1 From cf5f1a83d55d05412e29058844e4fda5e420553b Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 17 Mar 2018 19:44:16 +0200 Subject: Fix existing tests. --- run_unittests.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'run_unittests.py') diff --git a/run_unittests.py b/run_unittests.py index 44d5c9d..d528717 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -510,7 +510,8 @@ class BasePlatformTests(unittest.TestCase): windows_proof_rmtree(path) except FileNotFoundError: pass - os.environ = self.orig_env + os.environ.clear() + os.environ.update(self.orig_env) super().tearDown() def _run(self, command, workdir=None): @@ -2717,6 +2718,10 @@ endian = 'little' 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') + if subprocess.call(['pkg-config', '--cflags', 'glib-2.0'], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) != 0: + raise unittest.SkipTest('Glib 2.0 dependency not available.') with tempfile.TemporaryDirectory() as tempdirname: self.init(testdir1, ['--prefix=' + tempdirname, '--libdir=lib'], default_args=False) self.install(use_destdir=False) @@ -2737,8 +2742,10 @@ endian = 'little' self.build() myenv = os.environ.copy() myenv['LD_LIBRARY_PATH'] = lib_dir + if is_cygwin(): + bin_dir = os.path.join(tempdirname, 'bin') + myenv['PATH'] = bin_dir + os.pathsep + myenv['PATH'] 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) -- cgit v1.1