aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-02-10 06:16:12 -0800
committerNirbheek Chauhan <nirbheek@centricular.com>2023-02-19 02:55:58 +0530
commit42cbc5d0344394267f8104abd9971fd9bcf98a80 (patch)
tree6df1d6789d00e7c447c7883d04868e9dda5ca3b6
parentaf1fbf5b62d89f7ed2e169ae1c602cbf2eb98487 (diff)
downloadmeson-42cbc5d0344394267f8104abd9971fd9bcf98a80.zip
meson-42cbc5d0344394267f8104abd9971fd9bcf98a80.tar.gz
meson-42cbc5d0344394267f8104abd9971fd9bcf98a80.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: