Skip to content

build: add Qt6 runtime detection when os-version is unavailable#288

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/tmpfrom
liyigang1:develop/tmp
May 8, 2026
Merged

build: add Qt6 runtime detection when os-version is unavailable#288
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/tmpfrom
liyigang1:develop/tmp

Conversation

@liyigang1
Copy link
Copy Markdown
Contributor

When /etc/os-version does not exist MAJOR_VERSION defaults to 99 Previously this always assumed Qt6 was available and set USE_QT6=yes Now uses pkg-config --exists Qt6Core to check actual Qt6 installation Falls back to Qt5 if Qt6Core is not found on the system Also outputs HAS_QT6 status in the diagnostic logging section

Influence:

  1. Build will correctly fallback to Qt5 when Qt6 is not installed
  2. Prevents build failures on systems without /etc/os-version or Qt6
  3. Diagnostic output now shows Qt6 detection result for debugging
  4. MAJOR_VERSION >= 21 path remains unchanged

build: 在 os-version 不可用时添加 Qt6 运行时检测

当 /etc/os-version 不存在时 MAJOR_VERSION 默认为 99
此前始终假设 Qt6 可用并设置 USE_QT6=yes
现在使用 pkg-config --exists Qt6Core 检测 Qt6 实际安装情况
如果系统未安装 Qt6Core 则回退到 Qt5
同时在诊断日志中输出 HAS_QT6 检测状态

Influence:

  1. 未安装 Qt6 时构建将正确回退到 Qt5
  2. 防止在缺少 /etc/os-version 或 Qt6 的系统上构建失败
  3. 诊断输出现在显示 Qt6 检测结果便于调试
  4. MAJOR_VERSION >= 21 的路径保持不变

When /etc/os-version does not exist MAJOR_VERSION defaults to 99
Previously this always assumed Qt6 was available and set USE_QT6=yes
Now uses pkg-config --exists Qt6Core to check actual Qt6 installation
Falls back to Qt5 if Qt6Core is not found on the system
Also outputs HAS_QT6 status in the diagnostic logging section

Influence:
1. Build will correctly fallback to Qt5 when Qt6 is not installed
2. Prevents build failures on systems without /etc/os-version or Qt6
3. Diagnostic output now shows Qt6 detection result for debugging
4. MAJOR_VERSION >= 21 path remains unchanged

build: 在 os-version 不可用时添加 Qt6 运行时检测

当 /etc/os-version 不存在时 MAJOR_VERSION 默认为 99
此前始终假设 Qt6 可用并设置 USE_QT6=yes
现在使用 pkg-config --exists Qt6Core 检测 Qt6 实际安装情况
如果系统未安装 Qt6Core 则回退到 Qt5
同时在诊断日志中输出 HAS_QT6 检测状态

Influence:
1. 未安装 Qt6 时构建将正确回退到 Qt5
2. 防止在缺少 /etc/os-version 或 Qt6 的系统上构建失败
3. 诊断输出现在显示 Qt6 检测结果便于调试
4. MAJOR_VERSION >= 21 的路径保持不变
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

  • 检测到debian目录文件有变更: debian/rules

@github-actions github-actions Bot requested a review from liujianqiang-niu May 8, 2026 08:35
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@liyigang1
Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot
Copy link
Copy Markdown

deepin-bot Bot commented May 8, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 87c5d9d into linuxdeepin:develop/tmp May 8, 2026
17 of 21 checks passed
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码主要是针对 Debian 打包规则文件 debian/rules 的修改,目的是在无法确定系统版本(MAJOR_VERSION 为 99)时,通过检查 pkg-config 来动态判断是否使用 Qt6。

以下是对该代码的详细审查和改进意见:

1. 语法逻辑

审查意见:
逻辑基本通顺。当 MAJOR_VERSION 为 99 时,引入了 pkg-config 检查机制作为后备方案,这是一个很好的防御性编程实践。
但是,MAJOR_VERSION 的赋值逻辑(虽然不在 diff 中显示,但从上下文推断)是将文件不存在的情况赋值为 99。在 Makefile 中,使用 shell 命令进行字符串比较和数字比较需要格外小心,因为空变量或非数字变量可能会导致 shell 报错。

改进建议:

  • 确保 MAJOR_VERSION 始终是一个有效的数字字符串,避免后续的 -gt 比较或 ifeq 比较出现意外行为。
  • HAS_QT6 的检查中,使用了 pkg-config。如果 pkg-config 命令本身不存在(在某些极简构建环境中),命令会报错。建议增加对 pkg-config 是否存在的检查,或者确保 build-dependencies 中包含了它。

2. 代码质量

审查意见:

  • 代码增加了诊断信息的输出(HAS_QT6),这对于调试打包问题非常有帮助。
  • 变量命名清晰(USE_QT6, HAS_QT6)。
  • 使用了 2>/dev/null 来抑制错误输出,保持输出整洁。

改进建议:

  • 魔法数字 (Magic Number)9920 是硬编码的魔法数字。虽然 Makefile 中很常见,但建议在文件开头定义常量,例如:
    OS_VERSION_UNKNOWN := 99
    QT6_VERSION_THRESHOLD := 20
    这样代码的可读性和可维护性会更好。

3. 代码性能

审查意见:

  • 每次运行 make 时都会执行 pkg-config 命令。在构建过程中,Makefile 会被解析多次,这可能会导致重复执行 shell 命令。
  • sed 命令也是通过 $(shell ...) 立即执行的。

改进建议:

  • 对于 pkg-config 这种外部命令调用,虽然开销不大,但在复杂的构建系统中可能会累积。目前的写法在 debian/rules 这种通常只运行一次的场景下是可以接受的,无需过度优化。

4. 代码安全

审查意见:

  • 使用了 pkg-config,这是一个相对安全的方式,因为它只查询编译标志,不执行代码。
  • 2>/dev/null 隐藏了错误信息,这在生产环境中是好的,但在调试时如果 pkg-config 失败了,用户可能不知道原因。

改进建议:

  • 依赖声明:必须在 debian/control 文件的 Build-Depends 字段中显式声明 pkg-config。如果构建环境没有 pkg-configHAS_QT6 将为空或导致错误,可能导致构建失败或逻辑错误。
  • Shell 注入风险:虽然这里主要使用的是预定义变量,但在 Makefile 中使用 $(shell ...) 时要始终注意变量引用。如果 OS_VERSION_FILE 包含空格或特殊字符,可能会导致命令解析错误。建议对路径变量加引号(代码中已做 $(OS_VERSION_FILE),但在 shell 命令中最好确保引用)。

5. 综合改进代码示例

基于以上意见,优化后的代码片段如下:

# 定义常量
OS_VERSION_UNKNOWN := 99
QT6_VERSION_THRESHOLD := 20

# ... (原有 MAJOR_VERSION 赋值逻辑) ...

# 版本判断: MajorVersion > THRESHOLD 使用 Qt6, 否则使用 Qt5
USE_QT6 := $(shell if [ "$(MAJOR_VERSION)" -gt "$(QT6_VERSION_THRESHOLD)" ] 2>/dev/null; then echo yes; else echo no; fi)

# MajorVersion 为 UNKNOWN 时,检查 Qt6 是否实际安装
ifeq ($(MAJOR_VERSION),$(OS_VERSION_UNKNOWN))
# 确保命令输出 yes 或 no,处理 pkg-config 不存在或失败的情况
HAS_QT6 := $(shell command -v pkg-config >/dev/null 2>&1 && pkg-config --exists Qt6Core 2>/dev/null && echo yes || echo no)
ifeq ($(HAS_QT6),yes)
    USE_QT6 := yes
else
    USE_QT6 := no
endif
endif

# ... (后续逻辑) ...

总结

这段代码修改逻辑正确,能够解决在无法读取系统版本号时回退到检测 Qt6 安装情况的问题。主要需要关注的是确保构建依赖中包含 pkg-config,以及处理 pkg-config 命令本身可能不存在的情况。代码质量和安全性整体良好。

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