aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/mesonlib.py
diff options
context:
space:
mode:
authorJon Turney <jon.turney@dronecode.org.uk>2018-10-06 14:57:07 +0100
committerJussi Pakkanen <jpakkane@gmail.com>2018-10-10 19:43:24 +0300
commita0a0c244e2a062ceba357f05d4852cd063f0b0cd (patch)
tree06ada5034b0d0aadc874f0e24b253286e6dbb635 /mesonbuild/mesonlib.py
parente9ba04537fa4e3e6215d89b363f98945dd62e389 (diff)
downloadmeson-a0a0c244e2a062ceba357f05d4852cd063f0b0cd.zip
meson-a0a0c244e2a062ceba357f05d4852cd063f0b0cd.tar.gz
meson-a0a0c244e2a062ceba357f05d4852cd063f0b0cd.tar.bz2
os.path.relpath() can fail on Windows
If builddir and sourcedir have different drive letters, a relative path doesn't exist, and os.path.relpath fails with a ValueError exception. This just fixes the places which are hit by test cases in a simple-minded way. There are several other uses of os.path.relpath(), which might be suspect.
Diffstat (limited to 'mesonbuild/mesonlib.py')
-rw-r--r--mesonbuild/mesonlib.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 33900b6..dfd4687 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -1143,3 +1143,12 @@ class BuildDirLock:
elif have_msvcrt:
msvcrt.locking(self.lockfile.fileno(), msvcrt.LK_UNLCK, 1)
self.lockfile.close()
+
+def relpath(path, start):
+ # On Windows a relative path can't be evaluated for paths on two different
+ # drives (i.e. c:\foo and f:\bar). The only thing left to do is to use the
+ # original absolute path.
+ try:
+ return os.path.relpath(path, start)
+ except ValueError:
+ return path