aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2024-08-23 20:30:10 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commit3d585c3b3fba291374602750ef3201a017cb60db (patch)
treeb6d64ab1c5d6785391bc6c7b50fe89d18e6f4e32 /src
parentbd1c9d3f2e2e289e5b0cf98a65381ef6ca8e4b07 (diff)
downloadluarocks-3d585c3b3fba291374602750ef3201a017cb60db.tar.gz
luarocks-3d585c3b3fba291374602750ef3201a017cb60db.tar.bz2
luarocks-3d585c3b3fba291374602750ef3201a017cb60db.zip
deplocks: simplify types
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/core/manif.tl6
-rw-r--r--src/luarocks/core/persist.tl2
-rw-r--r--src/luarocks/core/types/depskey.d.tl9
-rw-r--r--src/luarocks/deplocks.lua44
-rw-r--r--src/luarocks/deplocks.tl58
-rw-r--r--src/luarocks/deps.lua11
-rw-r--r--src/luarocks/deps.tl25
-rw-r--r--src/luarocks/test.tl3
8 files changed, 81 insertions, 77 deletions
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl
index f75bf28e..1f3b3659 100644
--- a/src/luarocks/core/manif.tl
+++ b/src/luarocks/core/manif.tl
@@ -52,11 +52,11 @@ end
52-- @return table or (nil, string, string): the manifest or nil, 52-- @return table or (nil, string, string): the manifest or nil,
53-- error message and error code ("open", "load", "run"). 53-- error message and error code ("open", "load", "run").
54function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string | {any: any}, string 54function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string | {any: any}, string
55 local manifest, err, errcode: {any: any}, {any: any} | string, string = persist.load_into_table(file) 55 local manifest, err, errcode = persist.load_into_table(file)
56 if not manifest and err is string then 56 if not manifest and err is string then
57 return nil, "Failed loading manifest for "..repo_url..": " .. err, errcode 57 return nil, "Failed loading manifest for "..repo_url..": " .. err, errcode
58 end 58 end
59 59
60 manif.cache_manifest(repo_url, lua_version, manifest as Manifest) -- No runtime check if manifest is actually a Manifest! 60 manif.cache_manifest(repo_url, lua_version, manifest as Manifest) -- No runtime check if manifest is actually a Manifest!
61 return manifest as Manifest, err, errcode 61 return manifest as Manifest, err, errcode
62end 62end
@@ -88,7 +88,7 @@ function manif.load_rocks_tree_manifests(deps_mode?: string): {Tree_manifest}
88 return trees 88 return trees
89end 89end
90 90
91function manif.scan_dependencies(name: string, version: string, tree_manifests: {Tree_manifest}, dest: {any: any}) 91function manif.scan_dependencies(name: string, version: string, tree_manifests: {Tree_manifest}, dest: {string: string})
92 if dest[name] then 92 if dest[name] then
93 return 93 return
94 end 94 end
diff --git a/src/luarocks/core/persist.tl b/src/luarocks/core/persist.tl
index 89cac97e..4694afcb 100644
--- a/src/luarocks/core/persist.tl
+++ b/src/luarocks/core/persist.tl
@@ -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}) : {string: any}, {string: boolean} | 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/types/depskey.d.tl b/src/luarocks/core/types/depskey.d.tl
new file mode 100644
index 00000000..9d15fd25
--- /dev/null
+++ b/src/luarocks/core/types/depskey.d.tl
@@ -0,0 +1,9 @@
1local record depskey
2 enum DepsKey
3 "dependencies"
4 "build_dependencies"
5 "test_dependencies"
6 end
7end
8
9return depskey
diff --git a/src/luarocks/deplocks.lua b/src/luarocks/deplocks.lua
index 8a21ef1b..b07c91f7 100644
--- a/src/luarocks/deplocks.lua
+++ b/src/luarocks/deplocks.lua
@@ -1,5 +1,11 @@
1local deplocks = {} 1local deplocks = {}
2 2
3
4
5
6
7
8
3local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
4local dir = require("luarocks.dir") 10local dir = require("luarocks.dir")
5local util = require("luarocks.util") 11local util = require("luarocks.util")
@@ -7,22 +13,23 @@ local persist = require("luarocks.persist")
7 13
8 14
9 15
10local deptable = {} 16
11local deptable_mode = "start" 17local depstable = {}
18local depstable_mode = "start"
12local deplock_abs_filename 19local deplock_abs_filename
13local deplock_root_rock_name 20local deplock_root_rock_name
14 21
15function deplocks.init(root_rock_name, dirname) 22function deplocks.init(root_rock_name, dirname)
16 if deptable_mode ~= "start" then 23 if depstable_mode ~= "start" then
17 return 24 return
18 end 25 end
19 deptable_mode = "create" 26 depstable_mode = "create"
20 27
21 local filename = dir.path(dirname, "luarocks.lock") 28 local filename = dir.path(dirname, "luarocks.lock")
22 deplock_abs_filename = fs.absolute_name(filename) 29 deplock_abs_filename = fs.absolute_name(filename)
23 deplock_root_rock_name = root_rock_name 30 deplock_root_rock_name = root_rock_name
24 31
25 deptable = {} 32 depstable = {}
26end 33end
27 34
28function deplocks.get_abs_filename(root_rock_name) 35function deplocks.get_abs_filename(root_rock_name)
@@ -32,10 +39,10 @@ function deplocks.get_abs_filename(root_rock_name)
32end 39end
33 40
34function deplocks.load(root_rock_name, dirname) 41function deplocks.load(root_rock_name, dirname)
35 if deptable_mode ~= "start" then 42 if depstable_mode ~= "start" then
36 return true, nil 43 return true, nil
37 end 44 end
38 deptable_mode = "locked" 45 depstable_mode = "locked"
39 46
40 local filename = dir.path(dirname, "luarocks.lock") 47 local filename = dir.path(dirname, "luarocks.lock")
41 local _, result, errcode = persist.run_file(filename, {}) 48 local _, result, errcode = persist.run_file(filename, {})
@@ -52,19 +59,20 @@ function deplocks.load(root_rock_name, dirname)
52 deplock_abs_filename = fs.absolute_name(filename) 59 deplock_abs_filename = fs.absolute_name(filename)
53 deplock_root_rock_name = root_rock_name 60 deplock_root_rock_name = root_rock_name
54 61
55 deptable = result 62
63 depstable = result
56 return true, filename 64 return true, filename
57end 65end
58 66
59function deplocks.add(depskey, name, version) 67function deplocks.add(depskey, name, version)
60 if deptable_mode == "locked" then 68 if depstable_mode == "locked" then
61 return 69 return
62 end 70 end
63 71
64 local dk = deptable[depskey] 72 local dk = depstable[depskey]
65 if not dk then 73 if not dk then
66 dk = {} 74 dk = {}
67 deptable[depskey] = dk 75 depstable[depskey] = dk
68 end 76 end
69 77
70 if type(dk) == "table" and not dk[name] then 78 if type(dk) == "table" and not dk[name] then
@@ -73,23 +81,19 @@ function deplocks.add(depskey, name, version)
73end 81end
74 82
75function deplocks.get(depskey, name) 83function deplocks.get(depskey, name)
76 local dk = deptable[depskey] 84 local dk = depstable[depskey]
77 if not dk then
78 return nil
79 end
80 if type(dk) == "table" then 85 if type(dk) == "table" then
81 return dk[name] 86 return dk[name]
82 else
83 return dk
84 end 87 end
88 return nil
85end 89end
86 90
87function deplocks.write_file() 91function deplocks.write_file()
88 if deptable_mode ~= "create" then 92 if depstable_mode ~= "create" then
89 return true 93 return true
90 end 94 end
91 95
92 return persist.save_as_module(deplock_abs_filename, deptable) 96 return persist.save_as_module(deplock_abs_filename, depstable)
93end 97end
94 98
95 99
@@ -105,7 +109,7 @@ function deplocks.proxy(depskey)
105end 109end
106 110
107function deplocks.each(depskey) 111function deplocks.each(depskey)
108 return util.sortedpairs(deptable[depskey] or {}) 112 return util.sortedpairs(depstable[depskey] or {})
109end 113end
110 114
111return deplocks 115return deplocks
diff --git a/src/luarocks/deplocks.tl b/src/luarocks/deplocks.tl
index 37c0c700..2c4889bd 100644
--- a/src/luarocks/deplocks.tl
+++ b/src/luarocks/deplocks.tl
@@ -1,28 +1,35 @@
1local deplocks = {} 1local deplocks = {}
2 2
3local record DepsTable
4 dependencies: {string: string}
5 build_dependencies: {string: string}
6 test_dependencies: {string: string}
7end
8
3local fs = require("luarocks.fs") 9local fs = require("luarocks.fs")
4local dir = require("luarocks.dir") 10local dir = require("luarocks.dir")
5local util = require("luarocks.util") 11local util = require("luarocks.util")
6local persist = require("luarocks.persist") 12local persist = require("luarocks.persist")
7 13
14local type DepsKey = require("luarocks.core.types.depskey").DepsKey
8local type PersistableTable = require("luarocks.core.types.persist").PersistableTable 15local type PersistableTable = require("luarocks.core.types.persist").PersistableTable
9 16
10local deptable: PersistableTable = {} 17local depstable: DepsTable = {}
11local deptable_mode = "start" 18local depstable_mode = "start"
12local deplock_abs_filename: string 19local deplock_abs_filename: string
13local deplock_root_rock_name: string 20local deplock_root_rock_name: string
14 21
15function deplocks.init(root_rock_name: string, dirname: string) 22function deplocks.init(root_rock_name: string, dirname: string)
16 if deptable_mode ~= "start" then 23 if depstable_mode ~= "start" then
17 return 24 return
18 end 25 end
19 deptable_mode = "create" 26 depstable_mode = "create"
20 27
21 local filename = dir.path(dirname, "luarocks.lock") 28 local filename = dir.path(dirname, "luarocks.lock")
22 deplock_abs_filename = fs.absolute_name(filename) 29 deplock_abs_filename = fs.absolute_name(filename)
23 deplock_root_rock_name = root_rock_name 30 deplock_root_rock_name = root_rock_name
24 31
25 deptable = {} 32 depstable = {}
26end 33end
27 34
28function deplocks.get_abs_filename(root_rock_name: string): string 35function deplocks.get_abs_filename(root_rock_name: string): string
@@ -32,10 +39,10 @@ function deplocks.get_abs_filename(root_rock_name: string): string
32end 39end
33 40
34function deplocks.load(root_rock_name: string, dirname: string): boolean, string, string 41function deplocks.load(root_rock_name: string, dirname: string): boolean, string, string
35 if deptable_mode ~= "start" then 42 if depstable_mode ~= "start" then
36 return true, nil 43 return true, nil
37 end 44 end
38 deptable_mode = "locked" 45 depstable_mode = "locked"
39 46
40 local filename = dir.path(dirname, "luarocks.lock") 47 local filename = dir.path(dirname, "luarocks.lock")
41 local _, result, errcode = persist.run_file(filename, {}) 48 local _, result, errcode = persist.run_file(filename, {})
@@ -52,50 +59,47 @@ function deplocks.load(root_rock_name: string, dirname: string): boolean, string
52 deplock_abs_filename = fs.absolute_name(filename) 59 deplock_abs_filename = fs.absolute_name(filename)
53 deplock_root_rock_name = root_rock_name 60 deplock_root_rock_name = root_rock_name
54 61
55 deptable = result as PersistableTable --! cast 62 -- FIXME we're not really checking that the table is a DepsTable
63 depstable = result as DepsTable
56 return true, filename 64 return true, filename
57end 65end
58 66
59function deplocks.add(depskey: string, name: string, version: string) 67function deplocks.add(depskey: DepsKey, name: string, version: string)
60 if deptable_mode == "locked" then 68 if depstable_mode == "locked" then
61 return 69 return
62 end 70 end
63 71
64 local dk = deptable[depskey] 72 local dk = depstable[depskey]
65 if not dk then 73 if not dk then
66 dk = {} 74 dk = {}
67 deptable[depskey] = dk 75 depstable[depskey] = dk
68 end 76 end
69 77
70 if dk is PersistableTable and not dk[name] then 78 if dk is {string: string} and not dk[name] then
71 dk[name] = version 79 dk[name] = version
72 end 80 end
73end 81end
74 82
75function deplocks.get(depskey: string, name: string): string | number | boolean | PersistableTable 83function deplocks.get(depskey: DepsKey, name: string): string
76 local dk = deptable[depskey] 84 local dk = depstable[depskey]
77 if not dk then 85 if dk is {string: string} then
78 return nil
79 end
80 if dk is PersistableTable then
81 return dk[name] 86 return dk[name]
82 else
83 return dk
84 end 87 end
88 return nil
85end 89end
86 90
87function deplocks.write_file(): boolean, string 91function deplocks.write_file(): boolean, string
88 if deptable_mode ~= "create" then 92 if depstable_mode ~= "create" then
89 return true 93 return true
90 end 94 end
91 95
92 return persist.save_as_module(deplock_abs_filename, deptable) 96 return persist.save_as_module(deplock_abs_filename, depstable as PersistableTable)
93end 97end
94 98
95-- a table-like interface to deplocks 99-- a table-like interface to deplocks
96function deplocks.proxy(depskey: string): PersistableTable 100function deplocks.proxy(depskey: DepsKey): {string: string}
97 return setmetatable({}, { 101 return setmetatable({}, {
98 __index = function(_, k: string): string | number | boolean | PersistableTable 102 __index = function(_, k: string): string
99 return deplocks.get(depskey, k) 103 return deplocks.get(depskey, k)
100 end, 104 end,
101 __newindex = function(_, k: string, v: string) 105 __newindex = function(_, k: string, v: string)
@@ -104,8 +108,8 @@ function deplocks.proxy(depskey: string): PersistableTable
104 }) 108 })
105end 109end
106 110
107function deplocks.each(depskey: string): function(): string | number, string | number | boolean | PersistableTable 111function deplocks.each(depskey: DepsKey): function(): string, string
108 return util.sortedpairs(deptable[depskey] as PersistableTable or {}) 112 return util.sortedpairs(depstable[depskey] or {})
109end 113end
110 114
111return deplocks 115return deplocks
diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua
index c960f3b7..f02070a6 100644
--- a/src/luarocks/deps.lua
+++ b/src/luarocks/deps.lua
@@ -296,16 +296,9 @@ function deps.fulfill_dependencies(rockspec, depskey, deps_mode, verify, deplock
296 util.printout("Using dependencies pinned in lockfile: " .. filename) 296 util.printout("Using dependencies pinned in lockfile: " .. filename)
297 297
298 local get_versions = prepare_get_versions("none", rocks_provided, depskey) 298 local get_versions = prepare_get_versions("none", rocks_provided, depskey)
299 local dnsnamestr, dversionstr
300 for dnsname, dversion in deplocks.each(depskey) do 299 for dnsname, dversion in deplocks.each(depskey) do
301 if type(dnsname) == "string" then 300 local dname, dnamespace = util.split_namespace(dnsname)
302 dnsnamestr = dnsname 301 local depq = queries.new(dname, dnamespace, dversion)
303 end
304 if type(dversion) == "string" then
305 dversionstr = dversion
306 end
307 local dname, dnamespace = util.split_namespace(dnsnamestr)
308 local depq = queries.new(dname, dnamespace, dversionstr)
309 302
310 util.printout(("%s %s is pinned to %s (%s)"):format( 303 util.printout(("%s %s is pinned to %s (%s)"):format(
311 name, version, tostring(depq), rock_status(depq, get_versions))) 304 name, version, tostring(depq), rock_status(depq, get_versions)))
diff --git a/src/luarocks/deps.tl b/src/luarocks/deps.tl
index e26ba60f..17584c36 100644
--- a/src/luarocks/deps.tl
+++ b/src/luarocks/deps.tl
@@ -28,13 +28,13 @@ local type Query = require("luarocks.core.types.query").Query
28 28
29local type Version = require("luarocks.core.types.version").Version 29local type Version = require("luarocks.core.types.version").Version
30 30
31local type PersistableTable = require("luarocks.core.types.persist").PersistableTable
32
33local type Result = require("luarocks.core.types.result").Result 31local type Result = require("luarocks.core.types.result").Result
34 32
35local type Dir = require("luarocks.core.types.dir").Dir 33local type Dir = require("luarocks.core.types.dir").Dir
36local type Dirs = require("luarocks.core.types.dir").Dirs 34local type Dirs = require("luarocks.core.types.dir").Dirs
37 35
36local type DepsKey = require("luarocks.core.types.depskey").DepsKey
37
38local type Args = require("luarocks.core.types.args").Args 38local type Args = require("luarocks.core.types.args").Args
39 39
40--- Generate a function that matches dep queries against the manifest, 40--- Generate a function that matches dep queries against the manifest,
@@ -54,9 +54,9 @@ local type Args = require("luarocks.core.types.args").Args
54-- * map of versions to locations 54-- * map of versions to locations
55-- * version matched via lockfile if any 55-- * version matched via lockfile if any
56-- * true if rock matched via rocks_provided 56-- * true if rock matched via rocks_provided
57local function prepare_get_versions(deps_mode: string, rocks_provided: {string : string}, depskey: string, skip_set?: {string: {string: boolean}}): function(Query): {string}, {string: string | Tree}, string | number | boolean | PersistableTable, boolean 57local function prepare_get_versions(deps_mode: string, rocks_provided: {string : string}, depskey: DepsKey, skip_set?: {string: {string: boolean}}): function(Query): {string}, {string: string | Tree}, string, boolean
58 58
59 return function(dep: Query): {string}, {string: string | Tree}, string | number | boolean | PersistableTable, boolean 59 return function(dep: Query): {string}, {string: string | Tree}, string, boolean
60 local versions, locations: {string}, {string: string | Tree} 60 local versions, locations: {string}, {string: string | Tree}
61 local provided = rocks_provided[dep.name] 61 local provided = rocks_provided[dep.name]
62 if provided then 62 if provided then
@@ -78,7 +78,7 @@ local function prepare_get_versions(deps_mode: string, rocks_provided: {string :
78 end 78 end
79 end 79 end
80 80
81 local lockversion = deplocks.get(depskey, dep.name) --! cast? 81 local lockversion = deplocks.get(depskey, dep.name)
82 82
83 return versions, locations, lockversion, provided ~= nil 83 return versions, locations, lockversion, provided ~= nil
84 end 84 end
@@ -206,7 +206,7 @@ function deps.report_missing_dependencies(name: string, version: string, depende
206 end 206 end
207end 207end
208 208
209function deps.fulfill_dependency(dep: Query, deps_mode: string, rocks_provided: {string: string}, verify: boolean, depskey?: string): boolean, string, string | Tree 209function deps.fulfill_dependency(dep: Query, deps_mode: string, rocks_provided: {string: string}, verify: boolean, depskey?: DepsKey): boolean, string, string | Tree
210 210
211 deps_mode = deps_mode or "all" 211 deps_mode = deps_mode or "all"
212 rocks_provided = rocks_provided or {} 212 rocks_provided = rocks_provided or {}
@@ -286,7 +286,7 @@ end
286-- @return boolean or (nil, string, [string]): True if no errors occurred, or 286-- @return boolean or (nil, string, [string]): True if no errors occurred, or
287-- nil and an error message if any test failed, followed by an optional 287-- nil and an error message if any test failed, followed by an optional
288-- error code. 288-- error code.
289function deps.fulfill_dependencies(rockspec: Rockspec, depskey: string, deps_mode: string, verify?: boolean, deplock_dir?: string): boolean, string, string 289function deps.fulfill_dependencies(rockspec: Rockspec, depskey: DepsKey, deps_mode: string, verify?: boolean, deplock_dir?: string): boolean, string, string
290 local name = rockspec.name 290 local name = rockspec.name
291 local version = rockspec.version 291 local version = rockspec.version
292 local rocks_provided = rockspec.rocks_provided 292 local rocks_provided = rockspec.rocks_provided
@@ -296,16 +296,9 @@ function deps.fulfill_dependencies(rockspec: Rockspec, depskey: string, deps_mod
296 util.printout("Using dependencies pinned in lockfile: " .. filename) 296 util.printout("Using dependencies pinned in lockfile: " .. filename)
297 297
298 local get_versions = prepare_get_versions("none", rocks_provided, depskey) 298 local get_versions = prepare_get_versions("none", rocks_provided, depskey)
299 local dnsnamestr, dversionstr: string, string
300 for dnsname, dversion in deplocks.each(depskey) do 299 for dnsname, dversion in deplocks.each(depskey) do
301 if dnsname is string then 300 local dname, dnamespace = util.split_namespace(dnsname)
302 dnsnamestr = dnsname 301 local depq = queries.new(dname, dnamespace, dversion)
303 end
304 if dversion is string then
305 dversionstr = dversion
306 end
307 local dname, dnamespace = util.split_namespace(dnsnamestr)
308 local depq = queries.new(dname, dnamespace, dversionstr)
309 302
310 util.printout(("%s %s is pinned to %s (%s)"):format( 303 util.printout(("%s %s is pinned to %s (%s)"):format(
311 name, version, tostring(depq), rock_status(depq, get_versions))) 304 name, version, tostring(depq), rock_status(depq, get_versions)))
diff --git a/src/luarocks/test.tl b/src/luarocks/test.tl
index d076d264..e68096b8 100644
--- a/src/luarocks/test.tl
+++ b/src/luarocks/test.tl
@@ -7,6 +7,7 @@ local util = require("luarocks.util")
7 7
8local type Rockspec = require("luarocks.core.types.rockspec").Rockspec 8local type Rockspec = require("luarocks.core.types.rockspec").Rockspec
9local type Dependencies = require("luarocks.core.types.rockspec").Dependencies 9local type Dependencies = require("luarocks.core.types.rockspec").Dependencies
10local type DepsKey = require("luarocks.core.types.depskey").DepsKey
10 11
11local type TestRunner = require("luarocks.core.types.testrunner").TestRunner 12local type TestRunner = require("luarocks.core.types.testrunner").TestRunner
12 13
@@ -66,7 +67,7 @@ function test.run_test_suite(rockspec_arg: string | Rockspec, test_type: string,
66 end 67 end
67 end 68 end
68 69
69 local all_deps = { 70 local all_deps: {DepsKey} = {
70 "dependencies", 71 "dependencies",
71 "build_dependencies", 72 "build_dependencies",
72 "test_dependencies", 73 "test_dependencies",