[llvm] lit: improve long path support on Windows (PR #207250)
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 2 19:04:53 PDT 2026
https://github.com/compnerd updated https://github.com/llvm/llvm-project/pull/207250
>From 1fc323db03aad92ad18f63559f46e87d080ffb24 Mon Sep 17 00:00:00 2001
From: Saleem Abdulrasool <compnerd at compnerd.org>
Date: Thu, 2 Jul 2026 11:41:14 -0700
Subject: [PATCH 1/2] lit: handle `rm` on Windows for files with extended paths
Previous changes enabled long directories to be cleaned up by using
ShellWapi. This addresses the _file_ operation now. Use NT extended
paths to ensure that long paths do not silently fail.
---
llvm/utils/lit/lit/InprocBuiltins.py | 1 +
llvm/utils/lit/lit/util.py | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+)
diff --git a/llvm/utils/lit/lit/InprocBuiltins.py b/llvm/utils/lit/lit/InprocBuiltins.py
index b20aeb6993726..60ebc07cba5f6 100644
--- a/llvm/utils/lit/lit/InprocBuiltins.py
+++ b/llvm/utils/lit/lit/InprocBuiltins.py
@@ -251,6 +251,7 @@ class SHFILEOPSTRUCTW(Structure):
else:
shutil.rmtree(path, onerror=on_rm_error if force else None)
else:
+ path = lit.util.get_windows_extended_path(path)
if force and not os.access(path, os.W_OK):
os.chmod(path, stat.S_IMODE(os.stat(path).st_mode) | stat.S_IWRITE)
os.remove(path)
diff --git a/llvm/utils/lit/lit/util.py b/llvm/utils/lit/lit/util.py
index e02c99c3c609b..b870240face8c 100644
--- a/llvm/utils/lit/lit/util.py
+++ b/llvm/utils/lit/lit/util.py
@@ -476,3 +476,28 @@ def runCommandCached(lit_config, cmd, allow_failure, **kwargs):
lit_config.fatal(msg)
return None
+
+
+def get_windows_extended_path(path: str) -> str:
+ """
+ Return *path* in Windows extended-length (``\\\\?\\``) form.
+
+ On non-Windows platforms the path is returned unchanged. On Windows,
+ the path is made absolute and given the ``\\\\?\\`` prefix so it can
+ exceed the Win32 ``MAX_PATH`` (260-character) limit. UNC paths
+ (those beginning with ``\\\\``) are converted to the ``\\\\?\\UNC\\``
+ form instead.
+
+ Args:
+ path: The filesystem path to normalize.
+
+ Returns:
+ The original path on non-Windows platforms, otherwise the
+ absolute path in extended-length form.
+ """
+ if not platform.system() == 'Windows':
+ return path
+ path = os.path.abspath(path)
+ if path.startswith("\\\\"):
+ return "\\\\?\\UNC\\{0}".format(path[2:])
+ return "\\\\?\\{0}".format(path)
>From 29dd6831851caa7a5ed6bfc6f7022dad8c735516 Mon Sep 17 00:00:00 2001
From: Saleem Abdulrasool <compnerd at compnerd.org>
Date: Thu, 2 Jul 2026 11:40:21 -0700
Subject: [PATCH 2/2] lit: use extended paths on Windows for redirection
If you exceed the Win32 path limit, we will silently fail on Windows.
Use extended (NT) path spellings to allow us to use deeper paths.
---
llvm/utils/lit/lit/ShellEnvironment.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/utils/lit/lit/ShellEnvironment.py b/llvm/utils/lit/lit/ShellEnvironment.py
index ffd58617b42f2..1945865b19199 100644
--- a/llvm/utils/lit/lit/ShellEnvironment.py
+++ b/llvm/utils/lit/lit/ShellEnvironment.py
@@ -190,6 +190,7 @@ def processRedirects(cmd, stdin_source, cmd_shenv, opened_files):
else:
# Make sure relative paths are relative to the cwd.
redir_filename = os.path.join(cmd_shenv.cwd, name)
+ redir_filename = lit.util.get_windows_extended_path(redir_filename)
fd = open(redir_filename, mode, encoding="utf-8")
# Workaround a Win32 and/or subprocess bug when appending.
#
More information about the llvm-commits
mailing list