aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/project/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'project/utils.py')
-rw-r--r--project/utils.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/project/utils.py b/project/utils.py
index 711db97..39dfb0d 100644
--- a/project/utils.py
+++ b/project/utils.py
@@ -7,11 +7,14 @@ from contextlib import contextmanager
import functools
import logging
import os.path
+import shutil
import subprocess
import sys
import tempfile
import time
+from project.os import on_cygwin, on_linux
+
def normalize_path(s):
return os.path.abspath(os.path.normpath(s))
@@ -21,6 +24,33 @@ def mkdir_parent(path):
os.makedirs(path, exist_ok=True)
+def full_exe_name(exe):
+ if on_linux():
+ # There's no PATHEXT on Linux.
+ return exe
+ # b2 on Windows/Cygwin doesn't like it when the executable name doesn't
+ # include the extension.
+ dir_path = os.path.dirname(exe) or None
+ path = shutil.which(exe, path=dir_path)
+ if not path:
+ raise RuntimeError(f"executable '{exe}' could not be found")
+ if on_cygwin():
+ # On Cygwin, shutil.which('gcc') == '/usr/bin/gcc' and shutil.which('gcc.exe')
+ # == '/usr/bin/gcc.exe'; we want the latter version. shutil.which('clang++')
+ # == '/usr/bin/clang++' is fine though, since it _is_ the complete path
+ # (clang++ is a symlink).
+ if os.path.exists(path) and os.path.exists(path + '.exe'):
+ path += '.exe'
+ if dir_path:
+ # If it was found in a specific directory, include the directory in the
+ # result. shutil.which returns the executable name prefixed with the
+ # path argument.
+ return path
+ # If it was found in PATH, just return the basename (which includes the
+ # extension).
+ return os.path.basename(path)
+
+
@contextmanager
def setup_logging():
logging.basicConfig(