aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/add.lua1
-rw-r--r--src/luarocks/admin_remove.lua1
-rw-r--r--src/luarocks/build.lua31
-rw-r--r--src/luarocks/build/builtin.lua29
-rw-r--r--src/luarocks/build/cmake.lua22
-rw-r--r--src/luarocks/cfg.lua20
-rw-r--r--src/luarocks/config_cmd.lua1
-rw-r--r--src/luarocks/deps.lua50
-rw-r--r--src/luarocks/doc.lua1
-rw-r--r--src/luarocks/download.lua1
-rw-r--r--src/luarocks/fetch.lua35
-rw-r--r--src/luarocks/fetch/git.lua57
-rw-r--r--src/luarocks/help.lua1
-rw-r--r--src/luarocks/install.lua1
-rw-r--r--src/luarocks/lint.lua1
-rw-r--r--src/luarocks/list.lua1
-rw-r--r--src/luarocks/make.lua1
-rw-r--r--src/luarocks/make_manifest.lua1
-rw-r--r--src/luarocks/new_version.lua1
-rw-r--r--src/luarocks/pack.lua1
-rw-r--r--src/luarocks/path.lua5
-rw-r--r--src/luarocks/path_cmd.lua1
-rw-r--r--src/luarocks/purge.lua1
-rw-r--r--src/luarocks/refresh_cache.lua2
-rw-r--r--src/luarocks/remove.lua1
-rw-r--r--src/luarocks/search.lua1
-rw-r--r--src/luarocks/show.lua1
-rw-r--r--src/luarocks/tools/tar.lua6
-rw-r--r--src/luarocks/type_check.lua2
-rw-r--r--src/luarocks/unpack.lua1
-rw-r--r--src/luarocks/upload.lua1
-rw-r--r--src/luarocks/util.lua21
-rw-r--r--src/luarocks/validate.lua1
-rw-r--r--src/luarocks/write_rockspec.lua1
34 files changed, 228 insertions, 74 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua
index f37d334d..66f7504f 100644
--- a/src/luarocks/add.lua
+++ b/src/luarocks/add.lua
@@ -12,7 +12,6 @@ local index = require("luarocks.index")
12local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
13local cache = require("luarocks.cache") 13local cache = require("luarocks.cache")
14 14
15util.add_run_function(add)
16add.help_summary = "Add a rock or rockspec to a rocks server." 15add.help_summary = "Add a rock or rockspec to a rocks server."
17add.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" 16add.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}"
18add.help = [[ 17add.help = [[
diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua
index 621f1317..be1e7cbc 100644
--- a/src/luarocks/admin_remove.lua
+++ b/src/luarocks/admin_remove.lua
@@ -12,7 +12,6 @@ local index = require("luarocks.index")
12local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
13local cache = require("luarocks.cache") 13local cache = require("luarocks.cache")
14 14
15util.add_run_function(admin_remove)
16admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." 15admin_remove.help_summary = "Remove a rock or rockspec from a rocks server."
17admin_remove.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}" 16admin_remove.help_arguments = "[--server=<server>] [--no-refresh] {<rockspec>|<rock>...}"
18admin_remove.help = [[ 17admin_remove.help = [[
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index f87b2f1b..2d29e23f 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -16,7 +16,6 @@ local manif = require("luarocks.manif")
16local remove = require("luarocks.remove") 16local remove = require("luarocks.remove")
17local cfg = require("luarocks.cfg") 17local cfg = require("luarocks.cfg")
18 18
19util.add_run_function(build)
20build.help_summary = "Build/compile a rock." 19build.help_summary = "Build/compile a rock."
21build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}" 20build.help_arguments = "[--pack-binary-rock] [--keep] {<rockspec>|<rock>|<name> [<version>]}"
22build.help = [[ 21build.help = [[
@@ -151,6 +150,31 @@ local function install_default_docs(name, version)
151 end 150 end
152end 151end
153 152
153local function check_macosx_deployment_target(rockspec)
154 local target = rockspec.build.macosx_deployment_target
155 local function minor(version)
156 return tonumber(version and version:match("^[^.]+%.([^.]+)"))
157 end
158 local function patch_variable(var, target)
159 if rockspec.variables[var]:match("MACOSX_DEPLOYMENT_TARGET") then
160 rockspec.variables[var] = (rockspec.variables[var]):gsub("MACOSX_DEPLOYMENT_TARGET=[^ ]*", "MACOSX_DEPLOYMENT_TARGET="..target)
161 else
162 rockspec.variables[var] = "env MACOSX_DEPLOYMENT_TARGET="..target.." "..rockspec.variables[var]
163 end
164 end
165 if cfg.platforms.macosx and deps.format_is_at_least(rockspec, "3.0") and target then
166 local version = util.popen_read("sw_vers -productVersion")
167 local versionminor = minor(version)
168 local targetminor = minor(target)
169 if targetminor > versionminor then
170 return nil, ("This rock requires Mac OSX 10.%d, and you are running 10.%d."):format(targetminor, versionminor)
171 end
172 patch_variable("CC", target)
173 patch_variable("LD", target)
174 end
175 return true
176end
177
154--- Build and install a rock given a rockspec. 178--- Build and install a rock given a rockspec.
155-- @param rockspec_file string: local or remote filename of a rockspec. 179-- @param rockspec_file string: local or remote filename of a rockspec.
156-- @param need_to_fetch boolean: true if sources need to be fetched, 180-- @param need_to_fetch boolean: true if sources need to be fetched,
@@ -248,6 +272,11 @@ function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_m
248 end 272 end
249 end 273 end
250 274
275 ok, err = check_macosx_deployment_target(rockspec)
276 if not ok then
277 return nil, err
278 end
279
251 if build_spec.type ~= "none" then 280 if build_spec.type ~= "none" then
252 281
253 -- Temporary compatibility 282 -- Temporary compatibility
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index b6f53271..81fa8b13 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -49,7 +49,7 @@ end
49-- nil and an error message otherwise. 49-- nil and an error message otherwise.
50function builtin.run(rockspec) 50function builtin.run(rockspec)
51 assert(type(rockspec) == "table") 51 assert(type(rockspec) == "table")
52 local compile_object, compile_library, compile_wrapper_binary --TODO EXEWRAPPER 52 local compile_object, compile_library, compile_static_library, compile_wrapper_binary --TODO EXEWRAPPER
53 53
54 local build = rockspec.build 54 local build = rockspec.build
55 local variables = rockspec.variables 55 local variables = rockspec.variables
@@ -82,6 +82,13 @@ function builtin.run(rockspec)
82 local ok = execute(variables.LD.." "..variables.LIBFLAG, "-o", library, unpack(extras)) 82 local ok = execute(variables.LD.." "..variables.LIBFLAG, "-o", library, unpack(extras))
83 return ok 83 return ok
84 end 84 end
85 compile_static_library = function(library, objects, libraries, libdirs, name)
86 local ok = execute(variables.AR, "rc", library, unpack(objects))
87 if ok then
88 ok = execute(variables.RANLIB, library)
89 end
90 return ok
91 end
85 compile_wrapper_binary = function(fullname, name) 92 compile_wrapper_binary = function(fullname, name)
86 --TODO EXEWRAPPER 93 --TODO EXEWRAPPER
87 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\") 94 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\")
@@ -128,6 +135,10 @@ function builtin.run(rockspec)
128 end 135 end
129 return ok 136 return ok
130 end 137 end
138 compile_static_library = function(library, objects, libraries, libdirs, name)
139 local ok = execute(variables.AR, "-out:"..library, unpack(objects))
140 return ok
141 end
131 compile_wrapper_binary = function(fullname, name) 142 compile_wrapper_binary = function(fullname, name)
132 --TODO EXEWRAPPER 143 --TODO EXEWRAPPER
133 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\") 144 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\")
@@ -169,6 +180,13 @@ function builtin.run(rockspec)
169 end 180 end
170 return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras)) 181 return execute(variables.LD.." "..variables.LIBFLAG, "-o", library, "-L"..variables.LUA_LIBDIR, unpack(extras))
171 end 182 end
183 compile_static_library = function(library, objects, libraries, libdirs, name)
184 local ok = execute(variables.AR, "rc", library, unpack(objects))
185 if ok then
186 ok = execute(variables.RANLIB, library)
187 end
188 return ok
189 end
172 compile_wrapper_binary = function(_, name) return true, name end 190 compile_wrapper_binary = function(_, name) return true, name end
173 --TODO EXEWRAPPER 191 --TODO EXEWRAPPER
174 end 192 end
@@ -247,6 +265,15 @@ function builtin.run(rockspec)
247 if not ok then 265 if not ok then
248 return nil, "Failed compiling module "..module_name 266 return nil, "Failed compiling module "..module_name
249 end 267 end
268 module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.static_lib_extension)
269 if moddir ~= "" then
270 module_name = dir.path(moddir, module_name)
271 end
272 lib_modules[module_name] = dir.path(libdir, module_name)
273 ok = compile_static_library(module_name, objects, info.libraries, info.libdirs, name)
274 if not ok then
275 return nil, "Failed compiling static library "..module_name
276 end
250 end 277 end
251 end 278 end
252 for _, mods in ipairs({{ tbl = lua_modules, perms = cfg.perm_read }, { tbl = lib_modules, perms = cfg.perm_exec }}) do 279 for _, mods in ipairs({{ tbl = lua_modules, perms = cfg.perm_read }, { tbl = lib_modules, perms = cfg.perm_exec }}) do
diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua
index da5a31f1..c2712bb2 100644
--- a/src/luarocks/build/cmake.lua
+++ b/src/luarocks/build/cmake.lua
@@ -5,6 +5,7 @@ local cmake = {}
5local fs = require("luarocks.fs") 5local fs = require("luarocks.fs")
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local cfg = require("luarocks.cfg") 7local cfg = require("luarocks.cfg")
8local deps = require("luarocks.deps")
8 9
9--- Driver function for the "cmake" build back-end. 10--- Driver function for the "cmake" build back-end.
10-- @param rockspec table: the loaded rockspec. 11-- @param rockspec table: the loaded rockspec.
@@ -52,13 +53,26 @@ function cmake.run(rockspec)
52 return nil, "Failed cmake." 53 return nil, "Failed cmake."
53 end 54 end
54 55
55 if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --config Release") then 56 local do_build, do_install
56 return nil, "Failed building." 57 if deps.format_is_at_least(rockspec, "3.0") then
58 do_build = (build.build_pass == nil) and true or build.build_pass
59 do_install = (build.install_pass == nil) and true or build.install_pass
60 else
61 do_build = true
62 do_install = true
57 end 63 end
58 64
59 if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then 65 if do_build then
60 return nil, "Failed installing." 66 if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --config Release") then
67 return nil, "Failed building."
68 end
61 end 69 end
70 if do_install then
71 if not fs.execute_string(rockspec.variables.CMAKE.." --build build.luarocks --target install --config Release") then
72 return nil, "Failed installing."
73 end
74 end
75
62 return true 76 return true
63end 77end
64 78
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 9b1c5902..53387276 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -76,8 +76,8 @@ end
76-- so that this detection does not run every time. When it is 76-- so that this detection does not run every time. When it is
77-- performed, we use the Unix way to identify the system, 77-- performed, we use the Unix way to identify the system,
78-- even on Windows (assuming UnxUtils or Cygwin). 78-- even on Windows (assuming UnxUtils or Cygwin).
79local system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") 79local system = site_config.LUAROCKS_UNAME_S or util.popen_read("uname -s")
80local proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") 80local proc = site_config.LUAROCKS_UNAME_M or util.popen_read("uname -m")
81if proc:match("i[%d]86") then 81if proc:match("i[%d]86") then
82 cfg.target_cpu = "x86" 82 cfg.target_cpu = "x86"
83elseif proc:match("amd64") or proc:match("x86_64") then 83elseif proc:match("amd64") or proc:match("x86_64") then
@@ -343,6 +343,8 @@ local defaults = {
343 MAKE = "make", 343 MAKE = "make",
344 CC = "cc", 344 CC = "cc",
345 LD = "ld", 345 LD = "ld",
346 AR = "ar",
347 RANLIB = "ranlib",
346 348
347 CVS = "cvs", 349 CVS = "cvs",
348 GIT = "git", 350 GIT = "git",
@@ -398,7 +400,8 @@ local defaults = {
398 include = "include" 400 include = "include"
399 }, 401 },
400 402
401 rocks_provided = {} 403 rocks_provided = {},
404 rocks_provided_3_0 = {},
402} 405}
403 406
404if cfg.platforms.windows then 407if cfg.platforms.windows then
@@ -410,6 +413,7 @@ if cfg.platforms.windows then
410 defaults.arch = "win32-"..cfg.target_cpu 413 defaults.arch = "win32-"..cfg.target_cpu
411 defaults.lib_extension = "dll" 414 defaults.lib_extension = "dll"
412 defaults.external_lib_extension = "dll" 415 defaults.external_lib_extension = "dll"
416 defaults.static_lib_extension = "lib"
413 defaults.obj_extension = "obj" 417 defaults.obj_extension = "obj"
414 defaults.external_deps_dirs = { "c:/external/" } 418 defaults.external_deps_dirs = { "c:/external/" }
415 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/bin" 419 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/bin"
@@ -423,6 +427,7 @@ if cfg.platforms.windows then
423 defaults.variables.WRAPPER = full_prefix.."\\rclauncher.c" 427 defaults.variables.WRAPPER = full_prefix.."\\rclauncher.c"
424 defaults.variables.LD = "link" 428 defaults.variables.LD = "link"
425 defaults.variables.MT = "mt" 429 defaults.variables.MT = "mt"
430 defaults.variables.AR = "lib"
426 defaults.variables.LUALIB = "lua"..cfg.lua_version..".lib" 431 defaults.variables.LUALIB = "lua"..cfg.lua_version..".lib"
427 defaults.variables.CFLAGS = "/nologo /MD /O2" 432 defaults.variables.CFLAGS = "/nologo /MD /O2"
428 defaults.variables.LIBFLAG = "/nologo /dll" 433 defaults.variables.LIBFLAG = "/nologo /dll"
@@ -462,11 +467,14 @@ end
462 467
463if cfg.platforms.mingw32 then 468if cfg.platforms.mingw32 then
464 defaults.obj_extension = "o" 469 defaults.obj_extension = "o"
470 defaults.static_lib_extension = "a"
465 defaults.cmake_generator = "MinGW Makefiles" 471 defaults.cmake_generator = "MinGW Makefiles"
466 defaults.variables.MAKE = "mingw32-make" 472 defaults.variables.MAKE = "mingw32-make"
467 defaults.variables.CC = "mingw32-gcc" 473 defaults.variables.CC = "mingw32-gcc"
468 defaults.variables.RC = "windres" 474 defaults.variables.RC = "windres"
469 defaults.variables.LD = "mingw32-gcc" 475 defaults.variables.LD = "mingw32-gcc"
476 defaults.variables.AR = "ar"
477 defaults.variables.RANLIB = "ranlib"
470 defaults.variables.CFLAGS = "-O2" 478 defaults.variables.CFLAGS = "-O2"
471 defaults.variables.LIBFLAG = "-shared" 479 defaults.variables.LIBFLAG = "-shared"
472 defaults.external_deps_patterns = { 480 defaults.external_deps_patterns = {
@@ -486,6 +494,7 @@ end
486 494
487if cfg.platforms.unix then 495if cfg.platforms.unix then
488 defaults.lib_extension = "so" 496 defaults.lib_extension = "so"
497 defaults.static_lib_extension = "a"
489 defaults.external_lib_extension = "so" 498 defaults.external_lib_extension = "so"
490 defaults.obj_extension = "o" 499 defaults.obj_extension = "o"
491 defaults.external_deps_dirs = { "/usr/local", "/usr" } 500 defaults.external_deps_dirs = { "/usr/local", "/usr" }
@@ -558,7 +567,7 @@ if cfg.platforms.macosx then
558 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" 567 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load"
559 defaults.variables.STAT = "/usr/bin/stat" 568 defaults.variables.STAT = "/usr/bin/stat"
560 defaults.variables.STATFLAG = "-f '%A'" 569 defaults.variables.STATFLAG = "-f '%A'"
561 local version = io.popen("sw_vers -productVersion"):read("*l") 570 local version = util.popen_read("sw_vers -productVersion")
562 version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3 571 version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3
563 if version >= 10 then 572 if version >= 10 then
564 version = 8 573 version = 8
@@ -617,8 +626,8 @@ end
617if package.loaded.jit then 626if package.loaded.jit then
618 -- LuaJIT 627 -- LuaJIT
619 local lj_version = package.loaded.jit.version:match("LuaJIT (.*)"):gsub("%-","") 628 local lj_version = package.loaded.jit.version:match("LuaJIT (.*)"):gsub("%-","")
620 --defaults.rocks_provided["luajit"] = lj_version.."-1"
621 defaults.rocks_provided["luabitop"] = lj_version.."-1" 629 defaults.rocks_provided["luabitop"] = lj_version.."-1"
630 defaults.rocks_provided_3_0["luajit"] = lj_version.."-1"
622end 631end
623 632
624-- Use defaults: 633-- Use defaults:
@@ -635,6 +644,7 @@ for _, entry in ipairs({"variables", "rocks_provided"}) do
635 end 644 end
636 end 645 end
637end 646end
647setmetatable(defaults.rocks_provided_3_0, { __index = cfg.rocks_provided })
638 648
639-- For values not set in the config file, use values from the 'defaults' table. 649-- For values not set in the config file, use values from the 'defaults' table.
640local cfg_mt = { 650local cfg_mt = {
diff --git a/src/luarocks/config_cmd.lua b/src/luarocks/config_cmd.lua
index fe3cc637..9e73d228 100644
--- a/src/luarocks/config_cmd.lua
+++ b/src/luarocks/config_cmd.lua
@@ -6,7 +6,6 @@ local cfg = require("luarocks.cfg")
6local util = require("luarocks.util") 6local util = require("luarocks.util")
7local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
8 8
9util.add_run_function(config_cmd)
10config_cmd.help_summary = "Query information about the LuaRocks configuration." 9config_cmd.help_summary = "Query information about the LuaRocks configuration."
11config_cmd.help_arguments = "<flag>" 10config_cmd.help_arguments = "<flag>"
12config_cmd.help = [[ 11config_cmd.help = [[
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index f8deff3c..0d85d33e 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -158,6 +158,15 @@ function deps.compare_versions(a, b)
158 return deps.parse_version(a) > deps.parse_version(b) 158 return deps.parse_version(a) > deps.parse_version(b)
159end 159end
160 160
161--- Check if rockspec format version satisfies version requirement.
162-- @param rockspec table: The rockspec table.
163-- @param version string: required version.
164-- @return boolean: true if rockspec format matches version or is newer, false otherwise.
165function deps.format_is_at_least(rockspec, version)
166 local rockspec_format = rockspec.rockspec_format or "1.0"
167 return deps.parse_version(rockspec_format) >= deps.parse_version(version)
168end
169
161--- Consumes a constraint from a string, converting it to table format. 170--- Consumes a constraint from a string, converting it to table format.
162-- For example, a string ">= 1.0, > 2.0" is converted to a table in the 171-- For example, a string ">= 1.0, > 2.0" is converted to a table in the
163-- format {op = ">=", version={1,0}} and the rest, "> 2.0", is returned 172-- format {op = ">=", version={1,0}} and the rest, "> 2.0", is returned
@@ -321,15 +330,19 @@ end
321-- @param dep table: A dependency parsed in table format. 330-- @param dep table: A dependency parsed in table format.
322-- @param blacklist table: Versions that can't be accepted. Table where keys 331-- @param blacklist table: Versions that can't be accepted. Table where keys
323-- are program versions and values are 'true'. 332-- are program versions and values are 'true'.
333-- @param provided table: A table of auto-dependencies provided
334-- by this Lua implementation for the given dependency.
324-- @return string or nil: latest installed version of the rock matching the dependency 335-- @return string or nil: latest installed version of the rock matching the dependency
325-- or nil if it could not be matched. 336-- or nil if it could not be matched.
326local function match_dep(dep, blacklist, deps_mode) 337local function match_dep(dep, blacklist, deps_mode, rocks_provided)
327 assert(type(dep) == "table") 338 assert(type(dep) == "table")
328 339 assert(type(rocks_provided) == "table")
340
329 local versions 341 local versions
330 if cfg.rocks_provided[dep.name] then 342 local provided = rocks_provided[dep.name]
331 -- provided rocks have higher priority than manifest's rocks 343 if provided then
332 versions = { cfg.rocks_provided[dep.name] } 344 -- Provided rocks have higher priority than manifest's rocks.
345 versions = { provided }
333 else 346 else
334 versions = manif_core.get_versions(dep.name, deps_mode) 347 versions = manif_core.get_versions(dep.name, deps_mode)
335 end 348 end
@@ -366,9 +379,9 @@ function deps.match_deps(rockspec, blacklist, deps_mode)
366 local matched, missing, no_upgrade = {}, {}, {} 379 local matched, missing, no_upgrade = {}, {}, {}
367 380
368 for _, dep in ipairs(rockspec.dependencies) do 381 for _, dep in ipairs(rockspec.dependencies) do
369 local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode) 382 local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode, rockspec.rocks_provided)
370 if found then 383 if found then
371 if not cfg.rocks_provided[dep.name] then 384 if not rockspec.rocks_provided[dep.name] then
372 matched[dep] = {name = dep.name, version = found} 385 matched[dep] = {name = dep.name, version = found}
373 end 386 end
374 else 387 else
@@ -393,10 +406,10 @@ local function values_set(tbl)
393 return set 406 return set
394end 407end
395 408
396local function rock_status(name, deps_mode) 409local function rock_status(name, deps_mode, rocks_provided)
397 local search = require("luarocks.search") 410 local search = require("luarocks.search")
398 local installed = match_dep(search.make_query(name), nil, deps_mode) 411 local installed = match_dep(search.make_query(name), nil, deps_mode, rocks_provided)
399 local installation_type = cfg.rocks_provided[name] and "provided by VM" or "installed" 412 local installation_type = rocks_provided[name] and "provided by VM" or "installed"
400 return installed and installed.." "..installation_type or "not installed" 413 return installed and installed.." "..installation_type or "not installed"
401end 414end
402 415
@@ -442,27 +455,27 @@ function deps.fulfill_dependencies(rockspec, deps_mode)
442 local first_missing_dep = true 455 local first_missing_dep = true
443 456
444 for _, dep in ipairs(rockspec.dependencies) do 457 for _, dep in ipairs(rockspec.dependencies) do
445 if not match_dep(dep, nil, deps_mode) then 458 if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then
446 if first_missing_dep then 459 if first_missing_dep then
447 util.printout(("Missing dependencies for %s %s:"):format(rockspec.name, rockspec.version)) 460 util.printout(("Missing dependencies for %s %s:"):format(rockspec.name, rockspec.version))
448 first_missing_dep = false 461 first_missing_dep = false
449 end 462 end
450 463
451 util.printout((" %s (%s)"):format(deps.show_dep(dep), rock_status(dep.name, deps_mode))) 464 util.printout((" %s (%s)"):format(deps.show_dep(dep), rock_status(dep.name, deps_mode, rockspec.rocks_provided)))
452 end 465 end
453 end 466 end
454 467
455 first_missing_dep = true 468 first_missing_dep = true
456 469
457 for _, dep in ipairs(rockspec.dependencies) do 470 for _, dep in ipairs(rockspec.dependencies) do
458 if not match_dep(dep, nil, deps_mode) then 471 if not match_dep(dep, nil, deps_mode, rockspec.rocks_provided) then
459 if first_missing_dep then 472 if first_missing_dep then
460 util.printout() 473 util.printout()
461 first_missing_dep = false 474 first_missing_dep = false
462 end 475 end
463 476
464 util.printout(("%s %s depends on %s (%s)"):format( 477 util.printout(("%s %s depends on %s (%s)"):format(
465 rockspec.name, rockspec.version, deps.show_dep(dep), rock_status(dep.name, deps_mode))) 478 rockspec.name, rockspec.version, deps.show_dep(dep), rock_status(dep.name, deps_mode, rockspec.rocks_provided)))
466 479
467 if dep.constraints[1] and dep.constraints[1].no_upgrade then 480 if dep.constraints[1] and dep.constraints[1].no_upgrade then
468 util.printerr("This version of "..rockspec.name.." is designed for use with") 481 util.printerr("This version of "..rockspec.name.." is designed for use with")
@@ -709,7 +722,10 @@ function deps.scan_deps(results, missing, manifest, name, version, deps_mode)
709 end 722 end
710 dependencies_name[version] = rockspec.dependencies 723 dependencies_name[version] = rockspec.dependencies
711 else 724 else
712 rockspec = { dependencies = deplist } 725 rockspec = {
726 dependencies = deplist,
727 rocks_provided = setmetatable({}, { __index = cfg.rocks_provided_3_0 })
728 }
713 end 729 end
714 local matched, failures = deps.match_deps(rockspec, nil, deps_mode) 730 local matched, failures = deps.match_deps(rockspec, nil, deps_mode)
715 results[name] = results 731 results[name] = results
@@ -744,8 +760,4 @@ function deps.get_deps_mode(flags)
744 end 760 end
745end 761end
746 762
747function deps.deps_mode_to_flag(deps_mode)
748 return "--deps-mode="..deps_mode
749end
750
751return deps 763return deps
diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua
index ec2b1110..758fd9c5 100644
--- a/src/luarocks/doc.lua
+++ b/src/luarocks/doc.lua
@@ -12,7 +12,6 @@ local fetch = require("luarocks.fetch")
12local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
13local download = require("luarocks.download") 13local download = require("luarocks.download")
14 14
15util.add_run_function(doc)
16doc.help_summary = "Show documentation for an installed rock." 15doc.help_summary = "Show documentation for an installed rock."
17 16
18doc.help = [[ 17doc.help = [[
diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua
index 18573ae4..d793cab7 100644
--- a/src/luarocks/download.lua
+++ b/src/luarocks/download.lua
@@ -12,7 +12,6 @@ local fs = require("luarocks.fs")
12local dir = require("luarocks.dir") 12local dir = require("luarocks.dir")
13local cfg = require("luarocks.cfg") 13local cfg = require("luarocks.cfg")
14 14
15util.add_run_function(download)
16download.help_summary = "Download a specific rock file from a rocks server." 15download.help_summary = "Download a specific rock file from a rocks server."
17download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]" 16download.help_arguments = "[--all] [--arch=<arch> | --source | --rockspec] [<name> [<version>]]"
18 17
diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua
index 824a3731..2590afd4 100644
--- a/src/luarocks/fetch.lua
+++ b/src/luarocks/fetch.lua
@@ -244,10 +244,19 @@ function fetch.load_local_rockspec(filename, quick)
244 rockspec.local_filename = filename 244 rockspec.local_filename = filename
245 local filebase = rockspec.source.file or rockspec.source.url 245 local filebase = rockspec.source.file or rockspec.source.url
246 local base = fetch.url_to_base_dir(filebase) 246 local base = fetch.url_to_base_dir(filebase)
247 rockspec.source.dir_set = rockspec.source.dir ~= nil
247 rockspec.source.dir = rockspec.source.dir 248 rockspec.source.dir = rockspec.source.dir
248 or rockspec.source.module 249 or rockspec.source.module
249 or ((filebase:match("%.lua$") or filebase:match("%.c$")) and ".") 250 or ( (filebase:match("%.lua$") or filebase:match("%.c$"))
251 and (deps.format_is_at_least(rockspec, "3.0")
252 and (fetch.is_basic_protocol(protocol) and "." or base)
253 or ".") )
250 or base 254 or base
255
256 rockspec.rocks_provided = (deps.format_is_at_least(rockspec, "3.0")
257 and cfg.rocks_provided_3_0
258 or cfg.rocks_provided)
259
251 if rockspec.dependencies then 260 if rockspec.dependencies then
252 for i = 1, #rockspec.dependencies do 261 for i = 1, #rockspec.dependencies do
253 local parsed, err = deps.parse_dep(rockspec.dependencies[i]) 262 local parsed, err = deps.parse_dep(rockspec.dependencies[i])
@@ -347,7 +356,29 @@ function fetch.get_sources(rockspec, extract, dest_dir)
347 ok, err = fs.unpack_archive(rockspec.source.file) 356 ok, err = fs.unpack_archive(rockspec.source.file)
348 if not ok then return nil, err end 357 if not ok then return nil, err end
349 if not fs.exists(rockspec.source.dir) then 358 if not fs.exists(rockspec.source.dir) then
350 return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir 359
360 -- If rockspec.source.dir can't be found, see if we only have one
361 -- directory in store_dir. If that's the case, assume it's what
362 -- we're looking for.
363 -- We only do this if the rockspec source.dir was not set, and only
364 -- with rockspecs newer than 3.0.
365 local dir_count, found_dir = 0
366
367 if not rockspec.source.dir_set and deps.format_is_at_least(rockspec, "3.0") then
368 local files = fs.list_dir()
369 for _, f in ipairs(files) do
370 if fs.is_dir(f) then
371 dir_count = dir_count + 1
372 found_dir = f
373 end
374 end
375 end
376
377 if dir_count == 1 then
378 rockspec.source.dir = found_dir
379 else
380 return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir
381 end
351 end 382 end
352 fs.pop_dir() 383 fs.pop_dir()
353 end 384 end
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index f61d89e9..eaba7ffd 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -6,20 +6,48 @@ local unpack = unpack or table.unpack
6 6
7local fs = require("luarocks.fs") 7local fs = require("luarocks.fs")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local deps = require("luarocks.deps")
9local util = require("luarocks.util") 10local util = require("luarocks.util")
10 11
12local cached_git_version
13
14--- Get git version.
15-- @param git_cmd string: name of git command.
16-- @return table: git version as returned by luarocks.deps.parse_version.
17local function git_version(git_cmd)
18 if not cached_git_version then
19 local version_line = io.popen(fs.Q(git_cmd)..' --version'):read()
20 local version_string = version_line:match('%d-%.%d+%.?%d*')
21 cached_git_version = deps.parse_version(version_string)
22 end
23
24 return cached_git_version
25end
26
27--- Check if git satisfies version requirement.
28-- @param git_cmd string: name of git command.
29-- @param version string: required version.
30-- @return boolean: true if git matches version or is newer, false otherwise.
31local function git_is_at_least(git_cmd, version)
32 return git_version(git_cmd) >= deps.parse_version(version)
33end
34
11--- Git >= 1.7.10 can clone a branch **or tag**, < 1.7.10 by branch only. We 35--- Git >= 1.7.10 can clone a branch **or tag**, < 1.7.10 by branch only. We
12-- need to know this in order to build the appropriate command; if we can't 36-- need to know this in order to build the appropriate command; if we can't
13-- clone by tag then we'll have to issue a subsequent command to check out the 37-- clone by tag then we'll have to issue a subsequent command to check out the
14-- given tag. 38-- given tag.
39-- @param git_cmd string: name of git command.
15-- @return boolean: Whether Git can clone by tag. 40-- @return boolean: Whether Git can clone by tag.
16local function git_can_clone_by_tag(git_cmd) 41local function git_can_clone_by_tag(git_cmd)
17 local version_string = io.popen(fs.Q(git_cmd)..' --version'):read() 42 return git_is_at_least(git_cmd, "1.7.10")
18 local major, minor, tiny = version_string:match('(%d-)%.(%d+)%.?(%d*)') 43end
19 major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0 44
20 local value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10))) 45--- Git >= 1.8.4 can fetch submodules shallowly, saving bandwidth and time for
21 git_can_clone_by_tag = function() return value end 46-- submodules with large history.
22 return value 47-- @param git_cmd string: name of git command.
48-- @return boolean: Whether Git can fetch submodules shallowly.
49local function git_supports_shallow_submodules(git_cmd)
50 return git_is_at_least(git_cmd, "1.8.4")
23end 51end
24 52
25--- Download sources for building a rock, using git. 53--- Download sources for building a rock, using git.
@@ -76,12 +104,25 @@ function git.get_sources(rockspec, extract, dest_dir, depth)
76 ok, err = fs.change_dir(module) 104 ok, err = fs.change_dir(module)
77 if not ok then return nil, err end 105 if not ok then return nil, err end
78 if tag_or_branch and not git_can_clone_by_tag() then 106 if tag_or_branch and not git_can_clone_by_tag() then
79 local checkout_command = {fs.Q(git_cmd), "checkout", tag_or_branch} 107 if not fs.execute(fs.Q(git_cmd), "checkout", tag_or_branch) then
80 if not fs.execute(unpack(checkout_command)) then
81 return nil, 'Failed to check out the "' .. tag_or_branch ..'" tag or branch.' 108 return nil, 'Failed to check out the "' .. tag_or_branch ..'" tag or branch.'
82 end 109 end
83 end 110 end
84 111
112 -- Fetching git submodules is supported only when rockspec format is >= 3.0.
113 if deps.format_is_at_least(rockspec, "3.0") then
114 command = {fs.Q(git_cmd), "submodule", "update", "--init", "--recursive"}
115
116 if git_supports_shallow_submodules(git_cmd) then
117 -- Fetch only the last commit of each submodule.
118 table.insert(command, 5, "--depth=1")
119 end
120
121 if not fs.execute(unpack(command)) then
122 return nil, 'Failed to fetch submodules.'
123 end
124 end
125
85 fs.delete(dir.path(store_dir, module, ".git")) 126 fs.delete(dir.path(store_dir, module, ".git"))
86 fs.delete(dir.path(store_dir, module, ".gitignore")) 127 fs.delete(dir.path(store_dir, module, ".gitignore"))
87 fs.pop_dir() 128 fs.pop_dir()
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua
index 28f97702..5bac77ce 100644
--- a/src/luarocks/help.lua
+++ b/src/luarocks/help.lua
@@ -12,7 +12,6 @@ local dir = require("luarocks.dir")
12 12
13local program = util.this_program("luarocks") 13local program = util.this_program("luarocks")
14 14
15util.add_run_function(help)
16help.help_summary = "Help on commands. Type '"..program.." help <command>' for more." 15help.help_summary = "Help on commands. Type '"..program.." help <command>' for more."
17 16
18help.help_arguments = "[<command>]" 17help.help_arguments = "[<command>]"
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index acbf584a..10d57f37 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -13,7 +13,6 @@ local manif = require("luarocks.manif")
13local remove = require("luarocks.remove") 13local remove = require("luarocks.remove")
14local cfg = require("luarocks.cfg") 14local cfg = require("luarocks.cfg")
15 15
16util.add_run_function(install)
17install.help_summary = "Install a rock." 16install.help_summary = "Install a rock."
18 17
19install.help_arguments = "{<rock>|<name> [<version>]}" 18install.help_arguments = "{<rock>|<name> [<version>]}"
diff --git a/src/luarocks/lint.lua b/src/luarocks/lint.lua
index d5cc48d0..4c30804b 100644
--- a/src/luarocks/lint.lua
+++ b/src/luarocks/lint.lua
@@ -8,7 +8,6 @@ local util = require("luarocks.util")
8local download = require("luarocks.download") 8local download = require("luarocks.download")
9local fetch = require("luarocks.fetch") 9local fetch = require("luarocks.fetch")
10 10
11util.add_run_function(lint)
12lint.help_summary = "Check syntax of a rockspec." 11lint.help_summary = "Check syntax of a rockspec."
13lint.help_arguments = "<rockspec>" 12lint.help_arguments = "<rockspec>"
14lint.help = [[ 13lint.help = [[
diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua
index c65e058f..8c9c5107 100644
--- a/src/luarocks/list.lua
+++ b/src/luarocks/list.lua
@@ -10,7 +10,6 @@ local cfg = require("luarocks.cfg")
10local util = require("luarocks.util") 10local util = require("luarocks.util")
11local path = require("luarocks.path") 11local path = require("luarocks.path")
12 12
13util.add_run_function(list)
14list.help_summary = "List currently installed rocks." 13list.help_summary = "List currently installed rocks."
15list.help_arguments = "[--porcelain] <filter>" 14list.help_arguments = "[--porcelain] <filter>"
16list.help = [[ 15list.help = [[
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua
index 1464def7..476150eb 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/make.lua
@@ -15,7 +15,6 @@ local pack = require("luarocks.pack")
15local remove = require("luarocks.remove") 15local remove = require("luarocks.remove")
16local deps = require("luarocks.deps") 16local deps = require("luarocks.deps")
17 17
18util.add_run_function(make)
19make.help_summary = "Compile package in current directory using a rockspec." 18make.help_summary = "Compile package in current directory using a rockspec."
20make.help_arguments = "[--pack-binary-rock] [<rockspec>]" 19make.help_arguments = "[--pack-binary-rock] [<rockspec>]"
21make.help = [[ 20make.help = [[
diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua
index c39c2939..b89ba47f 100644
--- a/src/luarocks/make_manifest.lua
+++ b/src/luarocks/make_manifest.lua
@@ -12,7 +12,6 @@ local deps = require("luarocks.deps")
12local fs = require("luarocks.fs") 12local fs = require("luarocks.fs")
13local dir = require("luarocks.dir") 13local dir = require("luarocks.dir")
14 14
15util.add_run_function(make_manifest)
16make_manifest.help_summary = "Compile a manifest file for a repository." 15make_manifest.help_summary = "Compile a manifest file for a repository."
17 16
18make_manifest.help = [[ 17make_manifest.help = [[
diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua
index bd73e308..eb5dea25 100644
--- a/src/luarocks/new_version.lua
+++ b/src/luarocks/new_version.lua
@@ -10,7 +10,6 @@ local persist = require("luarocks.persist")
10local fs = require("luarocks.fs") 10local fs = require("luarocks.fs")
11local type_check = require("luarocks.type_check") 11local type_check = require("luarocks.type_check")
12 12
13util.add_run_function(new_version)
14new_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."
15new_version.help_arguments = "[--tag=<tag>] [<package>|<rockspec>] [<new_version>] [<new_url>]" 14new_version.help_arguments = "[--tag=<tag>] [<package>|<rockspec>] [<new_version>] [<new_url>]"
16new_version.help = [[ 15new_version.help = [[
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua
index 277cf246..3a163e92 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.lua
@@ -16,7 +16,6 @@ local dir = require("luarocks.dir")
16local manif = require("luarocks.manif") 16local manif = require("luarocks.manif")
17local search = require("luarocks.search") 17local search = require("luarocks.search")
18 18
19util.add_run_function(pack)
20pack.help_summary = "Create a rock, packing sources or binaries." 19pack.help_summary = "Create a rock, packing sources or binaries."
21pack.help_arguments = "{<rockspec>|<name> [<version>]}" 20pack.help_arguments = "{<rockspec>|<name> [<version>]}"
22pack.help = [[ 21pack.help = [[
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index dafc64e7..6219d8c6 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -250,6 +250,11 @@ function path.path_to_module(file)
250 name = file:match("(.*)%."..cfg.lib_extension.."$") 250 name = file:match("(.*)%."..cfg.lib_extension.."$")
251 if name then 251 if name then
252 name = name:gsub(dir.separator, ".") 252 name = name:gsub(dir.separator, ".")
253 else
254 name = file:match("(.*)%."..cfg.static_lib_extension.."$")
255 if name then
256 name = name:gsub(dir.separator, ".")
257 end
253 end 258 end
254 end 259 end
255 if not name then name = file end 260 if not name then name = file end
diff --git a/src/luarocks/path_cmd.lua b/src/luarocks/path_cmd.lua
index 15fb9ca2..c0329977 100644
--- a/src/luarocks/path_cmd.lua
+++ b/src/luarocks/path_cmd.lua
@@ -7,7 +7,6 @@ local util = require("luarocks.util")
7local deps = require("luarocks.deps") 7local deps = require("luarocks.deps")
8local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
9 9
10util.add_run_function(path_cmd)
11path_cmd.help_summary = "Return the currently configured package path." 10path_cmd.help_summary = "Return the currently configured package path."
12path_cmd.help_arguments = "" 11path_cmd.help_arguments = ""
13path_cmd.help = [[ 12path_cmd.help = [[
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua
index 1ce46c0f..18043cc3 100644
--- a/src/luarocks/purge.lua
+++ b/src/luarocks/purge.lua
@@ -14,7 +14,6 @@ local manif = require("luarocks.manif")
14local cfg = require("luarocks.cfg") 14local cfg = require("luarocks.cfg")
15local remove = require("luarocks.remove") 15local remove = require("luarocks.remove")
16 16
17util.add_run_function(purge)
18purge.help_summary = "Remove all installed rocks from a tree." 17purge.help_summary = "Remove all installed rocks from a tree."
19purge.help_arguments = "--tree=<tree> [--old-versions]" 18purge.help_arguments = "--tree=<tree> [--old-versions]"
20purge.help = [[ 19purge.help = [[
diff --git a/src/luarocks/refresh_cache.lua b/src/luarocks/refresh_cache.lua
index bbfd1f4d..1261044f 100644
--- a/src/luarocks/refresh_cache.lua
+++ b/src/luarocks/refresh_cache.lua
@@ -3,11 +3,9 @@
3local refresh_cache = {} 3local refresh_cache = {}
4package.loaded["luarocks.refresh_cache"] = refresh_cache 4package.loaded["luarocks.refresh_cache"] = refresh_cache
5 5
6local util = require("luarocks.util")
7local cfg = require("luarocks.cfg") 6local cfg = require("luarocks.cfg")
8local cache = require("luarocks.cache") 7local cache = require("luarocks.cache")
9 8
10util.add_run_function(refresh_cache)
11refresh_cache.help_summary = "Refresh local cache of a remote rocks server." 9refresh_cache.help_summary = "Refresh local cache of a remote rocks server."
12refresh_cache.help_arguments = "[--from=<server>]" 10refresh_cache.help_arguments = "[--from=<server>]"
13refresh_cache.help = [[ 11refresh_cache.help = [[
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index d72fabaf..3f62e89e 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -14,7 +14,6 @@ local cfg = require("luarocks.cfg")
14local manif = require("luarocks.manif") 14local manif = require("luarocks.manif")
15local fs = require("luarocks.fs") 15local fs = require("luarocks.fs")
16 16
17util.add_run_function(remove)
18remove.help_summary = "Uninstall a rock." 17remove.help_summary = "Uninstall a rock."
19remove.help_arguments = "[--force|--force-fast] <name> [<version>]" 18remove.help_arguments = "[--force|--force-fast] <name> [<version>]"
20remove.help = [[ 19remove.help = [[
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua
index eaa321d5..c3f00a7c 100644
--- a/src/luarocks/search.lua
+++ b/src/luarocks/search.lua
@@ -11,7 +11,6 @@ local deps = require("luarocks.deps")
11local cfg = require("luarocks.cfg") 11local cfg = require("luarocks.cfg")
12local util = require("luarocks.util") 12local util = require("luarocks.util")
13 13
14util.add_run_function(search)
15search.help_summary = "Query the LuaRocks servers." 14search.help_summary = "Query the LuaRocks servers."
16search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }" 15search.help_arguments = "[--source] [--binary] { <name> [<version>] | --all }"
17search.help = [[ 16search.help = [[
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua
index 01860e78..df992f5c 100644
--- a/src/luarocks/show.lua
+++ b/src/luarocks/show.lua
@@ -11,7 +11,6 @@ local deps = require("luarocks.deps")
11local fetch = require("luarocks.fetch") 11local fetch = require("luarocks.fetch")
12local manif = require("luarocks.manif") 12local manif = require("luarocks.manif")
13 13
14util.add_run_function(show)
15show.help_summary = "Show information about an installed rock." 14show.help_summary = "Show information about an installed rock."
16 15
17show.help = [[ 16show.help = [[
diff --git a/src/luarocks/tools/tar.lua b/src/luarocks/tools/tar.lua
index 637a6c95..ae5c83e2 100644
--- a/src/luarocks/tools/tar.lua
+++ b/src/luarocks/tools/tar.lua
@@ -56,10 +56,11 @@ end
56local function read_header_block(block) 56local function read_header_block(block)
57 local header = {} 57 local header = {}
58 header.name = nullterm(block:sub(1,100)) 58 header.name = nullterm(block:sub(1,100))
59 header.mode = nullterm(block:sub(101,108)) 59 header.mode = nullterm(block:sub(101,108)):gsub(" ", "")
60 header.uid = octal_to_number(nullterm(block:sub(109,116))) 60 header.uid = octal_to_number(nullterm(block:sub(109,116)))
61 header.gid = octal_to_number(nullterm(block:sub(117,124))) 61 header.gid = octal_to_number(nullterm(block:sub(117,124)))
62 header.size = octal_to_number(nullterm(block:sub(125,136))) 62 header.size = octal_to_number(nullterm(block:sub(125,136)))
63print("{"..block:sub(125,136).."}", "{"..nullterm(block:sub(125,136)).."}", "{"..octal_to_number(nullterm(block:sub(125,136))).."}", header.size)
63 header.mtime = octal_to_number(nullterm(block:sub(137,148))) 64 header.mtime = octal_to_number(nullterm(block:sub(137,148)))
64 header.chksum = octal_to_number(nullterm(block:sub(149,156))) 65 header.chksum = octal_to_number(nullterm(block:sub(149,156)))
65 header.typeflag = get_typeflag(block:sub(157,157)) 66 header.typeflag = get_typeflag(block:sub(157,157))
@@ -93,13 +94,14 @@ function tar.untar(filename, destdir)
93 local long_name, long_link_name 94 local long_name, long_link_name
94 while true do 95 while true do
95 local block 96 local block
96 repeat 97 repeat
97 block = tar_handle:read(blocksize) 98 block = tar_handle:read(blocksize)
98 until (not block) or checksum_header(block) > 256 99 until (not block) or checksum_header(block) > 256
99 if not block then break end 100 if not block then break end
100 local header, err = read_header_block(block) 101 local header, err = read_header_block(block)
101 if not header then 102 if not header then
102 util.printerr(err) 103 util.printerr(err)
104 return nil, err
103 end 105 end
104 106
105 local file_data = tar_handle:read(math.ceil(header.size / blocksize) * blocksize):sub(1,header.size) 107 local file_data = tar_handle:read(math.ceil(header.size / blocksize) * blocksize):sub(1,header.size)
diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua
index 82763401..287d8151 100644
--- a/src/luarocks/type_check.lua
+++ b/src/luarocks/type_check.lua
@@ -7,7 +7,7 @@ package.loaded["luarocks.type_check"] = type_check
7local cfg = require("luarocks.cfg") 7local cfg = require("luarocks.cfg")
8local deps = require("luarocks.deps") 8local deps = require("luarocks.deps")
9 9
10type_check.rockspec_format = "1.1" 10type_check.rockspec_format = "3.0"
11 11
12local string_1 = { _type = "string" } 12local string_1 = { _type = "string" }
13local number_1 = { _type = "number" } 13local number_1 = { _type = "number" }
diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua
index 2face005..4e4d9a06 100644
--- a/src/luarocks/unpack.lua
+++ b/src/luarocks/unpack.lua
@@ -11,7 +11,6 @@ local build = require("luarocks.build")
11local dir = require("luarocks.dir") 11local dir = require("luarocks.dir")
12local cfg = require("luarocks.cfg") 12local cfg = require("luarocks.cfg")
13 13
14util.add_run_function(unpack)
15unpack.help_summary = "Unpack the contents of a rock." 14unpack.help_summary = "Unpack the contents of a rock."
16unpack.help_arguments = "[--force] {<rock>|<name> [<version>]}" 15unpack.help_arguments = "[--force] {<rock>|<name> [<version>]}"
17unpack.help = [[ 16unpack.help = [[
diff --git a/src/luarocks/upload.lua b/src/luarocks/upload.lua
index 3adc1704..5031b1ef 100644
--- a/src/luarocks/upload.lua
+++ b/src/luarocks/upload.lua
@@ -7,7 +7,6 @@ local pack = require("luarocks.pack")
7local cfg = require("luarocks.cfg") 7local cfg = require("luarocks.cfg")
8local Api = require("luarocks.upload.api") 8local Api = require("luarocks.upload.api")
9 9
10util.add_run_function(upload)
11upload.help_summary = "Upload a rockspec to the public rocks repository." 10upload.help_summary = "Upload a rockspec to the public rocks repository."
12upload.help_arguments = "[--skip-pack] [--api-key=<key>] [--force] <rockspec>" 11upload.help_arguments = "[--skip-pack] [--api-key=<key>] [--force] <rockspec>"
13upload.help = [[ 12upload.help = [[
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index 532bea8b..d27710c1 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -8,6 +8,20 @@ local util = {}
8 8
9local unpack = unpack or table.unpack 9local unpack = unpack or table.unpack
10 10
11--- Run a process and read a its output.
12-- Equivalent to io.popen(cmd):read("*l"), except that it
13-- closes the fd right away.
14-- @param cmd string: The command to execute
15-- @param spec string: "*l" by default, to read a single line.
16-- May be used to read more, passing, for instance, "*a".
17-- @return string: the output of the program.
18function util.popen_read(cmd, spec)
19 local fd = io.popen(cmd)
20 local out = fd:read(spec or "*l")
21 fd:close()
22 return out
23end
24
11local scheduled_functions = {} 25local scheduled_functions = {}
12local debug = require("debug") 26local debug = require("debug")
13 27
@@ -196,13 +210,6 @@ function util.parse_flags(...)
196 return flags, unpack(out) 210 return flags, unpack(out)
197end 211end
198 212
199-- Adds legacy 'run' function to a command module.
200-- @param command table: command module with 'command' function,
201-- the added 'run' function calls it after parseing command-line arguments.
202function util.add_run_function(command)
203 command.run = function(...) return command.command(util.parse_flags(...)) end
204end
205
206--- Merges contents of src on top of dst's contents. 213--- Merges contents of src on top of dst's contents.
207-- @param dst Destination table, which will receive src's contents. 214-- @param dst Destination table, which will receive src's contents.
208-- @param src Table which provides new contents to dst. 215-- @param src Table which provides new contents to dst.
diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua
index c4570aa4..f0452bbd 100644
--- a/src/luarocks/validate.lua
+++ b/src/luarocks/validate.lua
@@ -11,7 +11,6 @@ local build = require("luarocks.build")
11local install = require("luarocks.install") 11local install = require("luarocks.install")
12local util = require("luarocks.util") 12local util = require("luarocks.util")
13 13
14util.add_run_function(validate)
15validate.help_summary = "Sandboxed test of build/install of all packages in a repository." 14validate.help_summary = "Sandboxed test of build/install of all packages in a repository."
16 15
17validate.help = [[ 16validate.help = [[
diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua
index 33edeb1b..68c00cce 100644
--- a/src/luarocks/write_rockspec.lua
+++ b/src/luarocks/write_rockspec.lua
@@ -11,7 +11,6 @@ local persist = require("luarocks.persist")
11local type_check = require("luarocks.type_check") 11local type_check = require("luarocks.type_check")
12local util = require("luarocks.util") 12local util = require("luarocks.util")
13 13
14util.add_run_function(write_rockspec)
15write_rockspec.help_summary = "Write a template for a rockspec file." 14write_rockspec.help_summary = "Write a template for a rockspec file."
16write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] [<url>|<path>]" 15write_rockspec.help_arguments = "[--output=<file> ...] [<name>] [<version>] [<url>|<path>]"
17write_rockspec.help = [[ 16write_rockspec.help = [[