New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFE: optional one-shot/cached macro expansion #1155
Comments
Is there any benefit in having macro files? Wouldn't be better to deprecate them instead? |
Um. And use what instead? The spec file format? Whose parser is the one of the most compilicated and loathed piece of code in rpm and would be difficult to lift out of librpmbuild to put it mildly, and as a consequence slow down every rpm startup in the process? In contrast, the macro file format is a nice, declarative format that can be always safely read without side-effects. It could be extended without sacrificing that. |
First seeing spec file and then trying to move some macros into macros file, it was very confusing, I can tell you. From packager POV, the macro file is the same as spec file, but you don't write Obviously, you know the internals, but honestly, that is just implementation detail to me. |
Well yes, people occasionally get confused about that. The difference is a big one though, its like comparing a shell script with an ini file. Both have their places. |
Crazy thought: we could allow to use %define/%global in the macro file, as those are illegal macro names. I.e. we could allow this:
(rpm internally somewhat rewrites the %foo to %define foo anyway) Then we could also allow
which is something I wanted to have since quite some time. The downside is of course that people will start to try to use %if statements, because the macro file looks too much like a spec file. |
There are other downsides too, such as arbitrary side-effects and code execution on load (as opposed to time of use). |
Well, we don't need to allow %global. Anyway, let's move a step back and talk about this issue. This is about one shot macros. Implementation wise this is not hard, it's more a question of syntax. It would be nice to have the following options:
So %global is %define plus the global + expand flags. Macro names can't start with a
As next step can can discuss how we support this in the macro files ;) |
Yeah, %define with options is what I'd really like (I think I even mentioned somewhere surrounding the pending %literal). In macro files the name limitation could be abused for similar effect by adding special characters in the front of the name. AIUI rpm5 used "." to denote a read-only macro, for our purposes eg "=" could mean "literal" and so on. It's pretty ugly of course. I suppose we could place the macro flags after the name, using a separator such as ':'
Not sure its any prettier than special characters in front, though 😂 For a moment I thought about putting the flags inside [] after the name, but I think we want to reserve that syntax for arrays if we ever get around to implement them. OTOH anything putting stuff after the name would need to deal with this first:
|
FWIW, a simple and generic way to implement this on macro level is to redefine the macro as a global on first evaluation, eg:
Optimally what would use %literal (or the equivalent) instead of %global but we don't have that yet... |
What about rewriting the macro in Lua and stashing the result in a Lua global variable? |
It's possible in Lua of course, the above was to point out a way to do it without, because not everybody is content with Lua. |
Some macros are really expensive to expand, notorious examples include python/perl/etc related macros that invoke the interpreter to fish out a configuration path or such. When these are expanded repeatedly, it really adds up.
In a spec one can use %global to achieve this, but that's not possible from a macro file which is how most such macros are distributed.
The text was updated successfully, but these errors were encountered: