[llvm] [llvm-lit] Fix `TypeError` string argument expected in lit's internal shell (PR #105925)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 01:29:56 PDT 2024
https://github.com/Harini0924 updated https://github.com/llvm/llvm-project/pull/105925
>From f5e4c4668005c4e66ba442355bcf4bcc7e161dbb Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Sat, 24 Aug 2024 05:36:25 +0000
Subject: [PATCH 1/3] Fix TypeError in BOLT test
Ensured that arguments passed to `stdout.write` in the `executeBuiltinEcho`
function are properly converted to strings.
---
llvm/utils/lit/lit/TestRunner.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 2d9af9fbbb3634..625ce009515d5f 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -413,7 +413,7 @@ def maybeUnescape(arg):
for arg in args[:-1]:
stdout.write(encode(maybeUnescape(arg)))
stdout.write(encode(" "))
- stdout.write(encode(maybeUnescape(args[-1])))
+ stdout.write(encode(maybeUnescape(str(args[-1]))))
if write_newline:
stdout.write(encode("\n"))
>From 3f7c6ea4f4fd2b9e0dce8d27461bc22471a5224d Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Thu, 5 Sep 2024 07:51:09 +0000
Subject: [PATCH 2/3] [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 | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 625ce009515d5f..b7581ccf95ffa7 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
@@ -768,9 +768,9 @@ 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):
# env calling an in-process builtin is useless, so we take the safe
@@ -867,9 +867,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:
>From 125622eb8c151137992a9b3891a7202438f87f39 Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Thu, 5 Sep 2024 07:51:09 +0000
Subject: [PATCH 3/3] [llvm-lit] Removed str() and fixed code formatter issues
---
llvm/utils/lit/lit/TestRunner.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index b7581ccf95ffa7..24fc0fdb91dca4 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -413,7 +413,7 @@ def maybeUnescape(arg):
for arg in args[:-1]:
stdout.write(encode(maybeUnescape(arg)))
stdout.write(encode(" "))
- stdout.write(encode(maybeUnescape(str(args[-1]))))
+ stdout.write(encode(maybeUnescape(args[-1])))
if write_newline:
stdout.write(encode("\n"))
@@ -770,7 +770,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
# 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):
# env calling an in-process builtin is useless, so we take the safe
More information about the llvm-commits
mailing list