-
Notifications
You must be signed in to change notification settings - Fork 91
feat: add version macros and property definitions to dconfig2cpp #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
1. Added version macros (VERSION_MAJOR/VERSION_MINOR) to generated header files for version tracking 2. Added property definition macros for all configuration properties to facilitate caller compatibility 3. Added version compatibility check in dconfig2cpp tool to warn when JSON file version exceeds supported version 4. Updated header comment to include dconfig2cpp tool version information 5. Added version struct and supported version constant to main.cpp 6. Modified code generation to output property macros before class definition Log: Added version and property macros to dconfig2cpp generated files for better compatibility Influence: 1. Test dconfig2cpp tool with JSON files of different versions (older, same, newer) 2. Verify generated header files contain correct version macros 3. Check that property definition macros are generated for all configuration properties 4. Test compilation of projects using the generated header files 5. Verify backward compatibility with existing code using the generated classes 6. Test version warning mechanism when using newer JSON files feat: dconfig2cpp添加版本宏和属性定义宏 1. 在生成的头文件中添加版本宏(VERSION_MAJOR/VERSION_MINOR)用于版本跟踪 2. 为所有配置属性添加属性定义宏,方便调用方兼容性处理 3. 在dconfig2cpp工具中添加版本兼容性检查,当JSON文件版本超过支持版本时发 出警告 4. 更新头文件注释以包含dconfig2cpp工具版本信息 5. 在main.cpp中添加版本结构和支持的版本常量 6. 修改代码生成逻辑,在类定义之前输出属性宏 Log: 为dconfig2cpp生成的文件添加版本和属性宏,提高兼容性 Influence: 1. 测试dconfig2cpp工具处理不同版本(旧版、相同、新版)的JSON文件 2. 验证生成的头文件包含正确的版本宏 3. 检查是否为所有配置属性生成了属性定义宏 4. 测试使用生成头文件的项目的编译情况 5. 验证与现有使用生成类的代码的向后兼容性 6. 测试使用新版JSON文件时的版本警告机制
deepin pr auto review这份代码审查将针对提供的 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结与改进建议总体来看,这次改动增加了工具版本信息的记录和生成代码的宏定义,有助于版本追踪和条件编译。但在处理输入(版本号和配置项名称)时的健壮性有待加强。 关键修改建议总结:
针对 // 建议在 main.cpp 中添加一个辅助函数来清理属性名,用于生成宏
QString sanitizeMacroName(const QString &input) {
QString result;
// 简单的过滤逻辑:只保留字母数字和下划线
// 注意:这只是示例,可能需要更复杂的逻辑来处理开头是数字的情况
for (const QChar &ch : input) {
if (ch.isLetterOrNumber() || ch == '_') {
result.append(ch);
} else {
result.append('_'); // 将非法字符替换为下划线
}
}
// 确保不以数字开头
if (!result.isEmpty() && result[0].isDigit()) {
result.prepend('_');
}
return result;
}
// 在生成宏的地方使用
for (const QString &propName : allPropertyNames) {
QString safeName = sanitizeMacroName(propName);
headerStream << "#define " << className.toUpper() << "_DCONFIG_FILE_" << safeName << "\n";
}针对版本检查逻辑的修改建议代码片段: // Parse version to get major
QString fileMajorVersion;
const auto versionParts = version.split('.');
// 逻辑改进:只要不为空就取第一部分
if (!versionParts.isEmpty()) {
fileMajorVersion = versionParts.first();
}
// 检查是否为空或不是数字(简单的健壮性检查)
bool ok;
int majorVer = fileMajorVersion.toInt(&ok);
if (!ok || majorVer != 1) {
qWarning() << QLatin1String("Warning: The JSON file version isn't supported. Expected major version 1.");
return -1;
} |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, zccrs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
header files for version tracking
facilitate caller compatibility
JSON file version exceeds supported version
information
definition
Log: Added version and property macros to dconfig2cpp generated files
for better compatibility
Influence:
same, newer)
configuration properties
classes
feat: dconfig2cpp添加版本宏和属性定义宏
出警告
Log: 为dconfig2cpp生成的文件添加版本和属性宏,提高兼容性
Influence: