diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2018-10-16 11:26:46 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2018-10-22 12:22:55 +0300 |
commit | ddc1d06c45994b40aea3dfefc60436e409fce08c (patch) | |
tree | 3a47be861a1487f7e91e77167f163995e3ea615e | |
parent | 3570c9beb5398541ea7423639891ef6a9de27087 (diff) | |
download | rpm-ddc1d06c45994b40aea3dfefc60436e409fce08c.tar.gz |
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)
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | macros.in | 2 | ||||
-rw-r--r-- | rpmio/rpmlua.c | 13 | ||||
-rw-r--r-- | tests/rpmmacro.at | 17 |
4 files changed, 26 insertions, 8 deletions
diff --git a/Makefile.am b/Makefile.am index 345adbc9e..26317a492 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 @@ -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 --git a/rpmio/rpmlua.c b/rpmio/rpmlua.c index c96fb6b67..426e81a2e 100644 --- a/rpmio/rpmlua.c +++ b/rpmio/rpmlua.c @@ -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 --git a/tests/rpmmacro.at b/tests/rpmmacro.at index b9aeb21d7..650e5428c 100644 --- a/tests/rpmmacro.at +++ b/tests/rpmmacro.at @@ -297,6 +297,21 @@ 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 +447,4 @@ runroot rpm --macros "/data/macros.testfile" \ macro_2 ]) -AT_CLEANUP
\ No newline at end of file +AT_CLEANUP |