aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-05 03:00:43 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:49:17 +0300
commitb537a1c1caa235d09698bd298be03996d8efaf14 (patch)
treea0c13b3f7d4af1ee507f293ce3d84ea7804f4add
parent90c01d94d37b475eb6f2fa898ed0650b826f3620 (diff)
downloadluarocks-b537a1c1caa235d09698bd298be03996d8efaf14.tar.gz
luarocks-b537a1c1caa235d09698bd298be03996d8efaf14.tar.bz2
luarocks-b537a1c1caa235d09698bd298be03996d8efaf14.zip
fixed more bugs (inc. vers bug), implemented tree and other config values, and created a prototype for manifest
-rw-r--r--src/luarocks/core/cfg.d.tl17
-rw-r--r--src/luarocks/core/dir.lua41
-rw-r--r--src/luarocks/core/manif.lua51
-rw-r--r--src/luarocks/core/manif.tl51
-rw-r--r--src/luarocks/core/path.lua6
-rw-r--r--src/luarocks/core/path.tl24
-rw-r--r--src/luarocks/core/util.lua11
-rw-r--r--src/luarocks/core/vers.lua39
-rw-r--r--src/luarocks/core/vers.tl12
9 files changed, 192 insertions, 60 deletions
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl
index 09815260..11d647ff 100644
--- a/src/luarocks/core/cfg.d.tl
+++ b/src/luarocks/core/cfg.d.tl
@@ -3,5 +3,18 @@ local record cfg
3 make_platforms: function(system: string): {any: boolean} 3 make_platforms: function(system: string): {any: boolean}
4 make_defaults: function(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any} 4 make_defaults: function(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any}
5 use_defaults: function(cfg, defaults: {any: any}) 5 use_defaults: function(cfg, defaults: {any: any})
6 --! 6 root_dir: string | Tree
7end \ No newline at end of file 7 rocks_subdir: string
8 lua_modules_path: string
9 lib_modules_path: string
10 rocks_trees: {string| Tree}
11 lua_version: string
12 record Tree
13 root: string
14 rocks_dir: string
15 lua_dir: string
16 lib_dir: string
17 end
18end
19
20return cfg \ No newline at end of file
diff --git a/src/luarocks/core/dir.lua b/src/luarocks/core/dir.lua
index cccc1333..7d9702ba 100644
--- a/src/luarocks/core/dir.lua
+++ b/src/luarocks/core/dir.lua
@@ -18,26 +18,6 @@ end
18 18
19 19
20 20
21
22
23
24
25function dir.path(...)
26 local t = { ... }
27 while t[1] == "" do
28 table.remove(t, 1)
29 end
30 for i, c in ipairs(t) do
31 t[i] = unquote(c)
32 end
33 return dir.normalize(table.concat(t, "/"))
34end
35
36
37
38
39
40
41function dir.split_url(url) 21function dir.split_url(url)
42 assert(type(url) == "string") 22 assert(type(url) == "string")
43 23
@@ -92,4 +72,25 @@ function dir.normalize(name)
92 return pathname 72 return pathname
93end 73end
94 74
75
76
77
78
79
80
81
82
83
84
85function dir.path(...)
86 local t = { ... }
87 while t[1] == "" do
88 table.remove(t, 1)
89 end
90 for i, c in ipairs(t) do
91 t[i] = unquote(c)
92 end
93 return dir.normalize(table.concat(t, "/"))
94end
95
95return dir 96return dir
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua
index 8b917590..758b76db 100644
--- a/src/luarocks/core/manif.lua
+++ b/src/luarocks/core/manif.lua
@@ -3,6 +3,57 @@ local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 th
3local manif = {} 3local manif = {}
4 4
5 5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
6local persist = require("luarocks.core.persist") 57local persist = require("luarocks.core.persist")
7local cfg = require("luarocks.core.cfg") 58local cfg = require("luarocks.core.cfg")
8local dir = require("luarocks.core.dir") 59local dir = require("luarocks.core.dir")
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl
index e5e72eaf..2ae908e0 100644
--- a/src/luarocks/core/manif.tl
+++ b/src/luarocks/core/manif.tl
@@ -3,6 +3,57 @@
3local record manif 3local record manif
4end 4end
5 5
6local record Command
7 name: string
8 version: string
9end
10
11local record Lua_version
12 major: integer
13 minor: integer
14 string: string
15end
16
17local record Constraints
18 op: string
19 lua_version: {Lua_version}
20end
21
22local record DependencyVersion
23 version: string
24 constraints: {Constraints}
25 name: string
26end
27
28local record Dependency
29 name: string
30 version: {DependencyVersion} --! multiple versions in the same dependency
31end
32
33local record Module
34 name: string --! ["tl.tl"] = {"tl/0.15.3-1"}
35 name_version: string --! or file location
36end
37
38local record RepositoryVersion
39 version: string
40 manifests: {Manifest}
41end
42
43local record Repository
44 name: string
45 version: {RepositoryVersion} --! multiple versions in the same repository
46
47end
48
49local record Manifest --!
50 arch: string --! only for repository
51 commands: {Command}
52 dependencies: {Dependency}
53 modules: {Module}
54 repository: {Repository} --! no repository for repositoyry
55end
56
6local persist = require("luarocks.core.persist") --! 57local persist = require("luarocks.core.persist") --!
7local cfg = require("luarocks.core.cfg") 58local cfg = require("luarocks.core.cfg")
8local dir = require("luarocks.core.dir") 59local dir = require("luarocks.core.dir")
diff --git a/src/luarocks/core/path.lua b/src/luarocks/core/path.lua
index 5dd0091b..07542a1f 100644
--- a/src/luarocks/core/path.lua
+++ b/src/luarocks/core/path.lua
@@ -6,6 +6,8 @@ local path = {}
6local cfg = require("luarocks.core.cfg") 6local cfg = require("luarocks.core.cfg")
7local dir = require("luarocks.core.dir") 7local dir = require("luarocks.core.dir")
8 8
9
10
9local dir_sep = package.config:sub(1, 1) 11local dir_sep = package.config:sub(1, 1)
10 12
11 13
@@ -16,7 +18,7 @@ function path.rocks_dir(tree)
16 if type(tree) == "string" then 18 if type(tree) == "string" then
17 return dir.path(tree, cfg.rocks_subdir) 19 return dir.path(tree, cfg.rocks_subdir)
18 end 20 end
19 return tostring(tree.rocks_dir) or dir.path(tree.root, cfg.rocks_subdir) 21 return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir)
20end 22end
21 23
22 24
@@ -74,7 +76,7 @@ function path.deploy_lua_dir(tree)
74 return dir.path(tree, cfg.lua_modules_path) 76 return dir.path(tree, cfg.lua_modules_path)
75 else 77 else
76 assert(type(tree) == "table") 78 assert(type(tree) == "table")
77 return tostring(tree.lua_dir) or dir.path(tree.root, cfg.lua_modules_path) 79 return tree.lua_dir or dir.path(tree.root, cfg.lua_modules_path)
78 end 80 end
79end 81end
80 82
diff --git a/src/luarocks/core/path.tl b/src/luarocks/core/path.tl
index a866f4d7..5834ef53 100644
--- a/src/luarocks/core/path.tl
+++ b/src/luarocks/core/path.tl
@@ -3,20 +3,22 @@
3local record path 3local record path
4end 4end
5 5
6local cfg = require("luarocks.core.cfg") --? cannot index key ... in boolean 'cfg' of type boolean 6local cfg = require("luarocks.core.cfg")
7local dir = require("luarocks.core.dir") 7local dir = require("luarocks.core.dir")
8 8
9local type Tree = cfg.Tree
10
9local dir_sep = package.config:sub(1, 1) 11local dir_sep = package.config:sub(1, 1)
10-------------------------------------------------------------------------------- 12--------------------------------------------------------------------------------
11 13
12function path.rocks_dir(tree: string | {any: any}): string 14function path.rocks_dir(tree: string | Tree): string
13 if tree == nil then 15 if tree == nil then
14 tree = cfg.root_dir 16 tree = cfg.root_dir
15 end 17 end
16 if tree is string then 18 if tree is string then
17 return dir.path(tree, cfg.rocks_subdir) 19 return dir.path(tree, cfg.rocks_subdir)
18 end 20 end
19 return tostring(tree.rocks_dir) or dir.path(tree.root, cfg.rocks_subdir) --? tostring(tree.root) 21 return tree.rocks_dir or dir.path(tree.root, cfg.rocks_subdir)
20end 22end
21 23
22--- Produce a versioned version of a filename. 24--- Produce a versioned version of a filename.
@@ -69,21 +71,21 @@ function path.path_to_module(file: string): string
69 return name 71 return name
70end 72end
71 73
72function path.deploy_lua_dir(tree: string | {any: any}): string 74function path.deploy_lua_dir(tree: string | Tree): string
73 if tree is string then 75 if tree is string then
74 return dir.path(tree, cfg.lua_modules_path) 76 return dir.path(tree, cfg.lua_modules_path)
75 else 77 else
76 assert(type(tree) == "table") 78 assert(type(tree) == "table")
77 return tostring(tree.lua_dir) or dir.path(tree.root, cfg.lua_modules_path) --? tostring(tree.root) 79 return tree.lua_dir or dir.path(tree.root, cfg.lua_modules_path)
78 end 80 end
79end 81end
80 82
81function path.deploy_lib_dir(tree: string | {any: any}): string 83function path.deploy_lib_dir(tree: string | Tree): string
82 if tree is string then 84 if tree is string then
83 return dir.path(tree, cfg.lib_modules_path) 85 return dir.path(tree, cfg.lib_modules_path)
84 else 86 else
85 assert(type(tree) == "table") 87 assert(type(tree) == "table")
86 return tostring(tree.lib_dir) or dir.path(tree.root, cfg.lib_modules_path) --? tostring(tree.root) 88 return tostring(tree.lib_dir) or dir.path(tree.root, cfg.lib_modules_path)
87 end 89 end
88end 90end
89 91
@@ -113,11 +115,11 @@ function path.which_i(file_name: string, name: string, version: string, tree: st
113 return file_name 115 return file_name
114end 116end
115 117
116function path.rocks_tree_to_string(tree: string | {any: any}): string 118function path.rocks_tree_to_string(tree: string | Tree): string
117 if tree is string then 119 if tree is string then
118 return tree 120 return tree
119 else 121 else
120 return tostring(tree.root) --? 122 return tostring(tree.root)
121 end 123 end
122end 124end
123 125
@@ -138,8 +140,8 @@ function path.map_trees(deps_mode: string, fn: function, ...: string): {any}
138 if deps_mode == "all" then 140 if deps_mode == "all" then
139 use = true 141 use = true
140 end 142 end
141 for _, tree in ipairs(cfg.rocks_trees or {}) do --! no mention of rocks_trees in the cfg file 143 for _, tree in ipairs(cfg.rocks_trees or {}) do
142 if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(current)) then --! 144 if dir.normalize(path.rocks_tree_to_string(tree)) == dir.normalize(path.rocks_tree_to_string(current)) then
143 use = true 145 use = true
144 end 146 end
145 if use then 147 if use then
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua
index 31aa5c25..38d7ae45 100644
--- a/src/luarocks/core/util.lua
+++ b/src/luarocks/core/util.lua
@@ -126,9 +126,10 @@ function util.deep_merge(dst, src)
126 local dstk = dst[k] 126 local dstk = dst[k]
127 if dstk == nil then 127 if dstk == nil then
128 dst[k] = {} 128 dst[k] = {}
129 dstk = dst[k]
129 end 130 end
130 if type(dstk) == "table" then 131 if type(dstk) == "table" then
131 util.deep_merge(dst[k], v) 132 util.deep_merge(dstk, v)
132 else 133 else
133 dst[k] = v 134 dst[k] = v
134 end 135 end
@@ -145,11 +146,13 @@ end
145function util.deep_merge_under(dst, src) 146function util.deep_merge_under(dst, src)
146 for k, v in pairs(src) do 147 for k, v in pairs(src) do
147 if type(v) == "table" then 148 if type(v) == "table" then
148 if dst[k] == nil then 149 local dstk = dst[k]
150 if dstk == nil then
149 dst[k] = {} 151 dst[k] = {}
152 dstk = dst[k]
150 end 153 end
151 if type(dst[k]) == "table" then 154 if type(dstk) == "table" then
152 util.deep_merge_under(dst[k], v) 155 util.deep_merge_under(dstk, v)
153 end 156 end
154 elseif dst[k] == nil then 157 elseif dst[k] == nil then
155 dst[k] = v 158 dst[k] = v
diff --git a/src/luarocks/core/vers.lua b/src/luarocks/core/vers.lua
index 231b9683..a5a1a0a9 100644
--- a/src/luarocks/core/vers.lua
+++ b/src/luarocks/core/vers.lua
@@ -1,5 +1,4 @@
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 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 = {}
2local vers = {}
3 2
4 3
5local util = require("luarocks.core.util") 4local util = require("luarocks.core.util")
@@ -22,6 +21,8 @@ local deltas = {
22 21
23 22
24 23
24
25
25local version_mt = { 26local version_mt = {
26 27
27 28
@@ -148,7 +149,7 @@ function vers.compare_versions(a, b)
148 if a == b then 149 if a == b then
149 return false 150 return false
150 end 151 end
151 return vers.parse_version(a) > vers.parse_version(b) 152 return vers.parse_version(b) < vers.parse_version(a)
152end 153end
153 154
154 155
@@ -167,8 +168,10 @@ local function partial_match(version_for_parse, requested_for_parce)
167 168
168 local version, requested 169 local version, requested
169 170
170 if not (type(version_for_parse) == "table") then version = vers.parse_version(version_for_parse) end 171 if not (type(version_for_parse) == "table") then version = vers.parse_version(version_for_parse)
171 if not (type(requested_for_parce) == "table") then requested = vers.parse_version(requested_for_parce) end 172 else version = version_for_parse end
173 if not (type(requested_for_parce) == "table") then requested = vers.parse_version(requested_for_parce)
174 else requested = requested_for_parce end
172 if not (type(version) == "table") or not (type(requested) == "table") then return false end 175 if not (type(version) == "table") or not (type(requested) == "table") then return false end
173 176
174 for i, ri in ipairs(requested) do 177 for i, ri in ipairs(requested) do
@@ -190,18 +193,22 @@ function vers.match_constraints(version, constraints)
190 local ok = true 193 local ok = true
191 setmetatable(version, version_mt) 194 setmetatable(version, version_mt)
192 for _, constr in pairs(constraints) do 195 for _, constr in pairs(constraints) do
193 if type(constr.version) == "string" then
194 constr.version = vers.parse_version(constr.version)
195 end
196 local constr_version, constr_op = constr.version, constr.op 196 local constr_version, constr_op = constr.version, constr.op
197 setmetatable(constr_version, version_mt) 197 local cv
198 if constr_op == "==" then ok = version == constr_version 198 if type(constr_version) == "string" then
199 elseif constr_op == "~=" then ok = version ~= constr_version 199 cv = vers.parse_version(constr_version)
200 elseif constr_op == ">" then ok = version > constr_version 200 constr.version = cv
201 elseif constr_op == "<" then ok = version < constr_version 201 else
202 elseif constr_op == ">=" then ok = version >= constr_version 202 cv = constr_version
203 elseif constr_op == "<=" then ok = version <= constr_version 203 end
204 elseif constr_op == "~>" then ok = partial_match(version, constr_version) 204 setmetatable(cv, version_mt)
205 if constr_op == "==" then ok = version == cv
206 elseif constr_op == "~=" then ok = version ~= cv
207 elseif constr_op == ">" then ok = cv < version
208 elseif constr_op == "<" then ok = version < cv
209 elseif constr_op == ">=" then ok = cv <= version
210 elseif constr_op == "<=" then ok = version <= cv
211 elseif constr_op == "~>" then ok = partial_match(version, cv)
205 end 212 end
206 if not ok then break end 213 if not ok then break end
207 end 214 end
diff --git a/src/luarocks/core/vers.tl b/src/luarocks/core/vers.tl
index 7d0f0a83..8953a730 100644
--- a/src/luarocks/core/vers.tl
+++ b/src/luarocks/core/vers.tl
@@ -4,7 +4,7 @@ end
4local util = require("luarocks.core.util") 4local util = require("luarocks.core.util")
5-------------------------------------------------------------------------------- 5--------------------------------------------------------------------------------
6 6
7local deltas: {string: integer} = { --?1 7local deltas: {string: integer} = {
8 dev = 120000000, 8 dev = 120000000,
9 scm = 110000000, 9 scm = 110000000,
10 cvs = 100000000, 10 cvs = 100000000,
@@ -23,7 +23,7 @@ local record Version
23 metamethod __le: function(Version, Version): boolean 23 metamethod __le: function(Version, Version): boolean
24end 24end
25 25
26local version_mt: metatable<Version> = { --? anything to do here 26local version_mt: metatable<Version> = {
27 --- Equality comparison for versions. 27 --- Equality comparison for versions.
28 -- All version numbers must be equal. 28 -- All version numbers must be equal.
29 -- If both versions have revision numbers, they must be equal; 29 -- If both versions have revision numbers, they must be equal;
@@ -132,7 +132,7 @@ function vers.parse_version(vstring: string): Version
132 version[i] = 0 132 version[i] = 0
133 break 133 break
134 end 134 end
135 version[i] = deltas[token] or (token:byte() / 1000) --?1 135 version[i] = deltas[token] or (token:byte() / 1000)
136 end 136 end
137 v = rest 137 v = rest
138 end 138 end
@@ -168,8 +168,10 @@ local function partial_match(version_for_parse: string | Version, requested_for_
168 168
169 local version, requested: Version, Version 169 local version, requested: Version, Version
170 170
171 if not version_for_parse is Version then version = vers.parse_version(version_for_parse) end 171 if not version_for_parse is Version then version = vers.parse_version(version_for_parse)
172 if not requested_for_parce is Version then requested = vers.parse_version(requested_for_parce) end 172 else version = version_for_parse end
173 if not requested_for_parce is Version then requested = vers.parse_version(requested_for_parce)
174 else requested = requested_for_parce end
173 if not version is Version or not requested is Version then return false end 175 if not version is Version or not requested is Version then return false end
174 176
175 for i, ri in ipairs(requested) do 177 for i, ri in ipairs(requested) do