[clang-tools-extra] [clang-tidy][test] Make check_clang_tidy.py work with very long file paths (PR #155318)

Arthur Eubanks via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 25 14:56:50 PDT 2025


https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/155318

http://github.com/llvm/llvm-project/pull/95220 added a test with a very long file path, which can fail if run on Windows with a long directory path.

On Windows, there are file path length limits, which can be worked around by prefixing the (absolute) path with '\\?\': https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation

>From 80f06489a7dec38f683303bf023f02effc528ed9 Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Mon, 25 Aug 2025 21:54:14 +0000
Subject: [PATCH] [clang-tidy][test] Make check_clang_tidy.py work with very
 long file paths

http://github.com/llvm/llvm-project/pull/95220 added a test with a very long file path, which can fail if run on Windows with a long directory path.

On Windows, there are file path length limits, which can be worked around by prefixing the (absolute) path with '\\?\':
https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
---
 clang-tools-extra/test/clang-tidy/check_clang_tidy.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index d225258c5d75d..7c77e498f28f8 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -45,6 +45,7 @@
 import argparse
 import os
 import pathlib
+import platform
 import re
 import subprocess
 import sys
@@ -145,7 +146,10 @@ def __init__(self, args: argparse.Namespace, extra_args: List[str]) -> None:
             self.clang_extra_args.append("-resource-dir=%s" % self.resource_dir)
 
     def read_input(self) -> None:
-        with open(self.input_file_name, "r", encoding="utf-8") as input_file:
+        file_name = self.input_file_name
+        if platform.system() == "Windows":
+            file_name = "\\\\?\\" + os.path.abspath(file_name)
+        with open(file_name, "r", encoding="utf-8") as input_file:
             self.input_text = input_file.read()
 
     def get_prefixes(self) -> None:



More information about the cfe-commits mailing list