Using spec info, on conditional expansion
Hi,
I have to list
- requires
- build_requires
but for a specific condition.
Can I do this actually ?
Regards,
Can you give me an example?
Do you mean you want to conditionally (depending on a global %define) parse the spec file? I'd imagine a spec file written for both, Fedora and CentOS, and you want only the BuildRequires for the Fedora-branch?
Hi @bkircher,
I mean parsing RPM spec fur for a specific target.
I'm creating a command line tool (https://github.com/waghanza/builder) to create binary packages (RPM for now).
This tool has to setup an environment (docker, cloud or else), that have set-up the packages in BuildRequires.
Sometimes, BuildRequires are conditional, I mean, for example :
%if 0%{?_with_systemd}
# Required for %%post, %%preun, %%postun
Requires: systemd
%if 0%{?fedora} >= 18 || 0%{?rhel} >= 7
BuildRequires: systemd
%else
BuildRequires: systemd-units
%endif
%else
# Required for %%post and %%preun
Requires: chkconfig
# Required for %%preun and %%postun
Requires: initscripts
%endif
(from https://github.com/puppetlabs/puppet/blob/master/ext/redhat/puppet.spec.erb)
and I'd :heart: to read spec with a filter, like
spec = Spec.from_file('puppet.spec',target=('fedora','18'))
Regards,
PS : I hope, I'm clear
Yes, thats pretty clear. Thanks.
I think it's a good idea. Never needed it myself yet but I'd be willing to merge any PRs regarding this. Not sure if I have the time myself to implement this right now.
if we can agree on a syntax, I'll be glad to do this ;-) (but make take some times)
I need this feature on my own, so ...
for me the main idea is to restrict parser lisibility, on conditional
conditional could be a string or a set, so adding this as a parameter to from_file seems to be accurate
for %if 0%{?_with_systemd}, usages could be
Spec.from_file('puppet.spec',target='_with_systemd') # reading
Spec.from_file('puppet.spec') # reading
Spec.from_file('puppet.spec') # not reading
for %if 0%{?fedora} >= 18 || 0%{?rhel} >= 7, usages could be
Spec.from_file('puppet.spec') # reading
Spec.from_file('puppet.spec',target=('fedora',15) # not reading
Spec.from_file('puppet.spec',target=('fedora',19) # reading
Spec.from_file('puppet.spec',target=('rhel',7) # reading
Spec.from_file('puppet.spec',target=('rhel',6) # not reading