matejcik is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.
matejcik @matejcik

RPM's macro expansion has a maximum depth of 16.
I'm now playing a kind of code golf, to fit as much expansion into these 16 levels.

The problem: with "%define pythons python2 python3 pypy3", expand "%{python_module foo}" => "python2-foo python3-foo pypy3-foo".
This must fit into one line and can't use shell or Lua, because it also targets a non-RPM spec parser that doesn't have these features.
Fit as many pythons as you can!

· Web · 0 · 0

my current solution:

%python_module_iter(a:) %{-a*}-%{args} %{expand:%%{?!python_module_iter_%1:%%{python_module_iter -a %*}}}
%python_module_iter_STOP stop

%python_module() %{expand:%%define args %{**}} %{expand:%%{python_module_iter -a %{pythons} STOP}}

At four pythons, this is 14 levels deep. 3 levels per python, 2 for setup.
now the question is: can I fit one more?

I *could* get to 2 levels per python, if i didn't mind that the recursion never stops....

...which doesn't actually matter in RPM. It's some sort of error somewhere in the log, but the output is the right thing.

holy fuck what a hack.

now to see if that other spec parser cares.
(it's this one: github.com/openSUSE/obs-build/ )

bad news: it cares.
well it doesn't, but will replace my very pretty expansion with "MACRO", which is, uh, not what I want.