diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 4feb44cfd..c02376ee2 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -347,7 +347,6 @@ def detect_cpu_family(compilers: CompilersDict) -> str: elif trial in {'ip30', 'ip35'}: trial = 'mips64' - # 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 # 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 \ ((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 # stuff like this: # (Sourcery CodeBench Lite 2014.05-29) 4.8.3 20140320 (prerelease) @@ -477,6 +476,13 @@ def search_version(text): match = version_regex.search(text) if match: 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' class Environment: diff --git a/run_unittests.py b/run_unittests.py index 170df88b3..41ae710d4 100755 --- a/run_unittests.py +++ b/run_unittests.py @@ -40,7 +40,7 @@ from contextlib import contextmanager from glob import glob from pathlib import (PurePath, Path) from distutils.dir_util import copy_tree -import typing +import typing as T import mesonbuild.mlog import mesonbuild.depfile @@ -312,8 +312,14 @@ class InternalTests(unittest.TestCase): 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('2016.10.28 1.2.3'), '1.2.3') - self.assertEqual(searchfunc('foobar 2016.10.128'), 'unknown version') - self.assertEqual(searchfunc('2016.10.128'), 'unknown version') + self.assertEqual(searchfunc('foobar 2016.10.128'), '2016.10.128') + 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): 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, - exe_wrapper: typing.Optional[typing.List[str]] = None) -> str: + exe_wrapper: T.Optional[T.List[str]] = None) -> str: if is_windows(): raise unittest.SkipTest('Cannot run this test on non-mingw/non-cygwin windows') if is_sunos():