Commit 64c558f6 authored by Ting-Wei Lan's avatar Ting-Wei Lan

core-deps-latest: Update meson to 0.53.0

Meson 0.53 is now able to use PKG_CONFIG_PATH to sort library paths.
Therefore, the local patch included in JHBuild can be dropped.

Meson 0.53 changes the installation path of .pc files from lib/pkgconfig
to libdata/pkgconfig on FreeBSD without providing any way to override
the behavior. While it can be an improvement of usability on FreeBSD
because FreeBSD configures its pkgconf to use libdata/pkgconfig instead
of the upstream default lib/pkgconfig and share/pkgconfig, it can also
be a problem for JHBuild. JHBuild does not change the directory layout
depending on the platform, and doing so can confuse the user and make
the environment messy. Therefore, revert the change until there is a
better way to choose the default installation path.
parent ecd10042
Pipeline #143556 passed with stage
in 7 minutes and 16 seconds
......@@ -1737,12 +1737,12 @@
<distutils id="meson" python3="1">
<branch repo="github-tar"
<patch file="meson-dont-use-rpath-on-pkg-config-deps.patch" strip="1"/>
<patch file="meson-sort-libpaths-with-pkg-config-path.patch" strip="1"/>
<patch file="meson-revert-change-pkgconfig-directory-freebsd.patch" strip="1"/>
<dep package="ninja"/>
From 08e37a624c7d938a0401b216c22542ee6b59dffb Mon Sep 17 00:00:00 2001
From: Ting-Wei Lan <>
Date: Tue, 14 Jan 2020 21:05:08 +0800
Subject: [PATCH] Revert "Change default pkgconfig directory on FreeBSD"
This reverts commit aba8792b6657e3aa380586764a8b3ec567895a28.
The commit aba8792b6657e3aa380586764a8b3ec567895a28 changes the
installation path of pkg-config files from lib/pkgconfig to
libdata/pkgconfig on FreeBSD. Since JHBuild does not change the
directory layout depending on the platform, revert it for now to keep
the current PKG_CONFIG_PATH working.
Works around
mesonbuild/modules/ | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/mesonbuild/modules/ b/mesonbuild/modules/
index a37dd4f6..cf86785a 100644
--- a/mesonbuild/modules/
+++ b/mesonbuild/modules/
@@ -437,10 +437,7 @@ class PkgConfigModule(ExtensionModule):
pcfile = filebase + '.pc'
pkgroot = kwargs.get('install_dir', default_install_dir)
if pkgroot is None:
- if mesonlib.is_freebsd():
- pkgroot = os.path.join(state.environment.coredata.get_builtin_option('prefix'), 'libdata', 'pkgconfig')
- else:
- pkgroot = os.path.join(state.environment.coredata.get_builtin_option('libdir'), 'pkgconfig')
+ pkgroot = os.path.join(state.environment.coredata.get_builtin_option('libdir'), 'pkgconfig')
if not isinstance(pkgroot, str):
raise mesonlib.MesonException('Install_dir must be a string.')
self.generate_pkgconfig_file(state, deps, subdirs, name, description, url,
From 93a432534c954ab43cee901fcb1a35f98a99da93 Mon Sep 17 00:00:00 2001
From: Ting-Wei Lan <>
Date: Thu, 4 Oct 2018 23:30:28 +0800
Subject: [PATCH 2/2] PkgConfigDependency: Sort -L flags according to
When there is more than one path in PKG_CONFIG_PATH. It is almost always
preferred to find things in the order specified by PKG_CONFIG_PATH
instead of assuming pkg-config returns flags in a meaningful order.
For example:
libcanberra-gtk3 is a library which depends on gtk+-3.0. The dependency
is mentioned in the .pc file with 'Requires', so flags from gtk+-3.0 are
used in both dynamic and static linking.
Assume the user wants to compile an application which needs both
libcanberra-gtk3 and gtk+-3.0. The application depends on features added
in the latest version of gtk+-3.0, which can be found in the home
directory of the user but not in /usr/local. When meson asks pkg-config
for linker flags of libcanberra-gtk3, pkg-config picks
/usr/local/lib/pkgconfig/libcanberra-gtk3.pc and
/home/mesonuser/.local/lib/pkgconfig/gtk+-3.0.pc. Since these two
libraries come from different prefixes, there will be two -L arguments
in the output of pkg-config. If -L/usr/local/lib is put before
-L/home/mesonuser/.local/lib, meson will find both libraries in
/usr/local/lib instead of picking from the home directory.
This can result in linking failure such as undefined references error
when meson decides to put linker arguments of libcanberra-gtk3 before
linker arguments of gtk+-3.0. When both /usr/local/lib/ and
/home/mesonuser/.local/lib/ are present on the command
line, the linker chooses the first one and ignores the second one. If
the application needs new symbols that are only available in the second
one, the linker will throw an error because of missing symbols.
To resolve the issue, we should reorder -L flags according to
PKG_CONFIG_PATH ourselves before using it to find the full path of
library files. This makes sure that we always follow the preferences of
users, without depending on the unreliable part of pkg-config output.
mesonbuild/dependencies/ | 40 +++++++++++++++++++++++++++++++++ | 20 +++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/mesonbuild/dependencies/ b/mesonbuild/dependencies/
index 3c55a56b..61485905 100644
--- a/mesonbuild/dependencies/
+++ b/mesonbuild/dependencies/
@@ -784,6 +784,22 @@ class PkgConfigDependency(ExternalDependency):
# Resolve the path as a compiler in the build directory would
path = os.path.join(self.env.get_build_dir(), path)
+ # Library paths are not always ordered in a meaningful way
+ #
+ # Instead of relying on pkg-config or pkgconf to provide -L flags in a
+ # specific order, we reorder library paths ourselves, according to th
+ # order specified in PKG_CONFIG_PATH. See:
+ #
+ #
+ # Only prefix_libpaths are reordered here because there should not be
+ # too many system_libpaths to cause library version issues.
+ pkg_config_path = os.environ.get('PKG_CONFIG_PATH')
+ if pkg_config_path:
+ pkg_config_path = pkg_config_path.split(os.pathsep)
+ else:
+ pkg_config_path = []
+ pkg_config_path = self._convert_mingw_paths(pkg_config_path)
+ prefix_libpaths = sort_libpaths(prefix_libpaths, pkg_config_path)
system_libpaths = OrderedSet()
full_args = self._convert_mingw_paths(self._split_args(out))
for arg in full_args:
@@ -2286,6 +2302,30 @@ def _build_external_dependency_list(name, env: Environment, kwargs: Dict[str, An
return candidates
+def sort_libpaths(libpaths: List[str], refpaths: List[str]) -> List[str]:
+ """Sort <libpaths> according to <refpaths>
+ It is intended to be used to sort -L flags returned by pkg-config.
+ Pkg-config returns flags in random order which cannot be relied on.
+ """
+ if len(refpaths) == 0:
+ return list(libpaths)
+ def key_func(libpath):
+ common_lengths = []
+ for refpath in refpaths:
+ try:
+ common_path = os.path.commonpath([libpath, refpath])
+ except ValueError:
+ common_path = ''
+ common_lengths.append(len(common_path))
+ max_length = max(common_lengths)
+ max_index = common_lengths.index(max_length)
+ reversed_max_length = len(refpaths[max_index]) - max_length
+ return (max_index, reversed_max_length)
+ return sorted(libpaths, key=key_func)
def strip_system_libdirs(environment, for_machine: MachineChoice, link_args):
"""Remove -L<system path> arguments.
diff --git a/ b/
index 29226fa9..17b23ab3 100755
--- a/
+++ b/
@@ -57,6 +57,7 @@ from mesonbuild.mesonlib import (
from mesonbuild.environment import detect_ninja
from mesonbuild.mesonlib import MesonException, EnvironmentException
from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram
+import mesonbuild.dependencies.base
from import Target
import mesonbuild.modules.pkgconfig
@@ -1164,6 +1165,25 @@ class InternalTests(unittest.TestCase):
deps = d.get_all_dependencies(target)
self.assertEqual(deps, expdeps)
+ def test_sort_libpaths(self):
+ sort_libpaths = mesonbuild.dependencies.base.sort_libpaths
+ self.assertEqual(sort_libpaths(
+ ['/home/mesonuser/.local/lib', '/usr/local/lib', '/usr/lib'],
+ ['/home/mesonuser/.local/lib/pkgconfig', '/usr/local/lib/pkgconfig']),
+ ['/home/mesonuser/.local/lib', '/usr/local/lib', '/usr/lib'])
+ self.assertEqual(sort_libpaths(
+ ['/usr/local/lib', '/home/mesonuser/.local/lib', '/usr/lib'],
+ ['/home/mesonuser/.local/lib/pkgconfig', '/usr/local/lib/pkgconfig']),
+ ['/home/mesonuser/.local/lib', '/usr/local/lib', '/usr/lib'])
+ self.assertEqual(sort_libpaths(
+ ['/usr/lib', '/usr/local/lib', '/home/mesonuser/.local/lib'],
+ ['/home/mesonuser/.local/lib/pkgconfig', '/usr/local/lib/pkgconfig']),
+ ['/home/mesonuser/.local/lib', '/usr/local/lib', '/usr/lib'])
+ self.assertEqual(sort_libpaths(
+ ['/usr/lib', '/usr/local/lib', '/home/mesonuser/.local/lib'],
+ ['/home/mesonuser/.local/lib/pkgconfig', '/usr/local/libdata/pkgconfig']),
+ ['/home/mesonuser/.local/lib', '/usr/local/lib', '/usr/lib'])
@unittest.skipIf(is_tarball(), 'Skipping because this is a tarball release')
class DataTests(unittest.TestCase):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment