From fdf700420bc30d98ba0070c539bde97fdbfd6344 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Sat, 13 Jul 2024 01:05:25 +0300 Subject: abandon manif + tests dir --- src/luarocks/core/manif-incomplete.lua | 143 +++++++++++++++++++++++++++++++++ src/luarocks/core/manif-original.lua | 114 -------------------------- src/luarocks/core/manif.lua | 99 ++++++++--------------- src/luarocks/dir-original.lua | 63 +++++++++++++++ src/luarocks/dir.lua | 50 ++++++------ 5 files changed, 268 insertions(+), 201 deletions(-) create mode 100644 src/luarocks/core/manif-incomplete.lua delete mode 100644 src/luarocks/core/manif-original.lua create mode 100644 src/luarocks/dir-original.lua (limited to 'src') diff --git a/src/luarocks/core/manif-incomplete.lua b/src/luarocks/core/manif-incomplete.lua new file mode 100644 index 00000000..c64795dc --- /dev/null +++ b/src/luarocks/core/manif-incomplete.lua @@ -0,0 +1,143 @@ +local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table + +local persist = require("luarocks.core.persist") +local cfg = require("luarocks.core.cfg") +local dir = require("luarocks.core.dir") +local util = require("luarocks.core.util") +local vers = require("luarocks.core.vers") +local path = require("luarocks.core.path") + + + + +local manif = {DependencyVersion = {}, Manifest = {}, Tree_manifest = {}, } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +local manifest_cache = {} + + + + + +function manif.cache_manifest(repo_url, lua_version, manifest) + lua_version = lua_version or cfg.lua_version + manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} + manifest_cache.repository[repo_url][lua_version] = manifest +end + + + + + +function manif.get_cached_manifest(repo_url, lua_version) + lua_version = lua_version or cfg.lua_version + return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] +end + + + + + + + + +function manif.manifest_loader(file, repo_url, lua_version) + local manifest, err, errcode = persist.load_into_table(file) + if not manifest and type(err) == "string" then + return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode + end + + manif.cache_manifest(repo_url, lua_version, manifest) + return manifest, err, errcode +end + + + + + + +function manif.fast_load_local_manifest(repo_url) + assert(type(repo_url) == "string") + + local cached_manifest = manif.get_cached_manifest(repo_url) + if cached_manifest then + return cached_manifest + end + + local pathname = dir.path(repo_url, "manifest") + return manif.manifest_loader(pathname, repo_url, nil) +end + +function manif.load_rocks_tree_manifests(deps_mode) + local trees = {} + path.map_trees(deps_mode, function(tree) + local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) + if manifest then + table.insert(trees, { tree = tree, manifest = manifest }) + end + end) + return trees +end + +function manif.scan_dependencies(name, version, tree_manifests, dest) + if dest[name] then + return + end + dest[name] = version + + for _, tree in ipairs(tree_manifests) do + local manifest = tree.manifest + + local pkgdeps + if manifest.dependencies and manifest.dependencies[name] then + pkgdeps = manifest.dependencies[name][version] + end + if pkgdeps then + for _, dep in ipairs(pkgdeps) do + local pkg, constraints = dep.name, dep.constraints + + for _, t in ipairs(tree_manifests) do + local entries = t.manifest.repository[pkg] + if entries then + for ver, _ in util.sortedpairs(entries, vers.compare_versions) do + if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then + manif.scan_dependencies(pkg, ver, tree_manifests, dest) + end + end + end + end + end + return + end + end +end + +return manif diff --git a/src/luarocks/core/manif-original.lua b/src/luarocks/core/manif-original.lua deleted file mode 100644 index 3925f636..00000000 --- a/src/luarocks/core/manif-original.lua +++ /dev/null @@ -1,114 +0,0 @@ - ---- Core functions for querying manifest files. -local manif = {} - -local persist = require("luarocks.core.persist") -local cfg = require("luarocks.core.cfg") -local dir = require("luarocks.core.dir") -local util = require("luarocks.core.util") -local vers = require("luarocks.core.vers") -local path = require("luarocks.core.path") -local require = nil --------------------------------------------------------------------------------- - --- Table with repository identifiers as keys and tables mapping --- Lua versions to cached loaded manifests as values. -local manifest_cache = {} - ---- Cache a loaded manifest. --- @param repo_url string: The repository identifier. --- @param lua_version string: Lua version in "5.x" format, defaults to installed version. --- @param manifest table: the manifest to be cached. -function manif.cache_manifest(repo_url, lua_version, manifest) - lua_version = lua_version or cfg.lua_version - manifest_cache[repo_url] = manifest_cache[repo_url] or {} - manifest_cache[repo_url][lua_version] = manifest -end - ---- Attempt to get cached loaded manifest. --- @param repo_url string: The repository identifier. --- @param lua_version string: Lua version in "5.x" format, defaults to installed version. --- @return table or nil: loaded manifest or nil if cache is empty. -function manif.get_cached_manifest(repo_url, lua_version) - lua_version = lua_version or cfg.lua_version - return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] -end - ---- Back-end function that actually loads the manifest --- and stores it in the manifest cache. --- @param file string: The local filename of the manifest file. --- @param repo_url string: The repository identifier. --- @param lua_version string: Lua version in "5.x" format, defaults to installed version. --- @return table or (nil, string, string): the manifest or nil, --- error message and error code ("open", "load", "run"). -function manif.manifest_loader(file, repo_url, lua_version) - local manifest, err, errcode = persist.load_into_table(file) - if not manifest then - return nil, "Failed loading manifest for "..repo_url..": "..err, errcode - end - manif.cache_manifest(repo_url, lua_version, manifest) - return manifest, err, errcode -end - ---- Load a local manifest describing a repository. --- 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.fast_load_local_manifest(repo_url) - assert(type(repo_url) == "string") - - local cached_manifest = manif.get_cached_manifest(repo_url) - if cached_manifest then - return cached_manifest - end - - local pathname = dir.path(repo_url, "manifest") - return manif.manifest_loader(pathname, repo_url, nil, true) -end - -function manif.load_rocks_tree_manifests(deps_mode) - local trees = {} - path.map_trees(deps_mode, function(tree) - local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) - if manifest then - table.insert(trees, {tree=tree, manifest=manifest}) - end - end) - return trees -end - -function manif.scan_dependencies(name, version, tree_manifests, dest) - if dest[name] then - return - end - dest[name] = version - - for _, tree in ipairs(tree_manifests) do - local manifest = tree.manifest - - local pkgdeps - if manifest.dependencies and manifest.dependencies[name] then - pkgdeps = manifest.dependencies[name][version] - end - if pkgdeps then - for _, dep in ipairs(pkgdeps) do - local pkg, constraints = dep.name, dep.constraints - - for _, t in ipairs(tree_manifests) do - local entries = t.manifest.repository[pkg] - if entries then - for ver, _ in util.sortedpairs(entries, vers.compare_versions) do - if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then - manif.scan_dependencies(pkg, ver, tree_manifests, dest) - end - end - end - end - end - return - end - end -end - -return manif diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index c64795dc..3925f636 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua @@ -1,4 +1,6 @@ -local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table + +--- Core functions for querying manifest files. +local manif = {} local persist = require("luarocks.core.persist") local cfg = require("luarocks.core.cfg") @@ -6,84 +8,53 @@ local dir = require("luarocks.core.dir") local util = require("luarocks.core.util") local vers = require("luarocks.core.vers") local path = require("luarocks.core.path") +local require = nil +-------------------------------------------------------------------------------- - - - -local manif = {DependencyVersion = {}, Manifest = {}, Tree_manifest = {}, } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +-- Table with repository identifiers as keys and tables mapping +-- Lua versions to cached loaded manifests as values. local manifest_cache = {} - - - - +--- Cache a loaded manifest. +-- @param repo_url string: The repository identifier. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. +-- @param manifest table: the manifest to be cached. function manif.cache_manifest(repo_url, lua_version, manifest) lua_version = lua_version or cfg.lua_version - manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} - manifest_cache.repository[repo_url][lua_version] = manifest + manifest_cache[repo_url] = manifest_cache[repo_url] or {} + manifest_cache[repo_url][lua_version] = manifest end - - - - +--- Attempt to get cached loaded manifest. +-- @param repo_url string: The repository identifier. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. +-- @return table or nil: loaded manifest or nil if cache is empty. function manif.get_cached_manifest(repo_url, lua_version) lua_version = lua_version or cfg.lua_version - return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] + return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] end - - - - - - - +--- Back-end function that actually loads the manifest +-- and stores it in the manifest cache. +-- @param file string: The local filename of the manifest file. +-- @param repo_url string: The repository identifier. +-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. +-- @return table or (nil, string, string): the manifest or nil, +-- error message and error code ("open", "load", "run"). function manif.manifest_loader(file, repo_url, lua_version) local manifest, err, errcode = persist.load_into_table(file) - if not manifest and type(err) == "string" then - return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode + if not manifest then + return nil, "Failed loading manifest for "..repo_url..": "..err, errcode end - manif.cache_manifest(repo_url, lua_version, manifest) return manifest, err, errcode end - - - - - +--- Load a local manifest describing a repository. +-- 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.fast_load_local_manifest(repo_url) assert(type(repo_url) == "string") @@ -93,15 +64,15 @@ function manif.fast_load_local_manifest(repo_url) end local pathname = dir.path(repo_url, "manifest") - return manif.manifest_loader(pathname, repo_url, nil) + return manif.manifest_loader(pathname, repo_url, nil, true) end function manif.load_rocks_tree_manifests(deps_mode) local trees = {} path.map_trees(deps_mode, function(tree) - local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) + local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) if manifest then - table.insert(trees, { tree = tree, manifest = manifest }) + table.insert(trees, {tree=tree, manifest=manifest}) end end) return trees diff --git a/src/luarocks/dir-original.lua b/src/luarocks/dir-original.lua new file mode 100644 index 00000000..be89e37b --- /dev/null +++ b/src/luarocks/dir-original.lua @@ -0,0 +1,63 @@ + +--- Generic utilities for handling pathnames. +local dir = {} + +local core = require("luarocks.core.dir") + +dir.path = core.path +dir.split_url = core.split_url +dir.normalize = core.normalize + +local dir_sep = package.config:sub(1, 1) + +--- Strip the path off a path+filename. +-- @param pathname string: A path+name, such as "/a/b/c" +-- or "\a\b\c". +-- @return string: The filename without its path, such as "c". +function dir.base_name(pathname) + assert(type(pathname) == "string") + + local b + b = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes + b = b:gsub("/*$", "") -- drop trailing slashes + b = b:match(".*[/\\]([^/\\]*)") -- match last component + b = b or pathname -- fallback to original if no slashes + + return b +end + +--- Strip the name off a path+filename. +-- @param pathname string: A path+name, such as "/a/b/c". +-- @return string: The filename without its path, such as "/a/b". +-- For entries such as "/a/b/", "/a" is returned. If there are +-- no directory separators in input, "" is returned. +function dir.dir_name(pathname) + assert(type(pathname) == "string") + + local d + d = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes + d = d:gsub("/*$", "") -- drop trailing slashes + d = d:match("(.*)[/]+[^/]*") -- match all components but the last + d = d or "" -- switch to "" if there's no match + d = d:gsub("/", dir_sep) -- decanonicalize to native slashes + + return d +end + +--- Returns true if protocol does not require additional tools. +-- @param protocol The protocol name +function dir.is_basic_protocol(protocol) + return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" +end + +function dir.deduce_base_dir(url) + -- for extensions like foo.tar.gz, "gz" is stripped first + local known_exts = {} + for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do + known_exts[ext] = "" + end + local base = dir.base_name(url) + return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", "")) +end + +return dir diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index be89e37b..f54f1458 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua @@ -1,7 +1,11 @@ +local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local package = _tl_compat and _tl_compat.package or package; local string = _tl_compat and _tl_compat.string or string ---- Generic utilities for handling pathnames. local dir = {} + + + + local core = require("luarocks.core.dir") dir.path = core.path @@ -10,50 +14,50 @@ dir.normalize = core.normalize local dir_sep = package.config:sub(1, 1) ---- Strip the path off a path+filename. --- @param pathname string: A path+name, such as "/a/b/c" --- or "\a\b\c". --- @return string: The filename without its path, such as "c". + + + + function dir.base_name(pathname) assert(type(pathname) == "string") local b - b = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes - b = b:gsub("/*$", "") -- drop trailing slashes - b = b:match(".*[/\\]([^/\\]*)") -- match last component - b = b or pathname -- fallback to original if no slashes + b = pathname:gsub("[/\\]", "/") + b = b:gsub("/*$", "") + b = b:match(".*[/\\]([^/\\]*)") + b = b or pathname return b end ---- Strip the name off a path+filename. --- @param pathname string: A path+name, such as "/a/b/c". --- @return string: The filename without its path, such as "/a/b". --- For entries such as "/a/b/", "/a" is returned. If there are --- no directory separators in input, "" is returned. + + + + + function dir.dir_name(pathname) assert(type(pathname) == "string") local d - d = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes - d = d:gsub("/*$", "") -- drop trailing slashes - d = d:match("(.*)[/]+[^/]*") -- match all components but the last - d = d or "" -- switch to "" if there's no match - d = d:gsub("/", dir_sep) -- decanonicalize to native slashes + d = pathname:gsub("[/\\]", "/") + d = d:gsub("/*$", "") + d = d:match("(.*)[/]+[^/]*") + d = d or "" + d = d:gsub("/", dir_sep) return d end ---- Returns true if protocol does not require additional tools. --- @param protocol The protocol name + + function dir.is_basic_protocol(protocol) return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" end function dir.deduce_base_dir(url) - -- for extensions like foo.tar.gz, "gz" is stripped first + local known_exts = {} - for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do + for _, ext in ipairs({ "zip", "git", "tgz", "tar", "gz", "bz2" }) do known_exts[ext] = "" end local base = dir.base_name(url) -- cgit v1.2.3-55-g6feb