From 16c2c973b0a1e6c8e94a4ba904c122cfd355f082 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sat, 4 Jan 2014 00:47:36 -0200 Subject: Improvements to the write_rockspec command. Let's make this more and more automagical over time. :) --- src/luarocks/write_rockspec.lua | 66 ++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index f8035b8d..a27f0b63 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua @@ -31,10 +31,14 @@ rockspec, and is not guaranteed to be complete or correct. --homepage= Project homepage. --lua-version= Supported Lua versions. Accepted values are "5.1", "5.2" or "5.1,5.2". +--tag= Tag to use. Will attempt to extract version number from it. --lib=[,] A comma-separated list of libraries that C files need to link to. ]] +local function open_file(name) + return io.open(dir.path(fs.current_dir(), name), "r") +end local function get_url(rockspec) local url = rockspec.source.url @@ -79,12 +83,11 @@ local function configure_lua_version(rockspec, luaver) end local function detect_description(rockspec) - local fd = io.open("README.md", "r") - if not fd then fd = io.open("README", "r") end + local fd = open_file("README.md") or open_file("README") if not fd then return end local data = fd:read("*a") fd:close() - local paragraph = data:match("\n\n(.-)\n\n") + local paragraph = data:match("\n\n([^%[].-)\n\n") if not paragraph then paragraph = data:match("\n\n(.*)") end if paragraph then if #paragraph < 80 then @@ -100,19 +103,32 @@ local function detect_description(rockspec) end end +local function detect_mit_license(data) + local strip_copyright = (data:gsub("Copyright [^\n]*\n", "")) + local sum = 0 + for i = 1, #strip_copyright do + local num = string.byte(strip_copyright:sub(i,i)) + if num > 32 and num <= 128 then + sum = sum + num + end + end + return sum == 78656 +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 fd = open_file("COPYING") or open_file("LICENSE") or open_file("MIT-LICENSE.txt") + if not fd then return nil end local data = fd:read("*a") fd:close() + local is_mit = detect_mit_license(data) util.title("License for "..rockspec.package..":") util.printout(data) util.printout() + return is_mit end local function get_cmod_name(file) - local fd = io.open(file, "r") + local fd = open_file(file) if not fd then return nil end local data = fd:read("*a") fd:close() @@ -199,22 +215,35 @@ function run(...) elseif not url_or_dir then url_or_dir = version end + + if flags["tag"] == true then + return nil, "Incorrect usage: --tag requires an argument. "..util.see_help("write_rockspec") + end + + if flags["tag"] then + if not version then + version = flags["tag"]:gsub("^v", "") + end + end local protocol, pathname = dir.split_url(url_or_dir) if not fetch.is_basic_protocol(protocol) then - version = "scm" if not name then name = dir.base_name(url_or_dir):gsub("%.[^.]+$", "") end + if not version then + version = "scm" + end elseif protocol ~= "file" then local filename = dir.base_name(url_or_dir) local newname, newversion = filename:match("(.*)-([^-]+)") - if not name then + if (not name) and newname then name = newname end - if newversion then + if (not version) and newversion then version = newversion:gsub(".[a-z]+$", ""):gsub(".tar$", "") - else + end + if not (name and version) then return nil, "Missing name and version arguments. "..util.see_help("write_rockspec") end elseif not version then @@ -222,13 +251,18 @@ function run(...) end local filename = flags["output"] or dir.path(fs.current_dir(), name:lower().."-"..version.."-1.rockspec") + + if not flags["homepage"] and url_or_dir:match("^git://github.com") then + flags["homepage"] = "http://"..url_or_dir:match("^[^:]+://(.*)") + end local rockspec = { package = name, name = name:lower(), version = version.."-1", source = { - url = "*** please add URL for source tarball, zip or repository here ***" + url = "*** please add URL for source tarball, zip or repository here ***", + tag = flags["tag"], }, description = { summary = flags["summary"] or "*** please specify description summary ***", @@ -252,7 +286,7 @@ function run(...) rockspec.source.dir = "dummy" if not fetch.is_basic_protocol(rockspec.source.protocol) then if version ~= "scm" then - rockspec.source.tag = "v" .. version + rockspec.source.tag = flags["tag"] or "v" .. version end end rockspec.source.dir = nil @@ -290,7 +324,11 @@ function run(...) detect_description(rockspec) - show_license(rockspec) + local is_mit = show_license(rockspec) + + if is_mit and not flags["license"] then + rockspec.description.license = "MIT" + end fill_as_builtin(rockspec, libs) -- cgit v1.2.3-55-g6feb From 2511c8377f6c924625b10d6e6cc77c5053890b94 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 7 Jan 2014 13:37:23 -0200 Subject: Add help on --deps-mode --- src/luarocks/build.lua | 3 ++- src/luarocks/install.lua | 3 ++- src/luarocks/remove.lua | 3 ++- src/luarocks/util.lua | 20 ++++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index ec269023..72b5649e 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -31,7 +31,8 @@ or the name of a rock to be fetched from a repository. rock after building a new one. This behavior can be made permanent by setting keep_other_versions=true in the configuration file. -]] + +]]..util.deps_mode_help() --- Install files to a given location. -- Takes a table where the array part is a list of filenames to be copied. diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index b28e6282..7458ec8e 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -25,7 +25,8 @@ or a filename of a locally available rock. rock after installing a new one. This behavior can be made permanent by setting keep_other_versions=true in the configuration file. -]] +]]..util.deps_mode_help() + --- Install a binary rock. -- @param rock_file string: local or remote filename of a rock. diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index f2f6997b..8f751a93 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -22,7 +22,8 @@ Will only perform the removal if it does not break dependencies. To override this check and force the removal, use --force. To perform a forced removal without reporting dependency issues, use --force=fast. -]] + +]]..util.deps_mode_help() --- Obtain a list of packages that depend on the given set of packages -- (where all packages of the set are versions of one program). diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 1a60fd9c..4b138516 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -8,6 +8,8 @@ local global_env = _G module("luarocks.util", package.seeall) +local cfg = require("luarocks.cfg") + local scheduled_functions = {} local debug = require("debug") @@ -371,6 +373,24 @@ function this_program(default) return last:sub(2) end +function deps_mode_help(program) + return [[ +--deps-mode= How to handle dependencies. Four modes are supported: + * all - use all trees from the rocks_trees list + for finding dependencies + * one - use only the current tree (possibly set + with --tree) + * order - use trees based on order (use the current + tree and all trees below it on the rocks_trees list) + * none - ignore dependencies altogether. + The default mode may be set with the deps_mode entry + in the configuration file. + The current default is "]]..cfg.deps_mode..[[". + Type ']]..this_program(program or "luarocks")..[[' with no arguments to see + your list of rocks trees. +]] +end + function see_help(command, program) return "See '"..this_program(program or "luarocks")..' help '..command.."'." end -- cgit v1.2.3-55-g6feb From 757539bac6ed6271d9f125a36c77dcd7366e7f50 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 9 Jan 2014 20:42:25 -0200 Subject: Performance improvements --- src/bin/luarocks | 36 ++++++++++--------- src/luarocks/build/builtin.lua | 3 +- src/luarocks/command_line.lua | 3 +- src/luarocks/deps.lua | 2 +- src/luarocks/dir.lua | 14 +++----- src/luarocks/fetch.lua | 18 ++++++---- src/luarocks/help.lua | 19 +++++----- src/luarocks/index.lua | 11 +++--- src/luarocks/manif.lua | 79 +++++++++++++++++++++++++++--------------- src/luarocks/search.lua | 7 ++-- 10 files changed, 108 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/bin/luarocks b/src/bin/luarocks index 6ab27fa3..e9cfc349 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -5,22 +5,24 @@ local command_line = require("luarocks.command_line") program_description = "LuaRocks main command-line interface" -commands = {} -commands.help = require("luarocks.help") -commands.pack = require("luarocks.pack") -commands.unpack = require("luarocks.unpack") -commands.build = require("luarocks.build") -commands.install = require("luarocks.install") -commands.search = require("luarocks.search") -commands.list = require("luarocks.list") -commands.remove = require("luarocks.remove") -commands.make = require("luarocks.make") -commands.download = require("luarocks.download") -commands.path = require("luarocks.path") -commands.show = require("luarocks.show") -commands.new_version = require("luarocks.new_version") -commands.lint = require("luarocks.lint") -commands.write_rockspec = require("luarocks.write_rockspec") -commands.purge = require("luarocks.purge") +commands = { + help = "luarocks.help", + pack = "luarocks.pack", + unpack = "luarocks.unpack", + build = "luarocks.build", + install = "luarocks.install", + search = "luarocks.search", + list = "luarocks.list", + remove = "luarocks.remove", + make = "luarocks.make", + download = "luarocks.download", + path = "luarocks.path", + show = "luarocks.show", + new_version = "luarocks.new_version", + lint = "luarocks.lint", + write_rockspec = "luarocks.write_rockspec", + purge = "luarocks.purge", + doc = "luarocks.doc", +} command_line.run_command(...) diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index f9ef4c44..5c58265a 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -235,8 +235,9 @@ function run(rockspec) table.insert(objects, object) end if not ok then break end - local module_name = dir.path(moddir, name:match("([^.]*)$").."."..util.matchquote(cfg.lib_extension)):gsub("//", "/") + 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) if not ok then return nil, err end end diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index e79b1442..19d04290 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -185,7 +185,8 @@ function run_command(...) -- I'm not changing this now to avoid messing with the run() -- interface, which I know some people use (even though -- I never published it as a public API...) - local xp, ok, err, exitcode = xpcall(function() return commands[command].run(unpack(args)) end, function(err) + local cmd = require(commands[command]) + local xp, ok, err, exitcode = xpcall(function() return cmd.run(unpack(args)) end, function(err) die(debug.traceback("LuaRocks "..cfg.program_version .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" ..err, 2)) diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 116b4bbb..0adb5834 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -689,7 +689,7 @@ function scan_deps(results, missing, manifest, name, version, deps_mode) local deplist = dependencies_name[version] local rockspec, err if not deplist then - rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version)) + rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version), false) if err then missing[name.." "..version] = err return results, missing diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index e8cd746e..1f3b5c3d 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -35,17 +35,11 @@ end -- @return string: a string with a platform-specific representation -- of the path. function path(...) - local items = {...} - local i = 1 - while items[i] do - items[i] = items[i]:gsub("(.+)/+$", "%1") - if items[i] == "" then - table.remove(items, i) - else - i = i + 1 - end + local t = {...} + while t[1] == "" do + table.remove(t, 1) end - return (table.concat(items, "/"):gsub("(.+)/+$", "%1")) + return (table.concat(t, "/"):gsub("([^:])/+", "%1/"):gsub("^/+", "/"):gsub("/*$", "")) end --- Split protocol and path from an URL or local pathname. diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 53c9d748..83ab6fa9 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -137,9 +137,11 @@ end --- Back-end function that actually loads the local rockspec. -- Performs some validation and postprocessing of the rockspec contents. -- @param filename string: The local filename of the rockspec file. +-- @param quick boolean: if true, skips some steps when loading +-- rockspec. -- @return table or (nil, string): A table representing the rockspec -- or nil followed by an error message. -function load_local_rockspec(filename) +function load_local_rockspec(filename, quick) assert(type(filename) == "string") filename = fs.absolute_name(filename) local rockspec, err = persist.load_into_table(filename) @@ -147,9 +149,12 @@ function load_local_rockspec(filename) return nil, "Could not load rockspec file "..filename.." ("..err..")" end - local ok, err = type_check.type_check_rockspec(rockspec) - if not ok then - return nil, filename..": "..err + local ok, err = true, nil + if not quick then + ok, err = type_check.type_check_rockspec(rockspec) + if not ok then + return nil, filename..": "..err + end end if rockspec.rockspec_format then @@ -207,9 +212,8 @@ function load_local_rockspec(filename) else rockspec.dependencies = {} end - local ok, err = path.configure_paths(rockspec) - if err then - return nil, "Error verifying paths: "..err + if not quick then + path.configure_paths(rockspec) end return rockspec diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 2774dc41..2136f5da 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua @@ -71,14 +71,10 @@ function run(...) can be overriden with VAR=VALUE assignments.]]) print_section("COMMANDS") local names = {} - for name, command in pairs(commands) do - table.insert(names, name) - end - table.sort(names) - for _, name in ipairs(names) do - local command = commands[name] + for name, command in util.sortedpairs(commands) do + local cmd = require(command) util.printout("", name) - util.printout("\t", command.help_summary) + util.printout("\t", cmd.help_summary) end print_section("CONFIGURATION") util.printout("\tLua version: " .. cfg.lua_version) @@ -100,15 +96,16 @@ function run(...) end else command = command:gsub("-", "_") - if commands[command] then - local arguments = commands[command].help_arguments or "" + local cmd = require(commands[command]) + if cmd then + local arguments = cmd.help_arguments or "" print_banner() print_section("NAME") - util.printout("\t"..program.." "..command.." - "..commands[command].help_summary) + util.printout("\t"..program.." "..command.." - "..cmd.help_summary) print_section("SYNOPSIS") util.printout("\t"..program.." "..command.." "..arguments) print_section("DESCRIPTION") - util.printout("",(commands[command].help:gsub("\n","\n\t"):gsub("\n\t$",""))) + util.printout("",(cmd.help:gsub("\n","\n\t"):gsub("\n\t$",""))) print_section("SEE ALSO") util.printout("","'"..program.." help' for general options and configuration.\n") else diff --git a/src/luarocks/index.lua b/src/luarocks/index.lua index e0785d9c..1ce66f70 100644 --- a/src/luarocks/index.lua +++ b/src/luarocks/index.lua @@ -139,15 +139,14 @@ function make_index(repo) output = output..version..': ' table.sort(data, function(a,b) return a.arch < b.arch end) for _, item in ipairs(data) do - local link = ''..item.arch..'' + local file if item.arch == 'rockspec' then - local rs = ("%s-%s.rockspec"):format(package, version) - if not latest_rockspec then latest_rockspec = rs end - link = link:gsub("$url", rs) + file = ("%s-%s.rockspec"):format(package, version) + if not latest_rockspec then latest_rockspec = file end else - link = link:gsub("$url", ("%s-%s.%s.rock"):format(package, version, item.arch)) + file = ("%s-%s.%s.rock"):format(package, version, item.arch) end - table.insert(versions, link) + table.insert(versions, ''..item.arch..'') end output = output .. table.concat(versions, ', ') .. '
' end diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 238c4056..ed1780b3 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -231,18 +231,11 @@ end -- @param deps_mode string: Dependency mode: "one" for the current default tree, -- "all" for all trees, "order" for all trees with priority >= the current default, -- "none" for no trees. --- @param repodir string: directory of repository being scanned --- @param filter_lua string or nil: filter by Lua version --- @param cache table: temporary rockspec cache table -local function update_dependencies(manifest, deps_mode, repodir, filter_lua, cache) +local function update_dependencies(manifest, deps_mode) assert(type(manifest) == "table") assert(type(deps_mode) == "string") - cache = cache or {} - local lua_version = filter_lua and deps.parse_version(filter_lua) - for pkg, versions in pairs(manifest.repository) do - local to_remove = {} for version, repositories in pairs(versions) do local current = pkg.." "..version for _, repo in ipairs(repositories) do @@ -259,11 +252,34 @@ local function update_dependencies(manifest, deps_mode, repodir, filter_lua, cac end end end - elseif filter_lua and repo.arch == "rockspec" then + end + end + end + end +end + +--- Filter manifest table by Lua version, removing rockspecs whose Lua version +-- does not match. +-- @param manifest table: a manifest table. +-- @param lua_version string or nil: filter by Lua version +-- @param repodir string: directory of repository being scanned +-- @param cache table: temporary rockspec cache table +local function filter_by_lua_version(manifest, lua_version, repodir, cache) + assert(type(manifest) == "table") + assert(type(repodir) == "string") + assert((not cache) or type(cache) == "table") + + cache = cache or {} + lua_version = deps.parse_version(lua_version) + for pkg, versions in pairs(manifest.repository) do + local to_remove = {} + for version, repositories in pairs(versions) do + for _, repo in ipairs(repositories) do + if repo.arch == "rockspec" then local pathname = dir.path(repodir, pkg.."-"..version..".rockspec") local rockspec, err = cache[pathname] if not rockspec then - rockspec, err = fetch.load_local_rockspec(pathname) + rockspec, err = fetch.load_local_rockspec(pathname, true) end if rockspec then cache[pathname] = rockspec @@ -283,9 +299,9 @@ local function update_dependencies(manifest, deps_mode, repodir, filter_lua, cac end if next(to_remove) then for _, incompat in ipairs(to_remove) do - manifest.repository[pkg][incompat] = nil + versions[incompat] = nil end - if not next(manifest.repository[pkg]) then + if not next(versions) then manifest.repository[pkg] = nil end end @@ -296,17 +312,12 @@ end -- @param results table: The search results as returned by search.disk_search. -- @param manifest table: A manifest table (must contain repository, modules, commands tables). -- It will be altered to include the search results. --- @param deps_mode string: Dependency mode: "one" for the current default tree, --- "all" for all trees, "order" for all trees with priority >= the current default, --- "none" for no trees. --- @param repo string: directory of repository --- @param filter_lua string or nil: filter by Lua version --- @param cache table: temporary rockspec cache table +-- @param dep_handler: dependency handler function -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. -local function store_results(results, manifest, deps_mode, repo, filter_lua, cache) +local function store_results(results, manifest, dep_handler) assert(type(results) == "table") assert(type(manifest) == "table") - assert(type(deps_mode) == "string") + assert((not dep_handler) or type(dep_handler) == "function") for name, versions in pairs(results) do local pkgtable = manifest.repository[name] or {} @@ -329,7 +340,9 @@ local function store_results(results, manifest, deps_mode, repo, filter_lua, cac end manifest.repository[name] = pkgtable end - update_dependencies(manifest, deps_mode, repo, filter_lua, cache) + if dep_handler then + dep_handler(manifest) + end sort_package_matching_table(manifest.modules) sort_package_matching_table(manifest.commands) return true @@ -345,7 +358,7 @@ end -- @param versioned boolean: if versioned versions of the manifest should be created. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. -function make_manifest(repo, deps_mode, versioned) +function make_manifest(repo, deps_mode, remote) assert(type(repo) == "string") assert(type(deps_mode) == "string") @@ -363,14 +376,23 @@ function make_manifest(repo, deps_mode, versioned) manif_core.manifest_cache[repo] = manifest - local cache = {} - local ok, err = store_results(results, manifest, deps_mode, repo, nil, cache) + local dep_handler = nil + if not remote then + dep_handler = function(manifest) + update_dependencies(manifest, deps_mode) + end + end + local ok, err = store_results(results, manifest, dep_handler) if not ok then return nil, err end - if versioned then + if remote then + local cache = {} for luaver in util.lua_versions() do local vmanifest = { repository = {}, modules = {}, commands = {} } - local ok, err = store_results(results, vmanifest, deps_mode, repo, luaver, cache) + local dep_handler = function(manifest) + filter_by_lua_version(manifest, luaver, repo, cache) + end + local ok, err = store_results(results, vmanifest, dep_handler) save_table(repo, "manifest-"..luaver, vmanifest) end end @@ -416,7 +438,10 @@ function update_manifest(name, version, repo, deps_mode) local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} - local ok, err = store_results(results, manifest, deps_mode, repo) + local dep_handler = function(manifest) + update_dependencies(manifest, deps_mode) + end + local ok, err = store_results(results, manifest, dep_handler) if not ok then return nil, err end return save_table(repo, "manifest", manifest) diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 76ea6815..ad205d6a 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -139,14 +139,15 @@ function disk_search(repo, query, results) for _, name in pairs(fs.list_dir(repo)) do local pathname = dir.path(repo, name) local rname, rversion, rarch = path.parse_name(name) - if fs.is_dir(pathname) then + + if rname and (pathname:match(".rockspec$") or pathname:match(".rock$")) then + store_if_match(results, repo, rname, rversion, rarch, query) + elseif fs.is_dir(pathname) then for _, version in pairs(fs.list_dir(pathname)) do if version:match("-%d+$") then store_if_match(results, repo, name, version, "installed", query) end end - elseif rname then - store_if_match(results, repo, rname, rversion, rarch, query) end end return results -- cgit v1.2.3-55-g6feb From fec24d3a9ef8650ace58d8c6c967405fadb2fd33 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 9 Jan 2014 21:57:58 -0200 Subject: Add missing commit of luarocks-admin command changes --- src/bin/luarocks-admin | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 983dda87..e7f49c25 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin @@ -6,12 +6,11 @@ local command_line = require("luarocks.command_line") program_description = "LuaRocks repository administration interface" commands = { + help = "luarocks.help", + make_manifest = "luarocks.make_manifest", + add = "luarocks.add", + remove = "luarocks.admin_remove", + refresh_cache = "luarocks.refresh_cache", } -commands.help = require("luarocks.help") -commands.make_manifest = require("luarocks.make_manifest") -commands.add = require("luarocks.add") -commands.remove = require("luarocks.admin_remove") -commands.refresh_cache = require("luarocks.refresh_cache") - command_line.run_command(...) -- cgit v1.2.3-55-g6feb From 4ec138869a1543389de638f93e5297ad9a7212d8 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 9 Jan 2014 22:14:29 -0200 Subject: Looks like I ran the test suite locally in the wrong branch --- src/bin/luarocks | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/bin/luarocks b/src/bin/luarocks index e9cfc349..72f04c83 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -22,7 +22,6 @@ commands = { lint = "luarocks.lint", write_rockspec = "luarocks.write_rockspec", purge = "luarocks.purge", - doc = "luarocks.doc", } command_line.run_command(...) -- cgit v1.2.3-55-g6feb From 74a46a38dbe37eb4a8bca9af9f65a3289797bfbe Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 00:46:36 -0200 Subject: First go on `luarocks doc` --- src/luarocks/doc.lua | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 src/luarocks/doc.lua (limited to 'src') diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua new file mode 100644 index 00000000..9fb9d688 --- /dev/null +++ b/src/luarocks/doc.lua @@ -0,0 +1,146 @@ + +--- Module implementing the LuaRocks "doc" command. +-- Shows documentation for an installed rock. +module("luarocks.doc", package.seeall) + +local util = require("luarocks.util") +local show = require("luarocks.show") +local path = require("luarocks.path") +local dir = require("luarocks.dir") +local fetch = require("luarocks.fetch") +local fs = require("luarocks.fs") +--[[ +local search = require("luarocks.search") +local cfg = require("luarocks.cfg") +local deps = require("luarocks.deps") +local manif = require("luarocks.manif") +]] +help_summary = "Shows documentation for an installed rock." + +help = [[ + is an existing package name. +Without any flags, tries to load the documentation +using a series of heuristics. +With these flags, return only the desired information: + +--home Open the home page of project. + +For more information about a rock, see the 'show' command. +]] + +--[[ +local function keys_as_string(t, sep) + return table.concat(util.keys(t), sep or " ") +end + +local function word_wrap(line) + local width = tonumber(os.getenv("COLUMNS")) or 80 + if width > 80 then width = 80 end + if #line > width then + local brk = width + while brk > 0 and line:sub(brk, brk) ~= " " do + brk = brk - 1 + end + if brk > 0 then + return line:sub(1, brk-1) .. "\n" .. word_wrap(line:sub(brk+1)) + end + end + return line +end + +local function format_text(text) + text = text:gsub("^%s*",""):gsub("%s$", ""):gsub("\n[ \t]+","\n"):gsub("([^\n])\n([^\n])","%1 %2") + local paragraphs = util.split_string(text, "\n\n") + for n, line in ipairs(paragraphs) do + paragraphs[n] = word_wrap(line) + end + return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) +end + +local function module_name(mod, filename, name, version, repo, manifest) + local base_dir + if filename:match("%.lua$") then + base_dir = path.deploy_lua_dir(repo) + else + base_dir = path.deploy_lib_dir(repo) + end + + return dir.path(base_dir, filename) +end +]] + +--- Driver function for "doc" command. +-- @param name or nil: an existing package name. +-- @param version string or nil: a version may also be passed. +-- @return boolean: True if succeeded, nil on errors. +function run(...) + local flags, name, version = util.parse_flags(...) + if not name then + return nil, "Argument missing. "..util.see_help("doc") + end + + local repo + name, version, repo = show.pick_installed_rock(name, version, flags["tree"]) + if not name then + return nil, version + end + + local rockspec, err = fetch.load_local_rockspec(path.rockspec_file(name, version, repo)) + if not rockspec then return nil,err end + local descript = rockspec.description or {} + + if flags["home"] then + util.printout("Opening "..descript.homepage.." ...") + fs.browser(descript.homepage) + return true + end + + local directory = path.install_dir(name,version,repo) + + local docdir + local directories = { "doc", "docs" } + for _, d in ipairs(directories) do + local dirname = dir.path(directory, d) + if fs.is_dir(dirname) then + docdir = dirname + break + end + end + if not docdir then + if descript.homepage then + util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") + fs.browser(descript.homepage) + return true + end + return nil, "Documentation directory not found for "..name.." "..version + end + + local files = fs.find(docdir) + local extensions = { ".html", ".md", ".txt", "" } + local basenames = { "index", "readme", "manual" } + + for _, extension in ipairs(extensions) do + for _, basename in ipairs(basenames) do + local filename = basename..extension + local found + for _, file in ipairs(files) do + if file:lower():match(filename) and ((not found) or #file < #found) then + found = file + end + end + if found then + local pathname = dir.path(docdir, found) + util.printout("Opening "..pathname.." ...") + if not fs.browser(pathname) then + local fd = io.open(pathname, "r") + util.printout(fd:read("*a")) + fd:close() + end + return true + end + end + end + + return true +end + -- cgit v1.2.3-55-g6feb From 64e386ed2c988910451079eb5879a2221976a644 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:05:48 -0200 Subject: Add default web browsers --- src/luarocks/cfg.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 87777b86..5e43535b 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -342,6 +342,7 @@ if detected.windows then localappdata = os.getenv("USERPROFILE").."/Local Settings/Application Data" end defaults.local_cache = localappdata.."/LuaRocks/Cache" + defaults.web_browser = "start" end if detected.mingw32 then @@ -403,6 +404,7 @@ if detected.unix then if not defaults.variables.CFLAGS:match("-fPIC") then defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" end + defaults.web_browser = "xdg-open" end if detected.cygwin then @@ -436,6 +438,7 @@ if detected.macosx then end defaults.variables.CC = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" defaults.variables.LD = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" + defaults.web_browser = "open" end if detected.linux then -- cgit v1.2.3-55-g6feb From cd0054de7731adc208cceb314b1b10cbbed470de Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:06:14 -0200 Subject: Remove spurious commented code --- src/luarocks/doc.lua | 48 +----------------------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) (limited to 'src') diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index 9fb9d688..dc51709f 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -9,12 +9,7 @@ local path = require("luarocks.path") local dir = require("luarocks.dir") local fetch = require("luarocks.fetch") local fs = require("luarocks.fs") ---[[ -local search = require("luarocks.search") -local cfg = require("luarocks.cfg") -local deps = require("luarocks.deps") -local manif = require("luarocks.manif") -]] + help_summary = "Shows documentation for an installed rock." help = [[ @@ -28,47 +23,6 @@ With these flags, return only the desired information: For more information about a rock, see the 'show' command. ]] ---[[ -local function keys_as_string(t, sep) - return table.concat(util.keys(t), sep or " ") -end - -local function word_wrap(line) - local width = tonumber(os.getenv("COLUMNS")) or 80 - if width > 80 then width = 80 end - if #line > width then - local brk = width - while brk > 0 and line:sub(brk, brk) ~= " " do - brk = brk - 1 - end - if brk > 0 then - return line:sub(1, brk-1) .. "\n" .. word_wrap(line:sub(brk+1)) - end - end - return line -end - -local function format_text(text) - text = text:gsub("^%s*",""):gsub("%s$", ""):gsub("\n[ \t]+","\n"):gsub("([^\n])\n([^\n])","%1 %2") - local paragraphs = util.split_string(text, "\n\n") - for n, line in ipairs(paragraphs) do - paragraphs[n] = word_wrap(line) - end - return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) -end - -local function module_name(mod, filename, name, version, repo, manifest) - local base_dir - if filename:match("%.lua$") then - base_dir = path.deploy_lua_dir(repo) - else - base_dir = path.deploy_lib_dir(repo) - end - - return dir.path(base_dir, filename) -end -]] - --- Driver function for "doc" command. -- @param name or nil: an existing package name. -- @param version string or nil: a version may also be passed. -- cgit v1.2.3-55-g6feb From f50cde93fe41f91466e1f355b4aa035f20144527 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:06:45 -0200 Subject: Add fs.browser command --- src/luarocks/fs/unix/tools.lua | 4 ++++ src/luarocks/fs/win32/tools.lua | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index 5495760b..91ea86c5 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -341,3 +341,7 @@ function get_permissions(filename) pipe:close() return ret end + +function browser(url) + return os.execute(cfg.web_browser..' '..url) +end diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 345ec682..e18ae58e 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -362,3 +362,7 @@ function exists(file) assert(file) return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname") end + +function browser(url) + return os.execute(cfg.web_browser..' '..url) +end -- cgit v1.2.3-55-g6feb From 5a8f454c95d622714dd5156b49689223f7591ccc Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:07:10 -0200 Subject: Modifications based on suggestions by @agladysh --- src/luarocks/doc.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index dc51709f..f96ac152 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -44,6 +44,9 @@ function run(...) local descript = rockspec.description or {} if flags["home"] then + if not descript.homepage then + return nil, "No 'homepage' field in rockspec for "..name.." "..version + end util.printout("Opening "..descript.homepage.." ...") fs.browser(descript.homepage) return true @@ -70,7 +73,7 @@ function run(...) end local files = fs.find(docdir) - local extensions = { ".html", ".md", ".txt", "" } + local extensions = { "%.htm", "%.md", "%.txt", "" } local basenames = { "index", "readme", "manual" } for _, extension in ipairs(extensions) do -- cgit v1.2.3-55-g6feb From 31685028b3e945bc30a1e567508ce1ebc3bd5d06 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:44:47 -0200 Subject: Add textile --- src/luarocks/doc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index f96ac152..e6d9c58a 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -73,7 +73,7 @@ function run(...) end local files = fs.find(docdir) - local extensions = { "%.htm", "%.md", "%.txt", "" } + local extensions = { "%.htm", "%.md", "%.txt", "%.textile", "" } local basenames = { "index", "readme", "manual" } for _, extension in ipairs(extensions) do -- cgit v1.2.3-55-g6feb From 9f8ab8c17a054557d4159b2c41204d8ca211c6cf Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:45:03 -0200 Subject: Factor out function for use by luarocks.doc --- src/luarocks/show.lua | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 536085a7..2e039dd4 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -66,22 +66,14 @@ local function module_name(mod, filename, name, version, repo, manifest) return dir.path(base_dir, filename) 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. --- @return boolean: True if succeeded, nil on errors. -function run(...) - local flags, name, version = util.parse_flags(...) - if not name then - return nil, "Argument missing. "..util.see_help("show") - end +function pick_installed_rock(name, version, tree) local results = {} local query = search.make_query(name, version) query.exact_name = true local tree_map = {} local trees = cfg.rocks_trees - if flags["tree"] then - trees = { flags["tree"] } + if tree then + trees = { tree } end for _, tree in ipairs(trees) do local rocks_dir = path.rocks_dir(tree) @@ -103,8 +95,26 @@ function run(...) for _, rp in ipairs(repositories) do repo_url = rp.repo end end - local repo = tree_map[repo_url] + return name, version, repo, repo_url +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. +-- @return boolean: True if succeeded, nil on errors. +function run(...) + local flags, name, version = util.parse_flags(...) + if not name then + return nil, "Argument missing. "..util.see_help("show") + end + + local repo, repo_url + name, version, repo, repo_url = pick_installed_rock(name, version, flags["tree"]) + if not name then + return nil, version + end + local directory = path.install_dir(name,version,repo) local rockspec_file = path.rockspec_file(name, version, repo) local rockspec, err = fetch.load_local_rockspec(rockspec_file) -- cgit v1.2.3-55-g6feb From 5592cbcadfb44c914427a0d538c30f56da1997e1 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 16:45:40 -0200 Subject: Add doc command --- src/bin/luarocks | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/bin/luarocks b/src/bin/luarocks index 72f04c83..e9cfc349 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -22,6 +22,7 @@ commands = { lint = "luarocks.lint", write_rockspec = "luarocks.write_rockspec", purge = "luarocks.purge", + doc = "luarocks.doc", } command_line.run_command(...) -- cgit v1.2.3-55-g6feb From bac6b52d0498ec1c8ae5f81847c0332324566c03 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 19 Dec 2013 18:05:46 -0200 Subject: Enhancements for `luarocks doc` UI --- src/luarocks/doc.lua | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index e6d9c58a..c2989f98 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -19,6 +19,7 @@ using a series of heuristics. With these flags, return only the desired information: --home Open the home page of project. +--list List documentation files only. For more information about a rock, see the 'show' command. ]] @@ -63,6 +64,7 @@ function run(...) break end end + docdir = dir.normalize(docdir):gsub("/+", "/") if not docdir then if descript.homepage then util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") @@ -73,9 +75,29 @@ function run(...) end local files = fs.find(docdir) - local extensions = { "%.htm", "%.md", "%.txt", "%.textile", "" } + local htmlpatt = "%.html?$" + local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" } local basenames = { "index", "readme", "manual" } + local porcelain = flags["porcelain"] + if #files > 0 then + util.title("Documentation files for "..name.." "..version, porcelain) + if porcelain then + for _, file in ipairs(files) do + util.printout(docdir.."/"..file) + end + else + util.printout(docdir.."/") + for _, file in ipairs(files) do + util.printout("\t"..file) + end + end + end + + if flags["list"] then + return true + end + for _, extension in ipairs(extensions) do for _, basename in ipairs(basenames) do local filename = basename..extension @@ -87,8 +109,11 @@ function run(...) end if found then local pathname = dir.path(docdir, found) + util.printout() util.printout("Opening "..pathname.." ...") - if not fs.browser(pathname) then + util.printout() + local ok = fs.browser(pathname) + if not ok and not pathname:match(htmlpatt) then local fd = io.open(pathname, "r") util.printout(fd:read("*a")) fd:close() -- cgit v1.2.3-55-g6feb From 2c21fecead35daf22107cc8f47c7ec510aced200 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 20 Dec 2013 17:40:20 -0200 Subject: Fix bug when docs are missing --- src/luarocks/doc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index c2989f98..a3badd54 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -64,9 +64,8 @@ function run(...) break end end - docdir = dir.normalize(docdir):gsub("/+", "/") if not docdir then - if descript.homepage then + if descript.homepage and not flags["list"] then util.printout("Local documentation directory not found -- opening "..descript.homepage.." ...") fs.browser(descript.homepage) return true @@ -74,6 +73,7 @@ function run(...) return nil, "Documentation directory not found for "..name.." "..version end + docdir = dir.normalize(docdir):gsub("/+", "/") local files = fs.find(docdir) local htmlpatt = "%.html?$" local extensions = { htmlpatt, "%.md$", "%.txt$", "%.textile$", "" } -- cgit v1.2.3-55-g6feb From 62359238b4ef27841343055e25522e057a2c0eb2 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 20 Dec 2013 17:42:59 -0200 Subject: Quote URLs. I wonder if it works properly with `start` on Windows. --- src/luarocks/fs/unix/tools.lua | 2 +- src/luarocks/fs/win32/tools.lua | 2 +- 2 files 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 91ea86c5..7535d679 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -343,5 +343,5 @@ function get_permissions(filename) end function browser(url) - return os.execute(cfg.web_browser..' '..url) + return fs.execute(cfg.web_browser, url) end diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index e18ae58e..abbcd844 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -364,5 +364,5 @@ function exists(file) end function browser(url) - return os.execute(cfg.web_browser..' '..url) + return fs.execute(cfg.web_browser, url) end -- cgit v1.2.3-55-g6feb From a1470202d55e5bf25c6326bed693aa43c1f4727d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 20 Dec 2013 18:53:15 -0200 Subject: Don't quote URL on Windows. Doesn't seem to work: https://twitter.com/pchapuis/status/414119212739604480 --- src/luarocks/fs/win32/tools.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index abbcd844..24197f47 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -364,5 +364,5 @@ function exists(file) end function browser(url) - return fs.execute(cfg.web_browser, url) + return fs.execute(cfg.web_browser.." "..url) end -- cgit v1.2.3-55-g6feb From 0402bceb92a5eb6a4650856b080953826229309d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 8 Jan 2014 16:28:54 -0200 Subject: Check if unzip failed --- src/luarocks/manif.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index ed1780b3..3fb3e4e3 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -141,12 +141,18 @@ function load_manifest(repo_url) end end if pathname:match(".*%.zip$") then + pathname = fs.absolute_name(pathname) local dir = dir.dir_name(pathname) fs.change_dir(dir) local nozip = pathname:match("(.*)%.zip$") fs.delete(nozip) - fs.unzip(pathname) + local ok = fs.unzip(pathname) fs.pop_dir() + if not ok then + fs.delete(pathname) + fs.delete(pathname..".timestamp") + return nil, "Failed extracting manifest file" + end pathname = nozip end return manif_core.manifest_loader(pathname, repo_url) -- cgit v1.2.3-55-g6feb From 04d071bd0ee90cbd82c3d1048254140e2363ce0a Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 9 Jan 2014 22:06:38 -0200 Subject: Use --homepage, which is less ambiguous. --- src/luarocks/doc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index a3badd54..1a843f37 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -18,7 +18,7 @@ Without any flags, tries to load the documentation using a series of heuristics. With these flags, return only the desired information: ---home Open the home page of project. +--homepage Open the home page of project. --list List documentation files only. For more information about a rock, see the 'show' command. @@ -44,7 +44,7 @@ function run(...) if not rockspec then return nil,err end local descript = rockspec.description or {} - if flags["home"] then + if flags["homepage"] then if not descript.homepage then return nil, "No 'homepage' field in rockspec for "..name.." "..version end -- cgit v1.2.3-55-g6feb