From 814a1247cd67524af76392ddb81e7dd83b6bfa1c Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 4 Nov 2020 12:02:53 +0200 Subject: [PATCH] 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. --- rpmio/macro.c | 8 ++++---- tests/rpmmacro.at | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index 1e9388a61..7a75e3b65 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -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, _(" 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 }, diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at index f5a3d3061..70aa3179c 100644 --- a/tests/rpmmacro.at +++ b/tests/rpmmacro.at @@ -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([