summaryrefslogtreecommitdiff
path: root/mesonbuild/utils
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/utils
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/utils')
-rw-r--r--mesonbuild/utils/universal.py11
1 files changed, 2 insertions, 9 deletions
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]':