aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-03 20:33:22 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:51:31 +0300
commitc90e0dc942626324e3fb81f03f111580d8ea9423 (patch)
tree268272e0b9aea16f085ff28245e549d1e73b6a49
parentd518c44235c3a820487f9218a83eff4b68792d7a (diff)
downloadluarocks-c90e0dc942626324e3fb81f03f111580d8ea9423.tar.gz
luarocks-c90e0dc942626324e3fb81f03f111580d8ea9423.tar.bz2
luarocks-c90e0dc942626324e3fb81f03f111580d8ea9423.zip
deplocks
-rw-r--r--src/luarocks/core/cfg.d.tl3
-rw-r--r--src/luarocks/core/manif.tl6
-rw-r--r--src/luarocks/deplocks-origianal.lua106
-rw-r--r--src/luarocks/deplocks.lua12
-rw-r--r--src/luarocks/deplocks.tl108
5 files changed, 227 insertions, 8 deletions
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl
index 7b74f258..26aec8d9 100644
--- a/src/luarocks/core/cfg.d.tl
+++ b/src/luarocks/core/cfg.d.tl
@@ -89,6 +89,9 @@ local record cfg
89 tool_version: string 89 tool_version: string
90 api_version: string 90 api_version: string
91 end 91 end
92 -- loader
93 init: function(): boolean, string, string
94 init_package_paths: function
92end 95end
93 96
94return cfg \ No newline at end of file 97return cfg \ No newline at end of file
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl
index 0713d293..cfa53dd0 100644
--- a/src/luarocks/core/manif.tl
+++ b/src/luarocks/core/manif.tl
@@ -7,13 +7,13 @@ local util = require("luarocks.core.util")
7local vers = require("luarocks.core.vers") 7local vers = require("luarocks.core.vers")
8local path = require("luarocks.core.path") 8local path = require("luarocks.core.path")
9 9
10local type Constraints = vers.Constraints 10local type Constraint = vers.Constraint
11 11
12--- Core functions for querying manifest files. 12--- Core functions for querying manifest files.
13local record manif 13local record manif
14 14
15 record DependencyVersion 15 record DependencyVersion
16 constraints: {Constraints} 16 constraints: {Constraint}
17 name: string 17 name: string
18 end 18 end
19 19
@@ -96,7 +96,7 @@ function manif.fast_load_local_manifest(repo_url: string): Manifest, string | {a
96 return manif.manifest_loader(pathname, repo_url, nil) 96 return manif.manifest_loader(pathname, repo_url, nil)
97end 97end
98 98
99function manif.load_rocks_tree_manifests(deps_mode: string): {Tree_manifest} 99function manif.load_rocks_tree_manifests(deps_mode?: string): {Tree_manifest}
100 local trees = {} 100 local trees = {}
101 path.map_trees(deps_mode, function(tree: cfg.Tree) 101 path.map_trees(deps_mode, function(tree: cfg.Tree)
102 local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree)) 102 local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree))
diff --git a/src/luarocks/deplocks-origianal.lua b/src/luarocks/deplocks-origianal.lua
new file mode 100644
index 00000000..d62908f4
--- /dev/null
+++ b/src/luarocks/deplocks-origianal.lua
@@ -0,0 +1,106 @@
1local deplocks = {}
2
3local fs = require("luarocks.fs")
4local dir = require("luarocks.dir")
5local util = require("luarocks.util")
6local persist = require("luarocks.persist")
7
8local deptable = {}
9local deptable_mode = "start"
10local deplock_abs_filename
11local deplock_root_rock_name
12
13function deplocks.init(root_rock_name, dirname)
14 if deptable_mode ~= "start" then
15 return
16 end
17 deptable_mode = "create"
18
19 local filename = dir.path(dirname, "luarocks.lock")
20 deplock_abs_filename = fs.absolute_name(filename)
21 deplock_root_rock_name = root_rock_name
22
23 deptable = {}
24end
25
26function deplocks.get_abs_filename(root_rock_name)
27 if root_rock_name == deplock_root_rock_name then
28 return deplock_abs_filename
29 end
30end
31
32function deplocks.load(root_rock_name, dirname)
33 if deptable_mode ~= "start" then
34 return true, nil
35 end
36 deptable_mode = "locked"
37
38 local filename = dir.path(dirname, "luarocks.lock")
39 local ok, result, errcode = persist.run_file(filename, {})
40 if errcode == "load" or errcode == "run" then
41 -- bad config file or depends on env, so error out
42 return nil, nil, "Could not read existing lockfile " .. filename
43 end
44
45 if errcode == "open" then
46 -- could not open, maybe file does not exist
47 return true, nil
48 end
49
50 deplock_abs_filename = fs.absolute_name(filename)
51 deplock_root_rock_name = root_rock_name
52
53 deptable = result
54 return true, filename
55end
56
57function deplocks.add(depskey, name, version)
58 if deptable_mode == "locked" then
59 return
60 end
61
62 local dk = deptable[depskey]
63 if not dk then
64 dk = {}
65 deptable[depskey] = dk
66 end
67
68 if not dk[name] then
69 dk[name] = version
70 end
71end
72
73function deplocks.get(depskey, name)
74 local dk = deptable[depskey]
75 if not dk then
76 return nil
77 end
78
79 return deptable[name]
80end
81
82function deplocks.write_file()
83 if deptable_mode ~= "create" then
84 return true
85 end
86
87 return persist.save_as_module(deplock_abs_filename, deptable)
88end
89
90-- a table-like interface to deplocks
91function deplocks.proxy(depskey)
92 return setmetatable({}, {
93 __index = function(_, k)
94 return deplocks.get(depskey, k)
95 end,
96 __newindex = function(_, k, v)
97 return deplocks.add(depskey, k, v)
98 end,
99 })
100end
101
102function deplocks.each(depskey)
103 return util.sortedpairs(deptable[depskey] or {})
104end
105
106return deplocks
diff --git a/src/luarocks/deplocks.lua b/src/luarocks/deplocks.lua
index d62908f4..1f6b4c82 100644
--- a/src/luarocks/deplocks.lua
+++ b/src/luarocks/deplocks.lua
@@ -5,6 +5,8 @@ local dir = require("luarocks.dir")
5local util = require("luarocks.util") 5local util = require("luarocks.util")
6local persist = require("luarocks.persist") 6local persist = require("luarocks.persist")
7 7
8
9
8local deptable = {} 10local deptable = {}
9local deptable_mode = "start" 11local deptable_mode = "start"
10local deplock_abs_filename 12local deplock_abs_filename
@@ -36,14 +38,14 @@ function deplocks.load(root_rock_name, dirname)
36 deptable_mode = "locked" 38 deptable_mode = "locked"
37 39
38 local filename = dir.path(dirname, "luarocks.lock") 40 local filename = dir.path(dirname, "luarocks.lock")
39 local ok, result, errcode = persist.run_file(filename, {}) 41 local _, result, errcode = persist.run_file(filename, {})
40 if errcode == "load" or errcode == "run" then 42 if errcode == "load" or errcode == "run" then
41 -- bad config file or depends on env, so error out 43
42 return nil, nil, "Could not read existing lockfile " .. filename 44 return nil, nil, "Could not read existing lockfile " .. filename
43 end 45 end
44 46
45 if errcode == "open" then 47 if errcode == "open" then
46 -- could not open, maybe file does not exist 48
47 return true, nil 49 return true, nil
48 end 50 end
49 51
@@ -65,7 +67,7 @@ function deplocks.add(depskey, name, version)
65 deptable[depskey] = dk 67 deptable[depskey] = dk
66 end 68 end
67 69
68 if not dk[name] then 70 if type(dk) == "table" and not dk[name] then
69 dk[name] = version 71 dk[name] = version
70 end 72 end
71end 73end
@@ -87,7 +89,7 @@ function deplocks.write_file()
87 return persist.save_as_module(deplock_abs_filename, deptable) 89 return persist.save_as_module(deplock_abs_filename, deptable)
88end 90end
89 91
90-- a table-like interface to deplocks 92
91function deplocks.proxy(depskey) 93function deplocks.proxy(depskey)
92 return setmetatable({}, { 94 return setmetatable({}, {
93 __index = function(_, k) 95 __index = function(_, k)
diff --git a/src/luarocks/deplocks.tl b/src/luarocks/deplocks.tl
new file mode 100644
index 00000000..693dd04b
--- /dev/null
+++ b/src/luarocks/deplocks.tl
@@ -0,0 +1,108 @@
1local deplocks = {}
2
3local fs = require("luarocks.fs")
4local dir = require("luarocks.dir")
5local util = require("luarocks.util")
6local persist = require("luarocks.persist")
7
8local type PersistableTable = persist.PersistableTable
9
10local deptable: PersistableTable = {}
11local deptable_mode = "start"
12local deplock_abs_filename: string
13local deplock_root_rock_name: string
14
15function deplocks.init(root_rock_name: string, dirname: string)
16 if deptable_mode ~= "start" then
17 return
18 end
19 deptable_mode = "create"
20
21 local filename = dir.path(dirname, "luarocks.lock")
22 deplock_abs_filename = fs.absolute_name(filename)
23 deplock_root_rock_name = root_rock_name
24
25 deptable = {}
26end
27
28function deplocks.get_abs_filename(root_rock_name: string): string
29 if root_rock_name == deplock_root_rock_name then
30 return deplock_abs_filename
31 end
32end
33
34function deplocks.load(root_rock_name: string, dirname: string): boolean, string, string
35 if deptable_mode ~= "start" then
36 return true, nil
37 end
38 deptable_mode = "locked"
39
40 local filename = dir.path(dirname, "luarocks.lock")
41 local _, result, errcode = persist.run_file(filename, {})
42 if errcode == "load" or errcode == "run" then
43 -- bad config file or depends on env, so error out
44 return nil, nil, "Could not read existing lockfile " .. filename
45 end
46
47 if errcode == "open" then
48 -- could not open, maybe file does not exist
49 return true, nil
50 end
51
52 deplock_abs_filename = fs.absolute_name(filename)
53 deplock_root_rock_name = root_rock_name
54
55 deptable = result as PersistableTable --! cast
56 return true, filename
57end
58
59function deplocks.add(depskey: string, name: string, version: string)
60 if deptable_mode == "locked" then
61 return
62 end
63
64 local dk = deptable[depskey]
65 if not dk then
66 dk = {}
67 deptable[depskey] = dk
68 end
69
70 if dk is PersistableTable and not dk[name] then
71 dk[name] = version
72 end
73end
74
75function deplocks.get(depskey: string, name: string): string | number | boolean | PersistableTable
76 local dk = deptable[depskey]
77 if not dk then
78 return nil
79 end
80
81 return deptable[name]
82end
83
84function deplocks.write_file(): boolean, string
85 if deptable_mode ~= "create" then
86 return true
87 end
88
89 return persist.save_as_module(deplock_abs_filename, deptable)
90end
91
92-- a table-like interface to deplocks
93function deplocks.proxy(depskey: string): PersistableTable
94 return setmetatable({}, {
95 __index = function(_, k: string): string | number | boolean | PersistableTable
96 return deplocks.get(depskey, k)
97 end,
98 __newindex = function(_, k: string, v: string)
99 return deplocks.add(depskey, k, v)
100 end,
101 })
102end
103
104function deplocks.each(depskey: string): function(): string | number, string | number | boolean | PersistableTable
105 return util.sortedpairs(deptable[depskey] as PersistableTable or {})
106end
107
108return deplocks \ No newline at end of file