From 8bbf9ea3e4a6ce56708df556f2909349a0c93c9e Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 13 Apr 2018 12:30:21 -0300 Subject: Use a single load_manifest function throughout the program --- src/luarocks/core/manif.lua | 5 ++--- src/luarocks/loader.lua | 2 +- src/luarocks/manif.lua | 37 +++++++++++++++++++++++++------------ src/luarocks/manif/writer.lua | 6 +++--- src/luarocks/queries.lua | 4 ++++ 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index cd8d7a06..7a561f8a 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua @@ -48,12 +48,11 @@ function manif.manifest_loader(file, repo_url, lua_version) end --- Load a local manifest describing a repository. --- All functions that use manifest tables assume they were obtained --- through either this function or load_manifest. +-- This is used by the luarocks.loader only. -- @param repo_url string: URL or pathname for the repository. -- @return table or (nil, string, string): A table representing the manifest, -- or nil followed by an error message and an error code, see manifest_loader. -function manif.load_local_manifest(repo_url) +function manif.fast_load_local_manifest(repo_url) assert(type(repo_url) == "string") local cached_manifest = manif.get_cached_manifest(repo_url) diff --git a/src/luarocks/loader.lua b/src/luarocks/loader.lua index 84cdd696..078e4068 100644 --- a/src/luarocks/loader.lua +++ b/src/luarocks/loader.lua @@ -58,7 +58,7 @@ local function load_rocks_trees() local any_ok = false local trees = {} for _, tree in ipairs(cfg.rocks_trees) do - local manifest, err = manif.load_local_manifest(path.rocks_dir(tree)) + local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) if manifest then any_ok = true table.insert(trees, {tree=tree, manifest=manifest}) diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 146d5d73..a982c6f7 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -12,6 +12,7 @@ local fs = require("luarocks.fs") local cfg = require("luarocks.core.cfg") local path = require("luarocks.path") local util = require("luarocks.util") +local queries = require("luarocks.queries") local type_manifest = require("luarocks.type.manifest") manif.cache_manifest = core.cache_manifest @@ -27,15 +28,24 @@ local function check_manifest(repo_url, manifest, globals) return manifest end -function manif.load_local_manifest(repo_url) - local manifest, err, errcode = core.load_local_manifest(repo_url) - if not manifest then - return nil, err, errcode - end - if err then - return check_manifest(repo_url, manifest, err) +local postprocess_dependencies +do + local postprocess_check = setmetatable({}, { __mode = "k" }) + postprocess_dependencies = function(manifest) + if postprocess_check[manifest] then + return + end + if manifest.dependencies then + for name, versions in pairs(manifest.dependencies) do + for version, entries in pairs(versions) do + for k, v in pairs(entries) do + entries[k] = queries.from_persisted_table(v) + end + end + end + end + postprocess_check[manifest] = true end - return manifest end function manif.load_rock_manifest(name, version, root) @@ -73,7 +83,7 @@ end --- Load a local or remote manifest describing a repository. -- All functions that use manifest tables assume they were obtained --- through either this function or load_local_manifest. +-- through this function. -- @param repo_url string: URL or pathname for the repository. -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. -- @return table or (nil, string, [string]): A table representing the manifest, @@ -85,6 +95,7 @@ function manif.load_manifest(repo_url, lua_version) local cached_manifest = core.get_cached_manifest(repo_url, lua_version) if cached_manifest then + postprocess_dependencies(cached_manifest) return cached_manifest end @@ -134,6 +145,8 @@ function manif.load_manifest(repo_url, lua_version) if not manifest then return nil, err, errcode end + + postprocess_dependencies(manifest) return check_manifest(repo_url, manifest, err) end @@ -153,7 +166,7 @@ local function get_providers(item_type, item_name, repo) assert(type(item_type) == "string") assert(type(item_name) == "string") local rocks_dir = path.rocks_dir(repo or cfg.root_dir) - local manifest = manif.load_local_manifest(rocks_dir) + local manifest = manif.load_manifest(rocks_dir) return manifest and manifest[item_type .. "s"][item_name] end @@ -189,7 +202,7 @@ end -- and path to the providing file relatively to that subtree. function manif.get_providing_file(name, version, item_type, item_name, repo) local rocks_dir = path.rocks_dir(repo or cfg.root_dir) - local manifest = manif.load_local_manifest(rocks_dir) + local manifest = manif.load_manifest(rocks_dir) local entry_table = manifest.repository[name][version][1] local file_path = entry_table[item_type .. "s"][item_name] @@ -239,7 +252,7 @@ function manif.get_versions(dep, deps_mode) local version_set = {} path.map_trees(deps_mode, function(tree) - local manifest = manif.load_local_manifest(path.rocks_dir(tree)) + local manifest = manif.load_manifest(path.rocks_dir(tree)) if manifest and manifest.repository[name] then for version in pairs(manifest.repository[name]) do diff --git a/src/luarocks/manif/writer.lua b/src/luarocks/manif/writer.lua index 07628ea2..8e8d5525 100644 --- a/src/luarocks/manif/writer.lua +++ b/src/luarocks/manif/writer.lua @@ -367,7 +367,7 @@ function writer.add_to_manifest(name, version, repo, deps_mode) if deps_mode == "none" then deps_mode = cfg.deps_mode end - local manifest, err = manif.load_local_manifest(rocks_dir) + local manifest, err = manif.load_manifest(rocks_dir) if not manifest then util.printerr("No existing manifest. Attempting to rebuild...") -- Manifest built by `writer.make_manifest` should already @@ -404,7 +404,7 @@ function writer.remove_from_manifest(name, version, repo, deps_mode) if deps_mode == "none" then deps_mode = cfg.deps_mode end - local manifest, err = manif.load_local_manifest(rocks_dir) + local manifest, err = manif.load_manifest(rocks_dir) if not manifest then util.printerr("No existing manifest. Attempting to rebuild...") -- Manifest built by `writer.make_manifest` should already @@ -442,7 +442,7 @@ function writer.check_dependencies(repo, deps_mode) assert(type(deps_mode) == "string") if deps_mode == "none" then deps_mode = cfg.deps_mode end - local manifest = manif.load_local_manifest(rocks_dir) + local manifest = manif.load_manifest(rocks_dir) if not manifest then return end diff --git a/src/luarocks/queries.lua b/src/luarocks/queries.lua index 6a9166ba..2699aa8c 100644 --- a/src/luarocks/queries.lua +++ b/src/luarocks/queries.lua @@ -172,6 +172,10 @@ do end end +function queries.from_persisted_table(tbl) + return setmetatable(tbl, query_mt) +end + --- Build a string representation of a query package name. -- Includes namespace, name and version, but not arch or constraints. -- @param query table: a query table -- cgit v1.2.3-55-g6feb