Bug 141535 - %{} macros are expanded in comments
Summary: %{} macros are expanded in comments
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: rpm   
(Show other bugs)
Version: 3.0
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: Jeff Johnson
QA Contact: Mike McLean
Depends On:
TreeView+ depends on / blocked
Reported: 2004-12-01 20:48 UTC by Rick Mohr
Modified: 2007-11-30 22:07 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-12-01 21:24:38 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Rick Mohr 2004-12-01 20:48:47 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3)

Description of problem:
Any macros defined in a spec file will be expanded even if they are
commented out.  This can cause unusual/undesirable behavior.

Expanding macros inside a comment is useless.  Anyone viewing a spec
file and reading the comments therein must necessarily see the
unexpanded macros.  If a comment contained a macro, the viewer would
need to process the original spec file to expand these macros.  But
then all the other macros would be expanded, so the original
documentation would not necessarily make sense in the context of the
new file because the uncommented content will have changed.

Plus, all other programming languages that I know of that include
macro capabilities ignore macros inside comments.  This includes C,
Lisp, and m4 (whose sole purpose is to expand macros for goodness sake!).

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

How reproducible:

Steps to Reproduce:
1.Define a macro outside of a comment
2.Redefine the macro inside a comment

Actual Results:  The second (commented) definition is used.

Expected Results:  The first (uncommented) definition is used.

Additional info:

Comment 1 Jeff Johnson 2004-12-01 21:24:38 UTC
Yep, macro expansion is entirely context free, macros are
expanded in comments, within quotes, on the false branch
of %if tests, everywhere.

Try escaping the % with anothe % to disable the expansion, like
   # %%{some_macro}

Comment 2 Rick Mohr 2004-12-01 22:14:15 UTC
Escaping % in a comment by adding another %% is a bad way to handle
this.  Often times I want to give an example %define within the
comment.  That means I would have to write it as %%define, and then
turn around and add a disclaimer saying that my example will not work
because you have to remove the first %.  It sort of defeats the
purpose of the documentation to start with.  Ex - 

# To define your own macro here, so something like
#       %%define cfg_localstatedir /var/tmp
# But be sure to ignore the first "%" above.  I can't show
# the real syntax because rpm's macro processor would mistakenly
# process the %define in this comment.  OH CR*P!  My explanation
# just triggered another error in rpmbuild!

(NOTE: This will indeed cause rpmbuild to fail.)

Even the /usr/lib/rpm/macros file that defines most of the macros used
by rpmbuild allows this sort of documentation:

# The configure macro does the following:
#       optionally change to a subdirectory (not implemented).
#       attempt to update config.guess and config.sub.
#       run configure with correct prefix, platform, and CFLAGS.
#       optionally restore current directory (not implemented).
# The configure macro should be invoked as %configure (rather than
# because the rest of the arguments will be expanded using %*.
# This is the version of %configure used through rpm-3.0.4.
#%configure     \
#  %{?__libtoolize:[ -f configure.in ] && %{__libtoolize} --copy
--force} \
#  CFLAGS="%{optflags}" ./configure %{_target_platform}
# This is an improved version of %configure (from PLD team).
%configure \
  CFLAGS="${CFLAGS:-%optflags}" ; export CFLAGS ; \
  CXXFLAGS="${CXXFLAGS:-%optflags}" ; export CXXFLAGS ; \
  FFLAGS="${FFLAGS:-%optflags}" ; export FFLAGS ; \
  ./configure --host=%{_host} --build=%{_build} \\\
        --target=%{_target_platform} \\\
        --program-prefix=%{?_program_prefix} \\\
        --prefix=%{_prefix} \\\
        --exec-prefix=%{_exec_prefix} \\\
        --bindir=%{_bindir} \\\
        --sbindir=%{_sbindir} \\\
        --sysconfdir=%{_sysconfdir} \\\
        --datadir=%{_datadir} \\\
        --includedir=%{_includedir} \\\
        --libdir=%{_libdir} \\\
        --libexecdir=%{_libexecdir} \\\
        --localstatedir=%{_localstatedir} \\\
        --sharedstatedir=%{_sharedstatedir} \\\
        --mandir=%{_mandir} \\\


See how nice it is to be able to adequately comment the definitions?

If you can provide even one instance of where this might be useful in
any sort of typical circumstance, I will happily concede :-)  I
haven't been able to find a good explanation for this behavior in the
other three previous bugzilla postings on this matter.

But other than that, the whole rpm concept has been great and I think
that the spec files are quite powerfule and flexible.  (And I am
serious about that!)

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