aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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/cmake.lua6
-rw-r--r--src/luarocks/cache.lua16
-rw-r--r--src/luarocks/cfg.lua120
-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/fs.lua14
-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.lua48
-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.lua16
-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.lua10
-rw-r--r--src/luarocks/type_check.lua22
-rw-r--r--src/luarocks/unpack.lua14
-rw-r--r--src/luarocks/validate.lua24
-rw-r--r--src/luarocks/write_rockspec.lua14
36 files changed, 512 insertions, 388 deletions
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/cmake.lua b/src/luarocks/build/cmake.lua
index 83ec20f3..ed2af3ff 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -29,9 +29,9 @@ function cmake.run(rockspec)
29 29
30 -- If inline cmake is present create CMakeLists.txt from it. 30 -- If inline cmake is present create CMakeLists.txt from it.
31 if type(build.cmake) == "string" then 31 if type(build.cmake) == "string" then
32 local cmake = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) 32 local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w"))
33 cmake:write(build.cmake) 33 cmake_handler:write(build.cmake)
34 cmake:close() 34 cmake_handler:close()
35 end 35 end
36 36
37 37
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/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/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/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..1fa15c5e 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -9,19 +9,21 @@ local global_env = _G
9local package, require, ipairs, pairs, table, type, next, unpack, tostring, error = 9local package, require, ipairs, pairs, table, type, next, unpack, tostring, error =
10 package, require, ipairs, pairs, table, type, next, unpack, tostring, error 10 package, require, ipairs, pairs, table, type, next, unpack, tostring, error
11 11
12module("luarocks.loader") 12--module("luarocks.loader")
13local loader = {}
14package.loaded["luarocks.loader"] = loader
13 15
14local path = require("luarocks.path") 16local path = require("luarocks.path")
15local manif_core = require("luarocks.manif_core") 17local manif_core = require("luarocks.manif_core")
16local deps = require("luarocks.deps") 18local deps = require("luarocks.deps")
17local cfg = require("luarocks.cfg") 19local cfg = require("luarocks.cfg")
18 20
19context = {} 21loader.context = {}
20 22
21-- Contains a table when rocks trees are loaded, 23-- Contains a table when rocks trees are loaded,
22-- or 'false' to indicate rocks trees failed to load. 24-- or 'false' to indicate rocks trees failed to load.
23-- 'nil' indicates rocks trees were not attempted to be loaded yet. 25-- 'nil' indicates rocks trees were not attempted to be loaded yet.
24rocks_trees = nil 26loader.rocks_trees = nil
25 27
26local function load_rocks_trees() 28local function load_rocks_trees()
27 local any_ok = false 29 local any_ok = false
@@ -34,10 +36,10 @@ local function load_rocks_trees()
34 end 36 end
35 end 37 end
36 if not any_ok then 38 if not any_ok then
37 rocks_trees = false 39 loader.rocks_trees = false
38 return false 40 return false
39 end 41 end
40 rocks_trees = trees 42 loader.rocks_trees = trees
41 return true 43 return true
42end 44end
43 45
@@ -45,20 +47,20 @@ end
45-- chain for loading modules. 47-- chain for loading modules.
46-- @param name string: The name of an installed rock. 48-- @param name string: The name of an installed rock.
47-- @param version string: The version of the rock, in string format 49-- @param version string: The version of the rock, in string format
48function add_context(name, version) 50function loader.add_context(name, version)
49 -- assert(type(name) == "string") 51 -- assert(type(name) == "string")
50 -- assert(type(version) == "string") 52 -- assert(type(version) == "string")
51 53
52 if context[name] then 54 if loader.context[name] then
53 return 55 return
54 end 56 end
55 context[name] = version 57 loader.context[name] = version
56 58
57 if not rocks_trees and not load_rocks_trees() then 59 if not loader.rocks_trees and not load_rocks_trees() then
58 return nil 60 return nil
59 end 61 end
60 62
61 for _, tree in ipairs(rocks_trees) do 63 for _, tree in ipairs(loader.rocks_trees) do
62 local manifest = tree.manifest 64 local manifest = tree.manifest
63 65
64 local pkgdeps 66 local pkgdeps
@@ -71,12 +73,12 @@ function add_context(name, version)
71 for _, dep in ipairs(pkgdeps) do 73 for _, dep in ipairs(pkgdeps) do
72 local pkg, constraints = dep.name, dep.constraints 74 local pkg, constraints = dep.name, dep.constraints
73 75
74 for _, tree in ipairs(rocks_trees) do 76 for _, tree in ipairs(loader.rocks_trees) do
75 local entries = tree.manifest.repository[pkg] 77 local entries = tree.manifest.repository[pkg]
76 if entries then 78 if entries then
77 for version, pkgs in pairs(entries) do 79 for version, pkgs in pairs(entries) do
78 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then 80 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then
79 add_context(pkg, version) 81 loader.add_context(pkg, version)
80 end 82 end
81 end 83 end
82 end 84 end
@@ -107,9 +109,9 @@ end
107-- @return table or (nil, string): The module table as returned by some other loader, 109-- @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. 110-- 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) 111local function call_other_loaders(module, name, version, module_name)
110 for i, loader in ipairs(package.loaders) do 112 for i, a_loader in ipairs(package.loaders) do
111 if loader ~= luarocks_loader then 113 if a_loader ~= loader.luarocks_loader then
112 local results = { loader(module_name) } 114 local results = { a_loader(module_name) }
113 if type(results[1]) == "function" then 115 if type(results[1]) == "function" then
114 return unpack(results) 116 return unpack(results)
115 end 117 end
@@ -133,12 +135,12 @@ local function select_module(module, filter_module_name)
133 --assert(type(module) == "string") 135 --assert(type(module) == "string")
134 --assert(type(filter_module_name) == "function") 136 --assert(type(filter_module_name) == "function")
135 137
136 if not rocks_trees and not load_rocks_trees() then 138 if not loader.rocks_trees and not load_rocks_trees() then
137 return nil 139 return nil
138 end 140 end
139 141
140 local providers = {} 142 local providers = {}
141 for _, tree in ipairs(rocks_trees) do 143 for _, tree in ipairs(loader.rocks_trees) do
142 local entries = tree.manifest.modules[module] 144 local entries = tree.manifest.modules[module]
143 if entries then 145 if entries then
144 for i, entry in ipairs(entries) do 146 for i, entry in ipairs(entries) do
@@ -148,7 +150,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)..")") 150 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")")
149 end 151 end
150 module_name = filter_module_name(module_name, name, version, tree.tree, i) 152 module_name = filter_module_name(module_name, name, version, tree.tree, i)
151 if context[name] == version then 153 if loader.context[name] == version then
152 return name, version, module_name 154 return name, version, module_name
153 end 155 end
154 version = deps.parse_version(version) 156 version = deps.parse_version(version)
@@ -184,7 +186,7 @@ end
184--- Return the pathname of the file that would be loaded for a module. 186--- Return the pathname of the file that would be loaded for a module.
185-- @param module string: module name (eg. "socket.core") 187-- @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") 188-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
187function which(module) 189function loader.which(module)
188 local name, version, module_name = select_module(module, path.which_i) 190 local name, version, module_name = select_module(module, path.which_i)
189 return module_name 191 return module_name
190end 192end
@@ -198,14 +200,16 @@ end
198-- @return table: The module table (typically), like in plain 200-- @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> 201-- 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. 202-- in the Lua reference manual for details.
201function luarocks_loader(module) 203function loader.luarocks_loader(module)
202 local name, version, module_name = pick_module(module) 204 local name, version, module_name = pick_module(module)
203 if not name then 205 if not name then
204 return "No LuaRocks module found for "..module 206 return "No LuaRocks module found for "..module
205 else 207 else
206 add_context(name, version) 208 loader.add_context(name, version)
207 return call_other_loaders(module, name, version, module_name) 209 return call_other_loaders(module, name, version, module_name)
208 end 210 end
209end 211end
210 212
211table.insert(global_env.package.loaders, 1, luarocks_loader) 213table.insert(global_env.package.loaders, 1, loader.luarocks_loader)
214
215return 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 c14200df..d160d2db 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..c23cf66a 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -1,7 +1,9 @@
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
5 7
6local path = require("luarocks.path") 8local path = require("luarocks.path")
7local repos = require("luarocks.repos") 9local repos = require("luarocks.repos")
@@ -13,9 +15,9 @@ local dir = require("luarocks.dir")
13local manif = require("luarocks.manif") 15local manif = require("luarocks.manif")
14local search = require("luarocks.search") 16local search = require("luarocks.search")
15 17
16help_summary = "Create a rock, packing sources or binaries." 18pack.help_summary = "Create a rock, packing sources or binaries."
17help_arguments = "{<rockspec>|<name> [<version>]}" 19pack.help_arguments = "{<rockspec>|<name> [<version>]}"
18help = [[ 20pack.help = [[
19Argument may be a rockspec file, for creating a source rock, 21Argument may be a rockspec file, for creating a source rock,
20or the name of an installed package, for creating a binary rock. 22or the name of an installed package, for creating a binary rock.
21In the latter case, the app version may be given as a second 23In the latter case, the app version may be given as a second
@@ -154,7 +156,7 @@ local function do_pack_binary_rock(name, version)
154 return rock_file 156 return rock_file
155end 157end
156 158
157function pack_binary_rock(name, version, cmd, ...) 159function pack.pack_binary_rock(name, version, cmd, ...)
158 160
159 -- The --pack-binary-rock option for "luarocks build" basically performs 161 -- The --pack-binary-rock option for "luarocks build" basically performs
160 -- "luarocks build" on a temporary tree and then "luarocks pack". The 162 -- "luarocks build" on a temporary tree and then "luarocks pack". The
@@ -188,7 +190,7 @@ end
188-- version may also be passed. 190-- version may also be passed.
189-- @return boolean or (nil, string): true if successful or nil followed 191-- @return boolean or (nil, string): true if successful or nil followed
190-- by an error message. 192-- by an error message.
191function run(...) 193function pack.run(...)
192 local flags, arg, version = util.parse_flags(...) 194 local flags, arg, version = util.parse_flags(...)
193 assert(type(version) == "string" or not version) 195 assert(type(version) == "string" or not version)
194 if type(arg) ~= "string" then 196 if type(arg) ~= "string" then
@@ -208,3 +210,5 @@ function run(...)
208 return true 210 return true
209 end 211 end
210end 212end
213
214return pack
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 4479e642..8df3093d 100644
--- a/src/luarocks/tools/patch.lua
+++ b/src/luarocks/tools/patch.lua
@@ -559,15 +559,15 @@ local function strip_dirs(filename, strip)
559 return filename 559 return filename
560end 560end
561 561
562function patch.apply_patch(patch, strip) 562function patch.apply_patch(the_patch, strip)
563 local all_ok = true 563 local all_ok = true
564 local total = #patch.source 564 local total = #the_patch.source
565 for fileno, filename in ipairs(patch.source) do 565 for fileno, filename in ipairs(the_patch.source) do
566 filename = strip_dirs(filename, strip) 566 filename = strip_dirs(filename, strip)
567 local continue 567 local continue
568 local f2patch = filename 568 local f2patch = filename
569 if not exists(f2patch) then 569 if not exists(f2patch) then
570 f2patch = strip_dirs(patch.target[fileno], strip) 570 f2patch = strip_dirs(the_patch.target[fileno], strip)
571 f2patch = fs.absolute_name(f2patch) 571 f2patch = fs.absolute_name(f2patch)
572 if not exists(f2patch) then --FIX:if f2patch nil 572 if not exists(f2patch) then --FIX:if f2patch nil
573 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",
@@ -588,7 +588,7 @@ function patch.apply_patch(patch, strip)
588 info(format("processing %d/%d:\t %s", fileno, total, filename)) 588 info(format("processing %d/%d:\t %s", fileno, total, filename))
589 589
590 -- validate before patching 590 -- validate before patching
591 local hunks = patch.hunks[fileno] 591 local hunks = the_patch.hunks[fileno]
592 local file = load_file(filename) 592 local file = load_file(filename)
593 local hunkno = 1 593 local hunkno = 1
594 local hunk = hunks[hunkno] 594 local hunk = hunks[hunkno]
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/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