environment: fallback regex for versions like 2020.01

add four-digit version unit_test cases
pull/7329/head
Michael Hirsch 5 years ago committed by Dylan Baker
parent 4ba06fb4dd
commit 0b9e8e39dd
  1. 10
      mesonbuild/environment.py
  2. 14
      run_unittests.py

@ -347,7 +347,6 @@ def detect_cpu_family(compilers: CompilersDict) -> str:
elif trial in {'ip30', 'ip35'}: elif trial in {'ip30', 'ip35'}:
trial = 'mips64' trial = 'mips64'
# On Linux (and maybe others) there can be any mixture of 32/64 bit code in # On Linux (and maybe others) there can be any mixture of 32/64 bit code in
# the kernel, Python, system, 32-bit chroot on 64-bit host, etc. The only # the kernel, Python, system, 32-bit chroot on 64-bit host, etc. The only
# reliable way to know is to check the compiler defines. # reliable way to know is to check the compiler defines.
@ -443,7 +442,7 @@ def machine_info_can_run(machine_info: MachineInfo):
(machine_info.cpu_family == true_build_cpu_family) or \ (machine_info.cpu_family == true_build_cpu_family) or \
((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86')) ((true_build_cpu_family == 'x86_64') and (machine_info.cpu_family == 'x86'))
def search_version(text): def search_version(text: str) -> str:
# Usually of the type 4.1.4 but compiler output may contain # Usually of the type 4.1.4 but compiler output may contain
# stuff like this: # stuff like this:
# (Sourcery CodeBench Lite 2014.05-29) 4.8.3 20140320 (prerelease) # (Sourcery CodeBench Lite 2014.05-29) 4.8.3 20140320 (prerelease)
@ -477,6 +476,13 @@ def search_version(text):
match = version_regex.search(text) match = version_regex.search(text)
if match: if match:
return match.group(0) return match.group(0)
# try a simpler regex that has like "blah 2020.01.100 foo" or "blah 2020.01 foo"
version_regex = re.compile(r"(\d{1,4}\.\d{1,4}\.?\d{0,4})")
match = version_regex.search(text)
if match:
return match.group(0)
return 'unknown version' return 'unknown version'
class Environment: class Environment:

@ -40,7 +40,7 @@ from contextlib import contextmanager
from glob import glob from glob import glob
from pathlib import (PurePath, Path) from pathlib import (PurePath, Path)
from distutils.dir_util import copy_tree from distutils.dir_util import copy_tree
import typing import typing as T
import mesonbuild.mlog import mesonbuild.mlog
import mesonbuild.depfile import mesonbuild.depfile
@ -312,8 +312,14 @@ class InternalTests(unittest.TestCase):
self.assertEqual(searchfunc('1.2.3'), '1.2.3') self.assertEqual(searchfunc('1.2.3'), '1.2.3')
self.assertEqual(searchfunc('foobar 2016.10.28 1.2.3'), '1.2.3') self.assertEqual(searchfunc('foobar 2016.10.28 1.2.3'), '1.2.3')
self.assertEqual(searchfunc('2016.10.28 1.2.3'), '1.2.3') self.assertEqual(searchfunc('2016.10.28 1.2.3'), '1.2.3')
self.assertEqual(searchfunc('foobar 2016.10.128'), 'unknown version') self.assertEqual(searchfunc('foobar 2016.10.128'), '2016.10.128')
self.assertEqual(searchfunc('2016.10.128'), 'unknown version') self.assertEqual(searchfunc('2016.10.128'), '2016.10.128')
self.assertEqual(searchfunc('2016.10'), '2016.10')
self.assertEqual(searchfunc('2016.10 1.2.3'), '1.2.3')
self.assertEqual(searchfunc('oops v1.2.3'), '1.2.3')
self.assertEqual(searchfunc('2016.oops 1.2.3'), '1.2.3')
self.assertEqual(searchfunc('2016.x'), 'unknown version')
def test_mode_symbolic_to_bits(self): def test_mode_symbolic_to_bits(self):
modefunc = mesonbuild.mesonlib.FileMode.perms_s_to_bits modefunc = mesonbuild.mesonlib.FileMode.perms_s_to_bits
@ -7768,7 +7774,7 @@ class CrossFileTests(BasePlatformTests):
""" """
def _cross_file_generator(self, *, needs_exe_wrapper: bool = False, def _cross_file_generator(self, *, needs_exe_wrapper: bool = False,
exe_wrapper: typing.Optional[typing.List[str]] = None) -> str: exe_wrapper: T.Optional[T.List[str]] = None) -> str:
if is_windows(): if is_windows():
raise unittest.SkipTest('Cannot run this test on non-mingw/non-cygwin windows') raise unittest.SkipTest('Cannot run this test on non-mingw/non-cygwin windows')
if is_sunos(): if is_sunos():

Loading…
Cancel
Save