[Lldb-commits] [lldb] cacaa44 - Reland "[lldb] Use shutil.which in Shell tests find_executable"
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 29 04:25:19 PDT 2022
Author: David Spickett
Date: 2022-04-29T11:25:09Z
New Revision: cacaa445c3a3a2551a6e2aef51414e47def9cc06
URL: https://github.com/llvm/llvm-project/commit/cacaa445c3a3a2551a6e2aef51414e47def9cc06
DIFF: https://github.com/llvm/llvm-project/commit/cacaa445c3a3a2551a6e2aef51414e47def9cc06.diff
LOG: Reland "[lldb] Use shutil.which in Shell tests find_executable"
This reverts commit d9247cc84825539d346c74eb1379c6cb948d3a71.
With the Windows tests updated to expect .EXE suffixes. This changed
because shutil.which uses PATHEXT which will contain, amongst others,
"EXE".
Also I noticed the "." in ".exe" was the wildcard dot not literal
dot so I've escaped those.
Added:
Modified:
lldb/test/Shell/BuildScript/toolchain-clang-cl.test
lldb/test/Shell/BuildScript/toolchain-clang.test
lldb/test/Shell/BuildScript/toolchain-msvc.test
lldb/test/Shell/helper/build.py
Removed:
################################################################################
diff --git a/lldb/test/Shell/BuildScript/toolchain-clang-cl.test b/lldb/test/Shell/BuildScript/toolchain-clang-cl.test
index cc219aca158f9..8c9ea9fddb8a5 100644
--- a/lldb/test/Shell/BuildScript/toolchain-clang-cl.test
+++ b/lldb/test/Shell/BuildScript/toolchain-clang-cl.test
@@ -23,9 +23,9 @@ CHECK-32: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe-foobar.obj
CHECK-32: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.pdb
CHECK-32: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe
CHECK-32: compiling foobar.c -> foo.exe-foobar.obj
-CHECK-32: {{.*}}clang-cl{{(.exe)?}} -m32
+CHECK-32: {{.*}}clang-cl{{(\.EXE)?}} -m32
CHECK-32: linking foo.exe-foobar.obj -> foo.exe
-CHECK-32: {{.*}}lld-link
+CHECK-32: {{.*}}lld-link{{(\.EXE)?}}
CHECK-64: Script Arguments:
CHECK-64: Arch: 64
@@ -44,6 +44,6 @@ CHECK-64: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe-foobar.obj
CHECK-64: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.pdb
CHECK-64: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe
CHECK-64: compiling foobar.c -> foo.exe-foobar.obj
-CHECK-64: {{.*}}clang-cl{{(.exe)?}} -m64
+CHECK-64: {{.*}}clang-cl{{(\.EXE)?}} -m64
CHECK-64: linking foo.exe-foobar.obj -> foo.exe
-CHECK-64: {{.*}}lld-link{{(.exe)?}}
+CHECK-64: {{.*}}lld-link{{(\.EXE)?}}
diff --git a/lldb/test/Shell/BuildScript/toolchain-clang.test b/lldb/test/Shell/BuildScript/toolchain-clang.test
index eb2dbd543548c..1eaf7064065d6 100644
--- a/lldb/test/Shell/BuildScript/toolchain-clang.test
+++ b/lldb/test/Shell/BuildScript/toolchain-clang.test
@@ -7,8 +7,8 @@ RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-64 %s
CHECK: Cleaning {{.*}}toolchain-clang.test.tmp{{.}}foo.exe-foobar.o
CHECK: Cleaning {{.*}}toolchain-clang.test.tmp{{.}}foo.exe
CHECK: compiling foobar.c -> foo.exe-foobar.o
-CHECK-32: {{.*}}clang++{{(.exe)?}} -m32 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
-CHECK-64: {{.*}}clang++{{(.exe)?}} -m64 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
+CHECK-32: {{.*}}clang++{{(\.EXE)?}} -m32 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
+CHECK-64: {{.*}}clang++{{(\.EXE)?}} -m64 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
CHECK: linking foo.exe-foobar.o -> foo.exe
-CHECK-32: {{.*}}clang++{{(.exe)?}} -m32 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
-CHECK-64: {{.*}}clang++{{(.exe)?}} -m64 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
+CHECK-32: {{.*}}clang++{{(\.EXE)?}} -m32 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
+CHECK-64: {{.*}}clang++{{(\.EXE)?}} -m64 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
diff --git a/lldb/test/Shell/BuildScript/toolchain-msvc.test b/lldb/test/Shell/BuildScript/toolchain-msvc.test
index 0ffd44489729f..6c0d3789869a6 100644
--- a/lldb/test/Shell/BuildScript/toolchain-msvc.test
+++ b/lldb/test/Shell/BuildScript/toolchain-msvc.test
@@ -23,9 +23,9 @@ RUN: | FileCheck --check-prefix=64BIT %s
32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
32BIT: compiling foobar.c -> foo.exe-foobar.obj
-32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\cl.exe
+32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\cl.EXE
32BIT: linking foo.exe-foobar.obj -> foo.exe
-32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\link.exe
+32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\link.EXE
32BIT: Env
32BIT: LIB = {{.*}}\ATLMFC\lib\{{(x86|arm)}}
32BIT: {{.*}}\lib\{{(x86|arm)}}
@@ -51,9 +51,9 @@ RUN: | FileCheck --check-prefix=64BIT %s
64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
64BIT: compiling foobar.c -> foo.exe-foobar.obj
-64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\cl.exe
+64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\cl.EXE
64BIT: linking foo.exe-foobar.obj -> foo.exe
-64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\link.exe
+64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\link.EXE
64BIT: Env
64BIT: LIB = {{.*}}\ATLMFC\lib\{{(x64|arm64)}}
64BIT: {{.*}}\lib\{{(x64|arm64)}}
diff --git a/lldb/test/Shell/helper/build.py b/lldb/test/Shell/helper/build.py
index 005f12bc09cf8..97d790661d5a1 100755
--- a/lldb/test/Shell/helper/build.py
+++ b/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 @@ def print_environment(env):
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':
More information about the lldb-commits
mailing list