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:
parent
59d85b9910
commit
c62337d9c7
@ -16,8 +16,11 @@ addToLuaSearchPathWithCustomDelimiter() {
|
|||||||
# delete longest match starting from the lua placeholder '?'
|
# delete longest match starting from the lua placeholder '?'
|
||||||
local topDir="${absPattern%%\?*}"
|
local topDir="${absPattern%%\?*}"
|
||||||
|
|
||||||
# export only if the folder exists else LUA_PATH grows too big
|
# export only if the folder exists else LUA_PATH/LUA_CPATH grow too large
|
||||||
if [ ! -d "$topDir" ]; then return; fi
|
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
|
||||||
|
|
||||||
export "${varName}=${!varName:+${!varName};}${absPattern}"
|
export "${varName}=${!varName:+${!varName};}${absPattern}"
|
||||||
}
|
}
|
||||||
@ -30,18 +33,15 @@ addToLuaPath() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
for pattern in @luapathsearchpaths@;
|
for pattern in @luapathsearchpaths@; do
|
||||||
do
|
addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern"
|
||||||
addToLuaSearchPathWithCustomDelimiter NIX_LUA_PATH "$PWD/$pattern"
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# LUA_CPATH
|
# LUA_CPATH
|
||||||
for pattern in @luacpathsearchpaths@;
|
for pattern in @luacpathsearchpaths@; do
|
||||||
do
|
addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern"
|
||||||
addToLuaSearchPathWithCustomDelimiter NIX_LUA_CPATH "$PWD/$pattern"
|
|
||||||
done
|
done
|
||||||
cd - >/dev/null
|
cd - >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
addEnvHooks "$hostOffset" addToLuaPath
|
addEnvHooks "$hostOffset" addToLuaPath
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ buildLuaPath() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# with an executable shell script which will set some environment variables
|
# with an executable shell script which will set some environment variables
|
||||||
# and then call into the original binary (which has been given a .wrapped suffix).
|
# and then call into the original binary (which has been given a .wrapped suffix).
|
||||||
# luaPath is a list of directories
|
# luaPath is a list of directories
|
||||||
@ -57,8 +56,8 @@ wrapLuaProgramsIn() {
|
|||||||
# (see pkgs/build-support/setup-hooks/make-wrapper.sh)
|
# (see pkgs/build-support/setup-hooks/make-wrapper.sh)
|
||||||
local -a wrap_args=("$f"
|
local -a wrap_args=("$f"
|
||||||
--prefix PATH ':' "$program_PATH"
|
--prefix PATH ':' "$program_PATH"
|
||||||
--prefix LUA_PATH ';' "$NIX_LUA_PATH"
|
--prefix LUA_PATH ';' "$LUA_PATH"
|
||||||
--prefix LUA_CPATH ';' "$NIX_LUA_CPATH"
|
--prefix LUA_CPATH ';' "$LUA_CPATH"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add any additional arguments provided by makeWrapperArgs
|
# Add any additional arguments provided by makeWrapperArgs
|
||||||
@ -81,7 +80,7 @@ loadFromPropagatedInputs() {
|
|||||||
local dir="$1"
|
local dir="$1"
|
||||||
# Stop if we've already visited here.
|
# Stop if we've already visited here.
|
||||||
if [ -n "${luaPathsSeen[$dir]}" ]; then
|
if [ -n "${luaPathsSeen[$dir]}" ]; then
|
||||||
return;
|
return
|
||||||
fi
|
fi
|
||||||
luaPathsSeen[$dir]=1
|
luaPathsSeen[$dir]=1
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ let
|
|||||||
rm -f "$out/bin/$prg"
|
rm -f "$out/bin/$prg"
|
||||||
if [ -x "$prg" ]; then
|
if [ -x "$prg" ]; then
|
||||||
nix_debug "Making wrapper $prg"
|
nix_debug "Making wrapper $prg"
|
||||||
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --suffix LUA_PATH ';' "$NIX_LUA_PATH" --suffix LUA_CPATH ';' "$NIX_LUA_CPATH" ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
|
makeWrapper "$path/bin/$prg" "$out/bin/$prg" --suffix LUA_PATH ';' "$LUA_PATH" --suffix LUA_CPATH ';' "$LUA_CPATH" ${stdenv.lib.concatStringsSep " " makeWrapperArgs}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{ lua, writeText, toLuaModule }:
|
{ lua, writeText, toLuaModule }:
|
||||||
|
|
||||||
{ buildInputs ? [], disabled ? false, ... } @ attrs:
|
{ disabled ? false, ... } @ attrs:
|
||||||
|
|
||||||
if disabled then
|
if disabled then
|
||||||
throw "${attrs.name} not supported by interpreter lua-${lua.luaversion}"
|
throw "${attrs.name} not supported by interpreter lua-${lua.luaversion}"
|
||||||
@ -18,37 +18,8 @@ else
|
|||||||
//
|
//
|
||||||
{
|
{
|
||||||
name = "lua${lua.luaversion}-" + attrs.name;
|
name = "lua${lua.luaversion}-" + attrs.name;
|
||||||
buildInputs = buildInputs ++ [ lua ];
|
propagatedBuildInputs = [
|
||||||
|
lua # propagate it for its setup-hook
|
||||||
setupHook = writeText "setup-hook.sh" ''
|
];
|
||||||
# check for lua/clua modules and don't add duplicates
|
|
||||||
|
|
||||||
addLuaLibPath() {
|
|
||||||
local package_path="$1/share/lua/${lua.luaversion}"
|
|
||||||
if [[ ! -d $package_path ]]; then return; fi
|
|
||||||
if [[ $LUA_PATH = *"$package_path"* ]]; then return; fi
|
|
||||||
|
|
||||||
if [[ -z $LUA_PATH ]]; then
|
|
||||||
export LUA_PATH="$package_path/?.lua;$package_path/?/init.lua"
|
|
||||||
else
|
|
||||||
export LUA_PATH="$LUA_PATH;$package_path/?.lua;$package_path/?/init.lua"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
addLuaLibCPath() {
|
|
||||||
local package_cpath="$1/lib/lua/${lua.luaversion}"
|
|
||||||
if [[ ! -d $package_cpath ]]; then return; fi
|
|
||||||
if [[ $LUA_CPATH = *"$package_cpath"* ]]; then return; fi
|
|
||||||
|
|
||||||
if [[ -z $LUA_CPATH ]]; then
|
|
||||||
export LUA_CPATH="$package_cpath/?.so"
|
|
||||||
else
|
|
||||||
export LUA_CPATH="$LUA_CPATH;$package_cpath/?.so"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
addEnvHooks "$hostOffset" addLuaLibPath
|
|
||||||
addEnvHooks "$hostOffset" addLuaLibCPath
|
|
||||||
'';
|
|
||||||
}
|
}
|
||||||
) )
|
) )
|
||||||
|
@ -64,17 +64,18 @@ in
|
|||||||
with self; {
|
with self; {
|
||||||
|
|
||||||
getLuaPathList = majorVersion: [
|
getLuaPathList = majorVersion: [
|
||||||
"lib/lua/${majorVersion}/?.lua" "share/lua/${majorVersion}/?.lua"
|
"share/lua/${majorVersion}/?.lua"
|
||||||
"share/lua/${majorVersion}/?/init.lua" "lib/lua/${majorVersion}/?/init.lua"
|
"share/lua/${majorVersion}/?/init.lua"
|
||||||
];
|
];
|
||||||
getLuaCPathList = majorVersion: [
|
getLuaCPathList = majorVersion: [
|
||||||
"lib/lua/${majorVersion}/?.so" "share/lua/${majorVersion}/?.so" "share/lua/${majorVersion}/?/init.so"
|
"lib/lua/${majorVersion}/?.so"
|
||||||
];
|
];
|
||||||
|
|
||||||
# helper functions for dealing with LUA_PATH and LUA_CPATH
|
# helper functions for dealing with LUA_PATH and LUA_CPATH
|
||||||
getPath = lib : type : "${lib}/lib/lua/${lua.luaversion}/?.${type};${lib}/share/lua/${lua.luaversion}/?.${type}";
|
getPath = drv: pathListForVersion:
|
||||||
getLuaPath = lib : getPath lib "lua";
|
lib.concatMapStringsSep ";" (path: "${drv}/${path}") (pathListForVersion lua.luaversion);
|
||||||
getLuaCPath = lib : getPath lib "so";
|
getLuaPath = drv: getPath drv getLuaPathList;
|
||||||
|
getLuaCPath = drv: getPath drv getLuaCPathList;
|
||||||
|
|
||||||
#define build lua package function
|
#define build lua package function
|
||||||
buildLuaPackage = callPackage ../development/lua-modules/generic {
|
buildLuaPackage = callPackage ../development/lua-modules/generic {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user