From 665a3410dac0168e8978c8537f0f8e07aa629878 Mon Sep 17 00:00:00 2001 From: Harini Date: Thu, 5 Sep 2024 07:51:09 +0000 Subject: [PATCH] [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. --- llvm/utils/lit/lit/TestRunner.py | 11 ++++------- llvm/utils/lit/tests/shtest-glob.py | 3 +-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index 19f35fc7e212f..a1a797da47dc7 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -217,8 +217,8 @@ def expand_glob(arg, cwd): def expand_glob_expressions(args, cwd): - result = [args[0]] - for arg in args[1:]: + result = [] + for arg in args: result.extend(expand_glob(arg, cwd)) return result @@ -776,8 +776,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): # FIXME: Standardize on the builtin echo implementation. We can use a # temporary file to sidestep blocking pipe write issues. - # Ensure args[0] is hashable. - args[0] = expand_glob(args[0], cmd_shenv.cwd)[0] + # Expand all glob expressions + args = expand_glob_expressions(args, cmd_shenv.cwd) inproc_builtin = inproc_builtins.get(args[0], None) if inproc_builtin and (args[0] != "echo" or len(cmd.commands) == 1): @@ -875,9 +875,6 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper): named_temp_files.append(f.name) args[i] = arg.replace(kDevNull, f.name) - # Expand all glob expressions - args = expand_glob_expressions(args, cmd_shenv.cwd) - # On Windows, do our own command line quoting for better compatibility # with some core utility distributions. if kIsWindows: diff --git a/llvm/utils/lit/tests/shtest-glob.py b/llvm/utils/lit/tests/shtest-glob.py index ae90f31907d49..e7840bd1be40a 100644 --- a/llvm/utils/lit/tests/shtest-glob.py +++ b/llvm/utils/lit/tests/shtest-glob.py @@ -5,8 +5,7 @@ # # END. -# CHECK: UNRESOLVED: shtest-glob :: glob-echo.txt ({{[^)]*}}) -# CHECK: TypeError: string argument expected, got 'GlobItem' +# CHECK: PASS: shtest-glob :: glob-echo.txt ({{[^)]*}}) # CHECK: FAIL: shtest-glob :: glob-mkdir.txt ({{[^)]*}}) # CHECK: # error: command failed with exit status: 1