-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Expand file tree
/
Copy pathluarocks_target.sh
More file actions
61 lines (49 loc) · 1.97 KB
/
Copy pathluarocks_target.sh
File metadata and controls
61 lines (49 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash -e
# template variables starts
luarocks_version="{{luarocks_version}}"
install_destdir="{{install_destdir}}"
build_destdir="{{build_destdir}}"
luarocks_exec="{{@@luarocks//:luarocks_exec}}"
luajit_path="{{@@openresty//:luajit}}"
lua_path="{{@@lua//:lua}}"
luarocks_host_path="{{@@luarocks//:luarocks_host}}"
luarocks_wrap_script="{{@@//build/luarocks:luarocks_wrap_script.lua}}"
# template variables ends
mkdir -p $(dirname $@)
# install luarocks
$luarocks_exec install "luarocks $luarocks_version"
# use host configuration to invoke luarocks API to wrap a correct bin/luarocks script
rocks_tree=$(dirname $luarocks_exec)/luarocks_tree
host_luajit=$luajit_path/bin/luajit
host_luarocks_tree=$luarocks_host_path
export LUA_PATH="$build_destdir/share/lua/5.1/?.lua;$build_destdir/share/lua/5.1/?/init.lua;$host_luarocks_tree/share/lua/5.1/?.lua;$host_luarocks_tree/share/lua/5.1/?/init.lua;;"
ROCKS_CONFIG="luarocks_make_config.lua"
cat << EOF > $ROCKS_CONFIG
rocks_trees = {
{ name = [[system]], root = [[$rocks_tree]] }
}
EOF
export LUAROCKS_CONFIG=$ROCKS_CONFIG
$host_luajit $luarocks_wrap_script \
luarocks $rocks_tree $install_destdir > $@.tmp 2>&1
# write the luarocks config with host configuration
mkdir -p $rocks_tree/etc/luarocks
cat << EOF > $rocks_tree/etc/luarocks/config-5.1.lua
-- LuaRocks configuration
rocks_trees = {
{ name = "user", root = home .. "/.luarocks" };
{ name = "system", root = "$install_destdir" };
}
lua_version = "5.1";
lua_interpreter = "luajit";
variables = {
LUA_DIR = "$install_destdir/openresty/luajit";
LUA_INCDIR = "$install_destdir/openresty/luajit/include/luajit-2.1";
LUA_BINDIR = "$install_destdir/openresty/luajit/bin";
}
EOF
sed -i -e "s|$build_destdir|$install_destdir|g" $rocks_tree/bin/luarocks
sed -i -e "s|$rocks_tree|$install_destdir|g" $rocks_tree/bin/luarocks
sed -i -e "s|openresty/luajit/bin/luajit|kong/bin/lua|" $rocks_tree/bin/luarocks
# only generate the output when the command succeeds
mv $@.tmp $@