From 3af05c7e5d7999500508c51a5d405e59c14363cc Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 20:59:24 +0400 Subject: Un-module bundled deps --- src/luarocks/build/builtin.lua | 7 +++++-- src/luarocks/build/cmake.lua | 7 +++++-- src/luarocks/build/command.lua | 7 +++++-- src/luarocks/build/make.lua | 7 +++++-- src/luarocks/fetch/cvs.lua | 7 +++++-- src/luarocks/fetch/git.lua | 7 +++++-- src/luarocks/fetch/git_file.lua | 7 +++++-- src/luarocks/fetch/git_http.lua | 7 +++++-- src/luarocks/fetch/hg.lua | 7 +++++-- src/luarocks/fetch/sscm.lua | 7 +++++-- src/luarocks/fetch/svn.lua | 7 +++++-- src/luarocks/fs/unix.lua | 17 ++++++++++------- src/luarocks/fs/win32.lua | 27 +++++++++++++++------------ src/luarocks/tools/patch.lua | 9 ++++++--- src/luarocks/tools/tar.lua | 7 +++++-- src/luarocks/tools/zip.lua | 11 +++++++---- 16 files changed, 98 insertions(+), 50 deletions(-) diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 5120c85c..e154e65c 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -1,6 +1,7 @@ --- A builtin build system: back-end to provide a portable way of building C-based Lua modules. -module("luarocks.build.builtin", package.seeall) +--module("luarocks.build.builtin", package.seeall) +local builtin = {} local fs = require("luarocks.fs") local path = require("luarocks.path") @@ -45,7 +46,7 @@ end -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors ocurred, -- nil and an error message otherwise. -function run(rockspec) +function builtin.run(rockspec) assert(type(rockspec) == "table") local compile_object, compile_library, compile_wrapper_binary --TODO EXEWRAPPER @@ -262,3 +263,5 @@ function run(rockspec) end return true end + +return builtin diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua index 0df3a921..83ec20f3 100644 --- a/src/luarocks/build/cmake.lua +++ b/src/luarocks/build/cmake.lua @@ -1,6 +1,7 @@ --- Build back-end for CMake-based modules. -module("luarocks.build.cmake", package.seeall) +--module("luarocks.build.cmake", package.seeall) +local cmake = {} local fs = require("luarocks.fs") local util = require("luarocks.util") @@ -10,7 +11,7 @@ local cfg = require("luarocks.cfg") -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors ocurred, -- nil and an error message otherwise. -function run(rockspec) +function cmake.run(rockspec) assert(type(rockspec) == "table") local build = rockspec.build local variables = build.variables or {} @@ -56,3 +57,5 @@ function run(rockspec) end return true end + +return cmake diff --git a/src/luarocks/build/command.lua b/src/luarocks/build/command.lua index aeec0da7..650e3236 100644 --- a/src/luarocks/build/command.lua +++ b/src/luarocks/build/command.lua @@ -1,6 +1,7 @@ --- Build back-end for raw listing of commands in rockspec files. -module("luarocks.build.command", package.seeall) +--module("luarocks.build.command", package.seeall) +local command = {} local fs = require("luarocks.fs") local util = require("luarocks.util") @@ -9,7 +10,7 @@ local util = require("luarocks.util") -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors ocurred, -- nil and an error message otherwise. -function run(rockspec) +function command.run(rockspec) assert(type(rockspec) == "table") local build = rockspec.build @@ -30,3 +31,5 @@ function run(rockspec) end return true end + +return command diff --git a/src/luarocks/build/make.lua b/src/luarocks/build/make.lua index c4b21578..31deac64 100644 --- a/src/luarocks/build/make.lua +++ b/src/luarocks/build/make.lua @@ -1,6 +1,7 @@ --- Build back-end for using Makefile-based packages. -module("luarocks.build.make", package.seeall) +--module("luarocks.build.make", package.seeall) +local make = {} local fs = require("luarocks.fs") local util = require("luarocks.util") @@ -36,7 +37,7 @@ end -- @param rockspec table: the loaded rockspec. -- @return boolean or (nil, string): true if no errors ocurred, -- nil and an error message otherwise. -function run(rockspec) +function make.run(rockspec) assert(type(rockspec) == "table") local build = rockspec.build @@ -90,3 +91,5 @@ function run(rockspec) end return true end + +return make diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua index 6b4cf186..efb59d05 100644 --- a/src/luarocks/fetch/cvs.lua +++ b/src/luarocks/fetch/cvs.lua @@ -1,6 +1,7 @@ --- Fetch back-end for retrieving sources from CVS. -module("luarocks.fetch.cvs", package.seeall) +--module("luarocks.fetch.cvs", package.seeall) +local cvs = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -13,7 +14,7 @@ local util = require("luarocks.util") -- @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 get_sources(rockspec, extract, dest_dir) +function cvs.get_sources(rockspec, extract, dest_dir) assert(type(rockspec) == "table") assert(type(dest_dir) == "string" or not dest_dir) @@ -43,3 +44,5 @@ function get_sources(rockspec, extract, dest_dir) return module, store_dir end + +return cvs diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 2bba4cdc..7fe4c4ee 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -1,6 +1,7 @@ --- Fetch back-end for retrieving sources from GIT. -module("luarocks.fetch.git", package.seeall) +--module("luarocks.fetch.git", package.seeall) +local git = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -27,7 +28,7 @@ end -- @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 get_sources(rockspec, extract, dest_dir, depth) +function git.get_sources(rockspec, extract, dest_dir, depth) assert(type(rockspec) == "table") assert(type(dest_dir) == "string" or not dest_dir) @@ -81,3 +82,5 @@ function get_sources(rockspec, extract, dest_dir, depth) fs.pop_dir() return module, store_dir end + +return git diff --git a/src/luarocks/fetch/git_file.lua b/src/luarocks/fetch/git_file.lua index 1b18d0fa..0144bc2e 100644 --- a/src/luarocks/fetch/git_file.lua +++ b/src/luarocks/fetch/git_file.lua @@ -1,6 +1,7 @@ --- Fetch back-end for retrieving sources from local Git repositories. -module("luarocks.fetch.git_file", package.seeall) +--module("luarocks.fetch.git_file", package.seeall) +local git_file = {} local git = require("luarocks.fetch.git") @@ -11,7 +12,9 @@ local git = require("luarocks.fetch.git") -- @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 get_sources(rockspec, extract, dest_dir) +function git_file.get_sources(rockspec, extract, dest_dir) rockspec.source.url = rockspec.source.url:gsub("^git.file://", "") return git.get_sources(rockspec, extract, dest_dir) end + +return git_file diff --git a/src/luarocks/fetch/git_http.lua b/src/luarocks/fetch/git_http.lua index b5fcd095..4ecd4816 100644 --- a/src/luarocks/fetch/git_http.lua +++ b/src/luarocks/fetch/git_http.lua @@ -7,7 +7,8 @@ -- source = { url = "git+http://example.com/foo.git" } -- Prefer using the normal git:// fetch mode as it is more widely -- available in older versions of LuaRocks. -module("luarocks.fetch.git_http", package.seeall) +--module("luarocks.fetch.git_http", package.seeall) +local git_http = {} local git = require("luarocks.fetch.git") @@ -18,7 +19,9 @@ local git = require("luarocks.fetch.git") -- @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 get_sources(rockspec, extract, dest_dir) +function git_http.get_sources(rockspec, extract, dest_dir) rockspec.source.url = rockspec.source.url:gsub("^git.", "") return git.get_sources(rockspec, extract, dest_dir, "--") end + +return git_http diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index 32e40469..44af3afa 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -1,6 +1,7 @@ --- Fetch back-end for retrieving sources from HG. -module("luarocks.fetch.hg", package.seeall) +--module("luarocks.fetch.hg", package.seeall) +local hg = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -13,7 +14,7 @@ local util = require("luarocks.util") -- @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 get_sources(rockspec, extract, dest_dir) +function hg.get_sources(rockspec, extract, dest_dir) assert(type(rockspec) == "table") assert(type(dest_dir) == "string" or not dest_dir) @@ -54,3 +55,5 @@ function get_sources(rockspec, extract, dest_dir) return module, store_dir end + +return hg diff --git a/src/luarocks/fetch/sscm.lua b/src/luarocks/fetch/sscm.lua index e52e8019..53ae86a3 100644 --- a/src/luarocks/fetch/sscm.lua +++ b/src/luarocks/fetch/sscm.lua @@ -1,6 +1,7 @@ --- Fetch back-end for retrieving sources from Surround SCM Server -module("luarocks.fetch.sscm", package.seeall) +--module("luarocks.fetch.sscm", package.seeall) +local sscm = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -12,7 +13,7 @@ local dir = require("luarocks.dir") -- @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 get_sources(rockspec, extract, dest_dir) +function sscm.get_sources(rockspec, extract, dest_dir) assert(type(rockspec) == "table") assert(type(dest_dir) == "string" or not dest_dir) @@ -40,3 +41,5 @@ function get_sources(rockspec, extract, dest_dir) -- FIXME: This function does not honor the dest_dir parameter. return module, working_dir end + +return sscm diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua index 7aa37ec5..63a443c7 100644 --- a/src/luarocks/fetch/svn.lua +++ b/src/luarocks/fetch/svn.lua @@ -1,6 +1,7 @@ --- Fetch back-end for retrieving sources from Subversion. -module("luarocks.fetch.svn", package.seeall) +--module("luarocks.fetch.svn", package.seeall) +local svn = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -13,7 +14,7 @@ local util = require("luarocks.util") -- @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 get_sources(rockspec, extract, dest_dir) +function svn.get_sources(rockspec, extract, dest_dir) assert(type(rockspec) == "table") assert(type(dest_dir) == "string" or not dest_dir) @@ -53,3 +54,5 @@ function get_sources(rockspec, extract, dest_dir) return module, store_dir end + +return svn diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 2dc5e492..3e6b9080 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -1,6 +1,7 @@ --- Unix implementation of filesystem and platform abstractions. -module("luarocks.fs.unix", package.seeall) +--module("luarocks.fs.unix", package.seeall) +local unix = {} local fs = require("luarocks.fs") @@ -14,7 +15,7 @@ math.randomseed(os.time()) --- Annotate command string for quiet execution. -- @param cmd string: A command-line string. -- @return string: The command-line, with silencing annotation. -function quiet(cmd) +function unix.quiet(cmd) return cmd.." 1> /dev/null 2> /dev/null" end @@ -24,7 +25,7 @@ end -- pathname absolute, or the current dir in the dir stack if -- not given. -- @return string: The pathname converted to absolute. -function absolute_name(pathname, relative_to) +function unix.absolute_name(pathname, relative_to) assert(type(pathname) == "string") assert(type(relative_to) == "string" or not relative_to) @@ -43,7 +44,7 @@ end -- @param version string: rock version to be used in loader context. -- @return boolean or (nil, string): True if succeeded, or nil and -- an error message. -function wrap_script(file, dest, name, version) +function unix.wrap_script(file, dest, name, version) assert(type(file) == "string") assert(type(dest) == "string") @@ -72,7 +73,7 @@ end -- @param filename string: the file name with full path. -- @return boolean: returns true if file is an actual binary -- (or if it couldn't check) or false if it is a Lua wrapper. -function is_actual_binary(filename) +function unix.is_actual_binary(filename) if filename:match("%.lua$") then return false end @@ -89,7 +90,7 @@ function is_actual_binary(filename) return first ~= "#!" end -function copy_binary(filename, dest) +function unix.copy_binary(filename, dest) return fs.copy(filename, dest, "0755") end @@ -103,6 +104,8 @@ end -- which will replace old_file. -- @return boolean or (nil, string): True if succeeded, or nil and -- an error message. -function replace_file(old_file, new_file) +function unix.replace_file(old_file, new_file) return os.rename(new_file, old_file) end + +return unix diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index a3f0663b..c4c20349 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -1,7 +1,8 @@ --- Windows implementation of filesystem and platform abstractions. -- Download http://unxutils.sourceforge.net/ for Windows GNU utilities -- used by this module. -module("luarocks.fs.win32", package.seeall) +--module("luarocks.fs.win32", package.seeall) +local win32 = {} local fs = require("luarocks.fs") @@ -21,7 +22,7 @@ os.execute = function(cmd, ...) return _execute(_prefix..cmd, ...) end --- Annotate command string for quiet execution. -- @param cmd string: A command-line string. -- @return string: The command-line, with silencing annotation. -function quiet(cmd) +function win32.quiet(cmd) return cmd.." 2> NUL 1> NUL" end @@ -43,7 +44,7 @@ end -- Adds double quotes and escapes. -- @param arg string: Unquoted argument. -- @return string: Quoted argument. -function Q(arg) +function win32.Q(arg) assert(type(arg) == "string") -- Quote DIR for Windows if arg:match("^[%.a-zA-Z]?:?[\\/]") then @@ -64,7 +65,7 @@ end -- Adds double quotes and escapes. -- @param arg string: Unquoted argument. -- @return string: Quoted argument. -function Qb(arg) +function win32.Qb(arg) assert(type(arg) == "string") -- Quote DIR for Windows if arg:match("^[%.a-zA-Z]?:?[\\/]") then @@ -86,7 +87,7 @@ end -- pathname absolute, or the current dir in the dir stack if -- not given. -- @return string: The pathname converted to absolute. -function absolute_name(pathname, relative_to) +function win32.absolute_name(pathname, relative_to) assert(type(pathname) == "string") assert(type(relative_to) == "string" or not relative_to) @@ -107,7 +108,7 @@ end -- @param version string: rock version to be used in loader context. -- @return boolean or (nil, string): True if succeeded, or nil and -- an error message. -function wrap_script(file, dest, name, version) +function win32.wrap_script(file, dest, name, version) assert(type(file) == "string") assert(type(dest) == "string") @@ -128,7 +129,7 @@ function wrap_script(file, dest, name, version) return true end -function is_actual_binary(name) +function win32.is_actual_binary(name) name = name:lower() if name:match("%.bat$") or name:match("%.exe$") then return true @@ -136,7 +137,7 @@ function is_actual_binary(name) return false end -function copy_binary(filename, dest) +function win32.copy_binary(filename, dest) local ok, err = fs.copy(filename, dest) if not ok then return nil, err @@ -158,11 +159,11 @@ function copy_binary(filename, dest) return true end -function chmod(filename, mode) +function win32.chmod(filename, mode) return true end -function get_permissions(filename) +function win32.get_permissions(filename) return "" end @@ -177,7 +178,7 @@ end -- which will replace old_file. -- @return boolean or (nil, string): True if succeeded, or nil and -- an error message. -function replace_file(old_file, new_file) +function win32.replace_file(old_file, new_file) os.remove(old_file) return os.rename(new_file, old_file) end @@ -188,7 +189,7 @@ end -- for checking the result of subsequent operations. -- @param file string: filename to test -- @return boolean: true if file exists, false otherwise. -function is_writable(file) +function win32.is_writable(file) assert(file) file = dir.normalize(file) local result @@ -212,3 +213,5 @@ function is_writable(file) end return result end + +return win32 diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index c518fc4d..a3e1602d 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua @@ -7,7 +7,8 @@ -- Copyright (c) 2008 rainforce.org, MIT License -- Project home: http://code.google.com/p/python-patch/ . -module("luarocks.tools.patch", package.seeall) +--module("luarocks.tools.patch", package.seeall) +local patch = {} local fs = require("luarocks.fs") local util = require("luarocks.util") @@ -153,7 +154,7 @@ local function match_linerange(line) return m1, m2, m3, m4 end -function read_patch(filename, data) +function patch.read_patch(filename, data) -- define possible file regions that will direct the parser flow local state = 'header' -- 'header' - comments before the patch body @@ -564,7 +565,7 @@ local function strip_dirs(filename, strip) return filename end -function apply_patch(patch, strip) +function patch.apply_patch(patch, strip) local all_ok = true local total = #patch.source for fileno, filename in ipairs(patch.source) do @@ -705,3 +706,5 @@ function apply_patch(patch, strip) -- todo: check for premature eof return all_ok end + +return patch diff --git a/src/luarocks/tools/tar.lua b/src/luarocks/tools/tar.lua index 0c68ab2f..03f7de3c 100644 --- a/src/luarocks/tools/tar.lua +++ b/src/luarocks/tools/tar.lua @@ -1,6 +1,7 @@ --- A pure-Lua implementation of untar (unpacking .tar archives) -module("luarocks.tools.tar", package.seeall) +--module("luarocks.tools.tar", package.seeall) +local tar = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -82,7 +83,7 @@ local function read_header_block(block) return header end -function untar(filename, destdir) +function tar.untar(filename, destdir) assert(type(filename) == "string") assert(type(destdir) == "string") @@ -144,3 +145,5 @@ function untar(filename, destdir) end return true end + +return tar diff --git a/src/luarocks/tools/zip.lua b/src/luarocks/tools/zip.lua index 35428d91..40cc089a 100644 --- a/src/luarocks/tools/zip.lua +++ b/src/luarocks/tools/zip.lua @@ -1,7 +1,8 @@ --- A Lua implementation of .zip file archiving (used for creating .rock files), -- using only lua-zlib. -module("luarocks.tools.zip", package.seeall) +--module("luarocks.tools.zip", package.seeall) +local zip = {} local zlib = require("zlib") local fs = require("luarocks.fs") @@ -188,7 +189,7 @@ end --- Return a zip handle open for writing. -- @param name filename of the zipfile to be created. -- @return a zip handle, or nil in case of error. -function new_zipwriter(name) +function zip.new_zipwriter(name) local zw = {} @@ -214,8 +215,8 @@ end -- additional arguments. -- @return boolean or (boolean, string): true on success, -- false and an error message on failure. -function zip(zipfile, ...) - local zw = new_zipwriter(zipfile) +function zip.zip(zipfile, ...) + local zw = zip.new_zipwriter(zipfile) if not zw then return nil, "error opening "..zipfile end @@ -243,3 +244,5 @@ function zip(zipfile, ...) return ok, err end + +return zip -- cgit v1.2.3-55-g6feb From a3ee3e91ae5147f15f521decfe4d9188afefc782 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 21:40:47 +0400 Subject: Split luarocks.path module --- Makefile | 2 +- src/bin/luarocks | 2 +- src/luarocks/path.lua | 154 +++++++++++++++--------------------------- src/luarocks/path_command.lua | 58 ++++++++++++++++ 4 files changed, 114 insertions(+), 102 deletions(-) create mode 100644 src/luarocks/path_command.lua diff --git a/Makefile b/Makefile index 1e9b9dd2..a1b87b20 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ remove.lua fs.lua manif.lua add.lua deps.lua build.lua search.lua show.lua \ manif_core.lua fetch.lua unpack.lua validate.lua cfg.lua download.lua \ 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 write_rockspec.lua doc.lua +purge.lua path.lua path_command.lua write_rockspec.lua doc.lua CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua diff --git a/src/bin/luarocks b/src/bin/luarocks index e9cfc349..9c190175 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -16,7 +16,7 @@ commands = { remove = "luarocks.remove", make = "luarocks.make", download = "luarocks.download", - path = "luarocks.path", + path = "luarocks.path_command", show = "luarocks.show", new_version = "luarocks.new_version", lint = "luarocks.lint", diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index d7273095..598e51d9 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -2,31 +2,23 @@ --- LuaRocks-specific path handling functions. -- All paths are configured in this module, making it a single -- point where the layout of the local installation is defined in LuaRocks. -module("luarocks.path", package.seeall) +--module("luarocks.path", package.seeall) +local path = {} local dir = require("luarocks.dir") local cfg = require("luarocks.cfg") local util = require("luarocks.util") -local deps = require("luarocks.deps") - -help_summary = "Return the currently configured package path." -help_arguments = "" -help = [[ -Returns the package path currently configured for this installation -of LuaRocks, formatted as shell commands to update LUA_PATH and -LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`) -]] --- Infer rockspec filename from a rock filename. -- @param rock_name string: Pathname of a rock file. -- @return string: Filename of the rockspec, without path. -function rockspec_name_from_rock(rock_name) +function path.rockspec_name_from_rock(rock_name) assert(type(rock_name) == "string") local base_name = dir.base_name(rock_name) return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" end -function rocks_dir(tree) +function path.rocks_dir(tree) if type(tree) == "string" then return dir.path(tree, cfg.rocks_subdir) else @@ -35,12 +27,12 @@ function rocks_dir(tree) end end -function root_dir(rocks_dir) +function path.root_dir(rocks_dir) assert(type(rocks_dir) == "string") return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") end -function rocks_tree_to_string(tree) +function path.rocks_tree_to_string(tree) if type(tree) == "string" then return tree else @@ -49,7 +41,7 @@ function rocks_tree_to_string(tree) end end -function deploy_bin_dir(tree) +function path.deploy_bin_dir(tree) if type(tree) == "string" then return dir.path(tree, "bin") else @@ -58,7 +50,7 @@ function deploy_bin_dir(tree) end end -function deploy_lua_dir(tree) +function path.deploy_lua_dir(tree) if type(tree) == "string" then return dir.path(tree, cfg.lua_modules_path) else @@ -67,7 +59,7 @@ function deploy_lua_dir(tree) end end -function deploy_lib_dir(tree) +function path.deploy_lib_dir(tree) if type(tree) == "string" then return dir.path(tree, cfg.lib_modules_path) else @@ -76,7 +68,7 @@ function deploy_lib_dir(tree) end end -function manifest_file(tree) +function path.manifest_file(tree) if type(tree) == "string" then return dir.path(tree, cfg.rocks_subdir, "manifest") else @@ -90,10 +82,10 @@ end -- @return string: The resulting path -- does not guarantee that -- @param tree string or nil: If given, specifies the local tree to use. -- the package (and by extension, the path) exists. -function versions_dir(name, tree) +function path.versions_dir(name, tree) assert(type(name) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name) + return dir.path(path.rocks_dir(tree), name) end --- Get the local installation directory (prefix) for a package. @@ -102,11 +94,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the path) exists. -function install_dir(name, version, tree) +function path.install_dir(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version) + return dir.path(path.rocks_dir(tree), name, version) end --- Get the local filename of the rockspec of an installed rock. @@ -115,11 +107,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the file) exists. -function rockspec_file(name, version, tree) +function path.rockspec_file(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version, name.."-"..version..".rockspec") + return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec") end --- Get the local filename of the rock_manifest file of an installed rock. @@ -128,11 +120,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the file) exists. -function rock_manifest_file(name, version, tree) +function path.rock_manifest_file(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version, "rock_manifest") + return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") end --- Get the local installation directory for C libraries of a package. @@ -141,11 +133,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the path) exists. -function lib_dir(name, version, tree) +function path.lib_dir(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version, "lib") + return dir.path(path.rocks_dir(tree), name, version, "lib") end --- Get the local installation directory for Lua modules of a package. @@ -154,11 +146,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the path) exists. -function lua_dir(name, version, tree) +function path.lua_dir(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version, "lua") + return dir.path(path.rocks_dir(tree), name, version, "lua") end --- Get the local installation directory for documentation of a package. @@ -167,11 +159,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the path) exists. -function doc_dir(name, version, tree) +function path.doc_dir(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version, "doc") + return dir.path(path.rocks_dir(tree), name, version, "doc") end --- Get the local installation directory for configuration files of a package. @@ -180,11 +172,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the path) exists. -function conf_dir(name, version, tree) +function path.conf_dir(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version, "conf") + return dir.path(path.rocks_dir(tree), name, version, "conf") end --- Get the local installation directory for command-line scripts @@ -194,11 +186,11 @@ end -- @param tree string or nil: If given, specifies the local tree to use. -- @return string: The resulting path -- does not guarantee that -- the package (and by extension, the path) exists. -function bin_dir(name, version, tree) +function path.bin_dir(name, version, tree) assert(type(name) == "string") assert(type(version) == "string") tree = tree or cfg.root_dir - return dir.path(rocks_dir(tree), name, version, "bin") + return dir.path(path.rocks_dir(tree), name, version, "bin") end --- Extract name, version and arch of a rock filename, @@ -206,7 +198,7 @@ end -- @param file_name string: pathname of a rock or rockspec -- @return (string, string, string) or nil: name, version and arch -- or nil if name could not be parsed -function parse_name(file_name) +function path.parse_name(file_name) assert(type(file_name) == "string") if file_name:match("%.rock$") then return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") @@ -221,7 +213,7 @@ end -- @param version string: Package version. -- @param arch string: Architecture identifier, or "rockspec" or "installed". -- @return string: A URL or pathname following LuaRocks naming conventions. -function make_url(pathname, name, version, arch) +function path.make_url(pathname, name, version, arch) assert(type(pathname) == "string") assert(type(name) == "string") assert(type(version) == "string") @@ -245,7 +237,7 @@ end -- @return string: The module identifier, or nil if given path is -- not a conformant module path (the function does not check if the -- path actually exists). -function path_to_module(file) +function path.path_to_module(file) assert(type(file) == "string") local name = file:match("(.*)%."..cfg.lua_extension.."$") @@ -270,7 +262,7 @@ end -- For example, on Unix, "foo.bar.baz" will return "foo/bar". -- @param mod string: A module name in Lua dot-separated format. -- @return string: A directory name using the platform's separator. -function module_to_path(mod) +function path.module_to_path(mod) assert(type(mod) == "string") return (mod:gsub("[^.]*$", ""):gsub("%.", dir.separator)) end @@ -279,19 +271,19 @@ end -- Create a "variables" table in the rockspec table, containing -- adjusted variables according to the configuration file. -- @param rockspec table: The rockspec table. -function configure_paths(rockspec) +function path.configure_paths(rockspec) assert(type(rockspec) == "table") local vars = {} for k,v in pairs(cfg.variables) do vars[k] = v end local name, version = rockspec.name, rockspec.version - vars.PREFIX = install_dir(name, version) - vars.LUADIR = lua_dir(name, version) - vars.LIBDIR = lib_dir(name, version) - vars.CONFDIR = conf_dir(name, version) - vars.BINDIR = bin_dir(name, version) - vars.DOCDIR = doc_dir(name, version) + vars.PREFIX = path.install_dir(name, version) + vars.LUADIR = path.lua_dir(name, version) + vars.LIBDIR = path.lib_dir(name, version) + vars.CONFDIR = path.conf_dir(name, version) + vars.BINDIR = path.bin_dir(name, version) + vars.DOCDIR = path.doc_dir(name, version) rockspec.variables = vars end @@ -301,7 +293,7 @@ end -- @param name string: Rock name -- @param version string: Rock version -- @return string: a pathname with the same directory parts and a versioned basename. -function versioned_name(file, prefix, name, version) +function path.versioned_name(file, prefix, name, version) assert(type(file) == "string") assert(type(name) == "string") assert(type(version) == "string") @@ -311,12 +303,12 @@ function versioned_name(file, prefix, name, version) return dir.path(prefix, name_version.."-"..rest) end -function use_tree(tree) +function path.use_tree(tree) cfg.root_dir = tree - cfg.rocks_dir = rocks_dir(tree) - cfg.deploy_bin_dir = deploy_bin_dir(tree) - cfg.deploy_lua_dir = deploy_lua_dir(tree) - cfg.deploy_lib_dir = deploy_lib_dir(tree) + cfg.rocks_dir = path.rocks_dir(tree) + cfg.deploy_bin_dir = path.deploy_bin_dir(tree) + cfg.deploy_lua_dir = path.deploy_lua_dir(tree) + cfg.deploy_lib_dir = path.deploy_lib_dir(tree) end --- Apply a given function to the active rocks trees based on chosen dependency mode. @@ -326,7 +318,7 @@ end -- @param fn function: function to be applied, with the tree dir (string) as the first -- argument and the remaining varargs of map_trees as the following arguments. -- @return a table with all results of invocations of fn collected. -function map_trees(deps_mode, fn, ...) +function path.map_trees(deps_mode, fn, ...) local result = {} if deps_mode == "one" then table.insert(result, (fn(cfg.root_dir, ...)) or 0) @@ -336,7 +328,7 @@ function map_trees(deps_mode, fn, ...) use = true end for _, tree in ipairs(cfg.rocks_trees) do - if dir.normalize(rocks_tree_to_string(tree)) == dir.normalize(rocks_tree_to_string(cfg.root_dir)) then + if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(cfg.root_dir)) then use = true end if use then @@ -355,17 +347,17 @@ end -- @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 which_i(module_name, name, version, tree, i) +function path.which_i(module_name, name, version, tree, i) local deploy_dir if module_name:match("%.lua$") then - deploy_dir = deploy_lua_dir(tree) + deploy_dir = path.deploy_lua_dir(tree) module_name = dir.path(deploy_dir, module_name) else - deploy_dir = deploy_lib_dir(tree) + deploy_dir = path.deploy_lib_dir(tree) module_name = dir.path(deploy_dir, module_name) end if i > 1 then - module_name = versioned_name(module_name, deploy_dir, name, version) + module_name = path.versioned_name(module_name, deploy_dir, name, version) end return module_name end @@ -379,53 +371,15 @@ end -- @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 which(module_name, filename, name, version, tree, manifest) +function path.which(module_name, filename, 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 which_i(filename, name, version, tree, i):gsub("//", "/") + return path.which_i(filename, name, version, tree, i):gsub("//", "/") end end assert(false) end ---- Driver function for "path" command. --- @return boolean This function always succeeds. -function run(...) - local flags = util.parse_flags(...) - local deps_mode = deps.get_deps_mode(flags) - - local lr_path, lr_cpath = cfg.package_paths() - local bin_dirs = map_trees(deps_mode, deploy_bin_dir) - - if flags["lr-path"] then - util.printout(util.remove_path_dupes(lr_path, ';')) - return true - elseif flags["lr-cpath"] then - util.printout(util.remove_path_dupes(lr_cpath, ';')) - return true - elseif flags["lr-bin"] then - local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) - util.printout(util.remove_path_dupes(lr_bin, ';')) - return true - end - - if flags["append"] then - lr_path = package.path .. ";" .. lr_path - lr_cpath = package.cpath .. ";" .. lr_cpath - else - lr_path = lr_path.. ";" .. package.path - lr_cpath = lr_cpath .. ";" .. package.cpath - end - - util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))) - util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))) - if flags["bin"] then - table.insert(bin_dirs, 1, os.getenv("PATH")) - local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) - util.printout(cfg.export_path:format(lr_bin)) - end - return true -end - +return path diff --git a/src/luarocks/path_command.lua b/src/luarocks/path_command.lua new file mode 100644 index 00000000..4e52bdc9 --- /dev/null +++ b/src/luarocks/path_command.lua @@ -0,0 +1,58 @@ + +--- Module implementing the LuaRocks "path" command. +-- Return the currently configured package path. +local path_command = {} + +local path = require("luarocks.path") +local cfg = require("luarocks.cfg") +local util = require("luarocks.util") +local deps = require("luarocks.deps") + +path_command.help_summary = "Return the currently configured package path." +path_command.help_arguments = "" +path_command.help = [[ +Returns the package path currently configured for this installation +of LuaRocks, formatted as shell commands to update LUA_PATH and +LUA_CPATH. (On Unix systems, you may run: eval `luarocks path`) +]] + +--- Driver function for "path" command. +-- @return boolean This function always succeeds. +function path_command.run(...) + local flags = util.parse_flags(...) + local deps_mode = deps.get_deps_mode(flags) + + local lr_path, lr_cpath = cfg.package_paths() + local bin_dirs = path.map_trees(deps_mode, path.deploy_bin_dir) + + if flags["lr-path"] then + util.printout(util.remove_path_dupes(lr_path, ';')) + return true + elseif flags["lr-cpath"] then + util.printout(util.remove_path_dupes(lr_cpath, ';')) + return true + elseif flags["lr-bin"] then + local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) + util.printout(util.remove_path_dupes(lr_bin, ';')) + return true + end + + if flags["append"] then + lr_path = package.path .. ";" .. lr_path + lr_cpath = package.cpath .. ";" .. lr_cpath + else + lr_path = lr_path.. ";" .. package.path + lr_cpath = lr_cpath .. ";" .. package.cpath + end + + util.printout(cfg.export_lua_path:format(util.remove_path_dupes(lr_path, ';'))) + util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(lr_cpath, ';'))) + if flags["bin"] then + table.insert(bin_dirs, 1, os.getenv("PATH")) + local lr_bin = util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator) + util.printout(cfg.export_path:format(lr_bin)) + end + return true +end + +return path_command -- cgit v1.2.3-55-g6feb From 066269a92b7d9cd7299188fea81a2ab9d16285d9 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 21:50:30 +0400 Subject: In luarocks.utils, require deps only inside functions --- src/luarocks/util.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 4b138516..4e70aa91 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -4,12 +4,8 @@ -- inside specific functions) to avoid interdependencies, -- as this is used in the bootstrapping stage of luarocks.cfg. -local global_env = _G - module("luarocks.util", package.seeall) -local cfg = require("luarocks.cfg") - local scheduled_functions = {} local debug = require("debug") @@ -374,6 +370,7 @@ function this_program(default) end function deps_mode_help(program) + local cfg = require("luarocks.cfg") return [[ --deps-mode= How to handle dependencies. Four modes are supported: * all - use all trees from the rocks_trees list -- cgit v1.2.3-55-g6feb From b63e863cf3ac9c830c5c81ece8e30f91edba4adc Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 22:07:34 +0400 Subject: Unmoduled CLI-related modules which used some globals --- src/luarocks/command_line.lua | 7 +++++-- src/luarocks/help.lua | 13 ++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 1c29aa77..54d64787 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -1,6 +1,7 @@ --- Functions for command-line scripts. -module("luarocks.command_line", package.seeall) +--module("luarocks.command_line", package.seeall) +local command_line = {} local util = require("luarocks.util") local cfg = require("luarocks.cfg") @@ -43,7 +44,7 @@ end -- Uses the global table "commands", which contains -- the loaded modules representing commands. -- @param ... string: Arguments given on the command-line. -function run_command(...) +function command_line.run_command(...) local args = {...} local cmdline_vars = {} for i = #args, 1, -1 do @@ -206,3 +207,5 @@ function run_command(...) end util.run_scheduled_functions() end + +return command_line diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 9f622f96..3e428a4a 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua @@ -4,7 +4,8 @@ -- uses a global table called "commands" to find commands -- to show help for; each command should be represented by a -- table containing "help" and "help_summary" fields. -module("luarocks.help", package.seeall) +--module("luarocks.help", package.seeall) +local help = {} local util = require("luarocks.util") local cfg = require("luarocks.cfg") @@ -12,10 +13,10 @@ local dir = require("luarocks.dir") local program = util.this_program("luarocks") -help_summary = "Help on commands. Type '"..program.." help ' for more." +help.help_summary = "Help on commands. Type '"..program.." help ' for more." -help_arguments = "[]" -help = [[ +help.help_arguments = "[]" +help.help = [[ is the command to show help for. ]] @@ -42,7 +43,7 @@ end -- given, help summaries for all commands are shown. -- @return boolean or (nil, string): true if there were no errors -- or nil and an error message if an invalid command was requested. -function run(...) +function help.run(...) local flags, command = util.parse_flags(...) if not command then @@ -114,3 +115,5 @@ function run(...) end return true end + +return help -- cgit v1.2.3-55-g6feb From 235124b431f2007dc2ecb6ee061c318d5f9b84a3 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 22:15:55 +0400 Subject: Unmoduled luarocks.util --- src/luarocks/util.lua | 83 ++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 4e70aa91..2c704a52 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -4,7 +4,8 @@ -- inside specific functions) to avoid interdependencies, -- as this is used in the bootstrapping stage of luarocks.cfg. -module("luarocks.util", package.seeall) +--module("luarocks.util", package.seeall) +local util = {} local scheduled_functions = {} local debug = require("debug") @@ -16,7 +17,7 @@ local debug = require("debug") -- @param ... arguments to be passed to function. -- @return table: A token representing the scheduled execution, -- which can be used to remove the item later from the list. -function schedule_function(f, ...) +function util.schedule_function(f, ...) assert(type(f) == "function") local item = { fn = f, args = {...} } @@ -28,7 +29,7 @@ end -- This is useful for cancelling a rollback of a completed operation. -- @param item table: The token representing the scheduled function that was -- returned from the schedule_function call. -function remove_scheduled_function(item) +function util.remove_scheduled_function(item) for k, v in pairs(scheduled_functions) do if v == item then table.remove(scheduled_functions, k) @@ -42,7 +43,7 @@ end -- corresponding cleanup functions. Calling this function will run -- these function, erasing temporaries. -- Functions are executed in the inverse order they were scheduled. -function run_scheduled_functions() +function util.run_scheduled_functions() local fs = require("luarocks.fs") fs.change_dir_to_root() for i = #scheduled_functions, 1, -1 do @@ -56,7 +57,7 @@ end -- so it does not include beginning- and end-of-string markers (^$) -- @param s string: The input string -- @return string: The equivalent pattern -function matchquote(s) +function util.matchquote(s) return (s:gsub("[?%-+*%[%].%%()$^]","%%%1")) end @@ -65,7 +66,7 @@ end -- For example, given "foo", "--tux=beep", "--bla", "bar", "--baz", -- it would return the following: -- {["bla"] = true, ["tux"] = "beep", ["baz"] = true}, "foo", "bar". -function parse_flags(...) +function util.parse_flags(...) local args = {...} local flags = {} for i = #args, 1, -1 do @@ -90,7 +91,7 @@ end -- in the flags table. If no flags are passed as varargs, the -- entire flags table is forwarded. -- @return string... A variable number of strings -function forward_flags(flags, ...) +function util.forward_flags(flags, ...) assert(type(flags) == "table") local out = {} local filter = select('#', ...) @@ -119,14 +120,14 @@ end -- @param dst Destination table, which will receive src's contents. -- @param src Table which provides new contents to dst. -- @see platform_overrides -function deep_merge(dst, src) +function util.deep_merge(dst, src) for k, v in pairs(src) do if type(v) == "table" then if not dst[k] then dst[k] = {} end if type(dst[k]) == "table" then - deep_merge(dst[k], v) + util.deep_merge(dst[k], v) else dst[k] = v end @@ -149,7 +150,7 @@ end -- tbl.x are preserved). -- @param tbl table or nil: Table which may contain a "platforms" field; -- if it doesn't (or if nil is passed), this function does nothing. -function platform_overrides(tbl) +function util.platform_overrides(tbl) assert(type(tbl) == "table" or not tbl) local cfg = require("luarocks.cfg") @@ -160,7 +161,7 @@ function platform_overrides(tbl) for _, platform in ipairs(cfg.platforms) do local platform_tbl = tbl.platforms[platform] if platform_tbl then - deep_merge(tbl, platform_tbl) + util.deep_merge(tbl, platform_tbl) end end end @@ -192,7 +193,7 @@ end -- @param needed_set: a set where keys are the names of -- needed variables. -- @param msg string: the warning message to display. -function warn_if_not_used(var_defs, needed_set, msg) +function util.warn_if_not_used(var_defs, needed_set, msg) needed_set = make_shallow_copy(needed_set) for var,val in pairs(var_defs) do for used in val:gmatch(var_format_pattern) do @@ -200,7 +201,7 @@ function warn_if_not_used(var_defs, needed_set, msg) end end for var,_ in pairs(needed_set) do - warning(msg:format(var)) + util.warning(msg:format(var)) end end @@ -211,7 +212,7 @@ local function warn_failed_matches(line) local any_failed = false if line:match(var_format_pattern) then for unmatched in line:gmatch(var_format_pattern) do - warning("unmatched variable " .. unmatched) + util.warning("unmatched variable " .. unmatched) any_failed = true end end @@ -226,7 +227,7 @@ end -- @param tbl table: Table to have its string values modified. -- @param vars table: Table containing string-string key-value pairs -- representing variables to replace in the strings values of tbl. -function variable_substitutions(tbl, vars) +function util.variable_substitutions(tbl, vars) assert(type(tbl) == "table") assert(type(vars) == "table") @@ -247,7 +248,7 @@ end --- Return an array of keys of a table. -- @param tbl table: The input table. -- @return table: The array of keys. -function keys(tbl) +function util.keys(tbl) local ks = {} for k,_ in pairs(tbl) do table.insert(ks, k) @@ -275,7 +276,7 @@ end -- to be used by table.sort when sorting keys. -- @see sortedpairs local function sortedpairs_iterator(tbl, sort_function) - local ks = keys(tbl) + local ks = util.keys(tbl) if not sort_function or type(sort_function) == "function" then table.sort(ks, sort_function or default_sort) for _, k in ipairs(ks) do @@ -313,11 +314,11 @@ end -- is a string representing the field name, and the second element is a priority table -- for that key. -- @return function: the iterator function. -function sortedpairs(tbl, sort_function) +function util.sortedpairs(tbl, sort_function) return coroutine.wrap(function() sortedpairs_iterator(tbl, sort_function) end) end -function lua_versions() +function util.lua_versions() local versions = { "5.1", "5.2" } local i = 0 return function() @@ -326,37 +327,37 @@ function lua_versions() end end -function starts_with(s, prefix) +function util.starts_with(s, prefix) return s:sub(1,#prefix) == prefix end --- Print a line to standard output -function printout(...) +function util.printout(...) io.stdout:write(table.concat({...},"\t")) io.stdout:write("\n") end --- Print a line to standard error -function printerr(...) +function util.printerr(...) io.stderr:write(table.concat({...},"\t")) io.stderr:write("\n") end --- Display a warning message. -- @param msg string: the warning message -function warning(msg) - printerr("Warning: "..msg) +function util.warning(msg) + util.printerr("Warning: "..msg) end -function title(msg, porcelain, underline) +function util.title(msg, porcelain, underline) if porcelain then return end - printout() - printout(msg) - printout((underline or "-"):rep(#msg)) - printout() + util.printout() + util.printout(msg) + util.printout((underline or "-"):rep(#msg)) + util.printout() end -function this_program(default) +function util.this_program(default) local i = 1 local last, cur = default, default while i do @@ -369,7 +370,7 @@ function this_program(default) return last:sub(2) end -function deps_mode_help(program) +function util.deps_mode_help(program) local cfg = require("luarocks.cfg") return [[ --deps-mode= How to handle dependencies. Four modes are supported: @@ -383,18 +384,18 @@ function deps_mode_help(program) 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 + Type ']]..util.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.."'." +function util.see_help(command, program) + return "See '"..util.this_program(program or "luarocks")..' help '..command.."'." end -- from http://lua-users.org/wiki/SplitJoin -- by PhilippeLhoste -function split_string(str, delim, maxNb) +function util.split_string(str, delim, maxNb) -- Eliminate bad cases... if string.find(str, delim) == nil then return { str } @@ -423,10 +424,10 @@ end -- Example: given ("a;b;c;a;b;d", ";"), returns "a;b;c;d". -- @param list string: A path string (from $PATH or package.path) -- @param sep string: The separator -function remove_path_dupes(list, sep) +function util.remove_path_dupes(list, sep) assert(type(list) == "string") assert(type(sep) == "string") - local parts = split_string(list, sep) + local parts = util.split_string(list, sep) local final, entries = {}, {} for _, part in ipairs(parts) do if not entries[part] then @@ -454,7 +455,7 @@ end -- @param name string: is the name of the table (optional) -- @param indent string: is a first indentation (optional). -- @return string: the pretty-printed table -function show_table(t, name, indent) +function util.show_table(t, name, indent) local cart -- a container local autoref -- for self references @@ -520,7 +521,7 @@ function show_table(t, name, indent) return cart .. autoref end -function array_contains(tbl, value) +function util.array_contains(tbl, value) for _, v in ipairs(tbl) do if v == value then return true @@ -532,6 +533,8 @@ end -- Quote Lua string, analogous to fs.Q. -- @param s A string, such as "hello" -- @return string: A quoted string, such as '"hello"' -function LQ(s) +function util.LQ(s) return ("%q"):format(s) end + +return util -- cgit v1.2.3-55-g6feb From 232317a633c5952f882ab4a891fa245d130dcc29 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 22:42:36 +0400 Subject: Fixed strange things in deps modules + fixed a bug with luarocks.fs.lua.get_md5 --- src/luarocks/build/builtin.lua | 2 -- src/luarocks/fetch/git.lua | 2 +- src/luarocks/fetch/hg.lua | 2 +- src/luarocks/fs/lua.lua | 10 +++++----- src/luarocks/fs/unix.lua | 1 - src/luarocks/fs/win32.lua | 2 +- src/luarocks/tools/patch.lua | 8 +------- 7 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index e154e65c..fa03f0d2 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -173,11 +173,9 @@ function builtin.run(rockspec) end local ok = true - local err = "Build error" local built_modules = {} local luadir = path.lua_dir(rockspec.name, rockspec.version) local libdir = path.lib_dir(rockspec.name, rockspec.version) - local docdir = path.doc_dir(rockspec.name, rockspec.version) --TODO EXEWRAPPER -- On Windows, compiles an .exe for each Lua file in build.install.bin, and -- replaces the filename with the .exe name. Strips the .lua extension if it exists, diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 7fe4c4ee..824ea905 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -67,7 +67,7 @@ function git.get_sources(rockspec, extract, dest_dir, depth) if not fs.execute(unpack(command)) then return nil, "Failed cloning git repository." end - local ok, err = fs.change_dir(module) + ok, err = fs.change_dir(module) if not ok then return nil, err end if tag_or_branch and not git_can_clone_by_tag() then local checkout_command = {fs.Q(git_cmd), "checkout", tag_or_branch} diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index 44af3afa..31b4f716 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -45,7 +45,7 @@ function hg.get_sources(rockspec, extract, dest_dir) if not fs.execute(unpack(command)) then return nil, "Failed cloning hg repository." end - local ok, err = fs.change_dir(module) + ok, err = fs.change_dir(module) if not ok then return nil, err end fs.delete(dir.path(store_dir, module, ".hg")) diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 495327ea..cd705eef 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -30,7 +30,7 @@ local dir_stack = {} math.randomseed(os.time()) -dir_separator = "/" +local dir_separator = "/" --- Quote argument for shell processing. -- Adds single quotes and escapes. @@ -683,10 +683,10 @@ if md5_ok then -- @return string: The MD5 checksum or nil + error function fs_lua.get_md5(file) file = fs.absolute_name(file) - local file = io.open(file, "rb") - if not file then return nil, "Failed to open file for reading: "..file end - local computed = md5.sumhexa(file:read("*a")) - file:close() + local file_handler = io.open(file, "rb") + if not file_handler then return nil, "Failed to open file for reading: "..file end + local computed = md5.sumhexa(file_handler:read("*a")) + file_handler:close() if computed then return computed end return nil, "Failed to compute MD5 hash for file "..file end diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 3e6b9080..a70ed116 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -7,7 +7,6 @@ local fs = require("luarocks.fs") local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") -local fs = require("luarocks.fs") local util = require("luarocks.util") math.randomseed(os.time()) diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index c4c20349..238a25e9 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -144,7 +144,7 @@ function win32.copy_binary(filename, dest) end local exe_pattern = "%.[Ee][Xx][Ee]$" local base = dir.base_name(filename) - local dest = dir.dir_name(dest) + dest = dir.dir_name(dest) if base:match(exe_pattern) then base = base:gsub(exe_pattern, ".lua") local helpname = dest.."/"..base diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index a3e1602d..4479e642 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua @@ -6,6 +6,7 @@ -- Code is heavilly based on the Python-based patch.py version 8.06-1 -- Copyright (c) 2008 rainforce.org, MIT License -- Project home: http://code.google.com/p/python-patch/ . +-- Version 0.1 --module("luarocks.tools.patch", package.seeall) local patch = {} @@ -13,8 +14,6 @@ local patch = {} local fs = require("luarocks.fs") local util = require("luarocks.util") -local version = '0.1' - local io = io local os = os local string = string @@ -397,7 +396,6 @@ local function find_hunk(file, h, hno) for i=0,#file do local found = true local location = lineno - local total = #h.text - fuzz for l, hline in ipairs(h.text) do if l > fuzz then -- todo: \ No newline at the end of file @@ -448,9 +446,6 @@ local function load_file(filename) end local function find_hunks(file, hunks) - local matched = true - local lineno = 1 - local hno = nil for hno, h in ipairs(hunks) do find_hunk(file, h, hno) end @@ -459,7 +454,6 @@ end local function check_patched(file, hunks) local matched = true local lineno = 1 - local hno = nil local ok, err = pcall(function() if #file == 0 then error 'nomatch' -- cgit v1.2.3-55-g6feb From cb08cbe837fce0b20055d55d240b18c2a6b7ebca Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 22:45:10 +0400 Subject: Unmoduled per-platform fs implementations --- src/luarocks/fs/unix/tools.lua | 55 ++++++++++++++++++++++------------------- src/luarocks/fs/win32/tools.lua | 49 +++++++++++++++++++----------------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/luarocks/fs/unix/tools.lua b/src/luarocks/fs/unix/tools.lua index df2eee3f..a288dd60 100644 --- a/src/luarocks/fs/unix/tools.lua +++ b/src/luarocks/fs/unix/tools.lua @@ -1,6 +1,7 @@ --- fs operations implemented with third-party tools for Unix platform abstractions. -module("luarocks.fs.unix.tools", package.seeall) +--module("luarocks.fs.unix.tools", package.seeall) +local tools = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -17,7 +18,7 @@ end --- Obtain current directory. -- Uses the module's internal directory stack. -- @return string: the absolute pathname of the current directory. -function current_dir() +function tools.current_dir() local pipe = io.popen(vars.PWD) local current = pipe:read("*l") pipe:close() @@ -32,7 +33,7 @@ end -- @param cmd string: No quoting/escaping is applied to the command. -- @return boolean: true if command succeeds (status code 0), false -- otherwise. -function execute_string(cmd) +function tools.execute_string(cmd) local code = os.execute(command_at(fs.current_dir(), cmd)) if code == 0 or code == true then return true @@ -46,7 +47,7 @@ end -- semantics of chdir, as it does not handle errors the same way, -- but works well for our purposes for now. -- @param directory string: The directory to switch to. -function change_dir(directory) +function tools.change_dir(directory) assert(type(directory) == "string") if fs.is_dir(directory) then table.insert(dir_stack, directory) @@ -58,12 +59,12 @@ end --- Change directory to root. -- Allows leaving a directory (e.g. for deleting it) in -- a crossplatform way. -function change_dir_to_root() +function tools.change_dir_to_root() table.insert(dir_stack, "/") end --- Change working directory to the previous in the directory stack. -function pop_dir() +function tools.pop_dir() local directory = table.remove(dir_stack) return directory ~= nil end @@ -73,7 +74,7 @@ end -- too, they are created as well. -- @param directory string: pathname of directory to create. -- @return boolean: true on success, false on failure. -function make_dir(directory) +function tools.make_dir(directory) assert(directory) local ok, err = fs.execute(vars.MKDIR.." -p", directory) if not ok then @@ -86,7 +87,7 @@ end -- Does not return errors (for example, if directory is not empty or -- if already does not exist) -- @param directory string: pathname of directory to remove. -function remove_dir_if_empty(directory) +function tools.remove_dir_if_empty(directory) assert(directory) fs.execute_quiet(vars.RMDIR, directory) end @@ -95,7 +96,7 @@ end -- Does not return errors (for example, if directory is not empty or -- if already does not exist) -- @param directory string: pathname of directory to remove. -function remove_dir_tree_if_empty(directory) +function tools.remove_dir_tree_if_empty(directory) assert(directory) fs.execute_quiet(vars.RMDIR, "-p", directory) end @@ -106,7 +107,7 @@ end -- @param perm string or nil: Permissions for destination file, -- @return boolean or (boolean, string): true on success, false on failure, -- plus an error message. -function copy(src, dest, perm) +function tools.copy(src, dest, perm) assert(src and dest) if fs.execute(vars.CP, src, dest) then if perm then @@ -130,7 +131,7 @@ end -- @param dest string: Pathname of destination -- @return boolean or (boolean, string): true on success, false on failure, -- plus an error message. -function copy_contents(src, dest) +function tools.copy_contents(src, dest) assert(src and dest) if fs.execute_quiet(vars.CP.." -pPR "..fs.Q(src).."/* "..fs.Q(dest)) then return true @@ -142,7 +143,7 @@ end -- For safety, this only accepts absolute paths. -- @param arg string: Pathname of source -- @return nil -function delete(arg) +function tools.delete(arg) assert(arg) assert(arg:sub(1,1) == "/") fs.execute_quiet(vars.RM, "-rf", arg) @@ -152,7 +153,7 @@ end -- Yields a filename on each iteration. -- @param at string: directory to list -- @return nil -function dir_iterator(at) +function tools.dir_iterator(at) local pipe = io.popen(command_at(at, vars.LS)) for file in pipe:lines() do if file ~= "." and file ~= ".." then @@ -167,7 +168,7 @@ end -- directory if none is given). -- @return table: an array of strings with the filenames representing -- the contents of a directory. -function find(at) +function tools.find(at) assert(type(at) == "string" or not at) if not at then at = fs.current_dir() @@ -189,14 +190,14 @@ end -- @param ... Filenames to be stored in the archive are given as -- additional arguments. -- @return boolean: true on success, false on failure. -function zip(zipfile, ...) +function tools.zip(zipfile, ...) return fs.execute(vars.ZIP.." -r", zipfile, ...) end --- Uncompress files from a .zip archive. -- @param zipfile string: pathname of .zip archive to be extracted. -- @return boolean: true on success, false on failure. -function unzip(zipfile) +function tools.unzip(zipfile) assert(zipfile) return fs.execute_quiet(vars.UNZIP, zipfile) end @@ -204,7 +205,7 @@ end --- Test is file/directory exists -- @param file string: filename to test -- @return boolean: true if file exists, false otherwise. -function exists(file) +function tools.exists(file) assert(file) return fs.execute(vars.TEST, "-e", file) end @@ -212,7 +213,7 @@ end --- Test is pathname is a directory. -- @param file string: pathname to test -- @return boolean: true if it is a directory, false otherwise. -function is_dir(file) +function tools.is_dir(file) assert(file) return fs.execute(vars.TEST, "-d", file) end @@ -220,7 +221,7 @@ end --- Test is pathname is a regular file. -- @param file string: pathname to test -- @return boolean: true if it is a regular file, false otherwise. -function is_file(file) +function tools.is_file(file) assert(file) return fs.execute(vars.TEST, "-f", file) end @@ -233,7 +234,7 @@ end -- filename can be given explicitly as this second argument. -- @return (boolean, string): true and the filename on success, -- false and the error message on failure. -function download(url, filename, cache) +function tools.download(url, filename, cache) assert(type(url) == "string") assert(type(filename) == "string" or not filename) @@ -263,7 +264,7 @@ function download(url, filename, cache) end end -function chmod(pathname, mode) +function tools.chmod(pathname, mode) if mode then return fs.execute(vars.CHMOD, mode, pathname) else @@ -273,7 +274,7 @@ end --- Apply a patch. -- @param patchname string: The filename of the patch. -function apply_patch(patchname) +function tools.apply_patch(patchname) return fs.execute(vars.PATCH.." -p1 -f -i ", patchname) end @@ -282,7 +283,7 @@ end -- filename extension. -- @param archive string: Filename of archive. -- @return boolean or (boolean, string): true on success, false and an error message on failure. -function unpack_archive(archive) +function tools.unpack_archive(archive) assert(type(archive) == "string") local ok @@ -314,7 +315,7 @@ local md5_cmd = { --- Get the MD5 checksum for a file. -- @param file string: The file to be computed. -- @return string: The MD5 checksum -function get_md5(file) +function tools.get_md5(file) local cmd = md5_cmd[cfg.md5checker] if not cmd then return nil, "no MD5 checker command configured" end local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) @@ -327,13 +328,15 @@ function get_md5(file) return nil, "Failed to compute MD5 hash for file "..tostring(fs.absolute_name(file)) end -function get_permissions(filename) +function tools.get_permissions(filename) local pipe = io.popen(vars.STAT.." "..vars.STATFLAG.." "..fs.Q(filename)) local ret = pipe:read("*l") pipe:close() return ret end -function browser(url) +function tools.browser(url) return fs.execute(cfg.web_browser, url) end + +return tools diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 55781b66..abf3779f 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua @@ -2,7 +2,8 @@ --- fs operations implemented with third-party tools for Windows platform abstractions. -- Download http://unxutils.sourceforge.net/ for Windows GNU utilities -- used by this module. -module("luarocks.fs.win32.tools", package.seeall) +--module("luarocks.fs.win32.tools", package.seeall) +local tools = {} local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -35,7 +36,7 @@ end --- Obtain current directory. -- Uses the module's internal directory stack. -- @return string: the absolute pathname of the current directory. -function current_dir() +function tools.current_dir() local current = cfg.cache_pwd if not current then local pipe = io.popen(fs.Q(vars.PWD)) @@ -54,7 +55,7 @@ end -- @param cmd string: No quoting/escaping is applied to the command. -- @return boolean: true if command succeeds (status code 0), false -- otherwise. -function execute_string(cmd) +function tools.execute_string(cmd) cmd = command_at(fs.current_dir(), cmd) local code = os.execute(cmd) if code == 0 or code == true then @@ -70,7 +71,7 @@ end -- but works well for our purposes for now. -- @param directory string: The directory to switch to. -- @return boolean or (nil, string): true if successful, (nil, error message) if failed. -function change_dir(directory) +function tools.change_dir(directory) assert(type(directory) == "string") if fs.is_dir(directory) then table.insert(dir_stack, directory) @@ -82,12 +83,12 @@ end --- Change directory to root. -- Allows leaving a directory (e.g. for deleting it) in -- a crossplatform way. -function change_dir_to_root() +function tools.change_dir_to_root() table.insert(dir_stack, "/") end --- Change working directory to the previous in the directory stack. -function pop_dir() +function tools.pop_dir() local directory = table.remove(dir_stack) return directory ~= nil end @@ -97,7 +98,7 @@ end -- too, they are created as well. -- @param directory string: pathname of directory to create. -- @return boolean: true on success, false on failure. -function make_dir(directory) +function tools.make_dir(directory) assert(directory) directory = dir.normalize(directory) fs.execute_quiet(fs.Q(vars.MKDIR).." -p ", directory) @@ -111,7 +112,7 @@ end -- Does not return errors (for example, if directory is not empty or -- if already does not exist) -- @param directory string: pathname of directory to remove. -function remove_dir_if_empty(directory) +function tools.remove_dir_if_empty(directory) assert(directory) fs.execute_quiet(fs.Q(vars.RMDIR), directory) end @@ -120,7 +121,7 @@ end -- Does not return errors (for example, if directory is not empty or -- if already does not exist) -- @param directory string: pathname of directory to remove. -function remove_dir_tree_if_empty(directory) +function tools.remove_dir_tree_if_empty(directory) assert(directory) fs.execute_quiet(fs.Q(vars.RMDIR), directory) end @@ -130,7 +131,7 @@ end -- @param dest string: Pathname of destination -- @return boolean or (boolean, string): true on success, false on failure, -- plus an error message. -function copy(src, dest) +function tools.copy(src, dest) assert(src and dest) if dest:match("[/\\]$") then dest = dest:sub(1, -2) end local ok = fs.execute(fs.Q(vars.CP), src, dest) @@ -146,7 +147,7 @@ end -- @param dest string: Pathname of destination -- @return boolean or (boolean, string): true on success, false on failure, -- plus an error message. -function copy_contents(src, dest) +function tools.copy_contents(src, dest) assert(src and dest) if fs.execute_quiet(fs.Q(vars.CP).." -dR "..src.."\\*.* "..fs.Q(dest)) then return true @@ -159,7 +160,7 @@ end -- For safety, this only accepts absolute paths. -- @param arg string: Pathname of source -- @return nil -function delete(arg) +function tools.delete(arg) assert(arg) assert(arg:match("^[a-zA-Z]?:?[\\/]")) fs.execute_quiet("if exist "..fs.Q(arg.."\\").." ( RMDIR /S /Q "..fs.Q(arg).." ) else ( DEL /Q /F "..fs.Q(arg).." )") @@ -169,7 +170,7 @@ end -- Yields a filename on each iteration. -- @param at string: directory to list -- @return nil -function dir_iterator(at) +function tools.dir_iterator(at) local pipe = io.popen(command_at(at, fs.Q(vars.LS))) for file in pipe:lines() do if file ~= "." and file ~= ".." then @@ -184,7 +185,7 @@ end -- directory if none is given). -- @return table: an array of strings with the filenames representing -- the contents of a directory. Paths are returned with forward slashes. -function find(at) +function tools.find(at) assert(type(at) == "string" or not at) if not at then at = fs.current_dir() @@ -211,14 +212,14 @@ end -- @param ... Filenames to be stored in the archive are given as -- additional arguments. -- @return boolean: true on success, false on failure. -function zip(zipfile, ...) +function tools.zip(zipfile, ...) return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa a -tzip", zipfile, ...) end --- Uncompress files from a .zip archive. -- @param zipfile string: pathname of .zip archive to be extracted. -- @return boolean: true on success, false on failure. -function unzip(zipfile) +function tools.unzip(zipfile) assert(zipfile) return fs.execute_quiet(fs.Q(vars.SEVENZ).." -aoa x", zipfile) end @@ -226,7 +227,7 @@ end --- Test is pathname is a directory. -- @param file string: pathname to test -- @return boolean: true if it is a directory, false otherwise. -function is_dir(file) +function tools.is_dir(file) assert(file) return fs.execute_quiet("if not exist " .. fs.Q(file.."\\").." invalidcommandname") end @@ -234,7 +235,7 @@ end --- Test is pathname is a regular file. -- @param file string: pathname to test -- @return boolean: true if it is a regular file, false otherwise. -function is_file(file) +function tools.is_file(file) assert(file) return fs.execute(fs.Q(vars.TEST).." -f", file) end @@ -247,7 +248,7 @@ end -- filename can be given explicitly as this second argument. -- @return (boolean, string): true and the filename on success, -- false and the error message on failure. -function download(url, filename, cache) +function tools.download(url, filename, cache) assert(type(url) == "string") assert(type(filename) == "string" or not filename) @@ -289,7 +290,7 @@ end -- filename extension. -- @param archive string: Filename of archive. -- @return boolean or (boolean, string): true on success, false and an error message on failure. -function unpack_archive(archive) +function tools.unpack_archive(archive) assert(type(archive) == "string") local ok @@ -333,7 +334,7 @@ local md5_cmd = { --- Get the MD5 checksum for a file. -- @param file string: The file to be computed. -- @return string: The MD5 checksum or nil + message -function get_md5(file) +function tools.get_md5(file) local cmd = md5_cmd[cfg.md5checker] if not cmd then return nil, "no MD5 checker command configured" end local pipe = io.popen(cmd.." "..fs.Q(fs.absolute_name(file))) @@ -349,11 +350,13 @@ end --- Test for existance of a file. -- @param file string: filename to test -- @return boolean: true if file exists, false otherwise. -function exists(file) +function tools.exists(file) assert(file) return fs.execute_quiet("if not exist " .. fs.Q(file) .. " invalidcommandname") end -function browser(url) +function tools.browser(url) return fs.execute(cfg.web_browser..' "Starting docs..." '..fs.Q(url)) end + +return tools -- cgit v1.2.3-55-g6feb From be3a3510e14b0d68bf6f51003f21b546fb86dec5 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 22:50:23 +0400 Subject: Minor consistency improvement in util.lua --- src/luarocks/util.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 2c704a52..fd0cda44 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -195,12 +195,12 @@ end -- @param msg string: the warning message to display. function util.warn_if_not_used(var_defs, needed_set, msg) needed_set = make_shallow_copy(needed_set) - for var,val in pairs(var_defs) do + for _, val in pairs(var_defs) do for used in val:gmatch(var_format_pattern) do needed_set[used] = nil end end - for var,_ in pairs(needed_set) do + for var, _ in pairs(needed_set) do util.warning(msg:format(var)) end end -- cgit v1.2.3-55-g6feb From 878f56e1f05447cfe1c79ef9b720433b51e61bd9 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 23:19:17 +0400 Subject: Unmoduled core modules with package.loaded trick + fixed locals shadowing module table Thanks to Metalua for the possibility to automate this. --- src/luarocks/add.lua | 14 +++-- src/luarocks/admin_remove.lua | 14 +++-- src/luarocks/build.lua | 66 +++++++++++----------- src/luarocks/build/cmake.lua | 6 +- src/luarocks/cache.lua | 16 ++++-- src/luarocks/cfg.lua | 120 +++++++++++++++++++++------------------- src/luarocks/deps.lua | 78 +++++++++++++------------- src/luarocks/dir.lua | 20 ++++--- src/luarocks/doc.lua | 12 ++-- src/luarocks/download.lua | 18 +++--- src/luarocks/fetch.lua | 50 +++++++++-------- src/luarocks/fs.lua | 14 +++-- src/luarocks/index.lua | 12 ++-- src/luarocks/install.lua | 20 ++++--- src/luarocks/lint.lua | 14 +++-- src/luarocks/list.lua | 14 +++-- src/luarocks/loader.lua | 48 ++++++++-------- src/luarocks/make.lua | 14 +++-- src/luarocks/make_manifest.lua | 12 ++-- src/luarocks/manif.lua | 40 ++++++++------ src/luarocks/manif_core.lua | 24 ++++---- src/luarocks/new_version.lua | 14 +++-- src/luarocks/pack.lua | 16 ++++-- src/luarocks/persist.lua | 16 ++++-- src/luarocks/purge.lua | 14 +++-- src/luarocks/refresh_cache.lua | 14 +++-- src/luarocks/remove.lua | 22 +++++--- src/luarocks/repos.lua | 28 ++++++---- src/luarocks/require.lua | 6 +- src/luarocks/search.lua | 44 ++++++++------- src/luarocks/show.lua | 16 ++++-- src/luarocks/tools/patch.lua | 10 ++-- src/luarocks/type_check.lua | 22 +++++--- src/luarocks/unpack.lua | 14 +++-- src/luarocks/validate.lua | 24 ++++---- src/luarocks/write_rockspec.lua | 14 +++-- 36 files changed, 512 insertions(+), 388 deletions(-) diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index c7acd5f8..fc913c95 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua @@ -1,7 +1,9 @@ --- Module implementing the luarocks-admin "add" command. -- Adds a rock or rockspec to a rocks server. -module("luarocks.add", package.seeall) +--module("luarocks.add", package.seeall) +local add = {} +package.loaded["luarocks.add"] = add local cfg = require("luarocks.cfg") local util = require("luarocks.util") @@ -11,9 +13,9 @@ local index = require("luarocks.index") local fs = require("luarocks.fs") local cache = require("luarocks.cache") -help_summary = "Add a rock or rockspec to a rocks server." -help_arguments = "[--server=] [--no-refresh] {|...}" -help = [[ +add.help_summary = "Add a rock or rockspec to a rocks server." +add.help_arguments = "[--server=] [--no-refresh] {|...}" +add.help = [[ Arguments are local files, which may be rockspecs or rocks. The flag --server indicates which server to use. If not given, the default server set in the upload_server variable @@ -106,7 +108,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) return true end -function run(...) +function add.run(...) local files = { util.parse_flags(...) } local flags = table.remove(files, 1) if #files < 1 then @@ -117,3 +119,5 @@ function run(...) return add_files_to_server(not flags["no-refresh"], files, server, server_table) end + +return add diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua index 477592b1..839121d1 100644 --- a/src/luarocks/admin_remove.lua +++ b/src/luarocks/admin_remove.lua @@ -1,7 +1,9 @@ --- Module implementing the luarocks-admin "remove" command. -- Removes a rock or rockspec from a rocks server. -module("luarocks.admin_remove", package.seeall) +--module("luarocks.admin_remove", package.seeall) +local admin_remove = {} +package.loaded["luarocks.admin_remove"] = admin_remove local cfg = require("luarocks.cfg") local util = require("luarocks.util") @@ -11,9 +13,9 @@ local index = require("luarocks.index") local fs = require("luarocks.fs") local cache = require("luarocks.cache") -help_summary = "Remove a rock or rockspec from a rocks server." -help_arguments = "[--server=] [--no-refresh] {|...}" -help = [[ +admin_remove.help_summary = "Remove a rock or rockspec from a rocks server." +admin_remove.help_arguments = "[--server=] [--no-refresh] {|...}" +admin_remove.help = [[ Arguments are local files, which may be rockspecs or rocks. The flag --server indicates which server to use. If not given, the default server set in the upload_server variable @@ -76,7 +78,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve return true end -function run(...) +function admin_remove.run(...) local files = { util.parse_flags(...) } local flags = table.remove(files, 1) if #files < 1 then @@ -87,3 +89,5 @@ function run(...) return remove_files_from_server(not flags["no-refresh"], files, server, server_table) end + +return admin_remove diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 30cdd309..cc56c782 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -1,7 +1,9 @@ --- Module implementing the LuaRocks "build" command. -- Builds a rock, compiling its C parts if any. -module("luarocks.build", package.seeall) +--module("luarocks.build", package.seeall) +local build = {} +package.loaded["luarocks.build"] = build local pack = require("luarocks.pack") local path = require("luarocks.path") @@ -15,9 +17,9 @@ local manif = require("luarocks.manif") local remove = require("luarocks.remove") local cfg = require("luarocks.cfg") -help_summary = "Build/compile a rock." -help_arguments = "[--pack-binary-rock] [--keep] {|| []}" -help = [[ +build.help_summary = "Build/compile a rock." +build.help_arguments = "[--pack-binary-rock] [--keep] {|| []}" +build.help = [[ Build and install a rock, compiling its C parts if any. Argument may be a rockspec file, a source rock file or the name of a rock to be fetched from a repository. @@ -107,16 +109,16 @@ end -- @param rockspec table: A rockspec table. -- @return boolean or (nil, string): True if succeeded or -- nil and an error message. -function apply_patches(rockspec) +function build.apply_patches(rockspec) assert(type(rockspec) == "table") - local build = rockspec.build - if build.extra_files then - extract_from_rockspec(build.extra_files) + local build_spec = rockspec.build + if build_spec.extra_files then + extract_from_rockspec(build_spec.extra_files) end - if build.patches then - extract_from_rockspec(build.patches) - for patch, patchdata in util.sortedpairs(build.patches) do + if build_spec.patches then + extract_from_rockspec(build_spec.patches) + for patch, patchdata in util.sortedpairs(build_spec.patches) do util.printout("Applying patch "..patch.."...") local ok, err = fs.apply_patch(tostring(patch), patchdata) if not ok then @@ -157,7 +159,7 @@ end -- "none" for no trees. -- @return (string, string) or (nil, string, [string]): Name and version of -- installed rock if succeeded or nil and an error message followed by an error code. -function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) +function build.build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) assert(type(rockspec_file) == "string") assert(type(need_to_fetch) == "boolean") @@ -223,31 +225,31 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) fs.remove_dir_if_empty(path.versions_dir(name)) end) - local build = rockspec.build + local build_spec = rockspec.build if not minimal_mode then - ok, err = apply_patches(rockspec) + ok, err = build.apply_patches(rockspec) if err then return nil, err end end - if build.type ~= "none" then + if build_spec.type ~= "none" then -- Temporary compatibility - if build.type == "module" then + if build_spec.type == "module" then util.printout("Do not use 'module' as a build type. Use 'builtin' instead.") - build.type = "builtin" + build_spec.type = "builtin" end - if cfg.accepted_build_types and util.array_contains(cfg.accepted_build_types, build.type) then - return nil, "This rockspec uses the '"..build.type.."' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." + if cfg.accepted_build_types and util.array_contains(cfg.accepted_build_types, build_spec.type) then + return nil, "This rockspec uses the '"..build_spec.type.."' build type, which is blocked by the 'accepted_build_types' setting in your LuaRocks configuration." end local build_type - ok, build_type = pcall(require, "luarocks.build." .. build.type) + ok, build_type = pcall(require, "luarocks.build." .. build_spec.type) if not ok or not type(build_type) == "table" then - return nil, "Failed initializing build back-end for build type '"..build.type.."': "..build_type + return nil, "Failed initializing build back-end for build type '"..build_spec.type.."': "..build_type end ok, err = build_type.run(rockspec) @@ -256,16 +258,16 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) end end - if build.install then + if build_spec.install then for id, install_dir in pairs(dirs) do - ok, err = install_files(build.install[id], install_dir.name, install_dir.is_module_path) + ok, err = install_files(build_spec.install[id], install_dir.name, install_dir.is_module_path) if not ok then return nil, err end end end - local copy_directories = build.copy_directories + local copy_directories = build_spec.copy_directories local copying_default = false if not copy_directories then copy_directories = {"doc"} @@ -340,7 +342,7 @@ end -- "order" for all trees with priority >= the current default, "none" for no trees. -- @return boolean or (nil, string, [string]): True if build was successful, -- or false and an error message and an optional error code. -function build_rock(rock_file, need_to_fetch, deps_mode) +function build.build_rock(rock_file, need_to_fetch, deps_mode) assert(type(rock_file) == "string") assert(type(need_to_fetch) == "boolean") @@ -351,24 +353,24 @@ function build_rock(rock_file, need_to_fetch, deps_mode) local rockspec_file = path.rockspec_name_from_rock(rock_file) local ok, err = fs.change_dir(unpack_dir) if not ok then return nil, err end - local ok, err, errcode = build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) + local ok, err, errcode = build.build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) fs.pop_dir() return ok, err, errcode end local function do_build(name, version, deps_mode) if name:match("%.rockspec$") then - return build_rockspec(name, true, false, deps_mode) + return build.build_rockspec(name, true, false, deps_mode) elseif name:match("%.src%.rock$") then - return build_rock(name, false, deps_mode) + return build.build_rock(name, false, deps_mode) elseif name:match("%.all%.rock$") then local install = require("luarocks.install") return install.install_binary_rock(name, deps_mode) elseif name:match("%.rock$") then - return build_rock(name, true, deps_mode) + return build.build_rock(name, true, deps_mode) elseif not name:match(dir.separator) then local search = require("luarocks.search") - return search.act_on_src_or_rockspec(run, name:lower(), version, deps.deps_mode_to_flag(deps_mode)) + return search.act_on_src_or_rockspec(build.run, name:lower(), version, deps.deps_mode_to_flag(deps_mode)) end return nil, "Don't know what to do with "..name end @@ -381,7 +383,7 @@ end -- also be given. -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an -- error message otherwise. exitcode is optionally returned. -function run(...) +function build.run(...) local flags, name, version = util.parse_flags(...) if type(name) ~= "string" then return nil, "Argument missing. "..util.see_help("build") @@ -403,3 +405,5 @@ function run(...) return name, version end end + +return build diff --git a/src/luarocks/build/cmake.lua b/src/luarocks/build/cmake.lua index 83ec20f3..ed2af3ff 100644 --- a/src/luarocks/build/cmake.lua +++ b/src/luarocks/build/cmake.lua @@ -29,9 +29,9 @@ function cmake.run(rockspec) -- If inline cmake is present create CMakeLists.txt from it. if type(build.cmake) == "string" then - local cmake = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) - cmake:write(build.cmake) - cmake:close() + local cmake_handler = assert(io.open(fs.current_dir().."/CMakeLists.txt", "w")) + cmake_handler:write(build.cmake) + cmake_handler:close() end diff --git a/src/luarocks/cache.lua b/src/luarocks/cache.lua index a3dfe8b1..dbea8405 100644 --- a/src/luarocks/cache.lua +++ b/src/luarocks/cache.lua @@ -1,14 +1,16 @@ --- Module handling the LuaRocks local cache. -- Adds a rock or rockspec to a rocks server. -module("luarocks.cache", package.seeall) +--module("luarocks.cache", package.seeall) +local cache = {} +package.loaded["luarocks.cache"] = cache local fs = require("luarocks.fs") local cfg = require("luarocks.cfg") local dir = require("luarocks.dir") local util = require("luarocks.util") -function get_upload_server(server) +function cache.get_upload_server(server) if not server then server = cfg.upload_server end if not server then return nil, "No server specified and no default configured with upload_server." @@ -16,7 +18,7 @@ function get_upload_server(server) return server, cfg.upload_servers and cfg.upload_servers[server] end -function get_server_urls(server, upload_server) +function cache.get_server_urls(server, upload_server) local download_url = server local login_url = nil if upload_server then @@ -32,7 +34,7 @@ function get_server_urls(server, upload_server) return download_url, login_url end -function split_server_url(server, url, user, password) +function cache.split_server_url(server, url, user, password) local protocol, server_path = dir.split_url(url) if server_path:match("@") then local credentials @@ -50,8 +52,8 @@ function split_server_url(server, url, user, password) return local_cache, protocol, server_path, user, password end -function refresh_local_cache(server, url, user, password) - local local_cache, protocol, server_path, user, password = split_server_url(server, url, user, password) +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 @@ -86,3 +88,5 @@ function refresh_local_cache(server, url, user, password) end return local_cache, protocol, server_path, user, password end + +return cache diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index e7e091e9..21cfbf6d 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -13,10 +13,12 @@ local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION = rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION -module("luarocks.cfg") +--module("luarocks.cfg") +local cfg = {} +package.loaded["luarocks.cfg"] = cfg -lua_version = _VERSION:sub(5) -local version_suffix = lua_version:gsub("%.", "_") +cfg.lua_version = _VERSION:sub(5) +local version_suffix = cfg.lua_version:gsub("%.", "_") -- Load site-local global configurations local ok, site_config = pcall(require, "luarocks.site_config_"..version_suffix) @@ -28,14 +30,14 @@ if not ok then site_config = {} end -_M.site_config = site_config +cfg.site_config = site_config -program_version = "2.1.2" -major_version = program_version:match("([^.]%.[^.])") +cfg.program_version = "2.1.2" +cfg.major_version = cfg.program_version:match("([^.]%.[^.])") local persist = require("luarocks.persist") -_M.errorcodes = setmetatable({ +cfg.errorcodes = setmetatable({ OK = 0, UNSPECIFIED = 1, PERMISSIONDENIED = 2, @@ -58,7 +60,7 @@ if popen_ok then else io.stderr:write("Your version of Lua does not support io.popen,\n") io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") - os.exit(_M.errorcodes.UNSPECIFIED) + os.exit(cfg.errorcodes.UNSPECIFIED) end -- System detection: @@ -124,27 +126,27 @@ local sys_config_ok, home_config_ok = false, false local extra_luarocks_module_dir sys_config_dir = site_config.LUAROCKS_SYSCONFDIR if detected.windows then - home = os.getenv("APPDATA") or "c:" + cfg.home = os.getenv("APPDATA") or "c:" sys_config_dir = sys_config_dir or "c:/luarocks" - home_config_dir = home.."/luarocks" - home_tree = home.."/luarocks/" + home_config_dir = cfg.home.."/luarocks" + cfg.home_tree = cfg.home.."/luarocks/" else - home = os.getenv("HOME") or "" + cfg.home = os.getenv("HOME") or "" sys_config_dir = sys_config_dir or "/etc/luarocks" - home_config_dir = home.."/.luarocks" - home_tree = home.."/.luarocks/" + home_config_dir = cfg.home.."/.luarocks" + cfg.home_tree = cfg.home.."/.luarocks/" end -variables = {} -rocks_trees = {} +cfg.variables = {} +cfg.rocks_trees = {} -sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..lua_version..".lua" +sys_config_file = site_config.LUAROCKS_SYSCONFIG or sys_config_dir.."/config-"..cfg.lua_version..".lua" local err -sys_config_ok, err = persist.load_into_table(sys_config_file, _M) +sys_config_ok, err = persist.load_into_table(sys_config_file, cfg) if not sys_config_ok then sys_config_file = sys_config_dir.."/config.lua" - sys_config_ok, err = persist.load_into_table(sys_config_file, _M) + sys_config_ok, err = persist.load_into_table(sys_config_file, cfg) end if err and sys_config_ok == nil then io.stderr:write(err.."\n") @@ -154,25 +156,25 @@ if not site_config.LUAROCKS_FORCE_CONFIG then local home_overrides, err home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") if home_config_file then - home_overrides, err = persist.load_into_table(home_config_file, { home = home, lua_version = lua_version }) + home_overrides, err = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version }) else - home_config_file = home_config_dir.."/config-"..lua_version..".lua" - home_overrides, err = persist.load_into_table(home_config_file, { home = home, lua_version = lua_version }) + home_config_file = home_config_dir.."/config-"..cfg.lua_version..".lua" + home_overrides, err = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version }) if not home_overrides then home_config_file = home_config_dir.."/config.lua" - home_overrides, err = persist.load_into_table(home_config_file, { home = home, lua_version = lua_version }) + home_overrides, err = persist.load_into_table(home_config_file, { home = cfg.home, lua_version = cfg.lua_version }) end end if home_overrides then home_config_ok = true local util = require("luarocks.util") if home_overrides.rocks_trees then - _M.rocks_trees = nil + cfg.rocks_trees = nil end if home_overrides.rocks_servers then - _M.rocks_servers = nil + cfg.rocks_servers = nil end - util.deep_merge(_M, home_overrides) + util.deep_merge(cfg, home_overrides) else -- nil or false home_config_ok = home_overrides if err and home_config_ok == nil then @@ -181,18 +183,18 @@ if not site_config.LUAROCKS_FORCE_CONFIG then end end -if not next(rocks_trees) then - if home_tree then - table.insert(rocks_trees, { name = "user", root = home_tree } ) +if not next(cfg.rocks_trees) then + if cfg.home_tree then + table.insert(cfg.rocks_trees, { name = "user", root = cfg.home_tree } ) end if site_config.LUAROCKS_ROCKS_TREE then - table.insert(rocks_trees, { name = "system", root = site_config.LUAROCKS_ROCKS_TREE } ) + table.insert(cfg.rocks_trees, { name = "system", root = site_config.LUAROCKS_ROCKS_TREE } ) end end -- Configure defaults: -local root = rocks_trees[#rocks_trees] +local root = cfg.rocks_trees[#cfg.rocks_trees] local defaults = { local_by_default = false, @@ -202,8 +204,8 @@ local defaults = { hooks_enabled = true, deps_mode = "one", - lua_modules_path = "/share/lua/"..lua_version, - lib_modules_path = "/lib/lua/"..lua_version, + lua_modules_path = "/share/lua/"..cfg.lua_version, + lib_modules_path = "/lib/lua/"..cfg.lua_version, rocks_subdir = site_config.LUAROCKS_ROCKS_SUBDIR or "/lib/luarocks/rocks", arch = "unknown", @@ -286,7 +288,7 @@ local defaults = { } if detected.windows then - local full_prefix = site_config.LUAROCKS_PREFIX.."\\"..major_version + local full_prefix = site_config.LUAROCKS_PREFIX.."\\"..cfg.major_version extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua" home_config_file = home_config_file and home_config_file:gsub("\\","/") @@ -297,9 +299,9 @@ if detected.windows then defaults.external_lib_extension = "dll" defaults.obj_extension = "obj" defaults.external_deps_dirs = { "c:/external/" } - defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/bin" - defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/include" - defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/lib" + defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/bin" + defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/include" + defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..cfg.lua_version.."/lib" defaults.cmake_generator = "MinGW Makefiles" defaults.makefile = "Makefile.win" defaults.variables.MAKE = "nmake" @@ -308,7 +310,7 @@ if detected.windows then defaults.variables.WRAPPER = full_prefix.."\\rclauncher.c" defaults.variables.LD = "link" defaults.variables.MT = "mt" - defaults.variables.LUALIB = "lua"..lua_version..".lib" + defaults.variables.LUALIB = "lua"..cfg.lua_version..".lib" defaults.variables.CFLAGS = "/MD /O2" defaults.variables.LIBFLAG = "/dll" @@ -400,7 +402,7 @@ if detected.unix then defaults.export_lua_path = "export LUA_PATH='%s'" defaults.export_lua_cpath = "export LUA_CPATH='%s'" defaults.wrapper_suffix = "" - defaults.local_cache = home.."/.cache/luarocks" + defaults.local_cache = cfg.home.."/.cache/luarocks" if not defaults.variables.CFLAGS:match("-fPIC") then defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" end @@ -474,11 +476,11 @@ defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter -- Add built-in modules to rocks_provided -defaults.rocks_provided["lua"] = lua_version.."-1" +defaults.rocks_provided["lua"] = cfg.lua_version.."-1" -if lua_version >= "5.2" then +if cfg.lua_version >= "5.2" then -- Lua 5.2+ - defaults.rocks_provided["bit32"] = lua_version.."-1" + defaults.rocks_provided["bit32"] = cfg.lua_version.."-1" end if package.loaded.jit then @@ -493,12 +495,12 @@ end -- Populate some arrays with values from their 'defaults' counterparts -- if they were not already set by user. for _, entry in ipairs({"variables", "rocks_provided"}) do - if not _M[entry] then - _M[entry] = {} + if not cfg[entry] then + cfg[entry] = {} end for k,v in pairs(defaults[entry]) do - if not _M[entry][k] then - _M[entry][k] = v + if not cfg[entry][k] then + cfg[entry][k] = v end end end @@ -513,38 +515,40 @@ local cfg_mt = { return default end } -setmetatable(_M, cfg_mt) +setmetatable(cfg, cfg_mt) -function package_paths() +function cfg.package_paths() local new_path, new_cpath = { extra_luarocks_module_dir }, {} - for _,tree in ipairs(rocks_trees) do + for _,tree in ipairs(cfg.rocks_trees) do if type(tree) == "string" then - table.insert(new_path, 1, tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua") - table.insert(new_cpath, 1, tree..lib_modules_path.."/?."..lib_extension) + table.insert(new_path, 1, tree..cfg.lua_modules_path.."/?.lua;"..tree..cfg.lua_modules_path.."/?/init.lua") + table.insert(new_cpath, 1, tree..cfg.lib_modules_path.."/?."..cfg.lib_extension) else - table.insert(new_path, 1, (tree.lua_dir or tree.root..lua_modules_path).."/?.lua;".. - (tree.lua_dir or tree.root..lua_modules_path).."/?/init.lua") - table.insert(new_cpath, 1, (tree.lib_dir or tree.root..lib_modules_path).."/?."..lib_extension) + table.insert(new_path, 1, (tree.lua_dir or tree.root..cfg.lua_modules_path).."/?.lua;".. + (tree.lua_dir or tree.root..cfg.lua_modules_path).."/?/init.lua") + table.insert(new_cpath, 1, (tree.lib_dir or tree.root..cfg.lib_modules_path).."/?."..cfg.lib_extension) end end return table.concat(new_path, ";"), table.concat(new_cpath, ";") end -function which_config() +function cfg.which_config() return sys_config_file, sys_config_ok, home_config_file, home_config_ok end -user_agent = "LuaRocks/"..program_version.." "..arch +cfg.user_agent = "LuaRocks/"..cfg.program_version.." "..cfg.arch --- Check if platform was detected -- @param query string: The platform name to check. -- @return boolean: true if LuaRocks is currently running on queried platform. -function is_platform(query) +function cfg.is_platform(query) assert(type(query) == "string") - for _, platform in ipairs(platforms) do + for _, platform in ipairs(cfg.platforms) do if platform == query then return true end end end + +return cfg diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 567a576b..3f75f9be 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -11,7 +11,9 @@ -- comparison criteria is the source code of this module, but the -- test/test_deps.lua file included with LuaRocks provides some -- insights on what these criteria are. -module("luarocks.deps", package.seeall) +--module("luarocks.deps", package.seeall) +local deps = {} +package.loaded["luarocks.deps"] = deps local cfg = require("luarocks.cfg") local manif_core = require("luarocks.manif_core") @@ -101,7 +103,7 @@ setmetatable(version_cache, { -- @param vstring string: A version number in string format. -- @return table or nil: A version table or nil -- if the input string contains invalid characters. -function parse_version(vstring) +function deps.parse_version(vstring) if not vstring then return nil end assert(type(vstring) == "string") @@ -153,8 +155,8 @@ end -- @param a string: one version. -- @param b string: another version. -- @return boolean: True if a > b. -function compare_versions(a, b) - return parse_version(a) > parse_version(b) +function deps.compare_versions(a, b) + return deps.parse_version(a) > deps.parse_version(b) end --- Consumes a constraint from a string, converting it to table format. @@ -170,7 +172,7 @@ local function parse_constraint(input) local no_upgrade, op, version, rest = input:match("^(@?)([<>=~!]*)%s*([%w%.%_%-]+)[%s,]*(.*)") local _op = operators[op] - version = parse_version(version) + version = deps.parse_version(version) if not _op then return nil, "Encountered bad constraint operator: '"..tostring(op).."' in '"..input.."'" end @@ -188,7 +190,7 @@ end -- @param input string: A list of constraints in string format. -- @return table or nil: A table representing the same constraints, -- or nil if the input string is invalid. -function parse_constraints(input) +function deps.parse_constraints(input) assert(type(input) == "string") local constraints, constraint, oinput = {}, nil, input @@ -213,12 +215,12 @@ end -- as entered in rockspec files. -- @return table or nil: A table representing the same dependency relation, -- or nil if the input string is invalid. -function parse_dep(dep) +function deps.parse_dep(dep) assert(type(dep) == "string") local name, rest = dep:match("^%s*([a-zA-Z0-9][a-zA-Z0-9%.%-%_]*)%s*(.*)") if not name then return nil, "failed to extract dependency name from '"..tostring(dep).."'" end - local constraints, err = parse_constraints(rest) + local constraints, err = deps.parse_constraints(rest) if not constraints then return nil, err end return { name = name, constraints = constraints } end @@ -228,7 +230,7 @@ end -- @param internal boolean or nil: Whether to display versions in their -- internal representation format or how they were specified. -- @return string: The dependency information pretty-printed as a string. -function show_version(v, internal) +function deps.show_version(v, internal) assert(type(v) == "table") assert(type(internal) == "boolean" or not internal) @@ -242,13 +244,13 @@ end -- @param internal boolean or nil: Whether to display versions in their -- internal representation format or how they were specified. -- @return string: The dependency information pretty-printed as a string. -function show_dep(dep, internal) +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 .. " " .. show_version(c.version, internal)) + table.insert(pretty, c.op .. " " .. deps.show_version(c.version, internal)) end return dep.name.." "..table.concat(pretty, ", ") end @@ -269,8 +271,8 @@ local function partial_match(version, requested) assert(type(version) == "string" or type(version) == "table") assert(type(requested) == "string" or type(version) == "table") - if type(version) ~= "table" then version = parse_version(version) end - if type(requested) ~= "table" then requested = parse_version(requested) end + if type(version) ~= "table" then version = deps.parse_version(version) end + if type(requested) ~= "table" then requested = deps.parse_version(requested) end if not version or not requested then return false end for i, ri in ipairs(requested) do @@ -288,14 +290,14 @@ end -- @param constraints table: An array of constraints in table format. -- @return boolean: True if version satisfies all constraints, -- false otherwise. -function match_constraints(version, constraints) +function deps.match_constraints(version, constraints) assert(type(version) == "table") assert(type(constraints) == "table") local ok = true setmetatable(version, version_mt) for _, constr in pairs(constraints) do if type(constr.version) == "string" then - constr.version = parse_version(constr.version) + constr.version = deps.parse_version(constr.version) end local constr_version, constr_op = constr.version, constr.op setmetatable(constr_version, version_mt) @@ -344,8 +346,8 @@ local function match_dep(dep, blacklist, deps_mode) end local candidates = {} for _, vstring in ipairs(versions) do - local version = parse_version(vstring) - if match_constraints(version, dep.constraints) then + local version = deps.parse_version(vstring) + if deps.match_constraints(version, dep.constraints) then table.insert(candidates, version) end end @@ -371,7 +373,7 @@ end -- parsed as tables; and a table of "no-upgrade" missing dependencies -- (to be used in plugin modules so that a plugin does not force upgrade of -- its parent application). -function match_deps(rockspec, blacklist, deps_mode) +function deps.match_deps(rockspec, blacklist, deps_mode) assert(type(rockspec) == "table") assert(type(blacklist) == "table" or not blacklist) local matched, missing, no_upgrade = {}, {}, {} @@ -411,24 +413,24 @@ end -- @return boolean or (nil, string, [string]): True if no errors occurred, or -- nil and an error message if any test failed, followed by an optional -- error code. -function fulfill_dependencies(rockspec, deps_mode) +function deps.fulfill_dependencies(rockspec, deps_mode) local search = require("luarocks.search") local install = require("luarocks.install") if rockspec.supported_platforms then - if not platforms_set then - platforms_set = values_set(cfg.platforms) + if not deps.platforms_set then + deps.platforms_set = values_set(cfg.platforms) end local supported = nil for _, plat in pairs(rockspec.supported_platforms) do local neg, plat = plat:match("^(!?)(.*)") if neg == "!" then - if platforms_set[plat] then + if deps.platforms_set[plat] then return nil, "This rockspec for "..rockspec.package.." does not support "..plat.." platforms." end else - if platforms_set[plat] then + if deps.platforms_set[plat] then supported = true else if supported == nil then @@ -443,22 +445,22 @@ function fulfill_dependencies(rockspec, deps_mode) end end - local _, missing, no_upgrade = match_deps(rockspec, nil, deps_mode) + local _, missing, no_upgrade = deps.match_deps(rockspec, nil, deps_mode) if next(no_upgrade) then util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") for _, dep in pairs(no_upgrade) do - util.printerr(show_dep(dep)) + util.printerr(deps.show_dep(dep)) end if next(missing) then for _, dep in pairs(missing) do - util.printerr(show_dep(dep)) + util.printerr(deps.show_dep(dep)) end end util.printerr() for _, dep in pairs(no_upgrade) do util.printerr("This version of "..rockspec.name.." is designed for use with") - util.printerr(show_dep(dep)..", but is configured to avoid upgrading it") + util.printerr(deps.show_dep(dep)..", but is configured to avoid upgrading it") util.printerr("automatically. Please upgrade "..dep.name.." with") util.printerr(" luarocks install "..dep.name) util.printerr("or choose an older version of "..rockspec.name.." with") @@ -471,7 +473,7 @@ function fulfill_dependencies(rockspec, deps_mode) util.printerr() util.printerr("Missing dependencies for "..rockspec.name..":") for _, dep in pairs(missing) do - util.printerr(show_dep(dep)) + util.printerr(deps.show_dep(dep)) end util.printerr() @@ -480,7 +482,7 @@ function fulfill_dependencies(rockspec, deps_mode) if not match_dep(dep, nil, deps_mode) then local rock = search.find_suitable_rock(dep) if not rock then - return nil, "Could not satisfy dependency: "..show_dep(dep) + return nil, "Could not satisfy dependency: "..deps.show_dep(dep) end local ok, err, errcode = install.run(rock) if not ok then @@ -530,7 +532,7 @@ end -- if "install" is given, do not scan for headers. -- @return boolean or (nil, string): True if no errors occurred, or -- nil and an error message if any test failed. -function check_external_deps(rockspec, mode) +function deps.check_external_deps(rockspec, mode) assert(type(rockspec) == "table") local fs = require("luarocks.fs") @@ -668,7 +670,7 @@ end -- @param name string: Package name. -- @param version string: Package version. -- @return (table, table): The results and a table of missing dependencies. -function scan_deps(results, missing, manifest, name, version, deps_mode) +function deps.scan_deps(results, missing, manifest, name, version, deps_mode) assert(type(results) == "table") assert(type(missing) == "table") assert(type(manifest) == "table") @@ -697,14 +699,14 @@ function scan_deps(results, missing, manifest, name, version, deps_mode) else rockspec = { dependencies = deplist } end - local matched, failures = match_deps(rockspec, nil, deps_mode) + local matched, failures = deps.match_deps(rockspec, nil, deps_mode) results[name] = results for _, match in pairs(matched) do - results, missing = scan_deps(results, missing, manifest, match.name, match.version, deps_mode) + results, missing = deps.scan_deps(results, missing, manifest, match.name, match.version, deps_mode) end if next(failures) then for _, failure in pairs(failures) do - missing[show_dep(failure)] = "failed" + missing[deps.show_dep(failure)] = "failed" end end results[name] = version @@ -718,11 +720,11 @@ local valid_deps_modes = { none = true, } -function check_deps_mode_flag(flag) +function deps.check_deps_mode_flag(flag) return valid_deps_modes[flag] end -function get_deps_mode(flags) +function deps.get_deps_mode(flags) if flags["deps-mode"] then return flags["deps-mode"] else @@ -730,6 +732,8 @@ function get_deps_mode(flags) end end -function deps_mode_to_flag(deps_mode) +function deps.deps_mode_to_flag(deps_mode) return "--deps-mode="..deps_mode end + +return deps diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index 1f3b5c3d..2ef9881e 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -1,14 +1,16 @@ --- Generic utilities for handling pathnames. -module("luarocks.dir", package.seeall) +--module("luarocks.dir", package.seeall) +local dir = {} +package.loaded["luarocks.dir"] = dir -separator = "/" +dir.separator = "/" --- Strip the path off a path+filename. -- @param pathname string: A path+name, such as "/a/b/c" -- or "\a\b\c". -- @return string: The filename without its path, such as "c". -function base_name(pathname) +function dir.base_name(pathname) assert(type(pathname) == "string") local base = pathname:gsub("[/\\]*$", ""):match(".*[/\\]([^/\\]*)") @@ -20,7 +22,7 @@ end -- @return string: The filename without its path, such as "/a/b". -- For entries such as "/a/b/", "/a" is returned. If there are -- no directory separators in input, "" is returned. -function dir_name(pathname) +function dir.dir_name(pathname) assert(type(pathname) == "string") return (pathname:gsub("/*$", ""):match("(.*)[/]+[^/]*")) or "" end @@ -34,7 +36,7 @@ end -- @param ... strings representing directories -- @return string: a string with a platform-specific representation -- of the path. -function path(...) +function dir.path(...) local t = {...} while t[1] == "" do table.remove(t, 1) @@ -47,7 +49,7 @@ end -- For local pathnames, "file" is returned as the protocol. -- @param url string: an URL or a local pathname. -- @return string, string: the protocol, and the pathname without the protocol. -function split_url(url) +function dir.split_url(url) assert(type(url) == "string") local protocol, pathname = url:match("^([^:]*)://(.*)") @@ -63,9 +65,11 @@ end -- forward slashes are used, removing trailing and double slashes -- @param url string: an URL or a local pathname. -- @return string: Normalized result. -function normalize(name) - local protocol, pathname = split_url(name) +function dir.normalize(name) + local protocol, pathname = dir.split_url(name) pathname = pathname:gsub("\\", "/"):gsub("(.)/*$", "%1"):gsub("//", "/") if protocol ~= "file" then pathname = protocol .."://"..pathname end return pathname end + +return dir diff --git a/src/luarocks/doc.lua b/src/luarocks/doc.lua index 324bf028..6dee1069 100644 --- a/src/luarocks/doc.lua +++ b/src/luarocks/doc.lua @@ -1,7 +1,9 @@ --- Module implementing the LuaRocks "doc" command. -- Shows documentation for an installed rock. -module("luarocks.doc", package.seeall) +--module("luarocks.doc", package.seeall) +local doc = {} +package.loaded["luarocks.doc"] = doc local util = require("luarocks.util") local show = require("luarocks.show") @@ -11,9 +13,9 @@ local fetch = require("luarocks.fetch") local fs = require("luarocks.fs") local download = require("luarocks.download") -help_summary = "Shows documentation for an installed rock." +doc.help_summary = "Shows documentation for an installed rock." -help = [[ +doc.help = [[ is an existing package name. Without any flags, tries to load the documentation using a series of heuristics. @@ -56,7 +58,7 @@ end -- @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(...) +function doc.run(...) local flags, name, version = util.parse_flags(...) if not name then return nil, "Argument missing. "..util.see_help("doc") @@ -150,3 +152,5 @@ function run(...) return true end + +return doc diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index d0f672f2..74ed40e9 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -1,7 +1,9 @@ --- Module implementing the luarocks "download" command. -- Download a rock from the repository. -module("luarocks.download", package.seeall) +--module("luarocks.download", package.seeall) +local download = {} +package.loaded["luarocks.download"] = download local util = require("luarocks.util") local path = require("luarocks.path") @@ -10,10 +12,10 @@ local search = require("luarocks.search") local fs = require("luarocks.fs") local dir = require("luarocks.dir") -help_summary = "Download a specific rock file from a rocks server." -help_arguments = "[--all] [--arch= | --source | --rockspec] [ []]" +download.help_summary = "Download a specific rock file from a rocks server." +download.help_arguments = "[--all] [--arch= | --source | --rockspec] [ []]" -help = [[ +download.help = [[ --all Download all files if there are multiple matches. --source Download .src.rock if available. --rockspec Download .rockspec if available. @@ -34,7 +36,7 @@ local function get_file(filename) end end -function download(arch, name, version, all) +function download.download(arch, name, version, all) local results, err local query = search.make_query(name, version) if arch then query.arch = arch end @@ -79,7 +81,7 @@ end -- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function run(...) +function download.run(...) local flags, name, version = util.parse_flags(...) assert(type(version) == "string" or not version) @@ -98,6 +100,8 @@ function run(...) arch = flags["arch"] end - local dl, err = download(arch, name, version, flags["all"]) + local dl, err = download.download(arch, name, version, flags["all"]) return dl and true, err end + +return download diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 3448473f..1d84b480 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -1,6 +1,8 @@ --- Functions related to fetching and loading local and remote files. -module("luarocks.fetch", package.seeall) +--module("luarocks.fetch", package.seeall) +local fetch = {} +package.loaded["luarocks.fetch"] = fetch local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -11,7 +13,7 @@ local persist = require("luarocks.persist") local util = require("luarocks.util") local cfg = require("luarocks.cfg") -function is_basic_protocol(protocol, remote) +function fetch.is_basic_protocol(protocol, remote) return protocol == "http" or protocol == "https" or protocol == "ftp" or (not remote and protocol == "file") end @@ -27,14 +29,14 @@ end -- @return string or (nil, string, [string]): the absolute local pathname for the -- fetched file, or nil and a message in case of errors, followed by -- an optional error code. -function fetch_url(url, filename, cache) +function fetch.fetch_url(url, filename, cache) assert(type(url) == "string") assert(type(filename) == "string" or not filename) local protocol, pathname = dir.split_url(url) if protocol == "file" then return fs.absolute_name(pathname) - elseif is_basic_protocol(protocol, true) then + elseif fetch.is_basic_protocol(protocol, true) then local ok, filename = fs.download(url, filename, cache) if not ok then return nil, "Failed downloading "..url..(filename and " - "..filename or ""), "network" @@ -56,7 +58,7 @@ end -- @return (string, string) or (nil, string, [string]): absolute local pathname of -- the fetched file and temporary directory name; or nil and an error message -- followed by an optional error code -function fetch_url_at_temp_dir(url, tmpname, filename) +function fetch.fetch_url_at_temp_dir(url, tmpname, filename) assert(type(url) == "string") assert(type(tmpname) == "string") assert(type(filename) == "string" or not filename) @@ -77,7 +79,7 @@ function fetch_url_at_temp_dir(url, tmpname, filename) util.schedule_function(fs.delete, temp_dir) local ok, err = fs.change_dir(temp_dir) if not ok then return nil, err end - local file, err, errcode = fetch_url(url, filename) + local file, err, errcode = fetch.fetch_url(url, filename) fs.pop_dir() if not file then return nil, "Error fetching file: "..err, errcode @@ -98,11 +100,11 @@ end -- be nil if not found), or nil followed by an error message. -- The inferred dir is returned first to avoid confusion with errors, -- because it is never nil. -function find_base_dir(file, temp_dir, src_url, src_dir) +function fetch.find_base_dir(file, temp_dir, src_url, src_dir) local ok, err = fs.change_dir(temp_dir) if not ok then return nil, err end fs.unpack_archive(file) - local inferred_dir = src_dir or url_to_base_dir(src_url) + local inferred_dir = src_dir or fetch.url_to_base_dir(src_url) local found_dir = nil if fs.exists(inferred_dir) then found_dir = inferred_dir @@ -126,13 +128,13 @@ end -- a permanent destination. -- @return string or (nil, string, [string]): the directory containing the contents -- of the unpacked rock. -function fetch_and_unpack_rock(rock_file, dest) +function fetch.fetch_and_unpack_rock(rock_file, dest) assert(type(rock_file) == "string") assert(type(dest) == "string" or not dest) local name = dir.base_name(rock_file):match("(.*)%.[^.]*%.rock") - local rock_file, err, errcode = fetch_url_at_temp_dir(rock_file,"luarocks-rock-"..name) + local rock_file, err, errcode = fetch.fetch_url_at_temp_dir(rock_file,"luarocks-rock-"..name) if not rock_file then return nil, "Could not fetch rock file: " .. err, errcode end @@ -161,7 +163,7 @@ function fetch_and_unpack_rock(rock_file, dest) return unpack_dir end -function url_to_base_dir(url) +function fetch.url_to_base_dir(url) local base = dir.base_name(url) return base:gsub("%.[^.]*$", ""):gsub("%.tar$", "") end @@ -173,7 +175,7 @@ end -- rockspec. -- @return table or (nil, string): A table representing the rockspec -- or nil followed by an error message. -function load_local_rockspec(filename, quick) +function fetch.load_local_rockspec(filename, quick) assert(type(filename) == "string") filename = fs.absolute_name(filename) local rockspec, err = persist.load_into_table(filename) @@ -216,7 +218,7 @@ function load_local_rockspec(filename, quick) end local protocol, pathname = dir.split_url(rockspec.source.url) - if is_basic_protocol(protocol) then + if fetch.is_basic_protocol(protocol) then rockspec.source.file = rockspec.source.file or dir.base_name(rockspec.source.url) end rockspec.source.protocol, rockspec.source.pathname = protocol, pathname @@ -232,7 +234,7 @@ function load_local_rockspec(filename, quick) rockspec.local_filename = filename local filebase = rockspec.source.file or rockspec.source.url - local base = url_to_base_dir(filebase) + local base = fetch.url_to_base_dir(filebase) rockspec.source.dir = rockspec.source.dir or rockspec.source.module or ((filebase:match("%.lua$") or filebase:match("%.c$")) and ".") @@ -264,7 +266,7 @@ end -- a temporary dir is created. -- @return table or (nil, string, [string]): A table representing the rockspec -- or nil followed by an error message and optional error code. -function load_rockspec(filename, location) +function fetch.load_rockspec(filename, location) assert(type(filename) == "string") local name @@ -282,16 +284,16 @@ function load_rockspec(filename, location) if location then local ok, err = fs.change_dir(location) if not ok then return nil, err end - filename, err = fetch_url(filename) + filename, err = fetch.fetch_url(filename) fs.pop_dir() else - filename, err, errcode = fetch_url_at_temp_dir(filename,"luarocks-rockspec-"..name) + filename, err, errcode = fetch.fetch_url_at_temp_dir(filename,"luarocks-rockspec-"..name) end if not filename then return nil, err, errcode end - return load_local_rockspec(filename) + return fetch.load_local_rockspec(filename) end --- Download sources for building a rock using the basic URL downloader. @@ -303,7 +305,7 @@ end -- @return (string, string) or (nil, string, [string]): The absolute pathname of -- the fetched source tarball and the temporary directory created to -- store it; or nil and an error message and optional error code. -function get_sources(rockspec, extract, dest_dir) +function fetch.get_sources(rockspec, extract, dest_dir) assert(type(rockspec) == "table") assert(type(extract) == "boolean") assert(type(dest_dir) == "string" or not dest_dir) @@ -315,11 +317,11 @@ function get_sources(rockspec, extract, dest_dir) if dest_dir then local ok, err = fs.change_dir(dest_dir) if not ok then return nil, err, "dest_dir" end - source_file, err, errcode = fetch_url(url, filename) + source_file, err, errcode = fetch.fetch_url(url, filename) fs.pop_dir() store_dir = dest_dir else - source_file, store_dir, errcode = fetch_url_at_temp_dir(url, "luarocks-source-"..name, filename) + source_file, store_dir, errcode = fetch.fetch_url_at_temp_dir(url, "luarocks-source-"..name, filename) end if not source_file then return nil, err or store_dir, errcode @@ -350,14 +352,14 @@ end -- @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 fetch_sources(rockspec, extract, dest_dir) +function fetch.fetch_sources(rockspec, extract, dest_dir) assert(type(rockspec) == "table") assert(type(extract) == "boolean") assert(type(dest_dir) == "string" or not dest_dir) local protocol = rockspec.source.protocol local ok, proto - if is_basic_protocol(protocol) then + if fetch.is_basic_protocol(protocol) then proto = require("luarocks.fetch") else ok, proto = pcall(require, "luarocks.fetch."..protocol:gsub("[+-]", "_")) @@ -377,3 +379,5 @@ function fetch_sources(rockspec, extract, dest_dir) end return proto.get_sources(rockspec, extract, dest_dir) end + +return fetch diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index b281eb14..72e11c09 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua @@ -7,7 +7,9 @@ local pairs = pairs -module("luarocks.fs", package.seeall) +--module("luarocks.fs", package.seeall) +local fs = {} +package.loaded["luarocks.fs"] = fs local cfg = require("luarocks.cfg") @@ -15,7 +17,7 @@ local pack = table.pack or function(...) return { n = select("#", ...), ... } en local unpack = table.unpack or unpack local old_popen, old_exec -_M.verbose = function() -- patch io.popen and os.execute to display commands in verbose mode +fs.verbose = function() -- patch io.popen and os.execute to display commands in verbose mode if old_popen or old_exec then return end old_popen = io.popen io.popen = function(one, two) @@ -38,12 +40,12 @@ _M.verbose = function() -- patch io.popen and os.execute to display commands return unpack(code, 1, code.n) end end -if cfg.verbose then _M.verbose() end +if cfg.verbose then fs.verbose() end local function load_fns(fs_table) for name, fn in pairs(fs_table) do - if not _M[name] then - _M[name] = fn + if not fs[name] then + fs[name] = fn end end end @@ -67,3 +69,5 @@ load_fns(fs_lua) local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") if ok and fs_plat_tools then load_fns(fs_plat_tools) end + +return fs diff --git a/src/luarocks/index.lua b/src/luarocks/index.lua index 1ce66f70..116bdfd2 100644 --- a/src/luarocks/index.lua +++ b/src/luarocks/index.lua @@ -1,6 +1,8 @@ --- Module which builds the index.html page to be used in rocks servers. -module("luarocks.index", package.seeall) +--module("luarocks.index", package.seeall) +local index = {} +package.loaded["luarocks.index"] = index local util = require("luarocks.util") local fs = require("luarocks.fs") @@ -95,7 +97,7 @@ local index_footer_end = [[ ]] -function format_external_dependencies(rockspec) +function index.format_external_dependencies(rockspec) if rockspec.external_dependencies then local deplist = {} local listed_set = {} @@ -123,7 +125,7 @@ function format_external_dependencies(rockspec) end end -function make_index(repo) +function index.make_index(repo) if not fs.is_dir(repo) then return nil, "Cannot access repository at "..repo end @@ -162,7 +164,7 @@ function make_index(repo) detailed = descript.detailed or "", license = descript.license or "N/A", homepage = descript.homepage and ('| project homepage') or "", - externaldependencies = format_external_dependencies(rockspec) + externaldependencies = index.format_external_dependencies(rockspec) } vars.detailed = vars.detailed:gsub("\n\n", "

"):gsub("%s+", " ") vars.detailed = vars.detailed:gsub("(https?://[a-zA-Z0-9%.%%-_%+%[%]=%?&/$@;:]+)", '%1') @@ -181,3 +183,5 @@ function make_index(repo) out:write(index_footer_end) out:close() end + +return index diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 68b7c125..7678c0cc 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -1,6 +1,8 @@ --- Module implementing the LuaRocks "install" command. -- Installs binary rocks. -module("luarocks.install", package.seeall) +--module("luarocks.install", package.seeall) +local install = {} +package.loaded["luarocks.install"] = install local path = require("luarocks.path") local repos = require("luarocks.repos") @@ -12,11 +14,11 @@ local manif = require("luarocks.manif") local remove = require("luarocks.remove") local cfg = require("luarocks.cfg") -help_summary = "Install a rock." +install.help_summary = "Install a rock." -help_arguments = "{| []}" +install.help_arguments = "{| []}" -help = [[ +install.help = [[ Argument may be the name of a rock to be fetched from a repository or a filename of a locally available rock. @@ -34,7 +36,7 @@ or a filename of a locally available rock. -- "order" for all trees with priority >= the current default, "none" for no trees. -- @return (string, string) or (nil, string, [string]): Name and version of -- installed rock if succeeded or nil and an error message followed by an error code. -function install_binary_rock(rock_file, deps_mode) +function install.install_binary_rock(rock_file, deps_mode) assert(type(rock_file) == "string") local name, version, arch = path.parse_name(rock_file) @@ -117,7 +119,7 @@ end -- may also be given. -- @return boolean or (nil, string, exitcode): True if installation was -- successful, nil and an error message otherwise. exitcode is optionally returned. -function run(...) +function install.run(...) local flags, name, version = util.parse_flags(...) if type(name) ~= "string" then return nil, "Argument missing. "..util.see_help("install") @@ -131,7 +133,7 @@ function run(...) local build = require("luarocks.build") return build.run(name, util.forward_flags(flags, "local", "keep", "deps-mode")) elseif name:match("%.rock$") then - ok, err = install_binary_rock(name, deps.get_deps_mode(flags)) + ok, err = install.install_binary_rock(name, deps.get_deps_mode(flags)) if not ok then return nil, err end local name, version = ok, err if (not flags["keep"]) and not cfg.keep_other_versions then @@ -147,7 +149,7 @@ function run(...) elseif type(results) == "string" then local url = results util.printout("Installing "..url.."...") - return run(url, util.forward_flags(flags)) + return install.run(url, util.forward_flags(flags)) else util.printout() util.printerr("Could not determine which rock to install.") @@ -157,3 +159,5 @@ function run(...) end end end + +return install diff --git a/src/luarocks/lint.lua b/src/luarocks/lint.lua index e3bf34b5..091c8de4 100644 --- a/src/luarocks/lint.lua +++ b/src/luarocks/lint.lua @@ -1,22 +1,24 @@ --- Module implementing the LuaRocks "lint" command. -- Utility function that checks syntax of the rockspec. -module("luarocks.lint", package.seeall) +--module("luarocks.lint", package.seeall) +local lint = {} +package.loaded["luarocks.lint"] = lint local util = require("luarocks.util") local download = require("luarocks.download") local fetch = require("luarocks.fetch") -help_summary = "Check syntax of a rockspec." -help_arguments = "" -help = [[ +lint.help_summary = "Check syntax of a rockspec." +lint.help_arguments = "" +lint.help = [[ This is a utility function that checks the syntax of a rockspec. It returns success or failure if the text of a rockspec is syntactically correct. ]] -function run(...) +function lint.run(...) local flags, input = util.parse_flags(...) if not input then @@ -51,3 +53,5 @@ function run(...) return ok, ok or filename.." failed consistency checks." end + +return lint diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua index 6081ed43..319909d3 100644 --- a/src/luarocks/list.lua +++ b/src/luarocks/list.lua @@ -1,16 +1,18 @@ --- Module implementing the LuaRocks "list" command. -- Lists currently installed rocks. -module("luarocks.list", package.seeall) +--module("luarocks.list", package.seeall) +local list = {} +package.loaded["luarocks.list"] = list local search = require("luarocks.search") local cfg = require("luarocks.cfg") local util = require("luarocks.util") local path = require("luarocks.path") -help_summary = "Lists currently installed rocks." -help_arguments = "[--porcelain] " -help = [[ +list.help_summary = "Lists currently installed rocks." +list.help_arguments = "[--porcelain] " +list.help = [[ is a substring of a rock name to filter by. --porcelain Produce machine-friendly output. @@ -20,7 +22,7 @@ help = [[ -- @param filter string or nil: A substring of a rock name to filter by. -- @param version string or nil: a version may also be passed. -- @return boolean: True if succeeded, nil on errors. -function run(...) +function list.run(...) local flags, filter, version = util.parse_flags(...) local results = {} local query = search.make_query(filter and filter:lower() or "", version) @@ -36,3 +38,5 @@ function run(...) search.print_results(results, flags["porcelain"]) return true end + +return list diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index d2fa4859..1fa15c5e 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -9,19 +9,21 @@ local global_env = _G local package, require, ipairs, pairs, table, type, next, unpack, tostring, error = package, require, ipairs, pairs, table, type, next, unpack, tostring, error -module("luarocks.loader") +--module("luarocks.loader") +local loader = {} +package.loaded["luarocks.loader"] = loader local path = require("luarocks.path") local manif_core = require("luarocks.manif_core") local deps = require("luarocks.deps") local cfg = require("luarocks.cfg") -context = {} +loader.context = {} -- Contains a table when rocks trees are loaded, -- or 'false' to indicate rocks trees failed to load. -- 'nil' indicates rocks trees were not attempted to be loaded yet. -rocks_trees = nil +loader.rocks_trees = nil local function load_rocks_trees() local any_ok = false @@ -34,10 +36,10 @@ local function load_rocks_trees() end end if not any_ok then - rocks_trees = false + loader.rocks_trees = false return false end - rocks_trees = trees + loader.rocks_trees = trees return true end @@ -45,20 +47,20 @@ end -- chain for loading modules. -- @param name string: The name of an installed rock. -- @param version string: The version of the rock, in string format -function add_context(name, version) +function loader.add_context(name, version) -- assert(type(name) == "string") -- assert(type(version) == "string") - if context[name] then + if loader.context[name] then return end - context[name] = version + loader.context[name] = version - if not rocks_trees and not load_rocks_trees() then + if not loader.rocks_trees and not load_rocks_trees() then return nil end - for _, tree in ipairs(rocks_trees) do + for _, tree in ipairs(loader.rocks_trees) do local manifest = tree.manifest local pkgdeps @@ -71,12 +73,12 @@ function add_context(name, version) for _, dep in ipairs(pkgdeps) do local pkg, constraints = dep.name, dep.constraints - for _, tree in ipairs(rocks_trees) do + for _, tree in ipairs(loader.rocks_trees) do local entries = tree.manifest.repository[pkg] if entries then for version, pkgs in pairs(entries) do if (not constraints) or deps.match_constraints(deps.parse_version(version), constraints) then - add_context(pkg, version) + loader.add_context(pkg, version) end end end @@ -107,9 +109,9 @@ end -- @return table or (nil, string): The module table as returned by some other loader, -- or nil followed by an error message if no other loader managed to load the module. local function call_other_loaders(module, name, version, module_name) - for i, loader in ipairs(package.loaders) do - if loader ~= luarocks_loader then - local results = { loader(module_name) } + for i, a_loader in ipairs(package.loaders) do + if a_loader ~= loader.luarocks_loader then + local results = { a_loader(module_name) } if type(results[1]) == "function" then return unpack(results) end @@ -133,12 +135,12 @@ local function select_module(module, filter_module_name) --assert(type(module) == "string") --assert(type(filter_module_name) == "function") - if not rocks_trees and not load_rocks_trees() then + if not loader.rocks_trees and not load_rocks_trees() then return nil end local providers = {} - for _, tree in ipairs(rocks_trees) do + for _, tree in ipairs(loader.rocks_trees) do local entries = tree.manifest.modules[module] if entries then for i, entry in ipairs(entries) do @@ -148,7 +150,7 @@ local function select_module(module, filter_module_name) 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) - if context[name] == version then + if loader.context[name] == version then return name, version, module_name end version = deps.parse_version(version) @@ -184,7 +186,7 @@ end --- Return the pathname of the file that would be loaded for a module. -- @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 which(module) +function loader.which(module) local name, version, module_name = select_module(module, path.which_i) return module_name end @@ -198,14 +200,16 @@ end -- @return table: The module table (typically), like in plain -- require(). See require() -- in the Lua reference manual for details. -function luarocks_loader(module) +function loader.luarocks_loader(module) local name, version, module_name = pick_module(module) if not name then return "No LuaRocks module found for "..module else - add_context(name, version) + loader.add_context(name, version) return call_other_loaders(module, name, version, module_name) end end -table.insert(global_env.package.loaders, 1, luarocks_loader) +table.insert(global_env.package.loaders, 1, loader.luarocks_loader) + +return loader diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 541d6a84..1dfe6473 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -3,7 +3,9 @@ -- Builds sources in the current directory, but unlike "build", -- it does not fetch sources, etc., assuming everything is -- available in the current directory. -module("luarocks.make", package.seeall) +--module("luarocks.make", package.seeall) +local make = {} +package.loaded["luarocks.make"] = make local build = require("luarocks.build") local fs = require("luarocks.fs") @@ -14,9 +16,9 @@ local pack = require("luarocks.pack") local remove = require("luarocks.remove") local deps = require("luarocks.deps") -help_summary = "Compile package in current directory using a rockspec." -help_arguments = "[--pack-binary-rock] []" -help = [[ +make.help_summary = "Compile package in current directory using a rockspec." +make.help_arguments = "[--pack-binary-rock] []" +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, @@ -46,7 +48,7 @@ To install rocks, you'll normally want to use the "install" and -- @param name string: A local rockspec. -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an -- error message otherwise. exitcode is optionally returned. -function run(...) +function make.run(...) local flags, rockspec = util.parse_flags(...) assert(type(rockspec) == "string" or not rockspec) @@ -87,3 +89,5 @@ function run(...) return name, version end end + +return make diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua index 53fffc88..b6e65bf8 100644 --- a/src/luarocks/make_manifest.lua +++ b/src/luarocks/make_manifest.lua @@ -1,7 +1,9 @@ --- Module implementing the luarocks-admin "make_manifest" command. -- Compile a manifest file for a repository. -module("luarocks.make_manifest", package.seeall) +--module("luarocks.make_manifest", package.seeall) +local make_manifest = {} +package.loaded["luarocks.make_manifest"] = make_manifest local manif = require("luarocks.manif") local index = require("luarocks.index") @@ -11,9 +13,9 @@ local deps = require("luarocks.deps") local fs = require("luarocks.fs") local dir = require("luarocks.dir") -help_summary = "Compile a manifest file for a repository." +make_manifest.help_summary = "Compile a manifest file for a repository." -help = [[ +make_manifest.help = [[ , if given, is a local repository pathname. --local-tree If given, do not write versioned versions of the manifest file. @@ -25,7 +27,7 @@ help = [[ -- the default local repository configured as cfg.rocks_dir is used. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. -function run(...) +function make_manifest.run(...) local flags, repo = util.parse_flags(...) assert(type(repo) == "string" or not repo) @@ -49,3 +51,5 @@ function run(...) end return ok, err end + +return make_manifest diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index c14200df..d160d2db 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -2,7 +2,9 @@ -- Manifest files describe the contents of a LuaRocks tree or server. -- They are loaded into manifest tables, which are then used for -- performing searches, matching dependencies, etc. -module("luarocks.manif", package.seeall) +--module("luarocks.manif", package.seeall) +local manif = {} +package.loaded["luarocks.manif"] = manif local manif_core = require("luarocks.manif_core") local persist = require("luarocks.persist") @@ -16,7 +18,7 @@ local path = require("luarocks.path") local repos = require("luarocks.repos") local deps = require("luarocks.deps") -rock_manifest_cache = {} +manif.rock_manifest_cache = {} --- Commit a table to disk in given local path. -- @param where string: The directory where the table should be saved. @@ -37,22 +39,22 @@ local function save_table(where, name, tbl) return ok, err end -function load_rock_manifest(name, version, root) +function manif.load_rock_manifest(name, version, root) assert(type(name) == "string") assert(type(version) == "string") local name_version = name.."/"..version - if rock_manifest_cache[name_version] then - return rock_manifest_cache[name_version].rock_manifest + if manif.rock_manifest_cache[name_version] then + return manif.rock_manifest_cache[name_version].rock_manifest end local pathname = path.rock_manifest_file(name, version, root) local rock_manifest = persist.load_into_table(pathname) if not rock_manifest then return nil end - rock_manifest_cache[name_version] = rock_manifest + manif.rock_manifest_cache[name_version] = rock_manifest return rock_manifest.rock_manifest end -function make_rock_manifest(name, version) +function manif.make_rock_manifest(name, version) local install_dir = path.install_dir(name, version) local rock_manifest = path.rock_manifest_file(name, version) local tree = {} @@ -80,7 +82,7 @@ function make_rock_manifest(name, version) end end rock_manifest = { rock_manifest=tree } - rock_manifest_cache[name.."/"..version] = rock_manifest + manif.rock_manifest_cache[name.."/"..version] = rock_manifest save_table(install_dir, "rock_manifest", rock_manifest ) end @@ -105,7 +107,7 @@ end -- @param repo_url string: URL or pathname for the repository. -- @return table or (nil, string, [string]): A table representing the manifest, -- or nil followed by an error message and an optional error code. -function load_manifest(repo_url) +function manif.load_manifest(repo_url) assert(type(repo_url) == "string") if manif_core.manifest_cache[repo_url] then @@ -332,7 +334,7 @@ local function store_results(results, manifest, dep_handler) local entrytable = {} entrytable.arch = entry.arch if entry.arch == "installed" then - local rock_manifest = load_rock_manifest(name, version) + local rock_manifest = manif.load_rock_manifest(name, version) if not rock_manifest then return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks 2 tree?" end @@ -363,7 +365,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, remote) +function manif.make_manifest(repo, deps_mode, remote) assert(type(repo) == "string") assert(type(deps_mode) == "string") @@ -418,7 +420,7 @@ end -- "none" for using the default dependency mode from the configuration. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. -function update_manifest(name, version, repo, deps_mode) +function manif.update_manifest(name, version, repo, deps_mode) assert(type(name) == "string") assert(type(version) == "string") repo = path.rocks_dir(repo or cfg.root_dir) @@ -428,14 +430,14 @@ function update_manifest(name, version, repo, deps_mode) util.printout("Updating manifest for "..repo) - local manifest, err = load_manifest(repo) + local manifest, err = manif.load_manifest(repo) if not manifest then util.printerr("No existing manifest. Attempting to rebuild...") - local ok, err = make_manifest(repo, deps_mode) + local ok, err = manif.make_manifest(repo, deps_mode) if not ok then return nil, err end - manifest, err = load_manifest(repo) + manifest, err = manif.load_manifest(repo) if not manifest then return nil, err end @@ -452,7 +454,7 @@ function update_manifest(name, version, repo, deps_mode) return save_table(repo, "manifest", manifest) end -function zip_manifests() +function manif.zip_manifests() for ver in util.lua_versions() do local file = "manifest-"..ver local zip = file..".zip" @@ -499,13 +501,13 @@ end -- @param file string: The full path of a deployed file. -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. -- @return string, string: name and version of the provider rock. -function find_current_provider(file, root) +function manif.find_current_provider(file, root) local providers, err = find_providers(file, root) if not providers then return nil, err end return providers[1]:match("([^/]*)/([^/]*)") end -function find_next_provider(file, root) +function manif.find_next_provider(file, root) local providers, err = find_providers(file, root) if not providers then return nil, err end if providers[2] then @@ -514,3 +516,5 @@ function find_next_provider(file, root) return nil end end + +return manif diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua index b9fe8ab9..1a2c111f 100644 --- a/src/luarocks/manif_core.lua +++ b/src/luarocks/manif_core.lua @@ -1,7 +1,9 @@ --- Core functions for querying manifest files. -- This module requires no specific 'fs' functionality. -module("luarocks.manif_core", package.seeall) +--module("luarocks.manif_core", package.seeall) +local manif_core = {} +package.loaded["luarocks.manif_core"] = manif_core local persist = require("luarocks.persist") local type_check = require("luarocks.type_check") @@ -10,14 +12,14 @@ local util = require("luarocks.util") local cfg = require("luarocks.cfg") local path = require("luarocks.path") -manifest_cache = {} +manif_core.manifest_cache = {} --- Back-end function that actually loads the manifest -- and stores it in the manifest cache. -- @param file string: The local filename of the manifest file. -- @param repo_url string: The repository identifier. -- @param quick boolean: If given, skips type checking. -function manifest_loader(file, repo_url, quick) +function manif_core.manifest_loader(file, repo_url, quick) local manifest, err = persist.load_into_table(file) if not manifest then return nil, "Failed loading manifest for "..repo_url..": "..err @@ -30,7 +32,7 @@ function manifest_loader(file, repo_url, quick) end end - manifest_cache[repo_url] = manifest + manif_core.manifest_cache[repo_url] = manifest return manifest end @@ -40,16 +42,16 @@ end -- @param repo_url string: URL or pathname for the repository. -- @return table or (nil, string): A table representing the manifest, -- or nil followed by an error message. -function load_local_manifest(repo_url) +function manif_core.load_local_manifest(repo_url) assert(type(repo_url) == "string") - if manifest_cache[repo_url] then - return manifest_cache[repo_url] + if manif_core.manifest_cache[repo_url] then + return manif_core.manifest_cache[repo_url] end local pathname = dir.path(repo_url, "manifest") - return manifest_loader(pathname, repo_url, true) + return manif_core.manifest_loader(pathname, repo_url, true) end --- Get all versions of a package listed in a manifest file. @@ -60,13 +62,13 @@ end -- or "all", to use all trees. -- @return table: An array of strings listing installed -- versions of a package. -function get_versions(name, deps_mode) +function manif_core.get_versions(name, deps_mode) assert(type(name) == "string") assert(type(deps_mode) == "string") local manifest = {} path.map_trees(deps_mode, function(tree) - local loaded = load_local_manifest(path.rocks_dir(tree)) + local loaded = manif_core.load_local_manifest(path.rocks_dir(tree)) if loaded then util.deep_merge(manifest, loaded) end @@ -78,3 +80,5 @@ function get_versions(name, deps_mode) end return {} end + +return manif_core diff --git a/src/luarocks/new_version.lua b/src/luarocks/new_version.lua index 883d2ea9..9ef0cfbb 100644 --- a/src/luarocks/new_version.lua +++ b/src/luarocks/new_version.lua @@ -1,7 +1,9 @@ --- 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) +--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") @@ -10,9 +12,9 @@ local persist = require("luarocks.persist") local fs = require("luarocks.fs") local type_check = require("luarocks.type_check") -help_summary = "Auto-write a rockspec for a new version of a rock." -help_arguments = "{|} [] []" -help = [[ +new_version.help_summary = "Auto-write a rockspec for a new version of a rock." +new_version.help_arguments = "{|} [] []" +new_version.help = [[ This is a utility function that writes a new rockspec, updating data from a previous one. @@ -102,7 +104,7 @@ local function update_source_section(out_rs, out_name, url, old_ver, new_ver) return true end -function run(...) +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") @@ -163,3 +165,5 @@ function run(...) return true end + +return new_version diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index 0ef7344b..c23cf66a 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -1,7 +1,9 @@ --- Module implementing the LuaRocks "pack" command. -- Creates a rock, packing sources or binaries. -module("luarocks.pack", package.seeall) +--module("luarocks.pack", package.seeall) +local pack = {} +package.loaded["luarocks.pack"] = pack local path = require("luarocks.path") local repos = require("luarocks.repos") @@ -13,9 +15,9 @@ local dir = require("luarocks.dir") local manif = require("luarocks.manif") local search = require("luarocks.search") -help_summary = "Create a rock, packing sources or binaries." -help_arguments = "{| []}" -help = [[ +pack.help_summary = "Create a rock, packing sources or binaries." +pack.help_arguments = "{| []}" +pack.help = [[ Argument may be a rockspec file, for creating a source rock, or the name of an installed package, for creating a binary rock. In the latter case, the app version may be given as a second @@ -154,7 +156,7 @@ local function do_pack_binary_rock(name, version) return rock_file end -function pack_binary_rock(name, version, cmd, ...) +function pack.pack_binary_rock(name, version, cmd, ...) -- The --pack-binary-rock option for "luarocks build" basically performs -- "luarocks build" on a temporary tree and then "luarocks pack". The @@ -188,7 +190,7 @@ end -- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function run(...) +function pack.run(...) local flags, arg, version = util.parse_flags(...) assert(type(version) == "string" or not version) if type(arg) ~= "string" then @@ -208,3 +210,5 @@ function run(...) return true end end + +return pack diff --git a/src/luarocks/persist.lua b/src/luarocks/persist.lua index ca6a1f8c..47afc81c 100644 --- a/src/luarocks/persist.lua +++ b/src/luarocks/persist.lua @@ -3,7 +3,9 @@ -- saving tables into files. -- Implemented separately to avoid interdependencies, -- as it is used in the bootstrapping stage of the cfg module. -module("luarocks.persist", package.seeall) +--module("luarocks.persist", package.seeall) +local persist = {} +package.loaded["luarocks.persist"] = persist local util = require("luarocks.util") @@ -14,7 +16,7 @@ local util = require("luarocks.util") -- loaded values. -- @return table or (nil, string): a table with the file's assignments -- as fields, or nil and a message in case of errors. -function load_into_table(filename, tbl) +function persist.load_into_table(filename, tbl) assert(type(filename) == "string") assert(type(tbl) == "table" or not tbl) @@ -32,7 +34,7 @@ function load_into_table(filename, tbl) if _VERSION == "Lua 5.1" then -- Lua 5.1 chunk, err = loadfile(filename) if chunk then - setfenv(chunk, result) + persist.setfenv(chunk, result) ran, err = pcall(chunk) end else -- Lua 5.2 @@ -156,7 +158,7 @@ end -- @param tbl table: the table containing the data to be written -- @param field_order table: an optional array indicating the order of top-level fields. -- @return string -function save_from_table_to_string(tbl, field_order) +function persist.save_from_table_to_string(tbl, field_order) local out = {buffer = {}} function out:write(data) table.insert(self.buffer, data) end write_table(out, tbl, field_order) @@ -172,7 +174,7 @@ end -- @param field_order table: an optional array indicating the order of top-level fields. -- @return boolean or (nil, string): true if successful, or nil and a -- message in case of errors. -function save_from_table(filename, tbl, field_order) +function persist.save_from_table(filename, tbl, field_order) local out = io.open(filename, "w") if not out then return nil, "Cannot create file at "..filename @@ -180,4 +182,6 @@ function save_from_table(filename, tbl, field_order) write_table(out, tbl, field_order) out:close() return true -end \ No newline at end of file +end + +return persist diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua index 8c2164f9..ba9b8705 100644 --- a/src/luarocks/purge.lua +++ b/src/luarocks/purge.lua @@ -1,7 +1,9 @@ --- Module implementing the LuaRocks "purge" command. -- Remove all rocks from a given tree. -module("luarocks.purge", package.seeall) +--module("luarocks.purge", package.seeall) +local purge = {} +package.loaded["luarocks.purge"] = purge local util = require("luarocks.util") local fs = require("luarocks.fs") @@ -13,9 +15,9 @@ local manif = require("luarocks.manif") local cfg = require("luarocks.cfg") local remove = require("luarocks.remove") -help_summary = "Remove all installed rocks from a tree." -help_arguments = "--tree= [--old-versions]" -help = [[ +purge.help_summary = "Remove all installed rocks from a tree." +purge.help_arguments = "--tree= [--old-versions]" +purge.help = [[ This command removes rocks en masse from a given tree. By default, it removes all rocks from a tree. @@ -29,7 +31,7 @@ assume a default tree. overridden with the flag --force. ]] -function run(...) +function purge.run(...) local flags = util.parse_flags(...) local tree = flags["tree"] @@ -75,3 +77,5 @@ function run(...) end return manif.make_manifest(cfg.rocks_dir, "one") end + +return purge diff --git a/src/luarocks/refresh_cache.lua b/src/luarocks/refresh_cache.lua index 80730375..193e5994 100644 --- a/src/luarocks/refresh_cache.lua +++ b/src/luarocks/refresh_cache.lua @@ -1,20 +1,22 @@ --- Module implementing the luarocks-admin "refresh_cache" command. -module("luarocks.refresh_cache", package.seeall) +--module("luarocks.refresh_cache", package.seeall) +local refresh_cache = {} +package.loaded["luarocks.refresh_cache"] = refresh_cache local util = require("luarocks.util") local cfg = require("luarocks.cfg") local cache = require("luarocks.cache") -help_summary = "Refresh local cache of a remote rocks server." -help_arguments = "[--from=]" -help = [[ +refresh_cache.help_summary = "Refresh local cache of a remote rocks server." +refresh_cache.help_arguments = "[--from=]" +refresh_cache.help = [[ The flag --from indicates which server to use. If not given, the default server set in the upload_server variable from the configuration file is used instead. ]] -function run(...) +function refresh_cache.run(...) local flags = util.parse_flags(...) local server, upload_server = cache.get_upload_server(flags["server"]) if not server then return nil, upload_server end @@ -28,3 +30,5 @@ function run(...) end end + +return refresh_cache diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 8f751a93..595df8f4 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -1,7 +1,9 @@ --- Module implementing the LuaRocks "remove" command. -- Uninstalls rocks. -module("luarocks.remove", package.seeall) +--module("luarocks.remove", package.seeall) +local remove = {} +package.loaded["luarocks.remove"] = remove local search = require("luarocks.search") local deps = require("luarocks.deps") @@ -13,9 +15,9 @@ local cfg = require("luarocks.cfg") local manif = require("luarocks.manif") local fs = require("luarocks.fs") -help_summary = "Uninstall a rock." -help_arguments = "[--force[=fast]] []" -help = [[ +remove.help_summary = "Uninstall a rock." +remove.help_arguments = "[--force[=fast]] []" +remove.help = [[ Argument is the name of a rock to be uninstalled. If a version is not given, try to remove all versions at once. Will only perform the removal if it does not break dependencies. @@ -72,7 +74,7 @@ local function delete_versions(name, versions) return true end -function remove_search_results(results, name, deps_mode, force) +function remove.remove_search_results(results, name, deps_mode, force) local versions = results[name] local version = next(versions) @@ -119,11 +121,11 @@ function remove_search_results(results, name, deps_mode, force) return true end -function remove_other_versions(name, version, force) +function remove.remove_other_versions(name, version, force) local results = {} search.manifest_search(results, cfg.rocks_dir, { name = name, exact_name = true, constraints = {{ op = "~=", version = version}} }) if results[name] then - return remove_search_results(results, name, cfg.deps_mode, force) + return remove.remove_search_results(results, name, cfg.deps_mode, force) end return true end @@ -135,7 +137,7 @@ end -- may also be given. -- @return boolean or (nil, string, exitcode): True if removal was -- successful, nil and an error message otherwise. exitcode is optionally returned. -function run(...) +function remove.run(...) local flags, name, version = util.parse_flags(...) if type(name) ~= "string" then @@ -160,5 +162,7 @@ function run(...) return nil, "Could not find rock '"..name..(version and " "..version or "").."' in local tree." end - return remove_search_results(results, name, deps_mode, flags["force"]) + return remove.remove_search_results(results, name, deps_mode, flags["force"]) end + +return remove diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 7ad75846..17456593 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -1,6 +1,8 @@ --- Functions for managing the repository on disk. -module("luarocks.repos", package.seeall) +--module("luarocks.repos", package.seeall) +local repos = {} +package.loaded["luarocks.repos"] = repos local fs = require("luarocks.fs") local path = require("luarocks.path") @@ -27,7 +29,7 @@ end -- @param version string: package version in string format -- @return boolean: true if a package is installed, -- false otherwise. -function is_installed(name, version) +function repos.is_installed(name, version) assert(type(name) == "string") assert(type(version) == "string") @@ -72,7 +74,7 @@ end -- in "foo.bar" format and values are pathnames in architecture-dependent -- "foo/bar.so" format. If no modules are found or if package or version -- are invalid, an empty table is returned. -function package_modules(package, version) +function repos.package_modules(package, version) assert(type(package) == "string") assert(type(version) == "string") @@ -91,7 +93,7 @@ end -- as strings and values are pathnames in architecture-dependent -- ".../bin/foo" format. If no modules are found or if package or version -- are invalid, an empty table is returned. -function package_commands(package, version) +function repos.package_commands(package, version) assert(type(package) == "string") assert(type(version) == "string") @@ -107,7 +109,7 @@ end -- @param version string: version of an installed rock -- @return boolean: returns true if rock contains platform-specific -- binary executables, or false if it is a pure-Lua rock. -function has_binaries(name, version) +function repos.has_binaries(name, version) assert(type(name) == "string") assert(type(version) == "string") @@ -123,7 +125,7 @@ function has_binaries(name, version) return false end -function run_hook(rockspec, hook_name) +function repos.run_hook(rockspec, hook_name) assert(type(rockspec) == "table") assert(type(hook_name) == "string") @@ -155,11 +157,11 @@ local function install_binary(source, target, name, version) assert(type(target) == "string") if fs.is_lua(source) then - ok, err = fs.wrap_script(source, target, name, version) + repos.ok, repos.err = fs.wrap_script(source, target, name, version) else - ok, err = fs.copy_binary(source, target) + repos.ok, repos.err = fs.copy_binary(source, target) end - return ok, err + return repos.ok, repos.err end local function resolve_conflict(target, deploy_dir, name, version) @@ -178,7 +180,7 @@ local function resolve_conflict(target, deploy_dir, name, version) end end -function should_wrap_bin_scripts(rockspec) +function repos.should_wrap_bin_scripts(rockspec) assert(type(rockspec) == "table") if cfg.wrap_bin_scripts ~= nil then @@ -190,7 +192,7 @@ function should_wrap_bin_scripts(rockspec) return true end -function deploy_files(name, version, wrap_bin_scripts) +function repos.deploy_files(name, version, wrap_bin_scripts) assert(type(name) == "string") assert(type(version) == "string") assert(type(wrap_bin_scripts) == "boolean") @@ -269,7 +271,7 @@ end -- of another version that provides the same module that -- was deleted. This is used during 'purge', as every module -- will be eventually deleted. -function delete_version(name, version, quick) +function repos.delete_version(name, version, quick) assert(type(name) == "string") assert(type(version) == "string") @@ -323,3 +325,5 @@ function delete_version(name, version, quick) end return true end + +return repos diff --git a/src/luarocks/require.lua b/src/luarocks/require.lua index 99177700..902bd1a3 100644 --- a/src/luarocks/require.lua +++ b/src/luarocks/require.lua @@ -1,6 +1,2 @@ --- Retained for compatibility reasons only. Use luarocks.loader instead. -local require, pairs = require, pairs -module("luarocks.require") -for k,v in pairs(require("luarocks.loader")) do - _M[k] = v -end +return require("luarocks.loader") diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 574ada40..53439386 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua @@ -1,7 +1,9 @@ --- Module implementing the LuaRocks "search" command. -- Queries LuaRocks servers. -module("luarocks.search", package.seeall) +--module("luarocks.search", package.seeall) +local search = {} +package.loaded["luarocks.search"] = search local dir = require("luarocks.dir") local path = require("luarocks.path") @@ -10,9 +12,9 @@ local deps = require("luarocks.deps") local cfg = require("luarocks.cfg") local util = require("luarocks.util") -help_summary = "Query the LuaRocks servers." -help_arguments = "[--source] [--binary] { [] | --all }" -help = [[ +search.help_summary = "Query the LuaRocks servers." +search.help_arguments = "[--source] [--binary] { [] | --all }" +search.help = [[ --source Return only rockspecs and source rocks, to be used with the "build" command. --binary Return only pure Lua and binary rocks (rocks that can be used @@ -124,7 +126,7 @@ end -- @param table: The results table, where keys are package names and -- versions are tables matching version strings to an array of servers. -- If a table was given in the "results" parameter, that is the result value. -function disk_search(repo, query, results) +function search.disk_search(repo, query, results) assert(type(repo) == "string") assert(type(query) == "table") assert(type(results) == "table" or not results) @@ -164,7 +166,7 @@ end -- is used. The special value "any" is also recognized, returning all -- matches regardless of architecture. -- @return true or, in case of errors, nil and an error message. -function manifest_search(results, repo, query) +function search.manifest_search(results, repo, query) assert(type(results) == "table") assert(type(repo) == "string") assert(type(query) == "table") @@ -189,7 +191,7 @@ end -- @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. -function search_repos(query) +function search.search_repos(query) assert(type(query) == "table") local results = {} @@ -203,7 +205,7 @@ function search_repos(query) if protocol == "file" then mirror = pathname end - local ok, err, errcode = manifest_search(results, mirror, query) + local ok, err, errcode = search.manifest_search(results, mirror, query) if errcode == "network" then cfg.disabled_servers[repo] = true end @@ -227,7 +229,7 @@ end -- @param name string: The query name. -- @param version string or nil: -- @return table: A query in table format -function make_query(name, version) +function search.make_query(name, version) assert(type(name) == "string") assert(type(version) == "string" or not version) @@ -276,10 +278,10 @@ end -- @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. -function find_suitable_rock(query) +function search.find_suitable_rock(query) assert(type(query) == "table") - local results = search_repos(query) + local results = search.search_repos(query) local first = next(results) if not first then return nil, "No results matching query were found." @@ -300,7 +302,7 @@ end -- @param results table: A table where keys are package names and versions -- are tables matching version strings to an array of rocks servers. -- @param porcelain boolean or nil: A flag to force machine-friendly output. -function print_results(results, porcelain) +function search.print_results(results, porcelain) assert(type(results) == "table") assert(type(porcelain) == "boolean" or not porcelain) @@ -355,14 +357,14 @@ end -- @param name string: A rock name -- @param version string or nil: A version number may also be given. -- @return The result of the action function, or nil and an error message. -function act_on_src_or_rockspec(action, name, version, ...) +function search.act_on_src_or_rockspec(action, name, version, ...) assert(type(action) == "function") assert(type(name) == "string") assert(type(version) == "string" or not version) - local query = make_query(name, version) + local query = search.make_query(name, version) query.arch = "src|rockspec" - local results, err = find_suitable_rock(query) + local results, err = search.find_suitable_rock(query) if type(results) == "string" then return action(results, ...) else @@ -375,7 +377,7 @@ end -- @param version string or nil: a version may also be passed. -- @return boolean or (nil, string): True if build was successful; nil and an -- error message otherwise. -function run(...) +function search.run(...) local flags, name, version = util.parse_flags(...) if flags["all"] then @@ -386,19 +388,21 @@ function run(...) return nil, "Enter name and version or use --all. "..util.see_help("search") end - local query = make_query(name:lower(), version) + local query = search.make_query(name:lower(), version) query.exact_name = false - local results, err = search_repos(query) + local results, err = search.search_repos(query) local porcelain = flags["porcelain"] util.title("Search results:", porcelain, "=") local sources, binaries = split_source_and_binary_results(results) if next(sources) and not flags["binary"] then util.title("Rockspecs and source rocks:", porcelain) - print_results(sources, porcelain) + search.print_results(sources, porcelain) end if next(binaries) and not flags["source"] then util.title("Binary and pure-Lua rocks:", porcelain) - print_results(binaries, porcelain) + search.print_results(binaries, porcelain) end return true end + +return search diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index 36225208..3243c0ce 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -1,6 +1,8 @@ --- Module implementing the LuaRocks "show" command. -- Shows information about an installed rock. -module("luarocks.show", package.seeall) +--module("luarocks.show", package.seeall) +local show = {} +package.loaded["luarocks.show"] = show local search = require("luarocks.search") local cfg = require("luarocks.cfg") @@ -9,9 +11,9 @@ local path = require("luarocks.path") local deps = require("luarocks.deps") local fetch = require("luarocks.fetch") local manif = require("luarocks.manif") -help_summary = "Shows information about an installed rock." +show.help_summary = "Shows information about an installed rock." -help = [[ +show.help = [[ is an existing package name. Without any flags, show all module information. With these flags, return only the desired information: @@ -53,7 +55,7 @@ local function format_text(text) return (table.concat(paragraphs, "\n\n"):gsub("%s$", "")) end -function pick_installed_rock(name, version, tree) +function show.pick_installed_rock(name, version, tree) local results = {} local query = search.make_query(name, version) query.exact_name = true @@ -90,14 +92,14 @@ end -- @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(...) +function show.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"]) + name, version, repo, repo_url = show.pick_installed_rock(name, version, flags["tree"]) if not name then return nil, version end @@ -151,3 +153,5 @@ function run(...) return true end + +return show diff --git a/src/luarocks/tools/patch.lua b/src/luarocks/tools/patch.lua index 4479e642..8df3093d 100644 --- a/src/luarocks/tools/patch.lua +++ b/src/luarocks/tools/patch.lua @@ -559,15 +559,15 @@ local function strip_dirs(filename, strip) return filename end -function patch.apply_patch(patch, strip) +function patch.apply_patch(the_patch, strip) local all_ok = true - local total = #patch.source - for fileno, filename in ipairs(patch.source) do + local total = #the_patch.source + for fileno, filename in ipairs(the_patch.source) do filename = strip_dirs(filename, strip) local continue local f2patch = filename if not exists(f2patch) then - f2patch = strip_dirs(patch.target[fileno], strip) + f2patch = strip_dirs(the_patch.target[fileno], strip) f2patch = fs.absolute_name(f2patch) if not exists(f2patch) then --FIX:if f2patch nil warning(format("source/target file does not exist\n--- %s\n+++ %s", @@ -588,7 +588,7 @@ function patch.apply_patch(patch, strip) info(format("processing %d/%d:\t %s", fileno, total, filename)) -- validate before patching - local hunks = patch.hunks[fileno] + local hunks = the_patch.hunks[fileno] local file = load_file(filename) local hunkno = 1 local hunk = hunks[hunkno] diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 1204c1d9..a78c4848 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua @@ -1,11 +1,13 @@ --- Type-checking functions. -- Functions and definitions for doing a basic lint check on files -- loaded by LuaRocks. -module("luarocks.type_check", package.seeall) +--module("luarocks.type_check", package.seeall) +local type_check = {} +package.loaded["luarocks.type_check"] = type_check local cfg = require("luarocks.cfg") -rockspec_format = "1.0" +type_check.rockspec_format = "1.0" local rockspec_types = { rockspec_format = "string", @@ -73,22 +75,22 @@ local rockspec_types = { } } -rockspec_order = {"rockspec_format", "package", "version", +type_check.rockspec_order = {"rockspec_format", "package", "version", { "source", { "url", "tag", "branch", "md5" } }, { "description", {"summary", "detailed", "homepage", "license" } }, "supported_platforms", "dependencies", "external_dependencies", { "build", {"type", "modules", "copy_directories", "platforms"} }, "hooks"} -function load_extensions() - rockspec_format = "1.1" +function type_check.load_extensions() + type_check.rockspec_format = "1.1" rockspec_types.deploy = { wrap_bin_scripts = true, } end if cfg.use_extensions then - load_extensions() + type_check.load_extensions() end rockspec_types.build.platforms.ANY = rockspec_types.build @@ -269,11 +271,11 @@ end -- mismatches. -- @return boolean or (nil, string): true if type checking -- succeeded, or nil and an error message if it failed. -function type_check_rockspec(rockspec, globals) +function type_check.type_check_rockspec(rockspec, globals) assert(type(rockspec) == "table") if rockspec.rockspec_format then -- relies on global state - load_extensions() + type_check.load_extensions() end local ok, err = check_undeclared_globals(globals, rockspec_types) if not ok then return nil, err end @@ -286,9 +288,11 @@ end -- mismatches. -- @return boolean or (nil, string): true if type checking -- succeeded, or nil and an error message if it failed. -function type_check_manifest(manifest, globals) +function type_check.type_check_manifest(manifest, globals) assert(type(manifest) == "table") local ok, err = check_undeclared_globals(globals, manifest_types) if not ok then return nil, err end return type_check_table(manifest, manifest_types, "") end + +return type_check diff --git a/src/luarocks/unpack.lua b/src/luarocks/unpack.lua index 95762a2c..9204e265 100644 --- a/src/luarocks/unpack.lua +++ b/src/luarocks/unpack.lua @@ -1,7 +1,9 @@ --- Module implementing the LuaRocks "unpack" command. -- Unpack the contents of a rock. -module("luarocks.unpack", package.seeall) +--module("luarocks.unpack", package.seeall) +local unpack = {} +package.loaded["luarocks.unpack"] = unpack local fetch = require("luarocks.fetch") local fs = require("luarocks.fs") @@ -9,9 +11,9 @@ local util = require("luarocks.util") local build = require("luarocks.build") local dir = require("luarocks.dir") -help_summary = "Unpack the contents of a rock." -help_arguments = "[--force] {| []}" -help = [[ +unpack.help_summary = "Unpack the contents of a rock." +unpack.help_arguments = "[--force] {| []}" +unpack.help = [[ Unpacks the contents of a rock in a newly created directory. Argument may be a rock file, or the name of a rock in a rocks server. In the latter case, the app version may be given as a second argument. @@ -145,7 +147,7 @@ end -- version may also be passed. -- @return boolean or (nil, string): true if successful or nil followed -- by an error message. -function run(...) +function unpack.run(...) local flags, name, version = util.parse_flags(...) assert(type(version) == "string" or not version) @@ -160,3 +162,5 @@ function run(...) return search.act_on_src_or_rockspec(run_unpacker, name, version) end end + +return unpack diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua index 15c2c6b7..e6e09c33 100644 --- a/src/luarocks/validate.lua +++ b/src/luarocks/validate.lua @@ -1,6 +1,8 @@ --- Sandboxed test of build/install of all packages in a repository (unfinished and disabled). -module("luarocks.validate", package.seeall) +--module("luarocks.validate", package.seeall) +local validate = {} +package.loaded["luarocks.validate"] = validate local fs = require("luarocks.fs") local dir = require("luarocks.dir") @@ -10,9 +12,9 @@ local build = require("luarocks.build") local install = require("luarocks.install") local util = require("luarocks.util") -help_summary = "Sandboxed test of build/install of all packages in a repository." +validate.help_summary = "Sandboxed test of build/install of all packages in a repository." -help = [[ +validate.help = [[ , if given, is a local repository pathname. ]] @@ -73,7 +75,12 @@ local function validate_rock(file) return ok, err, errcode end -local function validate(repo, flags) +function validate.run(...) + local flags, repo = util.parse_flags(...) + repo = repo or cfg.rocks_dir + + util.printout("Verifying contents of "..repo) + local results = { ok = {} } @@ -149,12 +156,5 @@ local function validate(repo, flags) return true end -function run(...) - local flags, repo = util.parse_flags(...) - repo = repo or cfg.rocks_dir - - util.printout("Verifying contents of "..repo) - - return validate(repo, flags) -end +return validate diff --git a/src/luarocks/write_rockspec.lua b/src/luarocks/write_rockspec.lua index 9cd8f892..a194201d 100644 --- a/src/luarocks/write_rockspec.lua +++ b/src/luarocks/write_rockspec.lua @@ -1,5 +1,7 @@ -module("luarocks.write_rockspec", package.seeall) +--module("luarocks.write_rockspec", package.seeall) +local write_rockspec = {} +package.loaded["luarocks.write_rockspec"] = write_rockspec local dir = require("luarocks.dir") local fetch = require("luarocks.fetch") @@ -9,9 +11,9 @@ local persist = require("luarocks.persist") local type_check = require("luarocks.type_check") local util = require("luarocks.util") -help_summary = "Write a template for a rockspec file." -help_arguments = "[--output= ...] [] [] {|}" -help = [[ +write_rockspec.help_summary = "Write a template for a rockspec file." +write_rockspec.help_arguments = "[--output= ...] [] [] {|}" +write_rockspec.help = [[ This command writes an initial version of a rockspec file, based on an URL or a local path. You may use a relative path such as '.'. If a local path is given, name and version arguments are mandatory. @@ -188,7 +190,7 @@ local function rockspec_cleanup(rockspec) rockspec.name = nil end -function run(...) +function write_rockspec.run(...) local flags, name, version, url_or_dir = util.parse_flags(...) if not name then @@ -328,3 +330,5 @@ function run(...) return true end + +return write_rockspec -- cgit v1.2.3-55-g6feb From 37e38841ba7445d724787b1b7c8145dbe1136f43 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 20 Mar 2014 23:49:40 +0400 Subject: Removed module calls from installation scripts --- Makefile | 35 ++++++++++++++++++----------------- install.bat | 29 +++++++++++++++-------------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index a1b87b20..244563b7 100644 --- a/Makefile +++ b/Makefile @@ -44,56 +44,57 @@ build: src/luarocks/site_config.lua build_bins src/luarocks/site_config.lua: config.unix rm -f src/luarocks/site_config.lua - echo 'module("luarocks.site_config")' >> src/luarocks/site_config.lua + echo 'local site_config = {}' >> src/luarocks/site_config.lua if [ -n "$(PREFIX)" ] ;\ then \ - echo "LUAROCKS_PREFIX=[[$(PREFIX)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUAROCKS_PREFIX=[[$(PREFIX)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(LUA_INCDIR)" ] ;\ then \ - echo "LUA_INCDIR=[[$(LUA_INCDIR)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUA_INCDIR=[[$(LUA_INCDIR)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(LUA_LIBDIR)" ] ;\ then \ - echo "LUA_LIBDIR=[[$(LUA_LIBDIR)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUA_LIBDIR=[[$(LUA_LIBDIR)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(LUA_BINDIR)" ] ;\ then \ - echo "LUA_BINDIR=[[$(LUA_BINDIR)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUA_BINDIR=[[$(LUA_BINDIR)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(LUA_SUFFIX)" ] ;\ then \ - echo "LUA_INTERPRETER=[[lua$(LUA_SUFFIX)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUA_INTERPRETER=[[lua$(LUA_SUFFIX)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(SYSCONFDIR)" ] ;\ then \ - echo "LUAROCKS_SYSCONFDIR=[[$(SYSCONFDIR)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUAROCKS_SYSCONFDIR=[[$(SYSCONFDIR)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(ROCKS_TREE)" ] ;\ then \ - echo "LUAROCKS_ROCKS_TREE=[[$(ROCKS_TREE)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUAROCKS_ROCKS_TREE=[[$(ROCKS_TREE)]]" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(FORCE_CONFIG)" ] ;\ then \ - echo "LUAROCKS_FORCE_CONFIG=true" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUAROCKS_FORCE_CONFIG=true" >> src/luarocks/site_config.lua ;\ fi if [ -n "$(LUAROCKS_ROCKS_SUBDIR)" ] ;\ then \ - echo "LUAROCKS_ROCKS_SUBDIR=[[$(LUAROCKS_ROCKS_SUBDIR)]]" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUAROCKS_ROCKS_SUBDIR=[[$(LUAROCKS_ROCKS_SUBDIR)]]" >> src/luarocks/site_config.lua ;\ fi if [ "$(LUA_DIR_SET)" = "yes" ] ;\ then \ - echo "LUA_DIR_SET=true" >> src/luarocks/site_config.lua ;\ + echo "site_config.LUA_DIR_SET=true" >> src/luarocks/site_config.lua ;\ fi - echo "LUAROCKS_UNAME_S=[[$(LUAROCKS_UNAME_S)]]" >> src/luarocks/site_config.lua - echo "LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> src/luarocks/site_config.lua - echo "LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> src/luarocks/site_config.lua - echo "LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> src/luarocks/site_config.lua + echo "site_config.LUAROCKS_UNAME_S=[[$(LUAROCKS_UNAME_S)]]" >> src/luarocks/site_config.lua + echo "site_config.LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> src/luarocks/site_config.lua + echo "site_config.LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> src/luarocks/site_config.lua + echo "site_config.LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> src/luarocks/site_config.lua if [ -n "$(MULTIARCH_SUBDIR)" ] ;\ then \ - echo 'LUAROCKS_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\ - echo 'LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\ + echo 'site_config.LUAROCKS_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\ + echo 'site_config.LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> src/luarocks/site_config.lua ;\ fi + echo "return site_config" >> src/luarocks/site_config.lua dev: $(MAKE) build_bins LUADIR=$(PWD)/src diff --git a/install.bat b/install.bat index 934154d0..287bad5b 100644 --- a/install.bat +++ b/install.bat @@ -771,27 +771,27 @@ if exists(S[[$LUADIR\luarocks\site_config.lua]]) then end local f = io.open(vars.LUADIR.."\\luarocks\\site_config.lua", "w") f:write(S[=[ -module("luarocks.site_config") -LUA_INCDIR=[[$LUA_INCDIR]] -LUA_LIBDIR=[[$LUA_LIBDIR]] -LUA_BINDIR=[[$LUA_BINDIR]] -LUA_INTERPRETER=[[$LUA_INTERPRETER]] +local site_config = {} +site_config.LUA_INCDIR=[[$LUA_INCDIR]] +site_config.LUA_LIBDIR=[[$LUA_LIBDIR]] +site_config.LUA_BINDIR=[[$LUA_BINDIR]] +site_config.LUA_INTERPRETER=[[$LUA_INTERPRETER]] ]=]) if USE_MINGW then - f:write("LUAROCKS_UNAME_S=[[MINGW]]\n") + f:write("site_config.LUAROCKS_UNAME_S=[[MINGW]]\n") else - f:write("LUAROCKS_UNAME_S=[[WindowsNT]]\n") + f:write("site_config.LUAROCKS_UNAME_S=[[WindowsNT]]\n") end f:write(S[=[ -LUAROCKS_UNAME_M=[[$UNAME_M]] -LUAROCKS_SYSCONFIG=[[$SYSCONFDIR\config.lua]] -LUAROCKS_ROCKS_TREE=[[$ROCKS_TREE]] -LUAROCKS_PREFIX=[[$PREFIX]] -LUAROCKS_DOWNLOADER=[[wget]] -LUAROCKS_MD5CHECKER=[[md5sum]] +site_config.LUAROCKS_UNAME_M=[[$UNAME_M]] +site_config.LUAROCKS_SYSCONFIG=[[$SYSCONFDIR\config.lua]] +site_config.LUAROCKS_ROCKS_TREE=[[$ROCKS_TREE]] +site_config.LUAROCKS_PREFIX=[[$PREFIX]] +site_config.LUAROCKS_DOWNLOADER=[[wget]] +site_config.LUAROCKS_MD5CHECKER=[[md5sum]] ]=]) if FORCE_CONFIG then - f:write("local LUAROCKS_FORCE_CONFIG=true\n") + f:write("site_config.LUAROCKS_FORCE_CONFIG=true\n") end if exists(vars.LUADIR.."\\luarocks\\site_config.lua.bak") then for line in io.lines(vars.LUADIR.."\\luarocks\\site_config.lua.bak", "r") do @@ -800,6 +800,7 @@ if exists(vars.LUADIR.."\\luarocks\\site_config.lua.bak") then end exec(S[[DEL /F /Q "$LUADIR\luarocks\site_config.lua.bak"]]) end +f:write("return site_config\n") f:close() print(S[[Created LuaRocks site-config file: $LUADIR\luarocks\site_config.lua]]) -- cgit v1.2.3-55-g6feb From d9c799153ebf5645cf7d7a8fe473c5aff32ec4d3 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Fri, 21 Mar 2014 11:20:27 +0400 Subject: Fixed some issues with table.unpack --- src/luarocks/command_line.lua | 2 ++ src/luarocks/loader.lua | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 54d64787..3cde4c41 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -3,6 +3,8 @@ --module("luarocks.command_line", package.seeall) local command_line = {} +local unpack = unpack or table.unpack + local util = require("luarocks.util") local cfg = require("luarocks.cfg") local path = require("luarocks.path") diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 1fa15c5e..3d36723f 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -5,9 +5,10 @@ -- table in the environment, which records which versions of packages were -- used to load previous modules, so that the loader chooses versions -- that are declared to be compatible with the ones loaded earlier. -local global_env = _G -local package, require, ipairs, pairs, table, type, next, unpack, tostring, error = - package, require, ipairs, pairs, table, type, next, unpack, tostring, error +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 unpack = unpack or table.unpack --module("luarocks.loader") local loader = {} @@ -109,7 +110,7 @@ end -- @return table or (nil, string): The module table as returned by some other loader, -- or nil followed by an error message if no other loader managed to load the module. local function call_other_loaders(module, name, version, module_name) - for i, a_loader in ipairs(package.loaders) do + for i, a_loader in ipairs(loaders) do if a_loader ~= loader.luarocks_loader then local results = { a_loader(module_name) } if type(results[1]) == "function" then @@ -210,6 +211,6 @@ function loader.luarocks_loader(module) end end -table.insert(global_env.package.loaders, 1, loader.luarocks_loader) +table.insert(loaders, 1, loader.luarocks_loader) return loader -- cgit v1.2.3-55-g6feb From 99c664cd30b2e80b7bdd2d33ab5619556c23e41d Mon Sep 17 00:00:00 2001 From: mpeterv Date: Fri, 21 Mar 2014 12:08:08 +0400 Subject: Fixed remaining unpack issues --- src/luarocks/build/builtin.lua | 2 ++ src/luarocks/build/make.lua | 2 ++ src/luarocks/fetch/cvs.lua | 2 ++ src/luarocks/fetch/git.lua | 2 ++ src/luarocks/fetch/hg.lua | 2 ++ src/luarocks/fetch/svn.lua | 2 ++ src/luarocks/pack.lua | 2 ++ src/luarocks/util.lua | 2 ++ 8 files changed, 16 insertions(+) diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index fa03f0d2..47aa71fc 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -3,6 +3,8 @@ --module("luarocks.build.builtin", package.seeall) local builtin = {} +local unpack = unpack or table.unpack + local fs = require("luarocks.fs") local path = require("luarocks.path") local util = require("luarocks.util") diff --git a/src/luarocks/build/make.lua b/src/luarocks/build/make.lua index 31deac64..0da183e9 100644 --- a/src/luarocks/build/make.lua +++ b/src/luarocks/build/make.lua @@ -3,6 +3,8 @@ --module("luarocks.build.make", package.seeall) local make = {} +local unpack = unpack or table.unpack + local fs = require("luarocks.fs") local util = require("luarocks.util") local cfg = require("luarocks.cfg") diff --git a/src/luarocks/fetch/cvs.lua b/src/luarocks/fetch/cvs.lua index efb59d05..cc9fd655 100644 --- a/src/luarocks/fetch/cvs.lua +++ b/src/luarocks/fetch/cvs.lua @@ -3,6 +3,8 @@ --module("luarocks.fetch.cvs", package.seeall) local cvs = {} +local unpack = unpack or table.unpack + local fs = require("luarocks.fs") local dir = require("luarocks.dir") local util = require("luarocks.util") diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 824ea905..53fd4445 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -3,6 +3,8 @@ --module("luarocks.fetch.git", package.seeall) local git = {} +local unpack = unpack or table.unpack + local fs = require("luarocks.fs") local dir = require("luarocks.dir") local util = require("luarocks.util") diff --git a/src/luarocks/fetch/hg.lua b/src/luarocks/fetch/hg.lua index 31b4f716..b2ba56e9 100644 --- a/src/luarocks/fetch/hg.lua +++ b/src/luarocks/fetch/hg.lua @@ -3,6 +3,8 @@ --module("luarocks.fetch.hg", package.seeall) local hg = {} +local unpack = unpack or table.unpack + local fs = require("luarocks.fs") local dir = require("luarocks.dir") local util = require("luarocks.util") diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua index 63a443c7..abeacf9a 100644 --- a/src/luarocks/fetch/svn.lua +++ b/src/luarocks/fetch/svn.lua @@ -3,6 +3,8 @@ --module("luarocks.fetch.svn", package.seeall) local svn = {} +local unpack = unpack or table.unpack + local fs = require("luarocks.fs") local dir = require("luarocks.dir") local util = require("luarocks.util") diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index c23cf66a..d8b3ad9b 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua @@ -5,6 +5,8 @@ local pack = {} package.loaded["luarocks.pack"] = pack +local unpack = unpack or table.unpack + local path = require("luarocks.path") local repos = require("luarocks.repos") local fetch = require("luarocks.fetch") diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index fd0cda44..7e34fe0e 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -7,6 +7,8 @@ --module("luarocks.util", package.seeall) local util = {} +local unpack = unpack or table.unpack + local scheduled_functions = {} local debug = require("debug") -- cgit v1.2.3-55-g6feb