Skip to content

fix(build): use DTKCORE_CLASS_DConfigFile macro instead of find_path - #217

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/1071from
tianming-1996:fix/dconfig-compat
Aug 12, 2026
Merged

fix(build): use DTKCORE_CLASS_DConfigFile macro instead of find_path#217
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/1071from
tianming-1996:fix/dconfig-compat

Conversation

@tianming-1996

@tianming-1996 tianming-1996 commented Aug 12, 2026

Copy link
Copy Markdown

Replace hand-written find_path + HAVE_DCONFIG with dtkcore built-in
feature detection macro DTKCORE_CLASS_DConfigFile, matching the approach
used by deepin-compressor. Also guard dconfig schema install with
DSG_DATA_DIR.

用 DTKCORE_CLASS_DConfigFile 宏替代手写 find_path 检测,与归档管理器
方案保持一致;CMake 用 DSG_DATA_DIR 条件安装 schema。

Bug: https://pms.uniontech.com/bug-view-372777.html

Summary by Sourcery

Switch DConfig usage to rely on DtkCore’s DTKCORE_CLASS_DConfigFile feature macro and tighten installation conditions for the DConfig schema.

Enhancements:

  • Update runtime DConfig conditional compilation to use DTKCORE_CLASS_DConfigFile instead of the custom HAVE_DCONFIG macro.

Build:

  • Require DtkCore via CMake instead of optional discovery and remove custom DConfig header detection logic.
  • Guard installation of the DConfig schema file behind the DSG_DATA_DIR definition to match the data directory configuration.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @tianming-1996, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR replaces custom DConfig presence detection with DtkCore’s built-in DTKCORE_CLASS_DConfigFile feature macro and makes DConfig schema installation conditional on DSG_DATA_DIR, aligning build behavior with other projects (e.g., deepin-compressor).

Flow diagram for build-time DConfig detection and schema installation

flowchart TD
    A[Configure CMake] --> B[find_package DtkCore REQUIRED]
    B --> C{DTKCORE_CLASS_DConfigFile available?}
    C -->|yes| D[Compile DeviceStorage.cpp with DConfig support
#ifdef DTKCORE_CLASS_DConfigFile]
    C -->|no| E[Compile DeviceStorage.cpp without DConfig support]

    A --> F{DSG_DATA_DIR defined?}
    F -->|yes| G[install FILES APP_DCONFIG_SCHEMA
DESTINATION share/dsg/configs/com.deepin.diskmanager/]
    F -->|no| H[Skip DConfig schema installation]
Loading

File-Level Changes

Change Details Files
Replace hand-written DConfig detection with DtkCore required dependency and DTKCORE_CLASS_DConfigFile macro usage.
  • Remove manual DConfig header lookup and HAVE_DCONFIG definition from service and test CMake configurations.
  • Require DtkCore via find_package in both service and test targets.
  • Switch C++ preprocessor guards from HAVE_DCONFIG to DTKCORE_CLASS_DConfigFile around DConfig usage in DeviceStorage.cpp.
service/CMakeLists.txt
test/CMakeLists.txt
service/diskoperation/DeviceStorage.cpp
Guard DConfig schema installation with DSG_DATA_DIR to avoid installing when DSG is not available or configured.
  • Wrap the install() call for APP_DCONFIG_SCHEMA in a DSG_DATA_DIR check.
  • Keep other install() rules unchanged to preserve existing installation layout.
service/CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: max-lvs, tianming-1996

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

Use DTK feature detection and explicitly include its configuration header.

使用 DTK 特性检测并显式引入配置头,兼容不支持 DConfig 的旧版本。

Log: 修复老版本 DTK 的 DConfig 编译兼容问题
Bug: https://pms.uniontech.com/bug-view-372777.html
Influence: 1030等旧版本可正常打包,新版本继续使用DConfig配置。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码正确重构了DConfig的引入方式并优化了构建逻辑,无任何缺陷
逻辑严谨,利用官方宏替代手动探测,消除了构建脆弱性,满分通过

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

在service/CMakeLists.txt和test/CMakeLists.txt中,移除了通过get_target_property和find_path手动探测DConfig头文件并定义HAVE_DCONFIG的脆弱逻辑,改为直接使用find_package(DtkCore REQUIRED)强制引入依赖。在DeviceStorage.cpp中,通过引入dtkcore_config.h并使用DTK官方提供的DTKCORE_CLASS_DConfigFile宏进行条件编译,完全符合C++和CMake的语法与逻辑规范。同时增加的if(DEFINED DSG_DATA_DIR)守卫有效防止了变量未定义时的安装报错。

  • 2.代码质量(优秀)✓

旧代码为了解决跨版本兼容问题使用了极不优雅的Hack方式,包含多层嵌套判断,可读性和可维护性极差。新代码直接利用DTK框架原生提供的特性宏DTKCORE_CLASS_DConfigFile,代码意图清晰,大幅降低了维护成本。CMakeLists.txt中的REQUIRED关键字明确了依赖关系,DSG_DATA_DIR的守卫体现了良好的防御性编程习惯。

  • 3.代码性能(无性能问题)✓

本次修改仅涉及构建系统的条件编译逻辑调整和C++预处理宏的替换,不涉及运行时的算法复杂度变化、资源分配或系统调用,对最终生成的二进制文件运行性能无任何影响。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改消除了旧代码因探测失败导致DConfig功能意外失效的潜在配置风险,通过REQUIRED强制依赖确保了环境一致性。install指令增加的DSG_DATA_DIR守卫避免了在非标准环境下可能产生的异常文件安装行为,整体代码无命令注入、路径遍历等安全风险。

  • 建议:保持当前的安全编码实践,后续新增外部依赖时优先采用官方提供的特性宏进行条件编译判断

■ 【改进建议代码示例】

# 当前代码已足够优秀,以下为保持一致性的最佳实践展示
# service/CMakeLists.txt
find_package(DtkCore REQUIRED)
find_package(DtkGui REQUIRED)

# 确保所有可能受环境变量影响的安装操作都有守卫
if(DEFINED DSG_DATA_DIR)
    install(FILES ${APP_DCONFIG_SCHEMA} DESTINATION share/dsg/configs/com.deepin.diskmanager/)
endif()
// service/diskoperation/DeviceStorage.cpp
#include <dtkcore_config.h>
#ifdef DTKCORE_CLASS_DConfigFile
#include <DConfig>
#endif

static QStringList ufsSpecVersions()
{
    const QStringList fallback{"300", "310", "400", "410"};
#ifdef DTKCORE_CLASS_DConfigFile
    QScopedPointer<Dtk::Core::DConfig> cfg(
        Dtk::Core::DConfig::create("com.deepin.diskmanager", "com.deepin.diskmanager.storage"));
    if (cfg && cfg->isValid()) {
        // 使用官方宏进行安全隔离,避免链接期找不到符号
        QStringList versions = cfg->value("ufsSpecVersions").toStringList();
        if (!versions.isEmpty()) {
            return versions;
        }
    }
#endif
    return fallback;
}

@tianming-1996

Copy link
Copy Markdown
Author

/merge

@deepin-bot
deepin-bot Bot merged commit 254ca07 into linuxdeepin:release/1071 Aug 12, 2026
20 checks passed
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.

3 participants