是否有任何语法或技巧可以创建多行 rpm 规范文件宏
背景。
$ rpmbuild --version RPM version 4.3.3
我正在处理一个需要处理多个 scriptlet 中的文件列表的规范文件。 DRY(不要重复)让我将列表定义为一个宏,该宏将扩展为各种帮助程序脚本。维护列表很痛苦,因为我还没有找到避免将所有文件放在同一行的方法。
%define LIST \ a \ b
给出一个错误
%define LIST a\ b\
也给出一个错误
%define LIST a %define LIST %LIST b
由于递归错误而失败
Background.
$ rpmbuild --version RPM version 4.3.3
I am working on a spec file that needs to process a list of files in multiple scriptlets. DRY (don't repeat youself) has me defining the list once as a macro which is expanded into the various helper scripts. Maintaining the list is a pain since I haven't seen a way to avoid putting all the files on the same line.
%define LIST \ a \ b
gives an error
%define LIST a\ b\
gives an error as well
%define LIST a %define LIST %LIST b
Fails due to a recursion error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您实际上无法像在 ~/.rpmmacros 文件中那样在规范文件中创建多行宏。有点傻。
我创建了一个子目录 SPECS/inc/ ,其中包含规范文件,这些文件充当多行宏,为我的站点创建的所有包都使用这些宏。您可以直接执行
%include inc/foo.spec
,而不是将宏用作%foo
。您还可以创建快捷方式以避免包含语法%global foo %include inc/foo.spec
。然后它就像多行宏一样工作。这是一个完整的例子。
inc/env.spec
inc/foo.spec
然后在我的包规范文件 mylib.spec 中:
You cannot really make multiline macros in a spec file the way you can in your ~/.rpmmacros file. Kind of silly.
I create a subdirectory SPECS/inc/ with spec files which act as multi-line macros which are used by all packages created for my site. Instead of using macros as
%foo
, you can just do%include inc/foo.spec
. You can also create shortcuts to avoid the include syntax%global foo %include inc/foo.spec
. Then it works just like a multi-line macro.Here is a complete example.
inc/env.spec
inc/foo.spec
And then in my package spec file, mylib.spec:
既然您进一步解释了您的目标,那么让我们尝试不同的方法。在您的规范文件中尝试一下:
在 Source1 文件中(在本例中为 flist):
我已经使用 rpm 4.4.6 对此进行了测试,因为这是我目前可用的最旧版本。
Since you explained your goal a bit more, let's try different approach. Try this in your spec file:
And this in Source1 file (in this case flist):
I have tested this with rpm 4.4.6 since that's the oldest version available to me at this time.
在宏定义中,行尾反斜杠被删除并用于告诉 RPM 宏定义继续。换行符不会被删除(与 make 文件不同)。因此,如果您正在构建多行脚本,则不需要分号。这也意味着,如果您要拆分单个命令,则必须使用 3 反斜杠。两个用于产生 shell 将看到的反斜杠,一个用于告诉 rpmbuild 继续解析宏。 shell 将删除它看到的反斜杠以及换行符,这将在两行上生成一个命令。 哇!!
In macro definitions, an end-of-line backslash is removed and used to tell RPM that the macro definition continues. The newline character is NOT stripped (unlike a make file). Therefore, if you are constructing a multi-line script, semi-colons are not needed. This also means that if you are splitting a single command, you must use 3 backslashes. Two to yield a backslash that the shell will see and one to tell rpmbuild to keep parsing the macro. The shell will remove the backslash it sees, plus the newline and that will yield one command on two lines. Whew !!
这个例子应该有效:
This example should work:
您必须在第一行至少包含该值的某些部分,即:
此宏定义将起作用。如果您打算将它们用作命令,即这样的东西
将不起作用。可执行部分中的行首先被分成单独的命令,然后扩展宏。即定义宏将起作用,但将其作为三个单独的命令执行则不起作用。
如果你想执行3个单独的命令,这样做更容易
You have to have at least some part of the value on the first line, i.e.:
This macro definition will work. If you plan to use these as commands, i.e. something like
this will not work. The lines in executable sections are split into separate commands first, THEN the macros are expanded. I.e. defining the macro will work, executing it as three separate commands will not.
If you want to execute 3 separate commands, it's easier to do it like
如果我是你,我会在源文件中维护该列表。
%{_sourcedir}/LIST
的内容:在规范文件中:
If I was you, I'd maintain the list in a source file.
Contents of
%{_sourcedir}/LIST
:In the spec file: