Files
qt6-migration-pipeline/fix_generated_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

103 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""
Fix include paths for generated files in Qt6 migration.
Generated files like *_dtc.h, *_fts.h, *_dts.h, *_enums.idl, *.idl
are placed in the build directory without the module path prefix.
This script converts:
#include <ModuleName/generated_file.h>
to:
#include "generated_file.h"
for known generated file patterns.
"""
import os
import re
import sys
from pathlib import Path
# Patterns for generated files
GENERATED_PATTERNS = [
r'.*_dtc\.h$', # Data Topic Client
r'.*_ftc\.h$', # Fault Topic Client
r'.*_dts\.h$', # Data Topic Server
r'.*_fts\.h$', # Fault Topic Server
r'.*_enums\.idl$', # IDL enums
r'.*\.idl$', # Other IDL files
r'.*_export\.h$', # Export headers
]
def is_generated_file(filename):
"""Check if filename matches a generated file pattern."""
for pattern in GENERATED_PATTERNS:
if re.match(pattern, filename):
return True
return False
def fix_includes_in_file(filepath):
"""Fix include paths in a single file."""
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
original = content
lines = content.split('\n')
fixed_count = 0
for i, line in enumerate(lines):
# Match #include <path/to/file.h>
match = re.match(r'#include\s+<([^>]+)>', line)
if match:
include_path = match.group(1)
filename = os.path.basename(include_path)
# Only fix if path contains a directory separator (not just filename)
if '/' not in include_path:
continue
# Check if this is a generated file
if is_generated_file(filename):
# Replace with quoted include (relative to build directory)
new_line = line.replace(f'<{include_path}>', f'"{filename}"')
if new_line != line:
lines[i] = new_line
fixed_count += 1
print(f"Fixed: {filepath}:{i+1}: {filename}")
if fixed_count > 0:
with open(filepath, 'w', encoding='utf-8') as f:
f.write('\n'.join(lines))
return fixed_count
def main():
if len(sys.argv) < 2:
print("Usage: fix_generated_includes.py <directory>")
sys.exit(1)
base_dir = Path(sys.argv[1])
if not base_dir.exists():
print(f"Error: Directory {base_dir} does not exist")
sys.exit(1)
total_fixed = 0
file_count = 0
# Find all .h, .hpp, .cpp files
for ext in ['*.h', '*.hpp', '*.cpp', '*.cc']:
for filepath in base_dir.rglob(ext):
# Skip autogen directories
if 'autogen' in str(filepath).lower():
continue
fixed = fix_includes_in_file(filepath)
if fixed > 0:
file_count += 1
total_fixed += fixed
print(f"\nTotal files fixed: {file_count}")
print(f"Total includes fixed: {total_fixed}")
if __name__ == '__main__':
main()