Linux $RPM_BUILD_ROOT 究竟是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8084796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What actually is $RPM_BUILD_ROOT?
提问by Amumu
In the process of building an RPM package, I have to specify the BuildRoot and later will be used in %install which invovles $RPM_BUILD_ROOT. I always think that $RPM_BUILD_ROOT is the fake installation for RPM to perform packaging. Then, at install time using the RPM package, it will install into actual location. For example:
在构建 RPM 包的过程中,我必须指定 BuildRoot,稍后将在涉及 $RPM_BUILD_ROOT 的 %install 中使用。我一直认为 $RPM_BUILD_ROOT 是 RPM 执行打包的假安装。然后,在安装时使用 RPM 包,它将安装到实际位置。例如:
$RPM_BUILD_ROOT/usr/bin
I thought that $RPM_BUILD_ROOT is for the packaging process only, and in some ways RPM can distinguish the $RPM_BUILD_ROOT and the actual install location when the user performs "rpm -ivh package.rpm" will be /usr/bin.
我以为$RPM_BUILD_ROOT只是为了打包过程,在某些方面RPM可以区分$RPM_BUILD_ROOT,用户执行“rpm -ivh package.rpm”时实际安装位置会是/usr/bin。
But recently upon reading some documents, it is suggested that $RPM_BUILD_ROOT is the actual location which will be installed, and the $RPM_BUILD_ROOT is specified by user with the setting of environment variable $RPM_BUILD_ROOT in order to let the users install the package in their desire locations. Otherwise, $RPM_BUILD_ROOT will be null and it will install into the default location. In the above case, it is /usr/bin . Thus, $RPM_BUILD_ROOT is not just for packaging or "fake installation" process, but is a way for user to define install location, similar to select folder location in Windows.
但是最近看了一些文档,建议 $RPM_BUILD_ROOT 是实际安装的位置,$RPM_BUILD_ROOT 是用户通过设置环境变量 $RPM_BUILD_ROOT 来指定的,以便用户按照自己的意愿安装包地点。否则, $RPM_BUILD_ROOT 将为空,并将安装到默认位置。在上述情况下,它是 /usr/bin 。因此,$RPM_BUILD_ROOT 不仅仅是用于打包或“假安装”过程,而是一种用户定义安装位置的方式,类似于 Windows 中的选择文件夹位置。
I don't know my thinking is correct or not. Can someone please verify? Thanks in advance.
我不知道我的想法是否正确。有人可以验证吗?提前致谢。
采纳答案by thkala
$RPM_BUILD_ROOT
(or the equivalent %{buildroot}
SPEC file macro) alwaysholds the directory under which RPM will look for any files to package. The RPM scripts (e.g. the script that compresses the manual pages) will also use that value to know where to look for the files that were just installed. Normally, this value will be non-empty and contain a location away from the system directories - usually somewhere under /tmp
or /var/tmp
.
$RPM_BUILD_ROOT
(或等效的%{buildroot}
SPEC 文件宏)始终保存 RPM 将在其下查找要打包的任何文件的目录。RPM 脚本(例如压缩手册页的脚本)也将使用该值来知道在哪里查找刚刚安装的文件。通常,此值将是非空的,并且包含远离系统目录的位置 - 通常位于/tmp
或下的某个位置/var/tmp
。
The author of the SPEC file is expected to make sure that make install
(or whatever installer the software in question is using) will place any files under $RPM_BUILD_ROOT
, with the same hierarchy that should be used when the software is finally installed. E.g. to have RPM install ls
in /bin/ls
, the %install
SPEC file section should make sure that ls
is placed in $RPM_BUILD_ROOT/bin/ls
.
SPEC 文件的作者应确保make install
(或相关软件使用的任何安装程序)将所有文件放置在 下$RPM_BUILD_ROOT
,并具有最终安装软件时应使用的相同层次结构。例如,有RPM安装ls
中/bin/ls
,在%install
SPEC文件部分应该确保ls
被放置在$RPM_BUILD_ROOT/bin/ls
。
The author of the SPEC file is also expected to use the BuildRoot:
tag to specify a proper location. Alternatively, the build system could have an rpmrc
RPM configuration file with a proper entry. In any casethe build root should be set, so that:
SPEC 文件的作者也应该使用BuildRoot:
标签来指定一个合适的位置。或者,构建系统可以有一个rpmrc
带有正确条目的RPM 配置文件。在任何情况下都应该设置构建根,以便:
Normal users will be able to build the source package.
Should the superuser ever build the source package, the build process will not clobber any system files, unless the superuser installs the resulting binary package. And yes, there may be a good reason to build somepackages as
root
- for example, running the fullglibc
testsuite requiresroot
privileges for some tests.
普通用户将能够构建源包。
如果超级用户构建了源包,构建过程将不会破坏任何系统文件,除非超级用户安装生成的二进制包。是的,可能有一个很好的理由来构建一些包
root
——例如,运行完整的glibc
测试套件需要root
一些测试的特权。
That said, RPM can and will build a package with an empty build root variable. In that case both the build install and the final destination locations will coincide. A potential call to e.g. make install
will use the default locations, thus clobbering the system files under e.g. /usr/lib
if run with sufficient privileges. Additionally, having /usr/bin/*
in your %files
section will happily pull the whole contents of the build host /usr/bin/
directory into your binary package.
也就是说,RPM 可以并且将会使用空的构建根变量构建一个包。在这种情况下,构建安装和最终目标位置将重合。对 eg 的潜在调用make install
将使用默认位置,从而破坏 eg 下的系统文件,/usr/lib
如果以足够的权限运行。此外,/usr/bin/*
在您的%files
部分中将很乐意将构建主机/usr/bin/
目录的全部内容拉入您的二进制包中。
Bottom line:
底线:
Never use an empty build root.
Do not build packages as
root
unless there is absolutely no other way.
永远不要使用空的构建根。
root
除非绝对没有其他方法,否则不要构建包。
回答by Martin Zeitler
the file ~/.rpmmacrosdefines the paths per user:
文件~/.rpmmacros定义了每个用户的路径:
%_topdir %(echo $HOME)/rpmbuild
%_tmppath %{_topdir}/tmp
and one can also define them with rpmbuild command line parameters:
还可以使用 rpmbuild 命令行参数定义它们:
rpmbuild --define '_topdir /home/username/rpmbuild'