[Lldb-commits] [PATCH] D124604: [lldb] Use shutil.which in Shell tests find_executable
David Spickett via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 29 03:01:32 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG713752610edd: [lldb] Use shutil.which in Shell tests find_executable (authored by DavidSpickett).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D124604/new/
https://reviews.llvm.org/D124604
Files:
lldb/test/Shell/helper/build.py
Index: lldb/test/Shell/helper/build.py
===================================================================
--- lldb/test/Shell/helper/build.py
+++ lldb/test/Shell/helper/build.py
@@ -4,6 +4,7 @@
import argparse
import os
+import shutil
import signal
import subprocess
import sys
@@ -170,16 +171,14 @@
print(' {0} = {1}'.format(e, formatted_value))
def find_executable(binary_name, search_paths):
- if sys.platform == 'win32':
- binary_name = binary_name + '.exe'
-
- search_paths = os.pathsep.join(search_paths)
- paths = search_paths + os.pathsep + os.environ.get('PATH', '')
- for path in paths.split(os.pathsep):
- p = os.path.join(path, binary_name)
- if os.path.exists(p) and not os.path.isdir(p):
- return os.path.normpath(p)
- return None
+ # shutil.which will ignore PATH if given a path argument, we want to include it.
+ search_paths.append(os.environ.get('PATH', ''))
+ search_path = os.pathsep.join(search_paths)
+ binary_path = shutil.which(binary_name, path=search_path)
+ if binary_path is not None:
+ # So for example, we get '/bin/gcc' instead of '/usr/../bin/gcc'.
+ binary_path = os.path.normpath(binary_path)
+ return binary_path
def find_toolchain(compiler, tools_dir):
if compiler == 'msvc':
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124604.426007.patch
Type: text/x-patch
Size: 1323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220429/dd75dc46/attachment-0001.bin>
More information about the lldb-commits
mailing list