aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.setup.inc2
-rwxr-xr-xconfigure8
-rw-r--r--install.bat4
-rw-r--r--src/luarocks/build/builtin.lua15
-rw-r--r--src/luarocks/cache.lua15
-rw-r--r--src/luarocks/cfg.lua33
-rw-r--r--src/luarocks/command_line.lua1
-rw-r--r--src/luarocks/deps.lua22
-rw-r--r--src/luarocks/download.lua40
-rw-r--r--src/luarocks/fetch.lua2
-rw-r--r--src/luarocks/fetch/git_ssh.lua32
-rw-r--r--src/luarocks/fs/lua.lua8
-rw-r--r--src/luarocks/fs/unix/tools.lua12
-rw-r--r--src/luarocks/help.lua2
-rw-r--r--src/luarocks/install.lua16
-rw-r--r--src/luarocks/loader.lua36
-rw-r--r--src/luarocks/make.lua67
-rw-r--r--src/luarocks/new_version.lua84
-rw-r--r--src/luarocks/path.lua19
-rw-r--r--src/luarocks/search.lua55
-rw-r--r--src/luarocks/show.lua34
-rw-r--r--src/luarocks/tools/zip.lua56
-rw-r--r--src/luarocks/upload/api.lua21
-rw-r--r--test/testing.bat2
-rw-r--r--test/testing.lua6
-rwxr-xr-xtest/testing.sh67
26 files changed, 434 insertions, 225 deletions
diff --git a/Makefile.setup.inc b/Makefile.setup.inc
index c228e78c..0a049bc4 100644
--- a/Makefile.setup.inc
+++ b/Makefile.setup.inc
@@ -16,5 +16,5 @@ help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \
16admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \ 16admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \
17purge.lua path.lua path_cmd.lua write_rockspec.lua doc.lua upload.lua \ 17purge.lua path.lua path_cmd.lua write_rockspec.lua doc.lua upload.lua \
18upload/api.lua upload/multipart.lua fetch/git_http.lua fetch/hg_http.lua \ 18upload/api.lua upload/multipart.lua fetch/git_http.lua fetch/hg_http.lua \
19fetch/hg_https.lua fetch/hg_ssh.lua fetch/git_https.lua 19fetch/hg_https.lua fetch/hg_ssh.lua fetch/git_https.lua fetch/git_ssh.lua
20 20
diff --git a/configure b/configure
index 75ba4039..665d52bc 100755
--- a/configure
+++ b/configure
@@ -101,7 +101,7 @@ find_helper() {
101 fi 101 fi
102 shift 102 shift
103 done 103 done
104 echo "Could not find a $explanation. Tried: $tried." 104 echo "Could not find $explanation. Tried: $tried."
105 die "Make sure one of them is installed and available in your PATH." 105 die "Make sure one of them is installed and available in your PATH."
106} 106}
107 107
@@ -362,16 +362,18 @@ fi
362 362
363if [ "$LUAROCKS_DOWNLOADER_SET" != "yes" ] 363if [ "$LUAROCKS_DOWNLOADER_SET" != "yes" ]
364then 364then
365 find_helper "downloader helper program" curl wget fetch 365 find_helper "a downloader helper program" curl wget fetch
366 LUAROCKS_DOWNLOADER=$HELPER 366 LUAROCKS_DOWNLOADER=$HELPER
367fi 367fi
368 368
369if [ "$LUAROCKS_MD5CHECKER_SET" != "yes" ] 369if [ "$LUAROCKS_MD5CHECKER_SET" != "yes" ]
370then 370then
371 find_helper "MD5 checksum calculator" md5sum openssl md5 371 find_helper "a MD5 checksum calculator" md5sum openssl md5
372 LUAROCKS_MD5CHECKER=$HELPER 372 LUAROCKS_MD5CHECKER=$HELPER
373fi 373fi
374 374
375find_helper "an 'unzip' program" unzip
376
375echo_n "Configuring for system... " 377echo_n "Configuring for system... "
376if uname -s 378if uname -s
377then 379then
diff --git a/install.bat b/install.bat
index 8e3df4d9..053fdfd6 100644
--- a/install.bat
+++ b/install.bat
@@ -427,7 +427,7 @@ end
427-- get a string value from windows registry. 427-- get a string value from windows registry.
428local function get_registry(key, value) 428local function get_registry(key, value)
429 local keys = {key} 429 local keys = {key}
430 local key64, replaced = key:gsub("(%u+\\Software\\)", "\1Wow6432Node\\", 1) 430 local key64, replaced = key:gsub("(%u+\\Software\\)", "%1Wow6432Node\\", 1)
431 431
432 if replaced == 1 then 432 if replaced == 1 then
433 keys = {key64, key} 433 keys = {key64, key}
@@ -983,7 +983,7 @@ if FORCE_CONFIG then
983 f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") 983 f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n")
984end 984end
985if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults 985if vars.SYSCONFFORCE then -- only write this value when explcitly given, otherwise rely on defaults
986 f:write("site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]\n") 986 f:write(S("site_config.LUAROCKS_SYSCONFIG=[[$CONFIG_FILE]]\n"))
987end 987end
988f:write("return site_config\n") 988f:write("return site_config\n")
989f:close() 989f:close()
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index 00fd09ea..afd05954 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -174,7 +174,7 @@ function builtin.run(rockspec)
174 --TODO EXEWRAPPER 174 --TODO EXEWRAPPER
175 end 175 end
176 176
177 local ok = true 177 local ok, err
178 local built_modules = {} 178 local built_modules = {}
179 local luadir = path.lua_dir(rockspec.name, rockspec.version) 179 local luadir = path.lua_dir(rockspec.name, rockspec.version)
180 local libdir = path.lib_dir(rockspec.name, rockspec.version) 180 local libdir = path.lib_dir(rockspec.name, rockspec.version)
@@ -202,7 +202,7 @@ function builtin.run(rockspec)
202 for name, info in pairs(build.modules) do 202 for name, info in pairs(build.modules) do
203 local moddir = path.module_to_path(name) 203 local moddir = path.module_to_path(name)
204 if type(info) == "string" then 204 if type(info) == "string" then
205 local ext = info:match(".([^.]+)$") 205 local ext = info:match("%.([^.]+)$")
206 if ext == "lua" then 206 if ext == "lua" then
207 local filename = dir.base_name(info) 207 local filename = dir.base_name(info)
208 if info:match("init%.lua$") and not name:match("%.init$") then 208 if info:match("init%.lua$") and not name:match("%.init$") then
@@ -226,7 +226,7 @@ function builtin.run(rockspec)
226 if info[1] then sources = info end 226 if info[1] then sources = info end
227 if type(sources) == "string" then sources = {sources} end 227 if type(sources) == "string" then sources = {sources} end
228 for _, source in ipairs(sources) do 228 for _, source in ipairs(sources) do
229 local object = source:gsub(".[^.]*$", "."..cfg.obj_extension) 229 local object = source:gsub("%.[^.]*$", "."..cfg.obj_extension)
230 if not object then 230 if not object then
231 object = source.."."..cfg.obj_extension 231 object = source.."."..cfg.obj_extension
232 end 232 end
@@ -236,11 +236,10 @@ function builtin.run(rockspec)
236 end 236 end
237 table.insert(objects, object) 237 table.insert(objects, object)
238 end 238 end
239 if not ok then break end
240 local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension) 239 local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension)
241 if moddir ~= "" then 240 if moddir ~= "" then
242 module_name = dir.path(moddir, module_name) 241 module_name = dir.path(moddir, module_name)
243 local ok, err = fs.make_dir(moddir) 242 ok, err = fs.make_dir(moddir)
244 if not ok then return nil, err end 243 if not ok then return nil, err end
245 end 244 end
246 built_modules[module_name] = dir.path(libdir, module_name) 245 built_modules[module_name] = dir.path(libdir, module_name)
@@ -252,13 +251,13 @@ function builtin.run(rockspec)
252 end 251 end
253 for name, dest in pairs(built_modules) do 252 for name, dest in pairs(built_modules) do
254 fs.make_dir(dir.dir_name(dest)) 253 fs.make_dir(dir.dir_name(dest))
255 ok = fs.copy(name, dest) 254 ok, err = fs.copy(name, dest)
256 if not ok then 255 if not ok then
257 return nil, "Failed installing "..name.." in "..dest 256 return nil, "Failed installing "..name.." in "..dest..": "..err
258 end 257 end
259 end 258 end
260 if fs.is_dir("lua") then 259 if fs.is_dir("lua") then
261 local ok, err = fs.copy_contents("lua", luadir) 260 ok, err = fs.copy_contents("lua", luadir)
262 if not ok then 261 if not ok then
263 return nil, "Failed copying contents of 'lua' directory: "..err 262 return nil, "Failed copying contents of 'lua' directory: "..err
264 end 263 end
diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua
index dbea8405..fb6344d8 100644
--- a/src/luarocks/cache.lua
+++ b/src/luarocks/cache.lua
@@ -45,25 +45,12 @@ function cache.split_server_url(server, url, user, password)
45 user = credentials 45 user = credentials
46 end 46 end
47 end 47 end
48 local local_cache 48 local local_cache = cfg.local_cache .. "/" .. server
49 if cfg.local_cache then
50 local_cache = cfg.local_cache .. "/" .. server
51 end
52 return local_cache, protocol, server_path, user, password 49 return local_cache, protocol, server_path, user, password
53end 50end
54 51
55function cache.refresh_local_cache(server, url, user, password) 52function cache.refresh_local_cache(server, url, user, password)
56 local local_cache, protocol, server_path, user, password = cache.split_server_url(server, url, user, password) 53 local local_cache, protocol, server_path, user, password = cache.split_server_url(server, url, user, password)
57
58 local ok, err = fs.make_dir(cfg.local_cache)
59 if not ok then return nil, err end
60
61 local tmp_cache = false
62 if not local_cache then
63 local err
64 local_cache, err = fs.make_temp_dir("local_cache")
65 tmp_cache = true
66 end
67 local ok, err = fs.make_dir(local_cache) 54 local ok, err = fs.make_dir(local_cache)
68 if not ok then 55 if not ok then
69 return nil, "Failed creating local cache dir: "..err 56 return nil, "Failed creating local cache dir: "..err
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index af30417c..60239d3f 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -113,6 +113,10 @@ elseif system == "SunOS" then
113elseif system and system:match("^CYGWIN") then 113elseif system and system:match("^CYGWIN") then
114 cfg.platforms.unix = true 114 cfg.platforms.unix = true
115 cfg.platforms.cygwin = true 115 cfg.platforms.cygwin = true
116elseif system and system:match("^MSYS") then
117 cfg.platforms.unix = true
118 cfg.platforms.msys = true
119 cfg.platforms.cygwin = true
116elseif system and system:match("^Windows") then 120elseif system and system:match("^Windows") then
117 cfg.platforms.windows = true 121 cfg.platforms.windows = true
118 cfg.platforms.win32 = true 122 cfg.platforms.win32 = true
@@ -120,6 +124,9 @@ elseif system and system:match("^MINGW") then
120 cfg.platforms.windows = true 124 cfg.platforms.windows = true
121 cfg.platforms.mingw32 = true 125 cfg.platforms.mingw32 = true
122 cfg.platforms.win32 = true 126 cfg.platforms.win32 = true
127elseif system == "Haiku" then
128 cfg.platforms.unix = true
129 cfg.platforms.haiku = true
123else 130else
124 cfg.platforms.unix = true 131 cfg.platforms.unix = true
125 -- Fall back to Unix in unknown systems. 132 -- Fall back to Unix in unknown systems.
@@ -137,11 +144,12 @@ local platform_order = {
137 linux = 7, 144 linux = 7,
138 macosx = 8, 145 macosx = 8,
139 cygwin = 9, 146 cygwin = 9,
147 msys = 10,
148 haiku = 11,
140 -- Windows 149 -- Windows
141 win32 = 10, 150 win32 = 12,
142 mingw32 = 11, 151 mingw32 = 13,
143 windows = 12 } 152 windows = 14 }
144
145 153
146-- Path configuration: 154-- Path configuration:
147local sys_config_file, home_config_file 155local sys_config_file, home_config_file
@@ -519,6 +527,23 @@ if cfg.platforms.cygwin then
519 defaults.variables.LIBFLAG = "-shared" 527 defaults.variables.LIBFLAG = "-shared"
520end 528end
521 529
530if cfg.platforms.msys then
531 -- msys is basically cygwin made out of mingw, meaning the subsytem is unixish
532 -- enough, yet we can freely mix with native win32
533 defaults.external_deps_patterns = {
534 bin = { "?.exe", "?.bat", "?" },
535 lib = { "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a",
536 "lib?.a", "lib?.dll", "?.dll", "?.lib" },
537 include = { "?.h" }
538 }
539 defaults.runtime_external_deps_patterns = {
540 bin = { "?.exe", "?.bat" },
541 lib = { "lib?.so", "?.dll", "lib?.dll" },
542 include = { "?.h" }
543 }
544end
545
546
522if cfg.platforms.bsd then 547if cfg.platforms.bsd then
523 defaults.variables.MAKE = "gmake" 548 defaults.variables.MAKE = "gmake"
524 defaults.variables.STATFLAG = "-f '%OLp'" 549 defaults.variables.STATFLAG = "-f '%OLp'"
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index e1c9f492..a016fc72 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -144,7 +144,6 @@ function command_line.run_command(...)
144 end 144 end
145 end 145 end
146 if not named then 146 if not named then
147 local fs = require("luarocks.fs")
148 local root_dir = fs.absolute_name(flags["tree"]) 147 local root_dir = fs.absolute_name(flags["tree"])
149 replace_tree(flags, args, root_dir) 148 replace_tree(flags, args, root_dir)
150 end 149 end
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 96f6a005..b9eda6e6 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -256,12 +256,16 @@ end
256function deps.show_dep(dep, internal) 256function deps.show_dep(dep, internal)
257 assert(type(dep) == "table") 257 assert(type(dep) == "table")
258 assert(type(internal) == "boolean" or not internal) 258 assert(type(internal) == "boolean" or not internal)
259 259
260 local pretty = {} 260 if #dep.constraints > 0 then
261 for _, c in ipairs(dep.constraints) do 261 local pretty = {}
262 table.insert(pretty, c.op .. " " .. deps.show_version(c.version, internal)) 262 for _, c in ipairs(dep.constraints) do
263 table.insert(pretty, c.op .. " " .. deps.show_version(c.version, internal))
264 end
265 return dep.name.." "..table.concat(pretty, ", ")
266 else
267 return dep.name
263 end 268 end
264 return dep.name.." "..table.concat(pretty, ", ")
265end 269end
266 270
267--- A more lenient check for equivalence between versions. 271--- A more lenient check for equivalence between versions.
@@ -493,13 +497,13 @@ function deps.fulfill_dependencies(rockspec, deps_mode)
493 for _, dep in pairs(missing) do 497 for _, dep in pairs(missing) do
494 -- Double-check in case dependency was filled during recursion. 498 -- Double-check in case dependency was filled during recursion.
495 if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then 499 if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then
496 local rock = search.find_suitable_rock(dep) 500 local url, err = search.find_suitable_rock(dep)
497 if not rock then 501 if not url then
498 return nil, "Could not satisfy dependency: "..deps.show_dep(dep) 502 return nil, "Could not satisfy dependency: "..deps.show_dep(dep)
499 end 503 end
500 local ok, err, errcode = install.run(rock) 504 local ok, err, errcode = install.run(url, deps.deps_mode_to_flag(deps_mode))
501 if not ok then 505 if not ok then
502 return nil, "Failed installing dependency: "..rock.." - "..err, errcode 506 return nil, "Failed installing dependency: "..url.." - "..err, errcode
503 end 507 end
504 end 508 end
505 end 509 end
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index 74ed40e9..f08ba7fe 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -37,25 +37,22 @@ local function get_file(filename)
37end 37end
38 38
39function download.download(arch, name, version, all) 39function download.download(arch, name, version, all)
40 local results, err
41 local query = search.make_query(name, version) 40 local query = search.make_query(name, version)
42 if arch then query.arch = arch end 41 if arch then query.arch = arch end
42
43 if all then 43 if all then
44 if name == "" then query.exact_name = false end 44 if name == "" then query.exact_name = false end
45 results = search.search_repos(query) 45 local results = search.search_repos(query)
46 else 46 local has_result = false
47 results, err = search.find_suitable_rock(query) 47 local all_ok = true
48 end 48 local any_err = ""
49 if type(results) == "string" then 49 for name, result in pairs(results) do
50 return get_file(results) 50 for version, items in pairs(result) do
51 elseif type(results) == "table" and next(results) then 51 for _, item in ipairs(items) do
52 if all then 52 -- Ignore provided rocks.
53 local all_ok = true 53 if item.arch ~= "installed" then
54 local any_err = "" 54 has_result = true
55 for name, result in pairs(results) do 55 local filename = path.make_url(item.repo, name, version, item.arch)
56 for version, versions in pairs(result) do
57 for _,items in pairs(versions) do
58 local filename = path.make_url(items.repo, name, version, items.arch)
59 local ok, err = get_file(filename) 56 local ok, err = get_file(filename)
60 if not ok then 57 if not ok then
61 all_ok = false 58 all_ok = false
@@ -64,12 +61,15 @@ function download.download(arch, name, version, all)
64 end 61 end
65 end 62 end
66 end 63 end
64 end
65
66 if has_result then
67 return all_ok, any_err 67 return all_ok, any_err
68 else 68 end
69 util.printerr("Multiple search results were returned.") 69 else
70 util.title("Search results:") 70 local url = search.find_suitable_rock(query)
71 search.print_results(results) 71 if url then
72 return nil, "Please narrow your query or use --all." 72 return get_file(url)
73 end 73 end
74 end 74 end
75 return nil, "Could not find a result named "..name..(version and " "..version or "").."." 75 return nil, "Could not find a result named "..name..(version and " "..version or "").."."
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua
index e1cad11b..d8fc84cc 100644
--- a/src/luarocks/fetch.lua
+++ b/src/luarocks/fetch.lua
@@ -379,7 +379,7 @@ function fetch.fetch_sources(rockspec, extract, dest_dir)
379 local protocol = rockspec.source.protocol 379 local protocol = rockspec.source.protocol
380 local ok, proto 380 local ok, proto
381 if fetch.is_basic_protocol(protocol) then 381 if fetch.is_basic_protocol(protocol) then
382 proto = require("luarocks.fetch") 382 proto = fetch
383 else 383 else
384 ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) 384 ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_"))
385 if not ok then 385 if not ok then
diff --git a/src/luarocks/fetch/git_ssh.lua b/src/luarocks/fetch/git_ssh.lua
new file mode 100644
index 00000000..0c2c0750
--- /dev/null
+++ b/src/luarocks/fetch/git_ssh.lua
@@ -0,0 +1,32 @@
1--- Fetch back-end for retrieving sources from Git repositories
2-- that use ssh:// transport. For example, for fetching a repository
3-- that requires the following command line:
4-- `git clone ssh://git@example.com/path/foo.git
5-- you can use this in the rockspec:
6-- source = { url = "git+ssh://git@example.com/path/foo.git" }
7-- It also handles scp-style ssh urls: git@example.com:path/foo.git,
8-- but you have to prepend the "git+ssh://" and why not use the "newer"
9-- style anyway?
10local git_ssh = {}
11
12local git = require("luarocks.fetch.git")
13
14--- Fetch sources for building a rock from a local Git repository.
15-- @param rockspec table: The rockspec table
16-- @param extract boolean: Unused in this module (required for API purposes.)
17-- @param dest_dir string or nil: If set, will extract to the given directory.
18-- @return (string, string) or (nil, string): The absolute pathname of
19-- the fetched source tarball and the temporary directory created to
20-- store it; or nil and an error message.
21function git_ssh.get_sources(rockspec, extract, dest_dir)
22 rockspec.source.url = rockspec.source.url:gsub("^git.", "")
23
24 -- Handle old-style scp-like git ssh urls
25 if rockspec.source.url:match("^ssh://[^/]+:[^%d]") then
26 rockspec.source.url = rockspec.source.url:gsub("^ssh://", "")
27 end
28
29 return git.get_sources(rockspec, extract, dest_dir, "--")
30end
31
32return git_ssh
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index a444f014..1d303c67 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -728,6 +728,14 @@ end
728 728
729if md5_ok then 729if md5_ok then
730 730
731-- Support the interface of lmd5 by lhf in addition to md5 by Roberto
732-- and the keplerproject.
733if not md5.sumhexa and md5.digest then
734 md5.sumhexa = function(msg)
735 return md5.digest(msg)
736 end
737end
738
731--- Get the MD5 checksum for a file. 739--- Get the MD5 checksum for a file.
732-- @param file string: The file to be computed. 740-- @param file string: The file to be computed.
733-- @return string: The MD5 checksum or nil + error 741-- @return string: The MD5 checksum or nil + error
diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua
index 442004ce..767bae4d 100644
--- a/src/luarocks/fs/unix/tools.lua
+++ b/src/luarocks/fs/unix/tools.lua
@@ -293,13 +293,19 @@ end
293function tools.unpack_archive(archive) 293function tools.unpack_archive(archive)
294 assert(type(archive) == "string") 294 assert(type(archive) == "string")
295 295
296 local pipe_to_tar = " | "..vars.TAR.." -xf -"
297
298 if not cfg.verbose then
299 pipe_to_tar = " 2> /dev/null"..fs.quiet(pipe_to_tar)
300 end
301
296 local ok 302 local ok
297 if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then 303 if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then
298 ok = fs.execute_string(vars.GUNZIP.." -c "..archive.."|"..vars.TAR.." -xf -") 304 ok = fs.execute_string(vars.GUNZIP.." -c "..fs.Q(archive)..pipe_to_tar)
299 elseif archive:match("%.tar%.bz2$") then 305 elseif archive:match("%.tar%.bz2$") then
300 ok = fs.execute_string(vars.BUNZIP2.." -c "..archive.."|tar -xf -") 306 ok = fs.execute_string(vars.BUNZIP2.." -c "..fs.Q(archive)..pipe_to_tar)
301 elseif archive:match("%.zip$") then 307 elseif archive:match("%.zip$") then
302 ok = fs.execute(vars.UNZIP, archive) 308 ok = fs.execute_quiet(vars.UNZIP, archive)
303 elseif archive:match("%.lua$") or archive:match("%.c$") then 309 elseif archive:match("%.lua$") or archive:match("%.c$") then
304 -- Ignore .lua and .c files; they don't need to be extracted. 310 -- Ignore .lua and .c files; they don't need to be extracted.
305 return true 311 return true
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua
index 92458b2b..5a2681a3 100644
--- a/src/luarocks/help.lua
+++ b/src/luarocks/help.lua
@@ -111,7 +111,7 @@ function help.run(...)
111 print_section("SEE ALSO") 111 print_section("SEE ALSO")
112 util.printout("","'"..program.." help' for general options and configuration.\n") 112 util.printout("","'"..program.." help' for general options and configuration.\n")
113 else 113 else
114 return nil, "Unknown command '"..command.."'" 114 return nil, "Unknown command: "..command
115 end 115 end
116 end 116 end
117 return true 117 return true
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 6d457fc2..c938aa9f 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -186,20 +186,12 @@ function install.run(...)
186 return name, version 186 return name, version
187 else 187 else
188 local search = require("luarocks.search") 188 local search = require("luarocks.search")
189 local results, err = search.find_suitable_rock(search.make_query(name:lower(), version)) 189 local url, err = search.find_suitable_rock(search.make_query(name:lower(), version))
190 if err then 190 if not url then
191 return nil, err 191 return nil, err
192 elseif type(results) == "string" then
193 local url = results
194 util.printout("Installing "..url.."...")
195 return install.run(url, util.forward_flags(flags))
196 else
197 util.printout()
198 util.printerr("Could not determine which rock to install.")
199 util.title("Search results:")
200 search.print_results(results)
201 return nil, (next(results) and "Please narrow your query." or "No results found.")
202 end 192 end
193 util.printout("Installing "..url.."...")
194 return install.run(url, util.forward_flags(flags))
203 end 195 end
204end 196end
205 197
diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua
index 1eaa6721..26280e94 100644
--- a/src/luarocks/loader.lua
+++ b/src/luarocks/loader.lua
@@ -6,8 +6,8 @@
6-- used to load previous modules, so that the loader chooses versions 6-- used to load previous modules, so that the loader chooses versions
7-- that are declared to be compatible with the ones loaded earlier. 7-- that are declared to be compatible with the ones loaded earlier.
8local loaders = package.loaders or package.searchers 8local loaders = package.loaders or package.searchers
9local package, require, ipairs, pairs, table, type, next, tostring, error = 9local package, require, ipairs, table, type, next, tostring, error =
10 package, require, ipairs, pairs, table, type, next, tostring, error 10 package, require, ipairs, table, type, next, tostring, error
11local unpack = unpack or table.unpack 11local unpack = unpack or table.unpack
12 12
13--module("luarocks.loader") 13--module("luarocks.loader")
@@ -20,6 +20,7 @@ cfg.init_package_paths()
20local path = require("luarocks.path") 20local path = require("luarocks.path")
21local manif_core = require("luarocks.manif_core") 21local manif_core = require("luarocks.manif_core")
22local deps = require("luarocks.deps") 22local deps = require("luarocks.deps")
23local util = require("luarocks.util")
23 24
24loader.context = {} 25loader.context = {}
25 26
@@ -79,7 +80,7 @@ function loader.add_context(name, version)
79 for _, tree in ipairs(loader.rocks_trees) do 80 for _, tree in ipairs(loader.rocks_trees) do
80 local entries = tree.manifest.repository[pkg] 81 local entries = tree.manifest.repository[pkg]
81 if entries then 82 if entries then
82 for version, pkgs in pairs(entries) do 83 for version, pkgs in util.sortedpairs(entries, deps.compare_versions) do
83 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then 84 if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then
84 loader.add_context(pkg, version) 85 loader.add_context(pkg, version)
85 end 86 end
@@ -125,17 +126,17 @@ end
125 126
126--- Search for a module in the rocks trees 127--- Search for a module in the rocks trees
127-- @param module string: module name (eg. "socket.core") 128-- @param module string: module name (eg. "socket.core")
128-- @param filter_module_name function(string, string, string, string, number): 129-- @param filter_file_name function(string, string, string, string, number):
129-- a function that takes the module name (eg "socket.core"), the rock name 130-- a function that takes the module file name (eg "socket/core.so"), the rock name
130-- (eg "luasocket"), the version (eg "2.0.2-1"), the path of the rocks tree 131-- (eg "luasocket"), the version (eg "2.0.2-1"), the path of the rocks tree
131-- (eg "/usr/local"), and the numeric index of the matching entry, so the 132-- (eg "/usr/local"), and the numeric index of the matching entry, so the
132-- filter function can know if the matching module was the first entry or not. 133-- filter function can know if the matching module was the first entry or not.
133-- @return string, string, string, (string or table): 134-- @return string, string, string, (string or table):
134-- * name of the rock containing the module (eg. "luasocket") 135-- * name of the rock containing the module (eg. "luasocket")
135-- * version of the rock (eg. "2.0.2-1") 136-- * version of the rock (eg. "2.0.2-1")
136-- * name of the module (eg. "socket.core", or "socket.core_2_0_2" if file is stored versioned). 137-- * return value of filter_file_name
137-- * tree of the module (string or table in `rocks_trees` format) 138-- * tree of the module (string or table in `rocks_trees` format)
138local function select_module(module, filter_module_name) 139local function select_module(module, filter_file_name)
139 --assert(type(module) == "string") 140 --assert(type(module) == "string")
140 --assert(type(filter_module_name) == "function") 141 --assert(type(filter_module_name) == "function")
141 142
@@ -149,16 +150,16 @@ local function select_module(module, filter_module_name)
149 if entries then 150 if entries then
150 for i, entry in ipairs(entries) do 151 for i, entry in ipairs(entries) do
151 local name, version = entry:match("^([^/]*)/(.*)$") 152 local name, version = entry:match("^([^/]*)/(.*)$")
152 local module_name = tree.manifest.repository[name][version][1].modules[module] 153 local file_name = tree.manifest.repository[name][version][1].modules[module]
153 if type(module_name) ~= "string" then 154 if type(file_name) ~= "string" then
154 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")") 155 error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")")
155 end 156 end
156 module_name = filter_module_name(module_name, name, version, tree.tree, i) 157 file_name = filter_file_name(file_name, name, version, tree.tree, i)
157 if loader.context[name] == version then 158 if loader.context[name] == version then
158 return name, version, module_name 159 return name, version, file_name
159 end 160 end
160 version = deps.parse_version(version) 161 version = deps.parse_version(version)
161 table.insert(providers, {name = name, version = version, module_name = module_name, tree = tree}) 162 table.insert(providers, {name = name, version = version, module_name = file_name, tree = tree})
162 end 163 end
163 end 164 end
164 end 165 end
@@ -179,12 +180,11 @@ end
179-- * tree of the module (string or table in `rocks_trees` format) 180-- * tree of the module (string or table in `rocks_trees` format)
180local function pick_module(module) 181local function pick_module(module)
181 return 182 return
182 select_module(module, function(module_name, name, version, tree, i) 183 select_module(module, function(file_name, name, version, tree, i)
183 if i > 1 then 184 if i > 1 then
184 module_name = path.versioned_name(module_name, "", name, version) 185 file_name = path.versioned_name(file_name, "", name, version)
185 end 186 end
186 module_name = path.path_to_module(module_name) 187 return path.path_to_module(file_name)
187 return module_name
188 end) 188 end)
189end 189end
190 190
@@ -192,8 +192,8 @@ end
192-- @param module string: module name (eg. "socket.core") 192-- @param module string: module name (eg. "socket.core")
193-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 193-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
194function loader.which(module) 194function loader.which(module)
195 local name, version, module_name = select_module(module, path.which_i) 195 local _, _, file_name = select_module(module, path.which_i)
196 return module_name 196 return file_name
197end 197end
198 198
199--- Package loader for LuaRocks support. 199--- Package loader for LuaRocks support.
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua
index 1dfe6473..94cf4414 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/make.lua
@@ -9,6 +9,8 @@ package.loaded["luarocks.make"] = make
9 9
10local build = require("luarocks.build") 10local build = require("luarocks.build")
11local fs = require("luarocks.fs") 11local fs = require("luarocks.fs")
12local dir = require("luarocks.dir")
13local path = require("luarocks.path")
12local util = require("luarocks.util") 14local util = require("luarocks.util")
13local cfg = require("luarocks.cfg") 15local cfg = require("luarocks.cfg")
14local fetch = require("luarocks.fetch") 16local fetch = require("luarocks.fetch")
@@ -22,8 +24,11 @@ make.help = [[
22Builds sources in the current directory, but unlike "build", 24Builds sources in the current directory, but unlike "build",
23it does not fetch sources, etc., assuming everything is 25it does not fetch sources, etc., assuming everything is
24available in the current directory. If no argument is given, 26available in the current directory. If no argument is given,
25look for a rockspec in the current directory. If more than one 27it looks for a rockspec in the current directory and in "rockspec/"
26is found, you must specify which to use, through the command-line. 28and "rockspecs/" subdirectories, picking the rockspec with newest version
29or without version name. If rockspecs for different rocks are found
30or there are several rockspecs without version, you must specify which to use,
31through the command-line.
27 32
28This command is useful as a tool for debugging rockspecs. 33This command is useful as a tool for debugging rockspecs.
29To install rocks, you'll normally want to use the "install" and 34To install rocks, you'll normally want to use the "install" and
@@ -44,6 +49,33 @@ To install rocks, you'll normally want to use the "install" and
44 49
45]] 50]]
46 51
52--- Collect rockspecs located in a subdirectory.
53-- @param versions table: A table mapping rock names to newest rockspec versions.
54-- @param paths table: A table mapping rock names to newest rockspec paths.
55-- @param unnamed_paths table: An array of rockspec paths that don't contain rock
56-- name and version in regular format.
57-- @param subdir string: path to subdirectory.
58local function collect_rockspecs(versions, paths, unnamed_paths, subdir)
59 if fs.is_dir(subdir) then
60 for file in fs.dir(subdir) do
61 file = dir.path(subdir, file)
62
63 if file:match("rockspec$") and fs.is_file(file) then
64 local rock, version = path.parse_name(file)
65
66 if rock then
67 if not versions[rock] or deps.compare_versions(version, versions[rock]) then
68 versions[rock] = version
69 paths[rock] = file
70 end
71 else
72 table.insert(unnamed_paths, file)
73 end
74 end
75 end
76 end
77end
78
47--- Driver function for "make" command. 79--- Driver function for "make" command.
48-- @param name string: A local rockspec. 80-- @param name string: A local rockspec.
49-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an 81-- @return boolean or (nil, string, exitcode): True if build was successful; nil and an
@@ -53,18 +85,35 @@ function make.run(...)
53 assert(type(rockspec) == "string" or not rockspec) 85 assert(type(rockspec) == "string" or not rockspec)
54 86
55 if not rockspec then 87 if not rockspec then
56 for file in fs.dir() do 88 -- Try to infer default rockspec name.
57 if file:match("rockspec$") then 89 local versions, paths, unnamed_paths = {}, {}, {}
58 if rockspec then 90 -- Look for rockspecs in some common locations.
91 collect_rockspecs(versions, paths, unnamed_paths, ".")
92 collect_rockspecs(versions, paths, unnamed_paths, "rockspec")
93 collect_rockspecs(versions, paths, unnamed_paths, "rockspecs")
94
95 if #unnamed_paths > 0 then
96 -- There are rockspecs not following "name-version.rockspec" format.
97 -- More than one are ambiguous.
98 if #unnamed_paths > 1 then
99 return nil, "Please specify which rockspec file to use."
100 else
101 rockspec = unnamed_paths[1]
102 end
103 else
104 local rock = next(versions)
105
106 if rock then
107 -- If there are rockspecs for multiple rocks it's ambiguous.
108 if next(versions, rock) then
59 return nil, "Please specify which rockspec file to use." 109 return nil, "Please specify which rockspec file to use."
60 else 110 else
61 rockspec = file 111 rockspec = paths[rock]
62 end 112 end
113 else
114 return nil, "Argument missing: please specify a rockspec to use on current directory."
63 end 115 end
64 end 116 end
65 if not rockspec then
66 return nil, "Argument missing: please specify a rockspec to use on current directory."
67 end
68 end 117 end
69 if not rockspec:match("rockspec$") then 118 if not rockspec:match("rockspec$") then
70 return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") 119 return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make")
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua
index 9ef0cfbb..6969d4b2 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/new_version.lua
@@ -1,9 +1,7 @@
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.
4--module("luarocks.new_version", package.seeall)
5local new_version = {} 4local new_version = {}
6package.loaded["luarocks.new_version"] = new_version
7 5
8local util = require("luarocks.util") 6local util = require("luarocks.util")
9local download = require("luarocks.download") 7local download = require("luarocks.download")
@@ -13,7 +11,7 @@ local fs = require("luarocks.fs")
13local type_check = require("luarocks.type_check") 11local type_check = require("luarocks.type_check")
14 12
15new_version.help_summary = "Auto-write a rockspec for a new version of a rock." 13new_version.help_summary = "Auto-write a rockspec for a new version of a rock."
16new_version.help_arguments = "{<package>|<rockspec>} [<new_version>] [<new_url>]" 14new_version.help_arguments = "[--tag=<tag>] {<package>|<rockspec>} [<new_version>] [<new_url>]"
17new_version.help = [[ 15new_version.help = [[
18This is a utility function that writes a new rockspec, updating data 16This is a utility function that writes a new rockspec, updating data
19from a previous one. 17from a previous one.
@@ -21,8 +19,10 @@ from a previous one.
21If a package name is given, it downloads the latest rockspec from the 19If a package name is given, it downloads the latest rockspec from the
22default server. If a rockspec is given, it uses it instead. 20default server. If a rockspec is given, it uses it instead.
23 21
24If the version number is not given, it only increments the revision 22If the version number is not given and tag is passed using --tag,
25number of the given (or downloaded) rockspec. 23it is used as the version, with 'v' removed from beginning.
24Otherwise, it only increments the revision number of the given
25(or downloaded) rockspec.
26 26
27If a URL is given, it replaces the one from the old rockspec with the 27If a URL is given, it replaces the one from the old rockspec with the
28given URL. If a URL is not given and a new version is given, it tries 28given URL. If a URL is not given and a new version is given, it tries
@@ -30,6 +30,9 @@ to guess the new URL by replacing occurrences of the version number
30in the URL or tag. It also tries to download the new URL to determine 30in the URL or tag. It also tries to download the new URL to determine
31the new MD5 checksum. 31the new MD5 checksum.
32 32
33If a tag is given, it replaces the one from the old rockspec. If there is
34an old tag but no new one passed, it is guessed in the same way URL is.
35
33WARNING: it writes the new rockspec to the current directory, 36WARNING: it writes the new rockspec to the current directory,
34overwriting the file if it already exists. 37overwriting the file if it already exists.
35]] 38]]
@@ -48,58 +51,73 @@ local function try_replace(tbl, field, old, new)
48 return false 51 return false
49end 52end
50 53
51local function check_url_and_update_md5(out_rs, out_name) 54-- Try to download source file using URL from a rockspec.
52 local old_md5 = out_rs.source.md5 55-- If it specified MD5, update it.
53 out_rs.source.md5 = nil 56-- @return (true, false) if MD5 was not specified or it stayed same,
54 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_name) 57-- (true, true) if MD5 changed, (nil, string) on error.
58local function check_url_and_update_md5(out_rs)
59 local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package)
55 if not file then 60 if not file then
56 util.printerr("Warning: invalid URL - "..temp_dir) 61 util.printerr("Warning: invalid URL - "..temp_dir)
57 return true 62 return true, false
58 end 63 end
59 util.printout("File successfully downloaded. Updating MD5 checksum...") 64
60 out_rs.source.md5 = fs.get_md5(file)
61 local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) 65 local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir)
62 if not inferred_dir then 66 if not inferred_dir then
63 return nil, found_dir 67 return nil, found_dir
64 end 68 end
69
65 if found_dir and found_dir ~= inferred_dir then 70 if found_dir and found_dir ~= inferred_dir then
66 out_rs.source.dir = found_dir 71 out_rs.source.dir = found_dir
67 end 72 end
68 return out_rs.source.md5 ~= old_md5 73
74 if file then
75 if out_rs.source.md5 then
76 util.printout("File successfully downloaded. Updating MD5 checksum...")
77 local new_md5, err = fs.get_md5(file)
78 if not new_md5 then
79 return nil, err
80 end
81 local old_md5 = out_rs.source.md5
82 out_rs.source.md5 = new_md5
83 return true, new_md5 ~= old_md5
84 else
85 util.printout("File successfully downloaded.")
86 return true, false
87 end
88 end
69end 89end
70 90
71local function update_source_section(out_rs, out_name, url, old_ver, new_ver) 91local function update_source_section(out_rs, url, tag, old_ver, new_ver)
92 if tag then
93 out_rs.source.tag = tag
94 end
72 if url then 95 if url then
73 out_rs.source.url = url 96 out_rs.source.url = url
74 check_url_and_update_md5(out_rs, out_name) 97 return check_url_and_update_md5(out_rs)
75 return true
76 end 98 end
77 if new_ver == old_ver then 99 if new_ver == old_ver then
78 return true 100 return true
79 end 101 end
80 if not out_rs.source then
81 return nil, "'source' table is missing. Invalid rockspec?"
82 end
83 if out_rs.source.dir then 102 if out_rs.source.dir then
84 try_replace(out_rs.source, "dir", old_ver, new_ver) 103 try_replace(out_rs.source, "dir", old_ver, new_ver)
85 end 104 end
86 if out_rs.source.file then 105 if out_rs.source.file then
87 try_replace(out_rs.source, "file", old_ver, new_ver) 106 try_replace(out_rs.source, "file", old_ver, new_ver)
88 end 107 end
89 local ok = try_replace(out_rs.source, "url", old_ver, new_ver) 108 if try_replace(out_rs.source, "url", old_ver, new_ver) then
90 if ok then 109 return check_url_and_update_md5(out_rs)
91 check_url_and_update_md5(out_rs, out_name) 110 end
111 if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then
92 return true 112 return true
93 end 113 end
94 ok = try_replace(out_rs.source, "tag", old_ver, new_ver) 114 -- Couldn't replace anything significant, use the old URL.
115 local ok, md5_changed = check_url_and_update_md5(out_rs)
95 if not ok then 116 if not ok then
96 ok = check_url_and_update_md5(out_rs, out_name) 117 return nil, md5_changed
97 if ok then
98 util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.")
99 end
100 end 118 end
101 if not ok then 119 if md5_changed then
102 return nil, "Failed to determine the location of the new version." 120 util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.")
103 end 121 end
104 return true 122 return true
105end 123end
@@ -107,7 +125,7 @@ end
107function new_version.run(...) 125function new_version.run(...)
108 local flags, input, version, url = util.parse_flags(...) 126 local flags, input, version, url = util.parse_flags(...)
109 if not input then 127 if not input then
110 return nil, "Missing arguments: expected program or rockspec. "..util.see_help("new_version") 128 return nil, "Missing argument: expected package or rockspec. "..util.see_help("new_version")
111 end 129 end
112 assert(type(input) == "string") 130 assert(type(input) == "string")
113 131
@@ -127,6 +145,10 @@ function new_version.run(...)
127 145
128 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") 146 local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$")
129 local new_ver, new_rev 147 local new_ver, new_rev
148
149 if flags.tag and not version then
150 version = flags.tag:gsub("^v", "")
151 end
130 152
131 if version then 153 if version then
132 new_ver, new_rev = version:match("(.*)%-(%d+)$") 154 new_ver, new_rev = version:match("(.*)%-(%d+)$")
@@ -145,7 +167,7 @@ function new_version.run(...)
145 local out_name = out_rs.package:lower() 167 local out_name = out_rs.package:lower()
146 out_rs.version = new_rockver.."-"..new_rev 168 out_rs.version = new_rockver.."-"..new_rev
147 169
148 local ok, err = update_source_section(out_rs, out_name, url, old_ver, new_ver) 170 local ok, err = update_source_section(out_rs, url, flags.tag, old_ver, new_ver)
149 if not ok then return nil, err end 171 if not ok then return nil, err end
150 172
151 if out_rs.build and out_rs.build.type == "module" then 173 if out_rs.build and out_rs.build.type == "module" then
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index fb5eec7e..bc7ab63b 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -342,44 +342,45 @@ end
342local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } 342local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true }
343 343
344--- Return the pathname of the file that would be loaded for a module, indexed. 344--- Return the pathname of the file that would be loaded for a module, indexed.
345-- @param module_name string: module name (eg. "socket.core") 345-- @param file_name string: module file name as in manifest (eg. "socket/core.so")
346-- @param name string: name of the package (eg. "luasocket") 346-- @param name string: name of the package (eg. "luasocket")
347-- @param version string: version number (eg. "2.0.2-1") 347-- @param version string: version number (eg. "2.0.2-1")
348-- @param tree string: repository path (eg. "/usr/local") 348-- @param tree string: repository path (eg. "/usr/local")
349-- @param i number: the index, 1 if version is the current default, > 1 otherwise. 349-- @param i number: the index, 1 if version is the current default, > 1 otherwise.
350-- This is done this way for use by select_module in luarocks.loader. 350-- This is done this way for use by select_module in luarocks.loader.
351-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 351-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
352function path.which_i(module_name, name, version, tree, i) 352function path.which_i(file_name, name, version, tree, i)
353 local deploy_dir 353 local deploy_dir
354 local extension = module_name:match("%.[a-z]+$") 354 local extension = file_name:match("%.[a-z]+$")
355 if is_src_extension[extension] then 355 if is_src_extension[extension] then
356 deploy_dir = path.deploy_lua_dir(tree) 356 deploy_dir = path.deploy_lua_dir(tree)
357 module_name = dir.path(deploy_dir, module_name) 357 file_name = dir.path(deploy_dir, file_name)
358 else 358 else
359 deploy_dir = path.deploy_lib_dir(tree) 359 deploy_dir = path.deploy_lib_dir(tree)
360 module_name = dir.path(deploy_dir, module_name) 360 file_name = dir.path(deploy_dir, file_name)
361 end 361 end
362 if i > 1 then 362 if i > 1 then
363 module_name = path.versioned_name(module_name, deploy_dir, name, version) 363 file_name = path.versioned_name(file_name, deploy_dir, name, version)
364 end 364 end
365 return module_name 365 return file_name
366end 366end
367 367
368--- Return the pathname of the file that would be loaded for a module, 368--- Return the pathname of the file that would be loaded for a module,
369-- returning the versioned pathname if given version is not the default version 369-- returning the versioned pathname if given version is not the default version
370-- in the given manifest. 370-- in the given manifest.
371-- @param module_name string: module name (eg. "socket.core") 371-- @param module_name string: module name (eg. "socket.core")
372-- @param file_name string: module file name as in manifest (eg. "socket/core.so")
372-- @param name string: name of the package (eg. "luasocket") 373-- @param name string: name of the package (eg. "luasocket")
373-- @param version string: version number (eg. "2.0.2-1") 374-- @param version string: version number (eg. "2.0.2-1")
374-- @param tree string: repository path (eg. "/usr/local") 375-- @param tree string: repository path (eg. "/usr/local")
375-- @param manifest table: the manifest table for the tree. 376-- @param manifest table: the manifest table for the tree.
376-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") 377-- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so")
377function path.which(module_name, filename, name, version, tree, manifest) 378function path.which(module_name, file_name, name, version, tree, manifest)
378 local versions = manifest.modules[module_name] 379 local versions = manifest.modules[module_name]
379 assert(versions) 380 assert(versions)
380 for i, name_version in ipairs(versions) do 381 for i, name_version in ipairs(versions) do
381 if name_version == name.."/"..version then 382 if name_version == name.."/"..version then
382 return path.which_i(filename, name, version, tree, i):gsub("//", "/") 383 return path.which_i(file_name, name, version, tree, i):gsub("//", "/")
383 end 384 end
384 end 385 end
385 assert(false) 386 assert(false)
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index f1a82d5b..5e6cf50e 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -48,7 +48,8 @@ end
48 48
49--- Store a search result (a rock or rockspec) in the results table. 49--- Store a search result (a rock or rockspec) in the results table.
50-- @param results table: The results table, where keys are package names and 50-- @param results table: The results table, where keys are package names and
51-- versions are tables matching version strings to an array of servers. 51-- values are tables matching version strings to arrays of
52-- tables with fields "arch" and "repo".
52-- @param name string: Package name. 53-- @param name string: Package name.
53-- @param version string: Package version. 54-- @param version string: Package version.
54-- @param arch string: Architecture of rock ("all", "src" or platform 55-- @param arch string: Architecture of rock ("all", "src" or platform
@@ -92,7 +93,8 @@ end
92-- table, optionally checking if version and arch (if given) match 93-- table, optionally checking if version and arch (if given) match
93-- a query. 94-- a query.
94-- @param results table: The results table, where keys are package names and 95-- @param results table: The results table, where keys are package names and
95-- versions are tables matching version strings to an array of servers. 96-- values are tables matching version strings to arrays of
97-- tables with fields "arch" and "repo".
96-- @param repo string: URL or pathname of the repository. 98-- @param repo string: URL or pathname of the repository.
97-- @param name string: The name of the package being tested. 99-- @param name string: The name of the package being tested.
98-- @param version string: The version of the package being tested. 100-- @param version string: The version of the package being tested.
@@ -123,8 +125,9 @@ end
123-- matches regardless of architecture. 125-- matches regardless of architecture.
124-- @param results table or nil: If given, this table will store the 126-- @param results table or nil: If given, this table will store the
125-- results; if not given, a new table will be created. 127-- results; if not given, a new table will be created.
126-- @param table: The results table, where keys are package names and 128-- @return table: The results table, where keys are package names and
127-- versions are tables matching version strings to an array of servers. 129-- values are tables matching version strings to arrays of
130-- tables with fields "arch" and "repo".
128-- If a table was given in the "results" parameter, that is the result value. 131-- If a table was given in the "results" parameter, that is the result value.
129function search.disk_search(repo, query, results) 132function search.disk_search(repo, query, results)
130 assert(type(repo) == "string") 133 assert(type(repo) == "string")
@@ -157,7 +160,8 @@ end
157 160
158--- Perform search on a rocks server or tree. 161--- Perform search on a rocks server or tree.
159-- @param results table: The results table, where keys are package names and 162-- @param results table: The results table, where keys are package names and
160-- versions are tables matching version strings to an array of servers. 163-- values are tables matching version strings to arrays of
164-- tables with fields "arch" and "repo".
161-- @param repo string: The URL of a rocks server or 165-- @param repo string: The URL of a rocks server or
162-- the pathname of a rocks tree (as returned by path.rocks_dir()). 166-- the pathname of a rocks tree (as returned by path.rocks_dir()).
163-- @param query table: A table describing the query in dependency 167-- @param query table: A table describing the query in dependency
@@ -190,8 +194,8 @@ end
190--- Search on all configured rocks servers. 194--- Search on all configured rocks servers.
191-- @param query table: A dependency query. 195-- @param query table: A dependency query.
192-- @return table: A table where keys are package names 196-- @return table: A table where keys are package names
193-- and values are tables matching version strings to an array of 197-- and values are tables matching version strings to arrays of
194-- rocks servers; if no results are found, an empty table is returned. 198-- tables with fields "arch" and "repo".
195function search.search_repos(query) 199function search.search_repos(query)
196 assert(type(query) == "table") 200 assert(type(query) == "table")
197 201
@@ -274,28 +278,26 @@ local function pick_latest_version(name, versions)
274 return nil 278 return nil
275end 279end
276 280
277--- Attempt to get a single URL for a given search. 281--- Attempt to get a single URL for a given search for a rock.
278-- @param query table: A dependency query. 282-- @param query table: A dependency query matching a single rock.
279-- @return string or table or (nil, string): URL for matching rock if 283-- @return string or (nil, string): URL for latest matching version
280-- a single one was found, a table of candidates if it could not narrow to 284-- of the rock if it was found, or nil followed by an error message.
281-- a single result, or nil followed by an error message.
282function search.find_suitable_rock(query) 285function search.find_suitable_rock(query)
283 assert(type(query) == "table") 286 assert(type(query) == "table")
284 287
285 local results = search.search_repos(query) 288 local results = search.search_repos(query)
286 local first = next(results) 289 local first_rock = next(results)
287 if not first then 290 if not first_rock then
288 return nil, "No results matching query were found." 291 return nil, "No results matching query were found."
289 elseif not next(results, first) then 292 elseif next(results, first_rock) then
290 if cfg.rocks_provided[query.name] ~= nil then 293 -- Shouldn't happen as query must match only one package.
291 -- do not install versions that listed in cfg.rocks_provided 294 return nil, "Several rocks matched query."
292 return nil, "Rock "..query.name.. 295 elseif cfg.rocks_provided[query.name] ~= nil then
293 " "..cfg.rocks_provided[query.name].. 296 -- Do not install versions listed in cfg.rocks_provided.
294 " was found but it is provided by VM or 'rocks_provided' in the config file." 297 return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name]..
295 end 298 " was found but it is provided by VM or 'rocks_provided' in the config file."
296 return pick_latest_version(query.name, results[first])
297 else 299 else
298 return results 300 return pick_latest_version(query.name, results[first_rock])
299 end 301 end
300end 302end
301 303
@@ -365,12 +367,11 @@ function search.act_on_src_or_rockspec(action, name, version, ...)
365 367
366 local query = search.make_query(name, version) 368 local query = search.make_query(name, version)
367 query.arch = "src|rockspec" 369 query.arch = "src|rockspec"
368 local results, err = search.find_suitable_rock(query) 370 local url, err = search.find_suitable_rock(query)
369 if type(results) == "string" then 371 if not url then
370 return action(results, ...)
371 else
372 return nil, "Could not find a result named "..name..(version and " "..version or "").."." 372 return nil, "Could not find a result named "..name..(version and " "..version or "").."."
373 end 373 end
374 return action(url, ...)
374end 375end
375 376
376--- Driver function for "search" command. 377--- Driver function for "search" command.
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua
index 08b2673f..ae41a513 100644
--- a/src/luarocks/show.lua
+++ b/src/luarocks/show.lua
@@ -28,7 +28,9 @@ With these flags, return only the desired information:
28]] 28]]
29 29
30local function keys_as_string(t, sep) 30local function keys_as_string(t, sep)
31 return table.concat(util.keys(t), sep or " ") 31 local keys = util.keys(t)
32 table.sort(keys)
33 return table.concat(keys, sep or " ")
32end 34end
33 35
34local function word_wrap(line) 36local function word_wrap(line)
@@ -88,6 +90,16 @@ function show.pick_installed_rock(name, version, tree)
88 return name, version, repo, repo_url 90 return name, version, repo, repo_url
89end 91end
90 92
93local function installed_rock_label(name, tree)
94 local installed, version
95 if cfg.rocks_provided[name] then
96 installed, version = true, cfg.rocks_provided[name]
97 else
98 installed, version = show.pick_installed_rock(name, nil, tree)
99 end
100 return installed and "(using "..version..")" or "(missing)"
101end
102
91--- Driver function for "show" command. 103--- Driver function for "show" command.
92-- @param name or nil: an existing package name. 104-- @param name or nil: an existing package name.
93-- @param version string or nil: a version may also be passed. 105-- @param version string or nil: a version may also be passed.
@@ -143,10 +155,26 @@ function show.run(...)
143 util.printout("\t"..mod.." ("..path.which(mod, filename, name, version, repo, manifest)..")") 155 util.printout("\t"..mod.." ("..path.which(mod, filename, name, version, repo, manifest)..")")
144 end 156 end
145 end 157 end
146 if next(minfo.dependencies) then 158 local direct_deps = {}
159 if #rockspec.dependencies > 0 then
147 util.printout() 160 util.printout()
148 util.printout("Depends on:") 161 util.printout("Depends on:")
149 util.printout("\t"..keys_as_string(minfo.dependencies, "\n\t")) 162 for _, dep in ipairs(rockspec.dependencies) do
163 direct_deps[dep.name] = true
164 util.printout("\t"..deps.show_dep(dep).." "..installed_rock_label(dep.name, flags["tree"]))
165 end
166 end
167 local has_indirect_deps
168 for dep_name in util.sortedpairs(minfo.dependencies) do
169 if not direct_deps[dep_name] then
170 if not has_indirect_deps then
171 util.printout()
172 util.printout("Indirectly pulling:")
173 has_indirect_deps = true
174 end
175
176 util.printout("\t"..dep_name.." "..installed_rock_label(dep_name, flags["tree"]))
177 end
150 end 178 end
151 util.printout() 179 util.printout()
152 end 180 end
diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua
index 101cae82..e6d9e36a 100644
--- a/src/luarocks/tools/zip.lua
+++ b/src/luarocks/tools/zip.lua
@@ -1,13 +1,35 @@
1 1
2--- A Lua implementation of .zip file archiving (used for creating .rock files), 2--- A Lua implementation of .zip file archiving (used for creating .rock files),
3-- using only lzlib. 3-- using only lzlib or lua-lzib.
4--module("luarocks.tools.zip", package.seeall)
5local zip = {} 4local zip = {}
6 5
7local zlib = require("zlib") 6local zlib = require("zlib")
8local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
9local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
10 9
10-- zlib module can be provided by both lzlib and lua-lzib packages.
11-- Create a compatibility layer.
12local zlib_compress, zlib_crc32
13if zlib._VERSION:match "^lua%-zlib" then
14 function zlib_compress(data)
15 return (zlib.deflate()(data, "finish"))
16 end
17
18 function zlib_crc32(data)
19 return zlib.crc32()(data)
20 end
21elseif zlib._VERSION:match "^lzlib" then
22 function zlib_compress(data)
23 return zlib.compress(data)
24 end
25
26 function zlib_crc32(data)
27 return zlib.crc32(zlib.crc32(), data)
28 end
29else
30 error("unknown zlib library", 0)
31end
32
11local function number_to_bytestring(number, nbytes) 33local function number_to_bytestring(number, nbytes)
12 local out = {} 34 local out = {}
13 for _ = 1, nbytes do 35 for _ = 1, nbytes do
@@ -31,32 +53,28 @@ local function zipwriter_open_new_file_in_zip(self, filename)
31 self.local_file_header = lfh 53 self.local_file_header = lfh
32 lfh.last_mod_file_time = 0 -- TODO 54 lfh.last_mod_file_time = 0 -- TODO
33 lfh.last_mod_file_date = 0 -- TODO 55 lfh.last_mod_file_date = 0 -- TODO
34 lfh.crc32 = 0 -- initial value
35 lfh.compressed_size = 0 -- unknown yet
36 lfh.uncompressed_size = 0 -- unknown yet
37 lfh.file_name_length = #filename 56 lfh.file_name_length = #filename
38 lfh.extra_field_length = 0 57 lfh.extra_field_length = 0
39 lfh.file_name = filename:gsub("\\", "/") 58 lfh.file_name = filename:gsub("\\", "/")
40 lfh.external_attr = 0 -- TODO properly store permissions 59 lfh.external_attr = 0 -- TODO properly store permissions
41 self.in_open_file = true 60 self.in_open_file = true
42 self.data = {}
43 return true 61 return true
44end 62end
45 63
46--- Write data to the file currently being stored in the zipfile. 64--- Write data to the file currently being stored in the zipfile.
47-- @param self handle of the zipfile being written. 65-- @param self handle of the zipfile being written.
48-- @param buf string containing data to be written. 66-- @param data string containing full contents of the file.
49-- @return true if succeeded, nil in case of failure. 67-- @return true if succeeded, nil in case of failure.
50local function zipwriter_write_file_in_zip(self, buf) 68local function zipwriter_write_file_in_zip(self, data)
51 if not self.in_open_file then 69 if not self.in_open_file then
52 return nil 70 return nil
53 end 71 end
54 local lfh = self.local_file_header 72 local lfh = self.local_file_header
55 local cbuf = zlib.compress(buf):sub(3, -5) 73 local compressed = zlib_compress(data):sub(3, -5)
56 lfh.crc32 = zlib.crc32(lfh.crc32, buf) 74 lfh.crc32 = zlib_crc32(data)
57 lfh.compressed_size = lfh.compressed_size + #cbuf 75 lfh.compressed_size = #compressed
58 lfh.uncompressed_size = lfh.uncompressed_size + #buf 76 lfh.uncompressed_size = #data
59 table.insert(self.data, cbuf) 77 self.data = compressed
60 return true 78 return true
61end 79end
62 80
@@ -86,10 +104,8 @@ local function zipwriter_close_file_in_zip(self)
86 zh:write(number_to_bytestring(lfh.extra_field_length, 2)) 104 zh:write(number_to_bytestring(lfh.extra_field_length, 2))
87 zh:write(lfh.file_name) 105 zh:write(lfh.file_name)
88 106
89 -- File data 107 -- File data
90 for _, cbuf in ipairs(self.data) do 108 zh:write(self.data)
91 zh:write(cbuf)
92 end
93 109
94 -- Data descriptor 110 -- Data descriptor
95 zh:write(number_to_bytestring(lfh.crc32, 4)) 111 zh:write(number_to_bytestring(lfh.crc32, 4))
@@ -117,12 +133,12 @@ local function zipwriter_add(self, file)
117 end 133 end
118 end 134 end
119 if ok then 135 if ok then
120 local buf = fin:read("*a") 136 local data = fin:read("*a")
121 if not buf then 137 if not data then
122 err = "error reading "..file 138 err = "error reading "..file
123 ok = false 139 ok = false
124 else 140 else
125 ok = self:write_file_in_zip(buf) 141 ok = self:write_file_in_zip(data)
126 if not ok then 142 if not ok then
127 err = "error in writing "..file.." in the zipfile" 143 err = "error in writing "..file.." in the zipfile"
128 end 144 end
diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua
index 2cf462fb..6df24569 100644
--- a/src/luarocks/upload/api.lua
+++ b/src/luarocks/upload/api.lua
@@ -106,13 +106,22 @@ end
106 106
107-- An ode to the multitude of JSON libraries out there... 107-- An ode to the multitude of JSON libraries out there...
108local function require_json() 108local function require_json()
109 for _, lib in ipairs({ "cjson", "dkjson", "json" }) do 109 local list = { "cjson", "dkjson", "json" }
110 for _, lib in ipairs(list) do
110 local json_ok, json = pcall(require, lib) 111 local json_ok, json = pcall(require, lib)
111 if json_ok then 112 if json_ok then
112 return json_ok, json 113 return json_ok, json
113 end 114 end
114 end 115 end
115 return nil 116 local errmsg = "Failed loading "
117 for i, name in ipairs(list) do
118 if i == #list then
119 errmsg = errmsg .."and '"..name.."'. Use 'luarocks search <partial-name>' to search for a library and 'luarocks install <name>' to install one."
120 else
121 errmsg = errmsg .."'"..name.."', "
122 end
123 end
124 return nil, errmsg
116end 125end
117 126
118local function redact_api_url(url) 127local function redact_api_url(url)
@@ -126,12 +135,12 @@ if not ltn12_ok then -- If not using LuaSocket and/or LuaSec...
126function Api:request(url, params, post_params) 135function Api:request(url, params, post_params)
127 local vars = cfg.variables 136 local vars = cfg.variables
128 local json_ok, json = require_json() 137 local json_ok, json = require_json()
129 if not json_ok then return nil, "A JSON library is required for this command." end 138 if not json_ok then return nil, "A JSON library is required for this command. "..json end
130 139
131 if cfg.downloader == "wget" then 140 if cfg.downloader == "wget" then
132 local curl_ok = fs.execute_quiet(vars.CURL, "--version") 141 local curl_ok, err = fs.is_tool_available(vars.CURL, "curl")
133 if not curl_ok then 142 if not curl_ok then
134 return nil, "Missing network helper program 'curl'.\nMake sure 'curl' is installed and available from your path." 143 return nil, err
135 end 144 end
136 end 145 end
137 146
@@ -192,7 +201,7 @@ local warned_luasec = false
192 201
193function Api:request(url, params, post_params) 202function Api:request(url, params, post_params)
194 local json_ok, json = require_json() 203 local json_ok, json = require_json()
195 if not json_ok then return nil, "A JSON library is required for this command." end 204 if not json_ok then return nil, "A JSON library is required for this command. "..json end
196 local server = tostring(self.config.server) 205 local server = tostring(self.config.server)
197 local http_ok, http 206 local http_ok, http
198 local via = "luasocket" 207 local via = "luasocket"
diff --git a/test/testing.bat b/test/testing.bat
index 319e12c3..7083678b 100644
--- a/test/testing.bat
+++ b/test/testing.bat
@@ -1,7 +1,7 @@
1@echo off 1@echo off
2Setlocal EnableDelayedExpansion EnableExtensions 2Setlocal EnableDelayedExpansion EnableExtensions
3 3
4if not defined LUAROCKS_REPO set LUAROCKS_REPO=http://rocks.moonscript.org 4if not defined LUAROCKS_REPO set LUAROCKS_REPO=https://luarocks.org
5 5
6appveyor DownloadFile %LUAROCKS_REPO%/stdlib-41.0.0-1.src.rock 6appveyor DownloadFile %LUAROCKS_REPO%/stdlib-41.0.0-1.src.rock
7luarocks build stdlib 7luarocks build stdlib
diff --git a/test/testing.lua b/test/testing.lua
index 63dead2b..6d4b4b05 100644
--- a/test/testing.lua
+++ b/test/testing.lua
@@ -86,6 +86,7 @@ local tests = {
86 fail_arg_string_followed_by_flag = function() return run "$luarocks --server --porcelain" end, 86 fail_arg_string_followed_by_flag = function() return run "$luarocks --server --porcelain" end,
87 fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end, 87 fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end,
88 test_empty_list = function() return run "$luarocks list" end, 88 test_empty_list = function() return run "$luarocks list" end,
89 test_list_outdated = function () return run "$luarocks list --outdated" end,
89 fail_sysconfig_err = function() 90 fail_sysconfig_err = function()
90 mkdir "$testing_lrprefix/etc/luarocks" 91 mkdir "$testing_lrprefix/etc/luarocks"
91 file_set_contents("$testing_lrprefix/etc/luarocks/config.lua", "aoeui") 92 file_set_contents("$testing_lrprefix/etc/luarocks/config.lua", "aoeui")
@@ -441,6 +442,11 @@ local tests = {
441 return run "$luarocks install luarepl" 442 return run "$luarocks install luarepl"
442 and run "$luarocks doc luarepl" 443 and run "$luarocks doc luarepl"
443 end, 444 end,
445 test_doc_home = function()
446 return run "$luarocks install luacov"
447 and run "$luarocks doc luacov --home"
448 end,
449 fail_doc_invalid = function () return run "$luarocks doc invalid" end,
444 450
445 -- Tests for https://github.com/keplerproject/luarocks/issues/375 451 -- Tests for https://github.com/keplerproject/luarocks/issues/375
446 test_fetch_base_dir = function() 452 test_fetch_base_dir = function()
diff --git a/test/testing.sh b/test/testing.sh
index a198c2f2..3a132a2b 100755
--- a/test/testing.sh
+++ b/test/testing.sh
@@ -127,20 +127,15 @@ upload_servers = {
127EOF 127EOF
128cat <<EOF > $testing_dir/luacov.config 128cat <<EOF > $testing_dir/luacov.config
129return { 129return {
130 ["configfile"] = ".luacov", 130 statsfile = "$testing_dir/luacov.stats.out",
131 ["statsfile"] = "$testing_dir/luacov.stats.out", 131 reportfile = "$testing_dir/luacov.report.out",
132 ["reportfile"] = "$testing_dir/luacov.report.out", 132 modules = {
133 runreport = false, 133 ["luarocks"] = "src/bin/luarocks",
134 deletestats = false, 134 ["luarocks-admin"] = "src/bin/luarocks-admin",
135 ["include"] = {}, 135 ["luarocks.*"] = "src",
136 ["exclude"] = { 136 ["luarocks.*.*"] = "src",
137 "luacov$", 137 ["luarocks.*.*.*"] = "src"
138 "luacov%.reporter$", 138 }
139 "luacov%.defaults$",
140 "luacov%.runner$",
141 "luacov%.stats$",
142 "luacov%.tick$",
143 },
144} 139}
145EOF 140EOF
146 141
@@ -218,7 +213,7 @@ srcdir_luasocket=luasocket-3.0-rc1
218version_cprint=0.1 213version_cprint=0.1
219verrev_cprint=0.1-2 214verrev_cprint=0.1-2
220 215
221version_luacov=0.8 216version_luacov=0.9.1
222verrev_luacov=${version_luacov}-1 217verrev_luacov=${version_luacov}-1
223version_lxsh=0.8.6 218version_lxsh=0.8.6
224version_validate_args=1.5.4 219version_validate_args=1.5.4
@@ -265,7 +260,7 @@ luajit_luarocks="luajit -e require('luacov.runner')('$testing_dir/luacov.config'
265mkdir -p "$testing_server" 260mkdir -p "$testing_server"
266( 261(
267 cd "$testing_server" 262 cd "$testing_server"
268 luarocks_repo="http://rocks.moonscript.org" 263 luarocks_repo="https://luarocks.org"
269 get() { [ -e `basename "$1"` ] || wget -c "$1"; } 264 get() { [ -e `basename "$1"` ] || wget -c "$1"; }
270 get "$luarocks_repo/luacov-${verrev_luacov}.src.rock" 265 get "$luarocks_repo/luacov-${verrev_luacov}.src.rock"
271 get "$luarocks_repo/luacov-${verrev_luacov}.rockspec" 266 get "$luarocks_repo/luacov-${verrev_luacov}.rockspec"
@@ -380,7 +375,10 @@ fail_arg_string_no_parameter() { $luarocks --server; }
380fail_arg_string_followed_by_flag() { $luarocks --server --porcelain; } 375fail_arg_string_followed_by_flag() { $luarocks --server --porcelain; }
381fail_arg_string_unknown() { $luarocks --invalid-flag=abc; } 376fail_arg_string_unknown() { $luarocks --invalid-flag=abc; }
382 377
378fail_invalid_assignment() { $luarocks invalid=5; }
379
383test_empty_list() { $luarocks list; } 380test_empty_list() { $luarocks list; }
381test_list_outdated() { $luarocks list --outdated; }
384 382
385fail_sysconfig_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; } 383fail_sysconfig_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; }
386fail_sysconfig_default_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config-$luashortversion.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; } 384fail_sysconfig_default_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config-$luashortversion.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; }
@@ -415,6 +413,12 @@ fail_build_permissions() { $luarocks build --tree=/usr lpeg; }
415fail_build_permissions_parent() { $luarocks build --tree=/usr/invalid lpeg; } 413fail_build_permissions_parent() { $luarocks build --tree=/usr/invalid lpeg; }
416 414
417test_build_verbose() { $luarocks build --verbose lpeg; } 415test_build_verbose() { $luarocks build --verbose lpeg; }
416test_build_timeout() { $luarocks --timeout=10; }
417fail_build_timeout_invalid() { $luarocks --timeout=abc; }
418test_build_branch() { $luarocks build --branch=master lpeg; }
419fail_build_invalid_entry_deps_mode() { $luarocks build --deps-mode=123 lpeg; }
420test_build_only_server() { $luarocks --only-server=testing; }
421test_build_only_sources() { $luarocks build --only-sources="http://example.com" lpeg; }
418fail_build_blank_arg() { $luarocks build --tree="" lpeg; } 422fail_build_blank_arg() { $luarocks build --tree="" lpeg; }
419test_build_withpatch() { need_luasocket; $luarocks build luadoc; } 423test_build_withpatch() { need_luasocket; $luarocks build luadoc; }
420test_build_diffversion() { $luarocks build luacov ${version_luacov}; } 424test_build_diffversion() { $luarocks build luacov ${version_luacov}; }
@@ -427,6 +431,8 @@ test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lx
427test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } 431test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
428test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; } 432test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; }
429test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } 433test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
434test_build_no_deps() { $luarocks build luasec --nodeps; }
435test_install_no_deps() { $luarocks install luasec --nodeps; }
430fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } 436fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; }
431fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } 437fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; }
432 438
@@ -461,12 +467,15 @@ test_list() { $luarocks list; }
461test_list_porcelain() { $luarocks list --porcelain; } 467test_list_porcelain() { $luarocks list --porcelain; }
462 468
463test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } 469test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; }
464test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } 470test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks new_version lxsh-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
471test_make_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
472fail_make_ambiguous_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec lxsh2-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
473fail_make_ambiguous_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && mv lxsh-${verrev_lxsh}.rockspec 1_rockspec && cp 1_rockspec 2_rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
465test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } 474test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
466fail_make_which_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; }
467 475
468test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } 476test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; }
469test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; } 477test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; }
478test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; }
470 479
471test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; } 480test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; }
472test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; } 481test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; }
@@ -487,10 +496,18 @@ fail_remove_invalid_name() { $luarocks remove invalid.rock; }
487 496
488test_search_found() { $luarocks search zlib; } 497test_search_found() { $luarocks search zlib; }
489test_search_missing() { $luarocks search missing_rock; } 498test_search_missing() { $luarocks search missing_rock; }
499test_search_version() { $luarocks search zlib 1.1; }
500test_search_all() { $luarocks search --all; }
501fail_search_nostring() { $var=123; $luarocks search $var; }
490 502
491test_show() { $luarocks show luacov; } 503test_show() { $luarocks show luacov; }
492test_show_modules() { $luarocks show --modules luacov; } 504test_show_modules() { $luarocks show --modules luacov; }
493test_show_home() { $luarocks show --home luacov; } 505test_show_home() { $luarocks show --home luacov; }
506test_show_deps() { $luarocks show --deps luacov; }
507test_show_rockspec() { $luarocks show --rockspec luacov; }
508test_show_mversion() { $luarocks show --mversion luacov; }
509test_show_rocktree() { $luarocks show --rock-tree luacov; }
510test_show_rockdir() { $luarocks show --rock-dir luacov; }
494test_show_depends() { need_luasocket; $luarocks install $luasec && $luarocks show luasec; } 511test_show_depends() { need_luasocket; $luarocks install $luasec && $luarocks show luasec; }
495test_show_oldversion() { $luarocks install luacov ${version_luacov} && $luarocks show luacov ${version_luacov}; } 512test_show_oldversion() { $luarocks install luacov ${version_luacov} && $luarocks show luacov ${version_luacov}; }
496 513
@@ -515,6 +532,7 @@ fail_admin_invalidrock() { $luarocks_admin --server=testing add invalid; }
515test_admin_refresh_cache() { $luarocks_admin --server=testing refresh_cache; } 532test_admin_refresh_cache() { $luarocks_admin --server=testing refresh_cache; }
516test_admin_remove() { $luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock; } 533test_admin_remove() { $luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock; }
517fail_admin_remove_missing() { $luarocks_admin --server=testing remove; } 534fail_admin_remove_missing() { $luarocks_admin --server=testing remove; }
535fail_admin_split_server_url() { $luarocks_admin --server="localhost@/tmp/luarocks_testing" add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; }
518 536
519fail_deps_mode_invalid_arg() { $luarocks remove luacov --deps-mode; } 537fail_deps_mode_invalid_arg() { $luarocks remove luacov --deps-mode; }
520test_deps_mode_one() { $luarocks build --tree="system" lpeg && $luarocks list && $luarocks build --deps-mode=one --tree="$testing_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ]; } 538test_deps_mode_one() { $luarocks build --tree="system" lpeg && $luarocks list && $luarocks build --deps-mode=one --tree="$testing_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ]; }
@@ -527,6 +545,7 @@ test_deps_mode_make_order() { $luarocks build --tree="$testing_sys_tree" lpeg &&
527test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_sys_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ] && rm -rf ./lxsh-${verrev_lxsh}; } 545test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_sys_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ] && rm -rf ./lxsh-${verrev_lxsh}; }
528 546
529test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; } 547test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; }
548test_write_rockspec_tag() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0; }
530test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; } 549test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; }
531test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; } 550test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; }
532test_write_rockspec_fullargs() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"; } 551test_write_rockspec_fullargs() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"; }
@@ -574,6 +593,8 @@ fail_luajit_dependency() {
574} 593}
575 594
576test_doc() { $luarocks install luarepl; $luarocks doc luarepl; } 595test_doc() { $luarocks install luarepl; $luarocks doc luarepl; }
596test_doc_home() { $luarocks install luacov; $luarocks doc luacov --home; }
597fail_doc_invalid() { $luarocks doc invalid; }
577 598
578# Driver ######################################### 599# Driver #########################################
579 600
@@ -639,16 +660,18 @@ run_all_tests() {
639run_all_tests $1 660run_all_tests $1
640#run_with_minimal_environment $1 661#run_with_minimal_environment $1
641 662
663cd "$testing_dir/.."
664
642if [ "$travis" ] 665if [ "$travis" ]
643then 666then
644 if [ "$TRAVIS" ] 667 if [ "$TRAVIS" ]
645 then 668 then
646 build_environment luacov luafilesystem luacov-coveralls 669 build_environment luacov luafilesystem luacov-coveralls
647 ( cd $testing_dir; $testing_sys_tree/bin/luacov-coveralls || echo "ok" ) 670 $testing_sys_tree/bin/luacov-coveralls -c "$testing_dir/luacov.config" || echo "ok"
648 fi 671 fi
649 $testing_sys_tree/bin/luacov -c $testing_dir/luacov.config src/luarocks src/bin 672 $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config"
650 grep "Summary" -B1 -A1000 $testing_dir/luacov.report.out 673 grep "Summary" -B1 -A1000 "$testing_dir/luacov.report.out"
651else 674else
652 $testing_sys_tree/bin/luacov -c $testing_dir/luacov.config src/luarocks src/bin 675 $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config"
653 cat "$testing_dir/luacov.report.out" 676 cat "$testing_dir/luacov.report.out"
654fi 677fi