From 233a9af0f19e00cc8aa488cc1557497c76d2a7b0 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 25 Sep 2012 15:44:03 -0300 Subject: unfinished work on multi-tree support --- src/luarocks/add.lua | 2 +- src/luarocks/admin_remove.lua | 2 +- src/luarocks/build.lua | 35 ++++++++++++++++-------------- src/luarocks/cfg.lua | 1 + src/luarocks/deps.lua | 48 +++++++++++++++++++++++++++++++++--------- src/luarocks/install.lua | 21 +++++++++++------- src/luarocks/make.lua | 5 +++-- src/luarocks/make_manifest.lua | 7 ++++-- src/luarocks/manif.lua | 22 +++++++++++-------- src/luarocks/manif_core.lua | 35 +++++++++++++++++++++++------- src/luarocks/purge.lua | 2 +- src/luarocks/remove.lua | 14 ++++++++---- src/luarocks/repos.lua | 6 +++--- src/luarocks/validate.lua | 8 +++---- 14 files changed, 139 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/luarocks/add.lua b/src/luarocks/add.lua index bf3f8979..48b9964c 100644 --- a/src/luarocks/add.lua +++ b/src/luarocks/add.lua @@ -65,7 +65,7 @@ local function add_files_to_server(refresh, rockfiles, server, upload_server) fs.change_dir(local_cache) util.printout("Updating manifest...") - manif.make_manifest(local_cache) + manif.make_manifest(local_cache, "one") util.printout("Updating index.html...") index.make_index(local_cache) diff --git a/src/luarocks/admin_remove.lua b/src/luarocks/admin_remove.lua index f1268576..dc36e16e 100644 --- a/src/luarocks/admin_remove.lua +++ b/src/luarocks/admin_remove.lua @@ -61,7 +61,7 @@ local function remove_files_from_server(refresh, rockfiles, server, upload_serve fs.change_dir(local_cache) util.printout("Updating manifest...") - manif.make_manifest(local_cache) + manif.make_manifest(local_cache, "one") util.printout("Updating index.html...") index.make_index(local_cache) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 6ffa0e79..d68acabd 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -111,10 +111,11 @@ end -- @param minimal_mode boolean: true if there's no need to fetch, -- unpack or change dir (this is used by "luarocks make"). Implies -- need_to_fetch = false. --- @param no_deps boolean: true if dependency check needs to be skipped +-- @param deps_mode: string: Which trees to check dependencies for: +-- "none", "one", "order" or "all". -- @return boolean or (nil, string, [string]): True if succeeded or -- nil and an error message followed by an error code. -function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps) +function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, deps_mode) assert(type(rockspec_file) == "string") assert(type(need_to_fetch) == "boolean") @@ -127,10 +128,10 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps) return nil, "Rockspec error: build type not specified" end - if no_deps then + if deps_mode == "none" then util.printerr("Warning: skipping dependency checks.") else - local ok, err, errcode = deps.fulfill_dependencies(rockspec) + local ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode) if err then return nil, err, errcode end @@ -253,7 +254,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode, no_deps) ok, err = repos.run_hook(rockspec, "post_install") if err then return nil, err end - ok, err = manif.update_manifest(name, version) + ok, err = manif.update_manifest(name, version, nil, deps_mode) if err then return nil, err end local license = "" @@ -273,9 +274,11 @@ end -- @param rock_file string: local or remote filename of a rock. -- @param need_to_fetch boolean: true if sources need to be fetched, -- false if the rockspec was obtained from inside a source rock. +-- @param deps_mode: string: Which trees to check dependencies for: +-- "none", "one", "order" or "all". -- @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, no_deps) +function build_rock(rock_file, need_to_fetch, deps_mode) assert(type(rock_file) == "string") assert(type(need_to_fetch) == "boolean") @@ -285,24 +288,24 @@ function build_rock(rock_file, need_to_fetch, no_deps) end local rockspec_file = path.rockspec_name_from_rock(rock_file) fs.change_dir(unpack_dir) - local ok, err, errcode = build_rockspec(rockspec_file, need_to_fetch, false, no_deps) + local ok, err, errcode = build_rockspec(rockspec_file, need_to_fetch, false, deps_mode) fs.pop_dir() return ok, err, errcode end - -local function do_build(name, version, no_deps) + +local function do_build(name, version, deps_mode) if name:match("%.rockspec$") then - return build_rockspec(name, true, false, no_deps) + return build_rockspec(name, true, false, deps_mode) elseif name:match("%.src%.rock$") then - return build_rock(name, false, no_deps) + return build_rock(name, false, deps_mode) elseif name:match("%.all%.rock$") then local install = require("luarocks.install") - return install.install_binary_rock(name, no_deps) + return install.install_binary_rock(name, deps_mode) elseif name:match("%.rock$") then - return build_rock(name, true, no_deps) + return 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, no_deps and "--nodeps") + return search.act_on_src_or_rockspec(run, name:lower(), version, deps.deps_mode_to_flag(deps_mode)) end return nil, "Don't know what to do with "..name end @@ -323,10 +326,10 @@ function run(...) assert(type(version) == "string" or not version) if flags["pack-binary-rock"] then - return pack.pack_binary_rock(name, version, do_build, name, version, flags["nodeps"]) + return pack.pack_binary_rock(name, version, do_build, name, version, deps.flags_to_deps_mode(flags)) else local ok, err = fs.check_command_permissions(flags) if not ok then return nil, err end - return do_build(name, version, flags["nodeps"]) + return do_build(name, version, deps.flags_to_deps_mode(flags)) end end diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 41adb4e5..b2ed2a96 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -164,6 +164,7 @@ local defaults = { use_extensions = false, accept_unknown_fields = false, fs_use_modules = true, + use_trees = "one", lua_modules_path = "/share/lua/"..lua_version, lib_modules_path = "/lib/lua/"..lua_version, diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 00e796b0..a409920a 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -312,14 +312,14 @@ end -- @return table or nil: A table containing fields 'name' and 'version' -- representing an installed rock which matches the given dependency, -- or nil if it could not be matched. -local function match_dep(dep, blacklist) +local function match_dep(dep, blacklist, use_trees) assert(type(dep) == "table") local versions if dep.name == "lua" then versions = { cfg.lua_version } else - versions = manif_core.get_versions(dep.name) + versions = manif_core.get_versions(dep.name, use_trees) end if not versions then return nil @@ -361,13 +361,13 @@ end -- in table format and values are tables containing fields 'name' and -- version' representing matches, and a table of missing dependencies -- parsed as tables. -function match_deps(rockspec, blacklist) +function match_deps(rockspec, blacklist, use_trees) assert(type(rockspec) == "table") assert(type(blacklist) == "table" or not blacklist) local matched, missing, no_upgrade = {}, {}, {} for _, dep in ipairs(rockspec.dependencies) do - local found = match_dep(dep, blacklist and blacklist[dep.name] or nil) + local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, use_trees) if found then if dep.name ~= "lua" then matched[dep] = found @@ -401,7 +401,7 @@ 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) +function fulfill_dependencies(rockspec, use_trees) local search = require("luarocks.search") local install = require("luarocks.install") @@ -433,7 +433,7 @@ function fulfill_dependencies(rockspec) end end - local matched, missing, no_upgrade = match_deps(rockspec) + local matched, missing, no_upgrade = match_deps(rockspec, nil, use_trees) if next(no_upgrade) then util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") @@ -467,7 +467,7 @@ function fulfill_dependencies(rockspec) for _, dep in pairs(missing) do -- Double-check in case dependency was filled during recursion. - if not match_dep(dep) then + if not match_dep(dep, nil, use_trees) then local rock = search.find_suitable_rock(dep) if not rock then return nil, "Could not satisfy dependency: "..show_dep(dep) @@ -640,7 +640,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) +function scan_deps(results, missing, manifest, name, version, use_trees) assert(type(results) == "table") assert(type(missing) == "table") assert(type(manifest) == "table") @@ -669,9 +669,9 @@ function scan_deps(results, missing, manifest, name, version) else rockspec = { dependencies = deplist } end - local matched, failures = match_deps(rockspec) + local matched, failures = match_deps(rockspec, nil, use_trees) for _, match in pairs(matched) do - results, missing = scan_deps(results, missing, manifest, match.name, match.version) + results, missing = scan_deps(results, missing, manifest, match.name, match.version, use_trees) end if next(failures) then for _, failure in pairs(failures) do @@ -681,3 +681,31 @@ function scan_deps(results, missing, manifest, name, version) results[name] = version return results, missing end + +local valid_trees = { + one = true, + order = true, + all = true, +} + +function check_trees_flag(flag) + return valid_trees[flag] +end + +function flags_to_deps_mode(flags) + if flags["nodeps"] then + return "none" + elseif flags["trees"] then + return flags["trees"] + else + return cfg.use_trees + end +end + +function deps_mode_to_flag(deps_mode) + if deps_mode == "none" then + return "--nodeps" + else + return "--trees="..deps_mode + end +end diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 6b5ea85f..a940d356 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -23,10 +23,11 @@ or a filename of a locally available rock. --- Install a binary rock. -- @param rock_file string: local or remote filename of a rock. --- @param no_deps boolean: true if dependency check needs to be skipped +-- @param deps_mode: string: Which trees to check dependencies for: +-- "none", "one", "order" or "all". -- @return boolean or (nil, string, [string]): True if succeeded or -- nil and an error message and an optional error code. -function install_binary_rock(rock_file, no_deps) +function install_binary_rock(rock_file, deps_mode) assert(type(rock_file) == "string") local name, version, arch = path.parse_name(rock_file) @@ -54,7 +55,7 @@ function install_binary_rock(rock_file, no_deps) return nil, "Failed loading rockspec for installed package: "..err, errcode end - if no_deps then + if deps_mode == "none" then util.printerr("Warning: skipping dependency checks.") else ok, err, errcode = deps.check_external_deps(rockspec, "install") @@ -67,8 +68,8 @@ function install_binary_rock(rock_file, no_deps) if err then return nil, err end end - if not no_deps then - ok, err, errcode = deps.fulfill_dependencies(rockspec) + if deps_mode ~= "none" then + ok, err, errcode = deps.fulfill_dependencies(rockspec, deps_mode) if err then return nil, err, errcode end end @@ -88,7 +89,7 @@ function install_binary_rock(rock_file, no_deps) ok, err = repos.run_hook(rockspec, "post_install") if err then return nil, err end - ok, err = manif.update_manifest(name, version) + ok, err = manif.update_manifest(name, version, nil, deps_mode) if err then return nil, err end local license = "" @@ -126,9 +127,13 @@ function run(...) if name:match("%.rockspec$") or name:match("%.src%.rock$") then util.printout("Using "..name.."... switching to 'build' mode") local build = require("luarocks.build") - return build.run(name, flags["local"] and "--local") + local build_flags = {} + if flags["local"] then table.insert(build_flags, "--local") end + if flags["nodeps"] then table.insert(build_flags, "--nodeps") end + if flags["trees"] then table.insert(build_flags, "--trees="..flags["trees"]) end + return build.run(name, unpack(build_flags)) elseif name:match("%.rock$") then - return install_binary_rock(name, flags["nodeps"]) + return install_binary_rock(name, deps.flags_to_deps_mode(flags)) else local search = require("luarocks.search") local results, err = search.find_suitable_rock(search.make_query(name:lower(), version)) diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 769db2f7..498445d8 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -11,6 +11,7 @@ local util = require("luarocks.util") local cfg = require("luarocks.cfg") local fetch = require("luarocks.fetch") local pack = require("luarocks.pack") +local deps = require("luarocks.deps") help_summary = "Compile package in current directory using a rockspec." help_arguments = "[--pack-binary-rock] []" @@ -62,10 +63,10 @@ function run(...) if not rspec then return nil, err end - return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, flags["nodeps"]) + return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.flags_to_deps_mode(flags)) else local ok, err = fs.check_command_permissions(flags) if not ok then return nil, err end - return build.build_rockspec(rockspec, false, true) + return build.build_rockspec(rockspec, false, true, deps.flags_to_deps_mode(flags)) end end diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua index 07d2fd05..e629b9de 100644 --- a/src/luarocks/make_manifest.lua +++ b/src/luarocks/make_manifest.lua @@ -7,6 +7,7 @@ local manif = require("luarocks.manif") local index = require("luarocks.index") local cfg = require("luarocks.cfg") local util = require("luarocks.util") +local deps = require("luarocks.deps") help_summary = "Compile a manifest file for a repository." @@ -19,13 +20,15 @@ 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(repo) +function run(...) + local flags, repo = util.parse_flags(...) + assert(type(repo) == "string" or not repo) repo = repo or cfg.rocks_dir util.printout("Making manifest for "..repo) - local ok, err = manif.make_manifest(repo) + local ok, err = manif.make_manifest(repo, deps.flags_to_deps_mode(flags)) if ok then util.printout("Generating index.html for "..repo) index.make_index(repo) diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 2c745f0b..9e5ee823 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -185,14 +185,14 @@ end -- and any dependency inconsistencies or missing dependencies are reported to -- standard error. -- @param manifest table: a manifest table. -local function update_dependencies(manifest) +local function update_dependencies(manifest, use_trees) for pkg, versions in pairs(manifest.repository) do for version, repositories in pairs(versions) do local current = pkg.." "..version for _, repo in ipairs(repositories) do if repo.arch == "installed" then local missing - repo.dependencies, missing = deps.scan_deps({}, {}, manifest, pkg, version) + repo.dependencies, missing = deps.scan_deps({}, {}, manifest, pkg, version, use_trees) repo.dependencies[pkg] = nil if missing then for miss, err in pairs(missing) do @@ -214,7 +214,7 @@ end -- @param manifest table: A manifest table (must contain repository, modules, commands tables). -- It will be altered to include the search results. -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. -local function store_results(results, manifest) +local function store_results(results, manifest, use_trees) assert(type(results) == "table") assert(type(manifest) == "table") @@ -239,7 +239,7 @@ local function store_results(results, manifest) end manifest.repository[name] = pkgtable end - update_dependencies(manifest) + update_dependencies(manifest, use_trees) sort_package_matching_table(manifest.modules) sort_package_matching_table(manifest.commands) return true @@ -251,9 +251,11 @@ end -- @param repo A local repository directory. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. -function make_manifest(repo) +function make_manifest(repo, use_trees) assert(type(repo) == "string") + if use_trees == "none" then use_trees = cfg.use_trees end + if not fs.is_dir(repo) then return nil, "Cannot access repository at "..repo end @@ -265,7 +267,7 @@ function make_manifest(repo) local manifest = { repository = {}, modules = {}, commands = {} } manif_core.manifest_cache[repo] = manifest - local ok, err = store_results(results, manifest) + local ok, err = store_results(results, manifest, use_trees) if not ok then return nil, err end return save_table(repo, "manifest", manifest) @@ -281,17 +283,19 @@ end -- 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 update_manifest(name, version, repo) +function update_manifest(name, version, repo, use_trees) assert(type(name) == "string") assert(type(version) == "string") repo = path.rocks_dir(repo or cfg.root_dir) + + if use_trees == "none" then use_trees = cfg.use_trees end util.printout("Updating manifest for "..repo) local manifest, err = load_manifest(repo) if not manifest then util.printerr("No existing manifest. Attempting to rebuild...") - local ok, err = make_manifest(repo) + local ok, err = make_manifest(repo, use_trees) if not ok then return nil, err end @@ -303,7 +307,7 @@ function update_manifest(name, version, repo) local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} - local ok, err = store_results(results, manifest) + local ok, err = store_results(results, manifest, use_trees) if not ok then return nil, err end return save_table(repo, "manifest", manifest) diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua index 40f16898..ed6cac07 100644 --- a/src/luarocks/manif_core.lua +++ b/src/luarocks/manif_core.lua @@ -8,6 +8,7 @@ local type_check = require("luarocks.type_check") local dir = require("luarocks.dir") local util = require("luarocks.util") local cfg = require("luarocks.cfg") +local path = require("luarocks.path") manifest_cache = {} @@ -52,22 +53,40 @@ end --- Get all versions of a package listed in a manifest file. -- @param name string: a package name. --- @param manifest table or nil: a manifest table; if not given, the --- default local manifest table is used. +-- @param use_trees string: "one", to use only the currently +-- configured tree; "order" to select trees based on order +-- (use the current tree and all trees below it on the list) +-- or "all", to use all trees. -- @return table: An array of strings listing installed -- versions of a package. -function get_versions(name, manifest) +function get_versions(name, use_trees) assert(type(name) == "string") - assert(type(manifest) == "table" or not manifest) + assert(type(use_trees) == "string") - if not manifest then + local manifest + + if use_trees == "one" then manifest = load_local_manifest(cfg.rocks_dir) - if not manifest then - return {} + elseif use_trees == "all" or use_trees == "order" then + manifest = {} + local use = false + if use_trees == "all" then + use = true + end + for _, tree in ipairs(cfg.rocks_trees) do + if tree == cfg.rocks_dir then + use = true + end + if use then + local loaded = load_local_manifest(path.rocks_dir(tree)) + if loaded then + util.deep_merge(manifest, loaded) + end + end end end - local item = manifest.repository[name] + local item = manifest and manifest.repository[name] if item then return util.keys(item) end diff --git a/src/luarocks/purge.lua b/src/luarocks/purge.lua index dc6b822d..ca682f7d 100644 --- a/src/luarocks/purge.lua +++ b/src/luarocks/purge.lua @@ -44,5 +44,5 @@ function run(...) end end end - return manif.make_manifest(cfg.rocks_dir) + return manif.make_manifest(cfg.rocks_dir, "one") end diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index a9d97540..261dc1c4 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -28,7 +28,7 @@ To override this check and force the removal, use --force. -- @param versions array of string: the versions to be deleted. -- @return array of string: an empty table if no packages depend on any -- of the given list, or an array of strings in "name/version" format. -local function check_dependents(name, versions) +local function check_dependents(name, versions, use_trees) local dependents = {} local blacklist = {} blacklist[name] = {} @@ -44,7 +44,7 @@ local function check_dependents(name, versions) for rock_version, _ in pairs(rock_versions) do local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) if rockspec then - local _, missing = deps.match_deps(rockspec, blacklist) + local _, missing = deps.match_deps(rockspec, blacklist, use_trees) if missing[name] then table.insert(dependents, { name = rock_name, version = rock_version }) end @@ -78,11 +78,17 @@ end -- successful, nil and an error message otherwise. function run(...) local flags, name, version = util.parse_flags(...) + + if flags["trees"] and type(flags["trees"]) ~= "string" then + return nil, "Invalid entry for --trees." + end if type(name) ~= "string" then return nil, "Argument missing, see help." end + local use_trees = flags["trees"] or cfg.use_trees + local ok, err = fs.check_command_permissions(flags) if not ok then return nil, err end @@ -100,7 +106,7 @@ function run(...) util.printout(name.." "..table.concat(util.keys(versions), ", ").."...") util.printout() - local dependents = check_dependents(name, versions) + local dependents = check_dependents(name, versions, use_trees) if #dependents == 0 or flags["force"] then if #dependents > 0 then @@ -112,7 +118,7 @@ function run(...) end local ok, err = delete_versions(name, versions) if not ok then return nil, err end - ok, err = manif.make_manifest(cfg.rocks_dir) + ok, err = manif.make_manifest(cfg.rocks_dir, use_trees) if not ok then return nil, err end else if not second then diff --git a/src/luarocks/repos.lua b/src/luarocks/repos.lua index 30c61f55..3a337e7c 100644 --- a/src/luarocks/repos.lua +++ b/src/luarocks/repos.lua @@ -14,7 +14,7 @@ local deps = require("luarocks.deps") -- @param name string: a package name. -- @return table or nil: An array of strings listing installed -- versions of a package, or nil if none is available. -function get_versions(name) +local function get_installed_versions(name) assert(type(name) == "string") local dirs = fs.list_dir(path.versions_dir(name)) @@ -229,7 +229,7 @@ function deploy_files(name, version, wrap_bin_scripts) else target = new_target end - end + end fs.make_dir(dir.dir_name(target)) ok, err = move_fn(source, target) fs.remove_dir_tree_if_empty(dir.dir_name(source)) @@ -312,7 +312,7 @@ function delete_version(name, version, quick) if err then return nil, err end fs.delete(path.install_dir(name, version)) - if not get_versions(name) then + if not get_installed_versions(name) then fs.delete(dir.path(cfg.rocks_dir, name)) end return true diff --git a/src/luarocks/validate.lua b/src/luarocks/validate.lua index 03e90ecf..fb6a78ad 100644 --- a/src/luarocks/validate.lua +++ b/src/luarocks/validate.lua @@ -50,7 +50,7 @@ local function prepare_sandbox(file) end local function validate_rockspec(file) - local ok, err, errcode = build.build_rockspec(file, true) + local ok, err, errcode = build.build_rockspec(file, true, "one") if not ok then util.printerr(err) end @@ -58,7 +58,7 @@ local function validate_rockspec(file) end local function validate_src_rock(file) - local ok, err, errcode = build.build_rock(file, false) + local ok, err, errcode = build.build_rock(file, false, "one") if not ok then util.printerr(err) end @@ -66,7 +66,7 @@ local function validate_src_rock(file) end local function validate_rock(file) - local ok, err, errcode = install.install_binary_rock(file) + local ok, err, errcode = install.install_binary_rock(file, "one") if not ok then util.printerr(err) end @@ -97,7 +97,7 @@ local function validate(repo, flags) util.printout() util.printout("Verifying "..pathname) if file:match("%.rockspec$") then - ok, err, errcode = validate_rockspec(pathname) + ok, err, errcode = validate_rockspec(pathname, "one") elseif file:match("%.src%.rock$") then ok, err, errcode = validate_src_rock(pathname) elseif file:match("%.rock$") then -- cgit v1.2.3-55-g6feb From 74b0087d28c735dc5440c4587be3085abbd05257 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 25 Sep 2012 17:17:27 -0300 Subject: factor out tree map operation and use it in "luarocks path" command, providing proper bin paths. --- src/luarocks/cfg.lua | 4 ++-- src/luarocks/dir.lua | 4 ++++ src/luarocks/fs/lua.lua | 40 ++++++++++++++++++---------------------- src/luarocks/manif_core.lua | 29 +++++++---------------------- src/luarocks/path.lua | 28 +++++++++++++++++++++++++++- src/luarocks/util.lua | 2 ++ 6 files changed, 60 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index b2ed2a96..330fabca 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -277,7 +277,7 @@ if detected.windows then lib = { "?.dll", "lib?.dll" }, include = { "?.h" } } - defaults.export_path = "SET PATH=%s;%s" + defaults.export_path = "SET PATH=%s" defaults.export_path_separator = ";" defaults.export_lua_path = "SET LUA_PATH=%s" defaults.export_lua_cpath = "SET LUA_CPATH=%s" @@ -322,7 +322,7 @@ if detected.unix then lib = { "lib?.so", "lib?.so.*" }, include = { "?.h" } } - defaults.export_path = "export PATH='%s:%s'" + defaults.export_path = "export PATH='%s'" defaults.export_path_separator = ":" defaults.export_lua_path = "export LUA_PATH='%s'" defaults.export_lua_cpath = "export LUA_CPATH='%s'" diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index 3de9e241..c2309ff1 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -68,3 +68,7 @@ function split_url(url) end return protocol, pathname end + +function normalize(name) + return name:gsub("\\", "/"):gsub("(.)/*$", "%1") +end diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index c413ccb3..eba61214 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -43,10 +43,6 @@ function Q(arg) return "'" .. arg:gsub("\\", "\\\\"):gsub("'", "'\\''") .. "'" end -local function normalize(name) - return name:gsub("\\", "/"):gsub("(.)/*$", "%1") -end - --- Test is file/dir is writable. -- Warning: testing if a file/dir is writable does not guarantee -- that it will remain writable and therefore it is no replacement @@ -55,7 +51,7 @@ end -- @return boolean: true if file exists, false otherwise. function is_writable(file) assert(file) - file = normalize(file) + file = dir.normalize(file) local result if fs.is_dir(file) then local file2 = dir.path(file, '.tmpluarockstestwritable') @@ -77,7 +73,7 @@ end -- @return string or nil: name of temporary directory or nil on failure. function make_temp_dir(name) assert(type(name) == "string") - name = normalize(name) + name = dir.normalize(name) local temp_dir = (os.getenv("TMP") or "/tmp") .. "/luarocks_" .. name:gsub(dir.separator, "_") .. "-" .. tostring(math.floor(math.random() * 10000)) if fs.make_dir(temp_dir) then @@ -110,7 +106,7 @@ end -- @return boolean: true if the MD5 checksum for 'file' equals 'md5sum', false if not -- or if it could not perform the check for any reason. function check_md5(file, md5sum) - file = normalize(file) + file = dir.normalize(file) local computed = fs.get_md5(file) if not computed then return false @@ -156,7 +152,7 @@ end -- @param d string: The directory to switch to. function change_dir(d) table.insert(dir_stack, lfs.currentdir()) - d = normalize(d) + d = dir.normalize(d) lfs.chdir(d) end @@ -187,7 +183,7 @@ end -- @return boolean: true on success, false on failure. function make_dir(directory) assert(type(directory) == "string") - directory = normalize(directory) + directory = dir.normalize(directory) local path = nil if directory:sub(2, 2) == ":" then path = directory:sub(1, 2) @@ -217,7 +213,7 @@ end -- @param d string: pathname of directory to remove. function remove_dir_if_empty(d) assert(d) - d = normalize(d) + d = dir.normalize(d) lfs.rmdir(d) end @@ -227,7 +223,7 @@ end -- @param d string: pathname of directory to remove. function remove_dir_tree_if_empty(d) assert(d) - d = normalize(d) + d = dir.normalize(d) for i=1,10 do lfs.rmdir(d) d = dir.dir_name(d) @@ -243,8 +239,8 @@ end -- plus an error message. function copy(src, dest, perms) assert(src and dest) - src = normalize(src) - dest = normalize(dest) + src = dir.normalize(src) + dest = dir.normalize(dest) local destmode = lfs.attributes(dest, "mode") if destmode == "directory" then dest = dir.path(dest, dir.base_name(src)) @@ -296,8 +292,8 @@ end -- plus an error message. function copy_contents(src, dest) assert(src and dest) - src = normalize(src) - dest = normalize(dest) + src = dir.normalize(src) + dest = dir.normalize(dest) assert(lfs.attributes(src, "mode") == "directory") for file in lfs.dir(src) do @@ -338,7 +334,7 @@ end -- @param name string: Pathname of source -- @return boolean: true on success, false on failure. function delete(name) - name = normalize(name) + name = dir.normalize(name) return recursive_delete(name) or false end @@ -352,7 +348,7 @@ function list_dir(at) if not at then at = fs.current_dir() end - at = normalize(at) + at = dir.normalize(at) if not fs.is_dir(at) then return {} end @@ -393,7 +389,7 @@ function find(at) if not at then at = fs.current_dir() end - at = normalize(at) + at = dir.normalize(at) if not fs.is_dir(at) then return {} end @@ -407,7 +403,7 @@ end -- @return boolean: true if file exists, false otherwise. function exists(file) assert(file) - file = normalize(file) + file = dir.normalize(file) return type(lfs.attributes(file)) == "table" end @@ -416,7 +412,7 @@ end -- @return boolean: true if it is a directory, false otherwise. function is_dir(file) assert(file) - file = normalize(file) + file = dir.normalize(file) return lfs.attributes(file, "mode") == "directory" end @@ -425,12 +421,12 @@ end -- @return boolean: true if it is a file, false otherwise. function is_file(file) assert(file) - file = normalize(file) + file = dir.normalize(file) return lfs.attributes(file, "mode") == "file" end function set_time(file, time) - file = normalize(file) + file = dir.normalize(file) return lfs.touch(file, time) end diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua index ed6cac07..6af99fe7 100644 --- a/src/luarocks/manif_core.lua +++ b/src/luarocks/manif_core.lua @@ -63,30 +63,15 @@ function get_versions(name, use_trees) assert(type(name) == "string") assert(type(use_trees) == "string") - local manifest - - if use_trees == "one" then - manifest = load_local_manifest(cfg.rocks_dir) - elseif use_trees == "all" or use_trees == "order" then - manifest = {} - local use = false - if use_trees == "all" then - use = true - end - for _, tree in ipairs(cfg.rocks_trees) do - if tree == cfg.rocks_dir then - use = true - end - if use then - local loaded = load_local_manifest(path.rocks_dir(tree)) - if loaded then - util.deep_merge(manifest, loaded) - end - end + local manifest = {} + path.map_trees(use_trees, function(tree) + local loaded = load_local_manifest(path.rocks_dir(tree)) + if loaded then + util.deep_merge(manifest, loaded) end - end + end) - local item = manifest and manifest.repository[name] + local item = next(manifest) and manifest.repository[name] if item then return util.keys(item) end diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index bbd928a0..17d9d52b 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -7,6 +7,7 @@ module("luarocks.path", package.seeall) local dir = require("luarocks.dir") local cfg = require("luarocks.cfg") local util = require("luarocks.util") +local deps = require("luarocks.deps") help_summary = "Return the currently configured package path." help_arguments = "" @@ -305,6 +306,27 @@ function use_tree(tree) cfg.deploy_lib_dir = deploy_lib_dir(tree) end +function map_trees(use_trees, fn, ...) + local result = {} + if use_trees == "one" then + table.insert(result, fn(cfg.root_dir, ...)) + elseif use_trees == "all" or use_trees == "order" then + local use = false + if use_trees == "all" then + use = true + end + for _, tree in ipairs(cfg.rocks_trees) do + if dir.normalize(tree) == dir.normalize(cfg.root_dir) then + use = true + end + if use then + table.insert(result, fn(tree, ...)) + end + end + end + return result +end + --- Return the pathname of the file that would be loaded for a module, indexed. -- @param module_name string: module name (eg. "socket.core") -- @param name string: name of the package (eg. "luasocket") @@ -352,10 +374,14 @@ end -- @return boolean This function always succeeds. function run(...) local flags = util.parse_flags(...) + local deps_mode = deps.flags_to_deps_mode(flags) + util.printout(cfg.export_lua_path:format(util.remove_path_dupes(package.path, ';'))) util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(package.cpath, ';'))) if flags["bin"] then - util.printout(cfg.export_path:format(util.remove_path_dupes(os.getenv("PATH"), cfg.export_path_separator), cfg.deploy_bin_dir)) + local bin_dirs = map_trees(deps_mode, deploy_bin_dir) + table.insert(bin_dirs, 1, os.getenv("PATH")) + util.printout(cfg.export_path:format(util.remove_path_dupes(table.concat(bin_dirs, cfg.export_path_separator), cfg.export_path_separator))) end return true end diff --git a/src/luarocks/util.lua b/src/luarocks/util.lua index 1a1cccf9..46802255 100644 --- a/src/luarocks/util.lua +++ b/src/luarocks/util.lua @@ -331,6 +331,8 @@ end -- @param list string: A path string (from $PATH or package.path) -- @param sep string: The separator function remove_path_dupes(list, sep) + assert(type(list) == "string") + assert(type(sep) == "string") local parts = split_string(list, sep) local final, entries = {}, {} for _, part in ipairs(parts) do -- cgit v1.2.3-55-g6feb From 7c8feab610fd956780c05700aac6d5d0b566da6d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 25 Sep 2012 19:48:26 -0300 Subject: Fix map_trees when fn does not return values. --- src/luarocks/path.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 17d9d52b..e613d112 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -309,7 +309,7 @@ end function map_trees(use_trees, fn, ...) local result = {} if use_trees == "one" then - table.insert(result, fn(cfg.root_dir, ...)) + table.insert(result, (fn(cfg.root_dir, ...)) or 0) elseif use_trees == "all" or use_trees == "order" then local use = false if use_trees == "all" then @@ -320,7 +320,7 @@ function map_trees(use_trees, fn, ...) use = true end if use then - table.insert(result, fn(tree, ...)) + table.insert(result, (fn(tree, ...)) or 0) end end end -- cgit v1.2.3-55-g6feb From 481fb3bb2e741957ccfcd68e569d83e7cf8bd5b7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 2 Oct 2012 20:11:28 -0300 Subject: Remove reference to unused module. --- src/luarocks/fs/lua.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index eba61214..879b5d75 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua @@ -23,7 +23,6 @@ if cfg.fs_use_modules then posix_ok, posix = pcall(require, "posix") end -local tar = require("luarocks.tools.tar") local patch = require("luarocks.tools.patch") local dir_stack = {} -- cgit v1.2.3-55-g6feb From c7b9fe0fc863ff09716ff592f3ae96fa3b0e0ca1 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 31 Oct 2012 01:45:27 -0200 Subject: Clean up and make use of deps-mode / deps_mode consistent. --nodeps is now an alias to --deps-mode=none --- src/luarocks/build.lua | 4 ++-- src/luarocks/cfg.lua | 2 +- src/luarocks/command_line.lua | 6 ++++++ src/luarocks/deps.lua | 43 +++++++++++++++++++----------------------- src/luarocks/install.lua | 8 ++------ src/luarocks/make.lua | 4 ++-- src/luarocks/make_manifest.lua | 2 +- src/luarocks/manif.lua | 28 ++++++++++++++++----------- src/luarocks/manif_core.lua | 8 ++++---- src/luarocks/path.lua | 10 +++++----- src/luarocks/remove.lua | 14 +++++--------- 11 files changed, 64 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index d68acabd..d61d6611 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -326,10 +326,10 @@ function run(...) assert(type(version) == "string" or not version) if flags["pack-binary-rock"] then - return pack.pack_binary_rock(name, version, do_build, name, version, deps.flags_to_deps_mode(flags)) + return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags)) else local ok, err = fs.check_command_permissions(flags) if not ok then return nil, err end - return do_build(name, version, deps.flags_to_deps_mode(flags)) + return do_build(name, version, deps.get_deps_mode(flags)) end end diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 136ea6be..0e43768e 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -165,7 +165,7 @@ local defaults = { use_extensions = false, accept_unknown_fields = false, fs_use_modules = true, - use_trees = "one", + deps_mode = "one", lua_modules_path = "/share/lua/"..lua_version, lib_modules_path = "/lib/lua/"..lua_version, diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index d08ffdfe..b4b20f84 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -7,6 +7,7 @@ local cfg = require("luarocks.cfg") local fs = require("luarocks.fs") local path = require("luarocks.path") local dir = require("luarocks.dir") +local deps = require("luarocks.deps") --- Display an error message and exit. -- @param message string: The error message. @@ -50,6 +51,7 @@ function run_command(...) if flags["only-from"] then flags["only-server"] = flags["only-from"] end if flags["only-sources-from"] then flags["only-sources"] = flags["only-sources-from"] end if flags["to"] then flags["tree"] = flags["to"] end + if flags["nodeps"] then flags["deps-mode"] = "none" end cfg.flags = flags @@ -83,6 +85,10 @@ function run_command(...) if cfg.local_by_default then flags["local"] = true end + + if flags["deps-mode"] and not deps.check_dep_trees_flag(flags["deps-mode"]) then + return nil, "Invalid entry for --deps-mode." + end if flags["tree"] then if flags["tree"] == true then diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index a409920a..6d5f3fef 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -312,14 +312,14 @@ end -- @return table or nil: A table containing fields 'name' and 'version' -- representing an installed rock which matches the given dependency, -- or nil if it could not be matched. -local function match_dep(dep, blacklist, use_trees) +local function match_dep(dep, blacklist, deps_mode) assert(type(dep) == "table") local versions if dep.name == "lua" then versions = { cfg.lua_version } else - versions = manif_core.get_versions(dep.name, use_trees) + versions = manif_core.get_versions(dep.name, deps_mode) end if not versions then return nil @@ -361,13 +361,13 @@ end -- in table format and values are tables containing fields 'name' and -- version' representing matches, and a table of missing dependencies -- parsed as tables. -function match_deps(rockspec, blacklist, use_trees) +function match_deps(rockspec, blacklist, deps_mode) assert(type(rockspec) == "table") assert(type(blacklist) == "table" or not blacklist) local matched, missing, no_upgrade = {}, {}, {} for _, dep in ipairs(rockspec.dependencies) do - local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, use_trees) + local found = match_dep(dep, blacklist and blacklist[dep.name] or nil, deps_mode) if found then if dep.name ~= "lua" then matched[dep] = found @@ -401,7 +401,7 @@ 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, use_trees) +function fulfill_dependencies(rockspec, deps_mode) local search = require("luarocks.search") local install = require("luarocks.install") @@ -433,7 +433,7 @@ function fulfill_dependencies(rockspec, use_trees) end end - local matched, missing, no_upgrade = match_deps(rockspec, nil, use_trees) + local matched, missing, no_upgrade = match_deps(rockspec, nil, deps_mode) if next(no_upgrade) then util.printerr("Missing dependencies for "..rockspec.name.." "..rockspec.version..":") @@ -467,7 +467,7 @@ function fulfill_dependencies(rockspec, use_trees) for _, dep in pairs(missing) do -- Double-check in case dependency was filled during recursion. - if not match_dep(dep, nil, use_trees) then + 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) @@ -640,7 +640,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, use_trees) +function scan_deps(results, missing, manifest, name, version, deps_mode) assert(type(results) == "table") assert(type(missing) == "table") assert(type(manifest) == "table") @@ -669,9 +669,9 @@ function scan_deps(results, missing, manifest, name, version, use_trees) else rockspec = { dependencies = deplist } end - local matched, failures = match_deps(rockspec, nil, use_trees) + local matched, failures = match_deps(rockspec, nil, deps_mode) for _, match in pairs(matched) do - results, missing = scan_deps(results, missing, manifest, match.name, match.version, use_trees) + results, missing = scan_deps(results, missing, manifest, match.name, match.version, deps_mode) end if next(failures) then for _, failure in pairs(failures) do @@ -682,30 +682,25 @@ function scan_deps(results, missing, manifest, name, version, use_trees) return results, missing end -local valid_trees = { +local valid_deps_modes = { one = true, order = true, all = true, + none = true, } -function check_trees_flag(flag) - return valid_trees[flag] +function check_deps_mode_flag(flag) + return valid_deps_modes[flag] end -function flags_to_deps_mode(flags) - if flags["nodeps"] then - return "none" - elseif flags["trees"] then - return flags["trees"] +function get_deps_mode(flags) + if flags["deps-mode"] then + return flags["deps-mode"] else - return cfg.use_trees + return cfg.deps_mode end end function deps_mode_to_flag(deps_mode) - if deps_mode == "none" then - return "--nodeps" - else - return "--trees="..deps_mode - end + return "--deps-mode="..deps_mode end diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index 0ffb95ef..e633ea23 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua @@ -127,13 +127,9 @@ function run(...) if name:match("%.rockspec$") or name:match("%.src%.rock$") then util.printout("Using "..name.."... switching to 'build' mode") local build = require("luarocks.build") - local build_flags = {} - if flags["local"] then table.insert(build_flags, "--local") end - if flags["nodeps"] then table.insert(build_flags, "--nodeps") end - if flags["trees"] then table.insert(build_flags, "--trees="..flags["trees"]) end - return build.run(name, unpack(build_flags)) + return build.run(name, deps.get_deps_mode(flags), flags["local"] and "--local") elseif name:match("%.rock$") then - return install_binary_rock(name, deps.flags_to_deps_mode(flags)) + return install_binary_rock(name, deps.get_deps_mode(flags)) else local search = require("luarocks.search") local results, err = search.find_suitable_rock(search.make_query(name:lower(), version)) diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 498445d8..69c2162f 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -63,10 +63,10 @@ function run(...) if not rspec then return nil, err end - return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.flags_to_deps_mode(flags)) + return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.get_deps_mode(flags)) else local ok, err = fs.check_command_permissions(flags) if not ok then return nil, err end - return build.build_rockspec(rockspec, false, true, deps.flags_to_deps_mode(flags)) + return build.build_rockspec(rockspec, false, true, deps.get_deps_mode(flags)) end end diff --git a/src/luarocks/make_manifest.lua b/src/luarocks/make_manifest.lua index e629b9de..845c9f8a 100644 --- a/src/luarocks/make_manifest.lua +++ b/src/luarocks/make_manifest.lua @@ -28,7 +28,7 @@ function run(...) util.printout("Making manifest for "..repo) - local ok, err = manif.make_manifest(repo, deps.flags_to_deps_mode(flags)) + local ok, err = manif.make_manifest(repo, deps.get_deps_mode(flags)) if ok then util.printout("Generating index.html for "..repo) index.make_index(repo) diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index b7554a33..414c3262 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -185,14 +185,17 @@ end -- and any dependency inconsistencies or missing dependencies are reported to -- standard error. -- @param manifest table: a manifest table. -local function update_dependencies(manifest, use_trees) +local function update_dependencies(manifest, deps_mode) + assert(type(manifest) == "table") + assert(type(deps_mode) == "string") + for pkg, versions in pairs(manifest.repository) do for version, repositories in pairs(versions) do local current = pkg.." "..version for _, repo in ipairs(repositories) do if repo.arch == "installed" then local missing - repo.dependencies, missing = deps.scan_deps({}, {}, manifest, pkg, version, use_trees) + repo.dependencies, missing = deps.scan_deps({}, {}, manifest, pkg, version, deps_mode) repo.dependencies[pkg] = nil if missing then for miss, err in pairs(missing) do @@ -214,9 +217,10 @@ end -- @param manifest table: A manifest table (must contain repository, modules, commands tables). -- It will be altered to include the search results. -- @return boolean or (nil, string): true in case of success, or nil followed by an error message. -local function store_results(results, manifest, use_trees) +local function store_results(results, manifest, deps_mode) assert(type(results) == "table") assert(type(manifest) == "table") + assert(type(deps_mode) == "string") for name, versions in pairs(results) do local pkgtable = manifest.repository[name] or {} @@ -239,7 +243,7 @@ local function store_results(results, manifest, use_trees) end manifest.repository[name] = pkgtable end - update_dependencies(manifest, use_trees) + update_dependencies(manifest, deps_mode) sort_package_matching_table(manifest.modules) sort_package_matching_table(manifest.commands) return true @@ -251,10 +255,11 @@ end -- @param repo A local repository directory. -- @return boolean or (nil, string): True if manifest was generated, -- or nil and an error message. -function make_manifest(repo, use_trees) +function make_manifest(repo, deps_mode) assert(type(repo) == "string") + assert(type(deps_mode) == "string") - if use_trees == "none" then use_trees = cfg.use_trees end + if deps_mode == "none" then deps_mode = cfg.deps_mode end if not fs.is_dir(repo) then return nil, "Cannot access repository at "..repo @@ -267,7 +272,7 @@ function make_manifest(repo, use_trees) local manifest = { repository = {}, modules = {}, commands = {} } manif_core.manifest_cache[repo] = manifest - local ok, err = store_results(results, manifest, use_trees) + local ok, err = store_results(results, manifest, deps_mode) if not ok then return nil, err end return save_table(repo, "manifest", manifest) @@ -283,19 +288,20 @@ end -- 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 update_manifest(name, version, repo, use_trees) +function update_manifest(name, version, repo, deps_mode) assert(type(name) == "string") assert(type(version) == "string") repo = path.rocks_dir(repo or cfg.root_dir) + assert(type(deps_mode) == "string") - if use_trees == "none" then use_trees = cfg.use_trees end + if deps_mode == "none" then deps_mode = cfg.deps_mode end util.printout("Updating manifest for "..repo) local manifest, err = load_manifest(repo) if not manifest then util.printerr("No existing manifest. Attempting to rebuild...") - local ok, err = make_manifest(repo, use_trees) + local ok, err = make_manifest(repo, deps_mode) if not ok then return nil, err end @@ -307,7 +313,7 @@ function update_manifest(name, version, repo, use_trees) local results = {[name] = {[version] = {{arch = "installed", repo = repo}}}} - local ok, err = store_results(results, manifest, use_trees) + local ok, err = store_results(results, manifest, deps_mode) if not ok then return nil, err end return save_table(repo, "manifest", manifest) diff --git a/src/luarocks/manif_core.lua b/src/luarocks/manif_core.lua index 6af99fe7..6424a1e8 100644 --- a/src/luarocks/manif_core.lua +++ b/src/luarocks/manif_core.lua @@ -53,18 +53,18 @@ end --- Get all versions of a package listed in a manifest file. -- @param name string: a package name. --- @param use_trees string: "one", to use only the currently +-- @param deps_mode string: "one", to use only the currently -- configured tree; "order" to select trees based on order -- (use the current tree and all trees below it on the list) -- or "all", to use all trees. -- @return table: An array of strings listing installed -- versions of a package. -function get_versions(name, use_trees) +function get_versions(name, deps_mode) assert(type(name) == "string") - assert(type(use_trees) == "string") + assert(type(deps_mode) == "string") local manifest = {} - path.map_trees(use_trees, function(tree) + path.map_trees(deps_mode, function(tree) local loaded = load_local_manifest(path.rocks_dir(tree)) if loaded then util.deep_merge(manifest, loaded) diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index 42d3b8f1..64a203ef 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua @@ -306,13 +306,13 @@ function use_tree(tree) cfg.deploy_lib_dir = deploy_lib_dir(tree) end -function map_trees(use_trees, fn, ...) +function map_trees(deps_mode, fn, ...) local result = {} - if use_trees == "one" then + if deps_mode == "one" then table.insert(result, (fn(cfg.root_dir, ...)) or 0) - elseif use_trees == "all" or use_trees == "order" then + elseif deps_mode == "all" or deps_mode == "order" then local use = false - if use_trees == "all" then + if deps_mode == "all" then use = true end for _, tree in ipairs(cfg.rocks_trees) do @@ -374,7 +374,7 @@ end -- @return boolean This function always succeeds. function run(...) local flags = util.parse_flags(...) - local deps_mode = deps.flags_to_deps_mode(flags) + local deps_mode = deps.get_deps_mode(flags) util.printout(cfg.export_lua_path:format(util.remove_path_dupes(package.path, ';'))) util.printout(cfg.export_lua_cpath:format(util.remove_path_dupes(package.cpath, ';'))) diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 261dc1c4..126cfdc8 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua @@ -28,7 +28,7 @@ To override this check and force the removal, use --force. -- @param versions array of string: the versions to be deleted. -- @return array of string: an empty table if no packages depend on any -- of the given list, or an array of strings in "name/version" format. -local function check_dependents(name, versions, use_trees) +local function check_dependents(name, versions, deps_mode) local dependents = {} local blacklist = {} blacklist[name] = {} @@ -44,7 +44,7 @@ local function check_dependents(name, versions, use_trees) for rock_version, _ in pairs(rock_versions) do local rockspec, err = fetch.load_rockspec(path.rockspec_file(rock_name, rock_version)) if rockspec then - local _, missing = deps.match_deps(rockspec, blacklist, use_trees) + local _, missing = deps.match_deps(rockspec, blacklist, deps_mode) if missing[name] then table.insert(dependents, { name = rock_name, version = rock_version }) end @@ -78,16 +78,12 @@ end -- successful, nil and an error message otherwise. function run(...) local flags, name, version = util.parse_flags(...) - - if flags["trees"] and type(flags["trees"]) ~= "string" then - return nil, "Invalid entry for --trees." - end if type(name) ~= "string" then return nil, "Argument missing, see help." end - local use_trees = flags["trees"] or cfg.use_trees + local deps_mode = flags["deps-mode"] or cfg.deps_mode local ok, err = fs.check_command_permissions(flags) if not ok then return nil, err end @@ -106,7 +102,7 @@ function run(...) util.printout(name.." "..table.concat(util.keys(versions), ", ").."...") util.printout() - local dependents = check_dependents(name, versions, use_trees) + local dependents = check_dependents(name, versions, deps_mode) if #dependents == 0 or flags["force"] then if #dependents > 0 then @@ -118,7 +114,7 @@ function run(...) end local ok, err = delete_versions(name, versions) if not ok then return nil, err end - ok, err = manif.make_manifest(cfg.rocks_dir, use_trees) + ok, err = manif.make_manifest(cfg.rocks_dir, deps_mode) if not ok then return nil, err end else if not second then -- cgit v1.2.3-55-g6feb From a94d8e04dfde6b35bb1ac6bdc1d4081b1d48cbf3 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 2 Nov 2012 06:54:45 -0200 Subject: Add documentation --- src/luarocks/list.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua index f56fc7e9..9a4630ff 100644 --- a/src/luarocks/list.lua +++ b/src/luarocks/list.lua @@ -9,9 +9,11 @@ local util = require("luarocks.util") local path = require("luarocks.path") help_summary = "Lists currently installed rocks." - +help_arguments = "[--porcelain] " help = [[ - is a substring of a rock name to filter by. + is a substring of a rock name to filter by. + +--porcelain Produce machine-friendly output. ]] --- Driver function for "list" command. -- cgit v1.2.3-55-g6feb From 455fcc2385c4e6be8e1f756d8a6997c4b67650f6 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 2 Nov 2012 06:54:57 -0200 Subject: Honor --tree in list command. --- src/luarocks/list.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/luarocks/list.lua b/src/luarocks/list.lua index 9a4630ff..6081ed43 100644 --- a/src/luarocks/list.lua +++ b/src/luarocks/list.lua @@ -25,7 +25,11 @@ function run(...) local results = {} local query = search.make_query(filter and filter:lower() or "", version) query.exact_name = false - for _, tree in ipairs(cfg.rocks_trees) do + local trees = cfg.rocks_trees + if flags["tree"] then + trees = { flags["tree"] } + end + for _, tree in ipairs(trees) do search.manifest_search(results, path.rocks_dir(tree), query) end util.title("Installed rocks:", flags["porcelain"]) -- cgit v1.2.3-55-g6feb From 0575ba154b102c4a8a4f3b75c5d9747c488ab719 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 2 Nov 2012 06:55:27 -0200 Subject: Fix behavior of --nodeps --- src/luarocks/command_line.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index b4b20f84..9e499fc2 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -4,7 +4,6 @@ module("luarocks.command_line", package.seeall) local util = require("luarocks.util") local cfg = require("luarocks.cfg") -local fs = require("luarocks.fs") local path = require("luarocks.path") local dir = require("luarocks.dir") local deps = require("luarocks.deps") @@ -51,7 +50,10 @@ function run_command(...) if flags["only-from"] then flags["only-server"] = flags["only-from"] end if flags["only-sources-from"] then flags["only-sources"] = flags["only-sources-from"] end if flags["to"] then flags["tree"] = flags["to"] end - if flags["nodeps"] then flags["deps-mode"] = "none" end + if flags["nodeps"] then + flags["deps-mode"] = "none" + table.insert(args, "--deps-mode=none") + end cfg.flags = flags @@ -86,14 +88,15 @@ function run_command(...) flags["local"] = true end - if flags["deps-mode"] and not deps.check_dep_trees_flag(flags["deps-mode"]) then - return nil, "Invalid entry for --deps-mode." + if flags["deps-mode"] and not deps.check_deps_mode_flag(flags["deps-mode"]) then + die("Invalid entry for --deps-mode.") end if flags["tree"] then - if flags["tree"] == true then + if flags["tree"] == true or flags["tree"] == "" then die("Argument error: use --tree=") end + local fs = require("luarocks.fs") local root_dir = fs.absolute_name(flags["tree"]) path.use_tree(root_dir) elseif flags["local"] then @@ -142,6 +145,12 @@ function run_command(...) end if commands[command] then + -- TODO the interface of run should be modified, to receive the + -- flags table and the (possibly unpacked) nonflags arguments. + -- This would remove redundant parsing of arguments. + -- I'm not changing this now to avoid messing with the run() + -- interface, which I know some people use (even though + -- I never published it as a public API...) local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) die(debug.traceback("LuaRocks "..cfg.program_version .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" -- cgit v1.2.3-55-g6feb From f011442df99e775e0fe8f28b4c84b59fcd787597 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 2 Nov 2012 08:06:49 -0200 Subject: remove dead code --- src/luarocks/dir.lua | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index c2309ff1..b496c962 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -26,10 +26,6 @@ function dir_name(pathname) return (pathname:gsub("/*$", ""):match("(.*/)[^/]*")) or "" end -function strip_base_dir(pathname) - return pathname:gsub("^[^/]*/", "") -end - --- Describe a path in a cross-platform way. -- Use this function to avoid platform-specific directory -- separators in other modules. Removes trailing slashes from -- cgit v1.2.3-55-g6feb From 8b8ff0119db3ad791d13a067fe7cfabdcc7bf329 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 2 Nov 2012 08:21:39 -0200 Subject: Make --tree in 'show' command compliant with the behavior of the flag in other commands. Rename old --tree to --rock-tree. --- src/luarocks/show.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/luarocks/show.lua b/src/luarocks/show.lua index dd84e794..7849934d 100644 --- a/src/luarocks/show.lua +++ b/src/luarocks/show.lua @@ -23,7 +23,7 @@ With these flags, return only the desired information: --deps packages this package depends on --rockspec the full path of the rockspec file --mversion the package version ---tree local tree where rock is installed +--rock-tree local tree where rock is installed --rock-dir data directory of the installed rock ]] @@ -79,7 +79,11 @@ function run(...) local query = search.make_query(name, version) query.exact_name = true local tree_map = {} - for _, tree in ipairs(cfg.rocks_trees) do + local trees = cfg.rocks_trees + if flags["tree"] then + trees = { flags["tree"] } + end + for _, tree in ipairs(trees) do local rocks_dir = path.rocks_dir(tree) tree_map[rocks_dir] = tree search.manifest_search(results, rocks_dir, query) @@ -111,7 +115,7 @@ function run(...) if not manifest then return nil,err end local minfo = manifest.repository[name][version][1] - if flags["tree"] then util.printout(repo) + if flags["rock-tree"] then util.printout(repo) elseif flags["rock-dir"] then util.printout(directory) elseif flags["home"] then util.printout(descript.homepage) elseif flags["modules"] then util.printout(keys_as_string(minfo.modules)) -- cgit v1.2.3-55-g6feb