aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2014-03-21 13:29:34 -0300
committerHisham Muhammad <hisham@gobolinux.org>2014-03-21 13:29:34 -0300
commit58b7f5d8531e054217bb6d425c04d76f699b6adf (patch)
tree06ee4d50c3393c97f99b6c693a161c880c8059a4
parent397659cc5cb30569b33cc9c0ab220f85379bc97f (diff)
parent99c664cd30b2e80b7bdd2d33ab5619556c23e41d (diff)
downloadluarocks-58b7f5d8531e054217bb6d425c04d76f699b6adf.tar.gz
luarocks-58b7f5d8531e054217bb6d425c04d76f699b6adf.tar.bz2
luarocks-58b7f5d8531e054217bb6d425c04d76f699b6adf.zip
Merge pull request #242 from mpeterv/lua52_compat
Compatibility with lua 5.2 without LUA_COMPAT_ALL
-rw-r--r--Makefile37
-rw-r--r--install.bat29
-rwxr-xr-xsrc/bin/luarocks1
-rw-r--r--src/luarocks/add.lua14
-rw-r--r--src/luarocks/admin_remove.lua14
-rw-r--r--src/luarocks/build.lua66
-rw-r--r--src/luarocks/build/builtin.lua11
-rw-r--r--src/luarocks/build/cmake.lua13
-rw-r--r--src/luarocks/build/command.lua7
-rw-r--r--src/luarocks/build/make.lua9
-rw-r--r--src/luarocks/cache.lua16
-rw-r--r--src/luarocks/cfg.lua120
-rw-r--r--src/luarocks/command_line.lua9
-rw-r--r--src/luarocks/deps.lua78
-rw-r--r--src/luarocks/dir.lua20
-rw-r--r--src/luarocks/doc.lua12
-rw-r--r--src/luarocks/download.lua18
-rw-r--r--src/luarocks/fetch.lua50
-rw-r--r--src/luarocks/fetch/cvs.lua9
-rw-r--r--src/luarocks/fetch/git.lua11
-rw-r--r--src/luarocks/fetch/git_file.lua7
-rw-r--r--src/luarocks/fetch/git_http.lua7
-rw-r--r--src/luarocks/fetch/hg.lua11
-rw-r--r--src/luarocks/fetch/sscm.lua7
-rw-r--r--src/luarocks/fetch/svn.lua9
-rw-r--r--src/luarocks/fs.lua14
-rw-r--r--src/luarocks/fs/lua.lua10
-rw-r--r--src/luarocks/fs/unix.lua18
-rw-r--r--src/luarocks/fs/unix/tools.lua55
-rw-r--r--src/luarocks/fs/win32.lua29
-rw-r--r--src/luarocks/fs/win32/tools.lua49
-rw-r--r--src/luarocks/help.lua13
-rw-r--r--src/luarocks/index.lua12
-rw-r--r--src/luarocks/install.lua20
-rw-r--r--src/luarocks/lint.lua14
-rw-r--r--src/luarocks/list.lua14
-rw-r--r--src/luarocks/loader.lua55
-rw-r--r--src/luarocks/make.lua14
-rw-r--r--src/luarocks/make_manifest.lua12
-rw-r--r--src/luarocks/manif.lua40
-rw-r--r--src/luarocks/manif_core.lua24
-rw-r--r--src/luarocks/new_version.lua14
-rw-r--r--src/luarocks/pack.lua18
-rw-r--r--src/luarocks/path.lua114
-rw-r--r--src/luarocks/path_cmd.lua8
-rw-r--r--src/luarocks/persist.lua16
-rw-r--r--src/luarocks/purge.lua14
-rw-r--r--src/luarocks/refresh_cache.lua14
-rw-r--r--src/luarocks/remove.lua22
-rw-r--r--src/luarocks/repos.lua28
-rw-r--r--src/luarocks/require.lua6
-rw-r--r--src/luarocks/search.lua44
-rw-r--r--src/luarocks/show.lua16
-rw-r--r--src/luarocks/tools/patch.lua25
-rw-r--r--src/luarocks/tools/tar.lua7
-rw-r--r--src/luarocks/tools/zip.lua11
-rw-r--r--src/luarocks/type_check.lua22
-rw-r--r--src/luarocks/unpack.lua14
-rw-r--r--src/luarocks/util.lua92
-rw-r--r--src/luarocks/validate.lua24
-rw-r--r--src/luarocks/write_rockspec.lua14
61 files changed, 850 insertions, 651 deletions
diff --git a/Makefile b/Makefile
index 1e9b9dd2..46943312 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ remove.lua fs.lua manif.lua add.lua deps.lua build.lua search.lua show.lua \
24manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \ 24manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \
25help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \ 25help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \
26admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \ 26admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \
27purge.lua path.lua write_rockspec.lua doc.lua 27purge.lua path.lua path_cmd.lua write_rockspec.lua doc.lua
28 28
29CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua 29CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua
30 30
@@ -44,56 +44,57 @@ build: src/luarocks/site_config.lua build_bins
44 44
45src/luarocks/site_config.lua: config.unix 45src/luarocks/site_config.lua: config.unix
46 rm -f src/luarocks/site_config.lua 46 rm -f src/luarocks/site_config.lua
47 echo 'module("luarocks.site_config")' >> src/luarocks/site_config.lua 47 echo 'local site_config = {}' >> src/luarocks/site_config.lua
48 if [ -n "$(PREFIX)" ] ;\ 48 if [ -n "$(PREFIX)" ] ;\
49 then \ 49 then \
50 echo "LUAROCKS_PREFIX=[[$(PREFIX)]]" >> src/luarocks/site_config.lua ;\ 50 echo "site_config.LUAROCKS_PREFIX=[[$(PREFIX)]]" >> src/luarocks/site_config.lua ;\
51 fi 51 fi
52 if [ -n "$(LUA_INCDIR)" ] ;\ 52 if [ -n "$(LUA_INCDIR)" ] ;\
53 then \ 53 then \
54 echo "LUA_INCDIR=[[$(LUA_INCDIR)]]" >> src/luarocks/site_config.lua ;\ 54 echo "site_config.LUA_INCDIR=[[$(LUA_INCDIR)]]" >> src/luarocks/site_config.lua ;\
55 fi 55 fi
56 if [ -n "$(LUA_LIBDIR)" ] ;\ 56 if [ -n "$(LUA_LIBDIR)" ] ;\
57 then \ 57 then \
58 echo "LUA_LIBDIR=[[$(LUA_LIBDIR)]]" >> src/luarocks/site_config.lua ;\ 58 echo "site_config.LUA_LIBDIR=[[$(LUA_LIBDIR)]]" >> src/luarocks/site_config.lua ;\
59 fi 59 fi
60 if [ -n "$(LUA_BINDIR)" ] ;\ 60 if [ -n "$(LUA_BINDIR)" ] ;\
61 then \ 61 then \
62 echo "LUA_BINDIR=[[$(LUA_BINDIR)]]" >> src/luarocks/site_config.lua ;\ 62 echo "site_config.LUA_BINDIR=[[$(LUA_BINDIR)]]" >> src/luarocks/site_config.lua ;\
63 fi 63 fi
64 if [ -n "$(LUA_SUFFIX)" ] ;\ 64 if [ -n "$(LUA_SUFFIX)" ] ;\
65 then \ 65 then \
66 echo "LUA_INTERPRETER=[[lua$(LUA_SUFFIX)]]" >> src/luarocks/site_config.lua ;\ 66 echo "site_config.LUA_INTERPRETER=[[lua$(LUA_SUFFIX)]]" >> src/luarocks/site_config.lua ;\
67 fi 67 fi
68 if [ -n "$(SYSCONFDIR)" ] ;\ 68 if [ -n "$(SYSCONFDIR)" ] ;\
69 then \ 69 then \
70 echo "LUAROCKS_SYSCONFDIR=[[$(SYSCONFDIR)]]" >> src/luarocks/site_config.lua ;\ 70 echo "site_config.LUAROCKS_SYSCONFDIR=[[$(SYSCONFDIR)]]" >> src/luarocks/site_config.lua ;\
71 fi 71 fi
72 if [ -n "$(ROCKS_TREE)" ] ;\ 72 if [ -n "$(ROCKS_TREE)" ] ;\
73 then \ 73 then \
74 echo "LUAROCKS_ROCKS_TREE=[[$(ROCKS_TREE)]]" >> src/luarocks/site_config.lua ;\ 74 echo "site_config.LUAROCKS_ROCKS_TREE=[[$(ROCKS_TREE)]]" >> src/luarocks/site_config.lua ;\
75 fi 75 fi
76 if [ -n "$(FORCE_CONFIG)" ] ;\ 76 if [ -n "$(FORCE_CONFIG)" ] ;\
77 then \ 77 then \
78 echo "LUAROCKS_FORCE_CONFIG=true" >> src/luarocks/site_config.lua ;\ 78 echo "site_config.LUAROCKS_FORCE_CONFIG=true" >> src/luarocks/site_config.lua ;\
79 fi 79 fi
80 if [ -n "$(LUAROCKS_ROCKS_SUBDIR)" ] ;\ 80 if [ -n "$(LUAROCKS_ROCKS_SUBDIR)" ] ;\
81 then \ 81 then \
82 echo "LUAROCKS_ROCKS_SUBDIR=[[$(LUAROCKS_ROCKS_SUBDIR)]]" >> src/luarocks/site_config.lua ;\ 82 echo "site_config.LUAROCKS_ROCKS_SUBDIR=[[$(LUAROCKS_ROCKS_SUBDIR)]]" >> src/luarocks/site_config.lua ;\
83 fi 83 fi
84 if [ "$(LUA_DIR_SET)" = "yes" ] ;\ 84 if [ "$(LUA_DIR_SET)" = "yes" ] ;\
85 then \ 85 then \
86 echo "LUA_DIR_SET=true" >> src/luarocks/site_config.lua ;\ 86 echo "site_config.LUA_DIR_SET=true" >> src/luarocks/site_config.lua ;\
87 fi 87 fi
88 echo "LUAROCKS_UNAME_S=[[$(LUAROCKS_UNAME_S)]]" >> src/luarocks/site_config.lua 88 echo "site_config.LUAROCKS_UNAME_S=[[$(LUAROCKS_UNAME_S)]]" >> src/luarocks/site_config.lua
89 echo "LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> src/luarocks/site_config.lua 89 echo "site_config.LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> src/luarocks/site_config.lua
90 echo "LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> src/luarocks/site_config.lua 90 echo "site_config.LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> src/luarocks/site_config.lua
91 echo "LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> src/luarocks/site_config.lua 91 echo "site_config.LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> src/luarocks/site_config.lua
92 if [ -n "$(MULTIARCH_SUBDIR)" ] ;\ 92 if [ -n "$(MULTIARCH_SUBDIR)" ] ;\
93 then \ 93 then \
94 echo 'LUAROCKS_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\ 94 echo 'site_config.LUAROCKS_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\
95 echo 'LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\ 95 echo 'site_config.LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\
96 fi 96 fi
97 echo "return site_config" >> src/luarocks/site_config.lua
97 98
98dev: 99dev:
99 $(MAKE) build_bins LUADIR=$(PWD)/src 100 $(MAKE) build_bins LUADIR=$(PWD)/src
diff --git a/install.bat b/install.bat
index 934154d0..287bad5b 100644
--- a/install.bat
+++ b/install.bat
@@ -771,27 +771,27 @@ if exists(S[[$LUADIR\luarocks\site_config.lua]]) then
771end 771end
772local f = io.open(vars.LUADIR.."\\luarocks\\site_config.lua", "w") 772local f = io.open(vars.LUADIR.."\\luarocks\\site_config.lua", "w")
773f:write(S[=[ 773f:write(S[=[
774module("luarocks.site_config") 774local site_config = {}
775LUA_INCDIR=[[$LUA_INCDIR]] 775site_config.LUA_INCDIR=[[$LUA_INCDIR]]
776LUA_LIBDIR=[[$LUA_LIBDIR]] 776site_config.LUA_LIBDIR=[[$LUA_LIBDIR]]
777LUA_BINDIR=[[$LUA_BINDIR]] 777site_config.LUA_BINDIR=[[$LUA_BINDIR]]
778LUA_INTERPRETER=[[$LUA_INTERPRETER]] 778site_config.LUA_INTERPRETER=[[$LUA_INTERPRETER]]
779]=]) 779]=])
780if USE_MINGW then 780if USE_MINGW then
781 f:write("LUAROCKS_UNAME_S=[[MINGW]]\n") 781 f:write("site_config.LUAROCKS_UNAME_S=[[MINGW]]\n")
782else 782else
783 f:write("LUAROCKS_UNAME_S=[[WindowsNT]]\n") 783 f:write("site_config.LUAROCKS_UNAME_S=[[WindowsNT]]\n")
784end 784end
785f:write(S[=[ 785f:write(S[=[
786LUAROCKS_UNAME_M=[[$UNAME_M]] 786site_config.LUAROCKS_UNAME_M=[[$UNAME_M]]
787LUAROCKS_SYSCONFIG=[[$SYSCONFDIR\config.lua]] 787site_config.LUAROCKS_SYSCONFIG=[[$SYSCONFDIR\config.lua]]
788LUAROCKS_ROCKS_TREE=[[$ROCKS_TREE]] 788site_config.LUAROCKS_ROCKS_TREE=[[$ROCKS_TREE]]
789LUAROCKS_PREFIX=[[$PREFIX]] 789site_config.LUAROCKS_PREFIX=[[$PREFIX]]
790LUAROCKS_DOWNLOADER=[[wget]] 790site_config.LUAROCKS_DOWNLOADER=[[wget]]
791LUAROCKS_MD5CHECKER=[[md5sum]] 791site_config.LUAROCKS_MD5CHECKER=[[md5sum]]
792]=]) 792]=])
793if FORCE_CONFIG then 793if FORCE_CONFIG then
794 f:write("local LUAROCKS_FORCE_CONFIG=true\n") 794 f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n")
795end 795end
796if exists(vars.LUADIR.."\\luarocks\\site_config.lua.bak") then 796if exists(vars.LUADIR.."\\luarocks\\site_config.lua.bak") then
797 for line in io.lines(vars.LUADIR.."\\luarocks\\site_config.lua.bak", "r") do 797 for line in io.lines(vars.LUADIR.."\\luarocks\\site_config.lua.bak", "r") do
@@ -800,6 +800,7 @@ if exists(vars.LUADIR.."\\luarocks\\site_config.lua.bak") then
800 end 800 end
801 exec(S[[DEL /F /Q "$LUADIR\luarocks\site_config.lua.bak"]]) 801 exec(S[[DEL /F /Q "$LUADIR\luarocks\site_config.lua.bak"]])
802end 802end
803f:write("return site_config\n")
803f:close() 804f:close()
804print(S[[Created LuaRocks site-config file: $LUADIR\luarocks\site_config.lua]]) 805print(S[[Created LuaRocks site-config file: $LUADIR\luarocks\site_config.lua]])
805 806
diff --git a/src/bin/luarocks b/src/bin/luarocks
index 1d81ed1e..b85fbc7c 100755
--- a/src/bin/luarocks
+++ b/src/bin/luarocks
@@ -1,4 +1,5 @@
1#!/usr/bin/env lua 1#!/usr/bin/env lua
2
2local loader = require("luarocks.loader") 3local loader = require("luarocks.loader")
3local command_line = require("luarocks.command_line") 4local command_line = require("luarocks.command_line")
4 5
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua
index c7acd5f8..fc913c95 100644
--- a/src/luarocks/add.lua
+++ b/src/luarocks/add.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the luarocks-admin "add" command. 2--- Module implementing the luarocks-admin "add" command.
3-- Adds a rock or rockspec to a rocks server. 3-- Adds a rock or rockspec to a rocks server.
4module("luarocks.add", package.seeall) 4--module("luarocks.add", package.seeall)
5local add = {}
6package.loaded["luarocks.add"] = add
5 7
6local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
7local util = require("luarocks.util") 9local util = require("luarocks.util")
@@ -11,9 +13,9 @@ local index = require("luarocks.index")
11local fs = require("luarocks.fs") 13local fs = require("luarocks.fs")
12local cache = require("luarocks.cache") 14local cache = require("luarocks.cache")
13 15
14help_summary = "Add a rock or rockspec to a rocks server." 16add.help_summary = "Add a rock or rockspec to a rocks server."
15help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" 17add.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}"
16help = [[ 18add.help = [[
17Arguments are local files, which may be rockspecs or rocks. 19Arguments are local files, which may be rockspecs or rocks.
18The flag --server indicates which server to use. 20The flag --server indicates which server to use.
19If not given, the default server set in the upload_server variable 21If not given, the default server set in the upload_server variable
@@ -106,7 +108,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server)
106 return true 108 return true
107end 109end
108 110
109function run(...) 111function add.run(...)
110 local files = { util.parse_flags(...) } 112 local files = { util.parse_flags(...) }
111 local flags = table.remove(files, 1) 113 local flags = table.remove(files, 1)
112 if #files < 1 then 114 if #files < 1 then
@@ -117,3 +119,5 @@ function run(...)
117 return add_files_to_server(not flags["no-refresh"], files, server, server_table) 119 return add_files_to_server(not flags["no-refresh"], files, server, server_table)
118end 120end
119 121
122
123return add
diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua
index 477592b1..839121d1 100644
--- a/src/luarocks/admin_remove.lua
+++ b/src/luarocks/admin_remove.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the luarocks-admin "remove" command. 2--- Module implementing the luarocks-admin "remove" command.
3-- Removes a rock or rockspec from a rocks server. 3-- Removes a rock or rockspec from a rocks server.
4module("luarocks.admin_remove", package.seeall) 4--module("luarocks.admin_remove", package.seeall)
5local admin_remove = {}
6package.loaded["luarocks.admin_remove"] = admin_remove
5 7
6local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
7local util = require("luarocks.util") 9local util = require("luarocks.util")
@@ -11,9 +13,9 @@ local index = require("luarocks.index")
11local fs = require("luarocks.fs") 13local fs = require("luarocks.fs")
12local cache = require("luarocks.cache") 14local cache = require("luarocks.cache")
13 15
14help_summary = "Remove a rock or rockspec from a rocks server." 16admin_remove.help_summary = "Remove a rock or rockspec from a rocks server."
15help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" 17admin_remove.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}"
16help = [[ 18admin_remove.help = [[
17Arguments are local files, which may be rockspecs or rocks. 19Arguments are local files, which may be rockspecs or rocks.
18The flag --server indicates which server to use. 20The flag --server indicates which server to use.
19If not given, the default server set in the upload_server variable 21If not given, the default server set in the upload_server variable
@@ -76,7 +78,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve
76 return true 78 return true
77end 79end
78 80
79function run(...) 81function admin_remove.run(...)
80 local files = { util.parse_flags(...) } 82 local files = { util.parse_flags(...) }
81 local flags = table.remove(files, 1) 83 local flags = table.remove(files, 1)
82 if #files < 1 then 84 if #files < 1 then
@@ -87,3 +89,5 @@ function run(...)
87 return remove_files_from_server(not flags["no-refresh"], files, server, server_table) 89 return remove_files_from_server(not flags["no-refresh"], files, server, server_table)
88end 90end
89 91
92
93return admin_remove
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 30cdd309..cc56c782 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "build" command. 2--- Module implementing the LuaRocks "build" command.
3-- Builds a rock, compiling its C parts if any. 3-- Builds a rock, compiling its C parts if any.
4module("luarocks.build", package.seeall) 4--module("luarocks.build", package.seeall)
5local build = {}
6package.loaded["luarocks.build"] = build
5 7
6local pack = require("luarocks.pack") 8local pack = require("luarocks.pack")
7local path = require("luarocks.path") 9local path = require("luarocks.path")
@@ -15,9 +17,9 @@ local manif = require("luarocks.manif")
15local remove = require("luarocks.remove") 17local remove = require("luarocks.remove")
16local cfg = require("luarocks.cfg") 18local cfg = require("luarocks.cfg")
17 19
18help_summary = "Build/compile a rock." 20build.help_summary = "Build/compile a rock."
19help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" 21build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}"
20help = [[ 22build.help = [[
21Build and install a rock, compiling its C parts if any. 23Build and install a rock, compiling its C parts if any.
22Argument may be a rockspec file, a source rock file 24Argument may be a rockspec file, a source rock file
23or the name of a rock to be fetched from a repository. 25or the name of a rock to be fetched from a repository.
@@ -107,16 +109,16 @@ end
107-- @param rockspec table: A rockspec table. 109-- @param rockspec table: A rockspec table.
108-- @return boolean or (nil, string): True if succeeded or 110-- @return boolean or (nil, string): True if succeeded or
109-- nil and an error message. 111-- nil and an error message.
110function apply_patches(rockspec) 112function build.apply_patches(rockspec)
111 assert(type(rockspec) == "table") 113 assert(type(rockspec) == "table")
112 114
113 local build = rockspec.build 115 local build_spec = rockspec.build
114 if build.extra_files then 116 if build_spec.extra_files then
115 extract_from_rockspec(build.extra_files) 117 extract_from_rockspec(build_spec.extra_files)
116 end 118 end
117 if build.patches then 119 if build_spec.patches then
118 extract_from_rockspec(build.patches) 120 extract_from_rockspec(build_spec.patches)
119 for patch, patchdata in util.sortedpairs(build.patches) do 121 for patch, patchdata in util.sortedpairs(build_spec.patches) do
120 util.printout("Applying patch "..patch.."...") 122 util.printout("Applying patch "..patch.."...")
121 local ok, err = fs.apply_patch(tostring(patch), patchdata) 123 local ok, err = fs.apply_patch(tostring(patch), patchdata)
122 if not ok then 124 if not ok then
@@ -157,7 +159,7 @@ end
157-- "none" for no trees. 159-- "none" for no trees.
158-- @return (string, string) or (nil, string, [string]): Name and version of 160-- @return (string, string) or (nil, string, [string]): Name and version of
159-- installed rock if succeeded or nil and an error message followed by an error code. 161-- installed rock if succeeded or nil and an error message followed by an error code.
160function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) 162function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode)
161 assert(type(rockspec_file) == "string") 163 assert(type(rockspec_file) == "string")
162 assert(type(need_to_fetch) == "boolean") 164 assert(type(need_to_fetch) == "boolean")
163 165
@@ -223,31 +225,31 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode)
223 fs.remove_dir_if_empty(path.versions_dir(name)) 225 fs.remove_dir_if_empty(path.versions_dir(name))
224 end) 226 end)
225 227
226 local build = rockspec.build 228 local build_spec = rockspec.build
227 229
228 if not minimal_mode then 230 if not minimal_mode then
229 ok, err = apply_patches(rockspec) 231 ok, err = build.apply_patches(rockspec)
230 if err then 232 if err then
231 return nil, err 233 return nil, err
232 end 234 end
233 end 235 end
234 236
235 if build.type ~= "none" then 237 if build_spec.type ~= "none" then
236 238
237 -- Temporary compatibility 239 -- Temporary compatibility
238 if build.type == "module" then 240 if build_spec.type == "module" then
239 util.printout("Do not use 'module' as a build type. Use 'builtin' instead.") 241 util.printout("Do not use 'module' as a build type. Use 'builtin' instead.")
240 build.type = "builtin" 242 build_spec.type = "builtin"
241 end 243 end
242 244
243 if cfg.accepted_build_types and util.array_contains(cfg.accepted_build_types, build.type) then 245 if cfg.accepted_build_types and util.array_contains(cfg.accepted_build_types, build_spec.type) then
244 return nil, "This rockspec uses the '"..build.type.."' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." 246 return nil, "This rockspec uses the '"..build_spec.type.."' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration."
245 end 247 end
246 248
247 local build_type 249 local build_type
248 ok, build_type = pcall(require, "luarocks.build." .. build.type) 250 ok, build_type = pcall(require, "luarocks.build." .. build_spec.type)
249 if not ok or not type(build_type) == "table" then 251 if not ok or not type(build_type) == "table" then
250 return nil, "Failed initializing build back-end for build type '"..build.type.."': "..build_type 252 return nil, "Failed initializing build back-end for build type '"..build_spec.type.."': "..build_type
251 end 253 end
252 254
253 ok, err = build_type.run(rockspec) 255 ok, err = build_type.run(rockspec)
@@ -256,16 +258,16 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode)
256 end 258 end
257 end 259 end
258 260
259 if build.install then 261 if build_spec.install then
260 for id, install_dir in pairs(dirs) do 262 for id, install_dir in pairs(dirs) do
261 ok, err = install_files(build.install[id], install_dir.name, install_dir.is_module_path) 263 ok, err = install_files(build_spec.install[id], install_dir.name, install_dir.is_module_path)
262 if not ok then 264 if not ok then
263 return nil, err 265 return nil, err
264 end 266 end
265 end 267 end
266 end 268 end
267 269
268 local copy_directories = build.copy_directories 270 local copy_directories = build_spec.copy_directories
269 local copying_default = false 271 local copying_default = false
270 if not copy_directories then 272 if not copy_directories then
271 copy_directories = {"doc"} 273 copy_directories = {"doc"}
@@ -340,7 +342,7 @@ end
340-- "order" for all trees with priority >= the current default, "none" for no trees. 342-- "order" for all trees with priority >= the current default, "none" for no trees.
341-- @return boolean or (nil, string, [string]): True if build was successful, 343-- @return boolean or (nil, string, [string]): True if build was successful,
342-- or false and an error message and an optional error code. 344-- or false and an error message and an optional error code.
343function build_rock(rock_file, need_to_fetch, deps_mode) 345function build.build_rock(rock_file, need_to_fetch, deps_mode)
344 assert(type(rock_file) == "string") 346 assert(type(rock_file) == "string")
345 assert(type(need_to_fetch) == "boolean") 347 assert(type(need_to_fetch) == "boolean")
346 348
@@ -351,24 +353,24 @@ function build_rock(rock_file, need_to_fetch, deps_mode)
351 local rockspec_file = path.rockspec_name_from_rock(rock_file) 353 local rockspec_file = path.rockspec_name_from_rock(rock_file)
352 local ok, err = fs.change_dir(unpack_dir) 354 local ok, err = fs.change_dir(unpack_dir)
353 if not ok then return nil, err end 355 if not ok then return nil, err end
354 local ok, err, errcode = build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) 356 local ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode)
355 fs.pop_dir() 357 fs.pop_dir()
356 return ok, err, errcode 358 return ok, err, errcode
357end 359end
358 360
359local function do_build(name, version, deps_mode) 361local function do_build(name, version, deps_mode)
360 if name:match("%.rockspec$") then 362 if name:match("%.rockspec$") then
361 return build_rockspec(name, true, false, deps_mode) 363 return build.build_rockspec(name, true, false, deps_mode)
362 elseif name:match("%.src%.rock$") then 364 elseif name:match("%.src%.rock$") then
363 return build_rock(name, false, deps_mode) 365 return build.build_rock(name, false, deps_mode)
364 elseif name:match("%.all%.rock$") then 366 elseif name:match("%.all%.rock$") then
365 local install = require("luarocks.install") 367 local install = require("luarocks.install")
366 return install.install_binary_rock(name, deps_mode) 368 return install.install_binary_rock(name, deps_mode)
367 elseif name:match("%.rock$") then 369 elseif name:match("%.rock$") then
368 return build_rock(name, true, deps_mode) 370 return build.build_rock(name, true, deps_mode)
369 elseif not name:match(dir.separator) then 371 elseif not name:match(dir.separator) then
370 local search = require("luarocks.search") 372 local search = require("luarocks.search")
371 return search.act_on_src_or_rockspec(run, name:lower(), version, deps.deps_mode_to_flag(deps_mode)) 373 return search.act_on_src_or_rockspec(build.run, name:lower(), version, deps.deps_mode_to_flag(deps_mode))
372 end 374 end
373 return nil, "Don't know what to do with "..name 375 return nil, "Don't know what to do with "..name
374end 376end
@@ -381,7 +383,7 @@ end
381-- also be given. 383-- also be given.
382-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an 384-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
383-- error message otherwise. exitcode is optionally returned. 385-- error message otherwise. exitcode is optionally returned.
384function run(...) 386function build.run(...)
385 local flags, name, version = util.parse_flags(...) 387 local flags, name, version = util.parse_flags(...)
386 if type(name) ~= "string" then 388 if type(name) ~= "string" then
387 return nil, "Argument missing. "..util.see_help("build") 389 return nil, "Argument missing. "..util.see_help("build")
@@ -403,3 +405,5 @@ function run(...)
403 return name, version 405 return name, version
404 end 406 end
405end 407end
408
409return build
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index 5120c85c..47aa71fc 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -1,6 +1,9 @@
1 1
2--- A builtin build system: back-end to provide a portable way of building C-based Lua modules. 2--- A builtin build system: back-end to provide a portable way of building C-based Lua modules.
3module("luarocks.build.builtin", package.seeall) 3--module("luarocks.build.builtin", package.seeall)
4local builtin = {}
5
6local unpack = unpack or table.unpack
4 7
5local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
6local path = require("luarocks.path") 9local path = require("luarocks.path")
@@ -45,7 +48,7 @@ end
45-- @param rockspec table: the loaded rockspec. 48-- @param rockspec table: the loaded rockspec.
46-- @return boolean or (nil, string): true if no errors ocurred, 49-- @return boolean or (nil, string): true if no errors ocurred,
47-- nil and an error message otherwise. 50-- nil and an error message otherwise.
48function run(rockspec) 51function builtin.run(rockspec)
49 assert(type(rockspec) == "table") 52 assert(type(rockspec) == "table")
50 local compile_object, compile_library, compile_wrapper_binary --TODO EXEWRAPPER 53 local compile_object, compile_library, compile_wrapper_binary --TODO EXEWRAPPER
51 54
@@ -172,11 +175,9 @@ function run(rockspec)
172 end 175 end
173 176
174 local ok = true 177 local ok = true
175 local err = "Build error"
176 local built_modules = {} 178 local built_modules = {}
177 local luadir = path.lua_dir(rockspec.name, rockspec.version) 179 local luadir = path.lua_dir(rockspec.name, rockspec.version)
178 local libdir = path.lib_dir(rockspec.name, rockspec.version) 180 local libdir = path.lib_dir(rockspec.name, rockspec.version)
179 local docdir = path.doc_dir(rockspec.name, rockspec.version)
180 --TODO EXEWRAPPER 181 --TODO EXEWRAPPER
181 -- On Windows, compiles an .exe for each Lua file in build.install.bin, and 182 -- On Windows, compiles an .exe for each Lua file in build.install.bin, and
182 -- replaces the filename with the .exe name. Strips the .lua extension if it exists, 183 -- replaces the filename with the .exe name. Strips the .lua extension if it exists,
@@ -262,3 +263,5 @@ function run(rockspec)
262 end 263 end
263 return true 264 return true
264end 265end
266
267return builtin
diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index 0df3a921..ed2af3ff 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -1,6 +1,7 @@
1 1
2--- Build back-end for CMake-based modules. 2--- Build back-end for CMake-based modules.
3module("luarocks.build.cmake", package.seeall) 3--module("luarocks.build.cmake", package.seeall)
4local cmake = {}
4 5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6local util = require("luarocks.util") 7local util = require("luarocks.util")
@@ -10,7 +11,7 @@ local cfg = require("luarocks.cfg")
10-- @param rockspec table: the loaded rockspec. 11-- @param rockspec table: the loaded rockspec.
11-- @return boolean or (nil, string): true if no errors ocurred, 12-- @return boolean or (nil, string): true if no errors ocurred,
12-- nil and an error message otherwise. 13-- nil and an error message otherwise.
13function run(rockspec) 14function cmake.run(rockspec)
14 assert(type(rockspec) == "table") 15 assert(type(rockspec) == "table")
15 local build = rockspec.build 16 local build = rockspec.build
16 local variables = build.variables or {} 17 local variables = build.variables or {}
@@ -28,9 +29,9 @@ function run(rockspec)
28 29
29 -- If inline cmake is present create CMakeLists.txt from it. 30 -- If inline cmake is present create CMakeLists.txt from it.
30 if type(build.cmake) == "string" then 31 if type(build.cmake) == "string" then
31 local cmake = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) 32 local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w"))
32 cmake:write(build.cmake) 33 cmake_handler:write(build.cmake)
33 cmake:close() 34 cmake_handler:close()
34 end 35 end
35 36
36 37
@@ -56,3 +57,5 @@ function run(rockspec)
56 end 57 end
57 return true 58 return true
58end 59end
60
61return cmake
diff --git a/src/luarocks/build/command.lua b/src/luarocks/build/command.lua
index aeec0da7..650e3236 100644
--- a/src/luarocks/build/command.lua
+++ b/src/luarocks/build/command.lua
@@ -1,6 +1,7 @@
1 1
2--- Build back-end for raw listing of commands in rockspec files. 2--- Build back-end for raw listing of commands in rockspec files.
3module("luarocks.build.command", package.seeall) 3--module("luarocks.build.command", package.seeall)
4local command = {}
4 5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6local util = require("luarocks.util") 7local util = require("luarocks.util")
@@ -9,7 +10,7 @@ local util = require("luarocks.util")
9-- @param rockspec table: the loaded rockspec. 10-- @param rockspec table: the loaded rockspec.
10-- @return boolean or (nil, string): true if no errors ocurred, 11-- @return boolean or (nil, string): true if no errors ocurred,
11-- nil and an error message otherwise. 12-- nil and an error message otherwise.
12function run(rockspec) 13function command.run(rockspec)
13 assert(type(rockspec) == "table") 14 assert(type(rockspec) == "table")
14 15
15 local build = rockspec.build 16 local build = rockspec.build
@@ -30,3 +31,5 @@ function run(rockspec)
30 end 31 end
31 return true 32 return true
32end 33end
34
35return command
diff --git a/src/luarocks/build/make.lua b/src/luarocks/build/make.lua
index c4b21578..0da183e9 100644
--- a/src/luarocks/build/make.lua
+++ b/src/luarocks/build/make.lua
@@ -1,6 +1,9 @@
1 1
2--- Build back-end for using Makefile-based packages. 2--- Build back-end for using Makefile-based packages.
3module("luarocks.build.make", package.seeall) 3--module("luarocks.build.make", package.seeall)
4local make = {}
5
6local unpack = unpack or table.unpack
4 7
5local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
6local util = require("luarocks.util") 9local util = require("luarocks.util")
@@ -36,7 +39,7 @@ end
36-- @param rockspec table: the loaded rockspec. 39-- @param rockspec table: the loaded rockspec.
37-- @return boolean or (nil, string): true if no errors ocurred, 40-- @return boolean or (nil, string): true if no errors ocurred,
38-- nil and an error message otherwise. 41-- nil and an error message otherwise.
39function run(rockspec) 42function make.run(rockspec)
40 assert(type(rockspec) == "table") 43 assert(type(rockspec) == "table")
41 44
42 local build = rockspec.build 45 local build = rockspec.build
@@ -90,3 +93,5 @@ function run(rockspec)
90 end 93 end
91 return true 94 return true
92end 95end
96
97return make
diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua
index a3dfe8b1..dbea8405 100644
--- a/src/luarocks/cache.lua
+++ b/src/luarocks/cache.lua
@@ -1,14 +1,16 @@
1 1
2--- Module handling the LuaRocks local cache. 2--- Module handling the LuaRocks local cache.
3-- Adds a rock or rockspec to a rocks server. 3-- Adds a rock or rockspec to a rocks server.
4module("luarocks.cache", package.seeall) 4--module("luarocks.cache", package.seeall)
5local cache = {}
6package.loaded["luarocks.cache"] = cache
5 7
6local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
7local cfg = require("luarocks.cfg") 9local cfg = require("luarocks.cfg")
8local dir = require("luarocks.dir") 10local dir = require("luarocks.dir")
9local util = require("luarocks.util") 11local util = require("luarocks.util")
10 12
11function get_upload_server(server) 13function cache.get_upload_server(server)
12 if not server then server = cfg.upload_server end 14 if not server then server = cfg.upload_server end
13 if not server then 15 if not server then
14 return nil, "No server specified and no default configured with upload_server." 16 return nil, "No server specified and no default configured with upload_server."
@@ -16,7 +18,7 @@ function get_upload_server(server)
16 return server, cfg.upload_servers and cfg.upload_servers[server] 18 return server, cfg.upload_servers and cfg.upload_servers[server]
17end 19end
18 20
19function get_server_urls(server, upload_server) 21function cache.get_server_urls(server, upload_server)
20 local download_url = server 22 local download_url = server
21 local login_url = nil 23 local login_url = nil
22 if upload_server then 24 if upload_server then
@@ -32,7 +34,7 @@ function get_server_urls(server, upload_server)
32 return download_url, login_url 34 return download_url, login_url
33end 35end
34 36
35function split_server_url(server, url, user, password) 37function cache.split_server_url(server, url, user, password)
36 local protocol, server_path = dir.split_url(url) 38 local protocol, server_path = dir.split_url(url)
37 if server_path:match("@") then 39 if server_path:match("@") then
38 local credentials 40 local credentials
@@ -50,8 +52,8 @@ function split_server_url(server, url, user, password)
50 return local_cache, protocol, server_path, user, password 52 return local_cache, protocol, server_path, user, password
51end 53end
52 54
53function refresh_local_cache(server, url, user, password) 55function cache.refresh_local_cache(server, url, user, password)
54 local local_cache, protocol, server_path, user, password = split_server_url(server, url, user, password) 56 local local_cache, protocol, server_path, user, password = cache.split_server_url(server, url, user, password)
55 57
56 local ok, err = fs.make_dir(cfg.local_cache) 58 local ok, err = fs.make_dir(cfg.local_cache)
57 if not ok then return nil, err end 59 if not ok then return nil, err end
@@ -86,3 +88,5 @@ function refresh_local_cache(server, url, user, password)
86 end 88 end
87 return local_cache, protocol, server_path, user, password 89 return local_cache, protocol, server_path, user, password
88end 90end
91
92return cache
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index e7e091e9..21cfbf6d 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -13,10 +13,12 @@
13local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION = 13local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION =
14 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION 14 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION
15 15
16module("luarocks.cfg") 16--module("luarocks.cfg")
17local cfg = {}
18package.loaded["luarocks.cfg"] = cfg
17 19
18lua_version = _VERSION:sub(5) 20cfg.lua_version = _VERSION:sub(5)
19local version_suffix = lua_version:gsub("%.", "_") 21local version_suffix = cfg.lua_version:gsub("%.", "_")
20 22
21-- Load site-local global configurations 23-- Load site-local global configurations
22local ok, site_config = pcall(require, "luarocks.site_config_"..version_suffix) 24local ok, site_config = pcall(require, "luarocks.site_config_"..version_suffix)
@@ -28,14 +30,14 @@ if not ok then
28 site_config = {} 30 site_config = {}
29end 31end
30 32
31_M.site_config = site_config 33cfg.site_config = site_config
32 34
33program_version = "2.1.2" 35cfg.program_version = "2.1.2"
34major_version = program_version:match("([^.]%.[^.])") 36cfg.major_version = cfg.program_version:match("([^.]%.[^.])")
35 37
36local persist = require("luarocks.persist") 38local persist = require("luarocks.persist")
37 39
38_M.errorcodes = setmetatable({ 40cfg.errorcodes = setmetatable({
39 OK = 0, 41 OK = 0,
40 UNSPECIFIED = 1, 42 UNSPECIFIED = 1,
41 PERMISSIONDENIED = 2, 43 PERMISSIONDENIED = 2,
@@ -58,7 +60,7 @@ if popen_ok then
58else 60else
59 io.stderr:write("Your version of Lua does not support io.popen,\n") 61 io.stderr:write("Your version of Lua does not support io.popen,\n")
60 io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") 62 io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n")
61 os.exit(_M.errorcodes.UNSPECIFIED) 63 os.exit(cfg.errorcodes.UNSPECIFIED)
62end 64end
63 65
64-- System detection: 66-- System detection:
@@ -124,27 +126,27 @@ local sys_config_ok, home_config_ok = false, false
124local extra_luarocks_module_dir 126local extra_luarocks_module_dir
125sys_config_dir = site_config.LUAROCKS_SYSCONFDIR 127sys_config_dir = site_config.LUAROCKS_SYSCONFDIR
126if detected.windows then 128if detected.windows then
127 home = os.getenv("APPDATA") or "c:" 129 cfg.home = os.getenv("APPDATA") or "c:"
128 sys_config_dir = sys_config_dir or "c:/luarocks" 130 sys_config_dir = sys_config_dir or "c:/luarocks"
129 home_config_dir = home.."/luarocks" 131 home_config_dir = cfg.home.."/luarocks"
130 home_tree = home.."/luarocks/" 132 cfg.home_tree = cfg.home.."/luarocks/"
131else 133else
132 home = os.getenv("HOME") or "" 134 cfg.home = os.getenv("HOME") or ""
133 sys_config_dir = sys_config_dir or "/etc/luarocks" 135 sys_config_dir = sys_config_dir or "/etc/luarocks"
134 home_config_dir = home.."/.luarocks" 136 home_config_dir = cfg.home.."/.luarocks"
135 home_tree = home.."/.luarocks/" 137 cfg.home_tree = cfg.home.."/.luarocks/"
136end 138end
137 139
138variables = {} 140cfg.variables = {}
139rocks_trees = {} 141cfg.rocks_trees = {}
140 142
141sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..lua_version..".lua" 143sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua"
142local err 144local err
143sys_config_ok, err = persist.load_into_table(sys_config_file, _M) 145sys_config_ok, err = persist.load_into_table(sys_config_file, cfg)
144 146
145if not sys_config_ok then 147if not sys_config_ok then
146 sys_config_file = sys_config_dir.."/config.lua" 148 sys_config_file = sys_config_dir.."/config.lua"
147 sys_config_ok, err = persist.load_into_table(sys_config_file, _M) 149 sys_config_ok, err = persist.load_into_table(sys_config_file, cfg)
148end 150end
149if err and sys_config_ok == nil then 151if err and sys_config_ok == nil then
150 io.stderr:write(err.."\n") 152 io.stderr:write(err.."\n")
@@ -154,25 +156,25 @@ if not site_config.LUAROCKS_FORCE_CONFIG then
154 local home_overrides, err 156 local home_overrides, err
155 home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") 157 home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG")
156 if home_config_file then 158 if home_config_file then
157 home_overrides, err = persist.load_into_table(home_config_file, { home = home, lua_version = lua_version }) 159 home_overrides, err = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version })
158 else 160 else
159 home_config_file = home_config_dir.."/config-"..lua_version..".lua" 161 home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua"
160 home_overrides, err = persist.load_into_table(home_config_file, { home = home, lua_version = lua_version }) 162 home_overrides, err = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version })
161 if not home_overrides then 163 if not home_overrides then
162 home_config_file = home_config_dir.."/config.lua" 164 home_config_file = home_config_dir.."/config.lua"
163 home_overrides, err = persist.load_into_table(home_config_file, { home = home, lua_version = lua_version }) 165 home_overrides, err = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version })
164 end 166 end
165 end 167 end
166 if home_overrides then 168 if home_overrides then
167 home_config_ok = true 169 home_config_ok = true
168 local util = require("luarocks.util") 170 local util = require("luarocks.util")
169 if home_overrides.rocks_trees then 171 if home_overrides.rocks_trees then
170 _M.rocks_trees = nil 172 cfg.rocks_trees = nil
171 end 173 end
172 if home_overrides.rocks_servers then 174 if home_overrides.rocks_servers then
173 _M.rocks_servers = nil 175 cfg.rocks_servers = nil
174 end 176 end
175 util.deep_merge(_M, home_overrides) 177 util.deep_merge(cfg, home_overrides)
176 else -- nil or false 178 else -- nil or false
177 home_config_ok = home_overrides 179 home_config_ok = home_overrides
178 if err and home_config_ok == nil then 180 if err and home_config_ok == nil then
@@ -181,18 +183,18 @@ if not site_config.LUAROCKS_FORCE_CONFIG then
181 end 183 end
182end 184end
183 185
184if not next(rocks_trees) then 186if not next(cfg.rocks_trees) then
185 if home_tree then 187 if cfg.home_tree then
186 table.insert(rocks_trees, { name = "user", root = home_tree } ) 188 table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } )
187 end 189 end
188 if site_config.LUAROCKS_ROCKS_TREE then 190 if site_config.LUAROCKS_ROCKS_TREE then
189 table.insert(rocks_trees, { name = "system", root = site_config.LUAROCKS_ROCKS_TREE } ) 191 table.insert(cfg.rocks_trees, { name = "system", root = site_config.LUAROCKS_ROCKS_TREE } )
190 end 192 end
191end 193end
192 194
193-- Configure defaults: 195-- Configure defaults:
194 196
195local root = rocks_trees[#rocks_trees] 197local root = cfg.rocks_trees[#cfg.rocks_trees]
196local defaults = { 198local defaults = {
197 199
198 local_by_default = false, 200 local_by_default = false,
@@ -202,8 +204,8 @@ local defaults = {
202 hooks_enabled = true, 204 hooks_enabled = true,
203 deps_mode = "one", 205 deps_mode = "one",
204 206
205 lua_modules_path = "/share/lua/"..lua_version, 207 lua_modules_path = "/share/lua/"..cfg.lua_version,
206 lib_modules_path = "/lib/lua/"..lua_version, 208 lib_modules_path = "/lib/lua/"..cfg.lua_version,
207 rocks_subdir = site_config.LUAROCKS_ROCKS_SUBDIR or "/lib/luarocks/rocks", 209 rocks_subdir = site_config.LUAROCKS_ROCKS_SUBDIR or "/lib/luarocks/rocks",
208 210
209 arch = "unknown", 211 arch = "unknown",
@@ -286,7 +288,7 @@ local defaults = {
286} 288}
287 289
288if detected.windows then 290if detected.windows then
289 local full_prefix = site_config.LUAROCKS_PREFIX.."\\"..major_version 291 local full_prefix = site_config.LUAROCKS_PREFIX.."\\"..cfg.major_version
290 extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua" 292 extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua"
291 293
292 home_config_file = home_config_file and home_config_file:gsub("\\","/") 294 home_config_file = home_config_file and home_config_file:gsub("\\","/")
@@ -297,9 +299,9 @@ if detected.windows then
297 defaults.external_lib_extension = "dll" 299 defaults.external_lib_extension = "dll"
298 defaults.obj_extension = "obj" 300 defaults.obj_extension = "obj"
299 defaults.external_deps_dirs = { "c:/external/" } 301 defaults.external_deps_dirs = { "c:/external/" }
300 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/bin" 302 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/bin"
301 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/include" 303 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/include"
302 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/lib" 304 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/lib"
303 defaults.cmake_generator = "MinGW Makefiles" 305 defaults.cmake_generator = "MinGW Makefiles"
304 defaults.makefile = "Makefile.win" 306 defaults.makefile = "Makefile.win"
305 defaults.variables.MAKE = "nmake" 307 defaults.variables.MAKE = "nmake"
@@ -308,7 +310,7 @@ if detected.windows then
308 defaults.variables.WRAPPER = full_prefix.."\\rclauncher.c" 310 defaults.variables.WRAPPER = full_prefix.."\\rclauncher.c"
309 defaults.variables.LD = "link" 311 defaults.variables.LD = "link"
310 defaults.variables.MT = "mt" 312 defaults.variables.MT = "mt"
311 defaults.variables.LUALIB = "lua"..lua_version..".lib" 313 defaults.variables.LUALIB = "lua"..cfg.lua_version..".lib"
312 defaults.variables.CFLAGS = "/MD /O2" 314 defaults.variables.CFLAGS = "/MD /O2"
313 defaults.variables.LIBFLAG = "/dll" 315 defaults.variables.LIBFLAG = "/dll"
314 316
@@ -400,7 +402,7 @@ if detected.unix then
400 defaults.export_lua_path = "export LUA_PATH='%s'" 402 defaults.export_lua_path = "export LUA_PATH='%s'"
401 defaults.export_lua_cpath = "export LUA_CPATH='%s'" 403 defaults.export_lua_cpath = "export LUA_CPATH='%s'"
402 defaults.wrapper_suffix = "" 404 defaults.wrapper_suffix = ""
403 defaults.local_cache = home.."/.cache/luarocks" 405 defaults.local_cache = cfg.home.."/.cache/luarocks"
404 if not defaults.variables.CFLAGS:match("-fPIC") then 406 if not defaults.variables.CFLAGS:match("-fPIC") then
405 defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" 407 defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC"
406 end 408 end
@@ -474,11 +476,11 @@ defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX
474defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter 476defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter
475 477
476-- Add built-in modules to rocks_provided 478-- Add built-in modules to rocks_provided
477defaults.rocks_provided["lua"] = lua_version.."-1" 479defaults.rocks_provided["lua"] = cfg.lua_version.."-1"
478 480
479if lua_version >= "5.2" then 481if cfg.lua_version >= "5.2" then
480 -- Lua 5.2+ 482 -- Lua 5.2+
481 defaults.rocks_provided["bit32"] = lua_version.."-1" 483 defaults.rocks_provided["bit32"] = cfg.lua_version.."-1"
482end 484end
483 485
484if package.loaded.jit then 486if package.loaded.jit then
@@ -493,12 +495,12 @@ end
493-- Populate some arrays with values from their 'defaults' counterparts 495-- Populate some arrays with values from their 'defaults' counterparts
494-- if they were not already set by user. 496-- if they were not already set by user.
495for _, entry in ipairs({"variables", "rocks_provided"}) do 497for _, entry in ipairs({"variables", "rocks_provided"}) do
496 if not _M[entry] then 498 if not cfg[entry] then
497 _M[entry] = {} 499 cfg[entry] = {}
498 end 500 end
499 for k,v in pairs(defaults[entry]) do 501 for k,v in pairs(defaults[entry]) do
500 if not _M[entry][k] then 502 if not cfg[entry][k] then
501 _M[entry][k] = v 503 cfg[entry][k] = v
502 end 504 end
503 end 505 end
504end 506end
@@ -513,38 +515,40 @@ local cfg_mt = {
513 return default 515 return default
514 end 516 end
515} 517}
516setmetatable(_M, cfg_mt) 518setmetatable(cfg, cfg_mt)
517 519
518function package_paths() 520function cfg.package_paths()
519 local new_path, new_cpath = { extra_luarocks_module_dir }, {} 521 local new_path, new_cpath = { extra_luarocks_module_dir }, {}
520 for _,tree in ipairs(rocks_trees) do 522 for _,tree in ipairs(cfg.rocks_trees) do
521 if type(tree) == "string" then 523 if type(tree) == "string" then
522 table.insert(new_path, 1, tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua") 524 table.insert(new_path, 1, tree..cfg.lua_modules_path.."/?.lua;"..tree..cfg.lua_modules_path.."/?/init.lua")
523 table.insert(new_cpath, 1, tree..lib_modules_path.."/?."..lib_extension) 525 table.insert(new_cpath, 1, tree..cfg.lib_modules_path.."/?."..cfg.lib_extension)
524 else 526 else
525 table.insert(new_path, 1, (tree.lua_dir or tree.root..lua_modules_path).."/?.lua;".. 527 table.insert(new_path, 1, (tree.lua_dir or tree.root..cfg.lua_modules_path).."/?.lua;"..
526 (tree.lua_dir or tree.root..lua_modules_path).."/?/init.lua") 528 (tree.lua_dir or tree.root..cfg.lua_modules_path).."/?/init.lua")
527 table.insert(new_cpath, 1, (tree.lib_dir or tree.root..lib_modules_path).."/?."..lib_extension) 529 table.insert(new_cpath, 1, (tree.lib_dir or tree.root..cfg.lib_modules_path).."/?."..cfg.lib_extension)
528 end 530 end
529 end 531 end
530 return table.concat(new_path, ";"), table.concat(new_cpath, ";") 532 return table.concat(new_path, ";"), table.concat(new_cpath, ";")
531end 533end
532 534
533function which_config() 535function cfg.which_config()
534 return sys_config_file, sys_config_ok, home_config_file, home_config_ok 536 return sys_config_file, sys_config_ok, home_config_file, home_config_ok
535end 537end
536 538
537user_agent = "LuaRocks/"..program_version.." "..arch 539cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch
538 540
539--- Check if platform was detected 541--- Check if platform was detected
540-- @param query string: The platform name to check. 542-- @param query string: The platform name to check.
541-- @return boolean: true if LuaRocks is currently running on queried platform. 543-- @return boolean: true if LuaRocks is currently running on queried platform.
542function is_platform(query) 544function cfg.is_platform(query)
543 assert(type(query) == "string") 545 assert(type(query) == "string")
544 546
545 for _, platform in ipairs(platforms) do 547 for _, platform in ipairs(cfg.platforms) do
546 if platform == query then 548 if platform == query then
547 return true 549 return true
548 end 550 end
549 end 551 end
550end 552end
553
554return cfg
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index 1c29aa77..3cde4c41 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -1,6 +1,9 @@
1 1
2--- Functions for command-line scripts. 2--- Functions for command-line scripts.
3module("luarocks.command_line", package.seeall) 3--module("luarocks.command_line", package.seeall)
4local command_line = {}
5
6local unpack = unpack or table.unpack
4 7
5local util = require("luarocks.util") 8local util = require("luarocks.util")
6local cfg = require("luarocks.cfg") 9local cfg = require("luarocks.cfg")
@@ -43,7 +46,7 @@ end
43-- Uses the global table "commands", which contains 46-- Uses the global table "commands", which contains
44-- the loaded modules representing commands. 47-- the loaded modules representing commands.
45-- @param ... string: Arguments given on the command-line. 48-- @param ... string: Arguments given on the command-line.
46function run_command(...) 49function command_line.run_command(...)
47 local args = {...} 50 local args = {...}
48 local cmdline_vars = {} 51 local cmdline_vars = {}
49 for i = #args, 1, -1 do 52 for i = #args, 1, -1 do
@@ -206,3 +209,5 @@ function run_command(...)
206 end 209 end
207 util.run_scheduled_functions() 210 util.run_scheduled_functions()
208end 211end
212
213return command_line
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 567a576b..3f75f9be 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -11,7 +11,9 @@
11-- comparison criteria is the source code of this module, but the 11-- comparison criteria is the source code of this module, but the
12-- test/test_deps.lua file included with LuaRocks provides some 12-- test/test_deps.lua file included with LuaRocks provides some
13-- insights on what these criteria are. 13-- insights on what these criteria are.
14module("luarocks.deps", package.seeall) 14--module("luarocks.deps", package.seeall)
15local deps = {}
16package.loaded["luarocks.deps"] = deps
15 17
16local cfg = require("luarocks.cfg") 18local cfg = require("luarocks.cfg")
17local manif_core = require("luarocks.manif_core") 19local manif_core = require("luarocks.manif_core")
@@ -101,7 +103,7 @@ setmetatable(version_cache, {
101-- @param vstring string: A version number in string format. 103-- @param vstring string: A version number in string format.
102-- @return table or nil: A version table or nil 104-- @return table or nil: A version table or nil
103-- if the input string contains invalid characters. 105-- if the input string contains invalid characters.
104function parse_version(vstring) 106function deps.parse_version(vstring)
105 if not vstring then return nil end 107 if not vstring then return nil end
106 assert(type(vstring) == "string") 108 assert(type(vstring) == "string")
107 109
@@ -153,8 +155,8 @@ end
153-- @param a string: one version. 155-- @param a string: one version.
154-- @param b string: another version. 156-- @param b string: another version.
155-- @return boolean: True if a > b. 157-- @return boolean: True if a > b.
156function compare_versions(a, b) 158function deps.compare_versions(a, b)
157 return parse_version(a) > parse_version(b) 159 return deps.parse_version(a) > deps.parse_version(b)
158end 160end
159 161
160--- Consumes a constraint from a string, converting it to table format. 162--- Consumes a constraint from a string, converting it to table format.
@@ -170,7 +172,7 @@ local function parse_constraint(input)
170 172
171 local no_upgrade, op, version, rest = input:match("^(@?)([<>=~!]*)%s*([%w%.%_%-]+)[%s,]*(.*)") 173 local no_upgrade, op, version, rest = input:match("^(@?)([<>=~!]*)%s*([%w%.%_%-]+)[%s,]*(.*)")
172 local _op = operators[op] 174 local _op = operators[op]
173 version = parse_version(version) 175 version = deps.parse_version(version)
174 if not _op then 176 if not _op then
175 return nil, "Encountered bad constraint operator: '"..tostring(op).."' in '"..input.."'" 177 return nil, "Encountered bad constraint operator: '"..tostring(op).."' in '"..input.."'"
176 end 178 end
@@ -188,7 +190,7 @@ end
188-- @param input string: A list of constraints in string format. 190-- @param input string: A list of constraints in string format.
189-- @return table or nil: A table representing the same constraints, 191-- @return table or nil: A table representing the same constraints,
190-- or nil if the input string is invalid. 192-- or nil if the input string is invalid.
191function parse_constraints(input) 193function deps.parse_constraints(input)
192 assert(type(input) == "string") 194 assert(type(input) == "string")
193 195
194 local constraints, constraint, oinput = {}, nil, input 196 local constraints, constraint, oinput = {}, nil, input
@@ -213,12 +215,12 @@ end
213-- as entered in rockspec files. 215-- as entered in rockspec files.
214-- @return table or nil: A table representing the same dependency relation, 216-- @return table or nil: A table representing the same dependency relation,
215-- or nil if the input string is invalid. 217-- or nil if the input string is invalid.
216function parse_dep(dep) 218function deps.parse_dep(dep)
217 assert(type(dep) == "string") 219 assert(type(dep) == "string")
218 220
219 local name, rest = dep:match("^%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*(.*)") 221 local name, rest = dep:match("^%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*(.*)")
220 if not name then return nil, "failed to extract dependency name from '"..tostring(dep).."'" end 222 if not name then return nil, "failed to extract dependency name from '"..tostring(dep).."'" end
221 local constraints, err = parse_constraints(rest) 223 local constraints, err = deps.parse_constraints(rest)
222 if not constraints then return nil, err end 224 if not constraints then return nil, err end
223 return { name = name, constraints = constraints } 225 return { name = name, constraints = constraints }
224end 226end
@@ -228,7 +230,7 @@ end
228-- @param internal boolean or nil: Whether to display versions in their 230-- @param internal boolean or nil: Whether to display versions in their
229-- internal representation format or how they were specified. 231-- internal representation format or how they were specified.
230-- @return string: The dependency information pretty-printed as a string. 232-- @return string: The dependency information pretty-printed as a string.
231function show_version(v, internal) 233function deps.show_version(v, internal)
232 assert(type(v) == "table") 234 assert(type(v) == "table")
233 assert(type(internal) == "boolean" or not internal) 235 assert(type(internal) == "boolean" or not internal)
234 236
@@ -242,13 +244,13 @@ end
242-- @param internal boolean or nil: Whether to display versions in their 244-- @param internal boolean or nil: Whether to display versions in their
243-- internal representation format or how they were specified. 245-- internal representation format or how they were specified.
244-- @return string: The dependency information pretty-printed as a string. 246-- @return string: The dependency information pretty-printed as a string.
245function show_dep(dep, internal) 247function deps.show_dep(dep, internal)
246 assert(type(dep) == "table") 248 assert(type(dep) == "table")
247 assert(type(internal) == "boolean" or not internal) 249 assert(type(internal) == "boolean" or not internal)
248 250
249 local pretty = {} 251 local pretty = {}
250 for _, c in ipairs(dep.constraints) do 252 for _, c in ipairs(dep.constraints) do
251 table.insert(pretty, c.op .. " " .. show_version(c.version, internal)) 253 table.insert(pretty, c.op .. " " .. deps.show_version(c.version, internal))
252 end 254 end
253 return dep.name.." "..table.concat(pretty, ", ") 255 return dep.name.." "..table.concat(pretty, ", ")
254end 256end
@@ -269,8 +271,8 @@ local function partial_match(version, requested)
269 assert(type(version) == "string" or type(version) == "table") 271 assert(type(version) == "string" or type(version) == "table")
270 assert(type(requested) == "string" or type(version) == "table") 272 assert(type(requested) == "string" or type(version) == "table")
271 273
272 if type(version) ~= "table" then version = parse_version(version) end 274 if type(version) ~= "table" then version = deps.parse_version(version) end
273 if type(requested) ~= "table" then requested = parse_version(requested) end 275 if type(requested) ~= "table" then requested = deps.parse_version(requested) end
274 if not version or not requested then return false end 276 if not version or not requested then return false end
275 277
276 for i, ri in ipairs(requested) do 278 for i, ri in ipairs(requested) do
@@ -288,14 +290,14 @@ end
288-- @param constraints table: An array of constraints in table format. 290-- @param constraints table: An array of constraints in table format.
289-- @return boolean: True if version satisfies all constraints, 291-- @return boolean: True if version satisfies all constraints,
290-- false otherwise. 292-- false otherwise.
291function match_constraints(version, constraints) 293function deps.match_constraints(version, constraints)
292 assert(type(version) == "table") 294 assert(type(version) == "table")
293 assert(type(constraints) == "table") 295 assert(type(constraints) == "table")
294 local ok = true 296 local ok = true
295 setmetatable(version, version_mt) 297 setmetatable(version, version_mt)
296 for _, constr in pairs(constraints) do 298 for _, constr in pairs(constraints) do
297 if type(constr.version) == "string" then 299 if type(constr.version) == "string" then
298 constr.version = parse_version(constr.version) 300 constr.version = deps.parse_version(constr.version)
299 end 301 end
300 local constr_version, constr_op = constr.version, constr.op 302 local constr_version, constr_op = constr.version, constr.op
301 setmetatable(constr_version, version_mt) 303 setmetatable(constr_version, version_mt)
@@ -344,8 +346,8 @@ local function match_dep(dep, blacklist, deps_mode)
344 end 346 end
345 local candidates = {} 347 local candidates = {}
346 for _, vstring in ipairs(versions) do 348 for _, vstring in ipairs(versions) do
347 local version = parse_version(vstring) 349 local version = deps.parse_version(vstring)
348 if match_constraints(version, dep.constraints) then 350 if deps.match_constraints(version, dep.constraints) then
349 table.insert(candidates, version) 351 table.insert(candidates, version)
350 end 352 end
351 end 353 end
@@ -371,7 +373,7 @@ end
371-- parsed as tables; and a table of "no-upgrade" missing dependencies 373-- parsed as tables; and a table of "no-upgrade" missing dependencies
372-- (to be used in plugin modules so that a plugin does not force upgrade of 374-- (to be used in plugin modules so that a plugin does not force upgrade of
373-- its parent application). 375-- its parent application).
374function match_deps(rockspec, blacklist, deps_mode) 376function deps.match_deps(rockspec, blacklist, deps_mode)
375 assert(type(rockspec) == "table") 377 assert(type(rockspec) == "table")
376 assert(type(blacklist) == "table" or not blacklist) 378 assert(type(blacklist) == "table" or not blacklist)
377 local matched, missing, no_upgrade = {}, {}, {} 379 local matched, missing, no_upgrade = {}, {}, {}
@@ -411,24 +413,24 @@ end
411-- @return boolean or (nil, string, [string]): True if no errors occurred, or 413-- @return boolean or (nil, string, [string]): True if no errors occurred, or
412-- nil and an error message if any test failed, followed by an optional 414-- nil and an error message if any test failed, followed by an optional
413-- error code. 415-- error code.
414function fulfill_dependencies(rockspec, deps_mode) 416function deps.fulfill_dependencies(rockspec, deps_mode)
415 417
416 local search = require("luarocks.search") 418 local search = require("luarocks.search")
417 local install = require("luarocks.install") 419 local install = require("luarocks.install")
418 420
419 if rockspec.supported_platforms then 421 if rockspec.supported_platforms then
420 if not platforms_set then 422 if not deps.platforms_set then
421 platforms_set = values_set(cfg.platforms) 423 deps.platforms_set = values_set(cfg.platforms)
422 end 424 end
423 local supported = nil 425 local supported = nil
424 for _, plat in pairs(rockspec.supported_platforms) do 426 for _, plat in pairs(rockspec.supported_platforms) do
425 local neg, plat = plat:match("^(!?)(.*)") 427 local neg, plat = plat:match("^(!?)(.*)")
426 if neg == "!" then 428 if neg == "!" then
427 if platforms_set[plat] then 429 if deps.platforms_set[plat] then
428 return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms." 430 return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms."
429 end 431 end
430 else 432 else
431 if platforms_set[plat] then 433 if deps.platforms_set[plat] then
432 supported = true 434 supported = true
433 else 435 else
434 if supported == nil then 436 if supported == nil then
@@ -443,22 +445,22 @@ function fulfill_dependencies(rockspec, deps_mode)
443 end 445 end
444 end 446 end
445 447
446 local _, missing, no_upgrade = match_deps(rockspec, nil, deps_mode) 448 local _, missing, no_upgrade = deps.match_deps(rockspec, nil, deps_mode)
447 449
448 if next(no_upgrade) then 450 if next(no_upgrade) then
449 util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") 451 util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":")
450 for _, dep in pairs(no_upgrade) do 452 for _, dep in pairs(no_upgrade) do
451 util.printerr(show_dep(dep)) 453 util.printerr(deps.show_dep(dep))
452 end 454 end
453 if next(missing) then 455 if next(missing) then
454 for _, dep in pairs(missing) do 456 for _, dep in pairs(missing) do
455 util.printerr(show_dep(dep)) 457 util.printerr(deps.show_dep(dep))
456 end 458 end
457 end 459 end
458 util.printerr() 460 util.printerr()
459 for _, dep in pairs(no_upgrade) do 461 for _, dep in pairs(no_upgrade) do
460 util.printerr("This version of "..rockspec.name.." is designed for use with") 462 util.printerr("This version of "..rockspec.name.." is designed for use with")
461 util.printerr(show_dep(dep)..", but is configured to avoid upgrading it") 463 util.printerr(deps.show_dep(dep)..", but is configured to avoid upgrading it")
462 util.printerr("automatically. Please upgrade "..dep.name.." with") 464 util.printerr("automatically. Please upgrade "..dep.name.." with")
463 util.printerr(" luarocks install "..dep.name) 465 util.printerr(" luarocks install "..dep.name)
464 util.printerr("or choose an older version of "..rockspec.name.." with") 466 util.printerr("or choose an older version of "..rockspec.name.." with")
@@ -471,7 +473,7 @@ function fulfill_dependencies(rockspec, deps_mode)
471 util.printerr() 473 util.printerr()
472 util.printerr("Missing dependencies for "..rockspec.name..":") 474 util.printerr("Missing dependencies for "..rockspec.name..":")
473 for _, dep in pairs(missing) do 475 for _, dep in pairs(missing) do
474 util.printerr(show_dep(dep)) 476 util.printerr(deps.show_dep(dep))
475 end 477 end
476 util.printerr() 478 util.printerr()
477 479
@@ -480,7 +482,7 @@ function fulfill_dependencies(rockspec, deps_mode)
480 if not match_dep(dep, nil, deps_mode) then 482 if not match_dep(dep, nil, deps_mode) then
481 local rock = search.find_suitable_rock(dep) 483 local rock = search.find_suitable_rock(dep)
482 if not rock then 484 if not rock then
483 return nil, "Could not satisfy dependency: "..show_dep(dep) 485 return nil, "Could not satisfy dependency: "..deps.show_dep(dep)
484 end 486 end
485 local ok, err, errcode = install.run(rock) 487 local ok, err, errcode = install.run(rock)
486 if not ok then 488 if not ok then
@@ -530,7 +532,7 @@ end
530-- if "install" is given, do not scan for headers. 532-- if "install" is given, do not scan for headers.
531-- @return boolean or (nil, string): True if no errors occurred, or 533-- @return boolean or (nil, string): True if no errors occurred, or
532-- nil and an error message if any test failed. 534-- nil and an error message if any test failed.
533function check_external_deps(rockspec, mode) 535function deps.check_external_deps(rockspec, mode)
534 assert(type(rockspec) == "table") 536 assert(type(rockspec) == "table")
535 537
536 local fs = require("luarocks.fs") 538 local fs = require("luarocks.fs")
@@ -668,7 +670,7 @@ end
668-- @param name string: Package name. 670-- @param name string: Package name.
669-- @param version string: Package version. 671-- @param version string: Package version.
670-- @return (table, table): The results and a table of missing dependencies. 672-- @return (table, table): The results and a table of missing dependencies.
671function scan_deps(results, missing, manifest, name, version, deps_mode) 673function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
672 assert(type(results) == "table") 674 assert(type(results) == "table")
673 assert(type(missing) == "table") 675 assert(type(missing) == "table")
674 assert(type(manifest) == "table") 676 assert(type(manifest) == "table")
@@ -697,14 +699,14 @@ function scan_deps(results, missing, manifest, name, version, deps_mode)
697 else 699 else
698 rockspec = { dependencies = deplist } 700 rockspec = { dependencies = deplist }
699 end 701 end
700 local matched, failures = match_deps(rockspec, nil, deps_mode) 702 local matched, failures = deps.match_deps(rockspec, nil, deps_mode)
701 results[name] = results 703 results[name] = results
702 for _, match in pairs(matched) do 704 for _, match in pairs(matched) do
703 results, missing = scan_deps(results, missing, manifest, match.name, match.version, deps_mode) 705 results, missing = deps.scan_deps(results, missing, manifest, match.name, match.version, deps_mode)
704 end 706 end
705 if next(failures) then 707 if next(failures) then
706 for _, failure in pairs(failures) do 708 for _, failure in pairs(failures) do
707 missing[show_dep(failure)] = "failed" 709 missing[deps.show_dep(failure)] = "failed"
708 end 710 end
709 end 711 end
710 results[name] = version 712 results[name] = version
@@ -718,11 +720,11 @@ local valid_deps_modes = {
718 none = true, 720 none = true,
719} 721}
720 722
721function check_deps_mode_flag(flag) 723function deps.check_deps_mode_flag(flag)
722 return valid_deps_modes[flag] 724 return valid_deps_modes[flag]
723end 725end
724 726
725function get_deps_mode(flags) 727function deps.get_deps_mode(flags)
726 if flags["deps-mode"] then 728 if flags["deps-mode"] then
727 return flags["deps-mode"] 729 return flags["deps-mode"]
728 else 730 else
@@ -730,6 +732,8 @@ function get_deps_mode(flags)
730 end 732 end
731end 733end
732 734
733function deps_mode_to_flag(deps_mode) 735function deps.deps_mode_to_flag(deps_mode)
734 return "--deps-mode="..deps_mode 736 return "--deps-mode="..deps_mode
735end 737end
738
739return deps
diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua
index 1f3b5c3d..2ef9881e 100644
--- a/src/luarocks/dir.lua
+++ b/src/luarocks/dir.lua
@@ -1,14 +1,16 @@
1 1
2--- Generic utilities for handling pathnames. 2--- Generic utilities for handling pathnames.
3module("luarocks.dir", package.seeall) 3--module("luarocks.dir", package.seeall)
4local dir = {}
5package.loaded["luarocks.dir"] = dir
4 6
5separator = "/" 7dir.separator = "/"
6 8
7--- Strip the path off a path+filename. 9--- Strip the path off a path+filename.
8-- @param pathname string: A path+name, such as "/a/b/c" 10-- @param pathname string: A path+name, such as "/a/b/c"
9-- or "\a\b\c". 11-- or "\a\b\c".
10-- @return string: The filename without its path, such as "c". 12-- @return string: The filename without its path, such as "c".
11function base_name(pathname) 13function dir.base_name(pathname)
12 assert(type(pathname) == "string") 14 assert(type(pathname) == "string")
13 15
14 local base = pathname:gsub("[/\\]*$", ""):match(".*[/\\]([^/\\]*)") 16 local base = pathname:gsub("[/\\]*$", ""):match(".*[/\\]([^/\\]*)")
@@ -20,7 +22,7 @@ end
20-- @return string: The filename without its path, such as "/a/b". 22-- @return string: The filename without its path, such as "/a/b".
21-- For entries such as "/a/b/", "/a" is returned. If there are 23-- For entries such as "/a/b/", "/a" is returned. If there are
22-- no directory separators in input, "" is returned. 24-- no directory separators in input, "" is returned.
23function dir_name(pathname) 25function dir.dir_name(pathname)
24 assert(type(pathname) == "string") 26 assert(type(pathname) == "string")
25 return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or "" 27 return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or ""
26end 28end
@@ -34,7 +36,7 @@ end
34-- @param ... strings representing directories 36-- @param ... strings representing directories
35-- @return string: a string with a platform-specific representation 37-- @return string: a string with a platform-specific representation
36-- of the path. 38-- of the path.
37function path(...) 39function dir.path(...)
38 local t = {...} 40 local t = {...}
39 while t[1] == "" do 41 while t[1] == "" do
40 table.remove(t, 1) 42 table.remove(t, 1)
@@ -47,7 +49,7 @@ end
47-- For local pathnames, "file" is returned as the protocol. 49-- For local pathnames, "file" is returned as the protocol.
48-- @param url string: an URL or a local pathname. 50-- @param url string: an URL or a local pathname.
49-- @return string, string: the protocol, and the pathname without the protocol. 51-- @return string, string: the protocol, and the pathname without the protocol.
50function split_url(url) 52function dir.split_url(url)
51 assert(type(url) == "string") 53 assert(type(url) == "string")
52 54
53 local protocol, pathname = url:match("^([^:]*)://(.*)") 55 local protocol, pathname = url:match("^([^:]*)://(.*)")
@@ -63,9 +65,11 @@ end
63-- forward slashes are used, removing trailing and double slashes 65-- forward slashes are used, removing trailing and double slashes
64-- @param url string: an URL or a local pathname. 66-- @param url string: an URL or a local pathname.
65-- @return string: Normalized result. 67-- @return string: Normalized result.
66function normalize(name) 68function dir.normalize(name)
67 local protocol, pathname = split_url(name) 69 local protocol, pathname = dir.split_url(name)
68 pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/") 70 pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/")
69 if protocol ~= "file" then pathname = protocol .."://"..pathname end 71 if protocol ~= "file" then pathname = protocol .."://"..pathname end
70 return pathname 72 return pathname
71end 73end
74
75return dir
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua
index 324bf028..6dee1069 100644
--- a/src/luarocks/doc.lua
+++ b/src/luarocks/doc.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "doc" command. 2--- Module implementing the LuaRocks "doc" command.
3-- Shows documentation for an installed rock. 3-- Shows documentation for an installed rock.
4module("luarocks.doc", package.seeall) 4--module("luarocks.doc", package.seeall)
5local doc = {}
6package.loaded["luarocks.doc"] = doc
5 7
6local util = require("luarocks.util") 8local util = require("luarocks.util")
7local show = require("luarocks.show") 9local show = require("luarocks.show")
@@ -11,9 +13,9 @@ local fetch = require("luarocks.fetch")
11local fs = require("luarocks.fs") 13local fs = require("luarocks.fs")
12local download = require("luarocks.download") 14local download = require("luarocks.download")
13 15
14help_summary = "Shows documentation for an installed rock." 16doc.help_summary = "Shows documentation for an installed rock."
15 17
16help = [[ 18doc.help = [[
17<argument> is an existing package name. 19<argument> is an existing package name.
18Without any flags, tries to load the documentation 20Without any flags, tries to load the documentation
19using a series of heuristics. 21using a series of heuristics.
@@ -56,7 +58,7 @@ end
56-- @param name or nil: an existing package name. 58-- @param name or nil: an existing package name.
57-- @param version string or nil: a version may also be passed. 59-- @param version string or nil: a version may also be passed.
58-- @return boolean: True if succeeded, nil on errors. 60-- @return boolean: True if succeeded, nil on errors.
59function run(...) 61function doc.run(...)
60 local flags, name, version = util.parse_flags(...) 62 local flags, name, version = util.parse_flags(...)
61 if not name then 63 if not name then
62 return nil, "Argument missing. "..util.see_help("doc") 64 return nil, "Argument missing. "..util.see_help("doc")
@@ -150,3 +152,5 @@ function run(...)
150 return true 152 return true
151end 153end
152 154
155
156return doc
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index d0f672f2..74ed40e9 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the luarocks "download" command. 2--- Module implementing the luarocks "download" command.
3-- Download a rock from the repository. 3-- Download a rock from the repository.
4module("luarocks.download", package.seeall) 4--module("luarocks.download", package.seeall)
5local download = {}
6package.loaded["luarocks.download"] = download
5 7
6local util = require("luarocks.util") 8local util = require("luarocks.util")
7local path = require("luarocks.path") 9local path = require("luarocks.path")
@@ -10,10 +12,10 @@ local search = require("luarocks.search")
10local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
11local dir = require("luarocks.dir") 13local dir = require("luarocks.dir")
12 14
13help_summary = "Download a specific rock file from a rocks server." 15download.help_summary = "Download a specific rock file from a rocks server."
14help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" 16download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]"
15 17
16help = [[ 18download.help = [[
17--all Download all files if there are multiple matches. 19--all Download all files if there are multiple matches.
18--source Download .src.rock if available. 20--source Download .src.rock if available.
19--rockspec Download .rockspec if available. 21--rockspec Download .rockspec if available.
@@ -34,7 +36,7 @@ local function get_file(filename)
34 end 36 end
35end 37end
36 38
37function download(arch, name, version, all) 39function download.download(arch, name, version, all)
38 local results, err 40 local results, err
39 local query = search.make_query(name, version) 41 local query = search.make_query(name, version)
40 if arch then query.arch = arch end 42 if arch then query.arch = arch end
@@ -79,7 +81,7 @@ end
79-- version may also be passed. 81-- version may also be passed.
80-- @return boolean or (nil, string): true if successful or nil followed 82-- @return boolean or (nil, string): true if successful or nil followed
81-- by an error message. 83-- by an error message.
82function run(...) 84function download.run(...)
83 local flags, name, version = util.parse_flags(...) 85 local flags, name, version = util.parse_flags(...)
84 86
85 assert(type(version) == "string" or not version) 87 assert(type(version) == "string" or not version)
@@ -98,6 +100,8 @@ function run(...)
98 arch = flags["arch"] 100 arch = flags["arch"]
99 end 101 end
100 102
101 local dl, err = download(arch, name, version, flags["all"]) 103 local dl, err = download.download(arch, name, version, flags["all"])
102 return dl and true, err 104 return dl and true, err
103end 105end
106
107return download
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua
index 3448473f..1d84b480 100644
--- a/src/luarocks/fetch.lua
+++ b/src/luarocks/fetch.lua
@@ -1,6 +1,8 @@
1 1
2--- Functions related to fetching and loading local and remote files. 2--- Functions related to fetching and loading local and remote files.
3module("luarocks.fetch", package.seeall) 3--module("luarocks.fetch", package.seeall)
4local fetch = {}
5package.loaded["luarocks.fetch"] = fetch
4 6
5local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
@@ -11,7 +13,7 @@ local persist = require("luarocks.persist")
11local util = require("luarocks.util") 13local util = require("luarocks.util")
12local cfg = require("luarocks.cfg") 14local cfg = require("luarocks.cfg")
13 15
14function is_basic_protocol(protocol, remote) 16function fetch.is_basic_protocol(protocol, remote)
15 return protocol == "http" or protocol == "https" or protocol == "ftp" or (not remote and protocol == "file") 17 return protocol == "http" or protocol == "https" or protocol == "ftp" or (not remote and protocol == "file")
16end 18end
17 19
@@ -27,14 +29,14 @@ end
27-- @return string or (nil, string, [string]): the absolute local pathname for the 29-- @return string or (nil, string, [string]): the absolute local pathname for the
28-- fetched file, or nil and a message in case of errors, followed by 30-- fetched file, or nil and a message in case of errors, followed by
29-- an optional error code. 31-- an optional error code.
30function fetch_url(url, filename, cache) 32function fetch.fetch_url(url, filename, cache)
31 assert(type(url) == "string") 33 assert(type(url) == "string")
32 assert(type(filename) == "string" or not filename) 34 assert(type(filename) == "string" or not filename)
33 35
34 local protocol, pathname = dir.split_url(url) 36 local protocol, pathname = dir.split_url(url)
35 if protocol == "file" then 37 if protocol == "file" then
36 return fs.absolute_name(pathname) 38 return fs.absolute_name(pathname)
37 elseif is_basic_protocol(protocol, true) then 39 elseif fetch.is_basic_protocol(protocol, true) then
38 local ok, filename = fs.download(url, filename, cache) 40 local ok, filename = fs.download(url, filename, cache)
39 if not ok then 41 if not ok then
40 return nil, "Failed downloading "..url..(filename and " - "..filename or ""), "network" 42 return nil, "Failed downloading "..url..(filename and " - "..filename or ""), "network"
@@ -56,7 +58,7 @@ end
56-- @return (string, string) or (nil, string, [string]): absolute local pathname of 58-- @return (string, string) or (nil, string, [string]): absolute local pathname of
57-- the fetched file and temporary directory name; or nil and an error message 59-- the fetched file and temporary directory name; or nil and an error message
58-- followed by an optional error code 60-- followed by an optional error code
59function fetch_url_at_temp_dir(url, tmpname, filename) 61function fetch.fetch_url_at_temp_dir(url, tmpname, filename)
60 assert(type(url) == "string") 62 assert(type(url) == "string")
61 assert(type(tmpname) == "string") 63 assert(type(tmpname) == "string")
62 assert(type(filename) == "string" or not filename) 64 assert(type(filename) == "string" or not filename)
@@ -77,7 +79,7 @@ function fetch_url_at_temp_dir(url, tmpname, filename)
77 util.schedule_function(fs.delete, temp_dir) 79 util.schedule_function(fs.delete, temp_dir)
78 local ok, err = fs.change_dir(temp_dir) 80 local ok, err = fs.change_dir(temp_dir)
79 if not ok then return nil, err end 81 if not ok then return nil, err end
80 local file, err, errcode = fetch_url(url, filename) 82 local file, err, errcode = fetch.fetch_url(url, filename)
81 fs.pop_dir() 83 fs.pop_dir()
82 if not file then 84 if not file then
83 return nil, "Error fetching file: "..err, errcode 85 return nil, "Error fetching file: "..err, errcode
@@ -98,11 +100,11 @@ end
98-- be nil if not found), or nil followed by an error message. 100-- be nil if not found), or nil followed by an error message.
99-- The inferred dir is returned first to avoid confusion with errors, 101-- The inferred dir is returned first to avoid confusion with errors,
100-- because it is never nil. 102-- because it is never nil.
101function find_base_dir(file, temp_dir, src_url, src_dir) 103function fetch.find_base_dir(file, temp_dir, src_url, src_dir)
102 local ok, err = fs.change_dir(temp_dir) 104 local ok, err = fs.change_dir(temp_dir)
103 if not ok then return nil, err end 105 if not ok then return nil, err end
104 fs.unpack_archive(file) 106 fs.unpack_archive(file)
105 local inferred_dir = src_dir or url_to_base_dir(src_url) 107 local inferred_dir = src_dir or fetch.url_to_base_dir(src_url)
106 local found_dir = nil 108 local found_dir = nil
107 if fs.exists(inferred_dir) then 109 if fs.exists(inferred_dir) then
108 found_dir = inferred_dir 110 found_dir = inferred_dir
@@ -126,13 +128,13 @@ end
126-- a permanent destination. 128-- a permanent destination.
127-- @return string or (nil, string, [string]): the directory containing the contents 129-- @return string or (nil, string, [string]): the directory containing the contents
128-- of the unpacked rock. 130-- of the unpacked rock.
129function fetch_and_unpack_rock(rock_file, dest) 131function fetch.fetch_and_unpack_rock(rock_file, dest)
130 assert(type(rock_file) == "string") 132 assert(type(rock_file) == "string")
131 assert(type(dest) == "string" or not dest) 133 assert(type(dest) == "string" or not dest)
132 134
133 local name = dir.base_name(rock_file):match("(.*)%.[^.]*%.rock") 135 local name = dir.base_name(rock_file):match("(.*)%.[^.]*%.rock")
134 136
135 local rock_file, err, errcode = fetch_url_at_temp_dir(rock_file,"luarocks-rock-"..name) 137 local rock_file, err, errcode = fetch.fetch_url_at_temp_dir(rock_file,"luarocks-rock-"..name)
136 if not rock_file then 138 if not rock_file then
137 return nil, "Could not fetch rock file: " .. err, errcode 139 return nil, "Could not fetch rock file: " .. err, errcode
138 end 140 end
@@ -161,7 +163,7 @@ function fetch_and_unpack_rock(rock_file, dest)
161 return unpack_dir 163 return unpack_dir
162end 164end
163 165
164function url_to_base_dir(url) 166function fetch.url_to_base_dir(url)
165 local base = dir.base_name(url) 167 local base = dir.base_name(url)
166 return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") 168 return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "")
167end 169end
@@ -173,7 +175,7 @@ end
173-- rockspec. 175-- rockspec.
174-- @return table or (nil, string): A table representing the rockspec 176-- @return table or (nil, string): A table representing the rockspec
175-- or nil followed by an error message. 177-- or nil followed by an error message.
176function load_local_rockspec(filename, quick) 178function fetch.load_local_rockspec(filename, quick)
177 assert(type(filename) == "string") 179 assert(type(filename) == "string")
178 filename = fs.absolute_name(filename) 180 filename = fs.absolute_name(filename)
179 local rockspec, err = persist.load_into_table(filename) 181 local rockspec, err = persist.load_into_table(filename)
@@ -216,7 +218,7 @@ function load_local_rockspec(filename, quick)
216 end 218 end
217 219
218 local protocol, pathname = dir.split_url(rockspec.source.url) 220 local protocol, pathname = dir.split_url(rockspec.source.url)
219 if is_basic_protocol(protocol) then 221 if fetch.is_basic_protocol(protocol) then
220 rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) 222 rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url)
221 end 223 end
222 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname 224 rockspec.source.protocol, rockspec.source.pathname = protocol, pathname
@@ -232,7 +234,7 @@ function load_local_rockspec(filename, quick)
232 234
233 rockspec.local_filename = filename 235 rockspec.local_filename = filename
234 local filebase = rockspec.source.file or rockspec.source.url 236 local filebase = rockspec.source.file or rockspec.source.url
235 local base = url_to_base_dir(filebase) 237 local base = fetch.url_to_base_dir(filebase)
236 rockspec.source.dir = rockspec.source.dir 238 rockspec.source.dir = rockspec.source.dir
237 or rockspec.source.module 239 or rockspec.source.module
238 or ((filebase:match("%.lua$") or filebase:match("%.c$")) and ".") 240 or ((filebase:match("%.lua$") or filebase:match("%.c$")) and ".")
@@ -264,7 +266,7 @@ end
264-- a temporary dir is created. 266-- a temporary dir is created.
265-- @return table or (nil, string, [string]): A table representing the rockspec 267-- @return table or (nil, string, [string]): A table representing the rockspec
266-- or nil followed by an error message and optional error code. 268-- or nil followed by an error message and optional error code.
267function load_rockspec(filename, location) 269function fetch.load_rockspec(filename, location)
268 assert(type(filename) == "string") 270 assert(type(filename) == "string")
269 271
270 local name 272 local name
@@ -282,16 +284,16 @@ function load_rockspec(filename, location)
282 if location then 284 if location then
283 local ok, err = fs.change_dir(location) 285 local ok, err = fs.change_dir(location)
284 if not ok then return nil, err end 286 if not ok then return nil, err end
285 filename, err = fetch_url(filename) 287 filename, err = fetch.fetch_url(filename)
286 fs.pop_dir() 288 fs.pop_dir()
287 else 289 else
288 filename, err, errcode = fetch_url_at_temp_dir(filename,"luarocks-rockspec-"..name) 290 filename, err, errcode = fetch.fetch_url_at_temp_dir(filename,"luarocks-rockspec-"..name)
289 end 291 end
290 if not filename then 292 if not filename then
291 return nil, err, errcode 293 return nil, err, errcode
292 end 294 end
293 295
294 return load_local_rockspec(filename) 296 return fetch.load_local_rockspec(filename)
295end 297end
296 298
297--- Download sources for building a rock using the basic URL downloader. 299--- Download sources for building a rock using the basic URL downloader.
@@ -303,7 +305,7 @@ end
303-- @return (string, string) or (nil, string, [string]): The absolute pathname of 305-- @return (string, string) or (nil, string, [string]): The absolute pathname of
304-- the fetched source tarball and the temporary directory created to 306-- the fetched source tarball and the temporary directory created to
305-- store it; or nil and an error message and optional error code. 307-- store it; or nil and an error message and optional error code.
306function get_sources(rockspec, extract, dest_dir) 308function fetch.get_sources(rockspec, extract, dest_dir)
307 assert(type(rockspec) == "table") 309 assert(type(rockspec) == "table")
308 assert(type(extract) == "boolean") 310 assert(type(extract) == "boolean")
309 assert(type(dest_dir) == "string" or not dest_dir) 311 assert(type(dest_dir) == "string" or not dest_dir)
@@ -315,11 +317,11 @@ function get_sources(rockspec, extract, dest_dir)
315 if dest_dir then 317 if dest_dir then
316 local ok, err = fs.change_dir(dest_dir) 318 local ok, err = fs.change_dir(dest_dir)
317 if not ok then return nil, err, "dest_dir" end 319 if not ok then return nil, err, "dest_dir" end
318 source_file, err, errcode = fetch_url(url, filename) 320 source_file, err, errcode = fetch.fetch_url(url, filename)
319 fs.pop_dir() 321 fs.pop_dir()
320 store_dir = dest_dir 322 store_dir = dest_dir
321 else 323 else
322 source_file, store_dir, errcode = fetch_url_at_temp_dir(url, "luarocks-source-"..name, filename) 324 source_file, store_dir, errcode = fetch.fetch_url_at_temp_dir(url, "luarocks-source-"..name, filename)
323 end 325 end
324 if not source_file then 326 if not source_file then
325 return nil, err or store_dir, errcode 327 return nil, err or store_dir, errcode
@@ -350,14 +352,14 @@ end
350-- @return (string, string) or (nil, string): The absolute pathname of 352-- @return (string, string) or (nil, string): The absolute pathname of
351-- the fetched source tarball and the temporary directory created to 353-- the fetched source tarball and the temporary directory created to
352-- store it; or nil and an error message. 354-- store it; or nil and an error message.
353function fetch_sources(rockspec, extract, dest_dir) 355function fetch.fetch_sources(rockspec, extract, dest_dir)
354 assert(type(rockspec) == "table") 356 assert(type(rockspec) == "table")
355 assert(type(extract) == "boolean") 357 assert(type(extract) == "boolean")
356 assert(type(dest_dir) == "string" or not dest_dir) 358 assert(type(dest_dir) == "string" or not dest_dir)
357 359
358 local protocol = rockspec.source.protocol 360 local protocol = rockspec.source.protocol
359 local ok, proto 361 local ok, proto
360 if is_basic_protocol(protocol) then 362 if fetch.is_basic_protocol(protocol) then
361 proto = require("luarocks.fetch") 363 proto = require("luarocks.fetch")
362 else 364 else
363 ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) 365 ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_"))
@@ -377,3 +379,5 @@ function fetch_sources(rockspec, extract, dest_dir)
377 end 379 end
378 return proto.get_sources(rockspec, extract, dest_dir) 380 return proto.get_sources(rockspec, extract, dest_dir)
379end 381end
382
383return fetch
diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua
index 6b4cf186..cc9fd655 100644
--- a/src/luarocks/fetch/cvs.lua
+++ b/src/luarocks/fetch/cvs.lua
@@ -1,6 +1,9 @@
1 1
2--- Fetch back-end for retrieving sources from CVS. 2--- Fetch back-end for retrieving sources from CVS.
3module("luarocks.fetch.cvs", package.seeall) 3--module("luarocks.fetch.cvs", package.seeall)
4local cvs = {}
5
6local unpack = unpack or table.unpack
4 7
5local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
@@ -13,7 +16,7 @@ local util = require("luarocks.util")
13-- @return (string, string) or (nil, string): The absolute pathname of 16-- @return (string, string) or (nil, string): The absolute pathname of
14-- the fetched source tarball and the temporary directory created to 17-- the fetched source tarball and the temporary directory created to
15-- store it; or nil and an error message. 18-- store it; or nil and an error message.
16function get_sources(rockspec, extract, dest_dir) 19function cvs.get_sources(rockspec, extract, dest_dir)
17 assert(type(rockspec) == "table") 20 assert(type(rockspec) == "table")
18 assert(type(dest_dir) == "string" or not dest_dir) 21 assert(type(dest_dir) == "string" or not dest_dir)
19 22
@@ -43,3 +46,5 @@ function get_sources(rockspec, extract, dest_dir)
43 return module, store_dir 46 return module, store_dir
44end 47end
45 48
49
50return cvs
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index 2bba4cdc..53fd4445 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -1,6 +1,9 @@
1 1
2--- Fetch back-end for retrieving sources from GIT. 2--- Fetch back-end for retrieving sources from GIT.
3module("luarocks.fetch.git", package.seeall) 3--module("luarocks.fetch.git", package.seeall)
4local git = {}
5
6local unpack = unpack or table.unpack
4 7
5local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
@@ -27,7 +30,7 @@ end
27-- @return (string, string) or (nil, string): The absolute pathname of 30-- @return (string, string) or (nil, string): The absolute pathname of
28-- the fetched source tarball and the temporary directory created to 31-- the fetched source tarball and the temporary directory created to
29-- store it; or nil and an error message. 32-- store it; or nil and an error message.
30function get_sources(rockspec, extract, dest_dir, depth) 33function git.get_sources(rockspec, extract, dest_dir, depth)
31 assert(type(rockspec) == "table") 34 assert(type(rockspec) == "table")
32 assert(type(dest_dir) == "string" or not dest_dir) 35 assert(type(dest_dir) == "string" or not dest_dir)
33 36
@@ -66,7 +69,7 @@ function get_sources(rockspec, extract, dest_dir, depth)
66 if not fs.execute(unpack(command)) then 69 if not fs.execute(unpack(command)) then
67 return nil, "Failed cloning git repository." 70 return nil, "Failed cloning git repository."
68 end 71 end
69 local ok, err = fs.change_dir(module) 72 ok, err = fs.change_dir(module)
70 if not ok then return nil, err end 73 if not ok then return nil, err end
71 if tag_or_branch and not git_can_clone_by_tag() then 74 if tag_or_branch and not git_can_clone_by_tag() then
72 local checkout_command = {fs.Q(git_cmd), "checkout", tag_or_branch} 75 local checkout_command = {fs.Q(git_cmd), "checkout", tag_or_branch}
@@ -81,3 +84,5 @@ function get_sources(rockspec, extract, dest_dir, depth)
81 fs.pop_dir() 84 fs.pop_dir()
82 return module, store_dir 85 return module, store_dir
83end 86end
87
88return git
diff --git a/src/luarocks/fetch/git_file.lua b/src/luarocks/fetch/git_file.lua
index 1b18d0fa..0144bc2e 100644
--- a/src/luarocks/fetch/git_file.lua
+++ b/src/luarocks/fetch/git_file.lua
@@ -1,6 +1,7 @@
1 1
2--- Fetch back-end for retrieving sources from local Git repositories. 2--- Fetch back-end for retrieving sources from local Git repositories.
3module("luarocks.fetch.git_file", package.seeall) 3--module("luarocks.fetch.git_file", package.seeall)
4local git_file = {}
4 5
5local git = require("luarocks.fetch.git") 6local git = require("luarocks.fetch.git")
6 7
@@ -11,7 +12,9 @@ local git = require("luarocks.fetch.git")
11-- @return (string, string) or (nil, string): The absolute pathname of 12-- @return (string, string) or (nil, string): The absolute pathname of
12-- the fetched source tarball and the temporary directory created to 13-- the fetched source tarball and the temporary directory created to
13-- store it; or nil and an error message. 14-- store it; or nil and an error message.
14function get_sources(rockspec, extract, dest_dir) 15function git_file.get_sources(rockspec, extract, dest_dir)
15 rockspec.source.url = rockspec.source.url:gsub("^git.file://", "") 16 rockspec.source.url = rockspec.source.url:gsub("^git.file://", "")
16 return git.get_sources(rockspec, extract, dest_dir) 17 return git.get_sources(rockspec, extract, dest_dir)
17end 18end
19
20return git_file
diff --git a/src/luarocks/fetch/git_http.lua b/src/luarocks/fetch/git_http.lua
index b5fcd095..4ecd4816 100644
--- a/src/luarocks/fetch/git_http.lua
+++ b/src/luarocks/fetch/git_http.lua
@@ -7,7 +7,8 @@
7-- source = { url = "git+http://example.com/foo.git" } 7-- source = { url = "git+http://example.com/foo.git" }
8-- Prefer using the normal git:// fetch mode as it is more widely 8-- Prefer using the normal git:// fetch mode as it is more widely
9-- available in older versions of LuaRocks. 9-- available in older versions of LuaRocks.
10module("luarocks.fetch.git_http", package.seeall) 10--module("luarocks.fetch.git_http", package.seeall)
11local git_http = {}
11 12
12local git = require("luarocks.fetch.git") 13local git = require("luarocks.fetch.git")
13 14
@@ -18,7 +19,9 @@ local git = require("luarocks.fetch.git")
18-- @return (string, string) or (nil, string): The absolute pathname of 19-- @return (string, string) or (nil, string): The absolute pathname of
19-- the fetched source tarball and the temporary directory created to 20-- the fetched source tarball and the temporary directory created to
20-- store it; or nil and an error message. 21-- store it; or nil and an error message.
21function get_sources(rockspec, extract, dest_dir) 22function git_http.get_sources(rockspec, extract, dest_dir)
22 rockspec.source.url = rockspec.source.url:gsub("^git.", "") 23 rockspec.source.url = rockspec.source.url:gsub("^git.", "")
23 return git.get_sources(rockspec, extract, dest_dir, "--") 24 return git.get_sources(rockspec, extract, dest_dir, "--")
24end 25end
26
27return git_http
diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua
index 32e40469..b2ba56e9 100644
--- a/src/luarocks/fetch/hg.lua
+++ b/src/luarocks/fetch/hg.lua
@@ -1,6 +1,9 @@
1 1
2--- Fetch back-end for retrieving sources from HG. 2--- Fetch back-end for retrieving sources from HG.
3module("luarocks.fetch.hg", package.seeall) 3--module("luarocks.fetch.hg", package.seeall)
4local hg = {}
5
6local unpack = unpack or table.unpack
4 7
5local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
@@ -13,7 +16,7 @@ local util = require("luarocks.util")
13-- @return (string, string) or (nil, string): The absolute pathname of 16-- @return (string, string) or (nil, string): The absolute pathname of
14-- the fetched source tarball and the temporary directory created to 17-- the fetched source tarball and the temporary directory created to
15-- store it; or nil and an error message. 18-- store it; or nil and an error message.
16function get_sources(rockspec, extract, dest_dir) 19function hg.get_sources(rockspec, extract, dest_dir)
17 assert(type(rockspec) == "table") 20 assert(type(rockspec) == "table")
18 assert(type(dest_dir) == "string" or not dest_dir) 21 assert(type(dest_dir) == "string" or not dest_dir)
19 22
@@ -44,7 +47,7 @@ function get_sources(rockspec, extract, dest_dir)
44 if not fs.execute(unpack(command)) then 47 if not fs.execute(unpack(command)) then
45 return nil, "Failed cloning hg repository." 48 return nil, "Failed cloning hg repository."
46 end 49 end
47 local ok, err = fs.change_dir(module) 50 ok, err = fs.change_dir(module)
48 if not ok then return nil, err end 51 if not ok then return nil, err end
49 52
50 fs.delete(dir.path(store_dir, module, ".hg")) 53 fs.delete(dir.path(store_dir, module, ".hg"))
@@ -54,3 +57,5 @@ function get_sources(rockspec, extract, dest_dir)
54 return module, store_dir 57 return module, store_dir
55end 58end
56 59
60
61return hg
diff --git a/src/luarocks/fetch/sscm.lua b/src/luarocks/fetch/sscm.lua
index e52e8019..53ae86a3 100644
--- a/src/luarocks/fetch/sscm.lua
+++ b/src/luarocks/fetch/sscm.lua
@@ -1,6 +1,7 @@
1 1
2--- Fetch back-end for retrieving sources from Surround SCM Server 2--- Fetch back-end for retrieving sources from Surround SCM Server
3module("luarocks.fetch.sscm", package.seeall) 3--module("luarocks.fetch.sscm", package.seeall)
4local sscm = {}
4 5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
@@ -12,7 +13,7 @@ local dir = require("luarocks.dir")
12-- @return (string, string) or (nil, string): The absolute pathname of 13-- @return (string, string) or (nil, string): The absolute pathname of
13-- the fetched source tarball and the temporary directory created to 14-- the fetched source tarball and the temporary directory created to
14-- store it; or nil and an error message. 15-- store it; or nil and an error message.
15function get_sources(rockspec, extract, dest_dir) 16function sscm.get_sources(rockspec, extract, dest_dir)
16 assert(type(rockspec) == "table") 17 assert(type(rockspec) == "table")
17 assert(type(dest_dir) == "string" or not dest_dir) 18 assert(type(dest_dir) == "string" or not dest_dir)
18 19
@@ -40,3 +41,5 @@ function get_sources(rockspec, extract, dest_dir)
40 -- FIXME: This function does not honor the dest_dir parameter. 41 -- FIXME: This function does not honor the dest_dir parameter.
41 return module, working_dir 42 return module, working_dir
42end 43end
44
45return sscm
diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua
index 7aa37ec5..abeacf9a 100644
--- a/src/luarocks/fetch/svn.lua
+++ b/src/luarocks/fetch/svn.lua
@@ -1,6 +1,9 @@
1 1
2--- Fetch back-end for retrieving sources from Subversion. 2--- Fetch back-end for retrieving sources from Subversion.
3module("luarocks.fetch.svn", package.seeall) 3--module("luarocks.fetch.svn", package.seeall)
4local svn = {}
5
6local unpack = unpack or table.unpack
4 7
5local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
@@ -13,7 +16,7 @@ local util = require("luarocks.util")
13-- @return (string, string) or (nil, string): The absolute pathname of 16-- @return (string, string) or (nil, string): The absolute pathname of
14-- the fetched source tarball and the temporary directory created to 17-- the fetched source tarball and the temporary directory created to
15-- store it; or nil and an error message. 18-- store it; or nil and an error message.
16function get_sources(rockspec, extract, dest_dir) 19function svn.get_sources(rockspec, extract, dest_dir)
17 assert(type(rockspec) == "table") 20 assert(type(rockspec) == "table")
18 assert(type(dest_dir) == "string" or not dest_dir) 21 assert(type(dest_dir) == "string" or not dest_dir)
19 22
@@ -53,3 +56,5 @@ function get_sources(rockspec, extract, dest_dir)
53 return module, store_dir 56 return module, store_dir
54end 57end
55 58
59
60return svn
diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua
index b281eb14..72e11c09 100644
--- a/src/luarocks/fs.lua
+++ b/src/luarocks/fs.lua
@@ -7,7 +7,9 @@
7 7
8local pairs = pairs 8local pairs = pairs
9 9
10module("luarocks.fs", package.seeall) 10--module("luarocks.fs", package.seeall)
11local fs = {}
12package.loaded["luarocks.fs"] = fs
11 13
12local cfg = require("luarocks.cfg") 14local cfg = require("luarocks.cfg")
13 15
@@ -15,7 +17,7 @@ local pack = table.pack or function(...) return { n = select("#", ...), ... } en
15local unpack = table.unpack or unpack 17local unpack = table.unpack or unpack
16 18
17local old_popen, old_exec 19local old_popen, old_exec
18_M.verbose = function() -- patch io.popen and os.execute to display commands in verbose mode 20fs.verbose = function() -- patch io.popen and os.execute to display commands in verbose mode
19 if old_popen or old_exec then return end 21 if old_popen or old_exec then return end
20 old_popen = io.popen 22 old_popen = io.popen
21 io.popen = function(one, two) 23 io.popen = function(one, two)
@@ -38,12 +40,12 @@ _M.verbose = function() -- patch io.popen and os.execute to display commands
38 return unpack(code, 1, code.n) 40 return unpack(code, 1, code.n)
39 end 41 end
40end 42end
41if cfg.verbose then _M.verbose() end 43if cfg.verbose then fs.verbose() end
42 44
43local function load_fns(fs_table) 45local function load_fns(fs_table)
44 for name, fn in pairs(fs_table) do 46 for name, fn in pairs(fs_table) do
45 if not _M[name] then 47 if not fs[name] then
46 _M[name] = fn 48 fs[name] = fn
47 end 49 end
48 end 50 end
49end 51end
@@ -67,3 +69,5 @@ load_fns(fs_lua)
67local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") 69local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools")
68if ok and fs_plat_tools then load_fns(fs_plat_tools) end 70if ok and fs_plat_tools then load_fns(fs_plat_tools) end
69 71
72
73return fs
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 495327ea..cd705eef 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -30,7 +30,7 @@ local dir_stack = {}
30 30
31math.randomseed(os.time()) 31math.randomseed(os.time())
32 32
33dir_separator = "/" 33local dir_separator = "/"
34 34
35--- Quote argument for shell processing. 35--- Quote argument for shell processing.
36-- Adds single quotes and escapes. 36-- Adds single quotes and escapes.
@@ -683,10 +683,10 @@ if md5_ok then
683-- @return string: The MD5 checksum or nil + error 683-- @return string: The MD5 checksum or nil + error
684function fs_lua.get_md5(file) 684function fs_lua.get_md5(file)
685 file = fs.absolute_name(file) 685 file = fs.absolute_name(file)
686 local file = io.open(file, "rb") 686 local file_handler = io.open(file, "rb")
687 if not file then return nil, "Failed to open file for reading: "..file end 687 if not file_handler then return nil, "Failed to open file for reading: "..file end
688 local computed = md5.sumhexa(file:read("*a")) 688 local computed = md5.sumhexa(file_handler:read("*a"))
689 file:close() 689 file_handler:close()
690 if computed then return computed end 690 if computed then return computed end
691 return nil, "Failed to compute MD5 hash for file "..file 691 return nil, "Failed to compute MD5 hash for file "..file
692end 692end
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua
index 2dc5e492..a70ed116 100644
--- a/src/luarocks/fs/unix.lua
+++ b/src/luarocks/fs/unix.lua
@@ -1,12 +1,12 @@
1 1
2--- Unix implementation of filesystem and platform abstractions. 2--- Unix implementation of filesystem and platform abstractions.
3module("luarocks.fs.unix", package.seeall) 3--module("luarocks.fs.unix", package.seeall)
4local unix = {}
4 5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6 7
7local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
8local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
9local fs = require("luarocks.fs")
10local util = require("luarocks.util") 10local util = require("luarocks.util")
11 11
12math.randomseed(os.time()) 12math.randomseed(os.time())
@@ -14,7 +14,7 @@ math.randomseed(os.time())
14--- Annotate command string for quiet execution. 14--- Annotate command string for quiet execution.
15-- @param cmd string: A command-line string. 15-- @param cmd string: A command-line string.
16-- @return string: The command-line, with silencing annotation. 16-- @return string: The command-line, with silencing annotation.
17function quiet(cmd) 17function unix.quiet(cmd)
18 return cmd.." 1> /dev/null 2> /dev/null" 18 return cmd.." 1> /dev/null 2> /dev/null"
19end 19end
20 20
@@ -24,7 +24,7 @@ end
24-- pathname absolute, or the current dir in the dir stack if 24-- pathname absolute, or the current dir in the dir stack if
25-- not given. 25-- not given.
26-- @return string: The pathname converted to absolute. 26-- @return string: The pathname converted to absolute.
27function absolute_name(pathname, relative_to) 27function unix.absolute_name(pathname, relative_to)
28 assert(type(pathname) == "string") 28 assert(type(pathname) == "string")
29 assert(type(relative_to) == "string" or not relative_to) 29 assert(type(relative_to) == "string" or not relative_to)
30 30
@@ -43,7 +43,7 @@ end
43-- @param version string: rock version to be used in loader context. 43-- @param version string: rock version to be used in loader context.
44-- @return boolean or (nil, string): True if succeeded, or nil and 44-- @return boolean or (nil, string): True if succeeded, or nil and
45-- an error message. 45-- an error message.
46function wrap_script(file, dest, name, version) 46function unix.wrap_script(file, dest, name, version)
47 assert(type(file) == "string") 47 assert(type(file) == "string")
48 assert(type(dest) == "string") 48 assert(type(dest) == "string")
49 49
@@ -72,7 +72,7 @@ end
72-- @param filename string: the file name with full path. 72-- @param filename string: the file name with full path.
73-- @return boolean: returns true if file is an actual binary 73-- @return boolean: returns true if file is an actual binary
74-- (or if it couldn't check) or false if it is a Lua wrapper. 74-- (or if it couldn't check) or false if it is a Lua wrapper.
75function is_actual_binary(filename) 75function unix.is_actual_binary(filename)
76 if filename:match("%.lua$") then 76 if filename:match("%.lua$") then
77 return false 77 return false
78 end 78 end
@@ -89,7 +89,7 @@ function is_actual_binary(filename)
89 return first ~= "#!" 89 return first ~= "#!"
90end 90end
91 91
92function copy_binary(filename, dest) 92function unix.copy_binary(filename, dest)
93 return fs.copy(filename, dest, "0755") 93 return fs.copy(filename, dest, "0755")
94end 94end
95 95
@@ -103,6 +103,8 @@ end
103-- which will replace old_file. 103-- which will replace old_file.
104-- @return boolean or (nil, string): True if succeeded, or nil and 104-- @return boolean or (nil, string): True if succeeded, or nil and
105-- an error message. 105-- an error message.
106function replace_file(old_file, new_file) 106function unix.replace_file(old_file, new_file)
107 return os.rename(new_file, old_file) 107 return os.rename(new_file, old_file)
108end 108end
109
110return unix
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 1f4f2a4e..8a71171d 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -1,6 +1,7 @@
1 1
2--- fs operations implemented with third-party tools for Unix platform abstractions. 2--- fs operations implemented with third-party tools for Unix platform abstractions.
3module("luarocks.fs.unix.tools", package.seeall) 3--module("luarocks.fs.unix.tools", package.seeall)
4local tools = {}
4 5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
@@ -17,7 +18,7 @@ end
17--- Obtain current directory. 18--- Obtain current directory.
18-- Uses the module's internal directory stack. 19-- Uses the module's internal directory stack.
19-- @return string: the absolute pathname of the current directory. 20-- @return string: the absolute pathname of the current directory.
20function current_dir() 21function tools.current_dir()
21 local current = cfg.cache_pwd 22 local current = cfg.cache_pwd
22 if not current then 23 if not current then
23 local pipe = io.popen(fs.Q(vars.PWD)) 24 local pipe = io.popen(fs.Q(vars.PWD))
@@ -36,7 +37,7 @@ end
36-- @param cmd string: No quoting/escaping is applied to the command. 37-- @param cmd string: No quoting/escaping is applied to the command.
37-- @return boolean: true if command succeeds (status code 0), false 38-- @return boolean: true if command succeeds (status code 0), false
38-- otherwise. 39-- otherwise.
39function execute_string(cmd) 40function tools.execute_string(cmd)
40 local code, err = os.execute(command_at(fs.current_dir(), cmd)) 41 local code, err = os.execute(command_at(fs.current_dir(), cmd))
41 if code == 0 or code == true then 42 if code == 0 or code == true then
42 return true 43 return true
@@ -50,7 +51,7 @@ end
50-- semantics of chdir, as it does not handle errors the same way, 51-- semantics of chdir, as it does not handle errors the same way,
51-- but works well for our purposes for now. 52-- but works well for our purposes for now.
52-- @param directory string: The directory to switch to. 53-- @param directory string: The directory to switch to.
53function change_dir(directory) 54function tools.change_dir(directory)
54 assert(type(directory) == "string") 55 assert(type(directory) == "string")
55 if fs.is_dir(directory) then 56 if fs.is_dir(directory) then
56 table.insert(dir_stack, directory) 57 table.insert(dir_stack, directory)
@@ -62,12 +63,12 @@ end
62--- Change directory to root. 63--- Change directory to root.
63-- Allows leaving a directory (e.g. for deleting it) in 64-- Allows leaving a directory (e.g. for deleting it) in
64-- a crossplatform way. 65-- a crossplatform way.
65function change_dir_to_root() 66function tools.change_dir_to_root()
66 table.insert(dir_stack, "/") 67 table.insert(dir_stack, "/")
67end 68end
68 69
69--- Change working directory to the previous in the directory stack. 70--- Change working directory to the previous in the directory stack.
70function pop_dir() 71function tools.pop_dir()
71 local directory = table.remove(dir_stack) 72 local directory = table.remove(dir_stack)
72 return directory ~= nil 73 return directory ~= nil
73end 74end
@@ -77,7 +78,7 @@ end
77-- too, they are created as well. 78-- too, they are created as well.
78-- @param directory string: pathname of directory to create. 79-- @param directory string: pathname of directory to create.
79-- @return boolean: true on success, false on failure. 80-- @return boolean: true on success, false on failure.
80function make_dir(directory) 81function tools.make_dir(directory)
81 assert(directory) 82 assert(directory)
82 local ok, err = fs.execute(vars.MKDIR.." -p", directory) 83 local ok, err = fs.execute(vars.MKDIR.." -p", directory)
83 if not ok then 84 if not ok then
@@ -90,7 +91,7 @@ end
90-- Does not return errors (for example, if directory is not empty or 91-- Does not return errors (for example, if directory is not empty or
91-- if already does not exist) 92-- if already does not exist)
92-- @param directory string: pathname of directory to remove. 93-- @param directory string: pathname of directory to remove.
93function remove_dir_if_empty(directory) 94function tools.remove_dir_if_empty(directory)
94 assert(directory) 95 assert(directory)
95 fs.execute_quiet(vars.RMDIR, directory) 96 fs.execute_quiet(vars.RMDIR, directory)
96end 97end
@@ -99,7 +100,7 @@ end
99-- Does not return errors (for example, if directory is not empty or 100-- Does not return errors (for example, if directory is not empty or
100-- if already does not exist) 101-- if already does not exist)
101-- @param directory string: pathname of directory to remove. 102-- @param directory string: pathname of directory to remove.
102function remove_dir_tree_if_empty(directory) 103function tools.remove_dir_tree_if_empty(directory)
103 assert(directory) 104 assert(directory)
104 fs.execute_quiet(vars.RMDIR, "-p", directory) 105 fs.execute_quiet(vars.RMDIR, "-p", directory)
105end 106end
@@ -110,7 +111,7 @@ end
110-- @param perm string or nil: Permissions for destination file, 111-- @param perm string or nil: Permissions for destination file,
111-- @return boolean or (boolean, string): true on success, false on failure, 112-- @return boolean or (boolean, string): true on success, false on failure,
112-- plus an error message. 113-- plus an error message.
113function copy(src, dest, perm) 114function tools.copy(src, dest, perm)
114 assert(src and dest) 115 assert(src and dest)
115 if fs.execute(vars.CP, src, dest) then 116 if fs.execute(vars.CP, src, dest) then
116 if perm then 117 if perm then
@@ -134,7 +135,7 @@ end
134-- @param dest string: Pathname of destination 135-- @param dest string: Pathname of destination
135-- @return boolean or (boolean, string): true on success, false on failure, 136-- @return boolean or (boolean, string): true on success, false on failure,
136-- plus an error message. 137-- plus an error message.
137function copy_contents(src, dest) 138function tools.copy_contents(src, dest)
138 assert(src and dest) 139 assert(src and dest)
139 if fs.execute_quiet(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest)) then 140 if fs.execute_quiet(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest)) then
140 return true 141 return true
@@ -146,7 +147,7 @@ end
146-- For safety, this only accepts absolute paths. 147-- For safety, this only accepts absolute paths.
147-- @param arg string: Pathname of source 148-- @param arg string: Pathname of source
148-- @return nil 149-- @return nil
149function delete(arg) 150function tools.delete(arg)
150 assert(arg) 151 assert(arg)
151 assert(arg:sub(1,1) == "/") 152 assert(arg:sub(1,1) == "/")
152 fs.execute_quiet(vars.RM, "-rf", arg) 153 fs.execute_quiet(vars.RM, "-rf", arg)
@@ -156,7 +157,7 @@ end
156-- Yields a filename on each iteration. 157-- Yields a filename on each iteration.
157-- @param at string: directory to list 158-- @param at string: directory to list
158-- @return nil 159-- @return nil
159function dir_iterator(at) 160function tools.dir_iterator(at)
160 local pipe = io.popen(command_at(at, vars.LS)) 161 local pipe = io.popen(command_at(at, vars.LS))
161 for file in pipe:lines() do 162 for file in pipe:lines() do
162 if file ~= "." and file ~= ".." then 163 if file ~= "." and file ~= ".." then
@@ -171,7 +172,7 @@ end
171-- directory if none is given). 172-- directory if none is given).
172-- @return table: an array of strings with the filenames representing 173-- @return table: an array of strings with the filenames representing
173-- the contents of a directory. 174-- the contents of a directory.
174function find(at) 175function tools.find(at)
175 assert(type(at) == "string" or not at) 176 assert(type(at) == "string" or not at)
176 if not at then 177 if not at then
177 at = fs.current_dir() 178 at = fs.current_dir()
@@ -193,14 +194,14 @@ end
193-- @param ... Filenames to be stored in the archive are given as 194-- @param ... Filenames to be stored in the archive are given as
194-- additional arguments. 195-- additional arguments.
195-- @return boolean: true on success, false on failure. 196-- @return boolean: true on success, false on failure.
196function zip(zipfile, ...) 197function tools.zip(zipfile, ...)
197 return fs.execute(vars.ZIP.." -r", zipfile, ...) 198 return fs.execute(vars.ZIP.." -r", zipfile, ...)
198end 199end
199 200
200--- Uncompress files from a .zip archive. 201--- Uncompress files from a .zip archive.
201-- @param zipfile string: pathname of .zip archive to be extracted. 202-- @param zipfile string: pathname of .zip archive to be extracted.
202-- @return boolean: true on success, false on failure. 203-- @return boolean: true on success, false on failure.
203function unzip(zipfile) 204function tools.unzip(zipfile)
204 assert(zipfile) 205 assert(zipfile)
205 return fs.execute_quiet(vars.UNZIP, zipfile) 206 return fs.execute_quiet(vars.UNZIP, zipfile)
206end 207end
@@ -208,7 +209,7 @@ end
208--- Test is file/directory exists 209--- Test is file/directory exists
209-- @param file string: filename to test 210-- @param file string: filename to test
210-- @return boolean: true if file exists, false otherwise. 211-- @return boolean: true if file exists, false otherwise.
211function exists(file) 212function tools.exists(file)
212 assert(file) 213 assert(file)
213 return fs.execute(vars.TEST, "-e", file) 214 return fs.execute(vars.TEST, "-e", file)
214end 215end
@@ -216,7 +217,7 @@ end
216--- Test is pathname is a directory. 217--- Test is pathname is a directory.
217-- @param file string: pathname to test 218-- @param file string: pathname to test
218-- @return boolean: true if it is a directory, false otherwise. 219-- @return boolean: true if it is a directory, false otherwise.
219function is_dir(file) 220function tools.is_dir(file)
220 assert(file) 221 assert(file)
221 return fs.execute(vars.TEST, "-d", file) 222 return fs.execute(vars.TEST, "-d", file)
222end 223end
@@ -224,7 +225,7 @@ end
224--- Test is pathname is a regular file. 225--- Test is pathname is a regular file.
225-- @param file string: pathname to test 226-- @param file string: pathname to test
226-- @return boolean: true if it is a regular file, false otherwise. 227-- @return boolean: true if it is a regular file, false otherwise.
227function is_file(file) 228function tools.is_file(file)
228 assert(file) 229 assert(file)
229 return fs.execute(vars.TEST, "-f", file) 230 return fs.execute(vars.TEST, "-f", file)
230end 231end
@@ -237,7 +238,7 @@ end
237-- filename can be given explicitly as this second argument. 238-- filename can be given explicitly as this second argument.
238-- @return (boolean, string): true and the filename on success, 239-- @return (boolean, string): true and the filename on success,
239-- false and the error message on failure. 240-- false and the error message on failure.
240function download(url, filename, cache) 241function tools.download(url, filename, cache)
241 assert(type(url) == "string") 242 assert(type(url) == "string")
242 assert(type(filename) == "string" or not filename) 243 assert(type(filename) == "string" or not filename)
243 244
@@ -267,7 +268,7 @@ function download(url, filename, cache)
267 end 268 end
268end 269end
269 270
270function chmod(pathname, mode) 271function tools.chmod(pathname, mode)
271 if mode then 272 if mode then
272 return fs.execute(vars.CHMOD, mode, pathname) 273 return fs.execute(vars.CHMOD, mode, pathname)
273 else 274 else
@@ -277,7 +278,7 @@ end
277 278
278--- Apply a patch. 279--- Apply a patch.
279-- @param patchname string: The filename of the patch. 280-- @param patchname string: The filename of the patch.
280function apply_patch(patchname) 281function tools.apply_patch(patchname)
281 return fs.execute(vars.PATCH.." -p1 -f -i ", patchname) 282 return fs.execute(vars.PATCH.." -p1 -f -i ", patchname)
282end 283end
283 284
@@ -286,7 +287,7 @@ end
286-- filename extension. 287-- filename extension.
287-- @param archive string: Filename of archive. 288-- @param archive string: Filename of archive.
288-- @return boolean or (boolean, string): true on success, false and an error message on failure. 289-- @return boolean or (boolean, string): true on success, false and an error message on failure.
289function unpack_archive(archive) 290function tools.unpack_archive(archive)
290 assert(type(archive) == "string") 291 assert(type(archive) == "string")
291 292
292 local ok 293 local ok
@@ -318,7 +319,7 @@ local md5_cmd = {
318--- Get the MD5 checksum for a file. 319--- Get the MD5 checksum for a file.
319-- @param file string: The file to be computed. 320-- @param file string: The file to be computed.
320-- @return string: The MD5 checksum 321-- @return string: The MD5 checksum
321function get_md5(file) 322function tools.get_md5(file)
322 local cmd = md5_cmd[cfg.md5checker] 323 local cmd = md5_cmd[cfg.md5checker]
323 if not cmd then return nil, "no MD5 checker command configured" end 324 if not cmd then return nil, "no MD5 checker command configured" end
324 local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) 325 local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file)))
@@ -331,13 +332,15 @@ function get_md5(file)
331 return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) 332 return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file))
332end 333end
333 334
334function get_permissions(filename) 335function tools.get_permissions(filename)
335 local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename)) 336 local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename))
336 local ret = pipe:read("*l") 337 local ret = pipe:read("*l")
337 pipe:close() 338 pipe:close()
338 return ret 339 return ret
339end 340end
340 341
341function browser(url) 342function tools.browser(url)
342 return fs.execute(cfg.web_browser, url) 343 return fs.execute(cfg.web_browser, url)
343end 344end
345
346return tools
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua
index a3f0663b..238a25e9 100644
--- a/src/luarocks/fs/win32.lua
+++ b/src/luarocks/fs/win32.lua
@@ -1,7 +1,8 @@
1--- Windows implementation of filesystem and platform abstractions. 1--- Windows implementation of filesystem and platform abstractions.
2-- Download http://unxutils.sourceforge.net/ for Windows GNU utilities 2-- Download http://unxutils.sourceforge.net/ for Windows GNU utilities
3-- used by this module. 3-- used by this module.
4module("luarocks.fs.win32", package.seeall) 4--module("luarocks.fs.win32", package.seeall)
5local win32 = {}
5 6
6local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
7 8
@@ -21,7 +22,7 @@ os.execute = function(cmd, ...) return _execute(_prefix..cmd, ...) end
21--- Annotate command string for quiet execution. 22--- Annotate command string for quiet execution.
22-- @param cmd string: A command-line string. 23-- @param cmd string: A command-line string.
23-- @return string: The command-line, with silencing annotation. 24-- @return string: The command-line, with silencing annotation.
24function quiet(cmd) 25function win32.quiet(cmd)
25 return cmd.." 2> NUL 1> NUL" 26 return cmd.." 2> NUL 1> NUL"
26end 27end
27 28
@@ -43,7 +44,7 @@ end
43-- Adds double quotes and escapes. 44-- Adds double quotes and escapes.
44-- @param arg string: Unquoted argument. 45-- @param arg string: Unquoted argument.
45-- @return string: Quoted argument. 46-- @return string: Quoted argument.
46function Q(arg) 47function win32.Q(arg)
47 assert(type(arg) == "string") 48 assert(type(arg) == "string")
48 -- Quote DIR for Windows 49 -- Quote DIR for Windows
49 if arg:match("^[%.a-zA-Z]?:?[\\/]") then 50 if arg:match("^[%.a-zA-Z]?:?[\\/]") then
@@ -64,7 +65,7 @@ end
64-- Adds double quotes and escapes. 65-- Adds double quotes and escapes.
65-- @param arg string: Unquoted argument. 66-- @param arg string: Unquoted argument.
66-- @return string: Quoted argument. 67-- @return string: Quoted argument.
67function Qb(arg) 68function win32.Qb(arg)
68 assert(type(arg) == "string") 69 assert(type(arg) == "string")
69 -- Quote DIR for Windows 70 -- Quote DIR for Windows
70 if arg:match("^[%.a-zA-Z]?:?[\\/]") then 71 if arg:match("^[%.a-zA-Z]?:?[\\/]") then
@@ -86,7 +87,7 @@ end
86-- pathname absolute, or the current dir in the dir stack if 87-- pathname absolute, or the current dir in the dir stack if
87-- not given. 88-- not given.
88-- @return string: The pathname converted to absolute. 89-- @return string: The pathname converted to absolute.
89function absolute_name(pathname, relative_to) 90function win32.absolute_name(pathname, relative_to)
90 assert(type(pathname) == "string") 91 assert(type(pathname) == "string")
91 assert(type(relative_to) == "string" or not relative_to) 92 assert(type(relative_to) == "string" or not relative_to)
92 93
@@ -107,7 +108,7 @@ end
107-- @param version string: rock version to be used in loader context. 108-- @param version string: rock version to be used in loader context.
108-- @return boolean or (nil, string): True if succeeded, or nil and 109-- @return boolean or (nil, string): True if succeeded, or nil and
109-- an error message. 110-- an error message.
110function wrap_script(file, dest, name, version) 111function win32.wrap_script(file, dest, name, version)
111 assert(type(file) == "string") 112 assert(type(file) == "string")
112 assert(type(dest) == "string") 113 assert(type(dest) == "string")
113 114
@@ -128,7 +129,7 @@ function wrap_script(file, dest, name, version)
128 return true 129 return true
129end 130end
130 131
131function is_actual_binary(name) 132function win32.is_actual_binary(name)
132 name = name:lower() 133 name = name:lower()
133 if name:match("%.bat$") or name:match("%.exe$") then 134 if name:match("%.bat$") or name:match("%.exe$") then
134 return true 135 return true
@@ -136,14 +137,14 @@ function is_actual_binary(name)
136 return false 137 return false
137end 138end
138 139
139function copy_binary(filename, dest) 140function win32.copy_binary(filename, dest)
140 local ok, err = fs.copy(filename, dest) 141 local ok, err = fs.copy(filename, dest)
141 if not ok then 142 if not ok then
142 return nil, err 143 return nil, err
143 end 144 end
144 local exe_pattern = "%.[Ee][Xx][Ee]$" 145 local exe_pattern = "%.[Ee][Xx][Ee]$"
145 local base = dir.base_name(filename) 146 local base = dir.base_name(filename)
146 local dest = dir.dir_name(dest) 147 dest = dir.dir_name(dest)
147 if base:match(exe_pattern) then 148 if base:match(exe_pattern) then
148 base = base:gsub(exe_pattern, ".lua") 149 base = base:gsub(exe_pattern, ".lua")
149 local helpname = dest.."/"..base 150 local helpname = dest.."/"..base
@@ -158,11 +159,11 @@ function copy_binary(filename, dest)
158 return true 159 return true
159end 160end
160 161
161function chmod(filename, mode) 162function win32.chmod(filename, mode)
162 return true 163 return true
163end 164end
164 165
165function get_permissions(filename) 166function win32.get_permissions(filename)
166 return "" 167 return ""
167end 168end
168 169
@@ -177,7 +178,7 @@ end
177-- which will replace old_file. 178-- which will replace old_file.
178-- @return boolean or (nil, string): True if succeeded, or nil and 179-- @return boolean or (nil, string): True if succeeded, or nil and
179-- an error message. 180-- an error message.
180function replace_file(old_file, new_file) 181function win32.replace_file(old_file, new_file)
181 os.remove(old_file) 182 os.remove(old_file)
182 return os.rename(new_file, old_file) 183 return os.rename(new_file, old_file)
183end 184end
@@ -188,7 +189,7 @@ end
188-- for checking the result of subsequent operations. 189-- for checking the result of subsequent operations.
189-- @param file string: filename to test 190-- @param file string: filename to test
190-- @return boolean: true if file exists, false otherwise. 191-- @return boolean: true if file exists, false otherwise.
191function is_writable(file) 192function win32.is_writable(file)
192 assert(file) 193 assert(file)
193 file = dir.normalize(file) 194 file = dir.normalize(file)
194 local result 195 local result
@@ -212,3 +213,5 @@ function is_writable(file)
212 end 213 end
213 return result 214 return result
214end 215end
216
217return win32
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua
index 55781b66..abf3779f 100644
--- a/src/luarocks/fs/win32/tools.lua
+++ b/src/luarocks/fs/win32/tools.lua
@@ -2,7 +2,8 @@
2--- fs operations implemented with third-party tools for Windows platform abstractions. 2--- fs operations implemented with third-party tools for Windows platform abstractions.
3-- Download http://unxutils.sourceforge.net/ for Windows GNU utilities 3-- Download http://unxutils.sourceforge.net/ for Windows GNU utilities
4-- used by this module. 4-- used by this module.
5module("luarocks.fs.win32.tools", package.seeall) 5--module("luarocks.fs.win32.tools", package.seeall)
6local tools = {}
6 7
7local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
8local dir = require("luarocks.dir") 9local dir = require("luarocks.dir")
@@ -35,7 +36,7 @@ end
35--- Obtain current directory. 36--- Obtain current directory.
36-- Uses the module's internal directory stack. 37-- Uses the module's internal directory stack.
37-- @return string: the absolute pathname of the current directory. 38-- @return string: the absolute pathname of the current directory.
38function current_dir() 39function tools.current_dir()
39 local current = cfg.cache_pwd 40 local current = cfg.cache_pwd
40 if not current then 41 if not current then
41 local pipe = io.popen(fs.Q(vars.PWD)) 42 local pipe = io.popen(fs.Q(vars.PWD))
@@ -54,7 +55,7 @@ end
54-- @param cmd string: No quoting/escaping is applied to the command. 55-- @param cmd string: No quoting/escaping is applied to the command.
55-- @return boolean: true if command succeeds (status code 0), false 56-- @return boolean: true if command succeeds (status code 0), false
56-- otherwise. 57-- otherwise.
57function execute_string(cmd) 58function tools.execute_string(cmd)
58 cmd = command_at(fs.current_dir(), cmd) 59 cmd = command_at(fs.current_dir(), cmd)
59 local code = os.execute(cmd) 60 local code = os.execute(cmd)
60 if code == 0 or code == true then 61 if code == 0 or code == true then
@@ -70,7 +71,7 @@ end
70-- but works well for our purposes for now. 71-- but works well for our purposes for now.
71-- @param directory string: The directory to switch to. 72-- @param directory string: The directory to switch to.
72-- @return boolean or (nil, string): true if successful, (nil, error message) if failed. 73-- @return boolean or (nil, string): true if successful, (nil, error message) if failed.
73function change_dir(directory) 74function tools.change_dir(directory)
74 assert(type(directory) == "string") 75 assert(type(directory) == "string")
75 if fs.is_dir(directory) then 76 if fs.is_dir(directory) then
76 table.insert(dir_stack, directory) 77 table.insert(dir_stack, directory)
@@ -82,12 +83,12 @@ end
82--- Change directory to root. 83--- Change directory to root.
83-- Allows leaving a directory (e.g. for deleting it) in 84-- Allows leaving a directory (e.g. for deleting it) in
84-- a crossplatform way. 85-- a crossplatform way.
85function change_dir_to_root() 86function tools.change_dir_to_root()
86 table.insert(dir_stack, "/") 87 table.insert(dir_stack, "/")
87end 88end
88 89
89--- Change working directory to the previous in the directory stack. 90--- Change working directory to the previous in the directory stack.
90function pop_dir() 91function tools.pop_dir()
91 local directory = table.remove(dir_stack) 92 local directory = table.remove(dir_stack)
92 return directory ~= nil 93 return directory ~= nil
93end 94end
@@ -97,7 +98,7 @@ end
97-- too, they are created as well. 98-- too, they are created as well.
98-- @param directory string: pathname of directory to create. 99-- @param directory string: pathname of directory to create.
99-- @return boolean: true on success, false on failure. 100-- @return boolean: true on success, false on failure.
100function make_dir(directory) 101function tools.make_dir(directory)
101 assert(directory) 102 assert(directory)
102 directory = dir.normalize(directory) 103 directory = dir.normalize(directory)
103 fs.execute_quiet(fs.Q(vars.MKDIR).." -p ", directory) 104 fs.execute_quiet(fs.Q(vars.MKDIR).." -p ", directory)
@@ -111,7 +112,7 @@ end
111-- Does not return errors (for example, if directory is not empty or 112-- Does not return errors (for example, if directory is not empty or
112-- if already does not exist) 113-- if already does not exist)
113-- @param directory string: pathname of directory to remove. 114-- @param directory string: pathname of directory to remove.
114function remove_dir_if_empty(directory) 115function tools.remove_dir_if_empty(directory)
115 assert(directory) 116 assert(directory)
116 fs.execute_quiet(fs.Q(vars.RMDIR), directory) 117 fs.execute_quiet(fs.Q(vars.RMDIR), directory)
117end 118end
@@ -120,7 +121,7 @@ end
120-- Does not return errors (for example, if directory is not empty or 121-- Does not return errors (for example, if directory is not empty or
121-- if already does not exist) 122-- if already does not exist)
122-- @param directory string: pathname of directory to remove. 123-- @param directory string: pathname of directory to remove.
123function remove_dir_tree_if_empty(directory) 124function tools.remove_dir_tree_if_empty(directory)
124 assert(directory) 125 assert(directory)
125 fs.execute_quiet(fs.Q(vars.RMDIR), directory) 126 fs.execute_quiet(fs.Q(vars.RMDIR), directory)
126end 127end
@@ -130,7 +131,7 @@ end
130-- @param dest string: Pathname of destination 131-- @param dest string: Pathname of destination
131-- @return boolean or (boolean, string): true on success, false on failure, 132-- @return boolean or (boolean, string): true on success, false on failure,
132-- plus an error message. 133-- plus an error message.
133function copy(src, dest) 134function tools.copy(src, dest)
134 assert(src and dest) 135 assert(src and dest)
135 if dest:match("[/\\]$") then dest = dest:sub(1, -2) end 136 if dest:match("[/\\]$") then dest = dest:sub(1, -2) end
136 local ok = fs.execute(fs.Q(vars.CP), src, dest) 137 local ok = fs.execute(fs.Q(vars.CP), src, dest)
@@ -146,7 +147,7 @@ end
146-- @param dest string: Pathname of destination 147-- @param dest string: Pathname of destination
147-- @return boolean or (boolean, string): true on success, false on failure, 148-- @return boolean or (boolean, string): true on success, false on failure,
148-- plus an error message. 149-- plus an error message.
149function copy_contents(src, dest) 150function tools.copy_contents(src, dest)
150 assert(src and dest) 151 assert(src and dest)
151 if fs.execute_quiet(fs.Q(vars.CP).." -dR "..src.."\\*.* "..fs.Q(dest)) then 152 if fs.execute_quiet(fs.Q(vars.CP).." -dR "..src.."\\*.* "..fs.Q(dest)) then
152 return true 153 return true
@@ -159,7 +160,7 @@ end
159-- For safety, this only accepts absolute paths. 160-- For safety, this only accepts absolute paths.
160-- @param arg string: Pathname of source 161-- @param arg string: Pathname of source
161-- @return nil 162-- @return nil
162function delete(arg) 163function tools.delete(arg)
163 assert(arg) 164 assert(arg)
164 assert(arg:match("^[a-zA-Z]?:?[\\/]")) 165 assert(arg:match("^[a-zA-Z]?:?[\\/]"))
165 fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )") 166 fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )")
@@ -169,7 +170,7 @@ end
169-- Yields a filename on each iteration. 170-- Yields a filename on each iteration.
170-- @param at string: directory to list 171-- @param at string: directory to list
171-- @return nil 172-- @return nil
172function dir_iterator(at) 173function tools.dir_iterator(at)
173 local pipe = io.popen(command_at(at, fs.Q(vars.LS))) 174 local pipe = io.popen(command_at(at, fs.Q(vars.LS)))
174 for file in pipe:lines() do 175 for file in pipe:lines() do
175 if file ~= "." and file ~= ".." then 176 if file ~= "." and file ~= ".." then
@@ -184,7 +185,7 @@ end
184-- directory if none is given). 185-- directory if none is given).
185-- @return table: an array of strings with the filenames representing 186-- @return table: an array of strings with the filenames representing
186-- the contents of a directory. Paths are returned with forward slashes. 187-- the contents of a directory. Paths are returned with forward slashes.
187function find(at) 188function tools.find(at)
188 assert(type(at) == "string" or not at) 189 assert(type(at) == "string" or not at)
189 if not at then 190 if not at then
190 at = fs.current_dir() 191 at = fs.current_dir()
@@ -211,14 +212,14 @@ end
211-- @param ... Filenames to be stored in the archive are given as 212-- @param ... Filenames to be stored in the archive are given as
212-- additional arguments. 213-- additional arguments.
213-- @return boolean: true on success, false on failure. 214-- @return boolean: true on success, false on failure.
214function zip(zipfile, ...) 215function tools.zip(zipfile, ...)
215 return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) 216 return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...)
216end 217end
217 218
218--- Uncompress files from a .zip archive. 219--- Uncompress files from a .zip archive.
219-- @param zipfile string: pathname of .zip archive to be extracted. 220-- @param zipfile string: pathname of .zip archive to be extracted.
220-- @return boolean: true on success, false on failure. 221-- @return boolean: true on success, false on failure.
221function unzip(zipfile) 222function tools.unzip(zipfile)
222 assert(zipfile) 223 assert(zipfile)
223 return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) 224 return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile)
224end 225end
@@ -226,7 +227,7 @@ end
226--- Test is pathname is a directory. 227--- Test is pathname is a directory.
227-- @param file string: pathname to test 228-- @param file string: pathname to test
228-- @return boolean: true if it is a directory, false otherwise. 229-- @return boolean: true if it is a directory, false otherwise.
229function is_dir(file) 230function tools.is_dir(file)
230 assert(file) 231 assert(file)
231 return fs.execute_quiet("if not exist " .. fs.Q(file.."\\").." invalidcommandname") 232 return fs.execute_quiet("if not exist " .. fs.Q(file.."\\").." invalidcommandname")
232end 233end
@@ -234,7 +235,7 @@ end
234--- Test is pathname is a regular file. 235--- Test is pathname is a regular file.
235-- @param file string: pathname to test 236-- @param file string: pathname to test
236-- @return boolean: true if it is a regular file, false otherwise. 237-- @return boolean: true if it is a regular file, false otherwise.
237function is_file(file) 238function tools.is_file(file)
238 assert(file) 239 assert(file)
239 return fs.execute(fs.Q(vars.TEST).." -f", file) 240 return fs.execute(fs.Q(vars.TEST).." -f", file)
240end 241end
@@ -247,7 +248,7 @@ end
247-- filename can be given explicitly as this second argument. 248-- filename can be given explicitly as this second argument.
248-- @return (boolean, string): true and the filename on success, 249-- @return (boolean, string): true and the filename on success,
249-- false and the error message on failure. 250-- false and the error message on failure.
250function download(url, filename, cache) 251function tools.download(url, filename, cache)
251 assert(type(url) == "string") 252 assert(type(url) == "string")
252 assert(type(filename) == "string" or not filename) 253 assert(type(filename) == "string" or not filename)
253 254
@@ -289,7 +290,7 @@ end
289-- filename extension. 290-- filename extension.
290-- @param archive string: Filename of archive. 291-- @param archive string: Filename of archive.
291-- @return boolean or (boolean, string): true on success, false and an error message on failure. 292-- @return boolean or (boolean, string): true on success, false and an error message on failure.
292function unpack_archive(archive) 293function tools.unpack_archive(archive)
293 assert(type(archive) == "string") 294 assert(type(archive) == "string")
294 295
295 local ok 296 local ok
@@ -333,7 +334,7 @@ local md5_cmd = {
333--- Get the MD5 checksum for a file. 334--- Get the MD5 checksum for a file.
334-- @param file string: The file to be computed. 335-- @param file string: The file to be computed.
335-- @return string: The MD5 checksum or nil + message 336-- @return string: The MD5 checksum or nil + message
336function get_md5(file) 337function tools.get_md5(file)
337 local cmd = md5_cmd[cfg.md5checker] 338 local cmd = md5_cmd[cfg.md5checker]
338 if not cmd then return nil, "no MD5 checker command configured" end 339 if not cmd then return nil, "no MD5 checker command configured" end
339 local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) 340 local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file)))
@@ -349,11 +350,13 @@ end
349--- Test for existance of a file. 350--- Test for existance of a file.
350-- @param file string: filename to test 351-- @param file string: filename to test
351-- @return boolean: true if file exists, false otherwise. 352-- @return boolean: true if file exists, false otherwise.
352function exists(file) 353function tools.exists(file)
353 assert(file) 354 assert(file)
354 return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname") 355 return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname")
355end 356end
356 357
357function browser(url) 358function tools.browser(url)
358 return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) 359 return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url))
359end 360end
361
362return tools
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua
index 9f622f96..3e428a4a 100644
--- a/src/luarocks/help.lua
+++ b/src/luarocks/help.lua
@@ -4,7 +4,8 @@
4-- uses a global table called "commands" to find commands 4-- uses a global table called "commands" to find commands
5-- to show help for; each command should be represented by a 5-- to show help for; each command should be represented by a
6-- table containing "help" and "help_summary" fields. 6-- table containing "help" and "help_summary" fields.
7module("luarocks.help", package.seeall) 7--module("luarocks.help", package.seeall)
8local help = {}
8 9
9local util = require("luarocks.util") 10local util = require("luarocks.util")
10local cfg = require("luarocks.cfg") 11local cfg = require("luarocks.cfg")
@@ -12,10 +13,10 @@ local dir = require("luarocks.dir")
12 13
13local program = util.this_program("luarocks") 14local program = util.this_program("luarocks")
14 15
15help_summary = "Help on commands. Type '"..program.." help <command>' for more." 16help.help_summary = "Help on commands. Type '"..program.." help <command>' for more."
16 17
17help_arguments = "[<command>]" 18help.help_arguments = "[<command>]"
18help = [[ 19help.help = [[
19<command> is the command to show help for. 20<command> is the command to show help for.
20]] 21]]
21 22
@@ -42,7 +43,7 @@ end
42-- given, help summaries for all commands are shown. 43-- given, help summaries for all commands are shown.
43-- @return boolean or (nil, string): true if there were no errors 44-- @return boolean or (nil, string): true if there were no errors
44-- or nil and an error message if an invalid command was requested. 45-- or nil and an error message if an invalid command was requested.
45function run(...) 46function help.run(...)
46 local flags, command = util.parse_flags(...) 47 local flags, command = util.parse_flags(...)
47 48
48 if not command then 49 if not command then
@@ -114,3 +115,5 @@ function run(...)
114 end 115 end
115 return true 116 return true
116end 117end
118
119return help
diff --git a/src/luarocks/index.lua b/src/luarocks/index.lua
index 1ce66f70..116bdfd2 100644
--- a/src/luarocks/index.lua
+++ b/src/luarocks/index.lua
@@ -1,6 +1,8 @@
1 1
2--- Module which builds the index.html page to be used in rocks servers. 2--- Module which builds the index.html page to be used in rocks servers.
3module("luarocks.index", package.seeall) 3--module("luarocks.index", package.seeall)
4local index = {}
5package.loaded["luarocks.index"] = index
4 6
5local util = require("luarocks.util") 7local util = require("luarocks.util")
6local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
@@ -95,7 +97,7 @@ local index_footer_end = [[
95</html> 97</html>
96]] 98]]
97 99
98function format_external_dependencies(rockspec) 100function index.format_external_dependencies(rockspec)
99 if rockspec.external_dependencies then 101 if rockspec.external_dependencies then
100 local deplist = {} 102 local deplist = {}
101 local listed_set = {} 103 local listed_set = {}
@@ -123,7 +125,7 @@ function format_external_dependencies(rockspec)
123 end 125 end
124end 126end
125 127
126function make_index(repo) 128function index.make_index(repo)
127 if not fs.is_dir(repo) then 129 if not fs.is_dir(repo) then
128 return nil, "Cannot access repository at "..repo 130 return nil, "Cannot access repository at "..repo
129 end 131 end
@@ -162,7 +164,7 @@ function make_index(repo)
162 detailed = descript.detailed or "", 164 detailed = descript.detailed or "",
163 license = descript.license or "N/A", 165 license = descript.license or "N/A",
164 homepage = descript.homepage and ('| <a href="'..descript.homepage..'"'..ext_url_target..'>project homepage</a>') or "", 166 homepage = descript.homepage and ('| <a href="'..descript.homepage..'"'..ext_url_target..'>project homepage</a>') or "",
165 externaldependencies = format_external_dependencies(rockspec) 167 externaldependencies = index.format_external_dependencies(rockspec)
166 } 168 }
167 vars.detailed = vars.detailed:gsub("\n\n", "</p><p>"):gsub("%s+", " ") 169 vars.detailed = vars.detailed:gsub("\n\n", "</p><p>"):gsub("%s+", " ")
168 vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '<a href="%1"'..ext_url_target..'>%1</a>') 170 vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '<a href="%1"'..ext_url_target..'>%1</a>')
@@ -181,3 +183,5 @@ function make_index(repo)
181 out:write(index_footer_end) 183 out:write(index_footer_end)
182 out:close() 184 out:close()
183end 185end
186
187return index
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 68b7c125..7678c0cc 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -1,6 +1,8 @@
1--- Module implementing the LuaRocks "install" command. 1--- Module implementing the LuaRocks "install" command.
2-- Installs binary rocks. 2-- Installs binary rocks.
3module("luarocks.install", package.seeall) 3--module("luarocks.install", package.seeall)
4local install = {}
5package.loaded["luarocks.install"] = install
4 6
5local path = require("luarocks.path") 7local path = require("luarocks.path")
6local repos = require("luarocks.repos") 8local repos = require("luarocks.repos")
@@ -12,11 +14,11 @@ local manif = require("luarocks.manif")
12local remove = require("luarocks.remove") 14local remove = require("luarocks.remove")
13local cfg = require("luarocks.cfg") 15local cfg = require("luarocks.cfg")
14 16
15help_summary = "Install a rock." 17install.help_summary = "Install a rock."
16 18
17help_arguments = "{<rock>|<name> [<version>]}" 19install.help_arguments = "{<rock>|<name> [<version>]}"
18 20
19help = [[ 21install.help = [[
20Argument may be the name of a rock to be fetched from a repository 22Argument may be the name of a rock to be fetched from a repository
21or a filename of a locally available rock. 23or a filename of a locally available rock.
22 24
@@ -34,7 +36,7 @@ or a filename of a locally available rock.
34-- "order" for all trees with priority >= the current default, "none" for no trees. 36-- "order" for all trees with priority >= the current default, "none" for no trees.
35-- @return (string, string) or (nil, string, [string]): Name and version of 37-- @return (string, string) or (nil, string, [string]): Name and version of
36-- installed rock if succeeded or nil and an error message followed by an error code. 38-- installed rock if succeeded or nil and an error message followed by an error code.
37function install_binary_rock(rock_file, deps_mode) 39function install.install_binary_rock(rock_file, deps_mode)
38 assert(type(rock_file) == "string") 40 assert(type(rock_file) == "string")
39 41
40 local name, version, arch = path.parse_name(rock_file) 42 local name, version, arch = path.parse_name(rock_file)
@@ -117,7 +119,7 @@ end
117-- may also be given. 119-- may also be given.
118-- @return boolean or (nil, string, exitcode): True if installation was 120-- @return boolean or (nil, string, exitcode): True if installation was
119-- successful, nil and an error message otherwise. exitcode is optionally returned. 121-- successful, nil and an error message otherwise. exitcode is optionally returned.
120function run(...) 122function install.run(...)
121 local flags, name, version = util.parse_flags(...) 123 local flags, name, version = util.parse_flags(...)
122 if type(name) ~= "string" then 124 if type(name) ~= "string" then
123 return nil, "Argument missing. "..util.see_help("install") 125 return nil, "Argument missing. "..util.see_help("install")
@@ -131,7 +133,7 @@ function run(...)
131 local build = require("luarocks.build") 133 local build = require("luarocks.build")
132 return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode")) 134 return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode"))
133 elseif name:match("%.rock$") then 135 elseif name:match("%.rock$") then
134 ok, err = install_binary_rock(name, deps.get_deps_mode(flags)) 136 ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags))
135 if not ok then return nil, err end 137 if not ok then return nil, err end
136 local name, version = ok, err 138 local name, version = ok, err
137 if (not flags["keep"]) and not cfg.keep_other_versions then 139 if (not flags["keep"]) and not cfg.keep_other_versions then
@@ -147,7 +149,7 @@ function run(...)
147 elseif type(results) == "string" then 149 elseif type(results) == "string" then
148 local url = results 150 local url = results
149 util.printout("Installing "..url.."...") 151 util.printout("Installing "..url.."...")
150 return run(url, util.forward_flags(flags)) 152 return install.run(url, util.forward_flags(flags))
151 else 153 else
152 util.printout() 154 util.printout()
153 util.printerr("Could not determine which rock to install.") 155 util.printerr("Could not determine which rock to install.")
@@ -157,3 +159,5 @@ function run(...)
157 end 159 end
158 end 160 end
159end 161end
162
163return install
diff --git a/src/luarocks/lint.lua b/src/luarocks/lint.lua
index e3bf34b5..091c8de4 100644
--- a/src/luarocks/lint.lua
+++ b/src/luarocks/lint.lua
@@ -1,22 +1,24 @@
1 1
2--- Module implementing the LuaRocks "lint" command. 2--- Module implementing the LuaRocks "lint" command.
3-- Utility function that checks syntax of the rockspec. 3-- Utility function that checks syntax of the rockspec.
4module("luarocks.lint", package.seeall) 4--module("luarocks.lint", package.seeall)
5local lint = {}
6package.loaded["luarocks.lint"] = lint
5 7
6local util = require("luarocks.util") 8local util = require("luarocks.util")
7local download = require("luarocks.download") 9local download = require("luarocks.download")
8local fetch = require("luarocks.fetch") 10local fetch = require("luarocks.fetch")
9 11
10help_summary = "Check syntax of a rockspec." 12lint.help_summary = "Check syntax of a rockspec."
11help_arguments = "<rockspec>" 13lint.help_arguments = "<rockspec>"
12help = [[ 14lint.help = [[
13This is a utility function that checks the syntax of a rockspec. 15This is a utility function that checks the syntax of a rockspec.
14 16
15It returns success or failure if the text of a rockspec is 17It returns success or failure if the text of a rockspec is
16syntactically correct. 18syntactically correct.
17]] 19]]
18 20
19function run(...) 21function lint.run(...)
20 local flags, input = util.parse_flags(...) 22 local flags, input = util.parse_flags(...)
21 23
22 if not input then 24 if not input then
@@ -51,3 +53,5 @@ function run(...)
51 53
52 return ok, ok or filename.." failed consistency checks." 54 return ok, ok or filename.." failed consistency checks."
53end 55end
56
57return lint
diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua
index 6081ed43..319909d3 100644
--- a/src/luarocks/list.lua
+++ b/src/luarocks/list.lua
@@ -1,16 +1,18 @@
1 1
2--- Module implementing the LuaRocks "list" command. 2--- Module implementing the LuaRocks "list" command.
3-- Lists currently installed rocks. 3-- Lists currently installed rocks.
4module("luarocks.list", package.seeall) 4--module("luarocks.list", package.seeall)
5local list = {}
6package.loaded["luarocks.list"] = list
5 7
6local search = require("luarocks.search") 8local search = require("luarocks.search")
7local cfg = require("luarocks.cfg") 9local cfg = require("luarocks.cfg")
8local util = require("luarocks.util") 10local util = require("luarocks.util")
9local path = require("luarocks.path") 11local path = require("luarocks.path")
10 12
11help_summary = "Lists currently installed rocks." 13list.help_summary = "Lists currently installed rocks."
12help_arguments = "[--porcelain] <filter>" 14list.help_arguments = "[--porcelain] <filter>"
13help = [[ 15list.help = [[
14<filter> is a substring of a rock name to filter by. 16<filter> is a substring of a rock name to filter by.
15 17
16--porcelain Produce machine-friendly output. 18--porcelain Produce machine-friendly output.
@@ -20,7 +22,7 @@ help = [[
20-- @param filter string or nil: A substring of a rock name to filter by. 22-- @param filter string or nil: A substring of a rock name to filter by.
21-- @param version string or nil: a version may also be passed. 23-- @param version string or nil: a version may also be passed.
22-- @return boolean: True if succeeded, nil on errors. 24-- @return boolean: True if succeeded, nil on errors.
23function run(...) 25function list.run(...)
24 local flags, filter, version = util.parse_flags(...) 26 local flags, filter, version = util.parse_flags(...)
25 local results = {} 27 local results = {}
26 local query = search.make_query(filter and filter:lower() or "", version) 28 local query = search.make_query(filter and filter:lower() or "", version)
@@ -36,3 +38,5 @@ function run(...)
36 search.print_results(results, flags["porcelain"]) 38 search.print_results(results, flags["porcelain"])
37 return true 39 return true
38end 40end
41
42return list
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua
index d2fa4859..3d36723f 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -5,23 +5,26 @@
5-- table in the environment, which records which versions of packages were 5-- table in the environment, which records which versions of packages were
6-- used to load previous modules, so that the loader chooses versions 6-- used to load previous modules, so that the loader chooses versions
7-- that are declared to be compatible with the ones loaded earlier. 7-- that are declared to be compatible with the ones loaded earlier.
8local global_env = _G 8local loaders = package.loaders or package.searchers
9local package, require, ipairs, pairs, table, type, next, unpack, tostring, error = 9local package, require, ipairs, pairs, table, type, next, tostring, error =
10 package, require, ipairs, pairs, table, type, next, unpack, tostring, error 10 package, require, ipairs, pairs, table, type, next, tostring, error
11local unpack = unpack or table.unpack
11 12
12module("luarocks.loader") 13--module("luarocks.loader")
14local loader = {}
15package.loaded["luarocks.loader"] = loader
13 16
14local path = require("luarocks.path") 17local path = require("luarocks.path")
15local manif_core = require("luarocks.manif_core") 18local manif_core = require("luarocks.manif_core")
16local deps = require("luarocks.deps") 19local deps = require("luarocks.deps")
17local cfg = require("luarocks.cfg") 20local cfg = require("luarocks.cfg")
18 21
19context = {} 22loader.context = {}
20 23
21-- Contains a table when rocks trees are loaded, 24-- Contains a table when rocks trees are loaded,
22-- or 'false' to indicate rocks trees failed to load. 25-- or 'false' to indicate rocks trees failed to load.
23-- 'nil' indicates rocks trees were not attempted to be loaded yet. 26-- 'nil' indicates rocks trees were not attempted to be loaded yet.
24rocks_trees = nil 27loader.rocks_trees = nil
25 28
26local function load_rocks_trees() 29local function load_rocks_trees()
27 local any_ok = false 30 local any_ok = false
@@ -34,10 +37,10 @@ local function load_rocks_trees()
34 end 37 end
35 end 38 end
36 if not any_ok then 39 if not any_ok then
37 rocks_trees = false 40 loader.rocks_trees = false
38 return false 41 return false
39 end 42 end
40 rocks_trees = trees 43 loader.rocks_trees = trees
41 return true 44 return true
42end 45end
43 46
@@ -45,20 +48,20 @@ end
45-- chain for loading modules. 48-- chain for loading modules.
46-- @param name string: The name of an installed rock. 49-- @param name string: The name of an installed rock.
47-- @param version string: The version of the rock, in string format 50-- @param version string: The version of the rock, in string format
48function add_context(name, version) 51function loader.add_context(name, version)
49 -- assert(type(name) == "string") 52 -- assert(type(name) == "string")
50 -- assert(type(version) == "string") 53 -- assert(type(version) == "string")
51 54
52 if context[name] then 55 if loader.context[name] then
53 return 56 return
54 end 57 end
55 context[name] = version 58 loader.context[name] = version
56 59
57 if not rocks_trees and not load_rocks_trees() then 60 if not loader.rocks_trees and not load_rocks_trees() then
58 return nil 61 return nil
59 end 62 end
60 63
61 for _, tree in ipairs(rocks_trees) do 64 for _, tree in ipairs(loader.rocks_trees) do
62 local manifest = tree.manifest 65 local manifest = tree.manifest
63 66
64 local pkgdeps 67 local pkgdeps
@@ -71,12 +74,12 @@ function add_context(name, version)
71 for _, dep in ipairs(pkgdeps) do 74 for _, dep in ipairs(pkgdeps) do
72 local pkg, constraints = dep.name, dep.constraints 75 local pkg, constraints = dep.name, dep.constraints
73 76
74 for _, tree in ipairs(rocks_trees) do 77 for _, tree in ipairs(loader.rocks_trees) do
75 local entries = tree.manifest.repository[pkg] 78 local entries = tree.manifest.repository[pkg]
76 if entries then 79 if entries then
77 for version, pkgs in pairs(entries) do 80 for version, pkgs in pairs(entries) do
78 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then 81 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then
79 add_context(pkg, version) 82 loader.add_context(pkg, version)
80 end 83 end
81 end 84 end
82 end 85 end
@@ -107,9 +110,9 @@ end
107-- @return table or (nil, string): The module table as returned by some other loader, 110-- @return table or (nil, string): The module table as returned by some other loader,
108-- or nil followed by an error message if no other loader managed to load the module. 111-- or nil followed by an error message if no other loader managed to load the module.
109local function call_other_loaders(module, name, version, module_name) 112local function call_other_loaders(module, name, version, module_name)
110 for i, loader in ipairs(package.loaders) do 113 for i, a_loader in ipairs(loaders) do
111 if loader ~= luarocks_loader then 114 if a_loader ~= loader.luarocks_loader then
112 local results = { loader(module_name) } 115 local results = { a_loader(module_name) }
113 if type(results[1]) == "function" then 116 if type(results[1]) == "function" then
114 return unpack(results) 117 return unpack(results)
115 end 118 end
@@ -133,12 +136,12 @@ local function select_module(module, filter_module_name)
133 --assert(type(module) == "string") 136 --assert(type(module) == "string")
134 --assert(type(filter_module_name) == "function") 137 --assert(type(filter_module_name) == "function")
135 138
136 if not rocks_trees and not load_rocks_trees() then 139 if not loader.rocks_trees and not load_rocks_trees() then
137 return nil 140 return nil
138 end 141 end
139 142
140 local providers = {} 143 local providers = {}
141 for _, tree in ipairs(rocks_trees) do 144 for _, tree in ipairs(loader.rocks_trees) do
142 local entries = tree.manifest.modules[module] 145 local entries = tree.manifest.modules[module]
143 if entries then 146 if entries then
144 for i, entry in ipairs(entries) do 147 for i, entry in ipairs(entries) do
@@ -148,7 +151,7 @@ local function select_module(module, filter_module_name)
148 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")") 151 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")")
149 end 152 end
150 module_name = filter_module_name(module_name, name, version, tree.tree, i) 153 module_name = filter_module_name(module_name, name, version, tree.tree, i)
151 if context[name] == version then 154 if loader.context[name] == version then
152 return name, version, module_name 155 return name, version, module_name
153 end 156 end
154 version = deps.parse_version(version) 157 version = deps.parse_version(version)
@@ -184,7 +187,7 @@ end
184--- Return the pathname of the file that would be loaded for a module. 187--- Return the pathname of the file that would be loaded for a module.
185-- @param module string: module name (eg. "socket.core") 188-- @param module string: module name (eg. "socket.core")
186-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 189-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
187function which(module) 190function loader.which(module)
188 local name, version, module_name = select_module(module, path.which_i) 191 local name, version, module_name = select_module(module, path.which_i)
189 return module_name 192 return module_name
190end 193end
@@ -198,14 +201,16 @@ end
198-- @return table: The module table (typically), like in plain 201-- @return table: The module table (typically), like in plain
199-- require(). See <a href="http://www.lua.org/manual/5.1/manual.html#pdf-require">require()</a> 202-- require(). See <a href="http://www.lua.org/manual/5.1/manual.html#pdf-require">require()</a>
200-- in the Lua reference manual for details. 203-- in the Lua reference manual for details.
201function luarocks_loader(module) 204function loader.luarocks_loader(module)
202 local name, version, module_name = pick_module(module) 205 local name, version, module_name = pick_module(module)
203 if not name then 206 if not name then
204 return "No LuaRocks module found for "..module 207 return "No LuaRocks module found for "..module
205 else 208 else
206 add_context(name, version) 209 loader.add_context(name, version)
207 return call_other_loaders(module, name, version, module_name) 210 return call_other_loaders(module, name, version, module_name)
208 end 211 end
209end 212end
210 213
211table.insert(global_env.package.loaders, 1, luarocks_loader) 214table.insert(loaders, 1, loader.luarocks_loader)
215
216return loader
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua
index 541d6a84..1dfe6473 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/make.lua
@@ -3,7 +3,9 @@
3-- Builds sources in the current directory, but unlike "build", 3-- Builds sources in the current directory, but unlike "build",
4-- it does not fetch sources, etc., assuming everything is 4-- it does not fetch sources, etc., assuming everything is
5-- available in the current directory. 5-- available in the current directory.
6module("luarocks.make", package.seeall) 6--module("luarocks.make", package.seeall)
7local make = {}
8package.loaded["luarocks.make"] = make
7 9
8local build = require("luarocks.build") 10local build = require("luarocks.build")
9local fs = require("luarocks.fs") 11local fs = require("luarocks.fs")
@@ -14,9 +16,9 @@ local pack = require("luarocks.pack")
14local remove = require("luarocks.remove") 16local remove = require("luarocks.remove")
15local deps = require("luarocks.deps") 17local deps = require("luarocks.deps")
16 18
17help_summary = "Compile package in current directory using a rockspec." 19make.help_summary = "Compile package in current directory using a rockspec."
18help_arguments = "[--pack-binary-rock] [<rockspec>]" 20make.help_arguments = "[--pack-binary-rock] [<rockspec>]"
19help = [[ 21make.help = [[
20Builds sources in the current directory, but unlike "build", 22Builds sources in the current directory, but unlike "build",
21it does not fetch sources, etc., assuming everything is 23it does not fetch sources, etc., assuming everything is
22available in the current directory. If no argument is given, 24available in the current directory. If no argument is given,
@@ -46,7 +48,7 @@ To install rocks, you'll normally want to use the "install" and
46-- @param name string: A local rockspec. 48-- @param name string: A local rockspec.
47-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an 49-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
48-- error message otherwise. exitcode is optionally returned. 50-- error message otherwise. exitcode is optionally returned.
49function run(...) 51function make.run(...)
50 local flags, rockspec = util.parse_flags(...) 52 local flags, rockspec = util.parse_flags(...)
51 assert(type(rockspec) == "string" or not rockspec) 53 assert(type(rockspec) == "string" or not rockspec)
52 54
@@ -87,3 +89,5 @@ function run(...)
87 return name, version 89 return name, version
88 end 90 end
89end 91end
92
93return make
diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua
index 53fffc88..b6e65bf8 100644
--- a/src/luarocks/make_manifest.lua
+++ b/src/luarocks/make_manifest.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the luarocks-admin "make_manifest" command. 2--- Module implementing the luarocks-admin "make_manifest" command.
3-- Compile a manifest file for a repository. 3-- Compile a manifest file for a repository.
4module("luarocks.make_manifest", package.seeall) 4--module("luarocks.make_manifest", package.seeall)
5local make_manifest = {}
6package.loaded["luarocks.make_manifest"] = make_manifest
5 7
6local manif = require("luarocks.manif") 8local manif = require("luarocks.manif")
7local index = require("luarocks.index") 9local index = require("luarocks.index")
@@ -11,9 +13,9 @@ local deps = require("luarocks.deps")
11local fs = require("luarocks.fs") 13local fs = require("luarocks.fs")
12local dir = require("luarocks.dir") 14local dir = require("luarocks.dir")
13 15
14help_summary = "Compile a manifest file for a repository." 16make_manifest.help_summary = "Compile a manifest file for a repository."
15 17
16help = [[ 18make_manifest.help = [[
17<argument>, if given, is a local repository pathname. 19<argument>, if given, is a local repository pathname.
18 20
19--local-tree If given, do not write versioned versions of the manifest file. 21--local-tree If given, do not write versioned versions of the manifest file.
@@ -25,7 +27,7 @@ help = [[
25-- the default local repository configured as cfg.rocks_dir is used. 27-- the default local repository configured as cfg.rocks_dir is used.
26-- @return boolean or (nil, string): True if manifest was generated, 28-- @return boolean or (nil, string): True if manifest was generated,
27-- or nil and an error message. 29-- or nil and an error message.
28function run(...) 30function make_manifest.run(...)
29 local flags, repo = util.parse_flags(...) 31 local flags, repo = util.parse_flags(...)
30 32
31 assert(type(repo) == "string" or not repo) 33 assert(type(repo) == "string" or not repo)
@@ -49,3 +51,5 @@ function run(...)
49 end 51 end
50 return ok, err 52 return ok, err
51end 53end
54
55return make_manifest
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index a239b206..f1d1629c 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -2,7 +2,9 @@
2-- Manifest files describe the contents of a LuaRocks tree or server. 2-- Manifest files describe the contents of a LuaRocks tree or server.
3-- They are loaded into manifest tables, which are then used for 3-- They are loaded into manifest tables, which are then used for
4-- performing searches, matching dependencies, etc. 4-- performing searches, matching dependencies, etc.
5module("luarocks.manif", package.seeall) 5--module("luarocks.manif", package.seeall)
6local manif = {}
7package.loaded["luarocks.manif"] = manif
6 8
7local manif_core = require("luarocks.manif_core") 9local manif_core = require("luarocks.manif_core")
8local persist = require("luarocks.persist") 10local persist = require("luarocks.persist")
@@ -16,7 +18,7 @@ local path = require("luarocks.path")
16local repos = require("luarocks.repos") 18local repos = require("luarocks.repos")
17local deps = require("luarocks.deps") 19local deps = require("luarocks.deps")
18 20
19rock_manifest_cache = {} 21manif.rock_manifest_cache = {}
20 22
21--- Commit a table to disk in given local path. 23--- Commit a table to disk in given local path.
22-- @param where string: The directory where the table should be saved. 24-- @param where string: The directory where the table should be saved.
@@ -37,22 +39,22 @@ local function save_table(where, name, tbl)
37 return ok, err 39 return ok, err
38end 40end
39 41
40function load_rock_manifest(name, version, root) 42function manif.load_rock_manifest(name, version, root)
41 assert(type(name) == "string") 43 assert(type(name) == "string")
42 assert(type(version) == "string") 44 assert(type(version) == "string")
43 45
44 local name_version = name.."/"..version 46 local name_version = name.."/"..version
45 if rock_manifest_cache[name_version] then 47 if manif.rock_manifest_cache[name_version] then
46 return rock_manifest_cache[name_version].rock_manifest 48 return manif.rock_manifest_cache[name_version].rock_manifest
47 end 49 end
48 local pathname = path.rock_manifest_file(name, version, root) 50 local pathname = path.rock_manifest_file(name, version, root)
49 local rock_manifest = persist.load_into_table(pathname) 51 local rock_manifest = persist.load_into_table(pathname)
50 if not rock_manifest then return nil end 52 if not rock_manifest then return nil end
51 rock_manifest_cache[name_version] = rock_manifest 53 manif.rock_manifest_cache[name_version] = rock_manifest
52 return rock_manifest.rock_manifest 54 return rock_manifest.rock_manifest
53end 55end
54 56
55function make_rock_manifest(name, version) 57function manif.make_rock_manifest(name, version)
56 local install_dir = path.install_dir(name, version) 58 local install_dir = path.install_dir(name, version)
57 local rock_manifest = path.rock_manifest_file(name, version) 59 local rock_manifest = path.rock_manifest_file(name, version)
58 local tree = {} 60 local tree = {}
@@ -80,7 +82,7 @@ function make_rock_manifest(name, version)
80 end 82 end
81 end 83 end
82 rock_manifest = { rock_manifest=tree } 84 rock_manifest = { rock_manifest=tree }
83 rock_manifest_cache[name.."/"..version] = rock_manifest 85 manif.rock_manifest_cache[name.."/"..version] = rock_manifest
84 save_table(install_dir, "rock_manifest", rock_manifest ) 86 save_table(install_dir, "rock_manifest", rock_manifest )
85end 87end
86 88
@@ -105,7 +107,7 @@ end
105-- @param repo_url string: URL or pathname for the repository. 107-- @param repo_url string: URL or pathname for the repository.
106-- @return table or (nil, string, [string]): A table representing the manifest, 108-- @return table or (nil, string, [string]): A table representing the manifest,
107-- or nil followed by an error message and an optional error code. 109-- or nil followed by an error message and an optional error code.
108function load_manifest(repo_url) 110function manif.load_manifest(repo_url)
109 assert(type(repo_url) == "string") 111 assert(type(repo_url) == "string")
110 112
111 if manif_core.manifest_cache[repo_url] then 113 if manif_core.manifest_cache[repo_url] then
@@ -332,7 +334,7 @@ local function store_results(results, manifest, dep_handler)
332 local entrytable = {} 334 local entrytable = {}
333 entrytable.arch = entry.arch 335 entrytable.arch = entry.arch
334 if entry.arch == "installed" then 336 if entry.arch == "installed" then
335 local rock_manifest = load_rock_manifest(name, version) 337 local rock_manifest = manif.load_rock_manifest(name, version)
336 if not rock_manifest then 338 if not rock_manifest then
337 return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" 339 return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?"
338 end 340 end
@@ -363,7 +365,7 @@ end
363-- @param versioned boolean: if versioned versions of the manifest should be created. 365-- @param versioned boolean: if versioned versions of the manifest should be created.
364-- @return boolean or (nil, string): True if manifest was generated, 366-- @return boolean or (nil, string): True if manifest was generated,
365-- or nil and an error message. 367-- or nil and an error message.
366function make_manifest(repo, deps_mode, remote) 368function manif.make_manifest(repo, deps_mode, remote)
367 assert(type(repo) == "string") 369 assert(type(repo) == "string")
368 assert(type(deps_mode) == "string") 370 assert(type(deps_mode) == "string")
369 371
@@ -418,7 +420,7 @@ end
418-- "none" for using the default dependency mode from the configuration. 420-- "none" for using the default dependency mode from the configuration.
419-- @return boolean or (nil, string): True if manifest was generated, 421-- @return boolean or (nil, string): True if manifest was generated,
420-- or nil and an error message. 422-- or nil and an error message.
421function update_manifest(name, version, repo, deps_mode) 423function manif.update_manifest(name, version, repo, deps_mode)
422 assert(type(name) == "string") 424 assert(type(name) == "string")
423 assert(type(version) == "string") 425 assert(type(version) == "string")
424 repo = path.rocks_dir(repo or cfg.root_dir) 426 repo = path.rocks_dir(repo or cfg.root_dir)
@@ -428,14 +430,14 @@ function update_manifest(name, version, repo, deps_mode)
428 430
429 util.printout("Updating manifest for "..repo) 431 util.printout("Updating manifest for "..repo)
430 432
431 local manifest, err = load_manifest(repo) 433 local manifest, err = manif.load_manifest(repo)
432 if not manifest then 434 if not manifest then
433 util.printerr("No existing manifest. Attempting to rebuild...") 435 util.printerr("No existing manifest. Attempting to rebuild...")
434 local ok, err = make_manifest(repo, deps_mode) 436 local ok, err = manif.make_manifest(repo, deps_mode)
435 if not ok then 437 if not ok then
436 return nil, err 438 return nil, err
437 end 439 end
438 manifest, err = load_manifest(repo) 440 manifest, err = manif.load_manifest(repo)
439 if not manifest then 441 if not manifest then
440 return nil, err 442 return nil, err
441 end 443 end
@@ -452,7 +454,7 @@ function update_manifest(name, version, repo, deps_mode)
452 return save_table(repo, "manifest", manifest) 454 return save_table(repo, "manifest", manifest)
453end 455end
454 456
455function zip_manifests() 457function manif.zip_manifests()
456 for ver in util.lua_versions() do 458 for ver in util.lua_versions() do
457 local file = "manifest-"..ver 459 local file = "manifest-"..ver
458 local zip = file..".zip" 460 local zip = file..".zip"
@@ -499,13 +501,13 @@ end
499-- @param file string: The full path of a deployed file. 501-- @param file string: The full path of a deployed file.
500-- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. 502-- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used.
501-- @return string, string: name and version of the provider rock. 503-- @return string, string: name and version of the provider rock.
502function find_current_provider(file, root) 504function manif.find_current_provider(file, root)
503 local providers, err = find_providers(file, root) 505 local providers, err = find_providers(file, root)
504 if not providers then return nil, err end 506 if not providers then return nil, err end
505 return providers[1]:match("([^/]*)/([^/]*)") 507 return providers[1]:match("([^/]*)/([^/]*)")
506end 508end
507 509
508function find_next_provider(file, root) 510function manif.find_next_provider(file, root)
509 local providers, err = find_providers(file, root) 511 local providers, err = find_providers(file, root)
510 if not providers then return nil, err end 512 if not providers then return nil, err end
511 if providers[2] then 513 if providers[2] then
@@ -514,3 +516,5 @@ function find_next_provider(file, root)
514 return nil 516 return nil
515 end 517 end
516end 518end
519
520return manif
diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua
index b9fe8ab9..1a2c111f 100644
--- a/src/luarocks/manif_core.lua
+++ b/src/luarocks/manif_core.lua
@@ -1,7 +1,9 @@
1 1
2--- Core functions for querying manifest files. 2--- Core functions for querying manifest files.
3-- This module requires no specific 'fs' functionality. 3-- This module requires no specific 'fs' functionality.
4module("luarocks.manif_core", package.seeall) 4--module("luarocks.manif_core", package.seeall)
5local manif_core = {}
6package.loaded["luarocks.manif_core"] = manif_core
5 7
6local persist = require("luarocks.persist") 8local persist = require("luarocks.persist")
7local type_check = require("luarocks.type_check") 9local type_check = require("luarocks.type_check")
@@ -10,14 +12,14 @@ local util = require("luarocks.util")
10local cfg = require("luarocks.cfg") 12local cfg = require("luarocks.cfg")
11local path = require("luarocks.path") 13local path = require("luarocks.path")
12 14
13manifest_cache = {} 15manif_core.manifest_cache = {}
14 16
15--- Back-end function that actually loads the manifest 17--- Back-end function that actually loads the manifest
16-- and stores it in the manifest cache. 18-- and stores it in the manifest cache.
17-- @param file string: The local filename of the manifest file. 19-- @param file string: The local filename of the manifest file.
18-- @param repo_url string: The repository identifier. 20-- @param repo_url string: The repository identifier.
19-- @param quick boolean: If given, skips type checking. 21-- @param quick boolean: If given, skips type checking.
20function manifest_loader(file, repo_url, quick) 22function manif_core.manifest_loader(file, repo_url, quick)
21 local manifest, err = persist.load_into_table(file) 23 local manifest, err = persist.load_into_table(file)
22 if not manifest then 24 if not manifest then
23 return nil, "Failed loading manifest for "..repo_url..": "..err 25 return nil, "Failed loading manifest for "..repo_url..": "..err
@@ -30,7 +32,7 @@ function manifest_loader(file, repo_url, quick)
30 end 32 end
31 end 33 end
32 34
33 manifest_cache[repo_url] = manifest 35 manif_core.manifest_cache[repo_url] = manifest
34 return manifest 36 return manifest
35end 37end
36 38
@@ -40,16 +42,16 @@ end
40-- @param repo_url string: URL or pathname for the repository. 42-- @param repo_url string: URL or pathname for the repository.
41-- @return table or (nil, string): A table representing the manifest, 43-- @return table or (nil, string): A table representing the manifest,
42-- or nil followed by an error message. 44-- or nil followed by an error message.
43function load_local_manifest(repo_url) 45function manif_core.load_local_manifest(repo_url)
44 assert(type(repo_url) == "string") 46 assert(type(repo_url) == "string")
45 47
46 if manifest_cache[repo_url] then 48 if manif_core.manifest_cache[repo_url] then
47 return manifest_cache[repo_url] 49 return manif_core.manifest_cache[repo_url]
48 end 50 end
49 51
50 local pathname = dir.path(repo_url, "manifest") 52 local pathname = dir.path(repo_url, "manifest")
51 53
52 return manifest_loader(pathname, repo_url, true) 54 return manif_core.manifest_loader(pathname, repo_url, true)
53end 55end
54 56
55--- Get all versions of a package listed in a manifest file. 57--- Get all versions of a package listed in a manifest file.
@@ -60,13 +62,13 @@ end
60-- or "all", to use all trees. 62-- or "all", to use all trees.
61-- @return table: An array of strings listing installed 63-- @return table: An array of strings listing installed
62-- versions of a package. 64-- versions of a package.
63function get_versions(name, deps_mode) 65function manif_core.get_versions(name, deps_mode)
64 assert(type(name) == "string") 66 assert(type(name) == "string")
65 assert(type(deps_mode) == "string") 67 assert(type(deps_mode) == "string")
66 68
67 local manifest = {} 69 local manifest = {}
68 path.map_trees(deps_mode, function(tree) 70 path.map_trees(deps_mode, function(tree)
69 local loaded = load_local_manifest(path.rocks_dir(tree)) 71 local loaded = manif_core.load_local_manifest(path.rocks_dir(tree))
70 if loaded then 72 if loaded then
71 util.deep_merge(manifest, loaded) 73 util.deep_merge(manifest, loaded)
72 end 74 end
@@ -78,3 +80,5 @@ function get_versions(name, deps_mode)
78 end 80 end
79 return {} 81 return {}
80end 82end
83
84return manif_core
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua
index 883d2ea9..9ef0cfbb 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/new_version.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "new_version" command. 2--- Module implementing the LuaRocks "new_version" command.
3-- Utility function that writes a new rockspec, updating data from a previous one. 3-- Utility function that writes a new rockspec, updating data from a previous one.
4module("luarocks.new_version", package.seeall) 4--module("luarocks.new_version", package.seeall)
5local new_version = {}
6package.loaded["luarocks.new_version"] = new_version
5 7
6local util = require("luarocks.util") 8local util = require("luarocks.util")
7local download = require("luarocks.download") 9local download = require("luarocks.download")
@@ -10,9 +12,9 @@ local persist = require("luarocks.persist")
10local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
11local type_check = require("luarocks.type_check") 13local type_check = require("luarocks.type_check")
12 14
13help_summary = "Auto-write a rockspec for a new version of a rock." 15new_version.help_summary = "Auto-write a rockspec for a new version of a rock."
14help_arguments = "{<package>|<rockspec>} [<new_version>] [<new_url>]" 16new_version.help_arguments = "{<package>|<rockspec>} [<new_version>] [<new_url>]"
15help = [[ 17new_version.help = [[
16This is a utility function that writes a new rockspec, updating data 18This is a utility function that writes a new rockspec, updating data
17from a previous one. 19from a previous one.
18 20
@@ -102,7 +104,7 @@ local function update_source_section(out_rs, out_name, url, old_ver, new_ver)
102 return true 104 return true
103end 105end
104 106
105function run(...) 107function new_version.run(...)
106 local flags, input, version, url = util.parse_flags(...) 108 local flags, input, version, url = util.parse_flags(...)
107 if not input then 109 if not input then
108 return nil, "Missing arguments: expected program or rockspec. "..util.see_help("new_version") 110 return nil, "Missing arguments: expected program or rockspec. "..util.see_help("new_version")
@@ -163,3 +165,5 @@ function run(...)
163 165
164 return true 166 return true
165end 167end
168
169return new_version
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index 0ef7344b..d8b3ad9b 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -1,7 +1,11 @@
1 1
2--- Module implementing the LuaRocks "pack" command. 2--- Module implementing the LuaRocks "pack" command.
3-- Creates a rock, packing sources or binaries. 3-- Creates a rock, packing sources or binaries.
4module("luarocks.pack", package.seeall) 4--module("luarocks.pack", package.seeall)
5local pack = {}
6package.loaded["luarocks.pack"] = pack
7
8local unpack = unpack or table.unpack
5 9
6local path = require("luarocks.path") 10local path = require("luarocks.path")
7local repos = require("luarocks.repos") 11local repos = require("luarocks.repos")
@@ -13,9 +17,9 @@ local dir = require("luarocks.dir")
13local manif = require("luarocks.manif") 17local manif = require("luarocks.manif")
14local search = require("luarocks.search") 18local search = require("luarocks.search")
15 19
16help_summary = "Create a rock, packing sources or binaries." 20pack.help_summary = "Create a rock, packing sources or binaries."
17help_arguments = "{<rockspec>|<name> [<version>]}" 21pack.help_arguments = "{<rockspec>|<name> [<version>]}"
18help = [[ 22pack.help = [[
19Argument may be a rockspec file, for creating a source rock, 23Argument may be a rockspec file, for creating a source rock,
20or the name of an installed package, for creating a binary rock. 24or the name of an installed package, for creating a binary rock.
21In the latter case, the app version may be given as a second 25In the latter case, the app version may be given as a second
@@ -154,7 +158,7 @@ local function do_pack_binary_rock(name, version)
154 return rock_file 158 return rock_file
155end 159end
156 160
157function pack_binary_rock(name, version, cmd, ...) 161function pack.pack_binary_rock(name, version, cmd, ...)
158 162
159 -- The --pack-binary-rock option for "luarocks build" basically performs 163 -- The --pack-binary-rock option for "luarocks build" basically performs
160 -- "luarocks build" on a temporary tree and then "luarocks pack". The 164 -- "luarocks build" on a temporary tree and then "luarocks pack". The
@@ -188,7 +192,7 @@ end
188-- version may also be passed. 192-- version may also be passed.
189-- @return boolean or (nil, string): true if successful or nil followed 193-- @return boolean or (nil, string): true if successful or nil followed
190-- by an error message. 194-- by an error message.
191function run(...) 195function pack.run(...)
192 local flags, arg, version = util.parse_flags(...) 196 local flags, arg, version = util.parse_flags(...)
193 assert(type(version) == "string" or not version) 197 assert(type(version) == "string" or not version)
194 if type(arg) ~= "string" then 198 if type(arg) ~= "string" then
@@ -208,3 +212,5 @@ function run(...)
208 return true 212 return true
209 end 213 end
210end 214end
215
216return pack
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 200829d0..598e51d9 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -2,30 +2,23 @@
2--- LuaRocks-specific path handling functions. 2--- LuaRocks-specific path handling functions.
3-- All paths are configured in this module, making it a single 3-- All paths are configured in this module, making it a single
4-- point where the layout of the local installation is defined in LuaRocks. 4-- point where the layout of the local installation is defined in LuaRocks.
5module("luarocks.path", package.seeall) 5--module("luarocks.path", package.seeall)
6local path = {}
6 7
7local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
8local cfg = require("luarocks.cfg") 9local cfg = require("luarocks.cfg")
9local util = require("luarocks.util") 10local util = require("luarocks.util")
10 11
11help_summary = "Return the currently configured package path."
12help_arguments = ""
13help = [[
14Returns the package path currently configured for this installation
15of LuaRocks, formatted as shell commands to update LUA_PATH and
16LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`)
17]]
18
19--- Infer rockspec filename from a rock filename. 12--- Infer rockspec filename from a rock filename.
20-- @param rock_name string: Pathname of a rock file. 13-- @param rock_name string: Pathname of a rock file.
21-- @return string: Filename of the rockspec, without path. 14-- @return string: Filename of the rockspec, without path.
22function rockspec_name_from_rock(rock_name) 15function path.rockspec_name_from_rock(rock_name)
23 assert(type(rock_name) == "string") 16 assert(type(rock_name) == "string")
24 local base_name = dir.base_name(rock_name) 17 local base_name = dir.base_name(rock_name)
25 return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" 18 return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec"
26end 19end
27 20
28function rocks_dir(tree) 21function path.rocks_dir(tree)
29 if type(tree) == "string" then 22 if type(tree) == "string" then
30 return dir.path(tree, cfg.rocks_subdir) 23 return dir.path(tree, cfg.rocks_subdir)
31 else 24 else
@@ -34,12 +27,12 @@ function rocks_dir(tree)
34 end 27 end
35end 28end
36 29
37function root_dir(rocks_dir) 30function path.root_dir(rocks_dir)
38 assert(type(rocks_dir) == "string") 31 assert(type(rocks_dir) == "string")
39 return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") 32 return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$")
40end 33end
41 34
42function rocks_tree_to_string(tree) 35function path.rocks_tree_to_string(tree)
43 if type(tree) == "string" then 36 if type(tree) == "string" then
44 return tree 37 return tree
45 else 38 else
@@ -48,7 +41,7 @@ function rocks_tree_to_string(tree)
48 end 41 end
49end 42end
50 43
51function deploy_bin_dir(tree) 44function path.deploy_bin_dir(tree)
52 if type(tree) == "string" then 45 if type(tree) == "string" then
53 return dir.path(tree, "bin") 46 return dir.path(tree, "bin")
54 else 47 else
@@ -57,7 +50,7 @@ function deploy_bin_dir(tree)
57 end 50 end
58end 51end
59 52
60function deploy_lua_dir(tree) 53function path.deploy_lua_dir(tree)
61 if type(tree) == "string" then 54 if type(tree) == "string" then
62 return dir.path(tree, cfg.lua_modules_path) 55 return dir.path(tree, cfg.lua_modules_path)
63 else 56 else
@@ -66,7 +59,7 @@ function deploy_lua_dir(tree)
66 end 59 end
67end 60end
68 61
69function deploy_lib_dir(tree) 62function path.deploy_lib_dir(tree)
70 if type(tree) == "string" then 63 if type(tree) == "string" then
71 return dir.path(tree, cfg.lib_modules_path) 64 return dir.path(tree, cfg.lib_modules_path)
72 else 65 else
@@ -75,7 +68,7 @@ function deploy_lib_dir(tree)
75 end 68 end
76end 69end
77 70
78function manifest_file(tree) 71function path.manifest_file(tree)
79 if type(tree) == "string" then 72 if type(tree) == "string" then
80 return dir.path(tree, cfg.rocks_subdir, "manifest") 73 return dir.path(tree, cfg.rocks_subdir, "manifest")
81 else 74 else
@@ -89,10 +82,10 @@ end
89-- @return string: The resulting path -- does not guarantee that 82-- @return string: The resulting path -- does not guarantee that
90-- @param tree string or nil: If given, specifies the local tree to use. 83-- @param tree string or nil: If given, specifies the local tree to use.
91-- the package (and by extension, the path) exists. 84-- the package (and by extension, the path) exists.
92function versions_dir(name, tree) 85function path.versions_dir(name, tree)
93 assert(type(name) == "string") 86 assert(type(name) == "string")
94 tree = tree or cfg.root_dir 87 tree = tree or cfg.root_dir
95 return dir.path(rocks_dir(tree), name) 88 return dir.path(path.rocks_dir(tree), name)
96end 89end
97 90
98--- Get the local installation directory (prefix) for a package. 91--- Get the local installation directory (prefix) for a package.
@@ -101,11 +94,11 @@ end
101-- @param tree string or nil: If given, specifies the local tree to use. 94-- @param tree string or nil: If given, specifies the local tree to use.
102-- @return string: The resulting path -- does not guarantee that 95-- @return string: The resulting path -- does not guarantee that
103-- the package (and by extension, the path) exists. 96-- the package (and by extension, the path) exists.
104function install_dir(name, version, tree) 97function path.install_dir(name, version, tree)
105 assert(type(name) == "string") 98 assert(type(name) == "string")
106 assert(type(version) == "string") 99 assert(type(version) == "string")
107 tree = tree or cfg.root_dir 100 tree = tree or cfg.root_dir
108 return dir.path(rocks_dir(tree), name, version) 101 return dir.path(path.rocks_dir(tree), name, version)
109end 102end
110 103
111--- Get the local filename of the rockspec of an installed rock. 104--- Get the local filename of the rockspec of an installed rock.
@@ -114,11 +107,11 @@ end
114-- @param tree string or nil: If given, specifies the local tree to use. 107-- @param tree string or nil: If given, specifies the local tree to use.
115-- @return string: The resulting path -- does not guarantee that 108-- @return string: The resulting path -- does not guarantee that
116-- the package (and by extension, the file) exists. 109-- the package (and by extension, the file) exists.
117function rockspec_file(name, version, tree) 110function path.rockspec_file(name, version, tree)
118 assert(type(name) == "string") 111 assert(type(name) == "string")
119 assert(type(version) == "string") 112 assert(type(version) == "string")
120 tree = tree or cfg.root_dir 113 tree = tree or cfg.root_dir
121 return dir.path(rocks_dir(tree), name, version, name.."-"..version..".rockspec") 114 return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec")
122end 115end
123 116
124--- Get the local filename of the rock_manifest file of an installed rock. 117--- Get the local filename of the rock_manifest file of an installed rock.
@@ -127,11 +120,11 @@ end
127-- @param tree string or nil: If given, specifies the local tree to use. 120-- @param tree string or nil: If given, specifies the local tree to use.
128-- @return string: The resulting path -- does not guarantee that 121-- @return string: The resulting path -- does not guarantee that
129-- the package (and by extension, the file) exists. 122-- the package (and by extension, the file) exists.
130function rock_manifest_file(name, version, tree) 123function path.rock_manifest_file(name, version, tree)
131 assert(type(name) == "string") 124 assert(type(name) == "string")
132 assert(type(version) == "string") 125 assert(type(version) == "string")
133 tree = tree or cfg.root_dir 126 tree = tree or cfg.root_dir
134 return dir.path(rocks_dir(tree), name, version, "rock_manifest") 127 return dir.path(path.rocks_dir(tree), name, version, "rock_manifest")
135end 128end
136 129
137--- Get the local installation directory for C libraries of a package. 130--- Get the local installation directory for C libraries of a package.
@@ -140,11 +133,11 @@ end
140-- @param tree string or nil: If given, specifies the local tree to use. 133-- @param tree string or nil: If given, specifies the local tree to use.
141-- @return string: The resulting path -- does not guarantee that 134-- @return string: The resulting path -- does not guarantee that
142-- the package (and by extension, the path) exists. 135-- the package (and by extension, the path) exists.
143function lib_dir(name, version, tree) 136function path.lib_dir(name, version, tree)
144 assert(type(name) == "string") 137 assert(type(name) == "string")
145 assert(type(version) == "string") 138 assert(type(version) == "string")
146 tree = tree or cfg.root_dir 139 tree = tree or cfg.root_dir
147 return dir.path(rocks_dir(tree), name, version, "lib") 140 return dir.path(path.rocks_dir(tree), name, version, "lib")
148end 141end
149 142
150--- Get the local installation directory for Lua modules of a package. 143--- Get the local installation directory for Lua modules of a package.
@@ -153,11 +146,11 @@ end
153-- @param tree string or nil: If given, specifies the local tree to use. 146-- @param tree string or nil: If given, specifies the local tree to use.
154-- @return string: The resulting path -- does not guarantee that 147-- @return string: The resulting path -- does not guarantee that
155-- the package (and by extension, the path) exists. 148-- the package (and by extension, the path) exists.
156function lua_dir(name, version, tree) 149function path.lua_dir(name, version, tree)
157 assert(type(name) == "string") 150 assert(type(name) == "string")
158 assert(type(version) == "string") 151 assert(type(version) == "string")
159 tree = tree or cfg.root_dir 152 tree = tree or cfg.root_dir
160 return dir.path(rocks_dir(tree), name, version, "lua") 153 return dir.path(path.rocks_dir(tree), name, version, "lua")
161end 154end
162 155
163--- Get the local installation directory for documentation of a package. 156--- Get the local installation directory for documentation of a package.
@@ -166,11 +159,11 @@ end
166-- @param tree string or nil: If given, specifies the local tree to use. 159-- @param tree string or nil: If given, specifies the local tree to use.
167-- @return string: The resulting path -- does not guarantee that 160-- @return string: The resulting path -- does not guarantee that
168-- the package (and by extension, the path) exists. 161-- the package (and by extension, the path) exists.
169function doc_dir(name, version, tree) 162function path.doc_dir(name, version, tree)
170 assert(type(name) == "string") 163 assert(type(name) == "string")
171 assert(type(version) == "string") 164 assert(type(version) == "string")
172 tree = tree or cfg.root_dir 165 tree = tree or cfg.root_dir
173 return dir.path(rocks_dir(tree), name, version, "doc") 166 return dir.path(path.rocks_dir(tree), name, version, "doc")
174end 167end
175 168
176--- Get the local installation directory for configuration files of a package. 169--- Get the local installation directory for configuration files of a package.
@@ -179,11 +172,11 @@ end
179-- @param tree string or nil: If given, specifies the local tree to use. 172-- @param tree string or nil: If given, specifies the local tree to use.
180-- @return string: The resulting path -- does not guarantee that 173-- @return string: The resulting path -- does not guarantee that
181-- the package (and by extension, the path) exists. 174-- the package (and by extension, the path) exists.
182function conf_dir(name, version, tree) 175function path.conf_dir(name, version, tree)
183 assert(type(name) == "string") 176 assert(type(name) == "string")
184 assert(type(version) == "string") 177 assert(type(version) == "string")
185 tree = tree or cfg.root_dir 178 tree = tree or cfg.root_dir
186 return dir.path(rocks_dir(tree), name, version, "conf") 179 return dir.path(path.rocks_dir(tree), name, version, "conf")
187end 180end
188 181
189--- Get the local installation directory for command-line scripts 182--- Get the local installation directory for command-line scripts
@@ -193,11 +186,11 @@ end
193-- @param tree string or nil: If given, specifies the local tree to use. 186-- @param tree string or nil: If given, specifies the local tree to use.
194-- @return string: The resulting path -- does not guarantee that 187-- @return string: The resulting path -- does not guarantee that
195-- the package (and by extension, the path) exists. 188-- the package (and by extension, the path) exists.
196function bin_dir(name, version, tree) 189function path.bin_dir(name, version, tree)
197 assert(type(name) == "string") 190 assert(type(name) == "string")
198 assert(type(version) == "string") 191 assert(type(version) == "string")
199 tree = tree or cfg.root_dir 192 tree = tree or cfg.root_dir
200 return dir.path(rocks_dir(tree), name, version, "bin") 193 return dir.path(path.rocks_dir(tree), name, version, "bin")
201end 194end
202 195
203--- Extract name, version and arch of a rock filename, 196--- Extract name, version and arch of a rock filename,
@@ -205,7 +198,7 @@ end
205-- @param file_name string: pathname of a rock or rockspec 198-- @param file_name string: pathname of a rock or rockspec
206-- @return (string, string, string) or nil: name, version and arch 199-- @return (string, string, string) or nil: name, version and arch
207-- or nil if name could not be parsed 200-- or nil if name could not be parsed
208function parse_name(file_name) 201function path.parse_name(file_name)
209 assert(type(file_name) == "string") 202 assert(type(file_name) == "string")
210 if file_name:match("%.rock$") then 203 if file_name:match("%.rock$") then
211 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") 204 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$")
@@ -220,7 +213,7 @@ end
220-- @param version string: Package version. 213-- @param version string: Package version.
221-- @param arch string: Architecture identifier, or "rockspec" or "installed". 214-- @param arch string: Architecture identifier, or "rockspec" or "installed".
222-- @return string: A URL or pathname following LuaRocks naming conventions. 215-- @return string: A URL or pathname following LuaRocks naming conventions.
223function make_url(pathname, name, version, arch) 216function path.make_url(pathname, name, version, arch)
224 assert(type(pathname) == "string") 217 assert(type(pathname) == "string")
225 assert(type(name) == "string") 218 assert(type(name) == "string")
226 assert(type(version) == "string") 219 assert(type(version) == "string")
@@ -244,7 +237,7 @@ end
244-- @return string: The module identifier, or nil if given path is 237-- @return string: The module identifier, or nil if given path is
245-- not a conformant module path (the function does not check if the 238-- not a conformant module path (the function does not check if the
246-- path actually exists). 239-- path actually exists).
247function path_to_module(file) 240function path.path_to_module(file)
248 assert(type(file) == "string") 241 assert(type(file) == "string")
249 242
250 local name = file:match("(.*)%."..cfg.lua_extension.."$") 243 local name = file:match("(.*)%."..cfg.lua_extension.."$")
@@ -269,7 +262,7 @@ end
269-- For example, on Unix, "foo.bar.baz" will return "foo/bar". 262-- For example, on Unix, "foo.bar.baz" will return "foo/bar".
270-- @param mod string: A module name in Lua dot-separated format. 263-- @param mod string: A module name in Lua dot-separated format.
271-- @return string: A directory name using the platform's separator. 264-- @return string: A directory name using the platform's separator.
272function module_to_path(mod) 265function path.module_to_path(mod)
273 assert(type(mod) == "string") 266 assert(type(mod) == "string")
274 return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) 267 return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator))
275end 268end
@@ -278,19 +271,19 @@ end
278-- Create a "variables" table in the rockspec table, containing 271-- Create a "variables" table in the rockspec table, containing
279-- adjusted variables according to the configuration file. 272-- adjusted variables according to the configuration file.
280-- @param rockspec table: The rockspec table. 273-- @param rockspec table: The rockspec table.
281function configure_paths(rockspec) 274function path.configure_paths(rockspec)
282 assert(type(rockspec) == "table") 275 assert(type(rockspec) == "table")
283 local vars = {} 276 local vars = {}
284 for k,v in pairs(cfg.variables) do 277 for k,v in pairs(cfg.variables) do
285 vars[k] = v 278 vars[k] = v
286 end 279 end
287 local name, version = rockspec.name, rockspec.version 280 local name, version = rockspec.name, rockspec.version
288 vars.PREFIX = install_dir(name, version) 281 vars.PREFIX = path.install_dir(name, version)
289 vars.LUADIR = lua_dir(name, version) 282 vars.LUADIR = path.lua_dir(name, version)
290 vars.LIBDIR = lib_dir(name, version) 283 vars.LIBDIR = path.lib_dir(name, version)
291 vars.CONFDIR = conf_dir(name, version) 284 vars.CONFDIR = path.conf_dir(name, version)
292 vars.BINDIR = bin_dir(name, version) 285 vars.BINDIR = path.bin_dir(name, version)
293 vars.DOCDIR = doc_dir(name, version) 286 vars.DOCDIR = path.doc_dir(name, version)
294 rockspec.variables = vars 287 rockspec.variables = vars
295end 288end
296 289
@@ -300,7 +293,7 @@ end
300-- @param name string: Rock name 293-- @param name string: Rock name
301-- @param version string: Rock version 294-- @param version string: Rock version
302-- @return string: a pathname with the same directory parts and a versioned basename. 295-- @return string: a pathname with the same directory parts and a versioned basename.
303function versioned_name(file, prefix, name, version) 296function path.versioned_name(file, prefix, name, version)
304 assert(type(file) == "string") 297 assert(type(file) == "string")
305 assert(type(name) == "string") 298 assert(type(name) == "string")
306 assert(type(version) == "string") 299 assert(type(version) == "string")
@@ -310,12 +303,12 @@ function versioned_name(file, prefix, name, version)
310 return dir.path(prefix, name_version.."-"..rest) 303 return dir.path(prefix, name_version.."-"..rest)
311end 304end
312 305
313function use_tree(tree) 306function path.use_tree(tree)
314 cfg.root_dir = tree 307 cfg.root_dir = tree
315 cfg.rocks_dir = rocks_dir(tree) 308 cfg.rocks_dir = path.rocks_dir(tree)
316 cfg.deploy_bin_dir = deploy_bin_dir(tree) 309 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
317 cfg.deploy_lua_dir = deploy_lua_dir(tree) 310 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
318 cfg.deploy_lib_dir = deploy_lib_dir(tree) 311 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
319end 312end
320 313
321--- Apply a given function to the active rocks trees based on chosen dependency mode. 314--- Apply a given function to the active rocks trees based on chosen dependency mode.
@@ -325,7 +318,7 @@ end
325-- @param fn function: function to be applied, with the tree dir (string) as the first 318-- @param fn function: function to be applied, with the tree dir (string) as the first
326-- argument and the remaining varargs of map_trees as the following arguments. 319-- argument and the remaining varargs of map_trees as the following arguments.
327-- @return a table with all results of invocations of fn collected. 320-- @return a table with all results of invocations of fn collected.
328function map_trees(deps_mode, fn, ...) 321function path.map_trees(deps_mode, fn, ...)
329 local result = {} 322 local result = {}
330 if deps_mode == "one" then 323 if deps_mode == "one" then
331 table.insert(result, (fn(cfg.root_dir, ...)) or 0) 324 table.insert(result, (fn(cfg.root_dir, ...)) or 0)
@@ -335,7 +328,7 @@ function map_trees(deps_mode, fn, ...)
335 use = true 328 use = true
336 end 329 end
337 for _, tree in ipairs(cfg.rocks_trees) do 330 for _, tree in ipairs(cfg.rocks_trees) do
338 if dir.normalize(rocks_tree_to_string(tree)) == dir.normalize(rocks_tree_to_string(cfg.root_dir)) then 331 if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then
339 use = true 332 use = true
340 end 333 end
341 if use then 334 if use then
@@ -354,17 +347,17 @@ end
354-- @param i number: the index, 1 if version is the current default, > 1 otherwise. 347-- @param i number: the index, 1 if version is the current default, > 1 otherwise.
355-- This is done this way for use by select_module in luarocks.loader. 348-- This is done this way for use by select_module in luarocks.loader.
356-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 349-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
357function which_i(module_name, name, version, tree, i) 350function path.which_i(module_name, name, version, tree, i)
358 local deploy_dir 351 local deploy_dir
359 if module_name:match("%.lua$") then 352 if module_name:match("%.lua$") then
360 deploy_dir = deploy_lua_dir(tree) 353 deploy_dir = path.deploy_lua_dir(tree)
361 module_name = dir.path(deploy_dir, module_name) 354 module_name = dir.path(deploy_dir, module_name)
362 else 355 else
363 deploy_dir = deploy_lib_dir(tree) 356 deploy_dir = path.deploy_lib_dir(tree)
364 module_name = dir.path(deploy_dir, module_name) 357 module_name = dir.path(deploy_dir, module_name)
365 end 358 end
366 if i > 1 then 359 if i > 1 then
367 module_name = versioned_name(module_name, deploy_dir, name, version) 360 module_name = path.versioned_name(module_name, deploy_dir, name, version)
368 end 361 end
369 return module_name 362 return module_name
370end 363end
@@ -378,14 +371,15 @@ end
378-- @param tree string: repository path (eg. "/usr/local") 371-- @param tree string: repository path (eg. "/usr/local")
379-- @param manifest table: the manifest table for the tree. 372-- @param manifest table: the manifest table for the tree.
380-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 373-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
381function which(module_name, filename, name, version, tree, manifest) 374function path.which(module_name, filename, name, version, tree, manifest)
382 local versions = manifest.modules[module_name] 375 local versions = manifest.modules[module_name]
383 assert(versions) 376 assert(versions)
384 for i, name_version in ipairs(versions) do 377 for i, name_version in ipairs(versions) do
385 if name_version == name.."/"..version then 378 if name_version == name.."/"..version then
386 return which_i(filename, name, version, tree, i):gsub("//", "/") 379 return path.which_i(filename, name, version, tree, i):gsub("//", "/")
387 end 380 end
388 end 381 end
389 assert(false) 382 assert(false)
390end 383end
391 384
385return path
diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/path_cmd.lua
index 4df51e2d..d52f985a 100644
--- a/src/luarocks/path_cmd.lua
+++ b/src/luarocks/path_cmd.lua
@@ -8,6 +8,14 @@ local deps = require("luarocks.deps")
8local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
9local path = require("luarocks.path") 9local path = require("luarocks.path")
10 10
11path_cmd.help_summary = "Return the currently configured package path."
12path_cmd.help_arguments = ""
13path_cmd.help = [[
14Returns the package path currently configured for this installation
15of LuaRocks, formatted as shell commands to update LUA_PATH and
16LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`)
17]]
18
11--- Driver function for "path" command. 19--- Driver function for "path" command.
12-- @return boolean This function always succeeds. 20-- @return boolean This function always succeeds.
13function path_cmd.run(...) 21function path_cmd.run(...)
diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua
index ca6a1f8c..47afc81c 100644
--- a/src/luarocks/persist.lua
+++ b/src/luarocks/persist.lua
@@ -3,7 +3,9 @@
3-- saving tables into files. 3-- saving tables into files.
4-- Implemented separately to avoid interdependencies, 4-- Implemented separately to avoid interdependencies,
5-- as it is used in the bootstrapping stage of the cfg module. 5-- as it is used in the bootstrapping stage of the cfg module.
6module("luarocks.persist", package.seeall) 6--module("luarocks.persist", package.seeall)
7local persist = {}
8package.loaded["luarocks.persist"] = persist
7 9
8local util = require("luarocks.util") 10local util = require("luarocks.util")
9 11
@@ -14,7 +16,7 @@ local util = require("luarocks.util")
14-- loaded values. 16-- loaded values.
15-- @return table or (nil, string): a table with the file's assignments 17-- @return table or (nil, string): a table with the file's assignments
16-- as fields, or nil and a message in case of errors. 18-- as fields, or nil and a message in case of errors.
17function load_into_table(filename, tbl) 19function persist.load_into_table(filename, tbl)
18 assert(type(filename) == "string") 20 assert(type(filename) == "string")
19 assert(type(tbl) == "table" or not tbl) 21 assert(type(tbl) == "table" or not tbl)
20 22
@@ -32,7 +34,7 @@ function load_into_table(filename, tbl)
32 if _VERSION == "Lua 5.1" then -- Lua 5.1 34 if _VERSION == "Lua 5.1" then -- Lua 5.1
33 chunk, err = loadfile(filename) 35 chunk, err = loadfile(filename)
34 if chunk then 36 if chunk then
35 setfenv(chunk, result) 37 persist.setfenv(chunk, result)
36 ran, err = pcall(chunk) 38 ran, err = pcall(chunk)
37 end 39 end
38 else -- Lua 5.2 40 else -- Lua 5.2
@@ -156,7 +158,7 @@ end
156-- @param tbl table: the table containing the data to be written 158-- @param tbl table: the table containing the data to be written
157-- @param field_order table: an optional array indicating the order of top-level fields. 159-- @param field_order table: an optional array indicating the order of top-level fields.
158-- @return string 160-- @return string
159function save_from_table_to_string(tbl, field_order) 161function persist.save_from_table_to_string(tbl, field_order)
160 local out = {buffer = {}} 162 local out = {buffer = {}}
161 function out:write(data) table.insert(self.buffer, data) end 163 function out:write(data) table.insert(self.buffer, data) end
162 write_table(out, tbl, field_order) 164 write_table(out, tbl, field_order)
@@ -172,7 +174,7 @@ end
172-- @param field_order table: an optional array indicating the order of top-level fields. 174-- @param field_order table: an optional array indicating the order of top-level fields.
173-- @return boolean or (nil, string): true if successful, or nil and a 175-- @return boolean or (nil, string): true if successful, or nil and a
174-- message in case of errors. 176-- message in case of errors.
175function save_from_table(filename, tbl, field_order) 177function persist.save_from_table(filename, tbl, field_order)
176 local out = io.open(filename, "w") 178 local out = io.open(filename, "w")
177 if not out then 179 if not out then
178 return nil, "Cannot create file at "..filename 180 return nil, "Cannot create file at "..filename
@@ -180,4 +182,6 @@ function save_from_table(filename, tbl, field_order)
180 write_table(out, tbl, field_order) 182 write_table(out, tbl, field_order)
181 out:close() 183 out:close()
182 return true 184 return true
183end \ No newline at end of file 185end
186
187return persist
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua
index 8c2164f9..ba9b8705 100644
--- a/src/luarocks/purge.lua
+++ b/src/luarocks/purge.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "purge" command. 2--- Module implementing the LuaRocks "purge" command.
3-- Remove all rocks from a given tree. 3-- Remove all rocks from a given tree.
4module("luarocks.purge", package.seeall) 4--module("luarocks.purge", package.seeall)
5local purge = {}
6package.loaded["luarocks.purge"] = purge
5 7
6local util = require("luarocks.util") 8local util = require("luarocks.util")
7local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
@@ -13,9 +15,9 @@ local manif = require("luarocks.manif")
13local cfg = require("luarocks.cfg") 15local cfg = require("luarocks.cfg")
14local remove = require("luarocks.remove") 16local remove = require("luarocks.remove")
15 17
16help_summary = "Remove all installed rocks from a tree." 18purge.help_summary = "Remove all installed rocks from a tree."
17help_arguments = "--tree=<tree> [--old-versions]" 19purge.help_arguments = "--tree=<tree> [--old-versions]"
18help = [[ 20purge.help = [[
19This command removes rocks en masse from a given tree. 21This command removes rocks en masse from a given tree.
20By default, it removes all rocks from a tree. 22By default, it removes all rocks from a tree.
21 23
@@ -29,7 +31,7 @@ assume a default tree.
29 overridden with the flag --force. 31 overridden with the flag --force.
30]] 32]]
31 33
32function run(...) 34function purge.run(...)
33 local flags = util.parse_flags(...) 35 local flags = util.parse_flags(...)
34 36
35 local tree = flags["tree"] 37 local tree = flags["tree"]
@@ -75,3 +77,5 @@ function run(...)
75 end 77 end
76 return manif.make_manifest(cfg.rocks_dir, "one") 78 return manif.make_manifest(cfg.rocks_dir, "one")
77end 79end
80
81return purge
diff --git a/src/luarocks/refresh_cache.lua b/src/luarocks/refresh_cache.lua
index 80730375..193e5994 100644
--- a/src/luarocks/refresh_cache.lua
+++ b/src/luarocks/refresh_cache.lua
@@ -1,20 +1,22 @@
1 1
2--- Module implementing the luarocks-admin "refresh_cache" command. 2--- Module implementing the luarocks-admin "refresh_cache" command.
3module("luarocks.refresh_cache", package.seeall) 3--module("luarocks.refresh_cache", package.seeall)
4local refresh_cache = {}
5package.loaded["luarocks.refresh_cache"] = refresh_cache
4 6
5local util = require("luarocks.util") 7local util = require("luarocks.util")
6local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
7local cache = require("luarocks.cache") 9local cache = require("luarocks.cache")
8 10
9help_summary = "Refresh local cache of a remote rocks server." 11refresh_cache.help_summary = "Refresh local cache of a remote rocks server."
10help_arguments = "[--from=<server>]" 12refresh_cache.help_arguments = "[--from=<server>]"
11help = [[ 13refresh_cache.help = [[
12The flag --from indicates which server to use. 14The flag --from indicates which server to use.
13If not given, the default server set in the upload_server variable 15If not given, the default server set in the upload_server variable
14from the configuration file is used instead. 16from the configuration file is used instead.
15]] 17]]
16 18
17function run(...) 19function refresh_cache.run(...)
18 local flags = util.parse_flags(...) 20 local flags = util.parse_flags(...)
19 local server, upload_server = cache.get_upload_server(flags["server"]) 21 local server, upload_server = cache.get_upload_server(flags["server"])
20 if not server then return nil, upload_server end 22 if not server then return nil, upload_server end
@@ -28,3 +30,5 @@ function run(...)
28 end 30 end
29end 31end
30 32
33
34return refresh_cache
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index 8f751a93..595df8f4 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "remove" command. 2--- Module implementing the LuaRocks "remove" command.
3-- Uninstalls rocks. 3-- Uninstalls rocks.
4module("luarocks.remove", package.seeall) 4--module("luarocks.remove", package.seeall)
5local remove = {}
6package.loaded["luarocks.remove"] = remove
5 7
6local search = require("luarocks.search") 8local search = require("luarocks.search")
7local deps = require("luarocks.deps") 9local deps = require("luarocks.deps")
@@ -13,9 +15,9 @@ local cfg = require("luarocks.cfg")
13local manif = require("luarocks.manif") 15local manif = require("luarocks.manif")
14local fs = require("luarocks.fs") 16local fs = require("luarocks.fs")
15 17
16help_summary = "Uninstall a rock." 18remove.help_summary = "Uninstall a rock."
17help_arguments = "[--force[=fast]] <name> [<version>]" 19remove.help_arguments = "[--force[=fast]] <name> [<version>]"
18help = [[ 20remove.help = [[
19Argument is the name of a rock to be uninstalled. 21Argument is the name of a rock to be uninstalled.
20If a version is not given, try to remove all versions at once. 22If a version is not given, try to remove all versions at once.
21Will only perform the removal if it does not break dependencies. 23Will only perform the removal if it does not break dependencies.
@@ -72,7 +74,7 @@ local function delete_versions(name, versions)
72 return true 74 return true
73end 75end
74 76
75function remove_search_results(results, name, deps_mode, force) 77function remove.remove_search_results(results, name, deps_mode, force)
76 local versions = results[name] 78 local versions = results[name]
77 79
78 local version = next(versions) 80 local version = next(versions)
@@ -119,11 +121,11 @@ function remove_search_results(results, name, deps_mode, force)
119 return true 121 return true
120end 122end
121 123
122function remove_other_versions(name, version, force) 124function remove.remove_other_versions(name, version, force)
123 local results = {} 125 local results = {}
124 search.manifest_search(results, cfg.rocks_dir, { name = name, exact_name = true, constraints = {{ op = "~=", version = version}} }) 126 search.manifest_search(results, cfg.rocks_dir, { name = name, exact_name = true, constraints = {{ op = "~=", version = version}} })
125 if results[name] then 127 if results[name] then
126 return remove_search_results(results, name, cfg.deps_mode, force) 128 return remove.remove_search_results(results, name, cfg.deps_mode, force)
127 end 129 end
128 return true 130 return true
129end 131end
@@ -135,7 +137,7 @@ end
135-- may also be given. 137-- may also be given.
136-- @return boolean or (nil, string, exitcode): True if removal was 138-- @return boolean or (nil, string, exitcode): True if removal was
137-- successful, nil and an error message otherwise. exitcode is optionally returned. 139-- successful, nil and an error message otherwise. exitcode is optionally returned.
138function run(...) 140function remove.run(...)
139 local flags, name, version = util.parse_flags(...) 141 local flags, name, version = util.parse_flags(...)
140 142
141 if type(name) ~= "string" then 143 if type(name) ~= "string" then
@@ -160,5 +162,7 @@ function run(...)
160 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in local tree." 162 return nil, "Could not find rock '"..name..(version and " "..version or "").."' in local tree."
161 end 163 end
162 164
163 return remove_search_results(results, name, deps_mode, flags["force"]) 165 return remove.remove_search_results(results, name, deps_mode, flags["force"])
164end 166end
167
168return remove
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua
index 7ad75846..17456593 100644
--- a/src/luarocks/repos.lua
+++ b/src/luarocks/repos.lua
@@ -1,6 +1,8 @@
1 1
2--- Functions for managing the repository on disk. 2--- Functions for managing the repository on disk.
3module("luarocks.repos", package.seeall) 3--module("luarocks.repos", package.seeall)
4local repos = {}
5package.loaded["luarocks.repos"] = repos
4 6
5local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
6local path = require("luarocks.path") 8local path = require("luarocks.path")
@@ -27,7 +29,7 @@ end
27-- @param version string: package version in string format 29-- @param version string: package version in string format
28-- @return boolean: true if a package is installed, 30-- @return boolean: true if a package is installed,
29-- false otherwise. 31-- false otherwise.
30function is_installed(name, version) 32function repos.is_installed(name, version)
31 assert(type(name) == "string") 33 assert(type(name) == "string")
32 assert(type(version) == "string") 34 assert(type(version) == "string")
33 35
@@ -72,7 +74,7 @@ end
72-- in "foo.bar" format and values are pathnames in architecture-dependent 74-- in "foo.bar" format and values are pathnames in architecture-dependent
73-- "foo/bar.so" format. If no modules are found or if package or version 75-- "foo/bar.so" format. If no modules are found or if package or version
74-- are invalid, an empty table is returned. 76-- are invalid, an empty table is returned.
75function package_modules(package, version) 77function repos.package_modules(package, version)
76 assert(type(package) == "string") 78 assert(type(package) == "string")
77 assert(type(version) == "string") 79 assert(type(version) == "string")
78 80
@@ -91,7 +93,7 @@ end
91-- as strings and values are pathnames in architecture-dependent 93-- as strings and values are pathnames in architecture-dependent
92-- ".../bin/foo" format. If no modules are found or if package or version 94-- ".../bin/foo" format. If no modules are found or if package or version
93-- are invalid, an empty table is returned. 95-- are invalid, an empty table is returned.
94function package_commands(package, version) 96function repos.package_commands(package, version)
95 assert(type(package) == "string") 97 assert(type(package) == "string")
96 assert(type(version) == "string") 98 assert(type(version) == "string")
97 99
@@ -107,7 +109,7 @@ end
107-- @param version string: version of an installed rock 109-- @param version string: version of an installed rock
108-- @return boolean: returns true if rock contains platform-specific 110-- @return boolean: returns true if rock contains platform-specific
109-- binary executables, or false if it is a pure-Lua rock. 111-- binary executables, or false if it is a pure-Lua rock.
110function has_binaries(name, version) 112function repos.has_binaries(name, version)
111 assert(type(name) == "string") 113 assert(type(name) == "string")
112 assert(type(version) == "string") 114 assert(type(version) == "string")
113 115
@@ -123,7 +125,7 @@ function has_binaries(name, version)
123 return false 125 return false
124end 126end
125 127
126function run_hook(rockspec, hook_name) 128function repos.run_hook(rockspec, hook_name)
127 assert(type(rockspec) == "table") 129 assert(type(rockspec) == "table")
128 assert(type(hook_name) == "string") 130 assert(type(hook_name) == "string")
129 131
@@ -155,11 +157,11 @@ local function install_binary(source, target, name, version)
155 assert(type(target) == "string") 157 assert(type(target) == "string")
156 158
157 if fs.is_lua(source) then 159 if fs.is_lua(source) then
158 ok, err = fs.wrap_script(source, target, name, version) 160 repos.ok, repos.err = fs.wrap_script(source, target, name, version)
159 else 161 else
160 ok, err = fs.copy_binary(source, target) 162 repos.ok, repos.err = fs.copy_binary(source, target)
161 end 163 end
162 return ok, err 164 return repos.ok, repos.err
163end 165end
164 166
165local function resolve_conflict(target, deploy_dir, name, version) 167local function resolve_conflict(target, deploy_dir, name, version)
@@ -178,7 +180,7 @@ local function resolve_conflict(target, deploy_dir, name, version)
178 end 180 end
179end 181end
180 182
181function should_wrap_bin_scripts(rockspec) 183function repos.should_wrap_bin_scripts(rockspec)
182 assert(type(rockspec) == "table") 184 assert(type(rockspec) == "table")
183 185
184 if cfg.wrap_bin_scripts ~= nil then 186 if cfg.wrap_bin_scripts ~= nil then
@@ -190,7 +192,7 @@ function should_wrap_bin_scripts(rockspec)
190 return true 192 return true
191end 193end
192 194
193function deploy_files(name, version, wrap_bin_scripts) 195function repos.deploy_files(name, version, wrap_bin_scripts)
194 assert(type(name) == "string") 196 assert(type(name) == "string")
195 assert(type(version) == "string") 197 assert(type(version) == "string")
196 assert(type(wrap_bin_scripts) == "boolean") 198 assert(type(wrap_bin_scripts) == "boolean")
@@ -269,7 +271,7 @@ end
269-- of another version that provides the same module that 271-- of another version that provides the same module that
270-- was deleted. This is used during 'purge', as every module 272-- was deleted. This is used during 'purge', as every module
271-- will be eventually deleted. 273-- will be eventually deleted.
272function delete_version(name, version, quick) 274function repos.delete_version(name, version, quick)
273 assert(type(name) == "string") 275 assert(type(name) == "string")
274 assert(type(version) == "string") 276 assert(type(version) == "string")
275 277
@@ -323,3 +325,5 @@ function delete_version(name, version, quick)
323 end 325 end
324 return true 326 return true
325end 327end
328
329return repos
diff --git a/src/luarocks/require.lua b/src/luarocks/require.lua
index 99177700..902bd1a3 100644
--- a/src/luarocks/require.lua
+++ b/src/luarocks/require.lua
@@ -1,6 +1,2 @@
1--- Retained for compatibility reasons only. Use luarocks.loader instead. 1--- Retained for compatibility reasons only. Use luarocks.loader instead.
2local require, pairs = require, pairs 2return require("luarocks.loader")
3module("luarocks.require")
4for k,v in pairs(require("luarocks.loader")) do
5 _M[k] = v
6end
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index 574ada40..53439386 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "search" command. 2--- Module implementing the LuaRocks "search" command.
3-- Queries LuaRocks servers. 3-- Queries LuaRocks servers.
4module("luarocks.search", package.seeall) 4--module("luarocks.search", package.seeall)
5local search = {}
6package.loaded["luarocks.search"] = search
5 7
6local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
7local path = require("luarocks.path") 9local path = require("luarocks.path")
@@ -10,9 +12,9 @@ local deps = require("luarocks.deps")
10local cfg = require("luarocks.cfg") 12local cfg = require("luarocks.cfg")
11local util = require("luarocks.util") 13local util = require("luarocks.util")
12 14
13help_summary = "Query the LuaRocks servers." 15search.help_summary = "Query the LuaRocks servers."
14help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" 16search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }"
15help = [[ 17search.help = [[
16--source Return only rockspecs and source rocks, 18--source Return only rockspecs and source rocks,
17 to be used with the "build" command. 19 to be used with the "build" command.
18--binary Return only pure Lua and binary rocks (rocks that can be used 20--binary Return only pure Lua and binary rocks (rocks that can be used
@@ -124,7 +126,7 @@ end
124-- @param table: The results table, where keys are package names and 126-- @param table: The results table, where keys are package names and
125-- versions are tables matching version strings to an array of servers. 127-- versions are tables matching version strings to an array of servers.
126-- If a table was given in the "results" parameter, that is the result value. 128-- If a table was given in the "results" parameter, that is the result value.
127function disk_search(repo, query, results) 129function search.disk_search(repo, query, results)
128 assert(type(repo) == "string") 130 assert(type(repo) == "string")
129 assert(type(query) == "table") 131 assert(type(query) == "table")
130 assert(type(results) == "table" or not results) 132 assert(type(results) == "table" or not results)
@@ -164,7 +166,7 @@ end
164-- is used. The special value "any" is also recognized, returning all 166-- is used. The special value "any" is also recognized, returning all
165-- matches regardless of architecture. 167-- matches regardless of architecture.
166-- @return true or, in case of errors, nil and an error message. 168-- @return true or, in case of errors, nil and an error message.
167function manifest_search(results, repo, query) 169function search.manifest_search(results, repo, query)
168 assert(type(results) == "table") 170 assert(type(results) == "table")
169 assert(type(repo) == "string") 171 assert(type(repo) == "string")
170 assert(type(query) == "table") 172 assert(type(query) == "table")
@@ -189,7 +191,7 @@ end
189-- @return table: A table where keys are package names 191-- @return table: A table where keys are package names
190-- and values are tables matching version strings to an array of 192-- and values are tables matching version strings to an array of
191-- rocks servers; if no results are found, an empty table is returned. 193-- rocks servers; if no results are found, an empty table is returned.
192function search_repos(query) 194function search.search_repos(query)
193 assert(type(query) == "table") 195 assert(type(query) == "table")
194 196
195 local results = {} 197 local results = {}
@@ -203,7 +205,7 @@ function search_repos(query)
203 if protocol == "file" then 205 if protocol == "file" then
204 mirror = pathname 206 mirror = pathname
205 end 207 end
206 local ok, err, errcode = manifest_search(results, mirror, query) 208 local ok, err, errcode = search.manifest_search(results, mirror, query)
207 if errcode == "network" then 209 if errcode == "network" then
208 cfg.disabled_servers[repo] = true 210 cfg.disabled_servers[repo] = true
209 end 211 end
@@ -227,7 +229,7 @@ end
227-- @param name string: The query name. 229-- @param name string: The query name.
228-- @param version string or nil: 230-- @param version string or nil:
229-- @return table: A query in table format 231-- @return table: A query in table format
230function make_query(name, version) 232function search.make_query(name, version)
231 assert(type(name) == "string") 233 assert(type(name) == "string")
232 assert(type(version) == "string" or not version) 234 assert(type(version) == "string" or not version)
233 235
@@ -276,10 +278,10 @@ end
276-- @return string or table or (nil, string): URL for matching rock if 278-- @return string or table or (nil, string): URL for matching rock if
277-- a single one was found, a table of candidates if it could not narrow to 279-- a single one was found, a table of candidates if it could not narrow to
278-- a single result, or nil followed by an error message. 280-- a single result, or nil followed by an error message.
279function find_suitable_rock(query) 281function search.find_suitable_rock(query)
280 assert(type(query) == "table") 282 assert(type(query) == "table")
281 283
282 local results = search_repos(query) 284 local results = search.search_repos(query)
283 local first = next(results) 285 local first = next(results)
284 if not first then 286 if not first then
285 return nil, "No results matching query were found." 287 return nil, "No results matching query were found."
@@ -300,7 +302,7 @@ end
300-- @param results table: A table where keys are package names and versions 302-- @param results table: A table where keys are package names and versions
301-- are tables matching version strings to an array of rocks servers. 303-- are tables matching version strings to an array of rocks servers.
302-- @param porcelain boolean or nil: A flag to force machine-friendly output. 304-- @param porcelain boolean or nil: A flag to force machine-friendly output.
303function print_results(results, porcelain) 305function search.print_results(results, porcelain)
304 assert(type(results) == "table") 306 assert(type(results) == "table")
305 assert(type(porcelain) == "boolean" or not porcelain) 307 assert(type(porcelain) == "boolean" or not porcelain)
306 308
@@ -355,14 +357,14 @@ end
355-- @param name string: A rock name 357-- @param name string: A rock name
356-- @param version string or nil: A version number may also be given. 358-- @param version string or nil: A version number may also be given.
357-- @return The result of the action function, or nil and an error message. 359-- @return The result of the action function, or nil and an error message.
358function act_on_src_or_rockspec(action, name, version, ...) 360function search.act_on_src_or_rockspec(action, name, version, ...)
359 assert(type(action) == "function") 361 assert(type(action) == "function")
360 assert(type(name) == "string") 362 assert(type(name) == "string")
361 assert(type(version) == "string" or not version) 363 assert(type(version) == "string" or not version)
362 364
363 local query = make_query(name, version) 365 local query = search.make_query(name, version)
364 query.arch = "src|rockspec" 366 query.arch = "src|rockspec"
365 local results, err = find_suitable_rock(query) 367 local results, err = search.find_suitable_rock(query)
366 if type(results) == "string" then 368 if type(results) == "string" then
367 return action(results, ...) 369 return action(results, ...)
368 else 370 else
@@ -375,7 +377,7 @@ end
375-- @param version string or nil: a version may also be passed. 377-- @param version string or nil: a version may also be passed.
376-- @return boolean or (nil, string): True if build was successful; nil and an 378-- @return boolean or (nil, string): True if build was successful; nil and an
377-- error message otherwise. 379-- error message otherwise.
378function run(...) 380function search.run(...)
379 local flags, name, version = util.parse_flags(...) 381 local flags, name, version = util.parse_flags(...)
380 382
381 if flags["all"] then 383 if flags["all"] then
@@ -386,19 +388,21 @@ function run(...)
386 return nil, "Enter name and version or use --all. "..util.see_help("search") 388 return nil, "Enter name and version or use --all. "..util.see_help("search")
387 end 389 end
388 390
389 local query = make_query(name:lower(), version) 391 local query = search.make_query(name:lower(), version)
390 query.exact_name = false 392 query.exact_name = false
391 local results, err = search_repos(query) 393 local results, err = search.search_repos(query)
392 local porcelain = flags["porcelain"] 394 local porcelain = flags["porcelain"]
393 util.title("Search results:", porcelain, "=") 395 util.title("Search results:", porcelain, "=")
394 local sources, binaries = split_source_and_binary_results(results) 396 local sources, binaries = split_source_and_binary_results(results)
395 if next(sources) and not flags["binary"] then 397 if next(sources) and not flags["binary"] then
396 util.title("Rockspecs and source rocks:", porcelain) 398 util.title("Rockspecs and source rocks:", porcelain)
397 print_results(sources, porcelain) 399 search.print_results(sources, porcelain)
398 end 400 end
399 if next(binaries) and not flags["source"] then 401 if next(binaries) and not flags["source"] then
400 util.title("Binary and pure-Lua rocks:", porcelain) 402 util.title("Binary and pure-Lua rocks:", porcelain)
401 print_results(binaries, porcelain) 403 search.print_results(binaries, porcelain)
402 end 404 end
403 return true 405 return true
404end 406end
407
408return search
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua
index 36225208..3243c0ce 100644
--- a/src/luarocks/show.lua
+++ b/src/luarocks/show.lua
@@ -1,6 +1,8 @@
1--- Module implementing the LuaRocks "show" command. 1--- Module implementing the LuaRocks "show" command.
2-- Shows information about an installed rock. 2-- Shows information about an installed rock.
3module("luarocks.show", package.seeall) 3--module("luarocks.show", package.seeall)
4local show = {}
5package.loaded["luarocks.show"] = show
4 6
5local search = require("luarocks.search") 7local search = require("luarocks.search")
6local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
@@ -9,9 +11,9 @@ local path = require("luarocks.path")
9local deps = require("luarocks.deps") 11local deps = require("luarocks.deps")
10local fetch = require("luarocks.fetch") 12local fetch = require("luarocks.fetch")
11local manif = require("luarocks.manif") 13local manif = require("luarocks.manif")
12help_summary = "Shows information about an installed rock." 14show.help_summary = "Shows information about an installed rock."
13 15
14help = [[ 16show.help = [[
15<argument> is an existing package name. 17<argument> is an existing package name.
16Without any flags, show all module information. 18Without any flags, show all module information.
17With these flags, return only the desired information: 19With these flags, return only the desired information:
@@ -53,7 +55,7 @@ local function format_text(text)
53 return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) 55 return (table.concat(paragraphs, "\n\n"):gsub("%s$", ""))
54end 56end
55 57
56function pick_installed_rock(name, version, tree) 58function show.pick_installed_rock(name, version, tree)
57 local results = {} 59 local results = {}
58 local query = search.make_query(name, version) 60 local query = search.make_query(name, version)
59 query.exact_name = true 61 query.exact_name = true
@@ -90,14 +92,14 @@ end
90-- @param name or nil: an existing package name. 92-- @param name or nil: an existing package name.
91-- @param version string or nil: a version may also be passed. 93-- @param version string or nil: a version may also be passed.
92-- @return boolean: True if succeeded, nil on errors. 94-- @return boolean: True if succeeded, nil on errors.
93function run(...) 95function show.run(...)
94 local flags, name, version = util.parse_flags(...) 96 local flags, name, version = util.parse_flags(...)
95 if not name then 97 if not name then
96 return nil, "Argument missing. "..util.see_help("show") 98 return nil, "Argument missing. "..util.see_help("show")
97 end 99 end
98 100
99 local repo, repo_url 101 local repo, repo_url
100 name, version, repo, repo_url = pick_installed_rock(name, version, flags["tree"]) 102 name, version, repo, repo_url = show.pick_installed_rock(name, version, flags["tree"])
101 if not name then 103 if not name then
102 return nil, version 104 return nil, version
103 end 105 end
@@ -151,3 +153,5 @@ function run(...)
151 return true 153 return true
152end 154end
153 155
156
157return show
diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua
index c518fc4d..8df3093d 100644
--- a/src/luarocks/tools/patch.lua
+++ b/src/luarocks/tools/patch.lua
@@ -6,14 +6,14 @@
6-- Code is heavilly based on the Python-based patch.py version 8.06-1 6-- Code is heavilly based on the Python-based patch.py version 8.06-1
7-- Copyright (c) 2008 rainforce.org, MIT License 7-- Copyright (c) 2008 rainforce.org, MIT License
8-- Project home: http://code.google.com/p/python-patch/ . 8-- Project home: http://code.google.com/p/python-patch/ .
9-- Version 0.1
9 10
10module("luarocks.tools.patch", package.seeall) 11--module("luarocks.tools.patch", package.seeall)
12local patch = {}
11 13
12local fs = require("luarocks.fs") 14local fs = require("luarocks.fs")
13local util = require("luarocks.util") 15local util = require("luarocks.util")
14 16
15local version = '0.1'
16
17local io = io 17local io = io
18local os = os 18local os = os
19local string = string 19local string = string
@@ -153,7 +153,7 @@ local function match_linerange(line)
153 return m1, m2, m3, m4 153 return m1, m2, m3, m4
154end 154end
155 155
156function read_patch(filename, data) 156function patch.read_patch(filename, data)
157 -- define possible file regions that will direct the parser flow 157 -- define possible file regions that will direct the parser flow
158 local state = 'header' 158 local state = 'header'
159 -- 'header' - comments before the patch body 159 -- 'header' - comments before the patch body
@@ -396,7 +396,6 @@ local function find_hunk(file, h, hno)
396 for i=0,#file do 396 for i=0,#file do
397 local found = true 397 local found = true
398 local location = lineno 398 local location = lineno
399 local total = #h.text - fuzz
400 for l, hline in ipairs(h.text) do 399 for l, hline in ipairs(h.text) do
401 if l > fuzz then 400 if l > fuzz then
402 -- todo: \ No newline at the end of file 401 -- todo: \ No newline at the end of file
@@ -447,9 +446,6 @@ local function load_file(filename)
447end 446end
448 447
449local function find_hunks(file, hunks) 448local function find_hunks(file, hunks)
450 local matched = true
451 local lineno = 1
452 local hno = nil
453 for hno, h in ipairs(hunks) do 449 for hno, h in ipairs(hunks) do
454 find_hunk(file, h, hno) 450 find_hunk(file, h, hno)
455 end 451 end
@@ -458,7 +454,6 @@ end
458local function check_patched(file, hunks) 454local function check_patched(file, hunks)
459 local matched = true 455 local matched = true
460 local lineno = 1 456 local lineno = 1
461 local hno = nil
462 local ok, err = pcall(function() 457 local ok, err = pcall(function()
463 if #file == 0 then 458 if #file == 0 then
464 error 'nomatch' 459 error 'nomatch'
@@ -564,15 +559,15 @@ local function strip_dirs(filename, strip)
564 return filename 559 return filename
565end 560end
566 561
567function apply_patch(patch, strip) 562function patch.apply_patch(the_patch, strip)
568 local all_ok = true 563 local all_ok = true
569 local total = #patch.source 564 local total = #the_patch.source
570 for fileno, filename in ipairs(patch.source) do 565 for fileno, filename in ipairs(the_patch.source) do
571 filename = strip_dirs(filename, strip) 566 filename = strip_dirs(filename, strip)
572 local continue 567 local continue
573 local f2patch = filename 568 local f2patch = filename
574 if not exists(f2patch) then 569 if not exists(f2patch) then
575 f2patch = strip_dirs(patch.target[fileno], strip) 570 f2patch = strip_dirs(the_patch.target[fileno], strip)
576 f2patch = fs.absolute_name(f2patch) 571 f2patch = fs.absolute_name(f2patch)
577 if not exists(f2patch) then --FIX:if f2patch nil 572 if not exists(f2patch) then --FIX:if f2patch nil
578 warning(format("source/target file does not exist\n--- %s\n+++ %s", 573 warning(format("source/target file does not exist\n--- %s\n+++ %s",
@@ -593,7 +588,7 @@ function apply_patch(patch, strip)
593 info(format("processing %d/%d:\t %s", fileno, total, filename)) 588 info(format("processing %d/%d:\t %s", fileno, total, filename))
594 589
595 -- validate before patching 590 -- validate before patching
596 local hunks = patch.hunks[fileno] 591 local hunks = the_patch.hunks[fileno]
597 local file = load_file(filename) 592 local file = load_file(filename)
598 local hunkno = 1 593 local hunkno = 1
599 local hunk = hunks[hunkno] 594 local hunk = hunks[hunkno]
@@ -705,3 +700,5 @@ function apply_patch(patch, strip)
705 -- todo: check for premature eof 700 -- todo: check for premature eof
706 return all_ok 701 return all_ok
707end 702end
703
704return patch
diff --git a/src/luarocks/tools/tar.lua b/src/luarocks/tools/tar.lua
index 0c68ab2f..03f7de3c 100644
--- a/src/luarocks/tools/tar.lua
+++ b/src/luarocks/tools/tar.lua
@@ -1,6 +1,7 @@
1 1
2--- A pure-Lua implementation of untar (unpacking .tar archives) 2--- A pure-Lua implementation of untar (unpacking .tar archives)
3module("luarocks.tools.tar", package.seeall) 3--module("luarocks.tools.tar", package.seeall)
4local tar = {}
4 5
5local fs = require("luarocks.fs") 6local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
@@ -82,7 +83,7 @@ local function read_header_block(block)
82 return header 83 return header
83end 84end
84 85
85function untar(filename, destdir) 86function tar.untar(filename, destdir)
86 assert(type(filename) == "string") 87 assert(type(filename) == "string")
87 assert(type(destdir) == "string") 88 assert(type(destdir) == "string")
88 89
@@ -144,3 +145,5 @@ function untar(filename, destdir)
144 end 145 end
145 return true 146 return true
146end 147end
148
149return tar
diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua
index 35428d91..40cc089a 100644
--- a/src/luarocks/tools/zip.lua
+++ b/src/luarocks/tools/zip.lua
@@ -1,7 +1,8 @@
1 1
2--- A Lua implementation of .zip file archiving (used for creating .rock files), 2--- A Lua implementation of .zip file archiving (used for creating .rock files),
3-- using only lua-zlib. 3-- using only lua-zlib.
4module("luarocks.tools.zip", package.seeall) 4--module("luarocks.tools.zip", package.seeall)
5local zip = {}
5 6
6local zlib = require("zlib") 7local zlib = require("zlib")
7local fs = require("luarocks.fs") 8local fs = require("luarocks.fs")
@@ -188,7 +189,7 @@ end
188--- Return a zip handle open for writing. 189--- Return a zip handle open for writing.
189-- @param name filename of the zipfile to be created. 190-- @param name filename of the zipfile to be created.
190-- @return a zip handle, or nil in case of error. 191-- @return a zip handle, or nil in case of error.
191function new_zipwriter(name) 192function zip.new_zipwriter(name)
192 193
193 local zw = {} 194 local zw = {}
194 195
@@ -214,8 +215,8 @@ end
214-- additional arguments. 215-- additional arguments.
215-- @return boolean or (boolean, string): true on success, 216-- @return boolean or (boolean, string): true on success,
216-- false and an error message on failure. 217-- false and an error message on failure.
217function zip(zipfile, ...) 218function zip.zip(zipfile, ...)
218 local zw = new_zipwriter(zipfile) 219 local zw = zip.new_zipwriter(zipfile)
219 if not zw then 220 if not zw then
220 return nil, "error opening "..zipfile 221 return nil, "error opening "..zipfile
221 end 222 end
@@ -243,3 +244,5 @@ function zip(zipfile, ...)
243 return ok, err 244 return ok, err
244end 245end
245 246
247
248return zip
diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua
index 1204c1d9..a78c4848 100644
--- a/src/luarocks/type_check.lua
+++ b/src/luarocks/type_check.lua
@@ -1,11 +1,13 @@
1--- Type-checking functions. 1--- Type-checking functions.
2-- Functions and definitions for doing a basic lint check on files 2-- Functions and definitions for doing a basic lint check on files
3-- loaded by LuaRocks. 3-- loaded by LuaRocks.
4module("luarocks.type_check", package.seeall) 4--module("luarocks.type_check", package.seeall)
5local type_check = {}
6package.loaded["luarocks.type_check"] = type_check
5 7
6local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
7 9
8rockspec_format = "1.0" 10type_check.rockspec_format = "1.0"
9 11
10local rockspec_types = { 12local rockspec_types = {
11 rockspec_format = "string", 13 rockspec_format = "string",
@@ -73,22 +75,22 @@ local rockspec_types = {
73 } 75 }
74} 76}
75 77
76rockspec_order = {"rockspec_format", "package", "version", 78type_check.rockspec_order = {"rockspec_format", "package", "version",
77 { "source", { "url", "tag", "branch", "md5" } }, 79 { "source", { "url", "tag", "branch", "md5" } },
78 { "description", {"summary", "detailed", "homepage", "license" } }, 80 { "description", {"summary", "detailed", "homepage", "license" } },
79 "supported_platforms", "dependencies", "external_dependencies", 81 "supported_platforms", "dependencies", "external_dependencies",
80 { "build", {"type", "modules", "copy_directories", "platforms"} }, 82 { "build", {"type", "modules", "copy_directories", "platforms"} },
81 "hooks"} 83 "hooks"}
82 84
83function load_extensions() 85function type_check.load_extensions()
84 rockspec_format = "1.1" 86 type_check.rockspec_format = "1.1"
85 rockspec_types.deploy = { 87 rockspec_types.deploy = {
86 wrap_bin_scripts = true, 88 wrap_bin_scripts = true,
87 } 89 }
88end 90end
89 91
90if cfg.use_extensions then 92if cfg.use_extensions then
91 load_extensions() 93 type_check.load_extensions()
92end 94end
93 95
94rockspec_types.build.platforms.ANY = rockspec_types.build 96rockspec_types.build.platforms.ANY = rockspec_types.build
@@ -269,11 +271,11 @@ end
269-- mismatches. 271-- mismatches.
270-- @return boolean or (nil, string): true if type checking 272-- @return boolean or (nil, string): true if type checking
271-- succeeded, or nil and an error message if it failed. 273-- succeeded, or nil and an error message if it failed.
272function type_check_rockspec(rockspec, globals) 274function type_check.type_check_rockspec(rockspec, globals)
273 assert(type(rockspec) == "table") 275 assert(type(rockspec) == "table")
274 if rockspec.rockspec_format then 276 if rockspec.rockspec_format then
275 -- relies on global state 277 -- relies on global state
276 load_extensions() 278 type_check.load_extensions()
277 end 279 end
278 local ok, err = check_undeclared_globals(globals, rockspec_types) 280 local ok, err = check_undeclared_globals(globals, rockspec_types)
279 if not ok then return nil, err end 281 if not ok then return nil, err end
@@ -286,9 +288,11 @@ end
286-- mismatches. 288-- mismatches.
287-- @return boolean or (nil, string): true if type checking 289-- @return boolean or (nil, string): true if type checking
288-- succeeded, or nil and an error message if it failed. 290-- succeeded, or nil and an error message if it failed.
289function type_check_manifest(manifest, globals) 291function type_check.type_check_manifest(manifest, globals)
290 assert(type(manifest) == "table") 292 assert(type(manifest) == "table")
291 local ok, err = check_undeclared_globals(globals, manifest_types) 293 local ok, err = check_undeclared_globals(globals, manifest_types)
292 if not ok then return nil, err end 294 if not ok then return nil, err end
293 return type_check_table(manifest, manifest_types, "") 295 return type_check_table(manifest, manifest_types, "")
294end 296end
297
298return type_check
diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua
index 95762a2c..9204e265 100644
--- a/src/luarocks/unpack.lua
+++ b/src/luarocks/unpack.lua
@@ -1,7 +1,9 @@
1 1
2--- Module implementing the LuaRocks "unpack" command. 2--- Module implementing the LuaRocks "unpack" command.
3-- Unpack the contents of a rock. 3-- Unpack the contents of a rock.
4module("luarocks.unpack", package.seeall) 4--module("luarocks.unpack", package.seeall)
5local unpack = {}
6package.loaded["luarocks.unpack"] = unpack
5 7
6local fetch = require("luarocks.fetch") 8local fetch = require("luarocks.fetch")
7local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
@@ -9,9 +11,9 @@ local util = require("luarocks.util")
9local build = require("luarocks.build") 11local build = require("luarocks.build")
10local dir = require("luarocks.dir") 12local dir = require("luarocks.dir")
11 13
12help_summary = "Unpack the contents of a rock." 14unpack.help_summary = "Unpack the contents of a rock."
13help_arguments = "[--force] {<rock>|<name> [<version>]}" 15unpack.help_arguments = "[--force] {<rock>|<name> [<version>]}"
14help = [[ 16unpack.help = [[
15Unpacks the contents of a rock in a newly created directory. 17Unpacks the contents of a rock in a newly created directory.
16Argument may be a rock file, or the name of a rock in a rocks server. 18Argument may be a rock file, or the name of a rock in a rocks server.
17In the latter case, the app version may be given as a second argument. 19In the latter case, the app version may be given as a second argument.
@@ -145,7 +147,7 @@ end
145-- version may also be passed. 147-- version may also be passed.
146-- @return boolean or (nil, string): true if successful or nil followed 148-- @return boolean or (nil, string): true if successful or nil followed
147-- by an error message. 149-- by an error message.
148function run(...) 150function unpack.run(...)
149 local flags, name, version = util.parse_flags(...) 151 local flags, name, version = util.parse_flags(...)
150 152
151 assert(type(version) == "string" or not version) 153 assert(type(version) == "string" or not version)
@@ -160,3 +162,5 @@ function run(...)
160 return search.act_on_src_or_rockspec(run_unpacker, name, version) 162 return search.act_on_src_or_rockspec(run_unpacker, name, version)
161 end 163 end
162end 164end
165
166return unpack
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 4b138516..7e34fe0e 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -4,11 +4,10 @@
4-- inside specific functions) to avoid interdependencies, 4-- inside specific functions) to avoid interdependencies,
5-- as this is used in the bootstrapping stage of luarocks.cfg. 5-- as this is used in the bootstrapping stage of luarocks.cfg.
6 6
7local global_env = _G 7--module("luarocks.util", package.seeall)
8local util = {}
8 9
9module("luarocks.util", package.seeall) 10local unpack = unpack or table.unpack
10
11local cfg = require("luarocks.cfg")
12 11
13local scheduled_functions = {} 12local scheduled_functions = {}
14local debug = require("debug") 13local debug = require("debug")
@@ -20,7 +19,7 @@ local debug = require("debug")
20-- @param ... arguments to be passed to function. 19-- @param ... arguments to be passed to function.
21-- @return table: A token representing the scheduled execution, 20-- @return table: A token representing the scheduled execution,
22-- which can be used to remove the item later from the list. 21-- which can be used to remove the item later from the list.
23function schedule_function(f, ...) 22function util.schedule_function(f, ...)
24 assert(type(f) == "function") 23 assert(type(f) == "function")
25 24
26 local item = { fn = f, args = {...} } 25 local item = { fn = f, args = {...} }
@@ -32,7 +31,7 @@ end
32-- This is useful for cancelling a rollback of a completed operation. 31-- This is useful for cancelling a rollback of a completed operation.
33-- @param item table: The token representing the scheduled function that was 32-- @param item table: The token representing the scheduled function that was
34-- returned from the schedule_function call. 33-- returned from the schedule_function call.
35function remove_scheduled_function(item) 34function util.remove_scheduled_function(item)
36 for k, v in pairs(scheduled_functions) do 35 for k, v in pairs(scheduled_functions) do
37 if v == item then 36 if v == item then
38 table.remove(scheduled_functions, k) 37 table.remove(scheduled_functions, k)
@@ -46,7 +45,7 @@ end
46-- corresponding cleanup functions. Calling this function will run 45-- corresponding cleanup functions. Calling this function will run
47-- these function, erasing temporaries. 46-- these function, erasing temporaries.
48-- Functions are executed in the inverse order they were scheduled. 47-- Functions are executed in the inverse order they were scheduled.
49function run_scheduled_functions() 48function util.run_scheduled_functions()
50 local fs = require("luarocks.fs") 49 local fs = require("luarocks.fs")
51 fs.change_dir_to_root() 50 fs.change_dir_to_root()
52 for i = #scheduled_functions, 1, -1 do 51 for i = #scheduled_functions, 1, -1 do
@@ -60,7 +59,7 @@ end
60-- so it does not include beginning- and end-of-string markers (^$) 59-- so it does not include beginning- and end-of-string markers (^$)
61-- @param s string: The input string 60-- @param s string: The input string
62-- @return string: The equivalent pattern 61-- @return string: The equivalent pattern
63function matchquote(s) 62function util.matchquote(s)
64 return (s:gsub("[?%-+*%[%].%%()$^]","%%%1")) 63 return (s:gsub("[?%-+*%[%].%%()$^]","%%%1"))
65end 64end
66 65
@@ -69,7 +68,7 @@ end
69-- For example, given "foo", "--tux=beep", "--bla", "bar", "--baz", 68-- For example, given "foo", "--tux=beep", "--bla", "bar", "--baz",
70-- it would return the following: 69-- it would return the following:
71-- {["bla"] = true, ["tux"] = "beep", ["baz"] = true}, "foo", "bar". 70-- {["bla"] = true, ["tux"] = "beep", ["baz"] = true}, "foo", "bar".
72function parse_flags(...) 71function util.parse_flags(...)
73 local args = {...} 72 local args = {...}
74 local flags = {} 73 local flags = {}
75 for i = #args, 1, -1 do 74 for i = #args, 1, -1 do
@@ -94,7 +93,7 @@ end
94-- in the flags table. If no flags are passed as varargs, the 93-- in the flags table. If no flags are passed as varargs, the
95-- entire flags table is forwarded. 94-- entire flags table is forwarded.
96-- @return string... A variable number of strings 95-- @return string... A variable number of strings
97function forward_flags(flags, ...) 96function util.forward_flags(flags, ...)
98 assert(type(flags) == "table") 97 assert(type(flags) == "table")
99 local out = {} 98 local out = {}
100 local filter = select('#', ...) 99 local filter = select('#', ...)
@@ -123,14 +122,14 @@ end
123-- @param dst Destination table, which will receive src's contents. 122-- @param dst Destination table, which will receive src's contents.
124-- @param src Table which provides new contents to dst. 123-- @param src Table which provides new contents to dst.
125-- @see platform_overrides 124-- @see platform_overrides
126function deep_merge(dst, src) 125function util.deep_merge(dst, src)
127 for k, v in pairs(src) do 126 for k, v in pairs(src) do
128 if type(v) == "table" then 127 if type(v) == "table" then
129 if not dst[k] then 128 if not dst[k] then
130 dst[k] = {} 129 dst[k] = {}
131 end 130 end
132 if type(dst[k]) == "table" then 131 if type(dst[k]) == "table" then
133 deep_merge(dst[k], v) 132 util.deep_merge(dst[k], v)
134 else 133 else
135 dst[k] = v 134 dst[k] = v
136 end 135 end
@@ -153,7 +152,7 @@ end
153-- tbl.x are preserved). 152-- tbl.x are preserved).
154-- @param tbl table or nil: Table which may contain a "platforms" field; 153-- @param tbl table or nil: Table which may contain a "platforms" field;
155-- if it doesn't (or if nil is passed), this function does nothing. 154-- if it doesn't (or if nil is passed), this function does nothing.
156function platform_overrides(tbl) 155function util.platform_overrides(tbl)
157 assert(type(tbl) == "table" or not tbl) 156 assert(type(tbl) == "table" or not tbl)
158 157
159 local cfg = require("luarocks.cfg") 158 local cfg = require("luarocks.cfg")
@@ -164,7 +163,7 @@ function platform_overrides(tbl)
164 for _, platform in ipairs(cfg.platforms) do 163 for _, platform in ipairs(cfg.platforms) do
165 local platform_tbl = tbl.platforms[platform] 164 local platform_tbl = tbl.platforms[platform]
166 if platform_tbl then 165 if platform_tbl then
167 deep_merge(tbl, platform_tbl) 166 util.deep_merge(tbl, platform_tbl)
168 end 167 end
169 end 168 end
170 end 169 end
@@ -196,15 +195,15 @@ end
196-- @param needed_set: a set where keys are the names of 195-- @param needed_set: a set where keys are the names of
197-- needed variables. 196-- needed variables.
198-- @param msg string: the warning message to display. 197-- @param msg string: the warning message to display.
199function warn_if_not_used(var_defs, needed_set, msg) 198function util.warn_if_not_used(var_defs, needed_set, msg)
200 needed_set = make_shallow_copy(needed_set) 199 needed_set = make_shallow_copy(needed_set)
201 for var,val in pairs(var_defs) do 200 for _, val in pairs(var_defs) do
202 for used in val:gmatch(var_format_pattern) do 201 for used in val:gmatch(var_format_pattern) do
203 needed_set[used] = nil 202 needed_set[used] = nil
204 end 203 end
205 end 204 end
206 for var,_ in pairs(needed_set) do 205 for var, _ in pairs(needed_set) do
207 warning(msg:format(var)) 206 util.warning(msg:format(var))
208 end 207 end
209end 208end
210 209
@@ -215,7 +214,7 @@ local function warn_failed_matches(line)
215 local any_failed = false 214 local any_failed = false
216 if line:match(var_format_pattern) then 215 if line:match(var_format_pattern) then
217 for unmatched in line:gmatch(var_format_pattern) do 216 for unmatched in line:gmatch(var_format_pattern) do
218 warning("unmatched variable " .. unmatched) 217 util.warning("unmatched variable " .. unmatched)
219 any_failed = true 218 any_failed = true
220 end 219 end
221 end 220 end
@@ -230,7 +229,7 @@ end
230-- @param tbl table: Table to have its string values modified. 229-- @param tbl table: Table to have its string values modified.
231-- @param vars table: Table containing string-string key-value pairs 230-- @param vars table: Table containing string-string key-value pairs
232-- representing variables to replace in the strings values of tbl. 231-- representing variables to replace in the strings values of tbl.
233function variable_substitutions(tbl, vars) 232function util.variable_substitutions(tbl, vars)
234 assert(type(tbl) == "table") 233 assert(type(tbl) == "table")
235 assert(type(vars) == "table") 234 assert(type(vars) == "table")
236 235
@@ -251,7 +250,7 @@ end
251--- Return an array of keys of a table. 250--- Return an array of keys of a table.
252-- @param tbl table: The input table. 251-- @param tbl table: The input table.
253-- @return table: The array of keys. 252-- @return table: The array of keys.
254function keys(tbl) 253function util.keys(tbl)
255 local ks = {} 254 local ks = {}
256 for k,_ in pairs(tbl) do 255 for k,_ in pairs(tbl) do
257 table.insert(ks, k) 256 table.insert(ks, k)
@@ -279,7 +278,7 @@ end
279-- to be used by table.sort when sorting keys. 278-- to be used by table.sort when sorting keys.
280-- @see sortedpairs 279-- @see sortedpairs
281local function sortedpairs_iterator(tbl, sort_function) 280local function sortedpairs_iterator(tbl, sort_function)
282 local ks = keys(tbl) 281 local ks = util.keys(tbl)
283 if not sort_function or type(sort_function) == "function" then 282 if not sort_function or type(sort_function) == "function" then
284 table.sort(ks, sort_function or default_sort) 283 table.sort(ks, sort_function or default_sort)
285 for _, k in ipairs(ks) do 284 for _, k in ipairs(ks) do
@@ -317,11 +316,11 @@ end
317-- is a string representing the field name, and the second element is a priority table 316-- is a string representing the field name, and the second element is a priority table
318-- for that key. 317-- for that key.
319-- @return function: the iterator function. 318-- @return function: the iterator function.
320function sortedpairs(tbl, sort_function) 319function util.sortedpairs(tbl, sort_function)
321 return coroutine.wrap(function() sortedpairs_iterator(tbl, sort_function) end) 320 return coroutine.wrap(function() sortedpairs_iterator(tbl, sort_function) end)
322end 321end
323 322
324function lua_versions() 323function util.lua_versions()
325 local versions = { "5.1", "5.2" } 324 local versions = { "5.1", "5.2" }
326 local i = 0 325 local i = 0
327 return function() 326 return function()
@@ -330,37 +329,37 @@ function lua_versions()
330 end 329 end
331end 330end
332 331
333function starts_with(s, prefix) 332function util.starts_with(s, prefix)
334 return s:sub(1,#prefix) == prefix 333 return s:sub(1,#prefix) == prefix
335end 334end
336 335
337--- Print a line to standard output 336--- Print a line to standard output
338function printout(...) 337function util.printout(...)
339 io.stdout:write(table.concat({...},"\t")) 338 io.stdout:write(table.concat({...},"\t"))
340 io.stdout:write("\n") 339 io.stdout:write("\n")
341end 340end
342 341
343--- Print a line to standard error 342--- Print a line to standard error
344function printerr(...) 343function util.printerr(...)
345 io.stderr:write(table.concat({...},"\t")) 344 io.stderr:write(table.concat({...},"\t"))
346 io.stderr:write("\n") 345 io.stderr:write("\n")
347end 346end
348 347
349--- Display a warning message. 348--- Display a warning message.
350-- @param msg string: the warning message 349-- @param msg string: the warning message
351function warning(msg) 350function util.warning(msg)
352 printerr("Warning: "..msg) 351 util.printerr("Warning: "..msg)
353end 352end
354 353
355function title(msg, porcelain, underline) 354function util.title(msg, porcelain, underline)
356 if porcelain then return end 355 if porcelain then return end
357 printout() 356 util.printout()
358 printout(msg) 357 util.printout(msg)
359 printout((underline or "-"):rep(#msg)) 358 util.printout((underline or "-"):rep(#msg))
360 printout() 359 util.printout()
361end 360end
362 361
363function this_program(default) 362function util.this_program(default)
364 local i = 1 363 local i = 1
365 local last, cur = default, default 364 local last, cur = default, default
366 while i do 365 while i do
@@ -373,7 +372,8 @@ function this_program(default)
373 return last:sub(2) 372 return last:sub(2)
374end 373end
375 374
376function deps_mode_help(program) 375function util.deps_mode_help(program)
376 local cfg = require("luarocks.cfg")
377 return [[ 377 return [[
378--deps-mode=<mode> How to handle dependencies. Four modes are supported: 378--deps-mode=<mode> How to handle dependencies. Four modes are supported:
379 * all - use all trees from the rocks_trees list 379 * all - use all trees from the rocks_trees list
@@ -386,18 +386,18 @@ function deps_mode_help(program)
386 The default mode may be set with the deps_mode entry 386 The default mode may be set with the deps_mode entry
387 in the configuration file. 387 in the configuration file.
388 The current default is "]]..cfg.deps_mode..[[". 388 The current default is "]]..cfg.deps_mode..[[".
389 Type ']]..this_program(program or "luarocks")..[[' with no arguments to see 389 Type ']]..util.this_program(program or "luarocks")..[[' with no arguments to see
390 your list of rocks trees. 390 your list of rocks trees.
391]] 391]]
392end 392end
393 393
394function see_help(command, program) 394function util.see_help(command, program)
395 return "See '"..this_program(program or "luarocks")..' help '..command.."'." 395 return "See '"..util.this_program(program or "luarocks")..' help '..command.."'."
396end 396end
397 397
398-- from http://lua-users.org/wiki/SplitJoin 398-- from http://lua-users.org/wiki/SplitJoin
399-- by PhilippeLhoste 399-- by PhilippeLhoste
400function split_string(str, delim, maxNb) 400function util.split_string(str, delim, maxNb)
401 -- Eliminate bad cases... 401 -- Eliminate bad cases...
402 if string.find(str, delim) == nil then 402 if string.find(str, delim) == nil then
403 return { str } 403 return { str }
@@ -426,10 +426,10 @@ end
426-- Example: given ("a;b;c;a;b;d", ";"), returns "a;b;c;d". 426-- Example: given ("a;b;c;a;b;d", ";"), returns "a;b;c;d".
427-- @param list string: A path string (from $PATH or package.path) 427-- @param list string: A path string (from $PATH or package.path)
428-- @param sep string: The separator 428-- @param sep string: The separator
429function remove_path_dupes(list, sep) 429function util.remove_path_dupes(list, sep)
430 assert(type(list) == "string") 430 assert(type(list) == "string")
431 assert(type(sep) == "string") 431 assert(type(sep) == "string")
432 local parts = split_string(list, sep) 432 local parts = util.split_string(list, sep)
433 local final, entries = {}, {} 433 local final, entries = {}, {}
434 for _, part in ipairs(parts) do 434 for _, part in ipairs(parts) do
435 if not entries[part] then 435 if not entries[part] then
@@ -457,7 +457,7 @@ end
457-- @param name string: is the name of the table (optional) 457-- @param name string: is the name of the table (optional)
458-- @param indent string: is a first indentation (optional). 458-- @param indent string: is a first indentation (optional).
459-- @return string: the pretty-printed table 459-- @return string: the pretty-printed table
460function show_table(t, name, indent) 460function util.show_table(t, name, indent)
461 local cart -- a container 461 local cart -- a container
462 local autoref -- for self references 462 local autoref -- for self references
463 463
@@ -523,7 +523,7 @@ function show_table(t, name, indent)
523 return cart .. autoref 523 return cart .. autoref
524end 524end
525 525
526function array_contains(tbl, value) 526function util.array_contains(tbl, value)
527 for _, v in ipairs(tbl) do 527 for _, v in ipairs(tbl) do
528 if v == value then 528 if v == value then
529 return true 529 return true
@@ -535,6 +535,8 @@ end
535-- Quote Lua string, analogous to fs.Q. 535-- Quote Lua string, analogous to fs.Q.
536-- @param s A string, such as "hello" 536-- @param s A string, such as "hello"
537-- @return string: A quoted string, such as '"hello"' 537-- @return string: A quoted string, such as '"hello"'
538function LQ(s) 538function util.LQ(s)
539 return ("%q"):format(s) 539 return ("%q"):format(s)
540end 540end
541
542return util
diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua
index 15c2c6b7..e6e09c33 100644
--- a/src/luarocks/validate.lua
+++ b/src/luarocks/validate.lua
@@ -1,6 +1,8 @@
1 1
2--- Sandboxed test of build/install of all packages in a repository (unfinished and disabled). 2--- Sandboxed test of build/install of all packages in a repository (unfinished and disabled).
3module("luarocks.validate", package.seeall) 3--module("luarocks.validate", package.seeall)
4local validate = {}
5package.loaded["luarocks.validate"] = validate
4 6
5local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
@@ -10,9 +12,9 @@ local build = require("luarocks.build")
10local install = require("luarocks.install") 12local install = require("luarocks.install")
11local util = require("luarocks.util") 13local util = require("luarocks.util")
12 14
13help_summary = "Sandboxed test of build/install of all packages in a repository." 15validate.help_summary = "Sandboxed test of build/install of all packages in a repository."
14 16
15help = [[ 17validate.help = [[
16<argument>, if given, is a local repository pathname. 18<argument>, if given, is a local repository pathname.
17]] 19]]
18 20
@@ -73,7 +75,12 @@ local function validate_rock(file)
73 return ok, err, errcode 75 return ok, err, errcode
74end 76end
75 77
76local function validate(repo, flags) 78function validate.run(...)
79 local flags, repo = util.parse_flags(...)
80 repo = repo or cfg.rocks_dir
81
82 util.printout("Verifying contents of "..repo)
83
77 local results = { 84 local results = {
78 ok = {} 85 ok = {}
79 } 86 }
@@ -149,12 +156,5 @@ local function validate(repo, flags)
149 return true 156 return true
150end 157end
151 158
152function run(...)
153 local flags, repo = util.parse_flags(...)
154 repo = repo or cfg.rocks_dir
155
156 util.printout("Verifying contents of "..repo)
157
158 return validate(repo, flags)
159end
160 159
160return validate
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua
index 9cd8f892..a194201d 100644
--- a/src/luarocks/write_rockspec.lua
+++ b/src/luarocks/write_rockspec.lua
@@ -1,5 +1,7 @@
1 1
2module("luarocks.write_rockspec", package.seeall) 2--module("luarocks.write_rockspec", package.seeall)
3local write_rockspec = {}
4package.loaded["luarocks.write_rockspec"] = write_rockspec
3 5
4local dir = require("luarocks.dir") 6local dir = require("luarocks.dir")
5local fetch = require("luarocks.fetch") 7local fetch = require("luarocks.fetch")
@@ -9,9 +11,9 @@ local persist = require("luarocks.persist")
9local type_check = require("luarocks.type_check") 11local type_check = require("luarocks.type_check")
10local util = require("luarocks.util") 12local util = require("luarocks.util")
11 13
12help_summary = "Write a template for a rockspec file." 14write_rockspec.help_summary = "Write a template for a rockspec file."
13help_arguments = "[--output=<file> ...] [<name>] [<version>] {<url>|<path>}" 15write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] {<url>|<path>}"
14help = [[ 16write_rockspec.help = [[
15This command writes an initial version of a rockspec file, 17This command writes an initial version of a rockspec file,
16based on an URL or a local path. You may use a relative path such as '.'. 18based on an URL or a local path. You may use a relative path such as '.'.
17If a local path is given, name and version arguments are mandatory. 19If a local path is given, name and version arguments are mandatory.
@@ -188,7 +190,7 @@ local function rockspec_cleanup(rockspec)
188 rockspec.name = nil 190 rockspec.name = nil
189end 191end
190 192
191function run(...) 193function write_rockspec.run(...)
192 local flags, name, version, url_or_dir = util.parse_flags(...) 194 local flags, name, version, url_or_dir = util.parse_flags(...)
193 195
194 if not name then 196 if not name then
@@ -328,3 +330,5 @@ function run(...)
328 330
329 return true 331 return true
330end 332end
333
334return write_rockspec