Files
qt6-migration-pipeline/fix_export_includes.py
T
torstenandCopilot 342ffd3e5c Update submodule to latest BUILD_RTI fixes
- HandlerMinelayerData: BUILD_RTI Guards für RTI-Abhängigkeiten
- svcTabCommon: Export-Header-Fix via Fallback-Target
- TrainingAreaBase: Stub-Header für BUILD_RTI=OFF
- ddsfts: Include-Pfad und Dependency-Fixes
- BUILD_RTI=OFF Compilation vollständig unterstützt

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Entire-Checkpoint: 01M0JNZA586SACX1PRZ2DJAE5S
2026-08-21 19:30:20 +02:00

83 lines
3.1 KiB
Python
Executable File

#!/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 <Component>/..
# Wir müssen den Pfad von der Datei zum Build-Verzeichnis berechnen
# Einfache Regel: Ersetze den Source-Pfad durch den korrekten Build-Pfad
# <Plugins/...> → <Lts/Plugins/...>
# <Common/...> → <Lts/Common/...>
# <Services/...> → <Lts/Services/...>
# <Proxies/...> → <Lts/Proxies/...>
# <DDS/...> → <Lts/DDS/...>
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}")