Skip to content

fix(build): make DConfig optional for 102X-107X compatibility - #215

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

fix(build): make DConfig optional for 102X-107X compatibility#215
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/1071from
tianming-1996:release/1071

Conversation

@tianming-1996

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

Copy link
Copy Markdown

Guard DConfig usage with HAVE_DCONFIG so builds succeed on older dtkcore versions that lack the DConfig header.

用#ifdef HAVE_DCONFIG保护DConfig调用,无DtkCore时回退到硬编码,
确保102X~107X全版本可编译。

Log: DConfig改为可选依赖,兼容低版本dtkcore
Bug: https://pms.uniontech.com/bug-view-372777.html
Influence: 解耦应用在102X~107X全版本可正常编译,低版本回退硬编码UFS版本列表。

Summary by Sourcery

Make DConfig usage optional so the service and tests build with or without DtkCore across 102X–107X versions.

Enhancements:

  • Guard DConfig-based UFS spec version lookup with HAVE_DCONFIG and fall back to a hardcoded version list when DConfig is unavailable.

Build:

  • Relax DtkCore from required to optional in service and test CMake configs and define HAVE_DCONFIG only when DtkCore is found.

Guard DConfig usage with HAVE_DCONFIG so builds succeed on older
dtkcore versions that lack the DConfig header.

用#ifdef HAVE_DCONFIG保护DConfig调用,无DtkCore时回退到硬编码,
确保102X~107X全版本可编译。

Log: DConfig改为可选依赖,兼容低版本dtkcore
Bug: https://pms.uniontech.com/bug-view-372777.html
Influence: 解耦应用在102X~107X全版本可正常编译,低版本回退硬编码UFS版本列表。

@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

Make DConfig an optional dependency by conditionally defining HAVE_DCONFIG when DtkCore is available and guarding all DConfig-related includes and runtime usage with that macro, falling back to a hard-coded UFS spec version list when DConfig is not present so the project builds on 102X–107X dtkcore versions.

Sequence diagram for ufsSpecVersions runtime behavior with optional DConfig

sequenceDiagram
    participant DeviceStorage
    participant DConfig

    DeviceStorage->>DeviceStorage: ufsSpecVersions()
    DeviceStorage->>DeviceStorage: create fallback list
    alt [HAVE_DCONFIG defined]
        DeviceStorage->>DConfig: Dtk::Core::DConfig::create("com.deepin.diskmanager", "com.deepin.diskmanager.storage")
        DConfig-->>DeviceStorage: cfg
        alt [cfg && cfg->isValid()]
            DeviceStorage->>DConfig: value("ufsSpecVersions")
            DConfig-->>DeviceStorage: versions
            alt [!versions.isEmpty()]
                DeviceStorage-->>DeviceStorage: return versions
            else [versions.isEmpty()]
                DeviceStorage-->>DeviceStorage: return fallback
            end
        else [cfg invalid]
            DeviceStorage-->>DeviceStorage: return fallback
        end
    else [HAVE_DCONFIG not defined]
        DeviceStorage-->>DeviceStorage: return fallback
    end
Loading

File-Level Changes

Change Details Files
Make DtkCore/DConfig an optional build dependency controlled via the HAVE_DCONFIG macro.
  • Change CMake configuration in the service module to remove the REQUIRED flag from find_package(DtkCore).
  • Define the HAVE_DCONFIG preprocessor macro only when DtkCore is found in the service build.
  • Adjust the test module CMake configuration to match the optional DtkCore behavior and define HAVE_DCONFIG when available.
service/CMakeLists.txt
test/CMakeLists.txt
Guard DConfig usage in runtime code and provide a fallback UFS spec version list when DConfig is unavailable.
  • Wrap the DConfig header include in DeviceStorage.cpp with an #ifdef HAVE_DCONFIG guard so it is only compiled when DtkCore/DConfig exists.
  • Update the ufsSpecVersions() helper to document and implement a fallback list used when DConfig is not available.
  • Wrap the DConfig-based configuration loading logic in ufsSpecVersions() with #ifdef HAVE_DCONFIG and always return the hard-coded fallback when the macro is not defined.
service/diskoperation/DeviceStorage.cpp

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

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了DtkCore依赖的可选化处理及回退机制,有效解决低版本环境构建失败问题
逻辑严密且无安全漏洞,符合满分标准

■ 【详细分析】

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

CMake中将DtkCore从REQUIRED改为可选并通过DtkCore_FOUND正确判断,C++代码中使用ifdef HAVE_DCONFIG进行条件编译,QScopedPointer防止内存泄漏,cfg有效性检查防止空指针,逻辑闭环完整

  • 2.代码质量(良好)✓

代码修改目的明确,注释清晰解释了回退机制的应用场景,符合规范且无冗余

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

在不支持DConfig的环境下直接返回静态的fallback列表,未引入额外性能开销

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码仅读取本地配置且做了严格的有效性校验,无外部输入风险

  • 建议:保持现有的安全编码习惯

■ 【改进建议代码示例】

// 当前代码已足够优秀,无需额外修改,此处展示当前最佳实践以供参考
static QStringList ufsSpecVersions()
{
    const QStringList fallback{"300", "310", "400", "410"};
#ifdef HAVE_DCONFIG
    QScopedPointer<Dtk::Core::DConfig> cfg(
        Dtk::Core::DConfig::create("com.deepin.diskmanager", "com.deepin.diskmanager.storage"));
    if (cfg && cfg->isValid()) {
        QStringList versions = cfg->value("ufs_spec_versions").toStringList();
        if (!versions.isEmpty())
            return versions;
    }
#endif
    return fallback;
}

@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

@tianming-1996

Copy link
Copy Markdown
Author

/merge

@deepin-bot
deepin-bot Bot merged commit 5ffa575 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