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(-) (limited to 'src') 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