Bug 495658

Summary: %global does not expand %{?2:...} like %define does
Product: [Fedora] Fedora Reporter: Jens Petersen <petersen>
Component: rpmAssignee: Panu Matilainen <pmatilai>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: low    
Version: rawhideCC: ffesti, jnovy, loupgaroublond, n3npq, pmatilai
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-05-18 09:04:28 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
testcase.spec none

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

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):
4.7.0.rc1

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}