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.
This commit is contained in:
Panu Matilainen 2020-11-04 12:02:53 +02:00
parent 04ab1f5129
commit 814a1247cd
2 changed files with 14 additions and 4 deletions

View File

@ -1005,9 +1005,9 @@ static void doOutput(MacroBuf mb, rpmMacroEntry me, const char * g, size_t gn)
_free(buf);
}
#ifdef WITH_LUA
static void doLua(MacroBuf mb, rpmMacroEntry me, const char * g, size_t gn)
{
#ifdef WITH_LUA
rpmlua lua = NULL; /* Global state. */
char *scriptbuf = xmalloc(gn + 1);
char *printbuf;
@ -1042,10 +1042,8 @@ static void doLua(MacroBuf mb, rpmMacroEntry me, const char * g, size_t gn)
free(printbuf);
}
free(scriptbuf);
#else
mbErr(mb, 1, _("<lua> scriptlet support not built in\n"));
#endif
}
#endif
static void
doSP(MacroBuf mb, rpmMacroEntry me, const char * g, size_t gn)
@ -1267,7 +1265,9 @@ static struct builtins_s {
{ "getncpus", doFoo, ME_FUNC },
{ "global", doGlobal, ME_PARSE },
{ "load", doLoad, ME_ARGFUNC },
#ifdef WITH_LUA
{ "lua", doLua, ME_ARGFUNC },
#endif
{ "macrobody", doBody, ME_ARGFUNC },
{ "quote", doFoo, ME_ARGFUNC },
{ "shrink", doFoo, ME_ARGFUNC },

View File

@ -526,6 +526,16 @@ runroot rpm \
[])
AT_CLEANUP
AT_SETUP([test lua support])
AT_KEYWORDS([macros lua])
AT_CHECK([[
lua_disabled=$(runroot rpm --eval '%[%{defined lua}?"0":"1"]'|tr -d '\n')
test $lua_disabled = $LUA_DISABLED
]],
[1],
[])
AT_CLEANUP
AT_SETUP([simple lua --eval])
AT_KEYWORDS([macros lua])
AT_CHECK([