Bug 676776 - %ifarch wrapping of definitions inside a macro function does not work
Summary: %ifarch wrapping of definitions inside a macro function does not work
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: rpm
Version: 21
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Fedora Packaging Toolset Team
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2011-02-11 06:20 UTC by Jens Petersen
Modified: 2015-07-01 12:48 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-07-01 12:48:48 UTC
Type: ---


Attachments (Terms of Use)

Description Jens Petersen 2011-02-11 06:20:31 UTC
Description of problem:
RPM seems to be evaluating global defines eagerly
inside macro definitions with %ifarch/%ifnarch?
Sorry if this is a FAQ but not sure how to solve this:
the behaviour seems a bit confusing to me.

Version-Release number of selected component (if applicable):
rpm-4.8.1-5.fc14
also tried 4.9.0 beta in rawhide

How reproducible:
every time

Steps to Reproduce:
I try to do the following say in a .spec file
(obviously this is just a testcase):

%global set_hello \
%ifarch ppc\
%global __with_hello hello\
%endif

%prep
%set_hello
echo %{?__with_hello}

Actual results:
+ echo hello
hello

Expected results:
no hello!

Additional info:
Actually the result seems to be the same for me
with "%ifarch anyblah" or "%ifnarch anyblah blah", etc.

How can I make the evaluation less eager?
I tried playing with %{expand:...} but that didn't help.
Maybe I have to make my macro file arch specific?

The context is I am trying to make some macros be
only set for ppc since ghc does not support
native shared libraries on that arch.

Comment 1 Jens Petersen 2011-02-12 12:26:23 UTC
Panu explained to me in IRC that %if[n]arch is a spec directive.

So in /usr/lib/rpm/macros does

%debug_package \
%ifnarch noarch\
%global __debug_package 1\
%package debug\
Summary: Debug information for package %{name}\
:
%endif\
%{nil}

work because %debug_package is only invoked late
in the rpmbuild process?

Anyway looks like I will have to make ghc-rpm-macros arch... ?

Comment 2 Jens Petersen 2011-02-13 09:05:17 UTC
I have worked around it for now by making ghc-rpm-macros arch.

Comment 3 Fedora Admin XMLRPC Client 2012-04-13 23:06:14 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 4 Fedora Admin XMLRPC Client 2012-04-13 23:09:21 UTC
This package has changed ownership in the Fedora Package Database.  Reassigning to the new owner of this component.

Comment 5 Fedora End Of Life 2013-04-03 16:46:00 UTC
This bug appears to have been reported against 'rawhide' during the Fedora 19 development cycle.
Changing version to '19'.

(As we did not run this process for some time, it could affect also pre-Fedora 19 development
cycle bugs. We are very sorry. It will help us with cleanup during Fedora 19 End Of Life. Thank you.)

More information and reason for this action is here:
https://fedoraproject.org/wiki/BugZappers/HouseKeeping/Fedora19

Comment 6 Jens Petersen 2015-01-08 08:50:52 UTC
This is similar to bug 495658 (or my 3rd report bug 1169111 ;)
or NOTABUG anyway I guess (ir "don't use %global inside a macro function def!").

Comment 7 Jens Petersen 2015-01-08 09:07:25 UTC
Erm, actually

%global set_hello \
%ifarch ppc\
%define __with_hello hello\
%endif

gives the same result.

Comment 8 Ľuboš Kardoš 2015-07-01 12:48:48 UTC
The problem is that "%ifarch" is not a real macro but it is a spec directive. So the rpm macro expander doesn't handle it in any special way. For the rpm macro expander "%ifarch" is just an ordinary string.

Rpm macros and directives don't provide a fully featured programming language and not everything is possible by them. But in rpm spec files it is possible to use the lua language that is more complex. You can do what you want in lua language:

%define set_hello \
%{lua:
if rpm.expand("%{_target_cpu}") == "ppc" then
    rpm.define("__with_hello hello")
end
}

...

%prep
%set_hello
echo %{?__with_hello}

Be aware that I used "%define" in above code when you replace it with "%global" then the lua code will be executed in time of definition of set_hello and not in time of calling set_hello.

I am closing this as wontfix because purpose of macros and directives is not to be fully featured programming language and for cases like this we have the lua language that is more complex.


Note You need to log in before you can comment on or make changes to this bug.