Commit Graph

15226 Commits

Author SHA1 Message Date
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
ggardet a7efb1a88e Do not fail if there is no "$temp"/res.* file
find-debuginfo is multi-threaded and rpm runs
scripts usually with "-e" to abort on error.
If the debug-splitting tool fails, that job will abort.
But if you have X files that are problematic in the tree,
and you have X or less jobs, find-debuginfo will abort
as no single res.$number has been written.
But if you have more than X jobs, the build will succeed,
which makes the whole process random.
This commit remove this randomness.
2020-10-28 14:09:16 +02:00
Panu Matilainen df22e4aaa7 Reorganize the ancient spec tag blurb into a new beginning
Remove long since obsoleted tags and such, at least mention all
spec sections by name. Obviously mountains of information is missing,
and what is there is totally chaotic and inconsistent, but at least
there's a place to add more now.
2020-10-28 12:48:51 +02:00
Panu Matilainen 5032470056 Document (however briefly) all our actively used header tags 2020-10-28 12:48:51 +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
Panu Matilainen 831461f36d Fix some Doxygen grouping artifacts (aka bugs) 2020-10-28 10:40:41 +02:00
Panu Matilainen 4821d42abb Replace uses of deprecated PyEval_CallObject() with PyObject_Call()
Python 3.9 has deprecated PyEval_CallObject(), replace with a more
modern and documented interface (https://bugs.python.org/issue29548).
2020-10-28 10:40:22 +02:00
Panu Matilainen dd5c0446a3 Stop using deprecated security_context_t
In libselinux >= 3.1 these cause deprecation warnings on build.

security_context_t always was nothing but typedef to plain old "char *"
so just using that is entirely backwards compatible too.
2020-10-28 10:40:22 +02:00
Fabrice Fontaine 6dbb036d2f lib/rpmrc.c: include fcntl.h for O_*
Fixes compilation on musl, otherwise it fails with undefined references
to various O_* symbols as mentioned here:

https://www.man7.org/linux/man-pages/man0/fcntl.h.0p.html

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2020-10-26 12:42:15 +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 f9516434dd Allow parametric macros to opt out of option processing (#547)
Macros might want to pass along options meant for others while perhaps
modifying some of them, without exposing it all to users.

Have "-" as the parametric macro opts string disable all options processing
in rpm, allowing the macro to handle the raw argument list as they place.

Fixes: #547
2020-10-19 11:27:35 +03:00
Panu Matilainen b278517d7f Don't muck with parametric macro arguments of cli defines
When converting - to _ in cli-defined macro names, stop at first '('
as we have no business mucking with the arguments.
2020-10-19 11:27:35 +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
Panu Matilainen 376fef14a6 Lose the internal Lua variable API
This whole lot has been barely used at all since its addition in 2004,
is totally undocumented and instead of being helpful, it only ends up
being more code using some strange add-on API. It also quite effectively
prevents anybody from doing anything fancy with Lua because you'd have to
wrap it up somewhere in this intermediate API.

People are better off using native Lua API for data manipulation, byebye.
2020-10-19 11:16:59 +03:00
Panu Matilainen 5a2c920dee Convert sources/patches table manipulation to "native" Lua API
It's actually less code, and what's better the Lua API is quite well
documented, unlike the internal rpmlua one...
2020-10-19 11:16:59 +03:00
Panu Matilainen d5a7961836 Add function for fetching the underlying Lua state from rpmlua
The rpmlua layer is nice for some things but at others it merely gets
in the way. Let us operate directly on Lua API when we need it.
2020-10-19 11:16:59 +03:00
Panu Matilainen 2579d3e5ad Consolidate librpmbuild Lua code to one place
Not much changes here in practise, although this does patch_nums and
source_nums "leaking" after a spec parse as we forgot to update
*that* code when adding them. More visible when consolidated...

Also store the Lua context in the spec struct. This doesn't make much
of a difference as it is, but it'll be needed someday when we create
a new Lua environment for each spec parse, and at any rate this is
gives us a single, easy place to check whether it was initialized or not.
2020-10-19 11:16:59 +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
scootergrisen b766e63de3 Translated using Weblate (Danish)
Currently translated at 32.5% (288 of 886 strings)

Translation: rpm/master
Translate-URL: https://translate.fedoraproject.org/projects/rpm/master/da/
2020-10-13 14:42:56 +02:00
Oğuz Ersen a3ed077f7f Translated using Weblate (Turkish)
Currently translated at 43.3% (384 of 886 strings)

Translation: rpm/master
Translate-URL: https://translate.fedoraproject.org/projects/rpm/master/tr/
2020-10-13 14:42:56 +02:00
Phu Hung Nguyen bc0ab5dacd Translated using Weblate (Vietnamese)
Currently translated at 79.5% (705 of 886 strings)

Translation: rpm/master
Translate-URL: https://translate.fedoraproject.org/projects/rpm/master/vi/

Translated using Weblate (Vietnamese)

Currently translated at 79.2% (702 of 886 strings)

Translation: rpm/master
Translate-URL: https://translate.fedoraproject.org/projects/rpm/master/vi/
2020-10-13 14:42:56 +02:00
Charles Lee 706fa711c9 Translated using Weblate (Chinese (Simplified))
Currently translated at 80.8% (716 of 886 strings)

Translation: rpm/master
Translate-URL: https://translate.fedoraproject.org/projects/rpm/master/zh_CN/

Translated using Weblate (Chinese (Simplified))

Currently translated at 80.0% (709 of 886 strings)

Translation: rpm/master
Translate-URL: https://translate.fedoraproject.org/projects/rpm/master/zh_CN/
2020-10-13 14:42:56 +02:00
Göran Uddeborg 22f3342fdf Translated using Weblate (Swedish)
Currently translated at 100.0% (886 of 886 strings)

Translation: rpm/master
Translate-URL: https://translate.fedoraproject.org/projects/rpm/master/sv/
2020-10-13 14:42:56 +02:00
Panu Matilainen ad1cad7e6a Supply tag numbers for special/signature/digest tags where missing
Drop internal-only special tags (header region types) from the list
2020-10-13 14:36:34 +02:00
Panu Matilainen 27f5ab73c2 Organize tag documentation to rough tag groups for some sanity 2020-10-13 14:36:34 +02:00
Panu Matilainen b441de0031 Fix RPMTAG_SUGGESTVERSION and -FLAGS info, they're not extensions 2020-10-13 14:36:34 +02:00
Panu Matilainen 6163c6cfd9 Add Lua binding for rpmMacroIsDefined() and ..IsParametric()
Since Lua can easily return multiple values, combine test for definition
and parametric into one rpm.isdefined() API, always returning two booleans.
This also kinda ensures correct API usage as both are needed to positively
identify a defined, non-parametric macro.
2020-10-09 12:53:14 +03:00
Panu Matilainen 9399a87dc1 Implement native Lua bindings for rpm io streams
Ability to read and write same compression formats as rpm could come handy.
2020-10-09 12:53:14 +03:00
Panu Matilainen 11eb3c3fb6 Implement native Lua bindings for rpm version objects
In particular, this allows parsing version strings to their components
which might well be a more common need than version comparison...
2020-10-09 12:53:14 +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 717a3f7ecf Pass install scriptlet arguments to Lua as real local arguments
The code is more obvious and there's a whole lot less of it, we get
rid of a klunky global table, allow Lua scriptlets to process arguments
using native facilities for variadic functions, all in a backwards
compatible manner. What's not to like?

As a side-effect, the package count arguments now appear as integers
instead of floats, which is much saner in the context. Lua will
automatically convert numbers as necessary so this should not break
anything.
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
Matthew Almond d1dee9c00a Make fdSeek return 0 on success, -1 on error
This code eliminates a false positive failure when the destination
position is > 2GiB. This is done by changing the contract for `Fseek`.
Now it returns `0` on success instead of an `int` offset.
Care should be used to interpret the result as there is a difference in
semantics between the POSIX `fseek(2)`. Existing code is correct: negative
results are still failures.
2020-10-09 10:46:47 +03:00
Michael Schroeder 85765a79b7 Add error handling for versions in expressions
Versions are not supported in arithmetic operations.
2020-10-09 08:40:12 +03:00
Michael Schroeder 0f6ffbb992 Support stringification of versions in the expression parser 2020-10-09 08:40:12 +03:00
Panu Matilainen bb8dea1f84 Add list of rpm tags to the manual
Actually describing them all is a whole other matter...
2020-10-07 17:41:21 +03:00
Panu Matilainen 148d763338 Merge conditional builds and dependencies docs from rpm-web 2020-10-07 17:41:21 +03:00