Commit Graph

391 Commits

Author SHA1 Message Date
Panu Matilainen 7f3fdf6868 Make Lua a hard requirement for rpm
More and more macros, scriptlets and other functionality has been getting
built around Lua, to the point that it has in practice been required for
several years now.

Maintaining the pretense of being optional comes at a cost in holding
back developments and having to check for that theoretical special
case. Lets make it a hard requirement and embrace it some more!
2021-02-09 13:57:27 +02:00
Panu Matilainen f67d239ccd Actually report the involved macro names in macro tracebacks
Should make macro debugging a little saner, including but not limited
to Lua.

Fixes: #545
2021-01-29 13:54:54 +01:00
Panu Matilainen 5bfb49d6b7 Conditionalize macro traceback dump on rpm verbosity level
Only dump out macro tracebacks in verbose mode, which incidentally
rpmbuild normally runs in.

Sadly our tracebacks are not as useful as they could be, but improving
that is a separate topic...
2021-01-29 13:54:54 +01:00
Panu Matilainen c145a6c86a Revert "Redirect macro stack backtrace printing to debug log."
The rationale behind the change was to suppress the excessive output
when trying to expand a recursive macro definition (RhBug:613010) but
this is not so good as it effectively suppresses *all* backtrace output,
include those requested by %trace where the other half is printed to
stderr and the other half in the debug log because of the change.

Besides making things consistent, this also avoids deadlock on
`rpm -vv --eval '%trace'`.

This reverts commit 7f220202f2.

Fixes: #1418
2021-01-29 13:54:54 +01:00
Panu Matilainen c072ef6bb8 Let %define and %global take name and body as separate arguments
doDefine() wants macro file-style "name body" string as an argument, but
when called through rpmExpandThisMacro() you'd expect to put the name
and body in separate arguments. Properly handling this in the macro engine
guts is more than I'm prepared to do at the moment, but we can detect
the multiple arguments case and turn the arguments into something that
doDefine groks.

This will matter when we add support for calling macros as native Lua
elements.
2021-01-27 14:32:34 +02:00
Panu Matilainen 43148cb9a7 Change %dump macro to "func" style now that we can
%dump macro takes no arguments of any kind, it just eats the rest of
the line which doesn't make any sense whatsoever. So while this
theoretically changes %dump behavior, the behavior actually changed
a few commits back with the calling syntax unification: %dump never
took actual arguments, so it'll now just error out if there's text
on the same line where it previously ignored that. Unless you use
%{dump} that is.
2020-11-26 12:07:25 +02:00
Panu Matilainen aec8bdb53a Change %undefine macro to "func" style now that we can
%undefine parsing its own argument makes no sense whatsoever,
it's just a name and nothing special. Now that the calling syntax
is no longer an issue, make it sane. No functional changes.
2020-11-26 12:07:25 +02:00
Panu Matilainen 78bb7369a3 Specify number of expected arguments for builtins in numbers
No functional changes here, but going forward this gives us more
flexibility than the ME_HAVEARG. We could also extend this to support
mandatory arguments to user defined macros too.
2020-11-26 12:07:25 +02:00
Panu Matilainen cfaf1c6292 Unify builtin macro calling now that we can
Now that both types use identical function signature, we can trivially
unify the calling code for both, simplifying things somewhat, make
the non-braced syntax for built-in macros work, and regain type safety.
2020-11-26 12:07:25 +02:00
Panu Matilainen 1c964243b5 Change func-macro types to return a number (always zero)
No functional changes, but look mom, we have identical signature for
both builtin macro types!
2020-11-26 12:07:25 +02:00
Panu Matilainen f5f9764e6d Change builtin "parse" type macros to take their arguments via an argv
No functional changes here and not sure if/how these would ever take
multiple arguments, but there's another treasure at the end of
this particular rainbow...
2020-11-26 12:07:25 +02:00
Panu Matilainen 3d3f717d28 Change builtin "func" type macros to take their arguments via an argv
No functional changes here, but opens the door for builts accepting
multiple arguments.
2020-11-26 12:07:25 +02:00
Panu Matilainen 1e3f40b14e Put an insulation layer between source line parsing and macro arguments
Change parse-type macros to return number of consumed characters rather
than a pointer to the parsed string to separate the two.
2020-11-26 12:07:25 +02:00
Panu Matilainen 1de248d440 Unify builtin and user-defined parametric macro calling syntax
Accept both %{foo:arg} and %{foo arg} notation for both builtins
and user-defined parametric macros, the former only ever has one
argument whereas the latter can have multiple.

"parse" type builtins such as %define are trickier and only work with
traditional syntax for now.
2020-11-26 12:07:25 +02:00
Panu Matilainen 814a1247cd Support testing for builtin Lua with a macro conditional
Only define builtin %{lua:...} if actually compiled with the support.
This loses the "informative" error message about the situation but
I think ability to test feature presence is more useful and important.
2020-11-09 13:59:47 +02:00
Panu Matilainen 04ab1f5129 Move the builtins table below the referenced functions to lose clutter
No code or functionality changes, just shuffling code to get rid of
redundant declarations.
2020-11-09 13:59:47 +02:00
Panu Matilainen ea6431c521 Make builtin macros honor generic macro conditionals 2020-11-09 13:59:47 +02:00
Panu Matilainen 1d83ec55d6 Lose now unnecessary chkexist and negate arguments to builtin macros
No functional changes.
2020-11-09 13:59:47 +02:00
Panu Matilainen 413c85f131 Drop support for undocumented %{!trace} builtin syntax
We can always add some other syntax to handle this if needed.
2020-11-09 13:59:47 +02:00
Panu Matilainen f955bc69d0 Drop undocumented special conditional syntax from %{load:...} builtin
%{load:...} supported strange conditional syntaxes that conflict
with general macro syntax. Drop support for these undocumented
variants, people can use %{exists:...} to test for file existence
before trying to load a macro file.
2020-11-09 13:59:47 +02:00
Panu Matilainen 7b25e19803 Add %{exists:...} builtin macro for testing file existence 2020-11-09 13:59:47 +02:00
Panu Matilainen d649c2aa3b Change builtin %{verbose:...} to return a simple 0/1 boolean
%{verbose:...} supported a special syntax of negation with %{!verbose}
but this conflicts with general macro syntax. Now that we have
expressions we can easily handle arbitrary conditions using generic
syntax but %verbose semantics need to change for that: lose the argument
and just return a simple boolean reflecting whether rpm is in verbose
mode or not.

This is obviously an incompatible change, but few things outside rpm itself
should care about this anyhow.

Update the sole user (build scriptlets) to use an expression instead
(whee, the first actual in-tree user!), documentation and testcases
accordingly.
2020-11-09 13:59:47 +02:00
Panu Matilainen 561c59db1b Convert some obvious cases to use rstrndup() instead of manual work
The net win in terms of LoC is not that big but it does make things
that little more readable and obvious.
2020-11-09 09:28:54 +02:00
Panu Matilainen fc31fec661 Pass their own macro entry as an argument (ie self) to all builtins
No intended functional changes, but it's one argument less to pass
around, brings builtins one step closer to how user defined
macros are called and is a step towards supporting options to
builtins as well.
2020-11-04 10:19:40 +02:00
Panu Matilainen ded0282b05 Lose now unnecessary name length member in builtin macro table 2020-11-04 10:19:40 +02:00
Panu Matilainen 94e2c299e2 Handle builtin-macros as defined entries in the macro table
Add the necessary infra to pass and carry a function pointer in the macro
entry, define builtins as part of macro initialization and switch
the main expansion loop to use the macro entry info instead of special
builtin lookup.

This has various nice benefits, such as allowing simple testing whether
rpm supports a given primitive by testing whether said macro is defined
and a small performance boost as an extra lookup for the builtins is
eliminated from all macro expansion cycles.
It also paves way for later implementing various spec constructs as
actual macros instead of the confusing pseudo-macros they are now.

Apart from builtins showing up as defined and macro initialization now
being mandatory, this is not supposed to change any concrete behavior.
2020-11-04 10:19:40 +02:00
Panu Matilainen f691cab7a4 Always copy cli macros in rpmInitMacros()
Even if macrofiles is NULL we (may) have other initialization tasks
to do, always grab the context lock and mind segfaulting when loading
files if macrofiles is NULL.
2020-11-04 10:19:40 +02:00
Panu Matilainen f9a4c0a39a Move builtin type information to flags bitfield
Compacts things a bit and allows for more flexibility later on,
unfortunately at the price of losing type safety. No functinal changes,
just paving way for next steps.
2020-11-04 10:19:40 +02:00
Michael Schroeder 98b71f7a92 Remove common code from expandMacro() and expandThisMacro()
Add a mbInit() function that allocates the buffer, increases the
expansion depth and stashes some values into a MacroExpansionData area.
Add a mbFini() function that decreases the depth again,
restores the values and optionally prints the expansion result.
2020-10-30 12:11:41 +02:00
Michael Schroeder a2e60c0a50 Add new rpmExpandThisMacro() public method
This expands the maco with the specified name. Argument expandsion
for parametric macros can be turned on with the RPMEXPAND_EXPAND_ARGS
flag.
2020-10-30 12:11:41 +02:00
Michael Schroeder ef4241d727 Split mbCreate() function from doExpandMacros() 2020-10-30 12:11:41 +02:00
Michael Schroeder 05eb42be9a Split doExpandThisMacro() from expandMarco()
This eleminates duplicate code.
2020-10-30 12:11:41 +02:00
Michael Schroeder 339510b2bf No longer free the args ARGV in freeArgs
This gets rid of the weird and unneeded ownership transfer and
makes the args seetup more symmetric.
2020-10-30 12:11:41 +02:00
Michael Schroeder 374802f1ad Move setupArgs() function so that it is next to freeArgs()
No functional changes.
2020-10-30 12:11:41 +02:00
Michael Schroeder 9a3fb26ebd Make comments reflect new macro parsing reality 2020-10-30 12:11:41 +02:00
Panu Matilainen 0b75075a8d Shut up bogus Doxygen warnings about undocumented parameters
As of Doxygen >= 1.8.20 it started complaining about anything marked
as @retval being undocumented. As this is widely used in rpm...
Mass-replace all @retval uses with @param[out] to silence. Some of
these are actually in/out parameters but combing through all of them
is a bit too much...

Also escape <CR><LF> in rpmpgp.h to shut up yet another new warning.
2020-10-28 10:40:41 +02:00
Michael Schroeder fec16cc9b5 Fix access of already freed memory in macro expansion
A macro can undefine itself so we must not access the
entry data after we expanded the body.
2020-10-26 07:54:29 +02:00
Michael Schroeder 72ba3dc228 Simplify grabArgs() usage
Change grabArgs to just append the parsed arguments to the
passed args array and do the setupArgs call in expandMacro.
2020-10-26 07:54:29 +02:00
Michael Schroeder 0cd8268ed2 Split setupArgs() function from grabArgs()
We will reuse setupArgs() in the future.
2020-10-26 07:54:29 +02:00
Michael Schroeder 13df6fda91 Split off mbAllocBuf() from expandMacro()
No need to fiddle with the internals of the mb in expandMacro.
2020-10-26 07:54:29 +02:00
Michael Schroeder 6d7fa91949 Fix logic error in grabArgs()
If there was a \ at the end of the buffer, the code would
return a pointer after the trailing \0 leading to unallocated
memory access and weird results in some cases.

See commit 817959609b.
2020-10-23 15:41:24 +03:00
Mark Wielaard b2659f9ec9 Fix warnings from set but unused, variables in macro.c and rpmlua.c
macro.c: In function ‘mbopt’:
macro.c:895:19: warning: unused variable ‘me’ [-Wunused-variable]
  895 |     rpmMacroEntry me = mb->me;
      |                   ^~

rpmlua.c: In function ‘fd_seek’:
rpmlua.c:985:22: warning: unused variable ‘mode’ [-Wunused-variable]
  985 |     static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
      |                      ^~~~

The former is actually unused, the latter should be used.
2020-10-23 15:07:36 +03:00
Panu Matilainen ce79e166fe Wrap getopt() usage into internal helper
Avoids code duplication (glibc quirks and whatnot) between macro and lua
option parsing, isolate the global opt* variable accesses to one spot.
Makes it easier to ensure identical behavior between the users if/when
something changes.

No behavior changes intended.
2020-10-19 11:27:35 +03:00
Michael Schroeder 6de7374bb8 Treat unparsable macros like undefined macros
This seems to be the intention of the code but it did
not work because macro parsing was resumed at the wrong
point of the input string. Without this commit, "%{}"
expanded to "%" instead of "%{}".
2020-10-14 13:27:09 +03:00
Panu Matilainen 67abf72ef5 Pass parametric macro options and arguments to Lua natively (#1092)
We already have the macro arguments in an ARGV that's suitable for
passing to Lua, just store it in the macro buffer for passing around.
As macros can nest arbitrarily, we need to store and restore the mb
args which is a bit hacky, but much less trouble than changing all the
related functions to pass argound an argv which only one function
ever uses. Ditto with the macro entry itself, which is needed to pass
around the options (and name, and maybe something else too later).

Besides all the normal rpm defined macros for arguments and options,
parametric Lua macros now get pre-processed options and arguments
in native local tables "opt" and "arg" for much more pleasant access.
"opt" and "arg" tables are always there even if no options or arguments
were passed, this avoids having to deal with multiple cases and test
for nil's all over the place.

Fixes: #1092
2020-10-09 12:52:47 +03:00
Panu Matilainen 192cbafcb2 Add API support for passing options and arguments to natively to Lua
Add support for passing getopt options and arguments to natively to Lua
scriptlets via the internal API. The processed opts and args are stored
in two chunk local two tables, options keyed by the letter and arguments
by their numeric index.

Update call sites accordingly, but no actual functionality changes here,
just pre-requisites for next steps.
2020-10-09 12:52:47 +03:00
Panu Matilainen d690ed7e48 Restore flagless variants of rpmExprBool() and rpmExprStr() for ABI compat
Commit cb4e5e755a added flags arguments
to rpmExprBool() and rpmExprStr(), but unfortunately rpm 4.15 sailed
with flagless versions them. It's extremely unlikely that anything out
there is actually using these, but then you never really know.
Rpm soname bumps are so inconvenient that we really do not want to do
that just for these two, so preserve binary compatibility and restore
flagless variants of both, adjust internal code to use flagged versions
always. If only we had symbol versioning, sigh.
2020-03-23 13:44:12 +02:00
Panu Matilainen 1d624239c4 Implement %{macrobody:...} built-in for retrieving the literal macro body
Fixes: #582
2020-02-19 13:09:21 +01:00
Panu Matilainen 9b37c4b349 Add APIs for testing whether a macro is defined and whether its parametric
Whether a macro is defined can be tested with eg rpmExpandNumeric()
but this is somewhat cumbersome and expensive for such a simple thing.
Prior to this, there was no way to find out whether a macro is
parametric (aka parameterized) or not.
2020-02-11 11:18:57 +01:00
Michael Schroeder 490c70d43c Use RPMMACRO_LITERAL/ME_LITERAL when defining some macros
It is used for setting __file_name, __file_lineno, buildsubdir.
We also use it for unmasking %license in the %files section.
2020-02-10 15:41:33 +02:00