Skip to content

Commit fa490a6

Browse files
committed
remove to_string from the runner
1 parent 4e82cd7 commit fa490a6

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import lit.ShUtil as ShUtil
2222
import lit.Test as Test
2323
import lit.util
24-
from lit.util import to_bytes, to_string
24+
from lit.util import to_bytes
2525
from lit.BooleanExpression import BooleanExpression
2626

2727

@@ -391,18 +391,14 @@ def executeBuiltinEcho(cmd, shenv):
391391
# Some tests have un-redirected echo commands to help debug test failures.
392392
# Buffer our output and return it to the caller.
393393
is_redirected = True
394-
encode = lambda x: x
395394
if stdout == subprocess.PIPE:
396395
is_redirected = False
397396
stdout = StringIO()
398397
elif kIsWindows:
399-
# Reopen stdout in binary mode to avoid CRLF translation. The versions
400-
# of echo we are replacing on Windows all emit plain LF, and the LLVM
401-
# tests now depend on this.
402-
# When we open as binary, however, this also means that we have to write
403-
# 'bytes' objects to stdout instead of 'str' objects.
404-
encode = lit.util.to_bytes
405-
stdout = open(stdout.name, stdout.mode + "b")
398+
# Reopen stdout with specifying `newline` to avoid CRLF translation.
399+
# The versions of echo we are replacing on Windows all emit plain LF,
400+
# and the LLVM tests now depend on this.
401+
stdout = open(stdout.name, stdout.mode, newline='')
406402
opened_files.append((None, None, stdout, None))
407403

408404
# Implement echo flags. We only support -e and -n, and not yet in
@@ -423,16 +419,15 @@ def maybeUnescape(arg):
423419
if not interpret_escapes:
424420
return arg
425421

426-
arg = lit.util.to_bytes(arg)
427-
return arg.decode("unicode_escape")
422+
return arg.encode("utf-8").decode("unicode_escape")
428423

429424
if args:
430425
for arg in args[:-1]:
431-
stdout.write(encode(maybeUnescape(arg)))
432-
stdout.write(encode(" "))
433-
stdout.write(encode(maybeUnescape(args[-1])))
426+
stdout.write(maybeUnescape(arg))
427+
stdout.write(" ")
428+
stdout.write(maybeUnescape(args[-1]))
434429
if write_newline:
435-
stdout.write(encode("\n"))
430+
stdout.write("\n")
436431

437432
for (name, mode, f, path) in opened_files:
438433
f.close()
@@ -1062,14 +1057,14 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
10621057
if out is None:
10631058
out = ""
10641059
else:
1065-
out = to_string(out.decode("utf-8", errors="replace"))
1060+
out = out.decode("utf-8", errors="replace")
10661061
except:
10671062
out = str(out)
10681063
try:
10691064
if err is None:
10701065
err = ""
10711066
else:
1072-
err = to_string(err.decode("utf-8", errors="replace"))
1067+
err = err.decode("utf-8", errors="replace")
10731068
except:
10741069
err = str(err)
10751070

@@ -1261,7 +1256,7 @@ def executeScriptInternal(
12611256

12621257
# Add the command output, if redirected.
12631258
for (name, path, data) in result.outputFiles:
1264-
data = to_string(data.decode("utf-8", errors="replace"))
1259+
data = data.decode("utf-8", errors="replace")
12651260
out += formatOutput(f"redirected output from '{name}'", data, limit=1024)
12661261
if result.stdout.strip():
12671262
out += formatOutput("command stdout", result.stdout)
@@ -1471,8 +1466,8 @@ def parseIntegratedTestScriptCommands(source_path, keywords):
14711466
keyword, ln = match.groups()
14721467
yield (
14731468
line_number,
1474-
to_string(keyword.decode("utf-8")),
1475-
to_string(ln.decode("utf-8").rstrip("\r")),
1469+
keyword.decode("utf-8"),
1470+
ln.decode("utf-8").rstrip("\r"),
14761471
)
14771472
finally:
14781473
f.close()

llvm/utils/lit/lit/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def executeCommand(
327327
328328
"""
329329
if input is not None:
330-
input = to_bytes(input)
330+
input = input.encode("utf-8")
331331
err_out = subprocess.STDOUT if redirect_stderr else subprocess.PIPE
332332
p = subprocess.Popen(
333333
command,
@@ -363,8 +363,8 @@ def killProcess():
363363
timerObject.cancel()
364364

365365
# Ensure the resulting output is always of string type.
366-
out = to_string(out)
367-
err = "" if redirect_stderr else to_string(err)
366+
out = out.decode("utf-8", errors="replace")
367+
err = "" if redirect_stderr else err.decode("utf-8", errors="replace")
368368

369369
if hitTimeOut[0]:
370370
raise ExecuteCommandTimeoutException(

0 commit comments

Comments
 (0)