Skip to content

Conversation

@deepin-ci-robot
Copy link
Contributor

Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#531

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@deepin-ci-robot
Copy link
Contributor Author

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: deepin-ci-robot

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#531
@github-actions
Copy link
Contributor

  • 敏感词检查失败, 检测到2个文件存在敏感词
详情
{
    "CMakeLists.txt": [
        {
            "line": "  HOMEPAGE_URL \"https://github.com/linuxdeepin/dtkcore\"",
            "line_number": 9,
            "rule": "S35",
            "reason": "Url link | e18a6b5679"
        }
    ],
    "docs/CMakeLists.txt": [
        {
            "line": "execute_process(COMMAND git clone https://github.com/linuxdeepin/doxygen-theme.git --depth=1",
            "line_number": 41,
            "rule": "S35",
            "reason": "Url link | d2deace9b0"
        }
    ]
}

@deepin-ci-robot
Copy link
Contributor Author

deepin pr auto review

代码审查报告

1. 总体评估

本次代码变更主要涉及DTK(Deepin Tool Kit)项目的版本管理和构建系统调整,包括:

  1. 版本命名方式的变更(DTK5/DTK6)
  2. 线程安全性和配置管理的改进
  3. 测试框架的优化
  4. 多个工具和示例的版本适配

整体来看,代码质量较高,但存在一些可以改进的地方。

2. 语法和逻辑审查

2.1 CMakeLists.txt 中的改进点

  1. 版本管理优化
# 原代码
if("${PROJECT_VERSION_MAJOR}" STREQUAL "5")
    set(QT_VERSION_MAJOR "5")
elseif("${PROJECT_VERSION_MAJOR}" STREQUAL "6")
    set(QT_VERSION_MAJOR "6")
    set(DTK_VERSION_MAJOR "6")
else()
    message(SEND_ERROR "not support Prject Version ${PROJECT_VERSION}.")
endif()

# 新代码
option(DTK5 "Build DTK5." ON)
if(DTK5)
    set(DTK_VERSION_MAJOR "5")
    set(DTK_NAME_SUFFIX "") # Empty name suffix for DTK5 products.
else()
    set(DTK_VERSION_MAJOR "6")
    set(DTK_NAME_SUFFIX "6")
endif()

评价:新代码通过option提供了更灵活的构建选项,逻辑更清晰。

建议

  • 添加对DTK5选项的验证,确保与QT版本匹配
if(DTK5 AND NOT QT_VERSION_MAJOR EQUAL 5)
    message(FATAL_ERROR "DTK5 requires Qt 5")
endif()
if(NOT DTK5 AND NOT QT_VERSION_MAJOR EQUAL 6)
    message(FATAL_ERROR "DTK6 requires Qt 6")
endif()
  1. 拼写错误
option(BUIILD_TESTING "Build tests" OFF)

问题:BUIILD_TESTING拼写错误,应为BUILD_TESTING

2.2 线程安全改进

dconfig_org_deepin_dtk_preference.hpp中,线程安全性有显著改进:

优点

  • 使用原子操作和CAS(Compare-And-Swap)保证线程安全
  • 引入状态机(Invalid→Initializing→Succeeded/Failed→Destroyed)
  • 分离数据和逻辑到Data类

潜在问题

  1. updateValue方法中,使用QMetaObject::invokeMethod可能导致信号槽调用顺序不确定
QMetaObject::invokeMethod(this, [this, newValue, key, value]() {
    Q_ASSERT(QThread::currentThread() == m_userConfig->thread());
    if (m_userConfig && p_autoDisplayFeature != newValue) {
        p_autoDisplayFeature = newValue;
        Q_EMIT m_userConfig->autoDisplayFeatureChanged();
        Q_EMIT m_userConfig->valueChanged(key, value);
    }
});

建议:考虑使用Qt::BlockingQueuedConnection确保顺序,或添加信号槽连接类型文档说明。

  1. 析构函数中的状态转换可能存在竞态条件
~dconfig_org_deepin_dtk_preference() {
    int oldStatus = m_data->m_status.fetchAndStoreOrdered(static_cast<int>(Data::Status::Destroyed));
    // ...
}

建议:添加更详细的注释说明线程安全保证,并考虑添加单元测试验证多线程场景。

2.3 测试框架改进

# 原代码
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)

# 新代码
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_options(-fsanitize=address)
    add_link_options(-fsanitize=address)
endif()

评价:改进合理,只在Debug模式下启用地址检查,避免影响Release性能。

建议

  • 添加对未定义行为的检查
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_options(-fsanitize=address -fsanitize=undefined)
    add_link_options(-fsanitize=address -fsanitize=undefined)
endif()

3. 代码质量改进

3.1 命名一致性

在多个文件中,版本后缀从DTK_VERSION_MAJOR改为DTK_NAME_SUFFIX,但部分地方仍使用旧命名:

# dtkcore.cmake
set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR}/dtk${DTK_VERSION_MAJOR}/DCore")

建议:统一使用DTK_NAME_SUFFIX,或添加命名转换函数。

3.2 代码注释

部分关键逻辑缺少注释,例如:

QPointer<Data> safeData(m_data);

QMetaObject::invokeMethod(worker, [safeData, backend, name, appId, subpath, isGeneric, worker]() mutable {
    delete worker;
    worker = nullptr;
    // ...

建议:添加注释说明使用QPointer的原因和线程安全保证。

3.3 错误处理

在配置初始化失败时:

if (!config || !config->isValid()) {
    qWarning() << QLatin1String("Failed to create DConfig instance.");
    // ...
}

建议

  • 添加更详细的错误信息,包括失败原因
  • 考虑添加错误码或错误枚举,便于调用者处理

4. 性能优化建议

  1. 减少字符串比较
if (key == QStringLiteral("autoDisplayFeature")) {
    // ...
}

建议:使用QStringLiteral或静态字符串常量,避免重复构造。

  1. 信号连接优化
connect(config, &DTK_CORE_NAMESPACE::DConfig::valueChanged, this, [this](const QString &key) {
    updateValue(key);
}, Qt::DirectConnection);

评价:使用DirectConnection是合理的,但需要确保线程安全。

建议:添加注释说明为什么使用DirectConnection,以及线程安全保证。

5. 安全性改进

  1. 输入验证
    dconfig2cpp工具中,缺少对输入JSON的验证:
QJsonDocument doc = QJsonDocument::fromJson(jsonData);
if (doc.isNull()) {
    // 处理错误
}

建议:添加更严格的输入验证,包括:

  • JSON格式验证
  • 字段类型验证
  • 必填字段检查
  1. 资源泄漏防护
    在配置初始化失败时:
if (!config || !config->isValid()) {
    // ...
    if (config)
        delete config;
    return;
}

评价:处理得当,避免了资源泄漏。

建议:考虑使用智能指针(如QScopedPointer)自动管理资源。

6. 兼容性考虑

版本变更可能影响现有代码:

set(DTK_NAME_SUFFIX "") # Empty name suffix for DTK5 products.

建议

  • 添加迁移指南
  • 提供兼容层或别名
  • 在文档中明确说明破坏性变更

7. 测试建议

  1. 添加单元测试覆盖以下场景:

    • 多线程配置读写
    • 配置初始化失败处理
    • 属性变更通知
    • 版本切换测试
  2. 添加集成测试验证:

    • DTK5/DTK6切换
    • Qt5/Qt6兼容性
    • 配置持久化

8. 文档改进建议

  1. 添加API文档说明:

    • 线程安全保证
    • 信号发射时机
    • 错误处理方式
  2. 添加构建文档:

    • DTK5/DTK6构建选项
    • 依赖要求
    • 常见问题

9. 总结

本次代码变更整体质量较高,主要改进包括:

  1. 更灵活的版本管理
  2. 增强的线程安全性
  3. 改进的测试框架

主要改进建议:

  1. 修复拼写错误(BUIILD_TESTING)
  2. 增强错误处理和日志
  3. 添加更多注释和文档
  4. 完善测试覆盖
  5. 统一命名规范

这些改进将进一步提高代码的可维护性、可靠性和性能。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants