From 88c6b1010984ea0596089858865cca55876e55c3 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 14 Oct 2013 23:07:28 -0300 Subject: Improvements for write_rockspec --- src/luarocks/fetch.lua | 6 +++--- src/luarocks/write_rockspec.lua | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 111d229a..3ba90647 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -274,7 +274,7 @@ function get_sources(rockspec, extract, dest_dir) local source_file, store_dir, err, errcode if dest_dir then local ok, err = fs.change_dir(dest_dir) - if not ok then return nil, err end + if not ok then return nil, err, "dest_dir" end source_file, err, errcode = fetch_url(url, filename) fs.pop_dir() store_dir = dest_dir @@ -286,7 +286,7 @@ function get_sources(rockspec, extract, dest_dir) end if rockspec.source.md5 then if not fs.check_md5(source_file, rockspec.source.md5) then - return nil, "MD5 check for "..filename.." has failed." + return nil, "MD5 check for "..filename.." has failed.", "md5" end end if extract then @@ -294,7 +294,7 @@ function get_sources(rockspec, extract, dest_dir) if not ok then return nil, err end fs.unpack_archive(rockspec.source.file) if not fs.exists(rockspec.source.dir) then - return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file + return nil, "Directory "..rockspec.source.dir.." not found inside archive "..rockspec.source.file, "source.dir", source_file, store_dir end fs.pop_dir() end diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 9c20a054..6bfa4f1c 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua @@ -36,8 +36,10 @@ rockspec, and is not guaranteed to be complete or correct. local function get_url(rockspec) local url = rockspec.source.url - local file, temp_dir = fetch.fetch_sources(rockspec, true) - if not file then + local file, temp_dir, err_code, err_file, err_temp_dir = fetch.fetch_sources(rockspec, true) + if err_code == "source.dir" then + file, temp_dir = err_file, err_temp_dir + elseif not file then util.warning("Could not fetch sources - "..temp_dir) return false end @@ -96,6 +98,17 @@ local function detect_description(rockspec) end end +local function show_license(rockspec) + local fd = io.open("COPYING", "r") + if not fd then fd = io.open("LICENSE", "r") end + if not fd then return end + local data = fd:read("*a") + fd:close() + util.title("License for "..rockspec.package..":") + util.printout(data) + util.printout() +end + local function get_cmod_name(file) local fd = io.open(file, "r") if not fd then return nil end @@ -183,6 +196,11 @@ function run(...) local_dir = name version = "scm" name = dir.base_name(name):gsub("%.[^.]+$", "") + elseif protocol ~= "file" then + local_dir = name + local filename = dir.base_name(name) + name, version = filename:match("(.*)-([^-]+)") + version = version:gsub(".[a-z]+$", ""):gsub(".tar$", "") else return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") end @@ -223,6 +241,8 @@ function run(...) if local_dir:match("://") then rockspec.source.url = local_dir + rockspec.source.file = dir.base_name(local_dir) + rockspec.source.dir = "dummy" if not fetch.is_basic_protocol(rockspec.source.protocol) then if version ~= "scm" then rockspec.source.tag = "v" .. version @@ -261,6 +281,8 @@ function run(...) if not ok then return nil, "Failed reaching files from project - error entering directory "..local_dir end detect_description(rockspec) + + show_license(rockspec) fill_as_builtin(rockspec, libs) -- cgit v1.2.3-55-g6feb