[llvm] 25aac60 - [lit] Use text mode when opening text files on z/OS (#217434)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 05:52:59 PDT 2026
Author: Abhina Sree
Date: 2026-09-22T08:52:51-04:00
New Revision: 25aac605a4f1fc72bd1dcf0bb8d64fbfe2db3aa9
URL: https://github.com/llvm/llvm-project/commit/25aac605a4f1fc72bd1dcf0bb8d64fbfe2db3aa9
DIFF: https://github.com/llvm/llvm-project/commit/25aac605a4f1fc72bd1dcf0bb8d64fbfe2db3aa9.diff
LOG: [lit] Use text mode when opening text files on z/OS (#217434)
On z/OS, we rely on autoconversion to read files correctly, and this
requires files to be opened as text.
The following change https://github.com/llvm/llvm-project/pull/208024
changed the streams to be read and piped as binary resulting in some
test regressions due to unreadable output. This patch restores the
functionality of opening and reading as a text stream.
Added:
Modified:
llvm/utils/lit/lit/TestRunner.py
llvm/utils/lit/lit/builtin_commands/cat.py
llvm/utils/lit/lit/builtin_commands/diff.py
Removed:
################################################################################
diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 1d4480f81f873..425255125db9c 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -5,6 +5,7 @@
import io
import os
import pathlib
+import platform
import re
import shlex
import signal
@@ -404,7 +405,8 @@ def _make_out_sink(stdout: int | TextIO, is_last: bool) -> IO[bytes] | None:
last stage or a non-pipe target, which don't need this sink.
"""
if stdout == subprocess.PIPE and not is_last:
- return tempfile.SpooledTemporaryFile(max_size=1 << 20)
+ _mode = "w+" if platform.system() == "OS/390" else "w+b"
+ return tempfile.SpooledTemporaryFile(max_size=1 << 20, mode=_mode)
return None
diff --git a/llvm/utils/lit/lit/builtin_commands/cat.py b/llvm/utils/lit/lit/builtin_commands/cat.py
index bfd6e86f46bdb..2882b79f572fd 100644
--- a/llvm/utils/lit/lit/builtin_commands/cat.py
+++ b/llvm/utils/lit/lit/builtin_commands/cat.py
@@ -90,8 +90,17 @@ def run(argv, stdin, stdout, stderr, cwd):
if show_nonprinting:
contents = convertToCaretAndMNotation(contents)
- elif is_text:
- contents = contents.encode()
+
+ # Determine if stdout expects text or binary
+ mode = getattr(stdout, "mode", "b")
+ is_text_output = "b" not in mode
+
+ if is_text_output:
+ if isinstance(contents, bytes):
+ contents = contents.decode()
+ else:
+ if isinstance(contents, str):
+ contents = contents.encode()
stdout.write(contents)
return 0
diff --git a/llvm/utils/lit/lit/builtin_commands/
diff .py b/llvm/utils/lit/lit/builtin_commands/
diff .py
index 3a85d2210705f..7f286fd5e16be 100644
--- a/llvm/utils/lit/lit/builtin_commands/
diff .py
+++ b/llvm/utils/lit/lit/builtin_commands/
diff .py
@@ -5,6 +5,7 @@
import os
import re
import sys
+import platform
#
diff .py runs in two modes during the in-process migration:
# - In-process: imported as 'lit.builtin_commands.
diff ', so __package__ is
@@ -63,11 +64,22 @@ def getDirTree(path, basedir=""):
def compareTwoFiles(flags, filepaths, stdin, stdout):
filelines = []
for file in filepaths:
+ is_text = False
if file == "-":
filelines.append(stdin.readlines())
else:
- with open(file, "rb") as file_bin:
- filelines.append(file_bin.readlines())
+ if platform.system() == "OS/390":
+ try:
+ with open(file, "r") as file_text:
+ filelines.append(
+ file_text.read().encode().splitlines(keepends=True)
+ )
+ is_text = True
+ except:
+ pass
+ if not is_text:
+ with open(file, "rb") as file_bin:
+ filelines.append(file_bin.readlines())
try:
return compareTwoTextFiles(
More information about the llvm-commits
mailing list