[libvirt] [PATCH] spec: Guess rhel/fedora macros from dist

Eric Blake eblake at redhat.com
Wed Mar 16 15:31:13 UTC 2011


On 03/16/2011 08:34 AM, Eric Blake wrote:
> On 03/16/2011 05:54 AM, Jiri Denemark wrote:
>> ---
>> If anyone knows how to make rpm to evaluate %(...) immediately and not
>> at every appearance of rhel/fedora, that would be really cool.
> 
> It looks like %{lua: expression} is the trick to do an immediate
> evaluation; my problem is that I don't know the appropriate lua
> expression to replace your sed script.
> 
> http://www.rpm.org/wiki/PackagerDocs/RpmLua
> 
>> +++ b/libvirt.spec.in
>> @@ -1,5 +1,11 @@
>>  # -*- rpm-spec -*-
>>  
>> +# if neither fedora nor rhel was defined, try to guess them from %{dist}
>> +%if !0%{?rhel} && !0%{?fedora}
>> +%define rhel %(echo "%{?dist}" | sed -ne 's/^\\.el\\([0-9]\\+\\).*/\\1/p')
>> +%define fedora %(echo "%{?dist}" | sed -ne 's/^\\.fc\\?\\([0-9]\\+\\).*/\\1/p')
>> +%endif
> 
> This looks reasonable as is, but like you said, it would be nicer to
> compute it once.

This works for one-shot evaluation:

# if neither fedora nor rhel was defined, try to guess them from %{dist}
%if !0%{?rhel} && !0%{?fedora}
%define rhel %{lua: v=string.match(rpm.expand("%{?dist}"),
  "^%.el([0-9]+).*"); if v ~= nil then print(v) end}
%define fedora %{lua: v=string.match(rpm.expand("%{?dist}"),
 "^%.fc?([0-9]+).*"); if v ~= nil then print(v) end}
%endif

It creates a temporary lua variable which is either nil or the matched
substring, and prints only the matched substring.

I tested it with lots of %{echo:...} and various manipulations of
%define/%undefine.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20110316/43b88739/attachment-0001.sig>


More information about the libvir-list mailing list