Support non-parametric builtins again

Macros like %getncpus should not treat the following text as
macro arguments. E.g. 'make -j %getncpus all' should work and
not complain about an unexpected argument.

We still treat arguments passed via %{foo:arg} or %{foo arg} as an
error for builtin macros. (They are silently ignored for user
defined macros.)
This commit is contained in:
Michael Schroeder 2021-10-25 12:32:24 +02:00 committed by Panu Matilainen
parent c00d85fb5e
commit bfbd0b3e7f
2 changed files with 7 additions and 3 deletions

View File

@ -1329,7 +1329,7 @@ doMacro(MacroBuf mb, rpmMacroEntry me, ARGV_t args, size_t *parsed)
/* Recursively expand body of macro */
if (me->flags & ME_FUNC) {
int nargs = argvCount(args) - 1;
int nargs = args && args[0] ? (argvCount(args) - 1) : 0;
int needarg = (me->nargs != 0);
int havearg = (nargs > 0);
if (needarg != havearg) {
@ -1517,12 +1517,14 @@ expandMacro(MacroBuf mb, const char *src, size_t slen)
continue;
}
if (me->opts == NULL) {
if (me->opts == NULL && !(me->flags & ME_FUNC)) {
/* Simple non-parametric macro */
doMacro(mb, me, NULL, NULL);
s = se;
continue;
}
if (me->opts == NULL && fe == se)
lastc = NULL; /* do not parse arguments coming after %foo */
ARGV_t args = NULL;
argvAdd(&args, me->name);
@ -1947,7 +1949,7 @@ rpmInitMacros(rpmMacroContext mc, const char * macrofiles)
/* Define built-in macros */
for (const struct builtins_s *b = builtinmacros; b->name; b++) {
pushMacroAny(mc, b->name, "", "<builtin>", b->func, b->nargs,
pushMacroAny(mc, b->name, b->nargs ? "" : NULL, "<builtin>", b->func, b->nargs,
RMIL_BUILTIN, b->flags | ME_FUNC);
}

View File

@ -319,6 +319,7 @@ runroot rpm --eval "%{dump:foo}"
runroot rpm --eval "%{shrink:%%%%}"
runroot rpm --eval "%{shrink %%%%}"
runroot rpm --eval "%shrink %%%%"
runroot rpm --eval "%verbose foo"
],
[0],
[
@ -332,6 +333,7 @@ bar baz\baz
%%
%%
%%
0 foo
],
[error: %dirname: argument expected
error: %dirname: argument expected