Skip to content

Commit 09d05d4

Browse files
committed
dependencies/pkgconfig: Canonicalize libpaths
Prefix library paths specified by -L are converted to canonical paths to improve the library runpath stored in the binary output. For example, if `pkg-config --libs add` returns the following: -L/usr/local/lib/pkgconfig/../../lib -ladd we convert the path so that it is as if it had returned: -L/usr/local/lib -ladd
1 parent 4bbd1ef commit 09d05d4

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

mesonbuild/dependencies/pkgconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# Copyright 2013-2021 The Meson development team
2+
# Copyright 2013-2025 The Meson development team
33

44
from __future__ import annotations
55

@@ -423,11 +423,11 @@ def _search_libs(self, libs_in: ImmutableListProtocol[str], raw_libs_in: Immutab
423423
if not os.path.isabs(path):
424424
# Resolve the path as a compiler in the build directory would
425425
path = os.path.join(self.env.get_build_dir(), path)
426-
prefix_libpaths.add(path)
426+
prefix_libpaths.add(Path(path).resolve().as_posix())
427427
# Library paths are not always ordered in a meaningful way
428428
#
429429
# Instead of relying on pkg-config or pkgconf to provide -L flags in a
430-
# specific order, we reorder library paths ourselves, according to th
430+
# specific order, we reorder library paths ourselves, according to the
431431
# order specified in PKG_CONFIG_PATH. See:
432432
# https://github.com/mesonbuild/meson/issues/4271
433433
#

unittests/allplatformstests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ def test_pkgconfig_gen_escaping(self):
21592159
kwargs = {'required': True, 'silent': True}
21602160
foo_dep = PkgConfigDependency('libanswer', env, kwargs)
21612161
# Ensure link_args are properly quoted
2162-
libdir = PurePath(prefix) / PurePath(libdir)
2162+
libdir = Path(prefix, libdir).resolve()
21632163
link_args = ['-L' + libdir.as_posix(), '-lanswer']
21642164
self.assertEqual(foo_dep.get_link_args(), link_args)
21652165
# Ensure include args are properly quoted

unittests/internaltests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# Copyright 2016-2021 The Meson development team
2+
# Copyright 2016-2025 The Meson development team
33

44
from configparser import ConfigParser
55
from pathlib import Path
@@ -669,6 +669,8 @@ def _call_pkgbin(self, args, env=None):
669669
instance_method.return_value = FakeInstance(env, MachineChoice.HOST, silent=True)
670670
kwargs = {'required': True, 'silent': True}
671671
foo_dep = PkgConfigDependency('foo', env, kwargs)
672+
p1 = p1.resolve()
673+
p2 = p2.resolve()
672674
self.assertEqual(foo_dep.get_link_args(),
673675
[(p1 / 'libfoo.a').as_posix(), (p2 / 'libbar.a').as_posix()])
674676
bar_dep = PkgConfigDependency('bar', env, kwargs)

unittests/linuxliketests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
2-
# Copyright 2016-2022 The Meson development team
2+
# Copyright 2016-2025 The Meson development team
33

44
import stat
55
import subprocess
@@ -1150,7 +1150,7 @@ def test_pkgconfig_relative_paths(self):
11501150
self.assertTrue(relative_path_dep.found())
11511151

11521152
# Ensure link_args are properly quoted
1153-
libpath = Path(self.builddir) / '../relativepath/lib'
1153+
libpath = Path(self.builddir).parent / 'relativepath/lib'
11541154
link_args = ['-L' + libpath.as_posix(), '-lrelativepath']
11551155
self.assertEqual(relative_path_dep.get_link_args(), link_args)
11561156

0 commit comments

Comments
 (0)