diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2018-10-06 14:57:07 +0100 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2018-10-10 19:43:24 +0300 |
commit | a0a0c244e2a062ceba357f05d4852cd063f0b0cd (patch) | |
tree | 06ada5034b0d0aadc874f0e24b253286e6dbb635 /mesonbuild/interpreter.py | |
parent | e9ba04537fa4e3e6215d89b363f98945dd62e389 (diff) | |
download | meson-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/interpreter.py')
-rw-r--r-- | mesonbuild/interpreter.py | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 9a41fab..9b3fdc7 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -1540,8 +1540,8 @@ class ModuleHolder(InterpreterObject, ObjectHolder): # because the Build object contains dicts and lists. num_targets = len(self.interpreter.build.targets) state = ModuleState( - build_to_src=os.path.relpath(self.interpreter.environment.get_source_dir(), - self.interpreter.environment.get_build_dir()), + build_to_src=mesonlib.relpath(self.interpreter.environment.get_source_dir(), + self.interpreter.environment.get_build_dir()), subproject=self.interpreter.subproject, subdir=self.interpreter.subdir, current_lineno=self.interpreter.current_lineno, @@ -2182,14 +2182,7 @@ external dependencies (including libraries) must go to "dependencies".''') raise InterpreterException('Program or command {!r} not found ' 'or not executable'.format(cmd)) cmd = prog - try: - cmd_path = os.path.relpath(cmd.get_path(), start=srcdir) - except ValueError: - # 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 is is to use the original absolute - # path. - cmd_path = cmd.get_path() + cmd_path = mesonlib.relpath(cmd.get_path(), start=srcdir) if not cmd_path.startswith('..') and cmd_path not in self.build_def_files: self.build_def_files.append(cmd_path) expanded_args = [] @@ -2206,7 +2199,7 @@ external dependencies (including libraries) must go to "dependencies".''') if not os.path.isabs(a): a = os.path.join(builddir if in_builddir else srcdir, self.subdir, a) if os.path.isfile(a): - a = os.path.relpath(a, start=srcdir) + a = mesonlib.relpath(a, start=srcdir) if not a.startswith('..'): if a not in self.build_def_files: self.build_def_files.append(a) |