lua: update setup-hook to limit LUA_PATH size

now that the lua interpreters include working directories with `./?.lua`
in LUA_PATH, the current test includes every derivation which quickly
becomes unreadable and unpractical.
The test is adapted to add a folder only if it can find lua files in the
subfolder.
This commit is contained in:
Matthieu Coudron 2024-03-06 22:41:35 +01:00
parent 815d3683f7
commit 0c9417100f
1 changed files with 9 additions and 6 deletions

View File

@ -13,11 +13,6 @@ nix_debug() {
addToLuaSearchPathWithCustomDelimiter() {
local varName="$1"
local absPattern="$2"
# delete longest match starting from the lua placeholder '?'
local topDir="${absPattern%%\?*}"
# export only if the folder exists else LUA_PATH/LUA_CPATH grow too large
if [[ ! -d "$topDir" ]]; then return; fi
# export only if we haven't already got this dir in the search path
if [[ ${!varName-} == *"$absPattern"* ]]; then return; fi
@ -27,7 +22,15 @@ addToLuaSearchPathWithCustomDelimiter() {
# allowing relative modules to be used even when there are system modules.
if [[ ! -v "${varName}" ]]; then export "${varName}=;;"; fi
export "${varName}=${!varName:+${!varName};}${absPattern}"
# export only if the folder contains lua files
shopt -s globstar
for _file in ${absPattern/\?/\*\*}; do
export "${varName}=${!varName:+${!varName};}${absPattern}"
shopt -u globstar
return;
done
shopt -u globstar
}
addToLuaPath() {