From ddc1d06c45994b40aea3dfefc60436e409fce08c Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 16 Oct 2018 11:26:46 +0300 Subject: [PATCH 2/4] Resurrect long since broken Lua library path LUA_PATH global variable is not consulted when loading libraries in Lua >= 5.1, package.path has replaced it. Rpm's Lua library path was always supposed to be /usr/lib/rpm/lua/ but this has been broken for the last ten years or so, oops. Make the directory a first-class citizen: create it on install, add a macro for it, make it actually work and ensure it stays that way by adding a test for it. (cherry picked from commit dd6c65044c41922193f520ace668e2c5e55f1004) --- Makefile.am | 2 ++ macros.in | 2 ++ rpmio/rpmlua.c | 13 ++++++------- tests/rpmmacro.at | 17 ++++++++++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) diff -urNp a/macros.in b/macros.in --- a/macros.in 2019-04-23 12:06:08.066000000 -0400 +++ b/macros.in 2019-04-23 12:11:29.225000000 -0400 @@ -149,6 +149,8 @@ %_rpmconfigdir %{getconfdir} # The directory where rpm's macro files live %_rpmmacrodir %{_rpmconfigdir}/macros.d +# The directory where rpm's addon lua libraries live +%_rpmluadir %{_rpmconfigdir}/lua # The directory where sources/patches will be unpacked and built. %_builddir %{_topdir}/BUILD diff -urNp a/Makefile.am b/Makefile.am --- a/Makefile.am 2019-04-23 12:05:54.541000000 -0400 +++ b/Makefile.am 2019-04-23 12:10:32.959000000 -0400 @@ -253,6 +253,7 @@ install-data-local: $(RPMCANONVENDOR) $(RPMCANONOS) $(RPMCANONGNU) @$(MKDIR_P) $(DESTDIR)$(localstatedir)/tmp @$(MKDIR_P) $(DESTDIR)$(rpmconfigdir)/macros.d + @$(MKDIR_P) $(DESTDIR)$(rpmconfigdir)/lua # XXX to appease distcheck we need to remove "stuff" here... uninstall-local: @@ -261,6 +262,7 @@ uninstall-local: @rm -rf $(DESTDIR)$(rpmconfigdir)/platform/ @rm -f $(DESTDIR)$(rpmconfigdir)/macros @rm -rf $(DESTDIR)$(rpmconfigdir)/macros.d + @rm -rf $(DESTDIR)$(rpmconfigdir)/lua MAINTAINERCLEANFILES = ChangeLog diff -urNp a/rpmio/rpmlua.c b/rpmio/rpmlua.c --- a/rpmio/rpmlua.c 2019-04-23 12:06:27.928000000 -0400 +++ b/rpmio/rpmlua.c 2019-04-23 12:18:35.940000000 -0400 @@ -100,13 +100,6 @@ rpmlua rpmluaNew() #ifndef LUA_GLOBALSINDEX lua_pushglobaltable(L); #endif - lua_pushliteral(L, "LUA_PATH"); - lua_pushfstring(L, "%s/%s", rpmConfigDir(), "/lua/?.lua"); -#ifdef LUA_GLOBALSINDEX - lua_rawset(L, LUA_GLOBALSINDEX); -#else - lua_settable(L, -3); -#endif lua_pushliteral(L, "print"); lua_pushcfunction(L, rpm_print); #ifdef LUA_GLOBALSINDEX @@ -117,6 +110,12 @@ rpmlua rpmluaNew() #ifndef LUA_GLOBALSINDEX lua_pop(L, 1); #endif + + lua_getglobal(L, "package"); + lua_pushfstring(L, "%s/%s", rpmConfigDir(), "/lua/?.lua"); + lua_setfield(L, -2, "path"); + lua_pop(L, 1); + rpmluaSetData(lua, "lua", lua); if (stat(initlua, &st) != -1) (void)rpmluaRunScriptFile(lua, initlua); diff -urNp a/tests/rpmmacro.at b/tests/rpmmacro.at --- a/tests/rpmmacro.at 2019-04-23 12:06:50.426000000 -0400 +++ b/tests/rpmmacro.at 2019-04-23 12:39:31.867000000 -0400 @@ -297,6 +297,22 @@ runroot rpm \ ) AT_CLEANUP +AT_SETUP([lua library path]) +AT_KEYWORDS([macros lua]) +AT_CHECK([ +AT_SKIP_IF([$LUA_DISABLED]) +f=$(rpm --eval "%{_rpmconfigdir}/lua/foo.lua") +echo "bar = 'graak'" > ${f} +runroot rpm \ + --eval '%{lua:require "foo"; print(bar)}' +rm -f ${f} +], +[0], +[graak +]) +AT_CLEANUP + + AT_SETUP([%define + %undefine in nested levels 1]) AT_KEYWORDS([macros define undefine]) AT_CHECK([ @@ -432,4 +448,4 @@ runroot rpm --macros "/data/macros.testf macro_2 ]) -AT_CLEANUP \ No newline at end of file +AT_CLEANUP