cmake: check that `re.search` returned a non-None value

If an re call fails to find a match it returns None. We're not checking
that, and crashing.

Fixes: #11376
pull/11391/head
Dylan Baker 2 years ago committed by Eli Schwartz
parent ce62190b17
commit 4d7a72b6db
  1. 18
      mesonbuild/cmake/executor.py

@ -108,23 +108,29 @@ class CMakeExecutor:
mlog.log(f'Did not find CMake {cmakebin.name!r}')
return None
try:
p, out = Popen_safe(cmakebin.get_command() + ['--version'])[0:2]
cmd = cmakebin.get_command()
p, out = Popen_safe(cmd + ['--version'])[0:2]
if p.returncode != 0:
mlog.warning('Found CMake {!r} but couldn\'t run it'
''.format(' '.join(cmakebin.get_command())))
''.format(' '.join(cmd)))
return None
except FileNotFoundError:
mlog.warning('We thought we found CMake {!r} but now it\'s not there. How odd!'
''.format(' '.join(cmakebin.get_command())))
''.format(' '.join(cmd)))
return None
except PermissionError:
msg = 'Found CMake {!r} but didn\'t have permissions to run it.'.format(' '.join(cmakebin.get_command()))
msg = 'Found CMake {!r} but didn\'t have permissions to run it.'.format(' '.join(cmd))
if not is_windows():
msg += '\n\nOn Unix-like systems this is often caused by scripts that are not executable.'
mlog.warning(msg)
return None
cmvers = re.search(r'(cmake|cmake3)\s*version\s*([\d.]+)', out).group(2)
return cmvers
cmvers = re.search(r'(cmake|cmake3)\s*version\s*([\d.]+)', out)
if cmvers is not None:
return cmvers.group(2)
mlog.warning(f'We thought we found CMake {cmd!r}, but it was missing the expected '
'version string in its output.')
return None
def set_exec_mode(self, print_cmout: T.Optional[bool] = None, always_capture_stderr: T.Optional[bool] = None) -> None:
if print_cmout is not None:

Loading…
Cancel
Save