aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-09 21:09:57 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:49:17 +0300
commit9094232f4de7827f464370d4bfae65f4dab96d98 (patch)
tree44e32e6341bf5107063eb40975dd94ceae4b0b75
parent179802ab0b5ce7792824f34116d58b2bdacb1a65 (diff)
downloadluarocks-9094232f4de7827f464370d4bfae65f4dab96d98.tar.gz
luarocks-9094232f4de7827f464370d4bfae65f4dab96d98.tar.bz2
luarocks-9094232f4de7827f464370d4bfae65f4dab96d98.zip
moved Constraints to vers and some work on manifest
-rw-r--r--src/luarocks/core/manif.tl93
-rw-r--r--src/luarocks/core/util.lua1
-rw-r--r--src/luarocks/core/util.tl1
-rw-r--r--src/luarocks/core/vers.lua10
-rw-r--r--src/luarocks/core/vers.tl10
5 files changed, 58 insertions, 57 deletions
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 @@
1 1
2--- Core functions for querying manifest files. 2--- Core functions for querying manifest files.
3local record manif 3local record manif
4
5 record DependencyVersion
6 constraints: {Constraints} --? vers.Constraints
7 name: string
8 end
9
10 record Manifest
11 arch: string
12 commands: {string: {string}}
13 dependencies: {string: {string: {DependencyVersion}}}
14 modules: {string: {string}}
15 repository: {string: {string: Manifest}}
16 end
17
18 record Tree_manifest
19 tree: cfg.Tree
20 manifest: Manifest
21 end
4end 22end
5 23
6local persist = require("luarocks.core.persist") --! 24local persist = require("luarocks.core.persist") --!
@@ -10,63 +28,35 @@ local util = require("luarocks.core.util")
10local vers = require("luarocks.core.vers") 28local vers = require("luarocks.core.vers")
11local path = require("luarocks.core.path") 29local path = require("luarocks.core.path")
12-------------------------------------------------------------------------------- 30--------------------------------------------------------------------------------
31
32local type Constraints = vers.Constraints
33local type DependencyVersion = manif.DependencyVersion
34local type Manifest = manif.Manifest
35local type Tree_manifest = manif.Tree_manifest
13 36
14local record Constraints
15 op: string
16 version: {vers.Version}
17end
18
19local record DependencyVersion
20 constraints: {Constraints}
21 name: string
22end
23
24local record Module
25 name: string --! ["tl.tl"] = {"tl/0.15.3-1"}
26 name_version: string --! or file location
27end
28
29local record RepositoryVersion
30 version: string
31 manifests: {Manifest}
32end
33
34local record Repository
35 name: string
36 version: {RepositoryVersion} --! multiple versions in the same repository
37
38end
39 37
40local record Manifest --!
41 arch: string --! only for repository
42 commands: {string:{string}}
43 dependencies: {string: {string: DependencyVersion}}
44 modules: {Module}
45 repository: {Repository} --! no repository for repositoyry
46end
47
48 38
49-- Table with repository identifiers as keys and tables mapping 39-- Table with repository identifiers as keys and tables mapping
50-- Lua versions to cached loaded manifests as values. 40-- Lua versions to cached loaded manifests as values.
51local manifest_cache: {any: {any: any}} = {} --? 41local manifest_cache: Manifest= {} --?
52 42
53--- Cache a loaded manifest. 43--- Cache a loaded manifest.
54-- @param repo_url string: The repository identifier. 44-- @param repo_url string: The repository identifier.
55-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. 45-- @param lua_version string: Lua version in "5.x" format, defaults to installed version.
56-- @param manifest table: the manifest to be cached. 46-- @param manifest table: the manifest to be cached.
57function manif.cache_manifest(repo_url: string, lua_version: string, manifest: {any: any}) 47function manif.cache_manifest(repo_url: string, lua_version: string, manifest: Manifest)
58 lua_version = lua_version or cfg.lua_version 48 lua_version = lua_version or cfg.lua_version
59 manifest_cache[repo_url] = manifest_cache[repo_url] or {} 49 manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {}
60 manifest_cache[repo_url][lua_version] = manifest 50 manifest_cache.repository[repo_url][lua_version] = manifest
61end 51end
62 52
63--- Attempt to get cached loaded manifest. 53--- Attempt to get cached loaded manifest.
64-- @param repo_url string: The repository identifier. 54-- @param repo_url string: The repository identifier.
65-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. 55-- @param lua_version string: Lua version in "5.x" format, defaults to installed version.
66-- @return table or nil: loaded manifest or nil if cache is empty. 56-- @return table or nil: loaded manifest or nil if cache is empty.
67function manif.get_cached_manifest(repo_url: string, lua_version: string): {any: any} 57function manif.get_cached_manifest(repo_url: string, lua_version: string): Manifest
68 lua_version = lua_version or cfg.lua_version 58 lua_version = lua_version or cfg.lua_version
69 return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] --! 59 return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] --!
70end 60end
71 61
72--- Back-end function that actually loads the manifest 62--- Back-end function that actually loads the manifest
@@ -76,9 +66,9 @@ end
76-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. 66-- @param lua_version string: Lua version in "5.x" format, defaults to installed version.
77-- @return table or (nil, string, string): the manifest or nil, 67-- @return table or (nil, string, string): the manifest or nil,
78-- error message and error code ("open", "load", "run"). 68-- error message and error code ("open", "load", "run").
79function manif.manifest_loader(file: string, repo_url: string, lua_version: string): {any: any} | nil, string, string 69function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest | nil, string, string
80 local manifest, err, errcode: {any: any} | nil, string, string = persist.load_into_table(file) 70 local manifest, err, errcode: {any: any}, {any: any} | string, string = persist.load_into_table(file)
81 if not manifest is {any: any} then 71 if not manifest is Manifest then --! Manifest != {any:any}
82 return nil, "Failed loading manifest for "..repo_url..": "..err, errcode 72 return nil, "Failed loading manifest for "..repo_url..": "..err, errcode
83 end 73 end
84 manif.cache_manifest(repo_url, lua_version, manifest) 74 manif.cache_manifest(repo_url, lua_version, manifest)
@@ -90,7 +80,7 @@ end
90-- @param repo_url string: URL or pathname for the repository. 80-- @param repo_url string: URL or pathname for the repository.
91-- @return table or (nil, string, string): A table representing the manifest, 81-- @return table or (nil, string, string): A table representing the manifest,
92-- or nil followed by an error message and an error code, see manifest_loader. 82-- or nil followed by an error message and an error code, see manifest_loader.
93function manif.fast_load_local_manifest(repo_url: string): {any: any} | nil, string, string 83function manif.fast_load_local_manifest(repo_url: string): Manifest | nil, string, string
94 84
95 local cached_manifest = manif.get_cached_manifest(repo_url) 85 local cached_manifest = manif.get_cached_manifest(repo_url)
96 if cached_manifest then 86 if cached_manifest then
@@ -98,21 +88,22 @@ function manif.fast_load_local_manifest(repo_url: string): {any: any} | nil, str
98 end 88 end
99 89
100 local pathname = dir.path(repo_url, "manifest") 90 local pathname = dir.path(repo_url, "manifest")
101 return manif.manifest_loader(pathname, repo_url, nil) --? return manif.manifest_loader(pathname, repo_url, nil, true) 91 return manif.manifest_loader(pathname, repo_url, nil)
102end 92end
103 93
104function manif.load_rocks_tree_manifests(deps_mode: string): {any: any} 94function manif.load_rocks_tree_manifests(deps_mode: string): {Tree_manifest}
105 local trees = {} 95 local trees = {}
106 path.map_trees(deps_mode, function(tree) 96 path.map_trees(deps_mode, function(tree: cfg.Tree) --! tree: cfg.Tree
107 local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree)) 97 local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree))
108 if manifest then 98 if manifest then
109 table.insert(trees, {tree=tree, manifest=manifest}) 99 local tree_manifest: Tree_manifest = {tree=tree, manifest=manifest}
100 table.insert(trees, tree_manifest)
110 end 101 end
111 end) 102 end)
112 return trees 103 return trees
113end 104end
114 105
115function 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}}}}}}}??? 106function manif.scan_dependencies(name: string, version: string, tree_manifests: {Tree_manifest}, dest: {any: any})
116 if dest[name] then 107 if dest[name] then
117 return 108 return
118 end 109 end
@@ -121,7 +112,7 @@ function manif.scan_dependencies(name: any, version: any, tree_manifests: {{any:
121 for _, tree in ipairs(tree_manifests) do 112 for _, tree in ipairs(tree_manifests) do
122 local manifest = tree.manifest 113 local manifest = tree.manifest
123 114
124 local pkgdeps: {{any: any}} 115 local pkgdeps: {DependencyVersion}
125 if manifest.dependencies and manifest.dependencies[name] then 116 if manifest.dependencies and manifest.dependencies[name] then
126 pkgdeps = manifest.dependencies[name][version] 117 pkgdeps = manifest.dependencies[name][version]
127 end 118 end
@@ -132,8 +123,8 @@ function manif.scan_dependencies(name: any, version: any, tree_manifests: {{any:
132 for _, t in ipairs(tree_manifests) do 123 for _, t in ipairs(tree_manifests) do
133 local entries = t.manifest.repository[pkg] 124 local entries = t.manifest.repository[pkg]
134 if entries then 125 if entries then
135 for ver, _ in util.sortedpairs(entries, vers.compare_versions) do --! entries should be a {any: any} 126 for ver, _ in util.sortedpairs(entries, vers.compare_versions) do
136 if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then 127 if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then --!
137 manif.scan_dependencies(pkg, ver, tree_manifests, dest) 128 manif.scan_dependencies(pkg, ver, tree_manifests, dest)
138 end 129 end
139 end 130 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
279 279
280 280
281function util.sortedpairs(tbl, sort_function) 281function util.sortedpairs(tbl, sort_function)
282
283 if not sort_function then 282 if not sort_function then
284 sort_function = default_sort 283 sort_function = default_sort
285 end 284 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
279-- and the value. 279-- and the value.
280-- @return function: the iterator function. 280-- @return function: the iterator function.
281function util.sortedpairs(tbl: {any: any}, sort_function: CompFn | {any} | nil): function(): any, any, any 281function util.sortedpairs(tbl: {any: any}, sort_function: CompFn | {any} | nil): function(): any, any, any
282 -- sort_function = sort_function or default_sort --?
283 if not sort_function then 282 if not sort_function then
284 sort_function = default_sort 283 sort_function = default_sort
285 end 284 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 @@
1local _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 = {}, } 1local _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 = {}, }
2
3
4
5
6
2 7
3 8
4 9
@@ -24,6 +29,7 @@ local deltas = {
24 29
25 30
26 31
32
27local version_mt = { 33local version_mt = {
28 34
29 35
@@ -193,7 +199,7 @@ end
193function vers.match_constraints(version, constraints) 199function vers.match_constraints(version, constraints)
194 local ok = true 200 local ok = true
195 setmetatable(version, version_mt) 201 setmetatable(version, version_mt)
196 for _, constr in pairs(constraints) do 202 for _, constr in ipairs(constraints) do
197 local constr_version, constr_op = constr.version, constr.op 203 local constr_version, constr_op = constr.version, constr.op
198 local cv 204 local cv
199 if type(constr_version) == "string" then 205 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
7 metamethod __lt: function(Version, Version): boolean 7 metamethod __lt: function(Version, Version): boolean
8 metamethod __le: function(Version, Version): boolean 8 metamethod __le: function(Version, Version): boolean
9 end 9 end
10
11 record Constraints
12 op: string
13 version: Version | string
14 end
10end 15end
11 16
12local util = require("luarocks.core.util") 17local util = require("luarocks.core.util")
@@ -23,6 +28,7 @@ local deltas: {string: integer} = {
23} 28}
24 29
25local type Version = vers.Version 30local type Version = vers.Version
31local type Constraints = vers.Constraints
26 32
27local version_mt: metatable<Version> = { 33local version_mt: metatable<Version> = {
28 --- Equality comparison for versions. 34 --- Equality comparison for versions.
@@ -190,10 +196,10 @@ end
190-- @param constraints table: An array of constraints in table format. 196-- @param constraints table: An array of constraints in table format.
191-- @return boolean: True if version satisfies all constraints, 197-- @return boolean: True if version satisfies all constraints,
192-- false otherwise. 198-- false otherwise.
193function vers.match_constraints(version: Version, constraints: {any: {any: Version | string}}): boolean 199function vers.match_constraints(version: Version, constraints: {Constraints}): boolean --!
194 local ok = true 200 local ok = true
195 setmetatable(version, version_mt) 201 setmetatable(version, version_mt)
196 for _, constr in pairs(constraints) do 202 for _, constr in ipairs(constraints) do
197 local constr_version, constr_op = constr.version, constr.op 203 local constr_version, constr_op = constr.version, constr.op
198 local cv: Version 204 local cv: Version
199 if constr_version is string then 205 if constr_version is string then