python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / development / interpreters / lua-5 / wrap.sh
blob5941ff4a6b98571d1247ac8f57d18510f88b1674
1 # Inspired by python/wrapper.nix
2 # Wrapper around wrapLuaProgramsIn, below. The $luaPath
3 # variable is passed in from the buildLuarocksPackage function.
4 set -e
6 wrapLuaPrograms() {
7 wrapLuaProgramsIn "$out/bin" "$out $luaPath"
10 # Builds environment variables like LUA_PATH and PATH walking through closure
11 # of dependencies.
12 buildLuaPath() {
13 local luaPath="$1"
14 local path
16 # Create an empty table of paths (see doc on loadFromPropagatedInputs
17 # for how this is used). Build up the program_PATH and program_LUA_PATH
18 # variables.
19 declare -A luaPathsSeen=()
20 program_PATH=
21 luaPathsSeen["@lua@"]=1
22 addToSearchPath program_PATH @lua@/bin
23 for path in $luaPath; do
24 addToLuaPath "$path"
25 done
28 # with an executable shell script which will set some environment variables
29 # and then call into the original binary (which has been given a .wrapped suffix).
30 # luaPath is a list of directories
31 wrapLuaProgramsIn() {
32 local dir="$1"
33 local luaPath="$2"
34 local f
36 buildLuaPath "$luaPath"
38 if [ ! -d "$dir" ]; then
39 nix_debug "$dir not a directory"
40 return
43 nix_debug "wrapping programs in [$dir]"
45 # Find all regular files in the output directory that are executable.
46 find "$dir" -type f -perm -0100 -print0 | while read -d "" f; do
47 # Rewrite "#! .../env lua" to "#! /nix/store/.../lua".
48 # Strip suffix, like "3" or "2.7m" -- we don't have any choice on which
49 # Lua to use besides one with this hook anyway.
50 if head -n1 "$f" | grep -q '#!.*/env.*\(lua\)'; then
51 sed -i "$f" -e "1 s^.*/env[ ]*\(lua\)[^ ]*^#! @executable@^"
54 # wrapProgram creates the executable shell script described
55 # above. The script will set LUA_(C)PATH and PATH variables!
56 # (see pkgs/build-support/setup-hooks/make-wrapper.sh)
57 local -a wrap_args=("$f"
58 --prefix PATH ':' "$program_PATH"
59 --prefix LUA_PATH ';' "$LUA_PATH"
60 --prefix LUA_CPATH ';' "$LUA_CPATH"
63 # Add any additional arguments provided by makeWrapperArgs
64 # argument to buildLuaPackage.
65 # makeWrapperArgs
66 local -a user_args="($makeWrapperArgs)"
67 local -a wrapProgramArgs=("${wrap_args[@]}" "${user_args[@]}")
69 # see setup-hooks/make-wrapper.sh
70 wrapProgram "${wrapProgramArgs[@]}"
72 done
75 # Adds the lib and bin directories to the LUA_PATH and PATH variables,
76 # respectively. Recurses on any paths declared in
77 # `propagated-native-build-inputs`, while avoiding duplicating paths by
78 # flagging the directories it has visited in `luaPathsSeen`.
79 loadFromPropagatedInputs() {
80 local dir="$1"
81 # Stop if we've already visited here.
82 if [ -n "${luaPathsSeen[$dir]}" ]; then
83 return
85 luaPathsSeen[$dir]=1
87 addToLuaPath "$dir"
88 addToSearchPath program_PATH $dir/bin
90 # Inspect the propagated inputs (if they exist) and recur on them.
91 local prop="$dir/nix-support/propagated-native-build-inputs"
92 if [ -e "$prop" ]; then
93 local new_path
94 for new_path in $(cat $prop); do
95 loadFromPropagatedInputs "$new_path"
96 done