Permalink
Browse files

fetch dependencies from luarocks

  • Loading branch information...
1 parent 8abf583 commit 6d9b15e371185716301f89eea154c45987c4aabc @leafo committed Feb 5, 2012
Showing with 163 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +9 −0 Makefile
  3. +11 −1 bin/compile
  4. +3 −0 opt/Makefile
  5. +78 −0 opt/prepare.lua
  6. +55 −0 opt/prepare.moon
  7. +6 −0 test/test_package.lua
View
@@ -0,0 +1 @@
+tmp-build/
View
@@ -0,0 +1,9 @@
+
+all:
+ cd opt; make
+
+test::
+ -rm -r tmp-build
+ mkdir -p tmp-build
+ cp test/test_package.lua tmp-build/package.lua
+ ENV=local bin/compile tmp-build
View
@@ -16,10 +16,20 @@ function indent() {
}
BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
+OPT_DIR=$(cd "$BIN_DIR/../opt"; pwd)
+
+LUA=$BIN_DIR/../opt/lua
+
+if [ "$ENV" == "local" ]; then
+ LUA=lua
+fi
cd $BUILD_DIR
mkdir -p bin
echo "-----> Copying lua to bin"
-cp "$BIN_DIR/../opt/lua" "bin/"
+cp "$OPT_DIR/lua" "bin/"
+
+echo "-----> Installing packages"
+$LUA "$OPT_DIR/prepare.lua" "package.lua" $OPT_DIR 2>&1 | indent
View
@@ -0,0 +1,3 @@
+
+all:
+ moonc *.moon
View
@@ -0,0 +1,78 @@
+local package_fname, opt_dir = ...
+local concat = table.concat
+if not package_fname then
+ error("missing package file")
+end
+if not opt_dir then
+ error("missing opt dir")
+end
+local fn = loadfile(package_fname)
+if not fn then
+ print("Failed to open package file:", package_fname)
+ os.exit(1)
+end
+local strip
+strip = function(str)
+ return str:match("^%s*(.-)%s*$")
+end
+local read_cmd
+read_cmd = function(cmd)
+ local f = io.popen(cmd, "r")
+ do
+ local _with_0 = strip(f:read("*a"))
+ f:close()
+ return _with_0
+ end
+end
+local tree = read_cmd("dirname " .. package_fname) .. "/packages"
+local lua_bin = opt_dir .. "/lua"
+if os.getenv("ENV") == "local" then
+ lua_bin = "lua"
+end
+local luarocks_dir = opt_dir .. "/luarocks"
+local lua_path = concat({
+ luarocks_dir .. "/?.lua"
+}, ";")
+local install
+install = function(pkg_name)
+ local cmd = concat({
+ "LUA_PATH='",
+ lua_path,
+ ";;' ",
+ lua_bin,
+ " ",
+ opt_dir,
+ "/luarocks/bin/luarocks",
+ " --tree=",
+ tree,
+ " install ",
+ pkg_name
+ })
+ return os.execute(cmd)
+end
+local actions = {
+ depends = function(tbl)
+ return (function()
+ local _accum_0 = { }
+ local _len_0 = 0
+ local _list_0 = tbl
+ for _index_0 = 1, #_list_0 do
+ local dep = _list_0[_index_0]
+ _len_0 = _len_0 + 1
+ _accum_0[_len_0] = install(dep)
+ end
+ return _accum_0
+ end)()
+ end
+}
+setfenv(fn, setmetatable({ }, {
+ __index = function(self, name)
+ local orig = _G[name]
+ if orig ~= nil then
+ return orig
+ end
+ return actions[name] or function() end
+ end
+}))
+os.execute("mkdir -p " .. tree)
+fn()
View
@@ -0,0 +1,55 @@
+
+package_fname, opt_dir = ...
+
+import concat from table
+
+error "missing package file" if not package_fname
+error "missing opt dir" if not opt_dir
+
+fn = loadfile package_fname
+if not fn
+ print "Failed to open package file:", package_fname
+ os.exit 1
+
+strip = (str) -> str\match "^%s*(.-)%s*$"
+
+read_cmd = (cmd) ->
+ f = io.popen cmd, "r"
+ with strip f\read"*a"
+ f\close!
+
+-- where packages are installed
+tree = read_cmd("dirname " .. package_fname) .. "/packages"
+
+lua_bin = opt_dir .. "/lua"
+lua_bin = "lua" if os.getenv("ENV") == "local"
+
+luarocks_dir = opt_dir .. "/luarocks"
+
+lua_path = concat {
+ luarocks_dir .. "/?.lua"
+}, ";"
+
+install = (pkg_name) ->
+ cmd = concat {
+ "LUA_PATH='", lua_path, ";;' "
+ lua_bin, " ", opt_dir, "/luarocks/bin/luarocks"
+ " --tree=", tree
+ " install ", pkg_name
+ }
+ os.execute cmd
+
+actions = {
+ depends: (tbl) ->
+ install dep for dep in *tbl
+}
+
+setfenv fn, setmetatable {}, {
+ __index: (name) =>
+ orig = _G[name]
+ return orig if orig != nil
+ actions[name] or ->
+}
+
+os.execute "mkdir -p " .. tree
+fn!
@@ -0,0 +1,6 @@
+
+depends {
+ "luafilesystem",
+ "xavante"
+}
+

0 comments on commit 6d9b15e

Please sign in to comment.