aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2012-11-04 21:58:26 -0200
committerHisham Muhammad <hisham@gobolinux.org>2012-11-04 21:58:26 -0200
commit2f07e7d8385c34192781d6174b1613cda8a73666 (patch)
tree1bb13a067a0343b60fff67d5b7dfe75187a1ea44
parentb8b7281d4aacc31578f4e2c1f6664f8cd73e49a8 (diff)
parent8b8ff0119db3ad791d13a067fe7cfabdcc7bf329 (diff)
downloadluarocks-2f07e7d8385c34192781d6174b1613cda8a73666.tar.gz
luarocks-2f07e7d8385c34192781d6174b1613cda8a73666.tar.bz2
luarocks-2f07e7d8385c34192781d6174b1613cda8a73666.zip
Merge branch 'multitree': add --deps-mode flag and deps_mode config option.
See http://www.luarocks.org/en/Dependencies for the documentation.
-rw-r--r--src/luarocks/add.lua2
-rw-r--r--src/luarocks/admin_remove.lua2
-rw-r--r--src/luarocks/build.lua35
-rw-r--r--src/luarocks/cfg.lua5
-rw-r--r--src/luarocks/command_line.lua19
-rw-r--r--src/luarocks/deps.lua43
-rw-r--r--src/luarocks/dir.lua8
-rw-r--r--src/luarocks/fs/lua.lua41
-rw-r--r--src/luarocks/install.lua17
-rw-r--r--src/luarocks/list.lua12
-rw-r--r--src/luarocks/make.lua5
-rw-r--r--src/luarocks/make_manifest.lua7
-rw-r--r--src/luarocks/manif.lua28
-rw-r--r--src/luarocks/manif_core.lua24
-rw-r--r--src/luarocks/path.lua28
-rw-r--r--src/luarocks/purge.lua2
-rw-r--r--src/luarocks/remove.lua10
-rw-r--r--src/luarocks/repos.lua6
-rw-r--r--src/luarocks/show.lua10
-rw-r--r--src/luarocks/util.lua2
-rw-r--r--src/luarocks/validate.lua8
21 files changed, 205 insertions, 109 deletions
diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua
index bf3f8979..48b9964c 100644
--- a/src/luarocks/add.lua
+++ b/src/luarocks/add.lua
@@ -65,7 +65,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server)
65 fs.change_dir(local_cache) 65 fs.change_dir(local_cache)
66 66
67 util.printout("Updating manifest...") 67 util.printout("Updating manifest...")
68 manif.make_manifest(local_cache) 68 manif.make_manifest(local_cache, "one")
69 util.printout("Updating index.html...") 69 util.printout("Updating index.html...")
70 index.make_index(local_cache) 70 index.make_index(local_cache)
71 71
diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua
index f1268576..dc36e16e 100644
--- a/src/luarocks/admin_remove.lua
+++ b/src/luarocks/admin_remove.lua
@@ -61,7 +61,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve
61 fs.change_dir(local_cache) 61 fs.change_dir(local_cache)
62 62
63 util.printout("Updating manifest...") 63 util.printout("Updating manifest...")
64 manif.make_manifest(local_cache) 64 manif.make_manifest(local_cache, "one")
65 util.printout("Updating index.html...") 65 util.printout("Updating index.html...")
66 index.make_index(local_cache) 66 index.make_index(local_cache)
67 67
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua
index 6ffa0e79..d61d6611 100644
--- a/src/luarocks/build.lua
+++ b/src/luarocks/build.lua
@@ -111,10 +111,11 @@ end
111-- @param minimal_mode boolean: true if there's no need to fetch, 111-- @param minimal_mode boolean: true if there's no need to fetch,
112-- unpack or change dir (this is used by "luarocks make"). Implies 112-- unpack or change dir (this is used by "luarocks make"). Implies
113-- need_to_fetch = false. 113-- need_to_fetch = false.
114-- @param no_deps boolean: true if dependency check needs to be skipped 114-- @param deps_mode: string: Which trees to check dependencies for:
115-- "none", "one", "order" or "all".
115-- @return boolean or (nil, string, [string]): True if succeeded or 116-- @return boolean or (nil, string, [string]): True if succeeded or
116-- nil and an error message followed by an error code. 117-- nil and an error message followed by an error code.
117function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps) 118function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode)
118 assert(type(rockspec_file) == "string") 119 assert(type(rockspec_file) == "string")
119 assert(type(need_to_fetch) == "boolean") 120 assert(type(need_to_fetch) == "boolean")
120 121
@@ -127,10 +128,10 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps)
127 return nil, "Rockspec error: build type not specified" 128 return nil, "Rockspec error: build type not specified"
128 end 129 end
129 130
130 if no_deps then 131 if deps_mode == "none" then
131 util.printerr("Warning: skipping dependency checks.") 132 util.printerr("Warning: skipping dependency checks.")
132 else 133 else
133 local ok, err, errcode = deps.fulfill_dependencies(rockspec) 134 local ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode)
134 if err then 135 if err then
135 return nil, err, errcode 136 return nil, err, errcode
136 end 137 end
@@ -253,7 +254,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps)
253 ok, err = repos.run_hook(rockspec, "post_install") 254 ok, err = repos.run_hook(rockspec, "post_install")
254 if err then return nil, err end 255 if err then return nil, err end
255 256
256 ok, err = manif.update_manifest(name, version) 257 ok, err = manif.update_manifest(name, version, nil, deps_mode)
257 if err then return nil, err end 258 if err then return nil, err end
258 259
259 local license = "" 260 local license = ""
@@ -273,9 +274,11 @@ end
273-- @param rock_file string: local or remote filename of a rock. 274-- @param rock_file string: local or remote filename of a rock.
274-- @param need_to_fetch boolean: true if sources need to be fetched, 275-- @param need_to_fetch boolean: true if sources need to be fetched,
275-- false if the rockspec was obtained from inside a source rock. 276-- false if the rockspec was obtained from inside a source rock.
277-- @param deps_mode: string: Which trees to check dependencies for:
278-- "none", "one", "order" or "all".
276-- @return boolean or (nil, string, [string]): True if build was successful, 279-- @return boolean or (nil, string, [string]): True if build was successful,
277-- or false and an error message and an optional error code. 280-- or false and an error message and an optional error code.
278function build_rock(rock_file, need_to_fetch, no_deps) 281function build_rock(rock_file, need_to_fetch, deps_mode)
279 assert(type(rock_file) == "string") 282 assert(type(rock_file) == "string")
280 assert(type(need_to_fetch) == "boolean") 283 assert(type(need_to_fetch) == "boolean")
281 284
@@ -285,24 +288,24 @@ function build_rock(rock_file, need_to_fetch, no_deps)
285 end 288 end
286 local rockspec_file = path.rockspec_name_from_rock(rock_file) 289 local rockspec_file = path.rockspec_name_from_rock(rock_file)
287 fs.change_dir(unpack_dir) 290 fs.change_dir(unpack_dir)
288 local ok, err, errcode = build_rockspec(rockspec_file, need_to_fetch, false, no_deps) 291 local ok, err, errcode = build_rockspec(rockspec_file, need_to_fetch, false, deps_mode)
289 fs.pop_dir() 292 fs.pop_dir()
290 return ok, err, errcode 293 return ok, err, errcode
291end 294end
292 295
293local function do_build(name, version, no_deps) 296local function do_build(name, version, deps_mode)
294 if name:match("%.rockspec$") then 297 if name:match("%.rockspec$") then
295 return build_rockspec(name, true, false, no_deps) 298 return build_rockspec(name, true, false, deps_mode)
296 elseif name:match("%.src%.rock$") then 299 elseif name:match("%.src%.rock$") then
297 return build_rock(name, false, no_deps) 300 return build_rock(name, false, deps_mode)
298 elseif name:match("%.all%.rock$") then 301 elseif name:match("%.all%.rock$") then
299 local install = require("luarocks.install") 302 local install = require("luarocks.install")
300 return install.install_binary_rock(name, no_deps) 303 return install.install_binary_rock(name, deps_mode)
301 elseif name:match("%.rock$") then 304 elseif name:match("%.rock$") then
302 return build_rock(name, true, no_deps) 305 return build_rock(name, true, deps_mode)
303 elseif not name:match(dir.separator) then 306 elseif not name:match(dir.separator) then
304 local search = require("luarocks.search") 307 local search = require("luarocks.search")
305 return search.act_on_src_or_rockspec(run, name:lower(), version, no_deps and "--nodeps") 308 return search.act_on_src_or_rockspec(run, name:lower(), version, deps.deps_mode_to_flag(deps_mode))
306 end 309 end
307 return nil, "Don't know what to do with "..name 310 return nil, "Don't know what to do with "..name
308end 311end
@@ -323,10 +326,10 @@ function run(...)
323 assert(type(version) == "string" or not version) 326 assert(type(version) == "string" or not version)
324 327
325 if flags["pack-binary-rock"] then 328 if flags["pack-binary-rock"] then
326 return pack.pack_binary_rock(name, version, do_build, name, version, flags["nodeps"]) 329 return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags))
327 else 330 else
328 local ok, err = fs.check_command_permissions(flags) 331 local ok, err = fs.check_command_permissions(flags)
329 if not ok then return nil, err end 332 if not ok then return nil, err end
330 return do_build(name, version, flags["nodeps"]) 333 return do_build(name, version, deps.get_deps_mode(flags))
331 end 334 end
332end 335end
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index d4222998..0e43768e 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -165,6 +165,7 @@ local defaults = {
165 use_extensions = false, 165 use_extensions = false,
166 accept_unknown_fields = false, 166 accept_unknown_fields = false,
167 fs_use_modules = true, 167 fs_use_modules = true,
168 deps_mode = "one",
168 169
169 lua_modules_path = "/share/lua/"..lua_version, 170 lua_modules_path = "/share/lua/"..lua_version,
170 lib_modules_path = "/lib/lua/"..lua_version, 171 lib_modules_path = "/lib/lua/"..lua_version,
@@ -278,7 +279,7 @@ if detected.windows then
278 lib = { "?.dll", "lib?.dll" }, 279 lib = { "?.dll", "lib?.dll" },
279 include = { "?.h" } 280 include = { "?.h" }
280 } 281 }
281 defaults.export_path = "SET PATH=%s;%s" 282 defaults.export_path = "SET PATH=%s"
282 defaults.export_path_separator = ";" 283 defaults.export_path_separator = ";"
283 defaults.export_lua_path = "SET LUA_PATH=%s" 284 defaults.export_lua_path = "SET LUA_PATH=%s"
284 defaults.export_lua_cpath = "SET LUA_CPATH=%s" 285 defaults.export_lua_cpath = "SET LUA_CPATH=%s"
@@ -323,7 +324,7 @@ if detected.unix then
323 lib = { "lib?.so", "lib?.so.*" }, 324 lib = { "lib?.so", "lib?.so.*" },
324 include = { "?.h" } 325 include = { "?.h" }
325 } 326 }
326 defaults.export_path = "export PATH='%s:%s'" 327 defaults.export_path = "export PATH='%s'"
327 defaults.export_path_separator = ":" 328 defaults.export_path_separator = ":"
328 defaults.export_lua_path = "export LUA_PATH='%s'" 329 defaults.export_lua_path = "export LUA_PATH='%s'"
329 defaults.export_lua_cpath = "export LUA_CPATH='%s'" 330 defaults.export_lua_cpath = "export LUA_CPATH='%s'"
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index d08ffdfe..9e499fc2 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -4,9 +4,9 @@ module("luarocks.command_line", package.seeall)
4 4
5local util = require("luarocks.util") 5local util = require("luarocks.util")
6local cfg = require("luarocks.cfg") 6local cfg = require("luarocks.cfg")
7local fs = require("luarocks.fs")
8local path = require("luarocks.path") 7local path = require("luarocks.path")
9local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local deps = require("luarocks.deps")
10 10
11--- Display an error message and exit. 11--- Display an error message and exit.
12-- @param message string: The error message. 12-- @param message string: The error message.
@@ -50,6 +50,10 @@ function run_command(...)
50 if flags["only-from"] then flags["only-server"] = flags["only-from"] end 50 if flags["only-from"] then flags["only-server"] = flags["only-from"] end
51 if flags["only-sources-from"] then flags["only-sources"] = flags["only-sources-from"] end 51 if flags["only-sources-from"] then flags["only-sources"] = flags["only-sources-from"] end
52 if flags["to"] then flags["tree"] = flags["to"] end 52 if flags["to"] then flags["tree"] = flags["to"] end
53 if flags["nodeps"] then
54 flags["deps-mode"] = "none"
55 table.insert(args, "--deps-mode=none")
56 end
53 57
54 cfg.flags = flags 58 cfg.flags = flags
55 59
@@ -83,11 +87,16 @@ function run_command(...)
83 if cfg.local_by_default then 87 if cfg.local_by_default then
84 flags["local"] = true 88 flags["local"] = true
85 end 89 end
90
91 if flags["deps-mode"] and not deps.check_deps_mode_flag(flags["deps-mode"]) then
92 die("Invalid entry for --deps-mode.")
93 end
86 94
87 if flags["tree"] then 95 if flags["tree"] then
88 if flags["tree"] == true then 96 if flags["tree"] == true or flags["tree"] == "" then
89 die("Argument error: use --tree=<path>") 97 die("Argument error: use --tree=<path>")
90 end 98 end
99 local fs = require("luarocks.fs")
91 local root_dir = fs.absolute_name(flags["tree"]) 100 local root_dir = fs.absolute_name(flags["tree"])
92 path.use_tree(root_dir) 101 path.use_tree(root_dir)
93 elseif flags["local"] then 102 elseif flags["local"] then
@@ -136,6 +145,12 @@ function run_command(...)
136 end 145 end
137 146
138 if commands[command] then 147 if commands[command] then
148 -- TODO the interface of run should be modified, to receive the
149 -- flags table and the (possibly unpacked) nonflags arguments.
150 -- This would remove redundant parsing of arguments.
151 -- I'm not changing this now to avoid messing with the run()
152 -- interface, which I know some people use (even though
153 -- I never published it as a public API...)
139 local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) 154 local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err)
140 die(debug.traceback("LuaRocks "..cfg.program_version 155 die(debug.traceback("LuaRocks "..cfg.program_version
141 .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" 156 .." bug (please report at luarocks-developers@lists.sourceforge.net).\n"
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index 00e796b0..6d5f3fef 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -312,14 +312,14 @@ end
312-- @return table or nil: A table containing fields 'name' and 'version' 312-- @return table or nil: A table containing fields 'name' and 'version'
313-- representing an installed rock which matches the given dependency, 313-- representing an installed rock which matches the given dependency,
314-- or nil if it could not be matched. 314-- or nil if it could not be matched.
315local function match_dep(dep, blacklist) 315local function match_dep(dep, blacklist, deps_mode)
316 assert(type(dep) == "table") 316 assert(type(dep) == "table")
317 317
318 local versions 318 local versions
319 if dep.name == "lua" then 319 if dep.name == "lua" then
320 versions = { cfg.lua_version } 320 versions = { cfg.lua_version }
321 else 321 else
322 versions = manif_core.get_versions(dep.name) 322 versions = manif_core.get_versions(dep.name, deps_mode)
323 end 323 end
324 if not versions then 324 if not versions then
325 return nil 325 return nil
@@ -361,13 +361,13 @@ end
361-- in table format and values are tables containing fields 'name' and 361-- in table format and values are tables containing fields 'name' and
362-- version' representing matches, and a table of missing dependencies 362-- version' representing matches, and a table of missing dependencies
363-- parsed as tables. 363-- parsed as tables.
364function match_deps(rockspec, blacklist) 364function match_deps(rockspec, blacklist, deps_mode)
365 assert(type(rockspec) == "table") 365 assert(type(rockspec) == "table")
366 assert(type(blacklist) == "table" or not blacklist) 366 assert(type(blacklist) == "table" or not blacklist)
367 local matched, missing, no_upgrade = {}, {}, {} 367 local matched, missing, no_upgrade = {}, {}, {}
368 368
369 for _, dep in ipairs(rockspec.dependencies) do 369 for _, dep in ipairs(rockspec.dependencies) do
370 local found = match_dep(dep, blacklist and blacklist[dep.name] or nil) 370 local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode)
371 if found then 371 if found then
372 if dep.name ~= "lua" then 372 if dep.name ~= "lua" then
373 matched[dep] = found 373 matched[dep] = found
@@ -401,7 +401,7 @@ end
401-- @return boolean or (nil, string, [string]): True if no errors occurred, or 401-- @return boolean or (nil, string, [string]): True if no errors occurred, or
402-- nil and an error message if any test failed, followed by an optional 402-- nil and an error message if any test failed, followed by an optional
403-- error code. 403-- error code.
404function fulfill_dependencies(rockspec) 404function fulfill_dependencies(rockspec, deps_mode)
405 405
406 local search = require("luarocks.search") 406 local search = require("luarocks.search")
407 local install = require("luarocks.install") 407 local install = require("luarocks.install")
@@ -433,7 +433,7 @@ function fulfill_dependencies(rockspec)
433 end 433 end
434 end 434 end
435 435
436 local matched, missing, no_upgrade = match_deps(rockspec) 436 local matched, missing, no_upgrade = match_deps(rockspec, nil, deps_mode)
437 437
438 if next(no_upgrade) then 438 if next(no_upgrade) then
439 util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") 439 util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":")
@@ -467,7 +467,7 @@ function fulfill_dependencies(rockspec)
467 467
468 for _, dep in pairs(missing) do 468 for _, dep in pairs(missing) do
469 -- Double-check in case dependency was filled during recursion. 469 -- Double-check in case dependency was filled during recursion.
470 if not match_dep(dep) then 470 if not match_dep(dep, nil, deps_mode) then
471 local rock = search.find_suitable_rock(dep) 471 local rock = search.find_suitable_rock(dep)
472 if not rock then 472 if not rock then
473 return nil, "Could not satisfy dependency: "..show_dep(dep) 473 return nil, "Could not satisfy dependency: "..show_dep(dep)
@@ -640,7 +640,7 @@ end
640-- @param name string: Package name. 640-- @param name string: Package name.
641-- @param version string: Package version. 641-- @param version string: Package version.
642-- @return (table, table): The results and a table of missing dependencies. 642-- @return (table, table): The results and a table of missing dependencies.
643function scan_deps(results, missing, manifest, name, version) 643function scan_deps(results, missing, manifest, name, version, deps_mode)
644 assert(type(results) == "table") 644 assert(type(results) == "table")
645 assert(type(missing) == "table") 645 assert(type(missing) == "table")
646 assert(type(manifest) == "table") 646 assert(type(manifest) == "table")
@@ -669,9 +669,9 @@ function scan_deps(results, missing, manifest, name, version)
669 else 669 else
670 rockspec = { dependencies = deplist } 670 rockspec = { dependencies = deplist }
671 end 671 end
672 local matched, failures = match_deps(rockspec) 672 local matched, failures = match_deps(rockspec, nil, deps_mode)
673 for _, match in pairs(matched) do 673 for _, match in pairs(matched) do
674 results, missing = scan_deps(results, missing, manifest, match.name, match.version) 674 results, missing = scan_deps(results, missing, manifest, match.name, match.version, deps_mode)
675 end 675 end
676 if next(failures) then 676 if next(failures) then
677 for _, failure in pairs(failures) do 677 for _, failure in pairs(failures) do
@@ -681,3 +681,26 @@ function scan_deps(results, missing, manifest, name, version)
681 results[name] = version 681 results[name] = version
682 return results, missing 682 return results, missing
683end 683end
684
685local valid_deps_modes = {
686 one = true,
687 order = true,
688 all = true,
689 none = true,
690}
691
692function check_deps_mode_flag(flag)
693 return valid_deps_modes[flag]
694end
695
696function get_deps_mode(flags)
697 if flags["deps-mode"] then
698 return flags["deps-mode"]
699 else
700 return cfg.deps_mode
701 end
702end
703
704function deps_mode_to_flag(deps_mode)
705 return "--deps-mode="..deps_mode
706end
diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua
index 3de9e241..b496c962 100644
--- a/src/luarocks/dir.lua
+++ b/src/luarocks/dir.lua
@@ -26,10 +26,6 @@ function dir_name(pathname)
26 return (pathname:gsub("/*$", ""):match("(.*/)[^/]*")) or "" 26 return (pathname:gsub("/*$", ""):match("(.*/)[^/]*")) or ""
27end 27end
28 28
29function strip_base_dir(pathname)
30 return pathname:gsub("^[^/]*/", "")
31end
32
33--- Describe a path in a cross-platform way. 29--- Describe a path in a cross-platform way.
34-- Use this function to avoid platform-specific directory 30-- Use this function to avoid platform-specific directory
35-- separators in other modules. Removes trailing slashes from 31-- separators in other modules. Removes trailing slashes from
@@ -68,3 +64,7 @@ function split_url(url)
68 end 64 end
69 return protocol, pathname 65 return protocol, pathname
70end 66end
67
68function normalize(name)
69 return name:gsub("\\", "/"):gsub("(.)/*$", "%1")
70end
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 00c576dc..d6795773 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -23,7 +23,6 @@ if cfg.fs_use_modules then
23 posix_ok, posix = pcall(require, "posix") 23 posix_ok, posix = pcall(require, "posix")
24end 24end
25 25
26local tar = require("luarocks.tools.tar")
27local patch = require("luarocks.tools.patch") 26local patch = require("luarocks.tools.patch")
28 27
29local dir_stack = {} 28local dir_stack = {}
@@ -43,10 +42,6 @@ function Q(arg)
43 return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'" 42 return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'"
44end 43end
45 44
46local function normalize(name)
47 return name:gsub("\\", "/"):gsub("(.)/*$", "%1")
48end
49
50--- Test is file/dir is writable. 45--- Test is file/dir is writable.
51-- Warning: testing if a file/dir is writable does not guarantee 46-- Warning: testing if a file/dir is writable does not guarantee
52-- that it will remain writable and therefore it is no replacement 47-- that it will remain writable and therefore it is no replacement
@@ -55,7 +50,7 @@ end
55-- @return boolean: true if file exists, false otherwise. 50-- @return boolean: true if file exists, false otherwise.
56function is_writable(file) 51function is_writable(file)
57 assert(file) 52 assert(file)
58 file = normalize(file) 53 file = dir.normalize(file)
59 local result 54 local result
60 if fs.is_dir(file) then 55 if fs.is_dir(file) then
61 local file2 = dir.path(file, '.tmpluarockstestwritable') 56 local file2 = dir.path(file, '.tmpluarockstestwritable')
@@ -77,7 +72,7 @@ end
77-- @return string or nil: name of temporary directory or nil on failure. 72-- @return string or nil: name of temporary directory or nil on failure.
78function make_temp_dir(name) 73function make_temp_dir(name)
79 assert(type(name) == "string") 74 assert(type(name) == "string")
80 name = normalize(name) 75 name = dir.normalize(name)
81 76
82 local temp_dir = (os.getenv("TMP") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) 77 local temp_dir = (os.getenv("TMP") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000))
83 if fs.make_dir(temp_dir) then 78 if fs.make_dir(temp_dir) then
@@ -110,7 +105,7 @@ end
110-- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false if not 105-- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false if not
111-- or if it could not perform the check for any reason. 106-- or if it could not perform the check for any reason.
112function check_md5(file, md5sum) 107function check_md5(file, md5sum)
113 file = normalize(file) 108 file = dir.normalize(file)
114 local computed = fs.get_md5(file) 109 local computed = fs.get_md5(file)
115 if not computed then 110 if not computed then
116 return false 111 return false
@@ -156,7 +151,7 @@ end
156-- @param d string: The directory to switch to. 151-- @param d string: The directory to switch to.
157function change_dir(d) 152function change_dir(d)
158 table.insert(dir_stack, lfs.currentdir()) 153 table.insert(dir_stack, lfs.currentdir())
159 d = normalize(d) 154 d = dir.normalize(d)
160 lfs.chdir(d) 155 lfs.chdir(d)
161end 156end
162 157
@@ -187,7 +182,7 @@ end
187-- @return boolean: true on success, false on failure. 182-- @return boolean: true on success, false on failure.
188function make_dir(directory) 183function make_dir(directory)
189 assert(type(directory) == "string") 184 assert(type(directory) == "string")
190 directory = normalize(directory) 185 directory = dir.normalize(directory)
191 local path = nil 186 local path = nil
192 if directory:sub(2, 2) == ":" then 187 if directory:sub(2, 2) == ":" then
193 path = directory:sub(1, 2) 188 path = directory:sub(1, 2)
@@ -217,7 +212,7 @@ end
217-- @param d string: pathname of directory to remove. 212-- @param d string: pathname of directory to remove.
218function remove_dir_if_empty(d) 213function remove_dir_if_empty(d)
219 assert(d) 214 assert(d)
220 d = normalize(d) 215 d = dir.normalize(d)
221 lfs.rmdir(d) 216 lfs.rmdir(d)
222end 217end
223 218
@@ -227,7 +222,7 @@ end
227-- @param d string: pathname of directory to remove. 222-- @param d string: pathname of directory to remove.
228function remove_dir_tree_if_empty(d) 223function remove_dir_tree_if_empty(d)
229 assert(d) 224 assert(d)
230 d = normalize(d) 225 d = dir.normalize(d)
231 for i=1,10 do 226 for i=1,10 do
232 lfs.rmdir(d) 227 lfs.rmdir(d)
233 d = dir.dir_name(d) 228 d = dir.dir_name(d)
@@ -243,8 +238,8 @@ end
243-- plus an error message. 238-- plus an error message.
244function copy(src, dest, perms) 239function copy(src, dest, perms)
245 assert(src and dest) 240 assert(src and dest)
246 src = normalize(src) 241 src = dir.normalize(src)
247 dest = normalize(dest) 242 dest = dir.normalize(dest)
248 local destmode = lfs.attributes(dest, "mode") 243 local destmode = lfs.attributes(dest, "mode")
249 if destmode == "directory" then 244 if destmode == "directory" then
250 dest = dir.path(dest, dir.base_name(src)) 245 dest = dir.path(dest, dir.base_name(src))
@@ -296,8 +291,8 @@ end
296-- plus an error message. 291-- plus an error message.
297function copy_contents(src, dest) 292function copy_contents(src, dest)
298 assert(src and dest) 293 assert(src and dest)
299 src = normalize(src) 294 src = dir.normalize(src)
300 dest = normalize(dest) 295 dest = dir.normalize(dest)
301 assert(lfs.attributes(src, "mode") == "directory") 296 assert(lfs.attributes(src, "mode") == "directory")
302 297
303 for file in lfs.dir(src) do 298 for file in lfs.dir(src) do
@@ -338,7 +333,7 @@ end
338-- @param name string: Pathname of source 333-- @param name string: Pathname of source
339-- @return boolean: true on success, false on failure. 334-- @return boolean: true on success, false on failure.
340function delete(name) 335function delete(name)
341 name = normalize(name) 336 name = dir.normalize(name)
342 return recursive_delete(name) or false 337 return recursive_delete(name) or false
343end 338end
344 339
@@ -352,7 +347,7 @@ function list_dir(at)
352 if not at then 347 if not at then
353 at = fs.current_dir() 348 at = fs.current_dir()
354 end 349 end
355 at = normalize(at) 350 at = dir.normalize(at)
356 if not fs.is_dir(at) then 351 if not fs.is_dir(at) then
357 return {} 352 return {}
358 end 353 end
@@ -393,7 +388,7 @@ function find(at)
393 if not at then 388 if not at then
394 at = fs.current_dir() 389 at = fs.current_dir()
395 end 390 end
396 at = normalize(at) 391 at = dir.normalize(at)
397 if not fs.is_dir(at) then 392 if not fs.is_dir(at) then
398 return {} 393 return {}
399 end 394 end
@@ -407,7 +402,7 @@ end
407-- @return boolean: true if file exists, false otherwise. 402-- @return boolean: true if file exists, false otherwise.
408function exists(file) 403function exists(file)
409 assert(file) 404 assert(file)
410 file = normalize(file) 405 file = dir.normalize(file)
411 return type(lfs.attributes(file)) == "table" 406 return type(lfs.attributes(file)) == "table"
412end 407end
413 408
@@ -416,7 +411,7 @@ end
416-- @return boolean: true if it is a directory, false otherwise. 411-- @return boolean: true if it is a directory, false otherwise.
417function is_dir(file) 412function is_dir(file)
418 assert(file) 413 assert(file)
419 file = normalize(file) 414 file = dir.normalize(file)
420 return lfs.attributes(file, "mode") == "directory" 415 return lfs.attributes(file, "mode") == "directory"
421end 416end
422 417
@@ -425,12 +420,12 @@ end
425-- @return boolean: true if it is a file, false otherwise. 420-- @return boolean: true if it is a file, false otherwise.
426function is_file(file) 421function is_file(file)
427 assert(file) 422 assert(file)
428 file = normalize(file) 423 file = dir.normalize(file)
429 return lfs.attributes(file, "mode") == "file" 424 return lfs.attributes(file, "mode") == "file"
430end 425end
431 426
432function set_time(file, time) 427function set_time(file, time)
433 file = normalize(file) 428 file = dir.normalize(file)
434 return lfs.touch(file, time) 429 return lfs.touch(file, time)
435end 430end
436 431
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua
index 708d6abe..e633ea23 100644
--- a/src/luarocks/install.lua
+++ b/src/luarocks/install.lua
@@ -23,10 +23,11 @@ or a filename of a locally available rock.
23 23
24--- Install a binary rock. 24--- Install a binary rock.
25-- @param rock_file string: local or remote filename of a rock. 25-- @param rock_file string: local or remote filename of a rock.
26-- @param no_deps boolean: true if dependency check needs to be skipped 26-- @param deps_mode: string: Which trees to check dependencies for:
27-- "none", "one", "order" or "all".
27-- @return boolean or (nil, string, [string]): True if succeeded or 28-- @return boolean or (nil, string, [string]): True if succeeded or
28-- nil and an error message and an optional error code. 29-- nil and an error message and an optional error code.
29function install_binary_rock(rock_file, no_deps) 30function install_binary_rock(rock_file, deps_mode)
30 assert(type(rock_file) == "string") 31 assert(type(rock_file) == "string")
31 32
32 local name, version, arch = path.parse_name(rock_file) 33 local name, version, arch = path.parse_name(rock_file)
@@ -54,7 +55,7 @@ function install_binary_rock(rock_file, no_deps)
54 return nil, "Failed loading rockspec for installed package: "..err, errcode 55 return nil, "Failed loading rockspec for installed package: "..err, errcode
55 end 56 end
56 57
57 if no_deps then 58 if deps_mode == "none" then
58 util.printerr("Warning: skipping dependency checks.") 59 util.printerr("Warning: skipping dependency checks.")
59 else 60 else
60 ok, err, errcode = deps.check_external_deps(rockspec, "install") 61 ok, err, errcode = deps.check_external_deps(rockspec, "install")
@@ -67,8 +68,8 @@ function install_binary_rock(rock_file, no_deps)
67 if err then return nil, err end 68 if err then return nil, err end
68 end 69 end
69 70
70 if not no_deps then 71 if deps_mode ~= "none" then
71 ok, err, errcode = deps.fulfill_dependencies(rockspec) 72 ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode)
72 if err then return nil, err, errcode end 73 if err then return nil, err, errcode end
73 end 74 end
74 75
@@ -88,7 +89,7 @@ function install_binary_rock(rock_file, no_deps)
88 ok, err = repos.run_hook(rockspec, "post_install") 89 ok, err = repos.run_hook(rockspec, "post_install")
89 if err then return nil, err end 90 if err then return nil, err end
90 91
91 ok, err = manif.update_manifest(name, version) 92 ok, err = manif.update_manifest(name, version, nil, deps_mode)
92 if err then return nil, err end 93 if err then return nil, err end
93 94
94 local license = "" 95 local license = ""
@@ -126,9 +127,9 @@ function run(...)
126 if name:match("%.rockspec$") or name:match("%.src%.rock$") then 127 if name:match("%.rockspec$") or name:match("%.src%.rock$") then
127 util.printout("Using "..name.."... switching to 'build' mode") 128 util.printout("Using "..name.."... switching to 'build' mode")
128 local build = require("luarocks.build") 129 local build = require("luarocks.build")
129 return build.run(name, flags["local"] and "--local") 130 return build.run(name, deps.get_deps_mode(flags), flags["local"] and "--local")
130 elseif name:match("%.rock$") then 131 elseif name:match("%.rock$") then
131 return install_binary_rock(name, flags["nodeps"]) 132 return install_binary_rock(name, deps.get_deps_mode(flags))
132 else 133 else
133 local search = require("luarocks.search") 134 local search = require("luarocks.search")
134 local results, err = search.find_suitable_rock(search.make_query(name:lower(), version)) 135 local results, err = search.find_suitable_rock(search.make_query(name:lower(), version))
diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua
index f56fc7e9..6081ed43 100644
--- a/src/luarocks/list.lua
+++ b/src/luarocks/list.lua
@@ -9,9 +9,11 @@ local util = require("luarocks.util")
9local path = require("luarocks.path") 9local path = require("luarocks.path")
10 10
11help_summary = "Lists currently installed rocks." 11help_summary = "Lists currently installed rocks."
12 12help_arguments = "[--porcelain] <filter>"
13help = [[ 13help = [[
14<argument> is a substring of a rock name to filter by. 14<filter> is a substring of a rock name to filter by.
15
16--porcelain Produce machine-friendly output.
15]] 17]]
16 18
17--- Driver function for "list" command. 19--- Driver function for "list" command.
@@ -23,7 +25,11 @@ function run(...)
23 local results = {} 25 local results = {}
24 local query = search.make_query(filter and filter:lower() or "", version) 26 local query = search.make_query(filter and filter:lower() or "", version)
25 query.exact_name = false 27 query.exact_name = false
26 for _, tree in ipairs(cfg.rocks_trees) do 28 local trees = cfg.rocks_trees
29 if flags["tree"] then
30 trees = { flags["tree"] }
31 end
32 for _, tree in ipairs(trees) do
27 search.manifest_search(results, path.rocks_dir(tree), query) 33 search.manifest_search(results, path.rocks_dir(tree), query)
28 end 34 end
29 util.title("Installed rocks:", flags["porcelain"]) 35 util.title("Installed rocks:", flags["porcelain"])
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua
index 769db2f7..69c2162f 100644
--- a/src/luarocks/make.lua
+++ b/src/luarocks/make.lua
@@ -11,6 +11,7 @@ local util = require("luarocks.util")
11local cfg = require("luarocks.cfg") 11local cfg = require("luarocks.cfg")
12local fetch = require("luarocks.fetch") 12local fetch = require("luarocks.fetch")
13local pack = require("luarocks.pack") 13local pack = require("luarocks.pack")
14local deps = require("luarocks.deps")
14 15
15help_summary = "Compile package in current directory using a rockspec." 16help_summary = "Compile package in current directory using a rockspec."
16help_arguments = "[--pack-binary-rock] [<rockspec>]" 17help_arguments = "[--pack-binary-rock] [<rockspec>]"
@@ -62,10 +63,10 @@ function run(...)
62 if not rspec then 63 if not rspec then
63 return nil, err 64 return nil, err
64 end 65 end
65 return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, flags["nodeps"]) 66 return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.get_deps_mode(flags))
66 else 67 else
67 local ok, err = fs.check_command_permissions(flags) 68 local ok, err = fs.check_command_permissions(flags)
68 if not ok then return nil, err end 69 if not ok then return nil, err end
69 return build.build_rockspec(rockspec, false, true) 70 return build.build_rockspec(rockspec, false, true, deps.get_deps_mode(flags))
70 end 71 end
71end 72end
diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua
index 07d2fd05..845c9f8a 100644
--- a/src/luarocks/make_manifest.lua
+++ b/src/luarocks/make_manifest.lua
@@ -7,6 +7,7 @@ local manif = require("luarocks.manif")
7local index = require("luarocks.index") 7local index = require("luarocks.index")
8local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
9local util = require("luarocks.util") 9local util = require("luarocks.util")
10local deps = require("luarocks.deps")
10 11
11help_summary = "Compile a manifest file for a repository." 12help_summary = "Compile a manifest file for a repository."
12 13
@@ -19,13 +20,15 @@ help = [[
19-- the default local repository configured as cfg.rocks_dir is used. 20-- the default local repository configured as cfg.rocks_dir is used.
20-- @return boolean or (nil, string): True if manifest was generated, 21-- @return boolean or (nil, string): True if manifest was generated,
21-- or nil and an error message. 22-- or nil and an error message.
22function run(repo) 23function run(...)
24 local flags, repo = util.parse_flags(...)
25
23 assert(type(repo) == "string" or not repo) 26 assert(type(repo) == "string" or not repo)
24 repo = repo or cfg.rocks_dir 27 repo = repo or cfg.rocks_dir
25 28
26 util.printout("Making manifest for "..repo) 29 util.printout("Making manifest for "..repo)
27 30
28 local ok, err = manif.make_manifest(repo) 31 local ok, err = manif.make_manifest(repo, deps.get_deps_mode(flags))
29 if ok then 32 if ok then
30 util.printout("Generating index.html for "..repo) 33 util.printout("Generating index.html for "..repo)
31 index.make_index(repo) 34 index.make_index(repo)
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index 65a6beba..414c3262 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -185,14 +185,17 @@ end
185-- and any dependency inconsistencies or missing dependencies are reported to 185-- and any dependency inconsistencies or missing dependencies are reported to
186-- standard error. 186-- standard error.
187-- @param manifest table: a manifest table. 187-- @param manifest table: a manifest table.
188local function update_dependencies(manifest) 188local function update_dependencies(manifest, deps_mode)
189 assert(type(manifest) == "table")
190 assert(type(deps_mode) == "string")
191
189 for pkg, versions in pairs(manifest.repository) do 192 for pkg, versions in pairs(manifest.repository) do
190 for version, repositories in pairs(versions) do 193 for version, repositories in pairs(versions) do
191 local current = pkg.." "..version 194 local current = pkg.." "..version
192 for _, repo in ipairs(repositories) do 195 for _, repo in ipairs(repositories) do
193 if repo.arch == "installed" then 196 if repo.arch == "installed" then
194 local missing 197 local missing
195 repo.dependencies, missing = deps.scan_deps({}, {}, manifest, pkg, version) 198 repo.dependencies, missing = deps.scan_deps({}, {}, manifest, pkg, version, deps_mode)
196 repo.dependencies[pkg] = nil 199 repo.dependencies[pkg] = nil
197 if missing then 200 if missing then
198 for miss, err in pairs(missing) do 201 for miss, err in pairs(missing) do
@@ -214,9 +217,10 @@ end
214-- @param manifest table: A manifest table (must contain repository, modules, commands tables). 217-- @param manifest table: A manifest table (must contain repository, modules, commands tables).
215-- It will be altered to include the search results. 218-- It will be altered to include the search results.
216-- @return boolean or (nil, string): true in case of success, or nil followed by an error message. 219-- @return boolean or (nil, string): true in case of success, or nil followed by an error message.
217local function store_results(results, manifest) 220local function store_results(results, manifest, deps_mode)
218 assert(type(results) == "table") 221 assert(type(results) == "table")
219 assert(type(manifest) == "table") 222 assert(type(manifest) == "table")
223 assert(type(deps_mode) == "string")
220 224
221 for name, versions in pairs(results) do 225 for name, versions in pairs(results) do
222 local pkgtable = manifest.repository[name] or {} 226 local pkgtable = manifest.repository[name] or {}
@@ -239,7 +243,7 @@ local function store_results(results, manifest)
239 end 243 end
240 manifest.repository[name] = pkgtable 244 manifest.repository[name] = pkgtable
241 end 245 end
242 update_dependencies(manifest) 246 update_dependencies(manifest, deps_mode)
243 sort_package_matching_table(manifest.modules) 247 sort_package_matching_table(manifest.modules)
244 sort_package_matching_table(manifest.commands) 248 sort_package_matching_table(manifest.commands)
245 return true 249 return true
@@ -251,8 +255,11 @@ end
251-- @param repo A local repository directory. 255-- @param repo A local repository directory.
252-- @return boolean or (nil, string): True if manifest was generated, 256-- @return boolean or (nil, string): True if manifest was generated,
253-- or nil and an error message. 257-- or nil and an error message.
254function make_manifest(repo) 258function make_manifest(repo, deps_mode)
255 assert(type(repo) == "string") 259 assert(type(repo) == "string")
260 assert(type(deps_mode) == "string")
261
262 if deps_mode == "none" then deps_mode = cfg.deps_mode end
256 263
257 if not fs.is_dir(repo) then 264 if not fs.is_dir(repo) then
258 return nil, "Cannot access repository at "..repo 265 return nil, "Cannot access repository at "..repo
@@ -265,7 +272,7 @@ function make_manifest(repo)
265 local manifest = { repository = {}, modules = {}, commands = {} } 272 local manifest = { repository = {}, modules = {}, commands = {} }
266 manif_core.manifest_cache[repo] = manifest 273 manif_core.manifest_cache[repo] = manifest
267 274
268 local ok, err = store_results(results, manifest) 275 local ok, err = store_results(results, manifest, deps_mode)
269 if not ok then return nil, err end 276 if not ok then return nil, err end
270 277
271 return save_table(repo, "manifest", manifest) 278 return save_table(repo, "manifest", manifest)
@@ -281,17 +288,20 @@ end
281-- the default local repository configured as cfg.rocks_dir is used. 288-- the default local repository configured as cfg.rocks_dir is used.
282-- @return boolean or (nil, string): True if manifest was generated, 289-- @return boolean or (nil, string): True if manifest was generated,
283-- or nil and an error message. 290-- or nil and an error message.
284function update_manifest(name, version, repo) 291function update_manifest(name, version, repo, deps_mode)
285 assert(type(name) == "string") 292 assert(type(name) == "string")
286 assert(type(version) == "string") 293 assert(type(version) == "string")
287 repo = path.rocks_dir(repo or cfg.root_dir) 294 repo = path.rocks_dir(repo or cfg.root_dir)
295 assert(type(deps_mode) == "string")
296
297 if deps_mode == "none" then deps_mode = cfg.deps_mode end
288 298
289 util.printout("Updating manifest for "..repo) 299 util.printout("Updating manifest for "..repo)
290 300
291 local manifest, err = load_manifest(repo) 301 local manifest, err = load_manifest(repo)
292 if not manifest then 302 if not manifest then
293 util.printerr("No existing manifest. Attempting to rebuild...") 303 util.printerr("No existing manifest. Attempting to rebuild...")
294 local ok, err = make_manifest(repo) 304 local ok, err = make_manifest(repo, deps_mode)
295 if not ok then 305 if not ok then
296 return nil, err 306 return nil, err
297 end 307 end
@@ -303,7 +313,7 @@ function update_manifest(name, version, repo)
303 313
304 local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} 314 local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}}
305 315
306 local ok, err = store_results(results, manifest) 316 local ok, err = store_results(results, manifest, deps_mode)
307 if not ok then return nil, err end 317 if not ok then return nil, err end
308 318
309 return save_table(repo, "manifest", manifest) 319 return save_table(repo, "manifest", manifest)
diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua
index 40f16898..6424a1e8 100644
--- a/src/luarocks/manif_core.lua
+++ b/src/luarocks/manif_core.lua
@@ -8,6 +8,7 @@ local type_check = require("luarocks.type_check")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local util = require("luarocks.util") 9local util = require("luarocks.util")
10local cfg = require("luarocks.cfg") 10local cfg = require("luarocks.cfg")
11local path = require("luarocks.path")
11 12
12manifest_cache = {} 13manifest_cache = {}
13 14
@@ -52,22 +53,25 @@ end
52 53
53--- Get all versions of a package listed in a manifest file. 54--- Get all versions of a package listed in a manifest file.
54-- @param name string: a package name. 55-- @param name string: a package name.
55-- @param manifest table or nil: a manifest table; if not given, the 56-- @param deps_mode string: "one", to use only the currently
56-- default local manifest table is used. 57-- configured tree; "order" to select trees based on order
58-- (use the current tree and all trees below it on the list)
59-- or "all", to use all trees.
57-- @return table: An array of strings listing installed 60-- @return table: An array of strings listing installed
58-- versions of a package. 61-- versions of a package.
59function get_versions(name, manifest) 62function get_versions(name, deps_mode)
60 assert(type(name) == "string") 63 assert(type(name) == "string")
61 assert(type(manifest) == "table" or not manifest) 64 assert(type(deps_mode) == "string")
62 65
63 if not manifest then 66 local manifest = {}
64 manifest = load_local_manifest(cfg.rocks_dir) 67 path.map_trees(deps_mode, function(tree)
65 if not manifest then 68 local loaded = load_local_manifest(path.rocks_dir(tree))
66 return {} 69 if loaded then
70 util.deep_merge(manifest, loaded)
67 end 71 end
68 end 72 end)
69 73
70 local item = manifest.repository[name] 74 local item = next(manifest) and manifest.repository[name]
71 if item then 75 if item then
72 return util.keys(item) 76 return util.keys(item)
73 end 77 end
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 798f15a9..64a203ef 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -7,6 +7,7 @@ module("luarocks.path", package.seeall)
7local dir = require("luarocks.dir") 7local dir = require("luarocks.dir")
8local cfg = require("luarocks.cfg") 8local cfg = require("luarocks.cfg")
9local util = require("luarocks.util") 9local util = require("luarocks.util")
10local deps = require("luarocks.deps")
10 11
11help_summary = "Return the currently configured package path." 12help_summary = "Return the currently configured package path."
12help_arguments = "" 13help_arguments = ""
@@ -305,6 +306,27 @@ function use_tree(tree)
305 cfg.deploy_lib_dir = deploy_lib_dir(tree) 306 cfg.deploy_lib_dir = deploy_lib_dir(tree)
306end 307end
307 308
309function map_trees(deps_mode, fn, ...)
310 local result = {}
311 if deps_mode == "one" then
312 table.insert(result, (fn(cfg.root_dir, ...)) or 0)
313 elseif deps_mode == "all" or deps_mode == "order" then
314 local use = false
315 if deps_mode == "all" then
316 use = true
317 end
318 for _, tree in ipairs(cfg.rocks_trees) do
319 if dir.normalize(tree) == dir.normalize(cfg.root_dir) then
320 use = true
321 end
322 if use then
323 table.insert(result, (fn(tree, ...)) or 0)
324 end
325 end
326 end
327 return result
328end
329
308--- Return the pathname of the file that would be loaded for a module, indexed. 330--- Return the pathname of the file that would be loaded for a module, indexed.
309-- @param module_name string: module name (eg. "socket.core") 331-- @param module_name string: module name (eg. "socket.core")
310-- @param name string: name of the package (eg. "luasocket") 332-- @param name string: name of the package (eg. "luasocket")
@@ -352,10 +374,14 @@ end
352-- @return boolean This function always succeeds. 374-- @return boolean This function always succeeds.
353function run(...) 375function run(...)
354 local flags = util.parse_flags(...) 376 local flags = util.parse_flags(...)
377 local deps_mode = deps.get_deps_mode(flags)
378
355 util.printout(cfg.export_lua_path:format(util.remove_path_dupes(package.path, ';'))) 379 util.printout(cfg.export_lua_path:format(util.remove_path_dupes(package.path, ';')))
356 util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(package.cpath, ';'))) 380 util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(package.cpath, ';')))
357 if flags["bin"] then 381 if flags["bin"] then
358 util.printout(cfg.export_path:format(util.remove_path_dupes(os.getenv("PATH"), cfg.export_path_separator), cfg.deploy_bin_dir)) 382 local bin_dirs = map_trees(deps_mode, deploy_bin_dir)
383 table.insert(bin_dirs, 1, os.getenv("PATH"))
384 util.printout(cfg.export_path:format(util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator)))
359 end 385 end
360 return true 386 return true
361end 387end
diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua
index dc6b822d..ca682f7d 100644
--- a/src/luarocks/purge.lua
+++ b/src/luarocks/purge.lua
@@ -44,5 +44,5 @@ function run(...)
44 end 44 end
45 end 45 end
46 end 46 end
47 return manif.make_manifest(cfg.rocks_dir) 47 return manif.make_manifest(cfg.rocks_dir, "one")
48end 48end
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua
index a9d97540..126cfdc8 100644
--- a/src/luarocks/remove.lua
+++ b/src/luarocks/remove.lua
@@ -28,7 +28,7 @@ To override this check and force the removal, use --force.
28-- @param versions array of string: the versions to be deleted. 28-- @param versions array of string: the versions to be deleted.
29-- @return array of string: an empty table if no packages depend on any 29-- @return array of string: an empty table if no packages depend on any
30-- of the given list, or an array of strings in "name/version" format. 30-- of the given list, or an array of strings in "name/version" format.
31local function check_dependents(name, versions) 31local function check_dependents(name, versions, deps_mode)
32 local dependents = {} 32 local dependents = {}
33 local blacklist = {} 33 local blacklist = {}
34 blacklist[name] = {} 34 blacklist[name] = {}
@@ -44,7 +44,7 @@ local function check_dependents(name, versions)
44 for rock_version, _ in pairs(rock_versions) do 44 for rock_version, _ in pairs(rock_versions) do
45 local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) 45 local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version))
46 if rockspec then 46 if rockspec then
47 local _, missing = deps.match_deps(rockspec, blacklist) 47 local _, missing = deps.match_deps(rockspec, blacklist, deps_mode)
48 if missing[name] then 48 if missing[name] then
49 table.insert(dependents, { name = rock_name, version = rock_version }) 49 table.insert(dependents, { name = rock_name, version = rock_version })
50 end 50 end
@@ -83,6 +83,8 @@ function run(...)
83 return nil, "Argument missing, see help." 83 return nil, "Argument missing, see help."
84 end 84 end
85 85
86 local deps_mode = flags["deps-mode"] or cfg.deps_mode
87
86 local ok, err = fs.check_command_permissions(flags) 88 local ok, err = fs.check_command_permissions(flags)
87 if not ok then return nil, err end 89 if not ok then return nil, err end
88 90
@@ -100,7 +102,7 @@ function run(...)
100 util.printout(name.." "..table.concat(util.keys(versions), ", ").."...") 102 util.printout(name.." "..table.concat(util.keys(versions), ", ").."...")
101 util.printout() 103 util.printout()
102 104
103 local dependents = check_dependents(name, versions) 105 local dependents = check_dependents(name, versions, deps_mode)
104 106
105 if #dependents == 0 or flags["force"] then 107 if #dependents == 0 or flags["force"] then
106 if #dependents > 0 then 108 if #dependents > 0 then
@@ -112,7 +114,7 @@ function run(...)
112 end 114 end
113 local ok, err = delete_versions(name, versions) 115 local ok, err = delete_versions(name, versions)
114 if not ok then return nil, err end 116 if not ok then return nil, err end
115 ok, err = manif.make_manifest(cfg.rocks_dir) 117 ok, err = manif.make_manifest(cfg.rocks_dir, deps_mode)
116 if not ok then return nil, err end 118 if not ok then return nil, err end
117 else 119 else
118 if not second then 120 if not second then
diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua
index 27cdc67d..dc1b63c8 100644
--- a/src/luarocks/repos.lua
+++ b/src/luarocks/repos.lua
@@ -14,7 +14,7 @@ local deps = require("luarocks.deps")
14-- @param name string: a package name. 14-- @param name string: a package name.
15-- @return table or nil: An array of strings listing installed 15-- @return table or nil: An array of strings listing installed
16-- versions of a package, or nil if none is available. 16-- versions of a package, or nil if none is available.
17function get_versions(name) 17local function get_installed_versions(name)
18 assert(type(name) == "string") 18 assert(type(name) == "string")
19 19
20 local dirs = fs.list_dir(path.versions_dir(name)) 20 local dirs = fs.list_dir(path.versions_dir(name))
@@ -213,7 +213,7 @@ function deploy_files(name, version, wrap_bin_scripts)
213 else 213 else
214 target = new_target 214 target = new_target
215 end 215 end
216 end 216 end
217 fs.make_dir(dir.dir_name(target)) 217 fs.make_dir(dir.dir_name(target))
218 ok, err = move_fn(source, target) 218 ok, err = move_fn(source, target)
219 fs.remove_dir_tree_if_empty(dir.dir_name(source)) 219 fs.remove_dir_tree_if_empty(dir.dir_name(source))
@@ -296,7 +296,7 @@ function delete_version(name, version, quick)
296 if err then return nil, err end 296 if err then return nil, err end
297 297
298 fs.delete(path.install_dir(name, version)) 298 fs.delete(path.install_dir(name, version))
299 if not get_versions(name) then 299 if not get_installed_versions(name) then
300 fs.delete(dir.path(cfg.rocks_dir, name)) 300 fs.delete(dir.path(cfg.rocks_dir, name))
301 end 301 end
302 return true 302 return true
diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua
index dd84e794..7849934d 100644
--- a/src/luarocks/show.lua
+++ b/src/luarocks/show.lua
@@ -23,7 +23,7 @@ With these flags, return only the desired information:
23--deps packages this package depends on 23--deps packages this package depends on
24--rockspec the full path of the rockspec file 24--rockspec the full path of the rockspec file
25--mversion the package version 25--mversion the package version
26--tree local tree where rock is installed 26--rock-tree local tree where rock is installed
27--rock-dir data directory of the installed rock 27--rock-dir data directory of the installed rock
28]] 28]]
29 29
@@ -79,7 +79,11 @@ function run(...)
79 local query = search.make_query(name, version) 79 local query = search.make_query(name, version)
80 query.exact_name = true 80 query.exact_name = true
81 local tree_map = {} 81 local tree_map = {}
82 for _, tree in ipairs(cfg.rocks_trees) do 82 local trees = cfg.rocks_trees
83 if flags["tree"] then
84 trees = { flags["tree"] }
85 end
86 for _, tree in ipairs(trees) do
83 local rocks_dir = path.rocks_dir(tree) 87 local rocks_dir = path.rocks_dir(tree)
84 tree_map[rocks_dir] = tree 88 tree_map[rocks_dir] = tree
85 search.manifest_search(results, rocks_dir, query) 89 search.manifest_search(results, rocks_dir, query)
@@ -111,7 +115,7 @@ function run(...)
111 if not manifest then return nil,err end 115 if not manifest then return nil,err end
112 local minfo = manifest.repository[name][version][1] 116 local minfo = manifest.repository[name][version][1]
113 117
114 if flags["tree"] then util.printout(repo) 118 if flags["rock-tree"] then util.printout(repo)
115 elseif flags["rock-dir"] then util.printout(directory) 119 elseif flags["rock-dir"] then util.printout(directory)
116 elseif flags["home"] then util.printout(descript.homepage) 120 elseif flags["home"] then util.printout(descript.homepage)
117 elseif flags["modules"] then util.printout(keys_as_string(minfo.modules)) 121 elseif flags["modules"] then util.printout(keys_as_string(minfo.modules))
diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua
index de7a43a2..c6e0c592 100644
--- a/src/luarocks/util.lua
+++ b/src/luarocks/util.lua
@@ -339,6 +339,8 @@ end
339-- @param list string: A path string (from $PATH or package.path) 339-- @param list string: A path string (from $PATH or package.path)
340-- @param sep string: The separator 340-- @param sep string: The separator
341function remove_path_dupes(list, sep) 341function remove_path_dupes(list, sep)
342 assert(type(list) == "string")
343 assert(type(sep) == "string")
342 local parts = split_string(list, sep) 344 local parts = split_string(list, sep)
343 local final, entries = {}, {} 345 local final, entries = {}, {}
344 for _, part in ipairs(parts) do 346 for _, part in ipairs(parts) do
diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua
index ed12f8f0..1e1e69e1 100644
--- a/src/luarocks/validate.lua
+++ b/src/luarocks/validate.lua
@@ -50,7 +50,7 @@ local function prepare_sandbox(file)
50end 50end
51 51
52local function validate_rockspec(file) 52local function validate_rockspec(file)
53 local ok, err, errcode = build.build_rockspec(file, true) 53 local ok, err, errcode = build.build_rockspec(file, true, "one")
54 if not ok then 54 if not ok then
55 util.printerr(err) 55 util.printerr(err)
56 end 56 end
@@ -58,7 +58,7 @@ local function validate_rockspec(file)
58end 58end
59 59
60local function validate_src_rock(file) 60local function validate_src_rock(file)
61 local ok, err, errcode = build.build_rock(file, false) 61 local ok, err, errcode = build.build_rock(file, false, "one")
62 if not ok then 62 if not ok then
63 util.printerr(err) 63 util.printerr(err)
64 end 64 end
@@ -66,7 +66,7 @@ local function validate_src_rock(file)
66end 66end
67 67
68local function validate_rock(file) 68local function validate_rock(file)
69 local ok, err, errcode = install.install_binary_rock(file) 69 local ok, err, errcode = install.install_binary_rock(file, "one")
70 if not ok then 70 if not ok then
71 util.printerr(err) 71 util.printerr(err)
72 end 72 end
@@ -97,7 +97,7 @@ local function validate(repo, flags)
97 util.printout() 97 util.printout()
98 util.printout("Verifying "..pathname) 98 util.printout("Verifying "..pathname)
99 if file:match("%.rockspec$") then 99 if file:match("%.rockspec$") then
100 ok, err, errcode = validate_rockspec(pathname) 100 ok, err, errcode = validate_rockspec(pathname, "one")
101 elseif file:match("%.src%.rock$") then 101 elseif file:match("%.src%.rock$") then
102 ok, err, errcode = validate_src_rock(pathname) 102 ok, err, errcode = validate_src_rock(pathname)
103 elseif file:match("%.rock$") then 103 elseif file:match("%.rock$") then