aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2017-10-06 11:48:08 -0700
committerDylan Baker <dylan@pnwbakers.com>2017-10-21 10:36:00 -0700
commit4e394b3341b2d30294a14b96b7e528b441b675a5 (patch)
tree4b1ed78ac1a9f0b0a560a6079d556b824fe68635 /mesonbuild
parent6ce42e2ec51a9f9b48b6d00303bf5dfc1596498e (diff)
downloadmeson-4e394b3341b2d30294a14b96b7e528b441b675a5.zip
meson-4e394b3341b2d30294a14b96b7e528b441b675a5.tar.gz
meson-4e394b3341b2d30294a14b96b7e528b441b675a5.tar.bz2
dependencies: Add function to strip system -L paths
PkgConfig automatically removes -L paths from libdirs if the -L points to a system path. It knows what these paths are by taking this as a configure option at build time, which the distro maintainers set appropriately and everything works. This allows one to have two versions of a package installed, a system and non system, and then override PKG_CONFIG_PATH to use the non system version, and everything just works. For non-pkgconfig dependencies (such as LLVM) meson needs to strip these themselves to avoid breaking the above use case.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/dependencies/base.py11
-rw-r--r--mesonbuild/environment.py18
2 files changed, 29 insertions, 0 deletions
diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py
index 0d9742d..9913a0b 100644
--- a/mesonbuild/dependencies/base.py
+++ b/mesonbuild/dependencies/base.py
@@ -640,3 +640,14 @@ def find_external_dependency(name, env, kwargs):
raise pkg_exc
mlog.log('Dependency', mlog.bold(name), 'found:', mlog.red('NO'))
return pkgdep
+
+
+def strip_system_libdirs(environment, link_args):
+ """Remove -L<system path> arguments.
+
+ leaving these in will break builds where a user has a version of a library
+ in the system path, and a different version not in the system path if they
+ want to link against the non-system path version.
+ """
+ exclude = {'-L{}'.format(p) for p in environment.get_compiler_system_dirs()}
+ return [l for l in link_args if l not in exclude]
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 2f33a03..a746cab 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -887,6 +887,24 @@ class Environment:
def get_datadir(self):
return self.coredata.get_builtin_option('datadir')
+ def get_compiler_system_dirs(self):
+ for comp in self.coredata.compilers.values():
+ if isinstance(comp, compilers.ClangCompiler):
+ index = 1
+ break
+ elif isinstance(comp, compilers.GnuCompiler):
+ index = 2
+ break
+ else:
+ # This option is only supported by gcc and clang. If we don't get a
+ # GCC or Clang compiler return and empty list.
+ return []
+
+ p, out, _ = Popen_safe(comp.get_exelist() + ['-print-search-dirs'])
+ if p.returncode != 0:
+ raise mesonlib.MesonException('Could not calculate system search dirs')
+ out = out.split('\n')[index].lstrip('libraries: =').split(':')
+ return [os.path.normpath(p) for p in out]
def get_args_from_envvars(compiler):
"""