Skip to content

Commit a4b954f

Browse files
committed
build: implement batch processing to handle Windows command line length limits
1 parent 2a3f5b9 commit a4b954f

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

scripts/run-clang-tidy.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -133,37 +133,46 @@ def run_clang_tidy(source_files: List[str],
133133
print("No source files to analyze.")
134134
return 0
135135

136-
cmd = [
137-
'clang-tidy',
138-
f'-p={compile_commands_path.parent}',
139-
]
140-
141-
if fix:
142-
cmd.append('--fix')
143-
144-
if extra_args:
145-
cmd.extend(extra_args)
136+
# Process files in batches to avoid command line length limits on Windows
137+
# Windows cmd.exe has a limit of ~8191 characters
138+
BATCH_SIZE = 50 # Conservative batch size for Windows compatibility
139+
total_files = len(source_files)
140+
batches = [source_files[i:i + BATCH_SIZE] for i in range(0, total_files, BATCH_SIZE)]
146141

147-
# Add source files
148-
cmd.extend(source_files)
142+
print(f"Running clang-tidy on {total_files} files in {len(batches)} batch(es)...")
143+
if jobs > 1:
144+
print(f"Note: Parallel execution with {jobs} jobs not implemented yet.")
149145

150-
print(f"Running clang-tidy on {len(source_files)} files...")
151-
print(f"Command: {' '.join(cmd[:5])} ... {len(source_files)} files")
152-
153-
try:
154-
if jobs > 1:
155-
# For parallel execution, we'd need to use run-clang-tidy.py from LLVM
156-
# For now, run sequentially
157-
print(f"Note: Parallel execution with {jobs} jobs not implemented yet.")
146+
overall_returncode = 0
147+
for batch_num, batch in enumerate(batches, 1):
148+
cmd = [
149+
'clang-tidy',
150+
f'-p={compile_commands_path.parent}',
151+
]
158152

159-
result = subprocess.run(cmd, cwd=find_project_root())
160-
return result.returncode
161-
except FileNotFoundError:
162-
print("Error: clang-tidy not found. Please install clang-tidy.")
163-
return 1
164-
except KeyboardInterrupt:
165-
print("\nInterrupted by user.")
166-
return 130
153+
if fix:
154+
cmd.append('--fix')
155+
156+
if extra_args:
157+
cmd.extend(extra_args)
158+
159+
# Add source files for this batch
160+
cmd.extend(batch)
161+
162+
print(f"\nBatch {batch_num}/{len(batches)}: Analyzing {len(batch)} file(s)...")
163+
164+
try:
165+
result = subprocess.run(cmd, cwd=find_project_root())
166+
if result.returncode != 0:
167+
overall_returncode = result.returncode
168+
except FileNotFoundError:
169+
print("Error: clang-tidy not found. Please install clang-tidy.")
170+
return 1
171+
except KeyboardInterrupt:
172+
print("\nInterrupted by user.")
173+
return 130
174+
175+
return overall_returncode
167176

168177

169178
def main():

0 commit comments

Comments
 (0)