summaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorMads Andreasen <github@andreasen.cc>2024-04-07 16:12:50 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2024-07-10 21:47:46 +0300
commit50704bced3775e9bc5b34f4295e282bfac7253f0 (patch)
tree01a0c0294f1f58e4efffee0c7e5abad35c638c6e /mesonbuild
parentf01ae52bc224e46661e0ee4404c949e4e27773a8 (diff)
downloadmeson-50704bced3775e9bc5b34f4295e282bfac7253f0.tar.gz
Replace exe_exists function with shutil.which()
The documentation for subprocess.run at https://docs.python.org/3/library/subprocess.html#popen-constructor has a warning, pointing to using shutil.which() instead of subprocess.run for detecting if exe files exists on the path. shutil.which() is used in many places already.
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/environment.py6
-rw-r--r--mesonbuild/scripts/coverage.py4
-rw-r--r--mesonbuild/utils/universal.py11
3 files changed, 7 insertions, 14 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index be40dbcfd..63499676d 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -109,13 +109,13 @@ def detect_llvm_cov(suffix: T.Optional[str] = None):
tool = 'llvm-cov'
else:
tool = f'llvm-cov-{suffix}'
- if mesonlib.exe_exists([tool, '--version']):
+ if shutil.which(tool) is not None:
return tool
else:
# Otherwise guess in the dark
tools = get_llvm_tool_names('llvm-cov')
for tool in tools:
- if mesonlib.exe_exists([tool, '--version']):
+ if shutil.which(tool):
return tool
return None
@@ -139,7 +139,7 @@ def compute_llvm_suffix(coredata: coredata.CoreData):
def detect_lcov_genhtml(lcov_exe: str = 'lcov', genhtml_exe: str = 'genhtml'):
lcov_exe, lcov_version = detect_lcov(lcov_exe)
- if not mesonlib.exe_exists([genhtml_exe, '--version']):
+ if shutil.which(genhtml_exe) is None:
genhtml_exe = None
return lcov_exe, lcov_version, genhtml_exe
diff --git a/mesonbuild/scripts/coverage.py b/mesonbuild/scripts/coverage.py
index 17a4a10ae..f01946944 100644
--- a/mesonbuild/scripts/coverage.py
+++ b/mesonbuild/scripts/coverage.py
@@ -5,7 +5,7 @@ from __future__ import annotations
from mesonbuild import environment, mesonlib
-import argparse, re, sys, os, subprocess, pathlib, stat
+import argparse, re, sys, os, subprocess, pathlib, stat, shutil
import typing as T
def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build_root: str, log_dir: str, use_llvm_cov: bool,
@@ -17,7 +17,7 @@ def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build
gcovr_exe = None
else:
gcovr_exe, gcovr_version = environment.detect_gcovr(gcovr_exe)
- if llvm_cov_exe == '' or not mesonlib.exe_exists([llvm_cov_exe, '--version']):
+ if llvm_cov_exe == '' or shutil.which(llvm_cov_exe) is None:
llvm_cov_exe = None
lcov_exe, lcov_version, genhtml_exe = environment.detect_lcov_genhtml()
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index 4f18ec11b..21173f5df 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -98,7 +98,6 @@ __all__ = [
'do_conf_file',
'do_conf_str',
'do_replacement',
- 'exe_exists',
'expand_arguments',
'extract_as_list',
'first',
@@ -683,14 +682,8 @@ def is_qnx() -> bool:
def is_aix() -> bool:
return platform.system().lower() == 'aix'
-def exe_exists(arglist: T.List[str]) -> bool:
- try:
- if subprocess.run(arglist, timeout=10).returncode == 0:
- return True
- except (FileNotFoundError, subprocess.TimeoutExpired):
- pass
- return False
-
+def exe_exists(exe: str) -> bool:
+ return shutil.which(exe) is not None
@lru_cache(maxsize=None)
def darwin_get_object_archs(objpath: str) -> 'ImmutableListProtocol[str]':