Bug 1021628

Summary: rpmbuild interprets lines which are commented out in spec files
Product: Red Hat Enterprise Linux 6 Reporter: Martin Hecht <martin.hecht>
Component: rpmAssignee: Packaging Maintenance Team <packaging-team-maint>
Status: CLOSED NOTABUG QA Contact: BaseOS QE Security Team <qe-baseos-security>
Severity: low Docs Contact:
Priority: unspecified    
Version: 6.4CC: martin.hecht, pmatilai
Target Milestone: rc   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-10-22 06:50:03 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Martin Hecht 2013-10-21 16:48:05 UTC
Description of problem:
in spec files, lines starting with '#' should be treated as comments and have no influence on the build process. However, this is not always the case. 

Version-Release number of selected component (if applicable):
RPM-Version 4.8.0
RPM-Version 4.7.2
(probably others as well)

How reproducible:


Steps to Reproduce:
1. create a spec file test.spec:

# test.spec
%{!?version: %define version 1.0}
%{!?name: %define name test}
%{!?release: %define release 1.0}
# %define is_client nothing  # this line is commented out

%{!?is_client: %define is_client 1}

Summary: Test of the rpm build system
Name: %{name}
Version: %{version}
Release: %{release}
License: GPL
Provides: %{name} = %{version}

%description
Test of the rpm build system


%prep
echo "the value of is_client is --%{is_client}--"


2. run rpmbuild -ba test.spec


Actual results:

rpmbuild -ba /usr/src/rpmbuild/SPECS/test.spec 
Ausführung(%prep): /bin/sh -e /var/tmp/rpm-tmp.enFbre
+ umask 022
+ cd /usr/src/rpmbuild/BUILD
+ echo the value of is_client is --nothing  # this line is commented out--
the value of is_client is --nothing  # this line is commented out--
+ exit 0
Prüfe auf nicht gepackte Datei(en): /usr/lib/rpm/check-files /usr/src/rpmbuild/BUILDROOT/test-1.0-1.0.i386
Erstellt: /usr/src/rpmbuild/SRPMS/test-1.0-1.0.src.rpm


Expected results:

Ausführung(%prep): /bin/sh -e /var/tmp/rpm-tmp.lFcTLx
+ umask 022
+ cd /usr/src/rpmbuild/BUILD
+ echo the value of is_client is --1--
the value of is_client is --1--
+ exit 0
Prüfe auf nicht gepackte Datei(en): /usr/lib/rpm/check-files /usr/src/rpmbuild/BUILDROOT/test-1.0-1.0.i386
Erstellt: /usr/src/rpmbuild/SRPMS/test-1.0-1.0.src.rpm

Additional info:
the value should be 1 in this case (which one could use for instance in a %if statement). It should not be influenced by something on a line starting with '#'

Comment 2 Panu Matilainen 2013-10-22 06:50:03 UTC
This is expected behavior, see http://www.rpm.org/max-rpm-snapshot/ch-rpm-specref.html

Comment 3 Martin Hecht 2013-10-22 08:38:44 UTC
Hi Panu,

Ok, but intuitively I wouldn't understand %define itself as a macro. 

If the macros which are already defined are expanded inside a comment, it wouldn't matter because the line is commented out anyway. The documentation explicitly speaks about multiline macros, that would add new lines which then "run out of the commented area", that's plausible. But %define rather seems to be a command than a macro, because it is not replaced by anything, but defines a macro. 

I would recommend to add an extra note to the documentation, that everything (including %define) is interpreted even on lines starting with a '#'-sign. The example with the %configure-macro nicely illustrates the problem with multiline macros, but the issue with %define is not that obvious.

I must admit, that I have found the list of builtin macros (http://www.rpm.org/wiki/PackagerDocs/Macros#BuiltinMacros) now, which includes %define. But since this is different from the C-preprocessor for example, I would at least add the link to this list on the page of the documentation you have posted.

best regards,
Martin