lua*Packages: Consolidate separate setup hooks together

- Lua packages now consistently use LUA_PATH/LUA_CPATH rather than a mix
  of those and NIX_LUA_PATH/NIX_LUA_CPATH
- Lua libraries are now consistently only added to the search path
variables if:
    1) The library actually has a corresponding directory to search
    2) The library is not already present in the search path
  This should help prevent the search paths from growing overly large
- Fixed bugs in some path helpers
- Changed the affected shell script indentation to 2 spaces; nixpkgs
  shell scripts are inconsistently split between 2 and 4 space
  indentation, but 2 matches better with the Nix expressions, so IMO it
  makes more sense
This commit is contained in:
Alexei Robyn
2019-08-21 23:03:11 +10:00
committed by Frederik Rietdijk
parent 59d85b9910
commit c62337d9c7
5 changed files with 103 additions and 132 deletions

View File

@@ -1,47 +1,47 @@
# set -e
nix_print() {
if [ ${NIX_DEBUG:-0} -ge $1 ]; then
echo "$2"
fi
if [ ${NIX_DEBUG:-0} -ge $1 ]; then
echo "$2"
fi
}
nix_debug() {
nix_print 3 "$1"
nix_print 3 "$1"
}
addToLuaSearchPathWithCustomDelimiter() {
local varName="$1"
local absPattern="$2"
# delete longest match starting from the lua placeholder '?'
local topDir="${absPattern%%\?*}"
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 grows too big
if [ ! -d "$topDir" ]; then return; fi
# export only if the folder exists else LUA_PATH/LUA_CPATH grow too large
if [[ ! -d "$topDir" ]]; then return; fi
export "${varName}=${!varName:+${!varName};}${absPattern}"
# export only if we haven't already got this dir in the search path
if [[ ${!varName} == *"$absPattern"* ]]; then return; fi
export "${varName}=${!varName:+${!varName};}${absPattern}"
}
addToLuaPath() {
local dir="$1"
local dir="$1"
if [[ ! -d "$dir" ]]; then
nix_debug "$dir not a directory abort"
return 0
fi
cd "$dir"
for pattern in @luapathsearchpaths@;
do
addToLuaSearchPathWithCustomDelimiter NIX_LUA_PATH "$PWD/$pattern"
done
if [[ ! -d "$dir" ]]; then
nix_debug "$dir not a directory abort"
return 0
fi
cd "$dir"
for pattern in @luapathsearchpaths@; do
addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern"
done
# LUA_CPATH
for pattern in @luacpathsearchpaths@;
do
addToLuaSearchPathWithCustomDelimiter NIX_LUA_CPATH "$PWD/$pattern"
done
cd - >/dev/null
# LUA_CPATH
for pattern in @luacpathsearchpaths@; do
addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern"
done
cd - >/dev/null
}
addEnvHooks "$hostOffset" addToLuaPath