From 908e4ba7f0d09fafb35272e021605404261f4432 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 19 Dec 2015 19:22:37 +0300 Subject: Fix extension splitting in builting backend Fixes incorrect gcc command and error message when a file name doesn't contain a dot: Error: Build error: Failed compiling object .o becomes Error: Build error: Failed compiling object dotlessname --- src/luarocks/build/builtin.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 00fd09ea..ffdc9450 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -202,7 +202,7 @@ function builtin.run(rockspec) for name, info in pairs(build.modules) do local moddir = path.module_to_path(name) if type(info) == "string" then - local ext = info:match(".([^.]+)$") + local ext = info:match("%.([^.]+)$") if ext == "lua" then local filename = dir.base_name(info) if info:match("init%.lua$") and not name:match("%.init$") then @@ -226,7 +226,7 @@ function builtin.run(rockspec) if info[1] then sources = info end if type(sources) == "string" then sources = {sources} end for _, source in ipairs(sources) do - local object = source:gsub(".[^.]*$", "."..cfg.obj_extension) + local object = source:gsub("%.[^.]*$", "."..cfg.obj_extension) if not object then object = source.."."..cfg.obj_extension end -- cgit v1.2.3-55-g6feb From d62622aa2502cf9d100723ad9232fd72b7e75b9b Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 19 Dec 2015 19:30:29 +0300 Subject: Improve error handling in builtin backend Show error message from fs.copy when failed to install a file. Nice for Lua module files, since their existence is not checked beforehand. Also remove extra 'local ok, err' declarations. --- src/luarocks/build/builtin.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index ffdc9450..afd05954 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -174,7 +174,7 @@ function builtin.run(rockspec) --TODO EXEWRAPPER end - local ok = true + local ok, err local built_modules = {} local luadir = path.lua_dir(rockspec.name, rockspec.version) local libdir = path.lib_dir(rockspec.name, rockspec.version) @@ -236,11 +236,10 @@ function builtin.run(rockspec) end table.insert(objects, object) end - if not ok then break end local module_name = name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension) if moddir ~= "" then module_name = dir.path(moddir, module_name) - local ok, err = fs.make_dir(moddir) + ok, err = fs.make_dir(moddir) if not ok then return nil, err end end built_modules[module_name] = dir.path(libdir, module_name) @@ -252,13 +251,13 @@ function builtin.run(rockspec) end for name, dest in pairs(built_modules) do fs.make_dir(dir.dir_name(dest)) - ok = fs.copy(name, dest) + ok, err = fs.copy(name, dest) if not ok then - return nil, "Failed installing "..name.." in "..dest + return nil, "Failed installing "..name.." in "..dest..": "..err end end if fs.is_dir("lua") then - local ok, err = fs.copy_contents("lua", luadir) + ok, err = fs.copy_contents("lua", luadir) if not ok then return nil, "Failed copying contents of 'lua' directory: "..err end -- cgit v1.2.3-55-g6feb From 7a385f7c94aa655820b9955217bc58651dce6756 Mon Sep 17 00:00:00 2001 From: Geoff Leyland Date: Wed, 23 Dec 2015 10:06:39 +1300 Subject: Add git+ssh support to fetchers, including both kinds of git ssh url --- Makefile.setup.inc | 2 +- src/luarocks/fetch/git_ssh.lua | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/luarocks/fetch/git_ssh.lua (limited to 'src') diff --git a/Makefile.setup.inc b/Makefile.setup.inc index c228e78c..0a049bc4 100644 --- a/Makefile.setup.inc +++ b/Makefile.setup.inc @@ -16,5 +16,5 @@ help.lua util.lua index.lua cache.lua refresh_cache.lua loader.lua \ admin_remove.lua fetch/hg.lua fetch/git_file.lua new_version.lua lint.lua \ purge.lua path.lua path_cmd.lua write_rockspec.lua doc.lua upload.lua \ upload/api.lua upload/multipart.lua fetch/git_http.lua fetch/hg_http.lua \ -fetch/hg_https.lua fetch/hg_ssh.lua fetch/git_https.lua +fetch/hg_https.lua fetch/hg_ssh.lua fetch/git_https.lua fetch/git_ssh.lua diff --git a/src/luarocks/fetch/git_ssh.lua b/src/luarocks/fetch/git_ssh.lua new file mode 100644 index 00000000..0c2c0750 --- /dev/null +++ b/src/luarocks/fetch/git_ssh.lua @@ -0,0 +1,32 @@ +--- Fetch back-end for retrieving sources from Git repositories +-- that use ssh:// transport. For example, for fetching a repository +-- that requires the following command line: +-- `git clone ssh://git@example.com/path/foo.git +-- you can use this in the rockspec: +-- source = { url = "git+ssh://git@example.com/path/foo.git" } +-- It also handles scp-style ssh urls: git@example.com:path/foo.git, +-- but you have to prepend the "git+ssh://" and why not use the "newer" +-- style anyway? +local git_ssh = {} + +local git = require("luarocks.fetch.git") + +--- Fetch sources for building a rock from a local Git repository. +-- @param rockspec table: The rockspec table +-- @param extract boolean: Unused in this module (required for API purposes.) +-- @param dest_dir string or nil: If set, will extract to the given directory. +-- @return (string, string) or (nil, string): The absolute pathname of +-- the fetched source tarball and the temporary directory created to +-- store it; or nil and an error message. +function git_ssh.get_sources(rockspec, extract, dest_dir) + rockspec.source.url = rockspec.source.url:gsub("^git.", "") + + -- Handle old-style scp-like git ssh urls + if rockspec.source.url:match("^ssh://[^/]+:[^%d]") then + rockspec.source.url = rockspec.source.url:gsub("^ssh://", "") + end + + return git.get_sources(rockspec, extract, dest_dir, "--") +end + +return git_ssh -- cgit v1.2.3-55-g6feb From 2f183bcd1a596748b4f117d9f07f31a006e3b8bb Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sun, 10 Jan 2016 21:09:30 -0800 Subject: provide a better error message for missing json libraries --- src/luarocks/upload/api.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index 2cf462fb..b56f23e1 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua @@ -106,13 +106,22 @@ end -- An ode to the multitude of JSON libraries out there... local function require_json() - for _, lib in ipairs({ "cjson", "dkjson", "json" }) do + local list = { "cjson", "dkjson", "json" } + for _, lib in ipairs(list) do local json_ok, json = pcall(require, lib) if json_ok then return json_ok, json end end - return nil + local errmsg = "Failed loading " + for i, name in ipairs(list) do + if i == #list then + errmsg = errmsg .."and '"..name.."'. Use 'luarocks search ' to search for a library and 'luarocks install ' to install one." + else + errmsg = errmsg .."'"..name.."', " + end + end + return nil, errmsg end local function redact_api_url(url) @@ -126,7 +135,7 @@ if not ltn12_ok then -- If not using LuaSocket and/or LuaSec... function Api:request(url, params, post_params) local vars = cfg.variables local json_ok, json = require_json() - if not json_ok then return nil, "A JSON library is required for this command." end + if not json_ok then return nil, "A JSON library is required for this command. "..json end if cfg.downloader == "wget" then local curl_ok = fs.execute_quiet(vars.CURL, "--version") -- cgit v1.2.3-55-g6feb From b1db72d91cda7a17b2f95a0a4f90b838cbf7993f Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sun, 10 Jan 2016 22:49:42 -0800 Subject: removed duplicate code, this part seems copy-pasted from the part that was later fixed by #455, hence this still contained the same bug --- src/luarocks/upload/api.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index b56f23e1..6a830abd 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua @@ -138,9 +138,9 @@ function Api:request(url, params, post_params) if not json_ok then return nil, "A JSON library is required for this command. "..json end if cfg.downloader == "wget" then - local curl_ok = fs.execute_quiet(vars.CURL, "--version") + local curl_ok, err = fs.is_tool_available(vars.CURL, "curl") if not curl_ok then - return nil, "Missing network helper program 'curl'.\nMake sure 'curl' is installed and available from your path." + return nil, err end end -- cgit v1.2.3-55-g6feb From d03b2c83b7d1673b41068bbc523b35fb4192ae64 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sun, 10 Jan 2016 22:57:17 -0800 Subject: 2nd occurence of the json error message also updated --- src/luarocks/upload/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/upload/api.lua b/src/luarocks/upload/api.lua index 6a830abd..6df24569 100644 --- a/src/luarocks/upload/api.lua +++ b/src/luarocks/upload/api.lua @@ -201,7 +201,7 @@ local warned_luasec = false function Api:request(url, params, post_params) local json_ok, json = require_json() - if not json_ok then return nil, "A JSON library is required for this command." end + if not json_ok then return nil, "A JSON library is required for this command. "..json end local server = tostring(self.config.server) local http_ok, http local via = "luasocket" -- cgit v1.2.3-55-g6feb From 3766d49926771f754bcd255c9e82102cbbe6ce01 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 5 Jan 2016 13:05:58 +0300 Subject: luarocks make: ignore 'rockspec' directory when no argument given Without an argument luarocks make looks if there is only one rockspec in the current directory. Consider only files as potential rockspec to avoid strange error when current directory contains a directory ending with 'rockspec'. --- src/luarocks/make.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 1dfe6473..4f70bafe 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -54,7 +54,7 @@ function make.run(...) if not rockspec then for file in fs.dir() do - if file:match("rockspec$") then + if file:match("rockspec$") and fs.is_file(file) then if rockspec then return nil, "Please specify which rockspec file to use." else -- cgit v1.2.3-55-g6feb From 8254cd3e69321963673e4909de4ec585adf6a706 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 5 Jan 2016 13:12:34 +0300 Subject: Remove two unnecessary require calls --- src/luarocks/command_line.lua | 1 - src/luarocks/fetch.lua | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index e1c9f492..a016fc72 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -144,7 +144,6 @@ function command_line.run_command(...) end end if not named then - local fs = require("luarocks.fs") local root_dir = fs.absolute_name(flags["tree"]) replace_tree(flags, args, root_dir) end diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index e92aeddf..2c028771 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -371,7 +371,7 @@ function fetch.fetch_sources(rockspec, extract, dest_dir) local protocol = rockspec.source.protocol local ok, proto if fetch.is_basic_protocol(protocol) then - proto = require("luarocks.fetch") + proto = fetch else ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) if not ok then -- cgit v1.2.3-55-g6feb From f73a7d9bca18884c7f882e90b5be650ab625a485 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 5 Jan 2016 13:16:16 +0300 Subject: Report unknown commands consistently Now both 'luarocks foo' and 'luarocks help foo' print 'Unknown command: foo'. --- src/luarocks/help.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 92458b2b..5a2681a3 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua @@ -111,7 +111,7 @@ function help.run(...) print_section("SEE ALSO") util.printout("","'"..program.." help' for general options and configuration.\n") else - return nil, "Unknown command '"..command.."'" + return nil, "Unknown command: "..command end end return true -- cgit v1.2.3-55-g6feb From d725a42e2efd2df34dc21cc1a8bb087241064268 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 11 Jan 2016 19:21:46 +0300 Subject: Do not handle cfg.local_cache == nil in luarocks.cache cfg.local_cache is always set by defaults. Fixes #479. --- src/luarocks/cache.lua | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src') diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua index dbea8405..fb6344d8 100644 --- a/src/luarocks/cache.lua +++ b/src/luarocks/cache.lua @@ -45,25 +45,12 @@ function cache.split_server_url(server, url, user, password) user = credentials end end - local local_cache - if cfg.local_cache then - local_cache = cfg.local_cache .. "/" .. server - end + local local_cache = cfg.local_cache .. "/" .. server return local_cache, protocol, server_path, user, password end function cache.refresh_local_cache(server, url, user, password) local local_cache, protocol, server_path, user, password = cache.split_server_url(server, url, user, password) - - local ok, err = fs.make_dir(cfg.local_cache) - if not ok then return nil, err end - - local tmp_cache = false - if not local_cache then - local err - local_cache, err = fs.make_temp_dir("local_cache") - tmp_cache = true - end local ok, err = fs.make_dir(local_cache) if not ok then return nil, "Failed creating local cache dir: "..err -- cgit v1.2.3-55-g6feb From 6dc745a70be16e99ca2bc3b389f92336f49b05ec Mon Sep 17 00:00:00 2001 From: Hisham Date: Mon, 1 Feb 2016 09:53:41 +0100 Subject: Make search order deterministic. --- src/luarocks/loader.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 1eaa6721..ba15613e 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -6,8 +6,8 @@ -- used to load previous modules, so that the loader chooses versions -- that are declared to be compatible with the ones loaded earlier. local loaders = package.loaders or package.searchers -local package, require, ipairs, pairs, table, type, next, tostring, error = - package, require, ipairs, pairs, table, type, next, tostring, error +local package, require, ipairs, table, type, next, tostring, error = + package, require, ipairs, table, type, next, tostring, error local unpack = unpack or table.unpack --module("luarocks.loader") @@ -20,6 +20,7 @@ cfg.init_package_paths() local path = require("luarocks.path") local manif_core = require("luarocks.manif_core") local deps = require("luarocks.deps") +local util = require("luarocks.util") loader.context = {} @@ -79,7 +80,7 @@ function loader.add_context(name, version) for _, tree in ipairs(loader.rocks_trees) do local entries = tree.manifest.repository[pkg] if entries then - for version, pkgs in pairs(entries) do + for version, pkgs in util.sortedpairs(entries, deps.compare_versions) do if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then loader.add_context(pkg, version) end -- cgit v1.2.3-55-g6feb From d9ffeaf66f77dc9321a574f6aec2df1785acb8e5 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 2 Feb 2016 17:34:50 +0300 Subject: Fix docs for path.which_i and some of its users It actually accepts file name of the module as in manifest.repository[package][version].modules[module], not the module name. --- src/luarocks/loader.lua | 29 ++++++++++++++--------------- src/luarocks/path.lua | 19 ++++++++++--------- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index ba15613e..26280e94 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -126,17 +126,17 @@ end --- Search for a module in the rocks trees -- @param module string: module name (eg. "socket.core") --- @param filter_module_name function(string, string, string, string, number): --- a function that takes the module name (eg "socket.core"), the rock name +-- @param filter_file_name function(string, string, string, string, number): +-- a function that takes the module file name (eg "socket/core.so"), the rock name -- (eg "luasocket"), the version (eg "2.0.2-1"), the path of the rocks tree -- (eg "/usr/local"), and the numeric index of the matching entry, so the -- filter function can know if the matching module was the first entry or not. -- @return string, string, string, (string or table): -- * name of the rock containing the module (eg. "luasocket") -- * version of the rock (eg. "2.0.2-1") --- * name of the module (eg. "socket.core", or "socket.core_2_0_2" if file is stored versioned). +-- * return value of filter_file_name -- * tree of the module (string or table in `rocks_trees` format) -local function select_module(module, filter_module_name) +local function select_module(module, filter_file_name) --assert(type(module) == "string") --assert(type(filter_module_name) == "function") @@ -150,16 +150,16 @@ local function select_module(module, filter_module_name) if entries then for i, entry in ipairs(entries) do local name, version = entry:match("^([^/]*)/(.*)$") - local module_name = tree.manifest.repository[name][version][1].modules[module] - if type(module_name) ~= "string" then + local file_name = tree.manifest.repository[name][version][1].modules[module] + if type(file_name) ~= "string" then error("Invalid data in manifest file for module "..tostring(module).." (invalid data for "..tostring(name).." "..tostring(version)..")") end - module_name = filter_module_name(module_name, name, version, tree.tree, i) + file_name = filter_file_name(file_name, name, version, tree.tree, i) if loader.context[name] == version then - return name, version, module_name + return name, version, file_name end version = deps.parse_version(version) - table.insert(providers, {name = name, version = version, module_name = module_name, tree = tree}) + table.insert(providers, {name = name, version = version, module_name = file_name, tree = tree}) end end end @@ -180,12 +180,11 @@ end -- * tree of the module (string or table in `rocks_trees` format) local function pick_module(module) return - select_module(module, function(module_name, name, version, tree, i) + select_module(module, function(file_name, name, version, tree, i) if i > 1 then - module_name = path.versioned_name(module_name, "", name, version) + file_name = path.versioned_name(file_name, "", name, version) end - module_name = path.path_to_module(module_name) - return module_name + return path.path_to_module(file_name) end) end @@ -193,8 +192,8 @@ end -- @param module string: module name (eg. "socket.core") -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") function loader.which(module) - local name, version, module_name = select_module(module, path.which_i) - return module_name + local _, _, file_name = select_module(module, path.which_i) + return file_name end --- Package loader for LuaRocks support. diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index fb5eec7e..bc7ab63b 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -342,44 +342,45 @@ end local is_src_extension = { [".lua"] = true, [".tl"] = true, [".tld"] = true, [".moon"] = true } --- Return the pathname of the file that would be loaded for a module, indexed. --- @param module_name string: module name (eg. "socket.core") +-- @param file_name string: module file name as in manifest (eg. "socket/core.so") -- @param name string: name of the package (eg. "luasocket") -- @param version string: version number (eg. "2.0.2-1") -- @param tree string: repository path (eg. "/usr/local") -- @param i number: the index, 1 if version is the current default, > 1 otherwise. -- This is done this way for use by select_module in luarocks.loader. -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") -function path.which_i(module_name, name, version, tree, i) +function path.which_i(file_name, name, version, tree, i) local deploy_dir - local extension = module_name:match("%.[a-z]+$") + local extension = file_name:match("%.[a-z]+$") if is_src_extension[extension] then deploy_dir = path.deploy_lua_dir(tree) - module_name = dir.path(deploy_dir, module_name) + file_name = dir.path(deploy_dir, file_name) else deploy_dir = path.deploy_lib_dir(tree) - module_name = dir.path(deploy_dir, module_name) + file_name = dir.path(deploy_dir, file_name) end if i > 1 then - module_name = path.versioned_name(module_name, deploy_dir, name, version) + file_name = path.versioned_name(file_name, deploy_dir, name, version) end - return module_name + return file_name end --- Return the pathname of the file that would be loaded for a module, -- returning the versioned pathname if given version is not the default version -- in the given manifest. -- @param module_name string: module name (eg. "socket.core") +-- @param file_name string: module file name as in manifest (eg. "socket/core.so") -- @param name string: name of the package (eg. "luasocket") -- @param version string: version number (eg. "2.0.2-1") -- @param tree string: repository path (eg. "/usr/local") -- @param manifest table: the manifest table for the tree. -- @return string: filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so") -function path.which(module_name, filename, name, version, tree, manifest) +function path.which(module_name, file_name, name, version, tree, manifest) local versions = manifest.modules[module_name] assert(versions) for i, name_version in ipairs(versions) do if name_version == name.."/"..version then - return path.which_i(filename, name, version, tree, i):gsub("//", "/") + return path.which_i(file_name, name, version, tree, i):gsub("//", "/") end end assert(false) -- cgit v1.2.3-55-g6feb From 7158d25512ce6b305160408398bfbfbdfe4dc3de Mon Sep 17 00:00:00 2001 From: Philipp Janda Date: Sun, 7 Feb 2016 15:08:00 +0100 Subject: Add compatibility with lhf's lmd5 module. Closes #494. --- src/luarocks/fs/lua.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index a444f014..1d303c67 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -728,6 +728,14 @@ end if md5_ok then +-- Support the interface of lmd5 by lhf in addition to md5 by Roberto +-- and the keplerproject. +if not md5.sumhexa and md5.digest then + md5.sumhexa = function(msg) + return md5.digest(msg) + end +end + --- Get the MD5 checksum for a file. -- @param file string: The file to be computed. -- @return string: The MD5 checksum or nil + error -- cgit v1.2.3-55-g6feb From 0f2594e63e175946115bf725cb6b52bc807d4216 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 15:20:51 +0300 Subject: Fix "missing argument" message for new_version --- src/luarocks/new_version.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index 9ef0cfbb..e5469295 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua @@ -107,7 +107,7 @@ end function new_version.run(...) local flags, input, version, url = util.parse_flags(...) if not input then - return nil, "Missing arguments: expected program or rockspec. "..util.see_help("new_version") + return nil, "Missing argument: expected package or rockspec. "..util.see_help("new_version") end assert(type(input) == "string") -- cgit v1.2.3-55-g6feb From d2991be0d3c03ecc953e9d80a90698397492e215 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 15:22:19 +0300 Subject: Remove a redundant check in new_version The template rockspec is type checked, no need to check if source table is present. --- src/luarocks/new_version.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index e5469295..73accf1e 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua @@ -77,9 +77,6 @@ local function update_source_section(out_rs, out_name, url, old_ver, new_ver) if new_ver == old_ver then return true end - if not out_rs.source then - return nil, "'source' table is missing. Invalid rockspec?" - end if out_rs.source.dir then try_replace(out_rs.source, "dir", old_ver, new_ver) end -- cgit v1.2.3-55-g6feb From 137a78e3997cfb97131956d76ddb6b50bd3f8d24 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 16:35:25 +0300 Subject: Fix update_source_section in new_version * Don't confuse cases "MD5 changed with same URL" and "couldn't fetch" * Don't check MD5 if it's not present in the old rockspec * Don't drop errors in fs.get_md5 * Don't drop errors in fetch.find_base_dir --- src/luarocks/new_version.lua | 59 +++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index 73accf1e..fb813183 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua @@ -48,31 +48,47 @@ local function try_replace(tbl, field, old, new) return false end -local function check_url_and_update_md5(out_rs, out_name) - local old_md5 = out_rs.source.md5 - out_rs.source.md5 = nil - local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_name) +-- Try to download source file using URL from a rockspec. +-- If it specified MD5, update it. +-- @return (true, false) if MD5 was not specified or it stayed same, +-- (true, true) if MD5 changed, (nil, string) on error. +local function check_url_and_update_md5(out_rs) + local file, temp_dir = fetch.fetch_url_at_temp_dir(out_rs.source.url, "luarocks-new-version-"..out_rs.package) if not file then util.printerr("Warning: invalid URL - "..temp_dir) - return true + return true, false end - util.printout("File successfully downloaded. Updating MD5 checksum...") - out_rs.source.md5 = fs.get_md5(file) + local inferred_dir, found_dir = fetch.find_base_dir(file, temp_dir, out_rs.source.url, out_rs.source.dir) if not inferred_dir then return nil, found_dir end + if found_dir and found_dir ~= inferred_dir then out_rs.source.dir = found_dir end - return out_rs.source.md5 ~= old_md5 + + if file then + if out_rs.source.md5 then + util.printout("File successfully downloaded. Updating MD5 checksum...") + local new_md5, err = fs.get_md5(file) + if not new_md5 then + return nil, err + end + local old_md5 = out_rs.source.md5 + out_rs.source.md5 = new_md5 + return true, new_md5 ~= old_md5 + else + util.printout("File successfully downloaded.") + return true, false + end + end end -local function update_source_section(out_rs, out_name, url, old_ver, new_ver) +local function update_source_section(out_rs, url, old_ver, new_ver) if url then out_rs.source.url = url - check_url_and_update_md5(out_rs, out_name) - return true + return check_url_and_update_md5(out_rs) end if new_ver == old_ver then return true @@ -83,20 +99,19 @@ local function update_source_section(out_rs, out_name, url, old_ver, new_ver) if out_rs.source.file then try_replace(out_rs.source, "file", old_ver, new_ver) end - local ok = try_replace(out_rs.source, "url", old_ver, new_ver) - if ok then - check_url_and_update_md5(out_rs, out_name) + if try_replace(out_rs.source, "url", old_ver, new_ver) then + return check_url_and_update_md5(out_rs) + end + if try_replace(out_rs.source, "tag", old_ver, new_ver) then return true end - ok = try_replace(out_rs.source, "tag", old_ver, new_ver) + -- Couldn't replace anything significant, use the old URL. + local ok, md5_changed = check_url_and_update_md5(out_rs) if not ok then - ok = check_url_and_update_md5(out_rs, out_name) - if ok then - util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.") - end + return nil, md5_changed end - if not ok then - return nil, "Failed to determine the location of the new version." + if md5_changed then + util.printerr("Warning: URL is the same, but MD5 has changed. Old rockspec is broken.") end return true end @@ -142,7 +157,7 @@ function new_version.run(...) local out_name = out_rs.package:lower() out_rs.version = new_rockver.."-"..new_rev - local ok, err = update_source_section(out_rs, out_name, url, old_ver, new_ver) + local ok, err = update_source_section(out_rs, url, old_ver, new_ver) if not ok then return nil, err end if out_rs.build and out_rs.build.type == "module" then -- cgit v1.2.3-55-g6feb From 01040d6f731a8ef423f0e0a916f51616f2b1b9a1 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 17:05:30 +0300 Subject: Add --tag option for luarocks new_version Allows using new_version command to create tagged rockspecs from untagged scm rockspecs. If not given, new version is copied from passed tag, with leading 'v' stripped if it's present. --- src/luarocks/new_version.lua | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index fb813183..6969d4b2 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua @@ -1,9 +1,7 @@ --- Module implementing the LuaRocks "new_version" command. -- Utility function that writes a new rockspec, updating data from a previous one. ---module("luarocks.new_version", package.seeall) local new_version = {} -package.loaded["luarocks.new_version"] = new_version local util = require("luarocks.util") local download = require("luarocks.download") @@ -13,7 +11,7 @@ local fs = require("luarocks.fs") local type_check = require("luarocks.type_check") new_version.help_summary = "Auto-write a rockspec for a new version of a rock." -new_version.help_arguments = "{|} [] []" +new_version.help_arguments = "[--tag=] {|} [] []" new_version.help = [[ This is a utility function that writes a new rockspec, updating data from a previous one. @@ -21,8 +19,10 @@ from a previous one. If a package name is given, it downloads the latest rockspec from the default server. If a rockspec is given, it uses it instead. -If the version number is not given, it only increments the revision -number of the given (or downloaded) rockspec. +If the version number is not given and tag is passed using --tag, +it is used as the version, with 'v' removed from beginning. +Otherwise, it only increments the revision number of the given +(or downloaded) rockspec. If a URL is given, it replaces the one from the old rockspec with the given URL. If a URL is not given and a new version is given, it tries @@ -30,6 +30,9 @@ to guess the new URL by replacing occurrences of the version number in the URL or tag. It also tries to download the new URL to determine the new MD5 checksum. +If a tag is given, it replaces the one from the old rockspec. If there is +an old tag but no new one passed, it is guessed in the same way URL is. + WARNING: it writes the new rockspec to the current directory, overwriting the file if it already exists. ]] @@ -85,7 +88,10 @@ local function check_url_and_update_md5(out_rs) end end -local function update_source_section(out_rs, url, old_ver, new_ver) +local function update_source_section(out_rs, url, tag, old_ver, new_ver) + if tag then + out_rs.source.tag = tag + end if url then out_rs.source.url = url return check_url_and_update_md5(out_rs) @@ -102,7 +108,7 @@ local function update_source_section(out_rs, url, old_ver, new_ver) if try_replace(out_rs.source, "url", old_ver, new_ver) then return check_url_and_update_md5(out_rs) end - if try_replace(out_rs.source, "tag", old_ver, new_ver) then + if tag or try_replace(out_rs.source, "tag", old_ver, new_ver) then return true end -- Couldn't replace anything significant, use the old URL. @@ -139,6 +145,10 @@ function new_version.run(...) local old_ver, old_rev = valid_rs.version:match("(.*)%-(%d+)$") local new_ver, new_rev + + if flags.tag and not version then + version = flags.tag:gsub("^v", "") + end if version then new_ver, new_rev = version:match("(.*)%-(%d+)$") @@ -157,7 +167,7 @@ function new_version.run(...) local out_name = out_rs.package:lower() out_rs.version = new_rockver.."-"..new_rev - local ok, err = update_source_section(out_rs, url, old_ver, new_ver) + local ok, err = update_source_section(out_rs, url, flags.tag, old_ver, new_ver) if not ok then return nil, err end if out_rs.build and out_rs.build.type == "module" then -- cgit v1.2.3-55-g6feb From 204d6cc98fb275865c28653b6eed57060e84255e Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 13 Feb 2016 15:34:20 +0300 Subject: Fix trailing space in dep.show_dep on dep without constraints --- src/luarocks/deps.lua | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index eb01075c..acc571f8 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -247,12 +247,16 @@ end function deps.show_dep(dep, internal) assert(type(dep) == "table") assert(type(internal) == "boolean" or not internal) - - local pretty = {} - for _, c in ipairs(dep.constraints) do - table.insert(pretty, c.op .. " " .. deps.show_version(c.version, internal)) + + if #dep.constraints > 0 then + local pretty = {} + for _, c in ipairs(dep.constraints) do + table.insert(pretty, c.op .. " " .. deps.show_version(c.version, internal)) + end + return dep.name.." "..table.concat(pretty, ", ") + else + return dep.name end - return dep.name.." "..table.concat(pretty, ", ") end --- A more lenient check for equivalence between versions. -- cgit v1.2.3-55-g6feb From c2bad31e7fea154c3fdee453b2d774f48b422be8 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Fri, 19 Feb 2016 11:16:35 +0300 Subject: Compatibility with lua-zlib --- src/luarocks/tools/zip.lua | 56 +++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua index 101cae82..e6d9e36a 100644 --- a/src/luarocks/tools/zip.lua +++ b/src/luarocks/tools/zip.lua @@ -1,13 +1,35 @@ --- A Lua implementation of .zip file archiving (used for creating .rock files), --- using only lzlib. ---module("luarocks.tools.zip", package.seeall) +-- using only lzlib or lua-lzib. local zip = {} local zlib = require("zlib") local fs = require("luarocks.fs") local dir = require("luarocks.dir") +-- zlib module can be provided by both lzlib and lua-lzib packages. +-- Create a compatibility layer. +local zlib_compress, zlib_crc32 +if zlib._VERSION:match "^lua%-zlib" then + function zlib_compress(data) + return (zlib.deflate()(data, "finish")) + end + + function zlib_crc32(data) + return zlib.crc32()(data) + end +elseif zlib._VERSION:match "^lzlib" then + function zlib_compress(data) + return zlib.compress(data) + end + + function zlib_crc32(data) + return zlib.crc32(zlib.crc32(), data) + end +else + error("unknown zlib library", 0) +end + local function number_to_bytestring(number, nbytes) local out = {} for _ = 1, nbytes do @@ -31,32 +53,28 @@ local function zipwriter_open_new_file_in_zip(self, filename) self.local_file_header = lfh lfh.last_mod_file_time = 0 -- TODO lfh.last_mod_file_date = 0 -- TODO - lfh.crc32 = 0 -- initial value - lfh.compressed_size = 0 -- unknown yet - lfh.uncompressed_size = 0 -- unknown yet lfh.file_name_length = #filename lfh.extra_field_length = 0 lfh.file_name = filename:gsub("\\", "/") lfh.external_attr = 0 -- TODO properly store permissions self.in_open_file = true - self.data = {} return true end --- Write data to the file currently being stored in the zipfile. -- @param self handle of the zipfile being written. --- @param buf string containing data to be written. +-- @param data string containing full contents of the file. -- @return true if succeeded, nil in case of failure. -local function zipwriter_write_file_in_zip(self, buf) +local function zipwriter_write_file_in_zip(self, data) if not self.in_open_file then return nil end local lfh = self.local_file_header - local cbuf = zlib.compress(buf):sub(3, -5) - lfh.crc32 = zlib.crc32(lfh.crc32, buf) - lfh.compressed_size = lfh.compressed_size + #cbuf - lfh.uncompressed_size = lfh.uncompressed_size + #buf - table.insert(self.data, cbuf) + local compressed = zlib_compress(data):sub(3, -5) + lfh.crc32 = zlib_crc32(data) + lfh.compressed_size = #compressed + lfh.uncompressed_size = #data + self.data = compressed return true end @@ -86,10 +104,8 @@ local function zipwriter_close_file_in_zip(self) zh:write(number_to_bytestring(lfh.extra_field_length, 2)) zh:write(lfh.file_name) - -- File data - for _, cbuf in ipairs(self.data) do - zh:write(cbuf) - end + -- File data + zh:write(self.data) -- Data descriptor zh:write(number_to_bytestring(lfh.crc32, 4)) @@ -117,12 +133,12 @@ local function zipwriter_add(self, file) end end if ok then - local buf = fin:read("*a") - if not buf then + local data = fin:read("*a") + if not data then err = "error reading "..file ok = false else - ok = self:write_file_in_zip(buf) + ok = self:write_file_in_zip(data) if not ok then err = "error in writing "..file.." in the zipfile" end -- cgit v1.2.3-55-g6feb From 436e58ccf28628768b74d7306ab1b1756a9dbf98 Mon Sep 17 00:00:00 2001 From: Karel Tuma Date: Tue, 23 Feb 2016 19:02:47 +0100 Subject: Implement MSYS2 support --- src/luarocks/cfg.lua | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index e41b632c..2924e435 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -113,6 +113,10 @@ elseif system == "SunOS" then elseif system and system:match("^CYGWIN") then cfg.platforms.unix = true cfg.platforms.cygwin = true +elseif system and system:match("^MSYS") then + cfg.platforms.unix = true + cfg.platforms.msys = true + cfg.platforms.cygwin = true elseif system and system:match("^Windows") then cfg.platforms.windows = true cfg.platforms.win32 = true @@ -137,10 +141,11 @@ local platform_order = { linux = 7, macosx = 8, cygwin = 9, + msys = 10, -- Windows - win32 = 10, - mingw32 = 11, - windows = 12 } + win32 = 11, + mingw32 = 12, + windows = 13 } -- Path configuration: @@ -518,6 +523,23 @@ if cfg.platforms.cygwin then defaults.variables.LIBFLAG = "-shared" end +if cfg.platforms.msys then + -- msys is basically cygwin made out of mingw, meaning the subsytem is unixish + -- enough, yet we can freely mix with native win32 + defaults.external_deps_patterns = { + bin = { "?.exe", "?.bat", "?" }, + lib = { "lib?.so", "lib?.so.*", "lib?.dll.a", "?.dll.a", + "lib?.a", "lib?.dll", "?.dll", "?.lib" }, + include = { "?.h" } + } + defaults.runtime_external_deps_patterns = { + bin = { "?.exe", "?.bat" }, + lib = { "lib?.so", "?.dll", "lib?.dll" }, + include = { "?.h" } + } +end + + if cfg.platforms.bsd then defaults.variables.MAKE = "gmake" defaults.variables.STATFLAG = "-f '%OLp'" -- cgit v1.2.3-55-g6feb From 6cf3159a9b71e58a055e359021174da958348e7a Mon Sep 17 00:00:00 2001 From: Hisham Date: Tue, 1 Mar 2016 23:48:21 -0300 Subject: Make sure deps-mode is respected when recursing the dependency chain. --- src/luarocks/deps.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index acc571f8..a2215351 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -488,7 +488,7 @@ function deps.fulfill_dependencies(rockspec, deps_mode) if not rock then return nil, "Could not satisfy dependency: "..deps.show_dep(dep) end - local ok, err, errcode = install.run(rock) + local ok, err, errcode = install.run(rock, deps.deps_mode_to_flag(deps_mode)) if not ok then return nil, "Failed installing dependency: "..rock.." - "..err, errcode end -- cgit v1.2.3-55-g6feb From efec62b7a85dc492e2a34a35ee3e1f83e15face2 Mon Sep 17 00:00:00 2001 From: Daniel Lemos Date: Fri, 11 Mar 2016 15:43:18 -0300 Subject: Add HaikuOS as platform --- src/luarocks/cfg.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index e41b632c..f4e50eff 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -120,6 +120,9 @@ elseif system and system:match("^MINGW") then cfg.platforms.windows = true cfg.platforms.mingw32 = true cfg.platforms.win32 = true +elseif system == "Haiku" then + cfg.platforms.unix = true + cfg.platforms.haiku = true else cfg.platforms.unix = true -- Fall back to Unix in unknown systems. @@ -137,11 +140,11 @@ local platform_order = { linux = 7, macosx = 8, cygwin = 9, + haiku = 10, -- Windows - win32 = 10, - mingw32 = 11, - windows = 12 } - + win32 = 11, + mingw32 = 12, + windows = 13 } -- Path configuration: local sys_config_file, home_config_file -- cgit v1.2.3-55-g6feb From 6b749bf2300e2ebdea3ef5c3ed171c397e00c98e Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 17 Mar 2016 20:59:10 +0300 Subject: Implement magical rockspec picking for "luarocks make" --- src/luarocks/make.lua | 67 ++++++++++++++++++++++++++++++++++++++++++++------- test/testing.sh | 6 +++-- 2 files changed, 62 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 4f70bafe..94cf4414 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -9,6 +9,8 @@ package.loaded["luarocks.make"] = make local build = require("luarocks.build") local fs = require("luarocks.fs") +local dir = require("luarocks.dir") +local path = require("luarocks.path") local util = require("luarocks.util") local cfg = require("luarocks.cfg") local fetch = require("luarocks.fetch") @@ -22,8 +24,11 @@ make.help = [[ Builds sources in the current directory, but unlike "build", it does not fetch sources, etc., assuming everything is available in the current directory. If no argument is given, -look for a rockspec in the current directory. If more than one -is found, you must specify which to use, through the command-line. +it looks for a rockspec in the current directory and in "rockspec/" +and "rockspecs/" subdirectories, picking the rockspec with newest version +or without version name. If rockspecs for different rocks are found +or there are several rockspecs without version, you must specify which to use, +through the command-line. This command is useful as a tool for debugging rockspecs. To install rocks, you'll normally want to use the "install" and @@ -44,6 +49,33 @@ To install rocks, you'll normally want to use the "install" and ]] +--- Collect rockspecs located in a subdirectory. +-- @param versions table: A table mapping rock names to newest rockspec versions. +-- @param paths table: A table mapping rock names to newest rockspec paths. +-- @param unnamed_paths table: An array of rockspec paths that don't contain rock +-- name and version in regular format. +-- @param subdir string: path to subdirectory. +local function collect_rockspecs(versions, paths, unnamed_paths, subdir) + if fs.is_dir(subdir) then + for file in fs.dir(subdir) do + file = dir.path(subdir, file) + + if file:match("rockspec$") and fs.is_file(file) then + local rock, version = path.parse_name(file) + + if rock then + if not versions[rock] or deps.compare_versions(version, versions[rock]) then + versions[rock] = version + paths[rock] = file + end + else + table.insert(unnamed_paths, file) + end + end + end + end +end + --- Driver function for "make" command. -- @param name string: A local rockspec. -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an @@ -53,18 +85,35 @@ function make.run(...) assert(type(rockspec) == "string" or not rockspec) if not rockspec then - for file in fs.dir() do - if file:match("rockspec$") and fs.is_file(file) then - if rockspec then + -- Try to infer default rockspec name. + local versions, paths, unnamed_paths = {}, {}, {} + -- Look for rockspecs in some common locations. + collect_rockspecs(versions, paths, unnamed_paths, ".") + collect_rockspecs(versions, paths, unnamed_paths, "rockspec") + collect_rockspecs(versions, paths, unnamed_paths, "rockspecs") + + if #unnamed_paths > 0 then + -- There are rockspecs not following "name-version.rockspec" format. + -- More than one are ambiguous. + if #unnamed_paths > 1 then + return nil, "Please specify which rockspec file to use." + else + rockspec = unnamed_paths[1] + end + else + local rock = next(versions) + + if rock then + -- If there are rockspecs for multiple rocks it's ambiguous. + if next(versions, rock) then return nil, "Please specify which rockspec file to use." else - rockspec = file + rockspec = paths[rock] end + else + return nil, "Argument missing: please specify a rockspec to use on current directory." end end - if not rockspec then - return nil, "Argument missing: please specify a rockspec to use on current directory." - end end if not rockspec:match("rockspec$") then return nil, "Invalid argument: 'make' takes a rockspec as a parameter. "..util.see_help("make") diff --git a/test/testing.sh b/test/testing.sh index 74b39b8f..4be71fa6 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -421,9 +421,11 @@ test_list() { $luarocks list; } test_list_porcelain() { $luarocks list --porcelain; } test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } -test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } +test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks new_version lxsh-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } +test_make_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } +fail_make_ambiguous_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec lxsh2-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } +fail_make_ambiguous_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && mv lxsh-${verrev_lxsh}.rockspec 1_rockspec && cp 1_rockspec 2_rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } -fail_make_which_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; } -- cgit v1.2.3-55-g6feb From ca60d34cf161e778bd4df7d79cda6df479df20ca Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 19 Mar 2016 13:34:23 +0300 Subject: Doc fixes for luarocks.search --- src/luarocks/search.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index f1a82d5b..32af1f9e 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -48,7 +48,8 @@ end --- Store a search result (a rock or rockspec) in the results table. -- @param results table: The results table, where keys are package names and --- versions are tables matching version strings to an array of servers. +-- values are tables matching version strings to arrays of +-- tables with fields "arch" and "repo". -- @param name string: Package name. -- @param version string: Package version. -- @param arch string: Architecture of rock ("all", "src" or platform @@ -92,7 +93,8 @@ end -- table, optionally checking if version and arch (if given) match -- a query. -- @param results table: The results table, where keys are package names and --- versions are tables matching version strings to an array of servers. +-- values are tables matching version strings to arrays of +-- tables with fields "arch" and "repo". -- @param repo string: URL or pathname of the repository. -- @param name string: The name of the package being tested. -- @param version string: The version of the package being tested. @@ -123,8 +125,9 @@ end -- matches regardless of architecture. -- @param results table or nil: If given, this table will store the -- results; if not given, a new table will be created. --- @param table: The results table, where keys are package names and --- versions are tables matching version strings to an array of servers. +-- @return table: The results table, where keys are package names and +-- values are tables matching version strings to arrays of +-- tables with fields "arch" and "repo". -- If a table was given in the "results" parameter, that is the result value. function search.disk_search(repo, query, results) assert(type(repo) == "string") @@ -157,7 +160,8 @@ end --- Perform search on a rocks server or tree. -- @param results table: The results table, where keys are package names and --- versions are tables matching version strings to an array of servers. +-- values are tables matching version strings to arrays of +-- tables with fields "arch" and "repo". -- @param repo string: The URL of a rocks server or -- the pathname of a rocks tree (as returned by path.rocks_dir()). -- @param query table: A table describing the query in dependency @@ -190,8 +194,8 @@ end --- Search on all configured rocks servers. -- @param query table: A dependency query. -- @return table: A table where keys are package names --- and values are tables matching version strings to an array of --- rocks servers; if no results are found, an empty table is returned. +-- and values are tables matching version strings to arrays of +-- tables with fields "arch" and "repo". function search.search_repos(query) assert(type(query) == "table") -- cgit v1.2.3-55-g6feb From 0e0d4ea53d4791e051d7dd82103da5805ba22558 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 19 Mar 2016 13:54:10 +0300 Subject: Don't handle multiple rock queries in find_suitable_rock In practice search.find_suitable_rock is always called with a precise query (no fuzzy name matching), and not all callers handle table as return value correctly. --- src/luarocks/deps.lua | 8 ++++---- src/luarocks/install.lua | 16 ++++------------ src/luarocks/search.lua | 37 +++++++++++++++++-------------------- 3 files changed, 25 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index a2215351..278b6356 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -484,13 +484,13 @@ function deps.fulfill_dependencies(rockspec, deps_mode) for _, dep in pairs(missing) do -- Double-check in case dependency was filled during recursion. if not match_dep(dep, nil, deps_mode) then - local rock = search.find_suitable_rock(dep) - if not rock then + local url, err = search.find_suitable_rock(dep) + if not url then return nil, "Could not satisfy dependency: "..deps.show_dep(dep) end - local ok, err, errcode = install.run(rock, deps.deps_mode_to_flag(deps_mode)) + local ok, err, errcode = install.run(url, deps.deps_mode_to_flag(deps_mode)) if not ok then - return nil, "Failed installing dependency: "..rock.." - "..err, errcode + return nil, "Failed installing dependency: "..url.." - "..err, errcode end end end diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 6d457fc2..c938aa9f 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -186,20 +186,12 @@ function install.run(...) return name, version else local search = require("luarocks.search") - local results, err = search.find_suitable_rock(search.make_query(name:lower(), version)) - if err then + local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) + if not url then return nil, err - elseif type(results) == "string" then - local url = results - util.printout("Installing "..url.."...") - return install.run(url, util.forward_flags(flags)) - else - util.printout() - util.printerr("Could not determine which rock to install.") - util.title("Search results:") - search.print_results(results) - return nil, (next(results) and "Please narrow your query." or "No results found.") end + util.printout("Installing "..url.."...") + return install.run(url, util.forward_flags(flags)) end end diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 32af1f9e..5e6cf50e 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -278,28 +278,26 @@ local function pick_latest_version(name, versions) return nil end ---- Attempt to get a single URL for a given search. --- @param query table: A dependency query. --- @return string or table or (nil, string): URL for matching rock if --- a single one was found, a table of candidates if it could not narrow to --- a single result, or nil followed by an error message. +--- Attempt to get a single URL for a given search for a rock. +-- @param query table: A dependency query matching a single rock. +-- @return string or (nil, string): URL for latest matching version +-- of the rock if it was found, or nil followed by an error message. function search.find_suitable_rock(query) assert(type(query) == "table") local results = search.search_repos(query) - local first = next(results) - if not first then + local first_rock = next(results) + if not first_rock then return nil, "No results matching query were found." - elseif not next(results, first) then - if cfg.rocks_provided[query.name] ~= nil then - -- do not install versions that listed in cfg.rocks_provided - return nil, "Rock "..query.name.. - " "..cfg.rocks_provided[query.name].. - " was found but it is provided by VM or 'rocks_provided' in the config file." - end - return pick_latest_version(query.name, results[first]) + elseif next(results, first_rock) then + -- Shouldn't happen as query must match only one package. + return nil, "Several rocks matched query." + elseif cfg.rocks_provided[query.name] ~= nil then + -- Do not install versions listed in cfg.rocks_provided. + return nil, "Rock "..query.name.." "..cfg.rocks_provided[query.name].. + " was found but it is provided by VM or 'rocks_provided' in the config file." else - return results + return pick_latest_version(query.name, results[first_rock]) end end @@ -369,12 +367,11 @@ function search.act_on_src_or_rockspec(action, name, version, ...) local query = search.make_query(name, version) query.arch = "src|rockspec" - local results, err = search.find_suitable_rock(query) - if type(results) == "string" then - return action(results, ...) - else + local url, err = search.find_suitable_rock(query) + if not url then return nil, "Could not find a result named "..name..(version and " "..version or "").."." end + return action(url, ...) end --- Driver function for "search" command. -- cgit v1.2.3-55-g6feb From b29a5d1ac614b02d0c8b7b0a4a7413a8d77007c6 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sun, 20 Mar 2016 12:57:43 +0300 Subject: Refactor download.download search.find_suitable_rock now can't return a table. --- src/luarocks/download.lua | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index 74ed40e9..d241fca8 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -37,26 +37,21 @@ local function get_file(filename) end function download.download(arch, name, version, all) - local results, err local query = search.make_query(name, version) if arch then query.arch = arch end + if all then if name == "" then query.exact_name = false end - results = search.search_repos(query) - else - results, err = search.find_suitable_rock(query) - end - if type(results) == "string" then - return get_file(results) - elseif type(results) == "table" and next(results) then - if all then + local results = search.search_repos(query) + + if next(results) then local all_ok = true local any_err = "" for name, result in pairs(results) do - for version, versions in pairs(result) do - for _,items in pairs(versions) do - local filename = path.make_url(items.repo, name, version, items.arch) - local ok, err = get_file(filename) + for version, items in pairs(result) do + for _, item in ipairs(items) do + local url = path.make_url(item.repo, name, version, item.arch) + local ok, err = get_file(url) if not ok then all_ok = false any_err = any_err .. "\n" .. err @@ -65,11 +60,11 @@ function download.download(arch, name, version, all) end end return all_ok, any_err - else - util.printerr("Multiple search results were returned.") - util.title("Search results:") - search.print_results(results) - return nil, "Please narrow your query or use --all." + end + else + local url = search.find_suitable_rock(query) + if url then + return get_file(url) end end return nil, "Could not find a result named "..name..(version and " "..version or "").."." -- cgit v1.2.3-55-g6feb From 88e16001e37eab28f5d6f4c242f65b8a4c2a1e33 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 19 Mar 2016 14:31:33 +0300 Subject: Fix stat error on `luarocks download --all` --- src/luarocks/download.lua | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index d241fca8..f08ba7fe 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -43,15 +43,17 @@ function download.download(arch, name, version, all) if all then if name == "" then query.exact_name = false end local results = search.search_repos(query) - - if next(results) then - local all_ok = true - local any_err = "" - for name, result in pairs(results) do - for version, items in pairs(result) do - for _, item in ipairs(items) do - local url = path.make_url(item.repo, name, version, item.arch) - local ok, err = get_file(url) + local has_result = false + local all_ok = true + local any_err = "" + for name, result in pairs(results) do + for version, items in pairs(result) do + for _, item in ipairs(items) do + -- Ignore provided rocks. + if item.arch ~= "installed" then + has_result = true + local filename = path.make_url(item.repo, name, version, item.arch) + local ok, err = get_file(filename) if not ok then all_ok = false any_err = any_err .. "\n" .. err @@ -59,6 +61,9 @@ function download.download(arch, name, version, all) end end end + end + + if has_result then return all_ok, any_err end else -- cgit v1.2.3-55-g6feb From b0d396b22febd4b3b717f6ddc3732c9dc57fad7c Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 22 Mar 2016 11:21:01 +0300 Subject: luarocks show: print modules and deps sorted Affects order when --modules and --deps flags are used. --- src/luarocks/show.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 08b2673f..0f29e468 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -28,7 +28,9 @@ With these flags, return only the desired information: ]] local function keys_as_string(t, sep) - return table.concat(util.keys(t), sep or " ") + local keys = util.keys(t) + table.sort(keys) + return table.concat(keys, sep or " ") end local function word_wrap(line) -- cgit v1.2.3-55-g6feb From 0af7e42eb7814424ce8365897593abb9fc62ce14 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Tue, 22 Mar 2016 11:40:34 +0300 Subject: luarocks show: split direct and indirect deps Additionally show constraints for direct deps and versions used for all deps. --- src/luarocks/show.lua | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 0f29e468..ae41a513 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -90,6 +90,16 @@ function show.pick_installed_rock(name, version, tree) return name, version, repo, repo_url end +local function installed_rock_label(name, tree) + local installed, version + if cfg.rocks_provided[name] then + installed, version = true, cfg.rocks_provided[name] + else + installed, version = show.pick_installed_rock(name, nil, tree) + end + return installed and "(using "..version..")" or "(missing)" +end + --- Driver function for "show" command. -- @param name or nil: an existing package name. -- @param version string or nil: a version may also be passed. @@ -145,10 +155,26 @@ function show.run(...) util.printout("\t"..mod.." ("..path.which(mod, filename, name, version, repo, manifest)..")") end end - if next(minfo.dependencies) then + local direct_deps = {} + if #rockspec.dependencies > 0 then util.printout() util.printout("Depends on:") - util.printout("\t"..keys_as_string(minfo.dependencies, "\n\t")) + for _, dep in ipairs(rockspec.dependencies) do + direct_deps[dep.name] = true + util.printout("\t"..deps.show_dep(dep).." "..installed_rock_label(dep.name, flags["tree"])) + end + end + local has_indirect_deps + for dep_name in util.sortedpairs(minfo.dependencies) do + if not direct_deps[dep_name] then + if not has_indirect_deps then + util.printout() + util.printout("Indirectly pulling:") + has_indirect_deps = true + end + + util.printout("\t"..dep_name.." "..installed_rock_label(dep_name, flags["tree"])) + end end util.printout() end -- cgit v1.2.3-55-g6feb From fde1b0777855999d5ef04585d73a1a2046ce517d Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 14 Apr 2016 19:16:59 +0300 Subject: Quote archive name when unpacking Also use vars.TAR instead of literal "tar" when unpacking .tar.bz2 --- src/luarocks/fs/unix/tools.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 442004ce..fed9c426 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -295,9 +295,9 @@ function tools.unpack_archive(archive) local ok if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then - ok = fs.execute_string(vars.GUNZIP.." -c "..archive.."|"..vars.TAR.." -xf -") + ok = fs.execute_string(vars.GUNZIP.." -c "..fs.Q(archive).." | "..vars.TAR.." -xf -") elseif archive:match("%.tar%.bz2$") then - ok = fs.execute_string(vars.BUNZIP2.." -c "..archive.."|tar -xf -") + ok = fs.execute_string(vars.BUNZIP2.." -c "..fs.Q(archive).." | "..vars.TAR.." -xf -") elseif archive:match("%.zip$") then ok = fs.execute(vars.UNZIP, archive) elseif archive:match("%.lua$") or archive:match("%.c$") then -- cgit v1.2.3-55-g6feb From 6fc4b35d4e89e83e15c47d0163c3ced47f236b7d Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 14 Apr 2016 19:53:12 +0300 Subject: Fix loud archive unpacking In luarocks.fs.unix.tools.unpack_archive execute commands in quiet mode (that is, silenced by default, but not with --verbose), like in luarocks.fs.unzip and luarocks.fs.win32.tools.unpack_archive. --- src/luarocks/fs/unix/tools.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index fed9c426..767bae4d 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -293,13 +293,19 @@ end function tools.unpack_archive(archive) assert(type(archive) == "string") + local pipe_to_tar = " | "..vars.TAR.." -xf -" + + if not cfg.verbose then + pipe_to_tar = " 2> /dev/null"..fs.quiet(pipe_to_tar) + end + local ok if archive:match("%.tar%.gz$") or archive:match("%.tgz$") then - ok = fs.execute_string(vars.GUNZIP.." -c "..fs.Q(archive).." | "..vars.TAR.." -xf -") + ok = fs.execute_string(vars.GUNZIP.." -c "..fs.Q(archive)..pipe_to_tar) elseif archive:match("%.tar%.bz2$") then - ok = fs.execute_string(vars.BUNZIP2.." -c "..fs.Q(archive).." | "..vars.TAR.." -xf -") + ok = fs.execute_string(vars.BUNZIP2.." -c "..fs.Q(archive)..pipe_to_tar) elseif archive:match("%.zip$") then - ok = fs.execute(vars.UNZIP, archive) + ok = fs.execute_quiet(vars.UNZIP, archive) elseif archive:match("%.lua$") or archive:match("%.c$") then -- Ignore .lua and .c files; they don't need to be extracted. return true -- cgit v1.2.3-55-g6feb