aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-02-10 06:16:12 -0800
committerEli Schwartz <eschwartz93@gmail.com>2023-02-13 13:30:06 -0500
commit4d7a72b6db181f09034051ef703e151607784ea8 (patch)
tree5938ceae985bfeb83da9123b9494eb69a081eeef
parentce62190b17e136c5b6810d3360b2cd71d0756920 (diff)
downloadmeson-4d7a72b6db181f09034051ef703e151607784ea8.zip
meson-4d7a72b6db181f09034051ef703e151607784ea8.tar.gz
meson-4d7a72b6db181f09034051ef703e151607784ea8.tar.bz2
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
-rw-r--r--mesonbuild/cmake/executor.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/mesonbuild/cmake/executor.py b/mesonbuild/cmake/executor.py
index 7482f54..c22c0ca 100644
--- a/mesonbuild/cmake/executor.py
+++ b/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: