From 9094232f4de7827f464370d4bfae65f4dab96d98 Mon Sep 17 00:00:00 2001 From: V1K1NGbg Date: Tue, 9 Jul 2024 21:09:57 +0300 Subject: moved Constraints to vers and some work on manifest --- src/luarocks/core/manif.tl | 93 +++++++++++++++++++++------------------------- src/luarocks/core/util.lua | 1 - src/luarocks/core/util.tl | 1 - src/luarocks/core/vers.lua | 10 ++++- src/luarocks/core/vers.tl | 10 ++++- 5 files changed, 58 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl index 6f7fd458..24178f14 100644 --- a/src/luarocks/core/manif.tl +++ b/src/luarocks/core/manif.tl @@ -1,6 +1,24 @@ --- Core functions for querying manifest files. local record manif + + record DependencyVersion + constraints: {Constraints} --? vers.Constraints + name: string + end + + record Manifest + arch: string + commands: {string: {string}} + dependencies: {string: {string: {DependencyVersion}}} + modules: {string: {string}} + repository: {string: {string: Manifest}} + end + + record Tree_manifest + tree: cfg.Tree + manifest: Manifest + end end local persist = require("luarocks.core.persist") --! @@ -10,63 +28,35 @@ local util = require("luarocks.core.util") local vers = require("luarocks.core.vers") local path = require("luarocks.core.path") -------------------------------------------------------------------------------- + +local type Constraints = vers.Constraints +local type DependencyVersion = manif.DependencyVersion +local type Manifest = manif.Manifest +local type Tree_manifest = manif.Tree_manifest -local record Constraints - op: string - version: {vers.Version} -end - -local record DependencyVersion - constraints: {Constraints} - name: string -end - -local record Module - name: string --! ["tl.tl"] = {"tl/0.15.3-1"} - name_version: string --! or file location -end - -local record RepositoryVersion - version: string - manifests: {Manifest} -end - -local record Repository - name: string - version: {RepositoryVersion} --! multiple versions in the same repository - -end -local record Manifest --! - arch: string --! only for repository - commands: {string:{string}} - dependencies: {string: {string: DependencyVersion}} - modules: {Module} - repository: {Repository} --! no repository for repositoyry -end - -- Table with repository identifiers as keys and tables mapping -- Lua versions to cached loaded manifests as values. -local manifest_cache: {any: {any: any}} = {} --? +local manifest_cache: Manifest= {} --? --- 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: string, lua_version: string, manifest: {any: any}) +function manif.cache_manifest(repo_url: string, lua_version: string, manifest: 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 + manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} + manifest_cache.repository[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: string, lua_version: string): {any: any} +function manif.get_cached_manifest(repo_url: string, lua_version: string): Manifest lua_version = lua_version or cfg.lua_version - return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] --! + return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] --! end --- Back-end function that actually loads the manifest @@ -76,9 +66,9 @@ end -- @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: string, repo_url: string, lua_version: string): {any: any} | nil, string, string - local manifest, err, errcode: {any: any} | nil, string, string = persist.load_into_table(file) - if not manifest is {any: any} then +function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest | nil, string, string + local manifest, err, errcode: {any: any}, {any: any} | string, string = persist.load_into_table(file) + if not manifest is Manifest then --! Manifest != {any:any} return nil, "Failed loading manifest for "..repo_url..": "..err, errcode end manif.cache_manifest(repo_url, lua_version, manifest) @@ -90,7 +80,7 @@ end -- @param repo_url string: URL or pathname for the repository. -- @return table or (nil, string, string): A table representing the manifest, -- or nil followed by an error message and an error code, see manifest_loader. -function manif.fast_load_local_manifest(repo_url: string): {any: any} | nil, string, string +function manif.fast_load_local_manifest(repo_url: string): Manifest | nil, string, string local cached_manifest = manif.get_cached_manifest(repo_url) if cached_manifest then @@ -98,21 +88,22 @@ function manif.fast_load_local_manifest(repo_url: string): {any: any} | nil, str 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) + return manif.manifest_loader(pathname, repo_url, nil) end -function manif.load_rocks_tree_manifests(deps_mode: string): {any: any} +function manif.load_rocks_tree_manifests(deps_mode: string): {Tree_manifest} local trees = {} - path.map_trees(deps_mode, function(tree) + path.map_trees(deps_mode, function(tree: cfg.Tree) --! tree: cfg.Tree local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree)) if manifest then - table.insert(trees, {tree=tree, manifest=manifest}) + local tree_manifest: Tree_manifest = {tree=tree, manifest=manifest} + table.insert(trees, tree_manifest) end end) return trees end -function manif.scan_dependencies(name: any, version: any, tree_manifests: {{any: {any: {any: {any: {{any: any}}}}}}}, dest: {any: any}) --? string or number, {{any: {any: {any: {any: {{any: any}}}}}}}??? +function manif.scan_dependencies(name: string, version: string, tree_manifests: {Tree_manifest}, dest: {any: any}) if dest[name] then return end @@ -121,7 +112,7 @@ function manif.scan_dependencies(name: any, version: any, tree_manifests: {{any: for _, tree in ipairs(tree_manifests) do local manifest = tree.manifest - local pkgdeps: {{any: any}} + local pkgdeps: {DependencyVersion} if manifest.dependencies and manifest.dependencies[name] then pkgdeps = manifest.dependencies[name][version] end @@ -132,8 +123,8 @@ function manif.scan_dependencies(name: any, version: any, tree_manifests: {{any: 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 --! entries should be a {any: any} - if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) 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 diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 38d7ae45..9ddf27a2 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua @@ -279,7 +279,6 @@ end function util.sortedpairs(tbl, sort_function) - if not sort_function then sort_function = default_sort end diff --git a/src/luarocks/core/util.tl b/src/luarocks/core/util.tl index e1e473da..759a7147 100644 --- a/src/luarocks/core/util.tl +++ b/src/luarocks/core/util.tl @@ -279,7 +279,6 @@ end -- and the value. -- @return function: the iterator function. function util.sortedpairs(tbl: {any: any}, sort_function: CompFn | {any} | nil): function(): any, any, any - -- sort_function = sort_function or default_sort --? if not sort_function then sort_function = default_sort end diff --git a/src/luarocks/core/vers.lua b/src/luarocks/core/vers.lua index 097e8199..02e7b1da 100644 --- a/src/luarocks/core/vers.lua +++ b/src/luarocks/core/vers.lua @@ -1,4 +1,9 @@ -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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local pairs = _tl_compat and _tl_compat.pairs or pairs; local string = _tl_compat and _tl_compat.string or string; local vers = {Version = {}, } +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 ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local math = _tl_compat and _tl_compat.math or math; local string = _tl_compat and _tl_compat.string or string; local vers = {Version = {}, Constraints = {}, } + + + + + @@ -24,6 +29,7 @@ local deltas = { + local version_mt = { @@ -193,7 +199,7 @@ end function vers.match_constraints(version, constraints) local ok = true setmetatable(version, version_mt) - for _, constr in pairs(constraints) do + for _, constr in ipairs(constraints) do local constr_version, constr_op = constr.version, constr.op local cv if type(constr_version) == "string" then diff --git a/src/luarocks/core/vers.tl b/src/luarocks/core/vers.tl index 7b2659e4..b1dcd795 100644 --- a/src/luarocks/core/vers.tl +++ b/src/luarocks/core/vers.tl @@ -7,6 +7,11 @@ local record vers metamethod __lt: function(Version, Version): boolean metamethod __le: function(Version, Version): boolean end + + record Constraints + op: string + version: Version | string + end end local util = require("luarocks.core.util") @@ -23,6 +28,7 @@ local deltas: {string: integer} = { } local type Version = vers.Version +local type Constraints = vers.Constraints local version_mt: metatable = { --- Equality comparison for versions. @@ -190,10 +196,10 @@ end -- @param constraints table: An array of constraints in table format. -- @return boolean: True if version satisfies all constraints, -- false otherwise. -function vers.match_constraints(version: Version, constraints: {any: {any: Version | string}}): boolean +function vers.match_constraints(version: Version, constraints: {Constraints}): boolean --! local ok = true setmetatable(version, version_mt) - for _, constr in pairs(constraints) do + for _, constr in ipairs(constraints) do local constr_version, constr_op = constr.version, constr.op local cv: Version if constr_version is string then -- cgit v1.2.3-55-g6feb