diff options
author | Matthieu C. <886074+teto@users.noreply.github.com> | 2024-06-12 15:31:04 +0200 |
---|---|---|
committer | Matthieu C. <886074+teto@users.noreply.github.com> | 2024-06-12 15:31:04 +0200 |
commit | 665f3f694bfc6c2f3a95a98b1abf71d2961879bb (patch) | |
tree | 4bcf316d1b7104fb3589eaea7b7e495660debabc /pkgs/development/interpreters/lua-5 | |
parent | 7e1ae5e8bbb9f6733c50aebdba9a242ee8d61d04 (diff) |
lua: take into propagated-build-inputs when building LUA_PATH
so far we ignored propagated-build-inputs
Diffstat (limited to 'pkgs/development/interpreters/lua-5')
-rw-r--r-- | pkgs/development/interpreters/lua-5/interpreter.nix | 2 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/tests/default.nix | 13 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/utils.sh | 83 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/wrap.sh | 44 | ||||
-rw-r--r-- | pkgs/development/interpreters/lua-5/wrapper.nix | 2 |
5 files changed, 97 insertions, 47 deletions
diff --git a/pkgs/development/interpreters/lua-5/interpreter.nix b/pkgs/development/interpreters/lua-5/interpreter.nix index 7775fa5c84939..497307d57b3f3 100644 --- a/pkgs/development/interpreters/lua-5/interpreter.nix +++ b/pkgs/development/interpreters/lua-5/interpreter.nix @@ -54,7 +54,7 @@ stdenv.mkDerivation (finalAttrs: LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList; setupHook = builtins.toFile "lua-setup-hook" '' source @out@/nix-support/utils.sh - addEnvHooks "$hostOffset" addToLuaPath + addEnvHooks "$hostOffset" luaEnvHook ''; nativeBuildInputs = [ makeWrapper ]; diff --git a/pkgs/development/interpreters/lua-5/tests/default.nix b/pkgs/development/interpreters/lua-5/tests/default.nix index c95d11aefc967..768f07cb84003 100644 --- a/pkgs/development/interpreters/lua-5/tests/default.nix +++ b/pkgs/development/interpreters/lua-5/tests/default.nix @@ -96,4 +96,17 @@ in touch $out ''); + + + /* + Check that a lua package's propagatedBuildInputs end up in LUA_PATH + */ + checkPropagatedBuildInputs = pkgs.runCommandLocal "test-${lua.name}-setup-hook" ({ + # lua-curl is a propagatedBuildInput of rest-nvim has + buildInputs = [ lua.pkgs.rest-nvim ]; + }) ('' + ${lua}/bin/lua -e "require'cURL'" + touch $out + ''); + }) diff --git a/pkgs/development/interpreters/lua-5/utils.sh b/pkgs/development/interpreters/lua-5/utils.sh index 5491f8f7ad2d5..2365af08dc9cb 100644 --- a/pkgs/development/interpreters/lua-5/utils.sh +++ b/pkgs/development/interpreters/lua-5/utils.sh @@ -1,4 +1,8 @@ -#!/bin/sh +#!/bin/bash + +declare -gA luaPathsSeen=() + +# shellcheck disable=SC2164,SC2041 nix_print() { if [ ${NIX_DEBUG:-0} -ge $1 ]; then echo "$2" @@ -33,13 +37,53 @@ addToLuaSearchPathWithCustomDelimiter() { shopt -u globstar } +# used in setup Hooks to load LUA_PATH and LUA_CPATH +# luaEnvHook +luaEnvHook() { + _addToLuaPath "$1" +} + addToLuaPath() { 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 LUA_PATH "$PWD/$pattern" + done + + # LUA_CPATH + for pattern in @luacpathsearchpaths@; do + addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern" + done + cd - >/dev/null +} + + +_addToLuaPath() { + local dir="$1" + + echo "_addToLuaPath called for dir $dir" + if [[ ! -d "$dir" ]]; then nix_debug "$dir not a directory abort" return 0 fi + +# set -x + # if [ -n "${pythonPathsSeen[$dir]}" ]; then return; fi + if [[ -n "${luaPathsSeen[$dir]:-}" ]]; then + # if [ -n "${luaPathsSeen[$dir]}" ]; then + echo "$dir already parsed" + return + fi + + luaPathsSeen["$dir"]=true + + # shellcheck disable=SC2164 cd "$dir" for pattern in @luapathsearchpaths@; do addToLuaSearchPathWithCustomDelimiter LUA_PATH "$PWD/$pattern" @@ -49,6 +93,43 @@ addToLuaPath() { for pattern in @luacpathsearchpaths@; do addToLuaSearchPathWithCustomDelimiter LUA_CPATH "$PWD/$pattern" done + cd - >/dev/null + + addToSearchPath program_PATH "$dir"/bin + + # Inspect the propagated inputs (if they exist) and recur on them. + local prop="$dir/nix-support/propagated-build-inputs" + if [ -e "$prop" ]; then + local new_path + for new_path in $(cat $prop); do + echo "newpath: $new_path" + _addToLuaPath "$new_path" + done + fi + } +# Builds environment variables like LUA_PATH and PATH walking through closure +# of dependencies. +buildLuaPath() { + local luaPath="$1" + local path + + echo "BUILD_LUA_PATH" + +# # set -x +# # Create an empty table of paths (see doc on loadFromPropagatedInputs +# # for how this is used). Build up the program_PATH and program_LUA_PATH +# # variables. + # declare -gA luaPathsSeen=() +# # shellcheck disable=SC2034 + program_PATH= + luaPathsSeen["@lua@"]=1 +# addToSearchPath program_PATH @lua@/bin + for path in $luaPath; do + _addToLuaPath "$path" + done +} + + diff --git a/pkgs/development/interpreters/lua-5/wrap.sh b/pkgs/development/interpreters/lua-5/wrap.sh index 7d59cf6095775..f6868e6faac56 100644 --- a/pkgs/development/interpreters/lua-5/wrap.sh +++ b/pkgs/development/interpreters/lua-5/wrap.sh @@ -9,24 +9,6 @@ wrapLuaPrograms() { wrapLuaProgramsIn "$out/bin" "$out $luaPath" } -# Builds environment variables like LUA_PATH and PATH walking through closure -# of dependencies. -buildLuaPath() { - local luaPath="$1" - local path - - # Create an empty table of paths (see doc on loadFromPropagatedInputs - # for how this is used). Build up the program_PATH and program_LUA_PATH - # variables. - declare -A luaPathsSeen=() - program_PATH= - luaPathsSeen["@lua@"]=1 - addToSearchPath program_PATH @lua@/bin - for path in $luaPath; do - addToLuaPath "$path" - done -} - # 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). # luaPath is a list of directories @@ -47,7 +29,6 @@ wrapLuaProgramsIn() { # Find all regular files in the output directory that are executable. find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do # Rewrite "#! .../env lua" to "#! /nix/store/.../lua". - # Strip suffix, like "3" or "2.7m" -- we don't have any choice on which # Lua to use besides one with this hook anyway. if head -n1 "$f" | grep -q '#!.*/env.*\(lua\)'; then sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^" @@ -73,28 +54,3 @@ wrapLuaProgramsIn() { done } - -# Adds the lib and bin directories to the LUA_PATH and PATH variables, -# respectively. Recurses on any paths declared in -# `propagated-native-build-inputs`, while avoiding duplicating paths by -# flagging the directories it has visited in `luaPathsSeen`. -loadFromPropagatedInputs() { - local dir="$1" - # Stop if we've already visited here. - if [ -n "${luaPathsSeen[$dir]}" ]; then - return - fi - luaPathsSeen[$dir]=1 - - addToLuaPath "$dir" - addToSearchPath program_PATH $dir/bin - - # Inspect the propagated inputs (if they exist) and recur on them. - local prop="$dir/nix-support/propagated-native-build-inputs" - if [ -e "$prop" ]; then - local new_path - for new_path in $(cat $prop); do - loadFromPropagatedInputs "$new_path" - done - fi -} diff --git a/pkgs/development/interpreters/lua-5/wrapper.nix b/pkgs/development/interpreters/lua-5/wrapper.nix index 07ea75605c0f9..6eb94b60360bb 100644 --- a/pkgs/development/interpreters/lua-5/wrapper.nix +++ b/pkgs/development/interpreters/lua-5/wrapper.nix @@ -30,7 +30,7 @@ let fi mkdir -p "$out/bin" - addToLuaPath "$out" + buildLuaPath "$out" # take every binary from lua packages and put them into the env for path in ${lib.concatStringsSep " " paths}; do |