From f2beb5ee1fd2c54d59a43f4f2a8fe0f7a1701daa Mon Sep 17 00:00:00 2001 From: Hisham Date: Thu, 30 Jun 2016 01:15:01 -0300 Subject: Core modules reorganization. Isolate all modules used by luarocks.loader in a luarocks.core.* namespace. Core modules can only require other core modules, and they only use require() at the top-level chunk. In other words, after luarocks.loader is setup, package.path can be altered at will and it should not affect the ability of luarocks.loader to run, and the luarocks.loader modules should not interfere with modules loaded later. This was motivated by @robooo's GSoC work on porting the LuaRocks test suite to Lua using Busted. Busted itself runs using luarocks.loader, and we need to ensure that the modules loaded by the tests do not conflict with the ones used by luarocks.loader. A circular dependency between luarocks.manif and luarocks.search was removed by creating a separate luarocks.manif.writer module. Also, luarocks-admin commands were moved to a luarocks.admin.* namespace. --- src/bin/luarocks-admin | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/bin/luarocks-admin') diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 2890d1f1..660c0a70 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin @@ -1,7 +1,7 @@ #!/usr/bin/env lua -- this should be loaded first. -local cfg = require("luarocks.cfg") +local cfg = require("luarocks.core.cfg") local loader = require("luarocks.loader") local command_line = require("luarocks.command_line") @@ -10,10 +10,10 @@ program_description = "LuaRocks repository administration interface" commands = { help = "luarocks.help", - make_manifest = "luarocks.make_manifest", - add = "luarocks.add", - remove = "luarocks.admin_remove", - refresh_cache = "luarocks.refresh_cache", + make_manifest = "luarocks.admin.make_manifest", + add = "luarocks.admin.add", + remove = "luarocks.admin.remove", + refresh_cache = "luarocks.admin.refresh_cache", } command_line.run_command(...) -- cgit v1.2.3-55-g6feb From 83b0f6d2343f2631b9dc96c09c2bc4b2cfadd17f Mon Sep 17 00:00:00 2001 From: Hisham Date: Thu, 28 Jul 2016 18:15:35 -0300 Subject: Tweak tests for luarocks-3 branch. --- .travis.yml | 2 +- src/bin/luarocks | 3 ++- src/bin/luarocks-admin | 3 ++- test/test_environment.lua | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/bin/luarocks-admin') diff --git a/.travis.yml b/.travis.yml index 02bdb6c9..86f7bbad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ matrix: before_install: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python; fi - pip install hererocks - - hererocks lua_install -r^ --$LUA + - hererocks lua_install --luarocks @luarocks-3 --$LUA - export PATH=$PATH:$PWD/lua_install/bin # Add directory with all installed binaries to PATH install: diff --git a/src/bin/luarocks b/src/bin/luarocks index 21f17da9..633f9f43 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -1,4 +1,5 @@ -#!/usr/bin/env lua +#!/Programs/Lua/5.3.0/bin/lua +package.path = [[/Users/hisham/luarocks/src/?.lua;]]..package.path -- this should be loaded first. local cfg = require("luarocks.core.cfg") diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 660c0a70..587afcab 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin @@ -1,4 +1,5 @@ -#!/usr/bin/env lua +#!/Programs/Lua/5.3.0/bin/lua +package.path = [[/Users/hisham/luarocks/src/?.lua;]]..package.path -- this should be loaded first. local cfg = require("luarocks.core.cfg") diff --git a/test/test_environment.lua b/test/test_environment.lua index 13e548f9..c26c1e87 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -361,7 +361,7 @@ local function reset_environment(testing_paths, md5sums) end local function create_paths(luaversion_full) - local cfg = require("luarocks.cfg") + local cfg = require("luarocks.core.cfg") local testing_paths = {} testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "") @@ -409,7 +409,7 @@ function test_env.setup_specs(extra_rocks) test_env.main() package.path = test_env.env_variables.LUA_PATH - test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) + test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.core.cfg\").arch)'", false, test_env.env_variables) test_env.md5sums = create_md5sums(test_env.testing_paths) test_env.setup_done = true title("RUNNING TESTS") -- cgit v1.2.3-55-g6feb From a47f54bb139aa3b932d807e89a0691dfdfaa9723 Mon Sep 17 00:00:00 2001 From: Hisham Date: Sat, 15 Oct 2016 10:16:01 -0700 Subject: Oops, my dev environment leaked in a commit, sorry. --- src/bin/luarocks | 3 +-- src/bin/luarocks-admin | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/bin/luarocks-admin') diff --git a/src/bin/luarocks b/src/bin/luarocks index 633f9f43..21f17da9 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -1,5 +1,4 @@ -#!/Programs/Lua/5.3.0/bin/lua -package.path = [[/Users/hisham/luarocks/src/?.lua;]]..package.path +#!/usr/bin/env lua -- this should be loaded first. local cfg = require("luarocks.core.cfg") diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 587afcab..660c0a70 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin @@ -1,5 +1,4 @@ -#!/Programs/Lua/5.3.0/bin/lua -package.path = [[/Users/hisham/luarocks/src/?.lua;]]..package.path +#!/usr/bin/env lua -- this should be loaded first. local cfg = require("luarocks.core.cfg") -- cgit v1.2.3-55-g6feb From 67f73b4a1a18a6ff9535ac4ed5faec0d1eb9671a Mon Sep 17 00:00:00 2001 From: Hisham Date: Sat, 29 Oct 2016 16:14:05 -0200 Subject: Move admin commands to luarocks.admin.cmd.*; fix references to modules. --- src/bin/luarocks | 38 ++++----- src/bin/luarocks-admin | 10 +-- src/luarocks/admin/add.lua | 129 ------------------------------- src/luarocks/admin/cmd/add.lua | 129 +++++++++++++++++++++++++++++++ src/luarocks/admin/cmd/make_manifest.lua | 51 ++++++++++++ src/luarocks/admin/cmd/refresh_cache.lua | 30 +++++++ src/luarocks/admin/cmd/remove.lua | 90 +++++++++++++++++++++ src/luarocks/admin/make_manifest.lua | 51 ------------ src/luarocks/admin/refresh_cache.lua | 30 ------- src/luarocks/admin/remove.lua | 90 --------------------- src/luarocks/cmd/install.lua | 4 +- src/luarocks/cmd/search.lua | 13 ++-- src/luarocks/deps.lua | 2 +- src/luarocks/download.lua | 4 +- 14 files changed, 336 insertions(+), 335 deletions(-) delete mode 100644 src/luarocks/admin/add.lua create mode 100644 src/luarocks/admin/cmd/add.lua create mode 100644 src/luarocks/admin/cmd/make_manifest.lua create mode 100644 src/luarocks/admin/cmd/refresh_cache.lua create mode 100644 src/luarocks/admin/cmd/remove.lua delete mode 100644 src/luarocks/admin/make_manifest.lua delete mode 100644 src/luarocks/admin/refresh_cache.lua delete mode 100644 src/luarocks/admin/remove.lua (limited to 'src/bin/luarocks-admin') diff --git a/src/bin/luarocks b/src/bin/luarocks index 21f17da9..88a1d1ca 100755 --- a/src/bin/luarocks +++ b/src/bin/luarocks @@ -9,25 +9,25 @@ local command_line = require("luarocks.command_line") program_description = "LuaRocks main command-line interface" commands = { - help = "luarocks.help", - pack = "luarocks.pack", - unpack = "luarocks.unpack", - build = "luarocks.build", - install = "luarocks.install", - search = "luarocks.search", - list = "luarocks.list", - remove = "luarocks.remove", - make = "luarocks.make", - download = "luarocks.download", - path = "luarocks.path_cmd", - show = "luarocks.show", - new_version = "luarocks.new_version", - lint = "luarocks.lint", - write_rockspec = "luarocks.write_rockspec", - purge = "luarocks.purge", - doc = "luarocks.doc", - upload = "luarocks.upload", - config = "luarocks.config_cmd", + help = "luarocks.cmd.help", + pack = "luarocks.cmd.pack", + unpack = "luarocks.cmd.unpack", + build = "luarocks.cmd.build", + install = "luarocks.cmd.install", + search = "luarocks.cmd.search", + list = "luarocks.cmd.list", + remove = "luarocks.cmd.remove", + make = "luarocks.cmd.make", + download = "luarocks.cmd.download", + path = "luarocks.cmd.path", + show = "luarocks.cmd.show", + new_version = "luarocks.cmd.new_version", + lint = "luarocks.cmd.lint", + write_rockspec = "luarocks.cmd.write_rockspec", + purge = "luarocks.cmd.purge", + doc = "luarocks.cmd.doc", + upload = "luarocks.cmd.upload", + config = "luarocks.cmd.config", } command_line.run_command(...) diff --git a/src/bin/luarocks-admin b/src/bin/luarocks-admin index 660c0a70..5db24640 100755 --- a/src/bin/luarocks-admin +++ b/src/bin/luarocks-admin @@ -9,11 +9,11 @@ local command_line = require("luarocks.command_line") program_description = "LuaRocks repository administration interface" commands = { - help = "luarocks.help", - make_manifest = "luarocks.admin.make_manifest", - add = "luarocks.admin.add", - remove = "luarocks.admin.remove", - refresh_cache = "luarocks.admin.refresh_cache", + help = "luarocks.cmd.help", + make_manifest = "luarocks.admin.cmd.make_manifest", + add = "luarocks.admin.cmd.add", + remove = "luarocks.admin.cmd.remove", + refresh_cache = "luarocks.admin.cmd.refresh_cache", } command_line.run_command(...) diff --git a/src/luarocks/admin/add.lua b/src/luarocks/admin/add.lua deleted file mode 100644 index daf46c1d..00000000 --- a/src/luarocks/admin/add.lua +++ /dev/null @@ -1,129 +0,0 @@ - ---- Module implementing the luarocks-admin "add" command. --- Adds a rock or rockspec to a rocks server. -local add = {} - -local cfg = require("luarocks.core.cfg") -local util = require("luarocks.util") -local dir = require("luarocks.dir") -local writer = require("luarocks.manif.writer") -local index = require("luarocks.index") -local fs = require("luarocks.fs") -local cache = require("luarocks.admin.cache") - -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 -from the configuration file is used instead. -The flag --no-refresh indicates the local cache should not be refreshed -prior to generation of the updated manifest. -]] - -local function zip_manifests() - for ver in util.lua_versions() do - local file = "manifest-"..ver - local zip = file..".zip" - fs.delete(dir.path(fs.current_dir(), zip)) - fs.zip(zip, file) - end -end - -local function add_files_to_server(refresh, rockfiles, server, upload_server) - assert(type(refresh) == "boolean" or not refresh) - assert(type(rockfiles) == "table") - assert(type(server) == "string") - assert(type(upload_server) == "table" or not upload_server) - - local download_url, login_url = cache.get_server_urls(server, upload_server) - local at = fs.current_dir() - local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url - - local local_cache, protocol, server_path, user, password = refresh_fn(server, download_url, cfg.upload_user, cfg.upload_password) - if not local_cache then - return nil, protocol - end - if protocol == "file" then - return nil, "Server "..server.." is not recognized, check your configuration." - end - - if not login_url then - login_url = protocol.."://"..server_path - end - - local ok, err = fs.change_dir(at) - if not ok then return nil, err end - - local files = {} - for _, rockfile in ipairs(rockfiles) do - if fs.exists(rockfile) then - util.printout("Copying file "..rockfile.." to "..local_cache.."...") - local absolute = fs.absolute_name(rockfile) - fs.copy(absolute, local_cache, cfg.perm_read) - table.insert(files, dir.base_name(absolute)) - else - util.printerr("File "..rockfile.." not found") - end - end - if #files == 0 then - return nil, "No files found" - end - - local ok, err = fs.change_dir(local_cache) - if not ok then return nil, err end - - util.printout("Updating manifest...") - writer.make_manifest(local_cache, "one", true) - - zip_manifests() - - util.printout("Updating index.html...") - index.make_index(local_cache) - - local login_info = "" - if user then login_info = " -u "..user end - if password then login_info = login_info..":"..password end - if not login_url:match("/$") then - login_url = login_url .. "/" - end - - table.insert(files, "index.html") - table.insert(files, "manifest") - for ver in util.lua_versions() do - table.insert(files, "manifest-"..ver) - table.insert(files, "manifest-"..ver..".zip") - end - - -- TODO abstract away explicit 'curl' call - - local cmd - if protocol == "rsync" then - local srv, path = server_path:match("([^/]+)(/.+)") - cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" - elseif upload_server and upload_server.sftp then - local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") - cmd = cfg.variables.SCP.." "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 - else - cmd = cfg.variables.CURL.." "..login_info.." -T '{"..table.concat(files, ",").."}' "..login_url - end - - util.printout(cmd) - fs.execute(cmd) - - return true -end - -function add.command(flags, ...) - local files = {...} - if #files < 1 then - return nil, "Argument missing. "..util.see_help("add", "luarocks-admin") - end - local server, server_table = cache.get_upload_server(flags["server"]) - if not server then return nil, server_table end - return add_files_to_server(not flags["no-refresh"], files, server, server_table) -end - - -return add diff --git a/src/luarocks/admin/cmd/add.lua b/src/luarocks/admin/cmd/add.lua new file mode 100644 index 00000000..daf46c1d --- /dev/null +++ b/src/luarocks/admin/cmd/add.lua @@ -0,0 +1,129 @@ + +--- Module implementing the luarocks-admin "add" command. +-- Adds a rock or rockspec to a rocks server. +local add = {} + +local cfg = require("luarocks.core.cfg") +local util = require("luarocks.util") +local dir = require("luarocks.dir") +local writer = require("luarocks.manif.writer") +local index = require("luarocks.index") +local fs = require("luarocks.fs") +local cache = require("luarocks.admin.cache") + +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 +from the configuration file is used instead. +The flag --no-refresh indicates the local cache should not be refreshed +prior to generation of the updated manifest. +]] + +local function zip_manifests() + for ver in util.lua_versions() do + local file = "manifest-"..ver + local zip = file..".zip" + fs.delete(dir.path(fs.current_dir(), zip)) + fs.zip(zip, file) + end +end + +local function add_files_to_server(refresh, rockfiles, server, upload_server) + assert(type(refresh) == "boolean" or not refresh) + assert(type(rockfiles) == "table") + assert(type(server) == "string") + assert(type(upload_server) == "table" or not upload_server) + + local download_url, login_url = cache.get_server_urls(server, upload_server) + local at = fs.current_dir() + local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url + + local local_cache, protocol, server_path, user, password = refresh_fn(server, download_url, cfg.upload_user, cfg.upload_password) + if not local_cache then + return nil, protocol + end + if protocol == "file" then + return nil, "Server "..server.." is not recognized, check your configuration." + end + + if not login_url then + login_url = protocol.."://"..server_path + end + + local ok, err = fs.change_dir(at) + if not ok then return nil, err end + + local files = {} + for _, rockfile in ipairs(rockfiles) do + if fs.exists(rockfile) then + util.printout("Copying file "..rockfile.." to "..local_cache.."...") + local absolute = fs.absolute_name(rockfile) + fs.copy(absolute, local_cache, cfg.perm_read) + table.insert(files, dir.base_name(absolute)) + else + util.printerr("File "..rockfile.." not found") + end + end + if #files == 0 then + return nil, "No files found" + end + + local ok, err = fs.change_dir(local_cache) + if not ok then return nil, err end + + util.printout("Updating manifest...") + writer.make_manifest(local_cache, "one", true) + + zip_manifests() + + util.printout("Updating index.html...") + index.make_index(local_cache) + + local login_info = "" + if user then login_info = " -u "..user end + if password then login_info = login_info..":"..password end + if not login_url:match("/$") then + login_url = login_url .. "/" + end + + table.insert(files, "index.html") + table.insert(files, "manifest") + for ver in util.lua_versions() do + table.insert(files, "manifest-"..ver) + table.insert(files, "manifest-"..ver..".zip") + end + + -- TODO abstract away explicit 'curl' call + + local cmd + if protocol == "rsync" then + local srv, path = server_path:match("([^/]+)(/.+)") + cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" + elseif upload_server and upload_server.sftp then + local part1, part2 = upload_server.sftp:match("^([^/]*)/(.*)$") + cmd = cfg.variables.SCP.." "..table.concat(files, " ").." "..user.."@"..part1..":/"..part2 + else + cmd = cfg.variables.CURL.." "..login_info.." -T '{"..table.concat(files, ",").."}' "..login_url + end + + util.printout(cmd) + fs.execute(cmd) + + return true +end + +function add.command(flags, ...) + local files = {...} + if #files < 1 then + return nil, "Argument missing. "..util.see_help("add", "luarocks-admin") + end + local server, server_table = cache.get_upload_server(flags["server"]) + if not server then return nil, server_table end + return add_files_to_server(not flags["no-refresh"], files, server, server_table) +end + + +return add diff --git a/src/luarocks/admin/cmd/make_manifest.lua b/src/luarocks/admin/cmd/make_manifest.lua new file mode 100644 index 00000000..57851942 --- /dev/null +++ b/src/luarocks/admin/cmd/make_manifest.lua @@ -0,0 +1,51 @@ + +--- Module implementing the luarocks-admin "make_manifest" command. +-- Compile a manifest file for a repository. +local make_manifest = {} + +local writer = require("luarocks.manif.writer") +local index = require("luarocks.index") +local cfg = require("luarocks.core.cfg") +local util = require("luarocks.util") +local deps = require("luarocks.deps") +local fs = require("luarocks.fs") +local dir = require("luarocks.dir") + +make_manifest.help_summary = "Compile a manifest file for a repository." + +make_manifest.help = [[ +, if given, is a local repository pathname. + +--local-tree If given, do not write versioned versions of the manifest file. + Use this when rebuilding the manifest of a local rocks tree. +]] + +--- Driver function for "make_manifest" command. +-- @param repo string or nil: Pathname of a local repository. If not given, +-- 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 make_manifest.command(flags, repo) + assert(type(repo) == "string" or not repo) + repo = repo or cfg.rocks_dir + + util.printout("Making manifest for "..repo) + + if repo:match("/lib/luarocks") and not flags["local-tree"] then + util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") + end + + local ok, err = writer.make_manifest(repo, deps.get_deps_mode(flags), not flags["local-tree"]) + if ok and not flags["local-tree"] then + util.printout("Generating index.html for "..repo) + index.make_index(repo) + end + if flags["local-tree"] then + for luaver in util.lua_versions() do + fs.delete(dir.path(repo, "manifest-"..luaver)) + end + end + return ok, err +end + +return make_manifest diff --git a/src/luarocks/admin/cmd/refresh_cache.lua b/src/luarocks/admin/cmd/refresh_cache.lua new file mode 100644 index 00000000..947dbfb0 --- /dev/null +++ b/src/luarocks/admin/cmd/refresh_cache.lua @@ -0,0 +1,30 @@ + +--- Module implementing the luarocks-admin "refresh_cache" command. +local refresh_cache = {} + +local cfg = require("luarocks.core.cfg") +local cache = require("luarocks.admin.cache") + +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 refresh_cache.command(flags) + local server, upload_server = cache.get_upload_server(flags["server"]) + if not server then return nil, upload_server end + local download_url = cache.get_server_urls(server, upload_server) + + local ok, err = cache.refresh_local_cache(server, download_url, cfg.upload_user, cfg.upload_password) + if not ok then + return nil, err + else + return true + end +end + + +return refresh_cache diff --git a/src/luarocks/admin/cmd/remove.lua b/src/luarocks/admin/cmd/remove.lua new file mode 100644 index 00000000..763a166f --- /dev/null +++ b/src/luarocks/admin/cmd/remove.lua @@ -0,0 +1,90 @@ + +--- Module implementing the luarocks-admin "remove" command. +-- Removes a rock or rockspec from a rocks server. +local admin_remove = {} + +local cfg = require("luarocks.core.cfg") +local util = require("luarocks.util") +local dir = require("luarocks.dir") +local writer = require("luarocks.manif.writer") +local index = require("luarocks.index") +local fs = require("luarocks.fs") +local cache = require("luarocks.admin.cache") + +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 +from the configuration file is used instead. +The flag --no-refresh indicates the local cache should not be refreshed +prior to generation of the updated manifest. +]] + +local function remove_files_from_server(refresh, rockfiles, server, upload_server) + assert(type(refresh) == "boolean" or not refresh) + assert(type(rockfiles) == "table") + assert(type(server) == "string") + assert(type(upload_server) == "table" or not upload_server) + + local download_url, login_url = cache.get_server_urls(server, upload_server) + local at = fs.current_dir() + local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url + + local local_cache, protocol, server_path, user, password = refresh_fn(server, download_url, cfg.upload_user, cfg.upload_password) + if not local_cache then + return nil, protocol + end + if protocol ~= "rsync" then + return nil, "This command requires 'rsync', check your configuration." + end + + local ok, err = fs.change_dir(at) + if not ok then return nil, err end + + local nr_files = 0 + for _, rockfile in ipairs(rockfiles) do + local basename = dir.base_name(rockfile) + local file = dir.path(local_cache, basename) + util.printout("Removing file "..file.."...") + fs.delete(file) + if not fs.exists(file) then + nr_files = nr_files + 1 + else + util.printerr("Failed removing "..file) + end + end + if nr_files == 0 then + return nil, "No files removed." + end + + local ok, err = fs.change_dir(local_cache) + if not ok then return nil, err end + + util.printout("Updating manifest...") + writer.make_manifest(local_cache, "one", true) + util.printout("Updating index.html...") + index.make_index(local_cache) + + local srv, path = server_path:match("([^/]+)(/.+)") + local cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." --delete -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" + + util.printout(cmd) + fs.execute(cmd) + + return true +end + +function admin_remove.command(flags, ...) + local files = {...} + if #files < 1 then + return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin") + end + local server, server_table = cache.get_upload_server(flags["server"]) + if not server then return nil, server_table end + return remove_files_from_server(not flags["no-refresh"], files, server, server_table) +end + + +return admin_remove diff --git a/src/luarocks/admin/make_manifest.lua b/src/luarocks/admin/make_manifest.lua deleted file mode 100644 index 57851942..00000000 --- a/src/luarocks/admin/make_manifest.lua +++ /dev/null @@ -1,51 +0,0 @@ - ---- Module implementing the luarocks-admin "make_manifest" command. --- Compile a manifest file for a repository. -local make_manifest = {} - -local writer = require("luarocks.manif.writer") -local index = require("luarocks.index") -local cfg = require("luarocks.core.cfg") -local util = require("luarocks.util") -local deps = require("luarocks.deps") -local fs = require("luarocks.fs") -local dir = require("luarocks.dir") - -make_manifest.help_summary = "Compile a manifest file for a repository." - -make_manifest.help = [[ -, if given, is a local repository pathname. - ---local-tree If given, do not write versioned versions of the manifest file. - Use this when rebuilding the manifest of a local rocks tree. -]] - ---- Driver function for "make_manifest" command. --- @param repo string or nil: Pathname of a local repository. If not given, --- 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 make_manifest.command(flags, repo) - assert(type(repo) == "string" or not repo) - repo = repo or cfg.rocks_dir - - util.printout("Making manifest for "..repo) - - if repo:match("/lib/luarocks") and not flags["local-tree"] then - util.warning("This looks like a local rocks tree, but you did not pass --local-tree.") - end - - local ok, err = writer.make_manifest(repo, deps.get_deps_mode(flags), not flags["local-tree"]) - if ok and not flags["local-tree"] then - util.printout("Generating index.html for "..repo) - index.make_index(repo) - end - if flags["local-tree"] then - for luaver in util.lua_versions() do - fs.delete(dir.path(repo, "manifest-"..luaver)) - end - end - return ok, err -end - -return make_manifest diff --git a/src/luarocks/admin/refresh_cache.lua b/src/luarocks/admin/refresh_cache.lua deleted file mode 100644 index 947dbfb0..00000000 --- a/src/luarocks/admin/refresh_cache.lua +++ /dev/null @@ -1,30 +0,0 @@ - ---- Module implementing the luarocks-admin "refresh_cache" command. -local refresh_cache = {} - -local cfg = require("luarocks.core.cfg") -local cache = require("luarocks.admin.cache") - -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 refresh_cache.command(flags) - local server, upload_server = cache.get_upload_server(flags["server"]) - if not server then return nil, upload_server end - local download_url = cache.get_server_urls(server, upload_server) - - local ok, err = cache.refresh_local_cache(server, download_url, cfg.upload_user, cfg.upload_password) - if not ok then - return nil, err - else - return true - end -end - - -return refresh_cache diff --git a/src/luarocks/admin/remove.lua b/src/luarocks/admin/remove.lua deleted file mode 100644 index 763a166f..00000000 --- a/src/luarocks/admin/remove.lua +++ /dev/null @@ -1,90 +0,0 @@ - ---- Module implementing the luarocks-admin "remove" command. --- Removes a rock or rockspec from a rocks server. -local admin_remove = {} - -local cfg = require("luarocks.core.cfg") -local util = require("luarocks.util") -local dir = require("luarocks.dir") -local writer = require("luarocks.manif.writer") -local index = require("luarocks.index") -local fs = require("luarocks.fs") -local cache = require("luarocks.admin.cache") - -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 -from the configuration file is used instead. -The flag --no-refresh indicates the local cache should not be refreshed -prior to generation of the updated manifest. -]] - -local function remove_files_from_server(refresh, rockfiles, server, upload_server) - assert(type(refresh) == "boolean" or not refresh) - assert(type(rockfiles) == "table") - assert(type(server) == "string") - assert(type(upload_server) == "table" or not upload_server) - - local download_url, login_url = cache.get_server_urls(server, upload_server) - local at = fs.current_dir() - local refresh_fn = refresh and cache.refresh_local_cache or cache.split_server_url - - local local_cache, protocol, server_path, user, password = refresh_fn(server, download_url, cfg.upload_user, cfg.upload_password) - if not local_cache then - return nil, protocol - end - if protocol ~= "rsync" then - return nil, "This command requires 'rsync', check your configuration." - end - - local ok, err = fs.change_dir(at) - if not ok then return nil, err end - - local nr_files = 0 - for _, rockfile in ipairs(rockfiles) do - local basename = dir.base_name(rockfile) - local file = dir.path(local_cache, basename) - util.printout("Removing file "..file.."...") - fs.delete(file) - if not fs.exists(file) then - nr_files = nr_files + 1 - else - util.printerr("Failed removing "..file) - end - end - if nr_files == 0 then - return nil, "No files removed." - end - - local ok, err = fs.change_dir(local_cache) - if not ok then return nil, err end - - util.printout("Updating manifest...") - writer.make_manifest(local_cache, "one", true) - util.printout("Updating index.html...") - index.make_index(local_cache) - - local srv, path = server_path:match("([^/]+)(/.+)") - local cmd = cfg.variables.RSYNC.." "..cfg.variables.RSYNCFLAGS.." --delete -e ssh "..local_cache.."/ "..user.."@"..srv..":"..path.."/" - - util.printout(cmd) - fs.execute(cmd) - - return true -end - -function admin_remove.command(flags, ...) - local files = {...} - if #files < 1 then - return nil, "Argument missing. "..util.see_help("remove", "luarocks-admin") - end - local server, server_table = cache.get_upload_server(flags["server"]) - if not server then return nil, server_table end - return remove_files_from_server(not flags["no-refresh"], files, server, server_table) -end - - -return admin_remove diff --git a/src/luarocks/cmd/install.lua b/src/luarocks/cmd/install.lua index c9b085f5..33cc8fbf 100644 --- a/src/luarocks/cmd/install.lua +++ b/src/luarocks/cmd/install.lua @@ -10,6 +10,7 @@ local fs = require("luarocks.fs") local deps = require("luarocks.deps") local writer = require("luarocks.manif.writer") local remove = require("luarocks.remove") +local search = require("luarocks.search") local cfg = require("luarocks.core.cfg") install.help_summary = "Install a rock." @@ -154,7 +155,7 @@ function install.command(flags, name, version) if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end if name:match("%.rockspec$") or name:match("%.src%.rock$") then - local build = require("luarocks.build") + local build = require("luarocks.cmd.build") return build.command(flags, name) elseif name:match("%.rock$") then if flags["only-deps"] then @@ -170,7 +171,6 @@ function install.command(flags, name, version) end return name, version else - local search = require("luarocks.search") local url, err = search.find_suitable_rock(search.make_query(name:lower(), version)) if not url then return nil, err diff --git a/src/luarocks/cmd/search.lua b/src/luarocks/cmd/search.lua index 109fe805..c4e4058d 100644 --- a/src/luarocks/cmd/search.lua +++ b/src/luarocks/cmd/search.lua @@ -1,14 +1,15 @@ --- Module implementing the LuaRocks "search" command. -- Queries LuaRocks servers. -local search = {} +local cmd_search = {} local cfg = require("luarocks.core.cfg") local util = require("luarocks.util") +local search = require("luarocks.search") -search.help_summary = "Query the LuaRocks servers." -search.help_arguments = "[--source] [--binary] { [] | --all }" -search.help = [[ +cmd_search.help_summary = "Query the LuaRocks servers." +cmd_search.help_arguments = "[--source] [--binary] { [] | --all }" +cmd_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 @@ -44,7 +45,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 search.command(flags, name, version) +function cmd_search.command(flags, name, version) if flags["all"] then name, version = "", nil end @@ -70,4 +71,4 @@ function search.command(flags, name, version) return true end -return search +return cmd_search diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index acbf1dd6..081265a5 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -240,7 +240,7 @@ end function deps.fulfill_dependencies(rockspec, deps_mode) local search = require("luarocks.search") - local install = require("luarocks.install") + local install = require("luarocks.cmd.install") if rockspec.supported_platforms then if not deps.platforms_set then diff --git a/src/luarocks/download.lua b/src/luarocks/download.lua index c0f2678f..ec9996b2 100644 --- a/src/luarocks/download.lua +++ b/src/luarocks/download.lua @@ -32,8 +32,8 @@ function download.download(arch, name, version, all) local has_result = false local all_ok = true local any_err = "" - for _, result in pairs(results) do - for _, items in pairs(result) do + for name, result in pairs(results) do + for version, items in pairs(result) do for _, item in ipairs(items) do -- Ignore provided rocks. if item.arch ~= "installed" then -- cgit v1.2.3-55-g6feb