From f895e2ae8bf9690dbbc79ba0b84d8eedf137764e Mon Sep 17 00:00:00 2001 From: jyelon Date: Mon, 9 Mar 2026 06:59:33 -0400 Subject: [PATCH] This script is no good. --- tools/trim-handler.py | 73 ------------------------------------------- 1 file changed, 73 deletions(-) delete mode 100644 tools/trim-handler.py diff --git a/tools/trim-handler.py b/tools/trim-handler.py deleted file mode 100644 index 5e39e20a..00000000 --- a/tools/trim-handler.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python3 -""" -Trim unnecessary #include lines from a C++ header file. - -Usage: python3 tools/trim-handler.py - -For each #include line, temporarily removes it and runs clangd diagnostics. -If no errors result, the include is marked unnecessary. At the end, rewrites -the file with all unnecessary includes removed. -""" - -import sys -import subprocess -import os - -def read_lines(path): - with open(path, 'r') as f: - return f.readlines() - -def write_lines(path, lines): - with open(path, 'w') as f: - f.writelines(lines) - -def has_errors(path): - result = subprocess.run( - ['python3', 'tools/clangd-query.py', 'diagnostics', path], - capture_output=True, text=True - ) - output = result.stdout.strip() - return output != "No problems found." - -def main(): - if len(sys.argv) != 2: - print("Usage: python3 tools/trim-handler.py ") - sys.exit(1) - - path = os.path.abspath(sys.argv[1]) - original_lines = read_lines(path) - - # First, verify the file starts with no errors. - if has_errors(path): - print(f"ERROR: {path} already has diagnostics errors. Fix those first.") - sys.exit(1) - - unnecessary = set() - - for i, line in enumerate(original_lines): - if not line.strip().startswith('#include'): - continue - # Skip the .generated.h include — always required by UHT. - if '.generated.h' in line: - continue - - # Rewrite the file without this line. - test_lines = original_lines[:i] + original_lines[i+1:] - write_lines(path, test_lines) - - if has_errors(path): - print(f" KEEP: {line.strip()}") - else: - print(f" DROP: {line.strip()}") - unnecessary.add(i) - - # Restore the original file before testing the next include. - write_lines(path, original_lines) - - # Final rewrite with unnecessary includes removed. - final_lines = [line for i, line in enumerate(original_lines) if i not in unnecessary] - write_lines(path, final_lines) - print(f"\nRemoved {len(unnecessary)} unnecessary include(s) from {path}") - -if __name__ == '__main__': - main()