Skip to content

Commit 0cddf3e

Browse files
aeubanksrnk
andauthored
[clang-tidy][test] Make check_clang_tidy.py work with very long file paths (#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 --------- Co-authored-by: Reid Kleckner <[email protected]>
1 parent 13a6342 commit 0cddf3e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

clang-tools-extra/test/clang-tidy/check_clang_tidy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import argparse
4646
import os
4747
import pathlib
48+
import platform
4849
import re
4950
import subprocess
5051
import sys
@@ -145,7 +146,12 @@ def __init__(self, args: argparse.Namespace, extra_args: List[str]) -> None:
145146
self.clang_extra_args.append("-resource-dir=%s" % self.resource_dir)
146147

147148
def read_input(self) -> None:
148-
with open(self.input_file_name, "r", encoding="utf-8") as input_file:
149+
# Use a "\\?\" prefix on Windows to handle long file paths transparently:
150+
# https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
151+
file_name = self.input_file_name
152+
if platform.system() == "Windows":
153+
file_name = "\\\\?\\" + os.path.abspath(file_name)
154+
with open(file_name, "r", encoding="utf-8") as input_file:
149155
self.input_text = input_file.read()
150156

151157
def get_prefixes(self) -> None:

0 commit comments

Comments
 (0)