forked from heroku/heroku-buildpack-c
-
Notifications
You must be signed in to change notification settings - Fork 28
/
prepare.moon
66 lines (47 loc) · 1.36 KB
/
prepare.moon
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
62
63
64
65
66
rockspec_path, opt_dir = ...
error "Missing opt_dir" if not opt_dir
error "Missing rockspec_path" if not rockspec_path
strip = (str) -> str\match "^%s*(.-)%s*$"
read_cmd = (cmd) ->
f = io.popen cmd, "r"
with strip f\read"*a"
f\close!
full_path = (dir) ->
path = read_cmd("dirname " .. rockspec_path) .. "/" .. dir
read_cmd "cd " .. path .. " && pwd"
-- where packages are installed
tree = full_path "packages"
bin = full_path "bin"
-- set path so we can find luarocks
luarocks_dir = opt_dir .. "/luarocks"
package.path = luarocks_dir .. "/?.lua;" .. package.path
-- keep error messages simple
error = (msg) ->
print msg
os.exit 1
fn = loadfile rockspec_path
error "Failed to open rockspec:", rockspec_path if not fn
rockspec = {
name: "anonymous_app"
dependencies: {}
}
setfenv(fn, rockspec)!
path = require"luarocks.path"
deps = require"luarocks.deps"
install = require"luarocks.install"
util = require"luarocks.util"
cfg = require"luarocks.cfg"
cfg.wrap_bin_scripts = false
util.deep_merge cfg, rockspec.config if rockspec.config
extras = {}
rockspec.dependencies = for dep in *rockspec.dependencies
parsed = deps.parse_dep dep
if not parsed
table.insert extras, dep
parsed
path.use_tree tree
cfg.deploy_bin_dir = bin
success, msg = deps.fulfill_dependencies rockspec, "one"
error msg if not success
for extra in *extras
install.run extra