[Rpm-maint] [rpm-software-management/rpm] Macro definitions expanding across multiple lines (Discussion #2353)
Miro Hrončok
notifications at github.com
Mon Jan 16 11:54:19 UTC 2023
Hello. I often written macros defined like this:
```rpm
%py_shebang_fix %{expand:\\\
if [ -z "%{?py_shebang_flags}" ]; then
shebang_flags="-k"
else
shebang_flags="-ka%{py_shebang_flags}"
fi
%{__python} -B %{_rpmconfigdir}/redhat/pathfix.py -pni %{__python} $shebang_flags}
```
I've abused `%expand` to have a macro definition that expands across multiple lines.
@pmatilai [said](https://bugzilla.redhat.com/show_bug.cgi?id=2160716#c10):
> Using an outer `%{expand:...}` just to make it look like a function (as seems to be a common habit in Fedora) is bad thing to do because it then breaks when you least expect it to. NEVER use `%{expand:...}` unless you actually mean it, as in, need that extra expand. And even then, only use it on the smallest possible block to achieve what you need, not the entire thing "just because"
If I had to drop the `%expand`, I'd probably have to do something like:
```rpm
%py_shebang_fix \
if [ -z "%{?py_shebang_flags}" ]; then \
shebang_flags="-k" \
else \
shebang_flags="-ka%{py_shebang_flags}" \
fi \
%{__python} -B %{_rpmconfigdir}/redhat/pathfix.py -pni %{__python} $shebang_flags
```
That is a bit **ugly**. Another option is to take a macro that is always defined and make the thing conditional on it:
```rpm
%py_shebang_fix %{?nil:\\\
if [ -z "%{?py_shebang_flags}" ]; then
shebang_flags="-k"
else
shebang_flags="-ka%{py_shebang_flags}"
fi
%{__python} -B %{_rpmconfigdir}/redhat/pathfix.py -pni %{__python} $shebang_flags}
```
That is **hard to understand** by the reader.
Could we get some kind of macro that allows us to achieve what we use `%expand` for?
E.g.
```rpm
%py_shebang_fix %{multiline:\
if [ -z "%{?py_shebang_flags}" ]; then
shebang_flags="-k"
else
shebang_flags="-ka%{py_shebang_flags}"
fi
%{__python} -B %{_rpmconfigdir}/redhat/pathfix.py -pni %{__python} $shebang_flags}
```
--
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/discussions/2353
You are receiving this because you are subscribed to this thread.
Message ID: <rpm-software-management/rpm/repo-discussions/2353 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20230116/c6ad0209/attachment.html>
More information about the Rpm-maint
mailing list