RPM Community Forums

Mailing List Message of <rpm-devel>

Re: Macro feature request: "once only" expansions ;-)

From: Ralf S. Engelschall <rse+rpm-devel@rpm5.org>
Date: Fri 25 Jan 2008 - 18:29:46 CET
Message-ID: <20080125172946.GA24226@engelschall.com>
On Fri, Jan 25, 2008, Ralf S. Engelschall wrote:

> On Thu, Jan 24, 2008, Jeff Johnson wrote:
> > On Jan 24, 2008, at 4:33 PM, Ralf S. Engelschall wrote:
> >>
> >> Ahhh... I see! Tricky, I've already seen the __policy_tree definition a
> >> few times during glancing over "macros.in" but I've not recognized that
> >> it actually redefines itself. Ok, for my particular 6 ultra-expensive
> >> macros this is certainly an acceptable speed-up solution. Will try.
> >> But for the other about 50-100 macro definitions a simple syntax like
> >> ":%<name> <value>" would be good to have as it doesn't make the whole
> >> stuff such hard to read...
> >
> > How about tweaking up %{load:...} to permit immediate
> > expansion of
> >      %:foo %{lua:...}
> > to transform to
> >     %{expand:%%define foo %{lua:...}}
> > definition.
> >
> > A bit slippery because it also makes macro initialization
> > order dependent, but can't be helped.
> >
> > Or do you need to delay the one-time expansion until
> > first usage?
>
> Exactly. I also thought about the ordering issue and came to the
> conclusion that it opens a large can of worms if we do the expansion
> already at definition time. The best is to really delay it until the
> macro is the first time actually expanded.
>
> > I've needed/wanted an immediate expansion within macro files
> > for years, just unwilling to listen to  the whiny "Incompatible!"
> > hollering.
>
> Well, with an additional syntactical tag it should be just fine as it
> means that the immediate expansion has to be explicitly requested.
>
> So, I see two tags: one which indicates that expansion should really be
> performed immediately and the other indicating that the expansion should
> be done once at the first expansion.

Ok, I'm now solving my "speed issues" just fine with:

| %once() %{expand:%%global %{*}}%{expand:%%{%{1}}}
| [...]
| %foo    %{once foo [...foo's body...]}
| %bar    %{once bar [...bar's body...]}

Nice trick! Works just fine...
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com
Received on Mon Jan 28 21:37:32 2008
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.