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(-) 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(-) 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(-) 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 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(-) 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(-) 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(-) 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(-) 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 5571c28fb73edcfc91ecdf44257481a12357c500 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 11 Feb 2016 17:27:21 +0300 Subject: Add a test for luarocks new_version --tag --- test/testing.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/testing.sh b/test/testing.sh index 44e78205..74b39b8f 100755 --- a/test/testing.sh +++ b/test/testing.sh @@ -427,6 +427,7 @@ fail_make_which_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks 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-*; } +test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; } test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; } test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; } -- 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(-) 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(-) 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