RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1259678 - %filter_setup breaks custom macros defined inside spec file
Summary: %filter_setup breaks custom macros defined inside spec file
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: rpm
Version: 6.7
Hardware: All
OS: Linux
unspecified
low
Target Milestone: rc
: ---
Assignee: Packaging Maintenance Team
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-09-03 10:49 UTC by Assen Totin
Modified: 2015-09-16 13:28 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-09-16 13:28:34 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
proof-of-concept spec file (809 bytes, text/x-matlab)
2015-09-03 10:49 UTC, Assen Totin
no flags Details

Description Assen Totin 2015-09-03 10:49:54 UTC
Created attachment 1069745 [details]
proof-of-concept spec file

Description of problem:
The %filter_setup macro in a spec file undefines any custom macro which was defined inside the spec file before the filter is run. If the macro originated on the command line, it will survive properly and will not gen undefined. 

Version-Release number of selected component (if applicable):
rpm-build-4.8.0-38

How reproducible:
Every time

Steps to Reproduce:
1. Create a spec file. Conditionally define a macro (i.e. define it with a default value if it was not defined on command line):
%{!?_example_macro:%define _example_macro example}

2. After this definition create a filter to udate the RPM metadata and call the %filter_setup macro to enable it. 

3. Build an RPM from the spec file without defining the custom macro on the command line.

Actual results:
After the %filter_setup is run, the macro is undefined. 

Expected results:
The macro stay defined after of %filter_setup runs.

Additional info:
An example spec file is attached.

If a macro is defined on command line with --define 'macro value', then %filter_setup will not touch it and it will properly expand in any subsequent section of the spec file (%install, %files etc.). However, if you do not define the macro on the command line and rely on its default value, %filter_setup will kill it, so the macro will only be defined from the point of defnition to the point where %filter_setup is run. Since the filter is usually defined and applied before %description, this makes the macro unavailable in any subsequent section (%prep, %build, %install, %files...)

When filter is not used, the default value for a macro works as expected (i.e. if macro is not defined on the command line, it gets defined inside the spec file with the specified value and properly expands throughout the spec file).

My current workaround is to move the %filter_setup before any default value definition for an undefined macro. However, this is not a fix and also breaks certain policies (e.g., EPEL guidelines).

Same issue is also present in Fedora, e.g. with rpm-build-4.12.0.1-7.fc21.

Comment 2 Ľuboš Kardoš 2015-09-16 13:28:34 UTC
You have to replace %define with %global in %{!?_example_macro:%define _example_macro example}

Have a look at [1][2].

It is possible to modify current behaviour in such a way that %define would be treated as locally scoped only within parametrized macros as suggested in [3] but if we want to do that, I prefer to do that in upstream first.

[1] http://www.redhat.com/archives/fedora-devel-list/2010-January/msg00093.html
[2] https://fedoraproject.org/wiki/Packaging:Guidelines?rd=Packaging/Guidelines#.25global_preferred_over_.25define
[3] https://bugzilla.redhat.com/show_bug.cgi?id=552944#c8


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