Lines 52-82
users, without depending on the unreliable part of pkg-config output.
Link Here
|
52 |
|
52 |
|
53 |
Fixes https://github.com/mesonbuild/meson/issues/4271. |
53 |
Fixes https://github.com/mesonbuild/meson/issues/4271. |
54 |
|
54 |
|
55 |
--- mesonbuild/dependencies/base.py.orig |
55 |
--- mesonbuild/dependencies/base.py.orig 2019-10-06 17:01:35 UTC |
56 |
+++ mesonbuild/dependencies/base.py |
56 |
+++ mesonbuild/dependencies/base.py |
57 |
@@ -706,6 +706,21 @@ def _set_cargs(self): |
57 |
@@ -784,6 +784,22 @@ class PkgConfigDependency(ExternalDependency): |
58 |
(self.name, out)) |
|
|
59 |
self.compile_args = self._convert_mingw_paths(shlex.split(out)) |
60 |
|
61 |
+ def _sort_libpaths(self, libpaths, refpaths): |
62 |
+ if len(refpaths) == 0: |
63 |
+ return list(libpaths) |
64 |
+ |
65 |
+ def key_func(libpath): |
66 |
+ common_lengths = [] |
67 |
+ for refpath in refpaths: |
68 |
+ common_path = os.path.commonpath([libpath, refpath]) |
69 |
+ common_lengths.append(len(common_path)) |
70 |
+ max_length = max(common_lengths) |
71 |
+ max_index = common_lengths.index(max_length) |
72 |
+ reversed_max_length = len(refpaths[max_index]) - max_length |
73 |
+ return (max_index, reversed_max_length) |
74 |
+ return sorted(libpaths, key=key_func) |
75 |
+ |
76 |
def _search_libs(self, out, out_raw): |
77 |
''' |
78 |
@out: PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 pkg-config --libs |
79 |
@@ -741,6 +756,22 @@ def _search_libs(self, out, out_raw): |
80 |
# Resolve the path as a compiler in the build directory would |
58 |
# Resolve the path as a compiler in the build directory would |
81 |
path = os.path.join(self.env.get_build_dir(), path) |
59 |
path = os.path.join(self.env.get_build_dir(), path) |
82 |
prefix_libpaths.add(path) |
60 |
prefix_libpaths.add(path) |
Lines 95-101
Fixes https://github.com/mesonbuild/meson/issues/4271.
Link Here
|
95 |
+ else: |
73 |
+ else: |
96 |
+ pkg_config_path = [] |
74 |
+ pkg_config_path = [] |
97 |
+ pkg_config_path = self._convert_mingw_paths(pkg_config_path) |
75 |
+ pkg_config_path = self._convert_mingw_paths(pkg_config_path) |
98 |
+ prefix_libpaths = self._sort_libpaths(prefix_libpaths, pkg_config_path) |
76 |
+ prefix_libpaths = sort_libpaths(prefix_libpaths, pkg_config_path) |
99 |
system_libpaths = OrderedSet() |
77 |
system_libpaths = OrderedSet() |
100 |
full_args = self._convert_mingw_paths(shlex.split(out)) |
78 |
full_args = self._convert_mingw_paths(self._split_args(out)) |
101 |
for arg in full_args: |
79 |
for arg in full_args: |
|
|
80 |
@@ -2284,6 +2300,30 @@ def _build_external_dependency_list(name, env: Environ |
81 |
False, None, env, None, kwargs)) |
82 |
|
83 |
return candidates |
84 |
+ |
85 |
+ |
86 |
+def sort_libpaths(libpaths: List[str], refpaths: List[str]) -> List[str]: |
87 |
+ """Sort <libpaths> according to <refpaths> |
88 |
+ |
89 |
+ It is intended to be used to sort -L flags returned by pkg-config. |
90 |
+ Pkg-config returns flags in random order which cannot be relied on. |
91 |
+ """ |
92 |
+ if len(refpaths) == 0: |
93 |
+ return list(libpaths) |
94 |
+ |
95 |
+ def key_func(libpath): |
96 |
+ common_lengths = [] |
97 |
+ for refpath in refpaths: |
98 |
+ try: |
99 |
+ common_path = os.path.commonpath([libpath, refpath]) |
100 |
+ except ValueError: |
101 |
+ common_path = '' |
102 |
+ common_lengths.append(len(common_path)) |
103 |
+ max_length = max(common_lengths) |
104 |
+ max_index = common_lengths.index(max_length) |
105 |
+ reversed_max_length = len(refpaths[max_index]) - max_length |
106 |
+ return (max_index, reversed_max_length) |
107 |
+ return sorted(libpaths, key=key_func) |
108 |
|
109 |
|
110 |
def strip_system_libdirs(environment, for_machine: MachineChoice, link_args): |