From 43f21cd99c7e7e1ef349a8b8d1d83ab0332cff0f Mon Sep 17 00:00:00 2001 From: Sean Perry Date: Mon, 13 Jul 2026 13:53:34 -0400 Subject: [PATCH 1/3] Add text file support for z/OS back in --- llvm/utils/lit/lit/builtin_commands/cat.py | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/llvm/utils/lit/lit/builtin_commands/cat.py b/llvm/utils/lit/lit/builtin_commands/cat.py index fc7d1229bc674..826cf94b1cb8e 100644 --- a/llvm/utils/lit/lit/builtin_commands/cat.py +++ b/llvm/utils/lit/lit/builtin_commands/cat.py @@ -65,18 +65,31 @@ def run(argv, stdin, stdout, stderr, cwd): for filename in filenames: path = filename - contents = None if not os.path.isabs(path): path = os.path.join(cwd, path) + + contents = None + is_text = False try: - with open(path, "rb") as fileToCat: - contents = fileToCat.read() - except IOError as error: - error.filename = filename - stderr.write(str(error).encode()) - return 1 + fileToCat = open(filename, "r") + contents = fileToCat.read() + is_text = True + except: + pass + + if contents is None: + try: + with open(path, "rb") as fileToCat: + contents = fileToCat.read() + except IOError as error: + error.filename = filename + stderr.write(str(error).encode()) + return 1 + if show_nonprinting: contents = convertToCaretAndMNotation(contents) + elif is_text: + contents = contents.encode() stdout.write(contents) return 0 From efcc3381903f0ddb797a20178cb2078f084158d0 Mon Sep 17 00:00:00 2001 From: Sean Perry Date: Mon, 13 Jul 2026 14:13:33 -0400 Subject: [PATCH 2/3] only open as text on z/OS --- llvm/utils/lit/lit/builtin_commands/cat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/utils/lit/lit/builtin_commands/cat.py b/llvm/utils/lit/lit/builtin_commands/cat.py index 826cf94b1cb8e..30d8b1b88a0cc 100644 --- a/llvm/utils/lit/lit/builtin_commands/cat.py +++ b/llvm/utils/lit/lit/builtin_commands/cat.py @@ -71,9 +71,9 @@ def run(argv, stdin, stdout, stderr, cwd): contents = None is_text = False try: - fileToCat = open(filename, "r") - contents = fileToCat.read() - is_text = True + with open(path, "r") as fileToCat: + contents = fileToCat.read() + is_text = True except: pass From a0b390aaf56b0888ec2c7117360ae9d8aa474f84 Mon Sep 17 00:00:00 2001 From: Sean Perry Date: Mon, 13 Jul 2026 16:42:13 -0400 Subject: [PATCH 3/3] only open as text on z/OS --- llvm/utils/lit/lit/builtin_commands/cat.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/llvm/utils/lit/lit/builtin_commands/cat.py b/llvm/utils/lit/lit/builtin_commands/cat.py index 30d8b1b88a0cc..bfd6e86f46bdb 100644 --- a/llvm/utils/lit/lit/builtin_commands/cat.py +++ b/llvm/utils/lit/lit/builtin_commands/cat.py @@ -1,5 +1,6 @@ import getopt import os +import platform import sys from io import StringIO @@ -70,12 +71,13 @@ def run(argv, stdin, stdout, stderr, cwd): contents = None is_text = False - try: - with open(path, "r") as fileToCat: - contents = fileToCat.read() - is_text = True - except: - pass + if platform.system() == "OS/390": + try: + with open(path, "r") as fileToCat: + contents = fileToCat.read() + is_text = True + except: + pass if contents is None: try: