aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-22 21:07:47 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:49:17 +0300
commit0e6068b309a4bb084322ed2934b8191d33f50626 (patch)
tree2fca8702a5013bf64416dbee71b40cd76963ebd8
parent49664ec9150d6f952ca95f3a0fce82e278b74f73 (diff)
downloadluarocks-0e6068b309a4bb084322ed2934b8191d33f50626.tar.gz
luarocks-0e6068b309a4bb084322ed2934b8191d33f50626.tar.bz2
luarocks-0e6068b309a4bb084322ed2934b8191d33f50626.zip
test core with the next version of teal
-rw-r--r--src/luarocks/core/manif.tl2
-rw-r--r--src/luarocks/core/persist.tl4
-rw-r--r--src/luarocks/core/util.tl78
-rw-r--r--src/luarocks/persist.lua (renamed from src/luarocks/persist-original.lua)0
-rw-r--r--src/luarocks/persist.tl31
-rw-r--r--src/luarocks/type/rockspec.lua28
-rw-r--r--src/luarocks/util.lua (renamed from src/luarocks/util-original.lua)0
-rw-r--r--src/luarocks/util.tl13
8 files changed, 88 insertions, 68 deletions
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl
index a089b5d8..0713d293 100644
--- a/src/luarocks/core/manif.tl
+++ b/src/luarocks/core/manif.tl
@@ -57,7 +57,7 @@ end
57-- @param repo_url string: The repository identifier. 57-- @param repo_url string: The repository identifier.
58-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. 58-- @param lua_version string: Lua version in "5.x" format, defaults to installed version.
59-- @return table or nil: loaded manifest or nil if cache is empty. 59-- @return table or nil: loaded manifest or nil if cache is empty.
60function manif.get_cached_manifest(repo_url: string, lua_version: string): Manifest 60function manif.get_cached_manifest(repo_url: string, lua_version?: string): Manifest
61 lua_version = lua_version or cfg.lua_version 61 lua_version = lua_version or cfg.lua_version
62 return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] 62 return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version]
63end 63end
diff --git a/src/luarocks/core/persist.tl b/src/luarocks/core/persist.tl
index 31dfe289..89cac97e 100644
--- a/src/luarocks/core/persist.tl
+++ b/src/luarocks/core/persist.tl
@@ -21,7 +21,7 @@ function persist.run_file(filename: string, env: {string:any}): boolean, any | s
21 return nil, read_err, "open" 21 return nil, read_err, "open"
22 end 22 end
23 str = str:gsub("^#![^\n]*\n", "") 23 str = str:gsub("^#![^\n]*\n", "")
24 local chunk, ran, err: function(any):(any), boolean, any 24 local chunk, ran, err: function(...: any):(any), boolean, any
25 chunk, err = load(str, filename, "t", env) 25 chunk, err = load(str, filename, "t", env)
26 if chunk then 26 if chunk then
27 ran, err = pcall(chunk) 27 ran, err = pcall(chunk)
@@ -45,7 +45,7 @@ end
45-- or nil, an error message and an error code ("open"; couldn't open the file, 45-- or nil, an error message and an error code ("open"; couldn't open the file,
46-- "load"; compile-time error, or "run"; run-time error) 46-- "load"; compile-time error, or "run"; run-time error)
47-- in case of errors. 47-- in case of errors.
48function persist.load_into_table(filename: string, tbl: {string:any}) : {any: any}, {any: any} | string, string 48function persist.load_into_table(filename: string, tbl?: {string:any}) : {any: any}, {any: any} | string, string
49 49
50 local result: {string:any} = tbl or {} 50 local result: {string:any} = tbl or {}
51 local globals = {} 51 local globals = {}
diff --git a/src/luarocks/core/util.tl b/src/luarocks/core/util.tl
index e9c21dac..39862dcb 100644
--- a/src/luarocks/core/util.tl
+++ b/src/luarocks/core/util.tl
@@ -1,13 +1,18 @@
1 1
2local record util 2local record util
3 type CompFn = function(any, any): boolean 3 record Ordering<K>
4 {K}
5
6 sub_orders: {K: Ordering<K>}
7 end
4end 8end
5 9
6-------------------------------------------------------------------------------- 10--------------------------------------------------------------------------------
7 11
8local dir_sep = package.config:sub(1, 1) 12local dir_sep = package.config:sub(1, 1)
9 13
10local type CompFn = util.CompFn 14local type SortBy<K> = table.SortFunction<K> | util.Ordering<K>
15
11 16
12--- Run a process and read a its output. 17--- Run a process and read a its output.
13-- Equivalent to io.popen(cmd):read("*l"), except that it 18-- Equivalent to io.popen(cmd):read("*l"), except that it
@@ -57,7 +62,7 @@ function util.show_table(t: {any:any}, tname: string, top_indent: string): strin
57 62
58 local function basic_serialize(o: any): string 63 local function basic_serialize(o: any): string
59 local so = tostring(o) 64 local so = tostring(o)
60 if type(o) == "function" then 65 if o is function then
61 local info = debug and debug.getinfo(o, "S") 66 local info = debug and debug.getinfo(o, "S")
62 if not info then 67 if not info then
63 return ("%q"):format(so) 68 return ("%q"):format(so)
@@ -76,7 +81,7 @@ function util.show_table(t: {any:any}, tname: string, top_indent: string): strin
76 end 81 end
77 end 82 end
78 83
79 local function add_to_cart (value: any | {any:any}, name: string, indent: string, saved: {any: string}, field: string) 84 local function add_to_cart (value: any | {any:any}, name: string, indent: string, saved?: {any: string}, field?: string)
80 indent = indent or "" 85 indent = indent or ""
81 saved = saved or {} 86 saved = saved or {}
82 field = field or name 87 field = field or name
@@ -172,7 +177,7 @@ end
172 177
173-- from http://lua-users.org/wiki/SplitJoin 178-- from http://lua-users.org/wiki/SplitJoin
174-- by Philippe Lhoste 179-- by Philippe Lhoste
175function util.split_string(str: string, delim: string, maxNb: number): {string} 180function util.split_string(str: string, delim: string, maxNb?: number): {string}
176 -- Eliminate bad cases... 181 -- Eliminate bad cases...
177 if string.find(str, delim) == nil then 182 if string.find(str, delim) == nil then
178 return { str } 183 return { str }
@@ -183,11 +188,11 @@ function util.split_string(str: string, delim: string, maxNb: number): {string}
183 local result = {} 188 local result = {}
184 local pat = "(.-)" .. delim .. "()" 189 local pat = "(.-)" .. delim .. "()"
185 local nb = 0 190 local nb = 0
186 local lastPos: number 191 local lastPos: integer
187 for part, pos in string.gmatch(str, pat) do 192 for part, pos in string.gmatch(str, pat) do
188 nb = nb + 1 193 nb = nb + 1
189 result[nb] = part 194 result[nb] = part
190 lastPos = tonumber(pos) 195 lastPos = math.tointeger(pos)
191 if nb == maxNb then break end 196 if nb == maxNb then break end
192 end 197 end
193 -- Handle the last field 198 -- Handle the last field
@@ -288,51 +293,46 @@ end
288-- for that key, which is returned by the iterator as the third value after the key 293-- for that key, which is returned by the iterator as the third value after the key
289-- and the value. 294-- and the value.
290-- @return function: the iterator function. 295-- @return function: the iterator function.
291function util.sortedpairs<K, V, S>(tbl: {K: V}, sort_function: CompFn | {K | {K, S}}): function(): K, V, S 296function util.sortedpairs<K, V>(tbl: {K: V}, sort_by?: SortBy<K>): function(): K, V, util.Ordering<K>
292 if not sort_function then
293 sort_function = default_sort
294 end
295 local keys = util.keys(tbl) 297 local keys = util.keys(tbl)
296 local sub_orders: {K: S} = {} 298 local sub_orders: {K: util.Ordering<K>} = nil
297 299
298 if sort_function is CompFn then 300 if sort_by == nil then
299 table.sort(keys, sort_function) 301 table.sort(keys, default_sort)
302 elseif sort_by is table.SortFunction<K> then
303 table.sort(keys, sort_by)
300 else 304 else
301 local order = sort_function 305 -- sort_by is Ordering<K>
302 local ordered_keys = {} 306
303 local all_keys = keys 307 sub_orders = sort_by.sub_orders
304 keys = {} 308
305 309 local seen_ordered_key: {K: boolean} = {}
306 for _, order_entry in ipairs(order) do 310
307 local key, sub_order: K, S 311 local my_ordered_keys: {K} = {}
308 312
309 if not order_entry is {K, S} then --TEAL BUG 313 for _, key in ipairs(sort_by) do
310 key = order_entry as K
311 else
312 key = order_entry[1]
313 sub_order = order_entry[2]
314 end
315
316 if tbl[key] then 314 if tbl[key] then
317 ordered_keys[key] = true 315 seen_ordered_key[key] = true
318 sub_orders[key] = sub_order 316 table.insert(my_ordered_keys, key)
319 table.insert(keys, key)
320 end 317 end
321 end 318 end
322 319
323 table.sort(all_keys, default_sort) 320 table.sort(keys, default_sort)
324 for _, key in ipairs(all_keys) do 321
325 if not ordered_keys[key] then 322 for _, key in ipairs(keys) do
326 table.insert(keys, key) 323 if not seen_ordered_key[key] then
324 table.insert(my_ordered_keys, key)
327 end 325 end
328 end 326 end
327
328 keys = my_ordered_keys
329 end 329 end
330 330
331 local i = 1 331 local i = 1
332 return function(): K, V, S 332 return function(): K, V, util.Ordering<K>
333 local key = keys[i] 333 local key = keys[i]
334 i = i + 1 334 i = i + 1
335 return key, tbl[key], sub_orders[key] 335 return key, tbl[key], sub_orders and sub_orders[key]
336 end 336 end
337end 337end
338 338
diff --git a/src/luarocks/persist-original.lua b/src/luarocks/persist.lua
index 4dcd930a..4dcd930a 100644
--- a/src/luarocks/persist-original.lua
+++ b/src/luarocks/persist.lua
diff --git a/src/luarocks/persist.tl b/src/luarocks/persist.tl
index 5611b684..f02fcfee 100644
--- a/src/luarocks/persist.tl
+++ b/src/luarocks/persist.tl
@@ -3,10 +3,11 @@
3-- saving tables into files. 3-- saving tables into files.
4local record persist 4local record persist
5 run_file: function(string, {string:any}): boolean, any | string, string 5 run_file: function(string, {string:any}): boolean, any | string, string
6 load_into_table: function(string, {string:any}) : {any: any}, {any: any} | string, string 6 load_into_table: function(string, ?{string:any}) : {any: any}, {any: any} | string, string
7end 7end
8 8
9local core = require("luarocks.core.persist") 9local core = require("luarocks.core.persist")
10local coreutil = require("luarocks.core.util")
10local util = require("luarocks.util") 11local util = require("luarocks.util")
11local dir = require("luarocks.dir") 12local dir = require("luarocks.dir")
12local fs = require("luarocks.fs") 13local fs = require("luarocks.fs")
@@ -14,7 +15,13 @@ local fs = require("luarocks.fs")
14persist.run_file = core.run_file 15persist.run_file = core.run_file
15persist.load_into_table = core.load_into_table 16persist.load_into_table = core.load_into_table
16 17
17local write_table: function(out, tbl: {number | string: number| string}, level: integer, field_order: {(number | string): any}) 18local type SortBy<K> = table.SortFunction<K> | coreutil.Ordering<K>
19
20local interface Writer
21 write: function(self: Writer, data: string)
22end
23
24local write_table: function(out: Writer, tbl: {number | string: number| string}, level: integer, field_order: SortBy<number | string>)
18 25
19--- Write a value as Lua code. 26--- Write a value as Lua code.
20-- This function handles only numbers and strings, invoking write_table 27-- This function handles only numbers and strings, invoking write_table
@@ -24,8 +31,8 @@ local write_table: function(out, tbl: {number | string: number| string}, level:
24-- @param level number: the indentation level 31-- @param level number: the indentation level
25-- @param sub_order table: optional prioritization table 32-- @param sub_order table: optional prioritization table
26-- @see write_table 33-- @see write_table
27function persist.write_value(out, v: any, level: integer, sub_order) --! out type 34function persist.write_value(out: Writer, v: any, level: integer, sub_order?: SortBy<number | string>)
28 if v is {any: any} then 35 if v is {number | string: number | string} then
29 level = level or 0 36 level = level or 0
30 write_table(out, v, level + 1, sub_order) 37 write_table(out, v, level + 1, sub_order)
31 elseif v is string then 38 elseif v is string then
@@ -79,7 +86,7 @@ do
79 end 86 end
80end 87end
81 88
82local function write_table_key_assignment(out, k: string | number, level: integer) 89local function write_table_key_assignment(out: Writer, k: string | number, level: integer)
83 if k is string and is_valid_plain_key(k) then 90 if k is string and is_valid_plain_key(k) then
84 out:write(k) 91 out:write(k)
85 else 92 else
@@ -98,7 +105,7 @@ end
98-- @param tbl table: the table to be written. 105-- @param tbl table: the table to be written.
99-- @param level number: the indentation level 106-- @param level number: the indentation level
100-- @param field_order table: optional prioritization table 107-- @param field_order table: optional prioritization table
101write_table = function(out, tbl: {number | string: number| string}, level: integer, field_order: {(number | string): any}) --? suborrder type? 108write_table = function(out: Writer, tbl: {number | string: number| string}, level: integer, field_order: SortBy<number | string>)
102 out:write("{") 109 out:write("{")
103 local sep = "\n" 110 local sep = "\n"
104 local indentation = " " 111 local indentation = " "
@@ -137,9 +144,9 @@ end
137-- @param tbl table: the table to be written. 144-- @param tbl table: the table to be written.
138-- @param field_order table: optional prioritization table 145-- @param field_order table: optional prioritization table
139-- @return true if successful; nil and error message if failed. 146-- @return true if successful; nil and error message if failed.
140local function write_table_as_assignments(out, tbl, field_order) 147local function write_table_as_assignments(out: Writer, tbl: {number | string: number| string}, field_order: SortBy<number | string>): boolean, string
141 for k, v, sub_order in util.sortedpairs(tbl, field_order) do 148 for k, v, sub_order in util.sortedpairs(tbl, field_order) do
142 if not is_valid_plain_key(k) then 149 if not is_valid_plain_key(k) then --? tostring
143 return nil, "cannot store '"..tostring(k).."' as a plain key." 150 return nil, "cannot store '"..tostring(k).."' as a plain key."
144 end 151 end
145 out:write(k.." = ") 152 out:write(k.." = ")
@@ -152,9 +159,9 @@ end
152--- Write a table using Lua table syntax to a writer object. 159--- Write a table using Lua table syntax to a writer object.
153-- @param out table or userdata: a writer object supporting :write() method. 160-- @param out table or userdata: a writer object supporting :write() method.
154-- @param tbl table: the table to be written. 161-- @param tbl table: the table to be written.
155local function write_table_as_table(out, tbl) 162local function write_table_as_table(out: Writer, tbl: {number | string: number| string})
156 out:write("return {\n") 163 out:write("return {\n")
157 for k, v, sub_order in util.sortedpairs(tbl) do 164 for k, v, sub_order in util.sortedpairs(tbl) do --! that has the right inputs and outputs yet it throws an error
158 out:write(" ") 165 out:write(" ")
159 write_table_key_assignment(out, k, 1) 166 write_table_key_assignment(out, k, 1)
160 persist.write_value(out, v, 1, sub_order) 167 persist.write_value(out, v, 1, sub_order)
@@ -170,8 +177,8 @@ end
170-- @param tbl table: the table containing the data to be written 177-- @param tbl table: the table containing the data to be written
171-- @param field_order table: an optional array indicating the order of top-level fields. 178-- @param field_order table: an optional array indicating the order of top-level fields.
172-- @return persisted data as string; or nil and an error message 179-- @return persisted data as string; or nil and an error message
173function persist.save_from_table_to_string(tbl, field_order) 180function persist.save_from_table_to_string(tbl: {number | string: number| string}, field_order: SortBy<number | string>): string
174 local out = {buffer = {}} 181 local out: Writer = {buffer = {}} --!
175 function out:write(data) table.insert(self.buffer, data) end 182 function out:write(data) table.insert(self.buffer, data) end
176 local ok, err = write_table_as_assignments(out, tbl, field_order) 183 local ok, err = write_table_as_assignments(out, tbl, field_order)
177 if not ok then 184 if not ok then
diff --git a/src/luarocks/type/rockspec.lua b/src/luarocks/type/rockspec.lua
index 0b4b5dcf..5ee944a4 100644
--- a/src/luarocks/type/rockspec.lua
+++ b/src/luarocks/type/rockspec.lua
@@ -135,13 +135,27 @@ local rockspec_formats, versions = type_check.declare_schemas({
135 } 135 }
136}) 136})
137 137
138type_rockspec.order = {"rockspec_format", "package", "version", 138type_rockspec.order = {
139 { "source", { "url", "tag", "branch", "md5" } }, 139 "rockspec_format",
140 { "description", {"summary", "detailed", "homepage", "license" } }, 140 "package",
141 "supported_platforms", "dependencies", "build_dependencies", "external_dependencies", 141 "version",
142 { "build", {"type", "modules", "copy_directories", "platforms"} }, 142 "source",
143 "test_dependencies", { "test", {"type"} }, 143 "description",
144 "hooks"} 144 "supported_platforms",
145 "dependencies",
146 "build_dependencies",
147 "external_dependencies",
148 "build",
149 "test_dependencies",
150 "test",
151 "hooks",
152 sub_orders = {
153 ["source"] = { "url", "tag", "branch", "md5" },
154 ["description"] = {"summary", "detailed", "homepage", "license" },
155 ["build"] = { "type", "modules", "copy_directories", "platforms" },
156 ["test"] = { "type" }
157 }
158}
145 159
146local function check_rockspec_using_version(rockspec, globals, version) 160local function check_rockspec_using_version(rockspec, globals, version)
147 local schema = rockspec_formats[version] 161 local schema = rockspec_formats[version]
diff --git a/src/luarocks/util-original.lua b/src/luarocks/util.lua
index de9157fc..de9157fc 100644
--- a/src/luarocks/util-original.lua
+++ b/src/luarocks/util.lua
diff --git a/src/luarocks/util.tl b/src/luarocks/util.tl
index 868e1552..f1447e60 100644
--- a/src/luarocks/util.tl
+++ b/src/luarocks/util.tl
@@ -7,12 +7,12 @@
7local core = require("luarocks.core.util") 7local core = require("luarocks.core.util")
8local cfg = require("luarocks.core.cfg") 8local cfg = require("luarocks.core.cfg")
9 9
10local type CompFn = core.CompFn 10local type SortBy<K> = table.SortFunction<K> | core.Ordering<K>
11 11
12local record util 12local record util
13 cleanup_path: function(string, string, string, boolean): string 13 cleanup_path: function(string, string, string, boolean): string
14 split_string: function(string, string, number): {string} 14 split_string: function(string, string, number): {string}
15 sortedpairs: function<K, V, S>({K : V}, CompFn | {K | {K, S}}): function(): K, V, S 15 sortedpairs: function<K, V>(tbl: {K: V}, sort_by: SortBy<K>): function(): K, V, core.Ordering<K>
16 deep_merge: function({any : any}, {any : any}) 16 deep_merge: function({any : any}, {any : any})
17 deep_merge_under: function({any : any}, {any : any}) 17 deep_merge_under: function({any : any}, {any : any})
18 popen_read: function(string, ?string): string 18 popen_read: function(string, ?string): string
@@ -27,19 +27,18 @@ local record util
27 args: table.PackTable<any> 27 args: table.PackTable<any>
28 end 28 end
29 29
30 record Parser --? 30 record Parser
31 option: function(Parser, ...: string): Parser 31 option: function(Parser, ...: string): Parser
32 argname: function(Parser, string): Parser 32 argname: function(Parser, string): Parser
33 choices: function(Parser, {string}): Parser 33 choices: function(Parser, {string}): Parser
34 flag: function(Parser, string): Parser 34 flag: function(Parser, string): Parser
35 hidden: function(Parser, boolean): Parser 35 hidden: function(Parser, boolean): Parser
36 end 36 end
37
38end 37end
39 38
40util.cleanup_path = core.cleanup_path --tlcheck acting funny 39util.cleanup_path = core.cleanup_path
41util.split_string = core.split_string 40util.split_string = core.split_string
42-- util.sortedpairs = core.sortedpairs 41util.sortedpairs = core.sortedpairs
43util.deep_merge = core.deep_merge 42util.deep_merge = core.deep_merge
44util.deep_merge_under = core.deep_merge_under 43util.deep_merge_under = core.deep_merge_under
45util.popen_read = core.popen_read 44util.popen_read = core.popen_read
@@ -53,6 +52,7 @@ local type Fn = util.Fn
53local type Rockspec = cfg.Rockspec 52local type Rockspec = cfg.Rockspec
54local type Parser = util.Parser 53local type Parser = util.Parser
55 54
55
56local scheduled_functions: {Fn} = {} --? infered from line 48-51 56local scheduled_functions: {Fn} = {} --? infered from line 48-51
57 57
58--- Schedule a function to be executed upon program termination. 58--- Schedule a function to be executed upon program termination.
@@ -290,7 +290,6 @@ local function collect_rockspecs(versions: {string: string}, paths: {string: str
290 local dir = require("luarocks.dir") 290 local dir = require("luarocks.dir")
291 local path = require("luarocks.path") 291 local path = require("luarocks.path")
292 local vers = require("luarocks.core.vers") 292 local vers = require("luarocks.core.vers")
293
294 if fs.is_dir(subdir) then 293 if fs.is_dir(subdir) then
295 for file in fs.dir(subdir) do 294 for file in fs.dir(subdir) do
296 file = dir.path(subdir, file) 295 file = dir.path(subdir, file)