我正在尝试从 RHEL8.2 机器上的 python 应用程序构建 RPM。
脚本上的 shebangs 已正确设置为
#!/usr/bin/python3
然而,由于某种原因,当 RPM 构建时,shebang 会更改为 #!/usr/libexec/platform-python -s
。
我几乎尝试了一切。
%undefine __brp_mangle_shebangs
但是shebangs仍然改变了。
这是规格文件的相关部分:
%undefine __brp_mangle_shebangs
Name: myapp
Version: 2.0.0
Release: 1%{?dist}
summary: rpm for my APP
BuildArch: noarch
### Build Dependencies ###
BuildRequires: python3-setuptools
BuildRequires: python3-devel
%?python_enable_dependency_generator
%build
%py3_build
%install
%py3_install
%files
....
我可以将
python*-rpm-macros
添加到规格中,这会将 shebang 设置为类似 /usr/bin/python3.6
之类的内容,但它的限制性太大。我们的代码可以在任何> python3.6 中工作,因此如果我们在使用 python3.8 的系统中部署 rpm,它应该可以工作。
如何设置 /usr/bin/python3 或在 python 脚本上保持 shebang 不变? rpm什么时候打包的?
%undefine __brp_mangle_shebangs
对我有用。
$ rpmbuild --version
RPM version 4.14.3
也许您需要将其放在序言中?例如:
Name: myapp
Version: 2.0.0
Release: 1%{?dist}
summary: rpm for my APP
BuildArch: noarch
### Build Dependencies ###
BuildRequires: python3-setuptools
BuildRequires: python3-devel
## Fixes
# disable shebang mangling of python scripts
%undefine __brp_mangle_shebangs
...
还请注意,似乎有一些额外的变量可以提供更细粒度的控制,但我还没有尝试过这些:
基于shebang排除:
%global __mangle_shebangs_exclude ruby
基于路径排除:
%global __mangle_shebangs_exclude_from /test/
参考:https://src.fedoraproject.org/rpms/redhat-rpm-config/pull-request/19
我还要指出,上面引用的文档是不正确的:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/packaging_and_distributing_software/advanced-topics第4.6.2节
防止BRP脚本检查和修改解释器 指令,使用以下 RPM 指令:
%取消定义%brp_mangle_shebangs
就这样
%undefine __brp_mangle_shebangs
我遇到了这个。将
%undefine __brp_mangle_shebangs
添加到规范文件中没有任何效果,规范文件仍然从 #!/usr/bin/python3
损坏为 #!/usr/libexec/platform-python
。但是,当将其作为命令行参数发送时,即 $ rpmbuild --undefine __brp_mangle_shebangs -bb <specfile>
处理了它。