Bug 495658 - %global does not expand %{?2:...} like %define does
Summary: %global does not expand %{?2:...} like %define does
Alias: None
Product: Fedora
Classification: Fedora
Component: rpm
Version: rawhide
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Panu Matilainen
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2009-04-14 09:41 UTC by Jens Petersen
Modified: 2009-05-18 09:04 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2009-05-18 09:04:28 UTC
Type: ---

Attachments (Terms of Use)
testcase.spec (650 bytes, text/plain)
2009-04-14 09:41 UTC, Jens Petersen
no flags Details

Description Jens Petersen 2009-04-14 09:41:47 UTC
Created attachment 339452 [details]

Description of problem:
I recently switched one of my packages to using %global instead of %define as had been recommended to us.
Today I discovered that %global does not expand %{?2:...} like %define does, causing missing requires
in a bunch of the subpackages.

Version-Release number of selected component (if applicable):

How reproducible:
every time

Steps to Reproduce:
1. rpmbuild -bb testcase.spec
2. rpm -qp --requires ~/rpmbuild/RPMS/noarch/testcase-0-1.noarch.rpm
Actual results:
1. %define expands %{?2:...} but %global seems to ignore it.

Expected results:
%define and %global to behave the expand %{?2:...} the same way.

Comment 1 Jeff Johnson 2009-04-14 10:31:47 UTC
So use %define instead of %global.

Adding an RFE in bugzilla to state an expectation that %global should work like
%define so that Fedora packaging policy recommendations can be accurately
stated as
    Always use %global.
makes very little sense to me.

Have fun!

Comment 2 Jens Petersen 2009-04-14 17:14:18 UTC
That is fine but are the expected behaviours of the two documented somewhere?

Comment 3 Jeff Johnson 2009-04-14 17:27:17 UTC
There's not much to document.

Macro expansion proceeds through levels of recursion.

%define is wrto whatever recursion level is active, with
automatic garbage collection and %undefine upon return.

%global is just a macro defined at the top level, i.e. level 0.

The problem is that lusers are surprised when %define
not at level 0 disappears. This is exactly the behavior
implemented and intended, just not what lusers expect.

Are luser expected behaviors of RPM documented anywhere? ;-)

Comment 4 Jens Petersen 2009-04-14 23:31:00 UTC
Thanks for that explanation.

Given that my testcase is for level 0 %define, what is the difference in this base between %define and %global?

(Docs, muahaha;)

Comment 5 Jeff Johnson 2009-04-16 11:33:07 UTC
The difference is that %define "works" and %global does not.

Comment 6 Panu Matilainen 2009-05-18 09:04:28 UTC
The difference is that %global expands the body at definition time whereas %define doesn't. Fedora recommendation of %global over %define completely misses this point.

You can force %global to be lazily expanded with %%-escapes though:

%global globalrequires()\
Requires: %%1, %%{?2:%%2-devel}

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