Skip to content

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Jan 27, 2026

  • Add Qt auto-detection using find_package(QT NAMES Qt6 Qt5)
  • Separate debian/control files:
    • control: V25 (Qt6) with explicit qt6-base-dev, libdtk6*-dev deps
    • control.1: V20 (Qt5) with explicit qtbase5-dev, libdtk*-dev deps
  • Removes legacy macro-based Qt version handling and implements dynamic package name resolution for Qt, DTK, PolkitQt and QApt dependencies.

This enables seamless building on both V25 (Qt6) and V20 (Qt5) systems without version-specific conditional dependencies.

Log: 分离Qt5/Qt6构建配置,支持V25/V20双版本
PMS: https://pms.uniontech.com/task-view-386321.html

Summary by Sourcery

Unify CMake-based Qt/DTK configuration to auto-detect the Qt major version and dynamically resolve related dependency packages, and adjust Debian packaging to support separate Qt5 and Qt6 build configurations.

Enhancements:

  • Refactor CMake Qt detection to use find_package(QT NAMES Qt6 Qt5) and derive the Qt major version automatically.
  • Introduce DTK version mapping from the detected Qt version and use interpolated targets (Qt${QT_VERSION_MAJOR}, Dtk${DTK_VERSION_MAJOR}) across binaries and libraries.
  • Replace macro-based conditional Qt logic with shared component lists and dynamic package/target names for Qt, DTK, PolkitQt and QApt in all CMakeLists.
  • Simplify deepin-devicecontrol, deepin-deviceinfo and customgpuinfo build scripts to use common Qt/DTK detection and linking patterns.

Build:

  • Split Debian packaging into Qt6-focused debian/control and a new Qt5-focused debian/control.1 with corresponding build dependencies for each toolchain.

- Add Qt auto-detection using find_package(QT NAMES Qt6 Qt5)
- Separate debian/control files:
  * control: V25 (Qt6) with explicit qt6-base-dev, libdtk6*-dev deps
  * control.1: V20 (Qt5) with explicit qtbase5-dev, libdtk*-dev deps
- Removes legacy macro-based Qt version handling and implements dynamic package name resolution
for Qt, DTK, PolkitQt and QApt dependencies.

This enables seamless building on both V25 (Qt6) and V20 (Qt5) systems
without version-specific conditional dependencies.

Log: 分离Qt5/Qt6构建配置,支持V25/V20双版本
PMS: https://pms.uniontech.com/task-view-386321.html
@deepin-ci-robot
Copy link

deepin pr auto review

这份代码diff主要涉及将项目从Qt5/Qt6双版本支持迁移到仅支持Qt6,并优化了CMake构建系统的版本检测逻辑。以下是对语法逻辑、代码质量、代码性能和代码安全的详细审查意见:

1. 语法逻辑审查

优点:

  1. 版本检测优化:在根目录的CMakeLists.txt中,使用find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)统一了Qt版本的检测逻辑,比之前的if-else结构更简洁高效。
  2. DTK版本映射:新增了DTK_VERSION_MAJOR变量,将Qt版本映射到对应的DTK版本(Qt6→DTK6, Qt5→DTK5),逻辑清晰。
  3. 组件列表管理:在deepin-devicemanager/CMakeLists.txt中,使用QT_COMPONENTS列表统一管理Qt组件,便于维护和扩展。

潜在问题:

  1. Qt5支持被完全移除debian/control文件中移除了所有Qt5相关的依赖(如qtbase5-dev),仅保留Qt6依赖。这意味着项目不再支持Qt5,需确认这是预期行为。
  2. control.1文件冗余:新增的debian/control.1文件似乎是Qt5版本的配置文件,但项目已迁移到Qt6,该文件可能不再需要,建议删除或明确其用途。

2. 代码质量审查

优点:

  1. 宏替换为函数:将重复的SET_QT_VERSION宏替换为动态变量(如QT_VERSION_MAJORDTK_VERSION_MAJOR),减少了代码重复,提高了可维护性。
  2. 统一命名规范:外部依赖包名(如POLKITQT_NAMEQAPT_NAME)使用变量统一管理,避免了硬编码。

改进建议:

  1. 错误消息一致性:部分错误消息使用QT_VERSION_MAJOR,部分使用QT_VERSION,建议统一为QT_VERSION_MAJOR,例如:
    message(FATAL_ERROR "Unsupported QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")

3. 代码性能审查

优点:

  1. 减少重复检测:通过统一版本检测逻辑,避免了多次调用find_package,提高了构建效率。
  2. 组件按需加载:在deepin-devicemanager/CMakeLists.txt中,根据Qt版本动态调整QT_COMPONENTS(如移除Qt5不支持的SvgWidgets),减少了不必要的依赖。

改进建议:

  1. 缓存依赖路径:对于频繁使用的依赖(如QAPT_NAME),可以考虑缓存其路径和库文件,避免重复查找。

4. 代码安全审查

优点:

  1. 依赖版本明确debian/control中移除了可选依赖(如libqapt-dev | libqapt-qt6-dev),强制使用Qt6版本,减少了版本冲突风险。
  2. 安全编译选项保留CMakeLists.txt中保留了-Wl,-z,relro -Wl,-z,now等安全编译选项。

潜在问题:

  1. control.1文件可能引入混淆:如果control.1是旧版本配置文件,保留它可能导致构建系统误用旧依赖,建议删除或明确其用途。
  2. Qt5支持移除的影响:如果项目仍需支持Qt5(如某些旧系统),完全移除Qt5支持可能导致兼容性问题。建议确认是否需要保留Qt5支持。

5. 其他建议

  1. 文档更新:建议更新项目文档(如README.md),明确说明项目仅支持Qt6,并更新构建说明。
  2. 测试覆盖:建议添加对Qt6构建的自动化测试,确保所有模块在Qt6环境下正常工作。
  3. 清理冗余文件:检查项目中是否有其他Qt5相关的配置文件或代码片段,确保完全迁移到Qt6。

总结

这份代码diff整体质量较高,成功优化了CMake构建系统的版本检测逻辑,并统一了依赖管理。主要改进点包括:

  • 简化了Qt版本检测逻辑。
  • 动态映射DTK版本。
  • 统一管理Qt组件和外部依赖。

建议的改进方向:

  • 明确control.1文件的用途或删除。
  • 确认是否需要保留Qt5支持。
  • 统一错误消息和文档更新。

如果确认项目完全迁移到Qt6,这些修改是合理的,且不会引入明显的安全或性能问题。

@sourcery-ai
Copy link

sourcery-ai bot commented Jan 27, 2026

Reviewer's Guide

Refactors CMake-based Qt/DTK integration to rely on automatic Qt version detection and dynamic package naming for Qt, DTK, PolkitQt and QApt, and splits Debian packaging metadata into separate Qt5/Qt6 control files to support V20 (Qt5) and V25 (Qt6) builds without manual conditionals.

File-Level Changes

Change Details Files
Centralize Qt and DTK version detection and mapping at the top-level CMake and remove local SET_QT_VERSION macros.
  • Replace manual QT_VERSION_MAJOR selection logic with find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core).
  • Introduce DTK_VERSION_MAJOR set to 6 when building against Qt6 and empty otherwise, and log detected Qt/DTK versions.
  • Delete local SET_QT_VERSION helper macros from multiple CMakeLists and rely on global QT_VERSION_MAJOR / DTK_VERSION_MAJOR instead.
CMakeLists.txt
deepin-devicemanager/CMakeLists.txt
deepin-devicemanager-server/deepin-devicecontrol/CMakeLists.txt
deepin-devicemanager-server/deepin-deviceinfo/CMakeLists.txt
deepin-devicemanager-server/customgpuinfo/CMakeLists.txt
Unify Qt component discovery and linking using Qt${QT_VERSION_MAJOR} generator expressions and shared component lists.
  • Define a QT_COMPONENTS list once for deepin-devicemanager and adjust it based on QT_VERSION_MAJOR (e.g. remove SvgWidgets for Qt5).
  • Use find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ...) instead of separate Qt5/Qt6 branches in each CMakeLists.
  • Update target_link_libraries/target_include_directories to use Qt${QT_VERSION_MAJOR}::* targets so the same code path works for both Qt5 and Qt6.
deepin-devicemanager/CMakeLists.txt
deepin-devicemanager-server/deepin-devicecontrol/CMakeLists.txt
deepin-devicemanager-server/deepin-deviceinfo/CMakeLists.txt
deepin-devicemanager-server/customgpuinfo/CMakeLists.txt
Make DTK, PolkitQt, and QApt dependency resolution dynamic based on the detected Qt version.
  • Use find_package(Dtk${DTK_VERSION_MAJOR} ...) in Qt6-capable targets, while preserving legacy DtkCore/DtkWidget variables where needed for Qt5.
  • Introduce POLKITQT_NAME and QAPT_NAME variables conditional on QT_VERSION_MAJOR and use find_package(${POLKITQT_NAME}) and find_package(${QAPT_NAME}).
  • Replace hard-coded PolkitQt6-1/PolkitQt5-1, QApt-qt6/QApt names and include paths with ${POLKITQT_NAME} and ${QAPT_NAME}-derived variables in include_directories and target_link_libraries.
deepin-devicemanager/CMakeLists.txt
deepin-devicemanager-server/deepin-devicecontrol/CMakeLists.txt
deepin-devicemanager-server/deepin-deviceinfo/CMakeLists.txt
Adjust include directories and link libraries to consistently incorporate dynamically selected QApt and Qt private includes.
  • Change include_directories calls from QApt-qt6/QApt variables to ${${QAPT_NAME}_INCLUDE_DIRS} in all relevant server and UI components.
  • Standardize inclusion of QtGui private headers as ${Qt${QT_VERSION_MAJOR}Gui_PRIVATE_INCLUDE_DIRS} instead of Qt5/Qt6-specific variables.
  • Ensure QApt libraries are linked via ${QAPT_NAME} (or ${QAPT_LIB} equivalent) in all targets that require it, including conditional driver linkage.
deepin-devicemanager/CMakeLists.txt
deepin-devicemanager-server/deepin-devicecontrol/CMakeLists.txt
deepin-devicemanager-server/deepin-deviceinfo/CMakeLists.txt
Separate Debian packaging metadata for Qt5 (V20) and Qt6 (V25) builds.
  • Keep debian/control as the Qt6/V25 control file with Qt6 and libdtk6*-dev Build-Depends (not shown in diff but implied).
  • Add new debian/control.1 as the Qt5/V20 control file with explicit qtbase5-dev, libdtk*-dev, libpolkit-qt5-1-dev, libqapt-dev Build-Depends.
  • Ensure runtime Depends in control.1 continue to use Qt5/DTK5-era libraries such as libdtkcore5 and libqapt3-runtime.
debian/control
debian/control.1

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new DTK version mapping in the top-level CMakeLists.txt sets DTK_VERSION_MAJOR to an empty string for Qt5, but the sub-CMakeLists now call find_package(Dtk${DTK_VERSION_MAJOR} ...) (e.g. find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget Core REQUIRED)), which will resolve to find_package(Dtk ...) instead of the previous DtkCore / DtkWidget packages and leaves the Qt5 branches still using ${DtkCore_LIBRARIES} / ${DtkWidget_LIBRARIES} without corresponding find_package calls; this likely breaks Qt5 builds and should be aligned (either keep using the old Dtk* packages for Qt5 or introduce a consistent DTK5 package pattern).
  • In deepin-devicemanager-server/deepin-deviceinfo/CMakeLists.txt, the Qt6 branch now links ${Dtk6Core_LIBRARIES}, but find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget Core REQUIRED) typically exposes imported targets Dtk6::Core/Dtk6::Widget rather than Dtk6Core_LIBRARIES; consider switching to the imported targets consistently or ensuring that the expected *_LIBRARIES variables are actually defined by the DTK find module.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new DTK version mapping in the top-level CMakeLists.txt sets `DTK_VERSION_MAJOR` to an empty string for Qt5, but the sub-CMakeLists now call `find_package(Dtk${DTK_VERSION_MAJOR} ...)` (e.g. `find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget Core REQUIRED)`), which will resolve to `find_package(Dtk ...)` instead of the previous `DtkCore` / `DtkWidget` packages and leaves the Qt5 branches still using `${DtkCore_LIBRARIES}` / `${DtkWidget_LIBRARIES}` without corresponding `find_package` calls; this likely breaks Qt5 builds and should be aligned (either keep using the old Dtk* packages for Qt5 or introduce a consistent DTK5 package pattern).
- In `deepin-devicemanager-server/deepin-deviceinfo/CMakeLists.txt`, the Qt6 branch now links `${Dtk6Core_LIBRARIES}`, but `find_package(Dtk${DTK_VERSION_MAJOR} COMPONENTS Widget Core REQUIRED)` typically exposes imported targets `Dtk6::Core`/`Dtk6::Widget` rather than `Dtk6Core_LIBRARIES`; consider switching to the imported targets consistently or ensuring that the expected *_LIBRARIES variables are actually defined by the DTK find module.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, re2zero

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

@re2zero
Copy link
Contributor Author

re2zero commented Jan 27, 2026

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 27, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit f97d027 into linuxdeepin:master Jan 27, 2026
16 of 18 checks passed
@re2zero re2zero deleted the bugfix branch January 27, 2026 05:39
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