diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-07 17:57:47 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2021-05-07 17:57:47 +0300 |
commit | 5bfde4ee72e5ef4f59d97947f195189e1c3ed8ff (patch) | |
tree | f0d05048673645588b093bd1f611b764e1af45b8 /project/utils.py | |
parent | project.toolset: support versioned MSVC toolsets (diff) | |
download | cmake-common-5bfde4ee72e5ef4f59d97947f195189e1c3ed8ff.tar.gz cmake-common-5bfde4ee72e5ef4f59d97947f195189e1c3ed8ff.zip |
project.toolset: move _full_exe_name to utils
Diffstat (limited to 'project/utils.py')
-rw-r--r-- | project/utils.py | 30 |
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( |