diff --git a/configure.ac b/configure.ac index 34aac5680..85eb203bc 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,14 @@ AC_ARG_WITH([system-luarocks], AM_CONDITIONAL([SYSTEM_LUAROCKS], [test "x$with_system_luarocks" = "xyes"]) AC_SUBST([SYSTEM_LUAROCKS]) +AC_ARG_WITH([vendored-luarocks-dir], + AS_HELP_STRING([--with-vendored-luarocks-dir=PATH], + [Specify a custom vendored location from which to load ‘system’ luarocks]), + [], + [with_vendored_luarocks_dir=no]) +AM_CONDITIONAL([VENDORED_LUAROCKS], [test "x$with_vendored_luarocks_dir" != "xno"]) +AC_SUBST([VENDORED_LUAROCKS]) + AC_ARG_WITH([system-lua-sources], AS_HELP_STRING([--with-system-lua-sources], [Don’t compile against vendored Lua sources, use system headers])) @@ -266,16 +274,20 @@ AM_COND_IF([DEVELOPER_MODE], [ AC_DEFINE_UNQUOTED([SILE_PATH], ["${SILE_PATH}"], [Path for SILE packages and classes]) AC_SUBST([SILE_PATH]) -# In order for our Rust CLI binary to use the same default package.path as the system Lua, -# we test the system Lua (required only at build not run time) for its current package.path. +# In order for our Rust CLI binary to use the same default package.(c)path as the system Lua, +# we test the system Lua (required only at build not run time) for its current package.(c)path. adl_RECURSIVE_EVAL(["$(${LUA} -e 'print(package.path)')"], [SYSTEM_LUA_PATH]) -AC_DEFINE_UNQUOTED([SYSTEM_LUA_PATH], ["${SYSTEM_LUA_PATH}"],[System Lua package path]) -AC_SUBST([SYSTEM_LUA_PATH]) - adl_RECURSIVE_EVAL(["$(${LUA} -e 'print(package.cpath)')"], [SYSTEM_LUA_CPATH]) +AC_DEFINE_UNQUOTED([SYSTEM_LUA_PATH], ["${SYSTEM_LUA_PATH}"],[System Lua package path]) AC_DEFINE_UNQUOTED([SYSTEM_LUA_CPATH], ["${SYSTEM_LUA_CPATH}"], [System Lua package cpath]) +AC_SUBST([SYSTEM_LUA_PATH]) AC_SUBST([SYSTEM_LUA_CPATH]) +# Accommodate Homebrew and/or other distros that pretend a vendored location is the system. +AM_COND_IF([VENDORED_LUAROCKS], + [VENDORED_LUAROCKS_DIR="$with_vendored_luarocks_dir"]) +AC_SUBST([VENDORED_LUAROCKS_DIR]) + adl_RECURSIVE_EVAL(["${libdir}/${TRANSFORMED_PACKAGE_NAME}"], [SILE_LIB_PATH]) AC_DEFINE_UNQUOTED([SILE_LIB_PATH],["${SILE_LIB_PATH}"], [Path for SILE libraries]) AC_SUBST([SILE_LIB_PATH]) diff --git a/core/pathsetup.lua.in b/core/pathsetup.lua.in index 9dff27a01..d7556f58d 100644 --- a/core/pathsetup.lua.in +++ b/core/pathsetup.lua.in @@ -6,16 +6,17 @@ if "@SYSTEM_LUA_PATH@" ~= "" then end -- stylua: ignore end --- In the event the user has exported Lua environment variables, use them like a system Lua VM would. This essentially --- nukes the existing runtime path and uses only the new value. This is useful for using `eval $(luarocks --local path)` +-- In the event the user has exported Lua environment variables, use them like a system Lua VM would. This can either +-- nuke the existing value and fully replace it, or using the Lua convention of ';;' to signify the default path, we can +-- extend what we deduced about the system at build time. This is useful for using `eval $(luarocks --local path)` -- or similar incantations that setup a path that will reach 3rd party modules. local env_lua_path = os.getenv("LUA_PATH") if env_lua_path then - package.path = env_lua_path + package.path = env_lua_path:gsub(";;", (";%s;"):format(package.path)) end local env_lua_cpath = os.getenv("LUA_CPATH") if env_lua_cpath then - package.cpath = env_lua_cpath + package.cpath = env_lua_cpath:gsub(";;", (";%s;"):format(package.cpath)) end local executable = debug.getinfo(3, "S").source @@ -92,6 +93,10 @@ extendPaths("@SILE_LIB_PATH@", true) -- development mode source directory or expected system installation location). if "@SYSTEM_LUAROCKS_FALSE@" == "" then -- see ./configure --with[out]-system-luarocks extendPathsRocks("@SILE_PATH@/lua_modules") +elseif "@VENDORED_LUAROCKS_TRUE@" == "" then -- see ./configure --with-vendored-luarocks=DIR + -- Accommodate Homebrew (and any other distros that pretend a vendored location is the system) in handling their + -- preferred location without clobbering users’ ability to setup 3rd party packages using `luarocks path`. + extendPathsRocks("@VENDORED_LUAROCKS_DIR@") end -- Stuff the variants of system Lua Rocks paths with sile suffixes added back at higher priority that regular paths.