meson/meson-restore-python3.4.patch

120 lines
5.3 KiB
Diff

--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -26,7 +26,7 @@ from .. import compilers
from ..compilers import CompilerArgs
from ..linkers import ArLinker
from ..mesonlib import File, MesonException, OrderedSet
-from ..mesonlib import get_compiler_for_source
+from ..mesonlib import get_compiler_for_source, commonpath
from .backends import CleanTrees, InstallData
from ..build import InvalidArguments
@@ -1166,8 +1166,8 @@ int dummy;
# Check if the vala file is in a subdir of --basedir
abs_srcbasedir = os.path.join(self.environment.get_source_dir(), target.get_subdir())
abs_vala_file = os.path.join(self.environment.get_build_dir(), vala_file)
- if PurePath(os.path.commonpath((abs_srcbasedir, abs_vala_file))) == PurePath(abs_srcbasedir):
- vala_c_subdir = PurePath(abs_vala_file).parent.relative_to(abs_srcbasedir)
+ if PurePath(commonpath((abs_srcbasedir, abs_vala_file))) == PurePath(abs_srcbasedir):
+ vala_c_subdir = str(PurePath(abs_vala_file).parent.relative_to(abs_srcbasedir))
vala_c_file = os.path.join(vala_c_subdir, vala_c_file)
else:
path_to_target = os.path.join(self.build_to_src, target.get_subdir())
--- a/mesonbuild/coredata.py
+++ b/mesonbuild/coredata.py
@@ -17,7 +17,7 @@ import pickle, os, uuid
import sys
from pathlib import PurePath
from collections import OrderedDict
-from .mesonlib import MesonException
+from .mesonlib import MesonException, commonpath
from .mesonlib import default_libdir, default_libexecdir, default_prefix
import ast
@@ -286,7 +286,7 @@ class CoreData:
# commonpath will always return a path in the native format, so we
# must use pathlib.PurePath to do the same conversion before
# comparing.
- if os.path.commonpath([value, prefix]) != str(PurePath(prefix)):
+ if commonpath([value, prefix]) != str(PurePath(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.'
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -935,6 +935,32 @@ def detect_subprojects(spdir_name, curre
result[basename] = [trial]
return result
+def commonpath(paths):
+ '''
+ For use on Python 3.4 where os.path.commonpath is not available.
+ '''
+ if sys.version_info >= (3, 5):
+ return os.path.commonpath(paths)
+
+ import pathlib
+ if not paths:
+ raise ValueError('commonpath() 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)
+
class OrderedSet(collections.MutableSet):
"""A set that preserves the order in which items are added, by first
insertion.
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -274,8 +274,8 @@ def run_script_command(args):
return cmdfunc(cmdargs)
def run(original_args, mainfile=None):
- if sys.version_info < (3, 5):
- print('Meson works correctly only with python 3.5+.')
+ if sys.version_info < (3, 4):
+ print('Meson works correctly only with python 3.4+.')
print('You have python %s.' % sys.version)
print('Please update your environment')
return 1
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -427,6 +427,26 @@ class InternalTests(unittest.TestCase):
kwargs = {'sources': [1, 2, 3], 'pch_sources': [4, 5, 6]}
self.assertEqual([[1, 2, 3], [4, 5, 6]], extract(kwargs, 'sources', 'pch_sources'))
+ def test_commonpath(self):
+ from os.path import sep
+ commonpath = mesonbuild.mesonlib.commonpath
+ self.assertRaises(ValueError, commonpath, [])
+ self.assertEqual(commonpath(['/usr', '/usr']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr', '/usr/']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr', '/usr/bin']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr/', '/usr/bin']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr/./', '/usr/bin']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr/bin', '/usr/bin']), sep + 'usr' + sep + 'bin')
+ self.assertEqual(commonpath(['/usr//bin', '/usr/bin']), sep + 'usr' + sep + 'bin')
+ self.assertEqual(commonpath(['/usr/./bin', '/usr/bin']), sep + 'usr' + sep + 'bin')
+ self.assertEqual(commonpath(['/usr/local', '/usr/lib']), sep + 'usr')
+ self.assertEqual(commonpath(['/usr', '/bin']), sep)
+ self.assertEqual(commonpath(['/usr', 'bin']), '')
+ self.assertEqual(commonpath(['blam', 'bin']), '')
+ prefix = '/some/path/to/prefix'
+ libdir = '/some/path/to/prefix/libdir'
+ self.assertEqual(commonpath([prefix, libdir]), str(PurePath(prefix)))
+
class BasePlatformTests(unittest.TestCase):
def setUp(self):