about summary refs log tree commit diff
path: root/pkgs/development/interpreters/lua-5/utils.sh
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/interpreters/lua-5/utils.sh')
-rw-r--r--pkgs/development/interpreters/lua-5/utils.sh83
1 files changed, 82 insertions, 1 deletions
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
+}
+
+