aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/clike.py
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2019-05-15 08:33:21 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2019-05-16 23:05:49 +0300
commit7ce9e56a4b7186d672611c43393e777bb3c479fc (patch)
tree215781b5ce78ecb34f3403ed47d8512202321ab7 /mesonbuild/compilers/clike.py
parent61750494f5ce7bd50d6856c36537cb7e8f5a7921 (diff)
downloadmeson-7ce9e56a4b7186d672611c43393e777bb3c479fc.zip
meson-7ce9e56a4b7186d672611c43393e777bb3c479fc.tar.gz
meson-7ce9e56a4b7186d672611c43393e777bb3c479fc.tar.bz2
Fix path splitting in get_compiler_dirs() with GCC/clang on Windows
It was using ':' as a path separator while GCC uses ';' resulting in bogus paths being returned. Instead assume that the compiler uses the platform native separator. The previous splitting code still worked sometimes because splitting "C:/foo;C:/bar" resulted in the last part "/bar" being valid if "<DriveOfCWD>:/bar" existed. The fix also exposes a clang Windows bug where it uses the wrong separator: https://reviews.llvm.org/D61121 . Use a regex to fix those first. This resulted in linker errors when statically linking against a library which had an external dependency linking against system libs. Fixes #5386
Diffstat (limited to 'mesonbuild/compilers/clike.py')
-rw-r--r--mesonbuild/compilers/clike.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/mesonbuild/compilers/clike.py b/mesonbuild/compilers/clike.py
index 3d29b75..3665f1f 100644
--- a/mesonbuild/compilers/clike.py
+++ b/mesonbuild/compilers/clike.py
@@ -170,10 +170,22 @@ class CLikeCompiler:
stdo = p.stdo
return stdo
- @staticmethod
- def _split_fetch_real_dirs(pathstr, sep=':'):
- paths = []
- for p in pathstr.split(sep):
+ def _split_fetch_real_dirs(self, pathstr):
+ # We need to use the path separator used by the compiler for printing
+ # lists of paths ("gcc --print-search-dirs"). By default
+ # we assume it uses the platform native separator.
+ pathsep = os.pathsep
+
+ # clang uses ':' instead of ';' on Windows https://reviews.llvm.org/D61121
+ # so we need to repair things like 'C:\foo:C:\bar'
+ if pathsep == ';':
+ pathstr = re.sub(r':([^/\\])', r';\1', pathstr)
+
+ # pathlib treats empty paths as '.', so filter those out
+ paths = [p for p in pathstr.split(pathsep) if p]
+
+ result = []
+ for p in paths:
# GCC returns paths like this:
# /usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/lib
# It would make sense to normalize them to get rid of the .. parts
@@ -185,15 +197,15 @@ class CLikeCompiler:
pobj = Path(p)
unresolved = pobj.as_posix()
if pobj.exists():
- if unresolved not in paths:
- paths.append(unresolved)
+ if unresolved not in result:
+ result.append(unresolved)
try:
resolved = Path(p).resolve().as_posix()
- if resolved not in paths:
- paths.append(resolved)
+ if resolved not in result:
+ result.append(resolved)
except FileNotFoundError:
pass
- return tuple(paths)
+ return tuple(result)
def get_compiler_dirs(self, env, name):
'''