[Rpm-maint] [rpm-software-management/rpm] Unclosed %if (when defined inside %define) (#1198)

Michal Domonkos notifications at github.com
Tue Aug 18 08:28:01 UTC 2020


Having revisited this again, I think I have a better grasp of the whole mechanism now. And it's way simpler than I originally thought.

First of all, there's no such thing as "support for conditionals inside macro definitions". Macros are just that - they may contain arbitrary text to be substituted by them, including other macros which are expanded recursively. Now, since `%if` is not a macro per se, it won't get expanded into anything and just pushed to the parser for further processing (which includes conditional parsing). As a result, spec directives found inside conditionals (that are found inside macros) are a valid construct.

In fact, we ourselves have been using this *for years* in the `%debug_package` macro shipped with RPM:

```
%debug_package \
%ifnarch noarch\
%global __debug_package 1\
%_debuginfo_template\
%{?_debugsource_packages:%_debugsource_template}\
%endif\
%{nil}
```

That being said, there's a catch. Since conditionals are only evaluated *after* recursive macro expansion, the `%__debug_package` macro above will *always* be set to 1, regardless of whether `BuildArch` is `noarch`. I think this was (quite understandably) misunderstood when the macro was written. Another example is the one I gave in the previous comment where "hello" is always printed due to the fact that `echo` gets expanded (and executed) before the conditional is.

In any case, bringing back the original functionality makes sense after all, and I'll post a PR shortly.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1198#issuecomment-675338506
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20200818/a2d0c712/attachment.html>


More information about the Rpm-maint mailing list