本文介绍了转速和rpmbuild - 在 %files 部分使用全局环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为这个而苦苦挣扎.所以我为我的项目写了一个 .specs 文件,一切都很好.rpm 已经构建好了,安装很顺利……但是后来我遇到了一些麻烦,因为现在我必须使用自定义的全局环境变量来设置安装路径.

I have been struggling for a while with this one.So I wrote a .specs file for my project and everything went fine. The rpm is built, the installation is smooth... but then I got some trouble because now, I have to use a custom global environment variable to set the install path.

这将给出一个 %files 部分:

This would give a %files section as such :

%files
%defattr(-,root,root)
$INSTALLPATH/Crystal/bin/Crystal.jar

Crystal 是我的项目名称,INSTALLPATH 是在 env 中定义的,这要归功于导出命令行.然后,运行时buildrpm -ba Crystal.specs我有以下错误:

Where Crystal is my project name, and INSTALLPATH is defined within env thanks to the export commandline. Then, when running buildrpm -ba Crystal.specsI have the following error:

error: File must begin with "/" : $INSTALLPATH/Crystal/bin/Crystal.jar

我试图在 .rpmmacros 文件中定义一个宏:%_installpath $INSTALLPATH

I have tried to define a macro inside the .rpmmacros file as such : %_installpath $INSTALLPATH

在我的规格文件中,当我这样做时回声%{_installpath}我得到了我在 .rpmmacros 中设置的值.但是如果我在 %files 中使用它:

And in my specs file, when i do echo %{_installpath}I get the value I set in the .rpmmacros. But if I use it in %files:

%files
%defattr(-,root,root)
%{_installpath}/Crystal/bin/Crystal.jar

我又犯了同样的错误!

error: File must begin with "/" : $INSTALLPATH/Crystal/bin/Crystal.jar

我还尝试使用规范文件定义一个变量,但结果同样令人难过.看起来只要我的变量/宏引用 $INSTALL,那么 %files 就不会接受它.但是我必须使用这个环境变量!

I also tried defining a variable with the specs file and I have the same sad result. It looks like as long as my variable/macro is referencing to $INSTALL, then %files won't accept it. But I have to use this env variable!

这就是我能想到的.有人有线索吗?任何帮助将不胜感激.

So that's all I could think about. Anyone got a clue? Any help would be greatly appreciated.

非常感谢!

推荐答案

%files 部分不扩展 shell 变量.你不能那样做.

The %files section does not expand shell variables. You cannot do this that way.

你有几个我可以看到的选项.你可以

You have a couple options that I can see offhand. You can

  • 生成包含文件列表的文件(在 %install 或 what-have-you 期间),然后使用 %files -f files.lst

  • generate a file with a list of your files (during %install or what-have-you) and then use %files -f files.lst

在 rpm 宏定义时扩展 $INSTALLPATH:

expand $INSTALLPATH at rpm macro definition time with:

# For RPM >= 4.7.0
%_installpath %{getenv:INSTALLPATH}
# For RPM < 4.7.0
%_installpath %{lua:print(os.getenv("INSTALLPATH"))}

这篇关于转速和rpmbuild - 在 %files 部分使用全局环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 19:06