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.
This commit is contained in:
Panu Matilainen 2021-01-22 12:40:36 +02:00
parent 5e40166380
commit c072ef6bb8
1 changed files with 17 additions and 4 deletions

View File

@ -762,16 +762,29 @@ doUndefine(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
return 0; return 0;
} }
static size_t doArgvDefine(MacroBuf mb, ARGV_t argv, int level, int expand)
{
char *args = NULL;
size_t ret;
const char *se = argv[1];
/* handle the "programmatic" case where macro name is arg1 and body arg2 */
if (argv[2])
se = args = rstrscat(NULL, argv[1], " ", argv[2], NULL);
ret = doDefine(mb, se, level, expand);
free(args);
return ret;
}
static size_t doDef(MacroBuf mb, rpmMacroEntry me, ARGV_t argv) static size_t doDef(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
{ {
const char *se = argv[1]; return doArgvDefine(mb, argv, mb->level, 0);
return doDefine(mb, se, mb->level, 0);
} }
static size_t doGlobal(MacroBuf mb, rpmMacroEntry me, ARGV_t argv) static size_t doGlobal(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)
{ {
const char *se = argv[1]; return doArgvDefine(mb, argv, RMIL_GLOBAL, 1);
return doDefine(mb, se, RMIL_GLOBAL, 1);
} }
static size_t doDump(MacroBuf mb, rpmMacroEntry me, ARGV_t argv) static size_t doDump(MacroBuf mb, rpmMacroEntry me, ARGV_t argv)