diff options
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/coredata.py | 5 | ||||
-rw-r--r-- | mesonbuild/mesonlib.py | 25 |
2 files changed, 28 insertions, 2 deletions
diff --git a/mesonbuild/coredata.py b/mesonbuild/coredata.py index 1ec769a..2dd2f2a 100644 --- a/mesonbuild/coredata.py +++ b/mesonbuild/coredata.py @@ -13,7 +13,8 @@ # limitations under the License. import pickle, os, uuid -from .mesonlib import MesonException, default_libdir, default_libexecdir, default_prefix +from .mesonlib import MesonException, commonpath +from .mesonlib import default_libdir, default_libexecdir, default_prefix version = '0.38.0.dev1' backendlist = ['ninja', 'vs2010', 'vs2015', 'xcode'] @@ -158,7 +159,7 @@ class CoreData: if option.endswith('dir') and os.path.isabs(value) and \ option not in builtin_dir_noprefix_options: # Value must be a subdir of the prefix - if os.path.commonpath([value, prefix]) != prefix: + if commonpath([value, prefix]) != prefix: m = 'The value of the {!r} option is {!r} which must be a ' \ 'subdir of the prefix {!r}.\nNote that if you pass a ' \ 'relative path, it is assumed to be a subdir of prefix.' diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py index 2ad43c8..f0b20e1 100644 --- a/mesonbuild/mesonlib.py +++ b/mesonbuild/mesonlib.py @@ -496,3 +496,28 @@ def Popen_safe(args, write=None, stderr=subprocess.PIPE, **kwargs): stderr=stderr, **kwargs) o, e = p.communicate(write) return p, o, e + +def commonpath(paths): + ''' + For use on Python 3.4 where os.path.commonpath is not available. + We currently use it everywhere so this receives enough testing. + ''' + # XXX: Replace me with os.path.commonpath when we start requiring Python 3.5 + import pathlib + if not paths: + raise ValueError('arg is an empty sequence') + common = pathlib.PurePath(paths[0]) + for path in paths[1:]: + new = [] + path = pathlib.PurePath(path) + for c, p in zip(common.parts, path.parts): + if c != p: + break + new.append(c) + # Don't convert '' into '.' + if not new: + common = '' + break + new = os.path.join(*new) + common = pathlib.PurePath(new) + return str(common) |