rpmbuild fails on nested user-defined %if* macros

Panu Matilainen pmatilai at laiskiainen.org
Tue Oct 2 06:48:50 UTC 2012

On 10/02/2012 05:44 AM, Mike Miller wrote:
> Hi, a regression has come up between rpmbuild 4.9 and 4.10 and I want to
> know if this was intentional or not. Here is an artificial test-case
> spec file that illustrates the regression:
> %define if_some_value() %{expand:%if "%{_some_value}" == "%1" || "%{_some_value}" == "%2"}
> Summary: Test case spec file for LP #1058378
> Name: test-pkg
> Version: 1.0.0
> Release: 1
> License: GPL
> Group: Development/Languages
> %description
> Test case spec file for LP #1058378
> %prep
> %if_some_value foo bar
> echo first case
> %else
> %if_some_value shibboleet
> echo second case
> %else
> echo third case
> %endif
> %endif
> If the first conditional is false, there is no problem. If the first
> conditional is true (e.g. rpmbuild -D"_some_value foo"), rpmbuild 4.9
> succeeds but 4.10 fails with
> error: /home/mike/lp-1058378.spec:19: Got a %endif with no %if
> So it looks to me like user-defined %if* macros are supported, but not
> if one appears in the false branch of a conditional. I think this commit
> http://rpm.org/gitweb?p=rpm.git;a=commitdiff;h=3a102207154bc9e695d8875d6f01fd98fc8783c7
> is responsible for the change in behavior that produces this error, but
> I'm not sure if the intention was to continue supporting such
> user-defined %if* macros or not. Can someone clarify? Thanks.
> Original bug report: https://bugs.launchpad.net/bugs/1058378

Hum, interesting case.

As a general rule, macros are not supposed to be expanded in a false 
branch of an %if, but the former implementation gets confused enough to 
let it through as *both* %if and a macro, expanding the macro when it 
technically shouldn't.

This and other similar mixups is pretty much exactly what the commit you 
mention was intended to fix, and it might be hard to convince me to 
revert that as the same can be achieved without abusing the spec parser.
Simply move the "%if" out of the macro:

%define some_value() %{expand:"%{_some_value}" == "%1" || 
"%{_some_value}" == "%2"}

%if %some_value foo

The careful reader might notice that this too actually circumvents the 
"macros should not be expanded in false branch" rule: the arguments to 
%if get always expanded, false branch or not.

	- Panu -

More information about the Rpm-list mailing list