Skip to content

Feat:添加 RHEL 兼容 RPM Package#6352

Open
Lingbou wants to merge 1 commit into
HMCL-dev:mainfrom
Lingbou:rpm-packaging
Open

Feat:添加 RHEL 兼容 RPM Package#6352
Lingbou wants to merge 1 commit into
HMCL-dev:mainfrom
Lingbou:rpm-packaging

Conversation

@Lingbou

@Lingbou Lingbou commented Jul 9, 2026

Copy link
Copy Markdown

摘要

关联 Issue:#5937

新的 :HMCL:makeRpm 任务使用 rpmbuild 构建 RPM 包,并尽量沿用现有 Debian 包的安装布局,包括按发布渠道区分的启动命令、desktop entry、图标安装,以及通过 alternatives 注册通用的 hmcl 命令。

主要改动

  • 新增 CreateRpm Gradle task。
  • 抽出 Debian 和 RPM 共用的 Linux 包路径与启动脚本生成逻辑。
  • 新增独立的 GitHub Actions RPM job,使用 Rocky Linux 9 容器构建。
  • RPM 安装启动时设置 HMCL_PACKAGE_MANAGED=rpm,避免内置更新流程和系统包管理器安装的版本冲突。

说明

  • RPM 打包任务是可选任务,没有加入默认 build 流程。
  • 现有 Debian/Ubuntu 打包行为保持不变。
  • RPM 当前沿用现有 Debian 包的轻依赖策略,没有额外声明 Java runtime dependency。

验证

本地已验证:

  • ./gradlew :HMCL:compileJava --no-daemon --stacktrace
  • ./gradlew :HMCL:checkTranslations --no-daemon --stacktrace
  • ./gradlew :HMCL:makeDeb --no-daemon --stacktrace
  • ./gradlew :HMCL:checkstyleMain --no-daemon --stacktrace

Docker 中已验证:

  • rockylinux:9 容器内执行 ./gradlew :HMCL:makeRpm --no-daemon --stacktrace,构建成功。
  • 在干净的 rockylinux:9 容器内使用 dnf 安装并卸载生成的 RPM,安装和卸载均成功。
  • 验证生成的包可安装为 hmcl-nightly-3.16.snapshot-1.noarch
  • 验证 /usr/bin/hmcl-nightly 可执行。
  • 验证 hmcl alternatives 指向 /usr/bin/hmcl-nightly
  • 验证 wrapper 会导出 HMCL_PACKAGE_MANAGED="rpm"

@Lingbou Lingbou changed the title 添加 RHEL 兼容 RPM 打包任务 Feat:添加 RHEL 兼容 RPM Package Jul 9, 2026
@Lingbou Lingbou marked this pull request as ready for review July 9, 2026 09:08
@Minecraft269

Copy link
Copy Markdown

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces RPM package generation support and integrates package manager detection to prevent package-managed installations from performing self-updates. It refactors Linux packaging logic by extracting shared paths and launcher script generation into a new LinuxPackageFiles helper class. The review feedback suggests adding explicit attributes to the /usr/share/java/hmcl directory in the RPM spec to prevent permission issues in strict umask environments, and expanding the boolean parser in PackageManagerIntegration to recognize "no" and "off" as disabled values.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

fi

%%files
%%dir /usr/share/java/hmcl

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

目录 /usr/share/java/hmcl 在打包时使用了 %%dir /usr/share/java/hmcl,但没有指定显式属性(attributes)。如果构建环境具有严格的 umask(例如在某些加固的 CI 环境中为 0077),该目录在暂存(staging)阶段创建时会带有严格的权限(如 0700),而 rpmbuild 会直接将这些权限打包进去。这将导致非 root 用户在安装后无法访问该目录下的启动器文件。

请为该目录条目添加显式的属性设置,以确保其始终以 0755 权限安装。

Suggested change
%%dir /usr/share/java/hmcl
%%attr(0755,root,root) %%dir /usr/share/java/hmcl

Comment on lines +48 to +53
private static boolean isEnabled(@Nullable String value) {
return value != null
&& !value.isBlank()
&& !"0".equals(value)
&& !"false".equalsIgnoreCase(value);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

在许多 Linux 环境中,环境变量中的布尔标志通常会被设置为 nooff 来禁用它们。目前,isEnabled 仅检查了 0false。如果用户或脚本显式设置了 HMCL_PACKAGE_MANAGED=noHMCL_PACKAGE_MANAGED=off,它将被错误地解析为已启用(enabled)。

建议在 isEnabled 中增加对 nooff(不区分大小写)的检查,以使环境变量的解析更加健壮。

    private static boolean isEnabled(@Nullable String value) {
        return value != null
                && !value.isBlank()
                && !"0".equals(value)
                && !"false".equalsIgnoreCase(value)
                && !"no".equalsIgnoreCase(value)
                && !"off".equalsIgnoreCase(value);
    }

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.

2 participants