aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2018-12-09 09:30:54 +0100
committerXavier Claessens <xclaesse@gmail.com>2018-12-12 10:42:32 -0500
commit261ab9b2140005d4f7e42118ccb6598fa5b7f15d (patch)
tree67f3113b526ed2eb271e6de7d9e3f74f647b254a
parentf0ee06bdab658eb021b911ccffaad2ad31d3e900 (diff)
downloadmeson-261ab9b2140005d4f7e42118ccb6598fa5b7f15d.zip
meson-261ab9b2140005d4f7e42118ccb6598fa5b7f15d.tar.gz
meson-261ab9b2140005d4f7e42118ccb6598fa5b7f15d.tar.bz2
pkgconfig: Fix link order of library dependencies
Since `_process_libs` appends the lib's dependencies this list already, the final return value of `_process_libs` will end up after its dependencies, which is the wrong way around. (The lib must come first, then its dependencies) The easiest solution is to simply pre-pend the return value of `_process_libs` rather than appending it, so that its dependencies come after the library itself. Closes #4091.
-rw-r--r--mesonbuild/modules/pkgconfig.py4
-rwxr-xr-xrun_unittests.py13
-rw-r--r--test cases/unit/50 pkgconfig static link order/meson.build11
3 files changed, 26 insertions, 2 deletions
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
index eee3783..47edeee 100644
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -35,13 +35,13 @@ class DependenciesHelper:
def add_pub_libs(self, libs):
libs, reqs, cflags = self._process_libs(libs, True)
- self.pub_libs += libs
+ self.pub_libs = libs + self.pub_libs # prepend to preserve dependencies
self.pub_reqs += reqs
self.cflags += cflags
def add_priv_libs(self, libs):
libs, reqs, _ = self._process_libs(libs, False)
- self.priv_libs += libs
+ self.priv_libs = libs + self.priv_libs
self.priv_reqs += reqs
def add_pub_reqs(self, reqs):
diff --git a/run_unittests.py b/run_unittests.py
index f1b2249..a47f74e 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -4274,6 +4274,19 @@ endian = 'little'
self.assertEqual("-r/usr/lib/libsomething.dll", str(stdo.decode('ascii')).strip())
+ @skipIfNoPkgconfig
+ def test_pkgconfig_link_order(self):
+ '''
+ Test that libraries are listed before their dependencies.
+ '''
+ testdir = os.path.join(self.unit_test_dir, '50 pkgconfig static link order')
+ self.init(testdir)
+ myenv = os.environ.copy()
+ myenv['PKG_CONFIG_PATH'] = self.privatedir
+ stdo = subprocess.check_output(['pkg-config', '--libs', 'libsomething'], env=myenv)
+ deps = stdo.split()
+ self.assertTrue(deps.index(b'-lsomething') < deps.index(b'-ldependency'))
+
def test_deterministic_dep_order(self):
'''
Test that the dependencies are always listed in a deterministic order.
diff --git a/test cases/unit/50 pkgconfig static link order/meson.build b/test cases/unit/50 pkgconfig static link order/meson.build
new file mode 100644
index 0000000..b61de9a
--- /dev/null
+++ b/test cases/unit/50 pkgconfig static link order/meson.build
@@ -0,0 +1,11 @@
+project('link order test', 'c')
+
+dep = library('dependency', [])
+lib = static_library('something', [], link_with: dep)
+
+import('pkgconfig').generate(
+ name: 'libsomething',
+ description: 'test library',
+ libraries: lib,
+ version: '1'
+)