Skip to content

Commit cacaa44

Browse files
committed
Reland "[lldb] Use shutil.which in Shell tests find_executable"
This reverts commit d9247cc. 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.
1 parent 4cacd22 commit cacaa44

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

lldb/test/Shell/BuildScript/toolchain-clang-cl.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ CHECK-32: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe-foobar.obj
2323
CHECK-32: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.pdb
2424
CHECK-32: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe
2525
CHECK-32: compiling foobar.c -> foo.exe-foobar.obj
26-
CHECK-32: {{.*}}clang-cl{{(.exe)?}} -m32
26+
CHECK-32: {{.*}}clang-cl{{(\.EXE)?}} -m32
2727
CHECK-32: linking foo.exe-foobar.obj -> foo.exe
28-
CHECK-32: {{.*}}lld-link
28+
CHECK-32: {{.*}}lld-link{{(\.EXE)?}}
2929

3030
CHECK-64: Script Arguments:
3131
CHECK-64: Arch: 64
@@ -44,6 +44,6 @@ CHECK-64: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe-foobar.obj
4444
CHECK-64: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.pdb
4545
CHECK-64: Cleaning {{.*}}toolchain-clang-cl.test.tmp{{.}}foo.exe
4646
CHECK-64: compiling foobar.c -> foo.exe-foobar.obj
47-
CHECK-64: {{.*}}clang-cl{{(.exe)?}} -m64
47+
CHECK-64: {{.*}}clang-cl{{(\.EXE)?}} -m64
4848
CHECK-64: linking foo.exe-foobar.obj -> foo.exe
49-
CHECK-64: {{.*}}lld-link{{(.exe)?}}
49+
CHECK-64: {{.*}}lld-link{{(\.EXE)?}}

lldb/test/Shell/BuildScript/toolchain-clang.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-64 %s
77
CHECK: Cleaning {{.*}}toolchain-clang.test.tmp{{.}}foo.exe-foobar.o
88
CHECK: Cleaning {{.*}}toolchain-clang.test.tmp{{.}}foo.exe
99
CHECK: compiling foobar.c -> foo.exe-foobar.o
10-
CHECK-32: {{.*}}clang++{{(.exe)?}} -m32 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
11-
CHECK-64: {{.*}}clang++{{(.exe)?}} -m64 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
10+
CHECK-32: {{.*}}clang++{{(\.EXE)?}} -m32 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
11+
CHECK-64: {{.*}}clang++{{(\.EXE)?}} -m64 -g -O0 -c -o {{.*}}foo.exe-foobar.o {{.*}}foobar.c
1212
CHECK: linking foo.exe-foobar.o -> foo.exe
13-
CHECK-32: {{.*}}clang++{{(.exe)?}} -m32 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
14-
CHECK-64: {{.*}}clang++{{(.exe)?}} -m64 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
13+
CHECK-32: {{.*}}clang++{{(\.EXE)?}} -m32 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o
14+
CHECK-64: {{.*}}clang++{{(\.EXE)?}} -m64 {{(-L.* )?(-Wl,-rpath,.* )?}}-o {{.*}}foo.exe {{.*}}foo.exe-foobar.o

lldb/test/Shell/BuildScript/toolchain-msvc.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ RUN: | FileCheck --check-prefix=64BIT %s
2323
32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
2424
32BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
2525
32BIT: compiling foobar.c -> foo.exe-foobar.obj
26-
32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\cl.exe
26+
32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\cl.EXE
2727
32BIT: linking foo.exe-foobar.obj -> foo.exe
28-
32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\link.exe
28+
32BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x86|arm)}}\link.EXE
2929
32BIT: Env
3030
32BIT: LIB = {{.*}}\ATLMFC\lib\{{(x86|arm)}}
3131
32BIT: {{.*}}\lib\{{(x86|arm)}}
@@ -51,9 +51,9 @@ RUN: | FileCheck --check-prefix=64BIT %s
5151
64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.pdb
5252
64BIT: Cleaning {{.*}}toolchain-msvc.test.tmp\foo.exe
5353
64BIT: compiling foobar.c -> foo.exe-foobar.obj
54-
64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\cl.exe
54+
64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\cl.EXE
5555
64BIT: linking foo.exe-foobar.obj -> foo.exe
56-
64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\link.exe
56+
64BIT: Command Line: {{.*}}\{{[Hh]ost[Xx](64|86)}}\{{(x64|arm64)}}\link.EXE
5757
64BIT: Env
5858
64BIT: LIB = {{.*}}\ATLMFC\lib\{{(x64|arm64)}}
5959
64BIT: {{.*}}\lib\{{(x64|arm64)}}

lldb/test/Shell/helper/build.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import argparse
66
import os
7+
import shutil
78
import signal
89
import subprocess
910
import sys
@@ -170,16 +171,14 @@ def print_environment(env):
170171
print(' {0} = {1}'.format(e, formatted_value))
171172

172173
def find_executable(binary_name, search_paths):
173-
if sys.platform == 'win32':
174-
binary_name = binary_name + '.exe'
175-
176-
search_paths = os.pathsep.join(search_paths)
177-
paths = search_paths + os.pathsep + os.environ.get('PATH', '')
178-
for path in paths.split(os.pathsep):
179-
p = os.path.join(path, binary_name)
180-
if os.path.exists(p) and not os.path.isdir(p):
181-
return os.path.normpath(p)
182-
return None
174+
# shutil.which will ignore PATH if given a path argument, we want to include it.
175+
search_paths.append(os.environ.get('PATH', ''))
176+
search_path = os.pathsep.join(search_paths)
177+
binary_path = shutil.which(binary_name, path=search_path)
178+
if binary_path is not None:
179+
# So for example, we get '/bin/gcc' instead of '/usr/../bin/gcc'.
180+
binary_path = os.path.normpath(binary_path)
181+
return binary_path
183182

184183
def find_toolchain(compiler, tools_dir):
185184
if compiler == 'msvc':

0 commit comments

Comments
 (0)