#!/usr/bin/env python3 import os import re base_dir = "/home/torsten/swy/sandbox/qt-migration-legatus/qt6-after/qt6-migrated-legatus" # Pattern für Export-Header Includes pattern = re.compile(r'#include\s+<([^>]+_export\.h)>') def get_correct_path(filepath, include_path): """Korrekten Pfad relativ zum Build-Verzeichnis berechnen""" # Datei-Pfad relativ zum Base-Dir rel_path = os.path.relpath(filepath, base_dir) file_dir = os.path.dirname(rel_path) # CMake fügt CMAKE_CURRENT_BINARY_DIR/.. hinzu # Also ist der Include-Pfad relativ zu /.. # Wir müssen den Pfad von der Datei zum Build-Verzeichnis berechnen # Einfache Regel: Ersetze den Source-Pfad durch den korrekten Build-Pfad # → # → # → # → # → if include_path.startswith("Plugins/"): return f"Lts/{include_path}" elif include_path.startswith("Common/"): return f"Lts/{include_path}" elif include_path.startswith("Services/"): return f"Lts/{include_path}" elif include_path.startswith("Proxies/"): return f"Lts/{include_path}" elif include_path.startswith("DDS/"): return f"Lts/{include_path}" elif include_path.startswith("Z/"): return f"{include_path}" # Z bleibt wie es ist elif include_path.startswith("TetraIF/"): return f"{include_path}" # TetraIF bleibt wie es ist else: return include_path # Unbekannt, unverändert fixed_count = 0 skipped_count = 0 for root, dirs, files in os.walk(base_dir): # Skip build directories if 'build' in root or 'build2' in root or 'build_migrate' in root: continue for file in files: if file.endswith(('.h', '.cpp', '.hpp', '.cc')): filepath = os.path.join(root, file) try: with open(filepath, 'r', encoding='utf-8', errors='ignore') as f: content = f.read() new_content = content for match in pattern.finditer(content): include_path = match.group(1) correct_path = get_correct_path(filepath, include_path) if include_path != correct_path: old_include = f'#include <{include_path}>' new_include = f'#include <{correct_path}>' new_content = new_content.replace(old_include, new_include) print(f"FIX: {filepath}: {include_path} → {correct_path}") fixed_count += 1 if new_content != content: with open(filepath, 'w', encoding='utf-8') as f: f.write(new_content) except Exception as e: print(f"ERROR: {filepath}: {e}") skipped_count += 1 print(f"\n=== Summary ===") print(f"Fixed: {fixed_count}") print(f"Skipped: {skipped_count}")