diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2019-09-18 22:06:19 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2019-10-01 13:06:45 -0400 |
commit | dc5ad1fad953d8cc2191aed1bd6c7c7db83faf99 (patch) | |
tree | 8e590d391931dd4701bf61f5609bc409ae3663b9 | |
parent | 484b721369957100ee6d2b76f17224a583e2bd86 (diff) | |
download | meson-dc5ad1fad953d8cc2191aed1bd6c7c7db83faf99.zip meson-dc5ad1fad953d8cc2191aed1bd6c7c7db83faf99.tar.gz meson-dc5ad1fad953d8cc2191aed1bd6c7c7db83faf99.tar.bz2 |
pkgconfig: Do not include uninstalled static libraries
-rw-r--r-- | mesonbuild/build.py | 10 | ||||
-rw-r--r-- | mesonbuild/modules/pkgconfig.py | 4 | ||||
-rwxr-xr-x | run_unittests.py | 10 | ||||
-rw-r--r-- | test cases/unit/69 static link/lib/func5.c | 4 | ||||
-rw-r--r-- | test cases/unit/69 static link/lib/func6.c | 6 | ||||
-rw-r--r-- | test cases/unit/69 static link/lib/meson.build | 12 | ||||
-rw-r--r-- | test cases/unit/69 static link/meson.build | 8 | ||||
-rw-r--r-- | test cases/unit/69 static link/test3.c | 6 |
8 files changed, 53 insertions, 7 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 1530ae5..bb5d9db 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -970,11 +970,11 @@ This will become a hard error in a future Meson release.''') def get_extra_args(self, language): return self.extra_args.get(language, []) - def get_dependencies(self, exclude=None, internal=True): + def get_dependencies(self, exclude=None, for_pkgconfig=False): transitive_deps = [] if exclude is None: exclude = [] - if internal: + if not for_pkgconfig: link_targets = itertools.chain(self.link_targets, self.link_whole_targets) else: # We don't want the 'internal' libraries when generating the @@ -983,9 +983,13 @@ This will become a hard error in a future Meson release.''') for t in link_targets: if t in transitive_deps or t in exclude: continue + if for_pkgconfig and t.is_internal(): + # Skip uninstalled static libraries, they have been promoted to + # link_whole into the static library. + continue transitive_deps.append(t) if isinstance(t, StaticLibrary): - transitive_deps += t.get_dependencies(transitive_deps + exclude, internal) + transitive_deps += t.get_dependencies(transitive_deps + exclude, for_pkgconfig) return transitive_deps def get_source_subdir(self): diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index ce5f5e0..5a95dfc 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -148,10 +148,10 @@ class DependenciesHelper: elif isinstance(obj, (build.SharedLibrary, build.StaticLibrary)): processed_libs.append(obj) if isinstance(obj, build.StaticLibrary) and public: - self.add_pub_libs(obj.get_dependencies(internal=False)) + self.add_pub_libs(obj.get_dependencies(for_pkgconfig=True)) self.add_pub_libs(obj.get_external_deps()) else: - self.add_priv_libs(obj.get_dependencies(internal=False)) + self.add_priv_libs(obj.get_dependencies(for_pkgconfig=True)) self.add_priv_libs(obj.get_external_deps()) elif isinstance(obj, str): processed_libs.append(obj) diff --git a/run_unittests.py b/run_unittests.py index 67a3df7..d835ccd 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -5637,6 +5637,9 @@ c = ['{0}'] self.init(testdir, override_envvars=env) def test_static_link(self): + if is_cygwin(): + raise unittest.SkipTest("Cygwin doesn't support LD_LIBRARY_PATH.") + # Build some libraries and install them testdir = os.path.join(self.unit_test_dir, '69 static link/lib') libdir = os.path.join(self.installdir, self.prefix[1:], self.libdir) @@ -5646,9 +5649,12 @@ c = ['{0}'] # Test that installed libraries works self.new_builddir() testdir = os.path.join(self.unit_test_dir, '69 static link') - self.init(testdir, extra_args=['-Dc_link_args="-L{}"'.format(libdir)]) + env = {'PKG_CONFIG_LIBDIR': os.path.join(libdir, 'pkgconfig')} + run_env = {'LD_LIBRARY_PATH': libdir} + self.init(testdir, extra_args=['-Dc_link_args="-L{}"'.format(libdir)], + override_envvars=env) self.build() - self.run_tests() + self.run_tests(override_envvars=run_env) def should_run_cross_arm_tests(): return shutil.which('arm-linux-gnueabihf-gcc') and not platform.machine().lower().startswith('arm') diff --git a/test cases/unit/69 static link/lib/func5.c b/test cases/unit/69 static link/lib/func5.c new file mode 100644 index 0000000..8e07864 --- /dev/null +++ b/test cases/unit/69 static link/lib/func5.c @@ -0,0 +1,4 @@ +int func5() +{ + return 1; +} diff --git a/test cases/unit/69 static link/lib/func6.c b/test cases/unit/69 static link/lib/func6.c new file mode 100644 index 0000000..276fe7d --- /dev/null +++ b/test cases/unit/69 static link/lib/func6.c @@ -0,0 +1,6 @@ +int func5(); + +int func6() +{ + return func5() + 1; +} diff --git a/test cases/unit/69 static link/lib/meson.build b/test cases/unit/69 static link/lib/meson.build index f5cc76b..9bd3d19 100644 --- a/test cases/unit/69 static link/lib/meson.build +++ b/test cases/unit/69 static link/lib/meson.build @@ -1,5 +1,7 @@ project('test static link libs', 'c') +pkg = import('pkgconfig') + # libfunc2 should contain both func1() and func2() symbols libfunc1 = static_library('func1', 'func1.c', install : false) @@ -14,3 +16,13 @@ libfunc3 = static_library('func3', 'func3.c', libfunc4 = static_library('func4', 'func4.c', link_with : libfunc3, install : true) + +# Same as above, but also generate an pkg-config file. Use both_libraries() to +# make sure a complete .pc file gets generated. libfunc5 should not be mentioned +# into the .pc file because it's not installed. +libfunc5 = static_library('func5', 'func5.c', + install : false) +libfunc6 = both_libraries('func6', 'func6.c', + link_with : libfunc5, + install : true) +pkg.generate(libfunc6) diff --git a/test cases/unit/69 static link/meson.build b/test cases/unit/69 static link/meson.build index 4d5d074..307139a 100644 --- a/test cases/unit/69 static link/meson.build +++ b/test cases/unit/69 static link/meson.build @@ -9,3 +9,11 @@ test('test1', executable('test1', 'test1.c', dependencies : func2_dep)) # Verify that installed libfunc4.a is usable func4_dep = cc.find_library('func4') test('test2', executable('test2', 'test2.c', dependencies : func4_dep)) + +# Verify that installed pkg-config file is usable for both shared and static link +func6_static_dep = dependency('func6', static : true) +test('test3-static', executable('test3-static', 'test3.c', + dependencies : func6_static_dep)) +func6_shared_dep = dependency('func6', static : false) +test('test3-shared', executable('test3-shared', 'test3.c', + dependencies : func6_shared_dep)) diff --git a/test cases/unit/69 static link/test3.c b/test cases/unit/69 static link/test3.c new file mode 100644 index 0000000..1216064 --- /dev/null +++ b/test cases/unit/69 static link/test3.c @@ -0,0 +1,6 @@ +int func6(); + +int main(int argc, char *argv[]) +{ + return func6() == 2 ? 0 : 1; +} |