#42 RFE: preproc: add variables & control structures
Opened 2 years ago by elmarco. Modified 2 years ago

It would be very convenient if preproc supported variables & control structures, jinja-like.

I wrote a simple template tool for mingw packages: https://gitlab.com/-/snippets/2243878

But it would be nice if this was integrated in fedora package workflow/tools.

Any opinion how we could achive that?


Btw, how does Fedora tooling handle packages that use a template, when doing mass-edit/rebuild etc?

Btw, how does Fedora tooling handle packages that use a template, when doing mass-edit/rebuild etc?

preproc is currently not used for packages in Fedora DistGit.

It would be very convenient if preproc supported variables & control structures, jinja-like.

I wrote a simple template tool for mingw packages: https://gitlab.com/-/snippets/2243878

But it would be nice if this was integrated in fedora package workflow/tools.

Any opinion how we could achive that?

Hello, variables are possible, you can pass environment variable to preproc which is then available inside the preproc tags. Or you can export a variable from inside a preproc tag and then this variable is going to be available across all the following tags ({{{, }}}).

As for control structures, they can be added. I was thinking something along the lines:

{{% for m in mingw.targets; do %}}
BuildRequires:  ${m}-filesystem >= 95
BuildRequires:  ${m}-gcc
BuildRequires:  ${m}-binutils
{{% done %}}

So the control structure would basically follow bash syntax (and would be interpreted by bash).
More precisely: a snippet similar to one below would be constructed and executed based on the above code:

for m in mingw.targets; do
     echo "BuildRequires:  ${m}-filesystem >= 95\nBuildRequires:  ${m}-gcc\nBuildRequires:  ${m}-binutils"
done

Btw. you can also always do (pseudocode):

{{{
for m in mingw.targets; do
     echo "BuildRequires:  ${m}-filesystem >= 95\nBuildRequires:  ${m}-gcc\nBuildRequires:  ${m}-binutils'
done
}}}

with the current syntax so the syntax extensions are nice to have but it's possible to live without them (but I would be more than ok if they were added).

Login to comment on this ticket.

Metadata