- Wrap FIND_PACKAGE(RTI) in IF(NOT TARGET RTI::nddsc) condition - Prevents placeholder targets from overwriting manually configured RTI:: targets - Manual configuration creates RTI:: targets when BUILD_RTI=ON and RTI found - FIND_PACKAGE only called as fallback when manual config doesn't create targets Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Entire-Checkpoint: 01M1CT3XSQXCX9RQR6WM9DG3GH
85 lines
3.5 KiB
Python
85 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Comprehensive fix for training_area_telegrams.h and .cpp
|
|
Fixes:
|
|
1. Remove BatteryAlarm::id() method (conflicts with final override in template)
|
|
2. Fix fromJson: ret.field → ret.m_field
|
|
3. Fix toJson: QJsonObject({...}) → QJsonObject{{...}}
|
|
4. Fix toJson: method calls need () in initializer lists
|
|
"""
|
|
|
|
import re
|
|
|
|
def fix_header():
|
|
"""Fix training_area_telegrams.h"""
|
|
with open('qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/training_area_telegrams.h', 'r') as f:
|
|
content = f.read()
|
|
|
|
# Remove BatteryAlarm::id() method (line ~2305)
|
|
# Find the BatteryAlarm struct and remove the id() getter
|
|
battery_alarm_pattern = r'(struct BatteryAlarm : TrainingAreaTelegramTmpl<BatteryAlarm>\s*\{[^}]*?)\s+TelegramId id\(\) const \{ return static_cast<TelegramId>\(m_id\); \}'
|
|
content = re.sub(battery_alarm_pattern, r'\1', content, flags=re.DOTALL)
|
|
|
|
with open('qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/training_area_telegrams.h', 'w') as f:
|
|
f.write(content)
|
|
print("Fixed header: removed BatteryAlarm::id() method")
|
|
|
|
def fix_cpp():
|
|
"""Fix training_area_telegrams.cpp"""
|
|
with open('qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/training_area_telegrams.cpp', 'r') as f:
|
|
content = f.read()
|
|
|
|
# Fix 1: fromJson - ret.field → ret.m_field
|
|
# Pattern: get(obj, QStringLiteral("field"), ret.field);
|
|
# Need to be careful not to change nested struct assignments like ret.header
|
|
def fix_fromJson_get(match):
|
|
key = match.group(1)
|
|
# Convert camelCase field to m_field
|
|
field_name = 'm_' + key[0].lower() + key[1:] if key else key
|
|
return f'get(obj, QStringLiteral("{key}"), ret.{field_name});'
|
|
|
|
content = re.sub(
|
|
r'get\(obj, QStringLiteral\("([^"]+)"\), ret\.([a-zA-Z_][a-zA-Z0-9_]*)\);',
|
|
fix_fromJson_get,
|
|
content
|
|
)
|
|
print("Fixed fromJson: ret.field → ret.m_field")
|
|
|
|
# Fix 2: toJson - QJsonObject({...}) → QJsonObject{{...}}
|
|
content = re.sub(r'QJsonObject\(\{', 'QJsonObject{{', content)
|
|
content = re.sub(r'\}\}\);', '}};', content)
|
|
print("Fixed toJson: QJsonObject syntax")
|
|
|
|
# Fix 3: toJson - method calls in initializer lists need ()
|
|
# Pattern: {QStringLiteral("key"), methodName} → {QStringLiteral("key"), methodName()}
|
|
# But only for methods, not for member variables or already-called methods
|
|
# This is tricky - we need to identify getter method calls
|
|
def fix_method_call(match):
|
|
key = match.group(1)
|
|
value = match.group(2)
|
|
# Skip if already has ()
|
|
if value.endswith('()'):
|
|
return match.group(0)
|
|
# Skip if it's a number/string literal
|
|
if value[0].isdigit() or value[0] == '"' or value.startswith('qint') or value.startswith('QLatin1'):
|
|
return match.group(0)
|
|
# Skip arrayToJson, enumToJson, etc.
|
|
if '(' in value:
|
|
return match.group(0)
|
|
# Assume it's a getter method that needs ()
|
|
return f'{{QStringLiteral("{key}"), {value}()}}'
|
|
|
|
content = re.sub(
|
|
r'\{QStringLiteral\("([^"]+)"\), ([a-zA-Z_][a-zA-Z0-9_]*)\}',
|
|
fix_method_call,
|
|
content
|
|
)
|
|
print("Fixed toJson: method calls")
|
|
|
|
with open('qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Proxies/TrainingAreaBase/training_area_telegrams.cpp', 'w') as f:
|
|
f.write(content)
|
|
|
|
if __name__ == '__main__':
|
|
fix_header()
|
|
fix_cpp()
|
|
print("Done!") |