Skip to content

Commit 665a341

Browse files
committed
[llvm-lit] Expand all glob expressions at once in TestRunner
This patch modifies the expand_glob_expressions function in TestRunner.py to expand all arguments instead of just the first one. Previously, only args[0] was expanded for glob expressions, which could lead to unexpected behavior when multiple arguments needed glob expansion. Changes: The loop in expand_glob_expressions now iterates over all arguments instead of starting from the second one. The call to expand_glob_expressions has been moved earlier in the _executeShCmd function to ensure all arguments are expanded before any processing. Removed the previous separate expansion for args[0] as it is now redundant. These changes ensure that all glob expressions are properly expanded across all command arguments, improving the robustness and correctness of the lit internal shell.
1 parent 0c1500e commit 665a341

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ def expand_glob(arg, cwd):
217217

218218

219219
def expand_glob_expressions(args, cwd):
220-
result = [args[0]]
221-
for arg in args[1:]:
220+
result = []
221+
for arg in args:
222222
result.extend(expand_glob(arg, cwd))
223223
return result
224224

@@ -776,8 +776,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
776776
# FIXME: Standardize on the builtin echo implementation. We can use a
777777
# temporary file to sidestep blocking pipe write issues.
778778

779-
# Ensure args[0] is hashable.
780-
args[0] = expand_glob(args[0], cmd_shenv.cwd)[0]
779+
# Expand all glob expressions
780+
args = expand_glob_expressions(args, cmd_shenv.cwd)
781781

782782
inproc_builtin = inproc_builtins.get(args[0], None)
783783
if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1):
@@ -875,9 +875,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
875875
named_temp_files.append(f.name)
876876
args[i] = arg.replace(kDevNull, f.name)
877877

878-
# Expand all glob expressions
879-
args = expand_glob_expressions(args, cmd_shenv.cwd)
880-
881878
# On Windows, do our own command line quoting for better compatibility
882879
# with some core utility distributions.
883880
if kIsWindows:

llvm/utils/lit/tests/shtest-glob.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#
66
# END.
77

8-
# CHECK: UNRESOLVED: shtest-glob :: glob-echo.txt ({{[^)]*}})
9-
# CHECK: TypeError: string argument expected, got 'GlobItem'
8+
# CHECK: PASS: shtest-glob :: glob-echo.txt ({{[^)]*}})
109

1110
# CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}})
1211
# CHECK: # error: command failed with exit status: 1

0 commit comments

Comments
 (0)