Skip to content

feat(packaging): add delivery packages as recommends for Professional edition#429

Merged
qiuzhiqian merged 1 commit into
masterfrom
feat-add-delivery
Jun 2, 2026
Merged

feat(packaging): add delivery packages as recommends for Professional edition#429
qiuzhiqian merged 1 commit into
masterfrom
feat-add-delivery

Conversation

@qiuzhiqian
Copy link
Copy Markdown
Contributor

No description provided.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

CLA Assistant Lite bot:
提交邮箱中包含我们的合作伙伴,但您似乎并非合作伙伴的成员或对接人,请联系相关对接人将您添加至组织之中,或由其重新发起 Pull Request。
The commit email domain belongs to one of our partners, but it seems you are not yet a member of the current organization, please contact the contact person to add you to the organization or let them submit the Pull Request.

xml seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request

@qiuzhiqian qiuzhiqian force-pushed the feat-add-delivery branch from 3480c9b to 9f0cf94 Compare June 2, 2026 03:23
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX。我已仔细审查了你提供的 Git Diff,本次修改主要涉及 Debian 打包规则(debian/rulesdebian/control),目的是根据系统版本动态注入推荐依赖(Recommends)。

以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的审查意见和改进建议:

1. 语法与逻辑

  • 配置文件读取逻辑存在隐患(严重)
    debian/rules 中新增了 EDITION=$(shell grep EditionName= /etc/os-version | cut -d= -f 2)
    问题:如果 /etc/os-version 文件不存在,或者文件中不包含 EditionName= 这一行,grep 会失败,导致 EDITION 为空字符串。此时 ifneq ($(EDITION), Community) 依然成立,会错误地将 uos-upgrade-delivery 等包推荐给非目标系统。
    建议:增加对文件存在性或 grep 结果的判断,确保在获取不到版本信息时,不添加这些特定依赖。

  • 变量为空时的 dh_gencontrol 行为(潜在逻辑错误)
    旧代码中使用了 ifdef DistDepends 来包裹 override_dh_gencontrol,这意味着只有当 DistDepends 非空时才会重写该步骤。你移除了 ifdef,使得 dh_gencontrol 无条件执行,并传入了 $(DistDepends)$(DistRecommends)
    问题:如果 DistDependsDistRecommends 都为空,执行 dh_gencontrol -- -Vdist:Depends="" -Vdist:Recommends="" 可能会在 dpkg-gencontrol 中产生警告,甚至将空字符串写入 debian/substvars,导致生成的 deb 包 control 文件中出现空的 DependsRecommends 字段(即 Recommends: \n),这可能会引发打包工具的语法解析错误。
    建议:在传递变量时做非空判断,或者确保 dpkg 工具链能正确处理空值。更稳健的做法是动态拼接参数。

2. 代码质量

  • 硬编码的魔法字符串
    代码中硬编码了 "Community"/etc/os-versionEditionName= 等字符串。
    建议:虽然 Makefile 中硬编码相对常见,但为了提高可维护性,建议在 Makefile 顶部将其提取为变量,并添加注释说明其用途,方便未来修改。

  • 跨平台兼容性
    旧代码读取的是 /etc/deepin-version,新代码读取的是 /etc/os-version。这说明系统版本管理方式发生了变更。
    建议:如果此软件包仍需兼容旧版系统(仅有 /etc/deepin-version),当前逻辑将无法正确识别版本。如果已完全废弃旧版系统,则无妨,但建议在提交信息中明确说明此兼容性变更。

3. 代码性能

  • 冗余的 Shell 执行
    SYSTYPEEDITION 的赋值都使用了 $(shell ...),这会在 Makefile 解析阶段各 fork 出一个进程执行 shell 命令。
    问题:对于 Debian 打包过程来说,这点性能损耗微不足道,可以忽略不计。
    优化(可选):如果追求极致,可以将多次 shell 调用合并为一次,例如:
    OS_INFO := $(shell grep -E 'Type=|EditionName=' /etc/os-version 2>/dev/null)

4. 代码安全

  • 构建环境依赖与可重现构建
    读取宿主机的 /etc/os-version 文件来决定打包产物,这违反了 Debian 的可重现构建原则。
    风险:不同的开发者在不同的系统版本上执行 dpkg-buildpackage,会生成依赖不同的 deb 包。如果构建服务器被篡改了 /etc/os-version 文件,可能会打包出带有后门推送软件(uos-upgrade-delivery)的包。
    建议:在 Debian 打包规范中,通常应通过环境变量(如 DEB_BUILD_OPTIONS 或自定义变量)来控制打包变体,而不是依赖构建主机的本地文件。如果必须依赖本地文件,请确保构建环境的绝对安全。

💡 综合改进建议代码

针对上述问题,我为你优化了 debian/rules 的相关部分,增强了健壮性:

# 提取配置文件路径和关键字为变量,增加可读性和可维护性
OS_VERSION_FILE := /etc/os-version
EDITION_KEY := EditionName=
COMMUNITY_EDITION := Community

# 增加文件存在性判断,避免文件不存在时 grep 报错或返回空值导致逻辑异常
ifneq ($(wildcard $(OS_VERSION_FILE)),)
    EDITION := $(shell grep '^$(EDITION_KEY)' $(OS_VERSION_FILE) 2>/dev/null | cut -d= -f 2)
endif

depend_ostree = true

ifdef depend_ostree
	DistDepends += ostree,
endif

# 仅在 EDITION 被成功获取且不等于 Community 时添加推荐依赖
ifneq ($(EDITION),$(COMMUNITY_EDITION))
    ifdef EDITION
        DistRecommends += uos-upgrade-delivery, uos-apt-delivery,
    endif
endif

# ... 中间省略 ...

# 动态生成 dh_gencontrol 的参数,避免向 dpkg-gencontrol 传递空字符串
GENCONTROL_ARGS := $(if $(DistDepends),-Vdist:Depends="$(DistDepends)") $(if $(DistRecommends),-Vdist:Recommends="$(DistRecommends)")

override_dh_gencontrol:
	dh_gencontrol -- $(GENCONTROL_ARGS)

改动解释:

  1. 使用 wildcard 检查文件是否存在,防止 grep 报错中断构建。
  2. grep 中加入 ^ 确保匹配行首,防止包含该子串的其他行被误匹配。
  3. 增加了 ifdef EDITION 的判断,确保只有在确实读取到了版本信息时,才添加推荐依赖。
  4. override_dh_gencontrol 中,使用 $(if ...) 函数动态生成参数,只有当变量非空时才注入 -V 参数,避免了空值引发的潜在 dpkg 控制文件解析错误。

@Zeno-sole
Copy link
Copy Markdown
Collaborator

/integrate

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

AutoIntegrationPr Bot
auto integrate with pr url: deepin-community/Repository-Integration#4100
PrNumber: 4100
PrBranch: auto-integration-26796745588

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: qiuzhiqian, Zeno-sole, zhaohuiw42

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

@qiuzhiqian qiuzhiqian merged commit 944d65e into master Jun 2, 2026
22 of 29 checks passed
@qiuzhiqian qiuzhiqian deleted the feat-add-delivery branch June 2, 2026 05:09
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.

4 participants