Bug 495658 - %global does not expand %{?2:...} like %define does
%global does not expand %{?2:...} like %define does
Product: Fedora
Classification: Fedora
Component: rpm (Show other bugs)
All Linux
low Severity medium
: ---
: ---
Assigned To: Panu Matilainen
Fedora Extras Quality Assurance
Depends On:
  Show dependency treegraph
Reported: 2009-04-14 05:41 EDT by Jens Petersen
Modified: 2009-05-18 05:04 EDT (History)
5 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2009-05-18 05:04:28 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

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

  None (edit)
Description Jens Petersen 2009-04-14 05:41:47 EDT
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 06:31:47 EDT
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 13:14:18 EDT
That is fine but are the expected behaviours of the two documented somewhere?
Comment 3 Jeff Johnson 2009-04-14 13:27:17 EDT
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 19:31:00 EDT
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 07:33:07 EDT
The difference is that %define "works" and %global does not.
Comment 6 Panu Matilainen 2009-05-18 05:04:28 EDT
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.