diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-07-12 23:48:15 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:49:17 +0300 |
commit | 13d93b09e6306dcb0eba3dd11292af0ed55a9a05 (patch) | |
tree | e0fa8bd9e4ed718f723c60cc6271505a4d004b77 | |
parent | 0efd878f6435c4d929c101f7c1388801096c6004 (diff) | |
download | luarocks-13d93b09e6306dcb0eba3dd11292af0ed55a9a05.tar.gz luarocks-13d93b09e6306dcb0eba3dd11292af0ed55a9a05.tar.bz2 luarocks-13d93b09e6306dcb0eba3dd11292af0ed55a9a05.zip |
manif test
-rw-r--r-- | src/luarocks/core/manif-original.lua (renamed from src/luarocks/core/manif-incomplete.lua) | 112 | ||||
-rw-r--r-- | src/luarocks/core/manif.lua | 105 | ||||
-rw-r--r-- | src/luarocks/core/manif.tl | 36 | ||||
-rw-r--r-- | src/luarocks/core/util.lua | 7 | ||||
-rw-r--r-- | src/luarocks/core/util.tl | 17 | ||||
-rw-r--r-- | src/luarocks/dir.lua (renamed from src/luarocks/dir-original.lua) | 0 | ||||
-rw-r--r-- | src/luarocks/dir.tl | 7 | ||||
-rw-r--r-- | src/luarocks/fs.d.tl | 13 | ||||
-rw-r--r-- | src/luarocks/fs.lua (renamed from src/luarocks/fs-original.lua) | 0 | ||||
-rw-r--r-- | src/luarocks/fs.tl | 151 | ||||
-rw-r--r-- | src/luarocks/util.lua (renamed from src/luarocks/util-original.lua) | 0 | ||||
-rw-r--r-- | src/luarocks/util.tl | 6 |
12 files changed, 149 insertions, 305 deletions
diff --git a/src/luarocks/core/manif-incomplete.lua b/src/luarocks/core/manif-original.lua index 758b76db..3925f636 100644 --- a/src/luarocks/core/manif-incomplete.lua +++ b/src/luarocks/core/manif-original.lua | |||
@@ -1,112 +1,62 @@ | |||
1 | local _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 table = _tl_compat and _tl_compat.table or table | ||
2 | 1 | ||
2 | --- Core functions for querying manifest files. | ||
3 | local manif = {} | 3 | local manif = {} |
4 | 4 | ||
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 | |||
57 | local persist = require("luarocks.core.persist") | 5 | local persist = require("luarocks.core.persist") |
58 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
59 | local dir = require("luarocks.core.dir") | 7 | local dir = require("luarocks.core.dir") |
60 | local util = require("luarocks.core.util") | 8 | local util = require("luarocks.core.util") |
61 | local vers = require("luarocks.core.vers") | 9 | local vers = require("luarocks.core.vers") |
62 | local path = require("luarocks.core.path") | 10 | local path = require("luarocks.core.path") |
11 | local require = nil | ||
12 | -------------------------------------------------------------------------------- | ||
63 | 13 | ||
64 | 14 | -- Table with repository identifiers as keys and tables mapping | |
65 | 15 | -- Lua versions to cached loaded manifests as values. | |
66 | |||
67 | local manifest_cache = {} | 16 | local manifest_cache = {} |
68 | 17 | ||
69 | 18 | --- Cache a loaded manifest. | |
70 | 19 | -- @param repo_url string: The repository identifier. | |
71 | 20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
72 | 21 | -- @param manifest table: the manifest to be cached. | |
73 | function manif.cache_manifest(repo_url, lua_version, manifest) | 22 | function manif.cache_manifest(repo_url, lua_version, manifest) |
74 | lua_version = lua_version or cfg.lua_version | 23 | lua_version = lua_version or cfg.lua_version |
75 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} | 24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} |
76 | manifest_cache[repo_url][lua_version] = manifest | 25 | manifest_cache[repo_url][lua_version] = manifest |
77 | end | 26 | end |
78 | 27 | ||
79 | 28 | --- Attempt to get cached loaded manifest. | |
80 | 29 | -- @param repo_url string: The repository identifier. | |
81 | 30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
82 | 31 | -- @return table or nil: loaded manifest or nil if cache is empty. | |
83 | function manif.get_cached_manifest(repo_url, lua_version) | 32 | function manif.get_cached_manifest(repo_url, lua_version) |
84 | lua_version = lua_version or cfg.lua_version | 33 | lua_version = lua_version or cfg.lua_version |
85 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] | 34 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] |
86 | end | 35 | end |
87 | 36 | ||
88 | 37 | --- Back-end function that actually loads the manifest | |
89 | 38 | -- and stores it in the manifest cache. | |
90 | 39 | -- @param file string: The local filename of the manifest file. | |
91 | 40 | -- @param repo_url string: The repository identifier. | |
92 | 41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
93 | 42 | -- @return table or (nil, string, string): the manifest or nil, | |
94 | 43 | -- error message and error code ("open", "load", "run"). | |
95 | function manif.manifest_loader(file, repo_url, lua_version) | 44 | function manif.manifest_loader(file, repo_url, lua_version) |
96 | local manifest, err, errcode = persist.load_into_table(file) | 45 | local manifest, err, errcode = persist.load_into_table(file) |
97 | if not (type(manifest) == "table") then | 46 | if not manifest then |
98 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode | 47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode |
99 | end | 48 | end |
100 | manif.cache_manifest(repo_url, lua_version, manifest) | 49 | manif.cache_manifest(repo_url, lua_version, manifest) |
101 | return manifest, err, errcode | 50 | return manifest, err, errcode |
102 | end | 51 | end |
103 | 52 | ||
104 | 53 | --- Load a local manifest describing a repository. | |
105 | 54 | -- This is used by the luarocks.loader only. | |
106 | 55 | -- @param repo_url string: URL or pathname for the repository. | |
107 | 56 | -- @return table or (nil, string, string): A table representing the manifest, | |
108 | 57 | -- or nil followed by an error message and an error code, see manifest_loader. | |
109 | function manif.fast_load_local_manifest(repo_url) | 58 | function manif.fast_load_local_manifest(repo_url) |
59 | assert(type(repo_url) == "string") | ||
110 | 60 | ||
111 | local cached_manifest = manif.get_cached_manifest(repo_url) | 61 | local cached_manifest = manif.get_cached_manifest(repo_url) |
112 | if cached_manifest then | 62 | if cached_manifest then |
@@ -114,15 +64,15 @@ function manif.fast_load_local_manifest(repo_url) | |||
114 | end | 64 | end |
115 | 65 | ||
116 | local pathname = dir.path(repo_url, "manifest") | 66 | local pathname = dir.path(repo_url, "manifest") |
117 | return manif.manifest_loader(pathname, repo_url, nil) | 67 | return manif.manifest_loader(pathname, repo_url, nil, true) |
118 | end | 68 | end |
119 | 69 | ||
120 | function manif.load_rocks_tree_manifests(deps_mode) | 70 | function manif.load_rocks_tree_manifests(deps_mode) |
121 | local trees = {} | 71 | local trees = {} |
122 | path.map_trees(deps_mode, function(tree) | 72 | path.map_trees(deps_mode, function(tree) |
123 | local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) | 73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
124 | if manifest then | 74 | if manifest then |
125 | table.insert(trees, { tree = tree, manifest = manifest }) | 75 | table.insert(trees, {tree=tree, manifest=manifest}) |
126 | end | 76 | end |
127 | end) | 77 | end) |
128 | return trees | 78 | return trees |
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index 3925f636..7d7d68fa 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua | |||
@@ -1,62 +1,88 @@ | |||
1 | 1 | local _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 table = _tl_compat and _tl_compat.table or table; local persist = require("luarocks.core.persist") | |
2 | --- Core functions for querying manifest files. | ||
3 | local manif = {} | ||
4 | |||
5 | local persist = require("luarocks.core.persist") | ||
6 | local cfg = require("luarocks.core.cfg") | 2 | local cfg = require("luarocks.core.cfg") |
7 | local dir = require("luarocks.core.dir") | 3 | local dir = require("luarocks.core.dir") |
8 | local util = require("luarocks.core.util") | 4 | local util = require("luarocks.core.util") |
9 | local vers = require("luarocks.core.vers") | 5 | local vers = require("luarocks.core.vers") |
10 | local path = require("luarocks.core.path") | 6 | local path = require("luarocks.core.path") |
11 | local require = nil | ||
12 | -------------------------------------------------------------------------------- | ||
13 | 7 | ||
14 | -- Table with repository identifiers as keys and tables mapping | 8 | |
15 | -- Lua versions to cached loaded manifests as values. | 9 | |
10 | |||
11 | local manif = {DependencyVersion = {}, Manifest = {}, Tree_manifest = {}, } | ||
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 | |||
16 | local manifest_cache = {} | 42 | local manifest_cache = {} |
17 | 43 | ||
18 | --- Cache a loaded manifest. | 44 | |
19 | -- @param repo_url string: The repository identifier. | 45 | |
20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 46 | |
21 | -- @param manifest table: the manifest to be cached. | 47 | |
22 | function manif.cache_manifest(repo_url, lua_version, manifest) | 48 | function manif.cache_manifest(repo_url, lua_version, manifest) |
23 | lua_version = lua_version or cfg.lua_version | 49 | lua_version = lua_version or cfg.lua_version |
24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} | 50 | manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} |
25 | manifest_cache[repo_url][lua_version] = manifest | 51 | manifest_cache.repository[repo_url][lua_version] = manifest |
26 | end | 52 | end |
27 | 53 | ||
28 | --- Attempt to get cached loaded manifest. | 54 | |
29 | -- @param repo_url string: The repository identifier. | 55 | |
30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 56 | |
31 | -- @return table or nil: loaded manifest or nil if cache is empty. | 57 | |
32 | function manif.get_cached_manifest(repo_url, lua_version) | 58 | function manif.get_cached_manifest(repo_url, lua_version) |
33 | lua_version = lua_version or cfg.lua_version | 59 | lua_version = lua_version or cfg.lua_version |
34 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] | 60 | return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] |
35 | end | 61 | end |
36 | 62 | ||
37 | --- Back-end function that actually loads the manifest | 63 | |
38 | -- and stores it in the manifest cache. | 64 | |
39 | -- @param file string: The local filename of the manifest file. | 65 | |
40 | -- @param repo_url string: The repository identifier. | 66 | |
41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 67 | |
42 | -- @return table or (nil, string, string): the manifest or nil, | 68 | |
43 | -- error message and error code ("open", "load", "run"). | 69 | |
44 | function manif.manifest_loader(file, repo_url, lua_version) | 70 | function manif.manifest_loader(file, repo_url, lua_version) |
45 | local manifest, err, errcode = persist.load_into_table(file) | 71 | local manifest, err, errcode = persist.load_into_table(file) |
46 | if not manifest then | 72 | if type(err) == "string" then |
47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode | 73 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode |
48 | end | 74 | end |
75 | |||
49 | manif.cache_manifest(repo_url, lua_version, manifest) | 76 | manif.cache_manifest(repo_url, lua_version, manifest) |
50 | return manifest, err, errcode | 77 | return manifest |
51 | end | 78 | end |
52 | 79 | ||
53 | --- Load a local manifest describing a repository. | 80 | |
54 | -- This is used by the luarocks.loader only. | 81 | |
55 | -- @param repo_url string: URL or pathname for the repository. | 82 | |
56 | -- @return table or (nil, string, string): A table representing the manifest, | 83 | |
57 | -- or nil followed by an error message and an error code, see manifest_loader. | 84 | |
58 | function manif.fast_load_local_manifest(repo_url) | 85 | function manif.fast_load_local_manifest(repo_url) |
59 | assert(type(repo_url) == "string") | ||
60 | 86 | ||
61 | local cached_manifest = manif.get_cached_manifest(repo_url) | 87 | local cached_manifest = manif.get_cached_manifest(repo_url) |
62 | if cached_manifest then | 88 | if cached_manifest then |
@@ -64,15 +90,16 @@ function manif.fast_load_local_manifest(repo_url) | |||
64 | end | 90 | end |
65 | 91 | ||
66 | local pathname = dir.path(repo_url, "manifest") | 92 | local pathname = dir.path(repo_url, "manifest") |
67 | return manif.manifest_loader(pathname, repo_url, nil, true) | 93 | return manif.manifest_loader(pathname, repo_url, nil) |
68 | end | 94 | end |
69 | 95 | ||
70 | function manif.load_rocks_tree_manifests(deps_mode) | 96 | function manif.load_rocks_tree_manifests(deps_mode) |
71 | local trees = {} | 97 | local trees = {} |
72 | path.map_trees(deps_mode, function(tree) | 98 | path.map_trees(deps_mode, function(tree) |
73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) | 99 | local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
74 | if manifest then | 100 | if manifest then |
75 | table.insert(trees, {tree=tree, manifest=manifest}) | 101 | local tree_manifest = { tree = tree, manifest = manifest } |
102 | table.insert(trees, tree_manifest) | ||
76 | end | 103 | end |
77 | end) | 104 | end) |
78 | return trees | 105 | return trees |
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl index 24178f14..cf698d82 100644 --- a/src/luarocks/core/manif.tl +++ b/src/luarocks/core/manif.tl | |||
@@ -1,9 +1,17 @@ | |||
1 | local persist = require("luarocks.core.persist") | ||
2 | local cfg = require("luarocks.core.cfg") | ||
3 | local dir = require("luarocks.core.dir") | ||
4 | local util = require("luarocks.core.util") | ||
5 | local vers = require("luarocks.core.vers") | ||
6 | local path = require("luarocks.core.path") | ||
7 | |||
8 | local type Constraints = vers.Constraints | ||
1 | 9 | ||
2 | --- Core functions for querying manifest files. | 10 | --- Core functions for querying manifest files. |
3 | local record manif | 11 | local record manif |
4 | 12 | ||
5 | record DependencyVersion | 13 | record DependencyVersion |
6 | constraints: {Constraints} --? vers.Constraints | 14 | constraints: {Constraints} |
7 | name: string | 15 | name: string |
8 | end | 16 | end |
9 | 17 | ||
@@ -21,15 +29,8 @@ local record manif | |||
21 | end | 29 | end |
22 | end | 30 | end |
23 | 31 | ||
24 | local persist = require("luarocks.core.persist") --! | ||
25 | local cfg = require("luarocks.core.cfg") | ||
26 | local dir = require("luarocks.core.dir") | ||
27 | local util = require("luarocks.core.util") | ||
28 | local vers = require("luarocks.core.vers") | ||
29 | local path = require("luarocks.core.path") | ||
30 | -------------------------------------------------------------------------------- | 32 | -------------------------------------------------------------------------------- |
31 | 33 | ||
32 | local type Constraints = vers.Constraints | ||
33 | local type DependencyVersion = manif.DependencyVersion | 34 | local type DependencyVersion = manif.DependencyVersion |
34 | local type Manifest = manif.Manifest | 35 | local type Manifest = manif.Manifest |
35 | local type Tree_manifest = manif.Tree_manifest | 36 | local type Tree_manifest = manif.Tree_manifest |
@@ -38,7 +39,7 @@ local type Tree_manifest = manif.Tree_manifest | |||
38 | 39 | ||
39 | -- Table with repository identifiers as keys and tables mapping | 40 | -- Table with repository identifiers as keys and tables mapping |
40 | -- Lua versions to cached loaded manifests as values. | 41 | -- Lua versions to cached loaded manifests as values. |
41 | local manifest_cache: Manifest= {} --? | 42 | local manifest_cache: Manifest = {} |
42 | 43 | ||
43 | --- Cache a loaded manifest. | 44 | --- Cache a loaded manifest. |
44 | -- @param repo_url string: The repository identifier. | 45 | -- @param repo_url string: The repository identifier. |
@@ -56,7 +57,7 @@ end | |||
56 | -- @return table or nil: loaded manifest or nil if cache is empty. | 57 | -- @return table or nil: loaded manifest or nil if cache is empty. |
57 | function manif.get_cached_manifest(repo_url: string, lua_version: string): Manifest | 58 | function manif.get_cached_manifest(repo_url: string, lua_version: string): Manifest |
58 | lua_version = lua_version or cfg.lua_version | 59 | lua_version = lua_version or cfg.lua_version |
59 | return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] --! | 60 | return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] |
60 | end | 61 | end |
61 | 62 | ||
62 | --- Back-end function that actually loads the manifest | 63 | --- Back-end function that actually loads the manifest |
@@ -66,13 +67,14 @@ end | |||
66 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 67 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. |
67 | -- @return table or (nil, string, string): the manifest or nil, | 68 | -- @return table or (nil, string, string): the manifest or nil, |
68 | -- error message and error code ("open", "load", "run"). | 69 | -- error message and error code ("open", "load", "run"). |
69 | function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest | nil, string, string | 70 | function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string, string |
70 | local manifest, err, errcode: {any: any}, {any: any} | string, string = persist.load_into_table(file) | 71 | local manifest, err, errcode: {any: any}, {any: any} | string, string = persist.load_into_table(file) |
71 | if not manifest is Manifest then --! Manifest != {any:any} | 72 | if err is string then |
72 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode | 73 | return nil, "Failed loading manifest for "..repo_url..": " ..err, errcode |
73 | end | 74 | end |
74 | manif.cache_manifest(repo_url, lua_version, manifest) | 75 | |
75 | return manifest, err, errcode | 76 | manif.cache_manifest(repo_url, lua_version, manifest as Manifest) -- No runtime check if manifest is actually a Manifest! |
77 | return manifest as Manifest | ||
76 | end | 78 | end |
77 | 79 | ||
78 | --- Load a local manifest describing a repository. | 80 | --- Load a local manifest describing a repository. |
@@ -93,7 +95,7 @@ end | |||
93 | 95 | ||
94 | function manif.load_rocks_tree_manifests(deps_mode: string): {Tree_manifest} | 96 | function manif.load_rocks_tree_manifests(deps_mode: string): {Tree_manifest} |
95 | local trees = {} | 97 | local trees = {} |
96 | path.map_trees(deps_mode, function(tree: cfg.Tree) --! tree: cfg.Tree | 98 | path.map_trees(deps_mode, function(tree: cfg.Tree) |
97 | local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree)) | 99 | local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree)) |
98 | if manifest then | 100 | if manifest then |
99 | local tree_manifest: Tree_manifest = {tree=tree, manifest=manifest} | 101 | local tree_manifest: Tree_manifest = {tree=tree, manifest=manifest} |
@@ -124,7 +126,7 @@ function manif.scan_dependencies(name: string, version: string, tree_manifests: | |||
124 | local entries = t.manifest.repository[pkg] | 126 | local entries = t.manifest.repository[pkg] |
125 | if entries then | 127 | if entries then |
126 | for ver, _ in util.sortedpairs(entries, vers.compare_versions) do | 128 | for ver, _ in util.sortedpairs(entries, vers.compare_versions) do |
127 | if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then --! | 129 | if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then |
128 | manif.scan_dependencies(pkg, ver, tree_manifests, dest) | 130 | manif.scan_dependencies(pkg, ver, tree_manifests, dest) |
129 | end | 131 | end |
130 | end | 132 | end |
diff --git a/src/luarocks/core/util.lua b/src/luarocks/core/util.lua index 9ddf27a2..8c995fa6 100644 --- a/src/luarocks/core/util.lua +++ b/src/luarocks/core/util.lua | |||
@@ -295,11 +295,12 @@ function util.sortedpairs(tbl, sort_function) | |||
295 | 295 | ||
296 | for _, order_entry in ipairs(order) do | 296 | for _, order_entry in ipairs(order) do |
297 | local key, sub_order | 297 | local key, sub_order |
298 | if type(order_entry) == "table" then | 298 | |
299 | if not (type(order_entry) == "table") then | ||
300 | key = order_entry | ||
301 | else | ||
299 | key = order_entry[1] | 302 | key = order_entry[1] |
300 | sub_order = order_entry[2] | 303 | sub_order = order_entry[2] |
301 | else | ||
302 | key = order_entry | ||
303 | end | 304 | end |
304 | 305 | ||
305 | if tbl[key] then | 306 | if tbl[key] then |
diff --git a/src/luarocks/core/util.tl b/src/luarocks/core/util.tl index 759a7147..d20fa2e0 100644 --- a/src/luarocks/core/util.tl +++ b/src/luarocks/core/util.tl | |||
@@ -233,7 +233,7 @@ end | |||
233 | --- Return an array of keys of a table. | 233 | --- Return an array of keys of a table. |
234 | -- @param tbl table: The input table. | 234 | -- @param tbl table: The input table. |
235 | -- @return table: The array of keys. | 235 | -- @return table: The array of keys. |
236 | function util.keys(tbl: {any:any}): {any} | 236 | function util.keys<K, V>(tbl: {K: V}): {K} |
237 | local ks = {} | 237 | local ks = {} |
238 | for k,_ in pairs(tbl) do | 238 | for k,_ in pairs(tbl) do |
239 | table.insert(ks, k) | 239 | table.insert(ks, k) |
@@ -278,12 +278,12 @@ end | |||
278 | -- for that key, which is returned by the iterator as the third value after the key | 278 | -- for that key, which is returned by the iterator as the third value after the key |
279 | -- and the value. | 279 | -- and the value. |
280 | -- @return function: the iterator function. | 280 | -- @return function: the iterator function. |
281 | function util.sortedpairs(tbl: {any: any}, sort_function: CompFn | {any} | nil): function(): any, any, any | 281 | function util.sortedpairs<K, V, S>(tbl: {K: V}, sort_function: CompFn | {K | {K, S}}): function(): K, V, S |
282 | if not sort_function then | 282 | if not sort_function then |
283 | sort_function = default_sort | 283 | sort_function = default_sort |
284 | end | 284 | end |
285 | local keys = util.keys(tbl) | 285 | local keys = util.keys(tbl) |
286 | local sub_orders = {} | 286 | local sub_orders: {K: S} = {} |
287 | 287 | ||
288 | if sort_function is CompFn then | 288 | if sort_function is CompFn then |
289 | table.sort(keys, sort_function) | 289 | table.sort(keys, sort_function) |
@@ -294,12 +294,13 @@ function util.sortedpairs(tbl: {any: any}, sort_function: CompFn | {any} | nil): | |||
294 | keys = {} | 294 | keys = {} |
295 | 295 | ||
296 | for _, order_entry in ipairs(order) do | 296 | for _, order_entry in ipairs(order) do |
297 | local key, sub_order: any, any | 297 | local key, sub_order: K, S |
298 | if order_entry is {any: any} then | 298 | |
299 | if not order_entry is {K, S} then --TEAL BUG | ||
300 | key = order_entry as K | ||
301 | else | ||
299 | key = order_entry[1] | 302 | key = order_entry[1] |
300 | sub_order = order_entry[2] | 303 | sub_order = order_entry[2] |
301 | else | ||
302 | key = order_entry | ||
303 | end | 304 | end |
304 | 305 | ||
305 | if tbl[key] then | 306 | if tbl[key] then |
@@ -318,7 +319,7 @@ function util.sortedpairs(tbl: {any: any}, sort_function: CompFn | {any} | nil): | |||
318 | end | 319 | end |
319 | 320 | ||
320 | local i = 1 | 321 | local i = 1 |
321 | return function(): any, any, any | 322 | return function(): K, V, S |
322 | local key = keys[i] | 323 | local key = keys[i] |
323 | i = i + 1 | 324 | i = i + 1 |
324 | return key, tbl[key], sub_orders[key] | 325 | return key, tbl[key], sub_orders[key] |
diff --git a/src/luarocks/dir-original.lua b/src/luarocks/dir.lua index be89e37b..be89e37b 100644 --- a/src/luarocks/dir-original.lua +++ b/src/luarocks/dir.lua | |||
diff --git a/src/luarocks/dir.tl b/src/luarocks/dir.tl index 86098413..d349ac71 100644 --- a/src/luarocks/dir.tl +++ b/src/luarocks/dir.tl | |||
@@ -1,11 +1,14 @@ | |||
1 | 1 | ||
2 | --- Generic utilities for handling pathnames. | 2 | --- Generic utilities for handling pathnames. |
3 | local record dir | 3 | local record dir |
4 | path: function(...: string): string | ||
5 | split_url: function(string): string, string | ||
6 | normalize: function(string): string | ||
4 | end | 7 | end |
5 | 8 | ||
6 | local core = require("luarocks.core.dir") | 9 | local core = require("luarocks.core.dir") |
7 | 10 | ||
8 | dir.path = core.path --! | 11 | dir.path = core.path |
9 | dir.split_url = core.split_url | 12 | dir.split_url = core.split_url |
10 | dir.normalize = core.normalize | 13 | dir.normalize = core.normalize |
11 | 14 | ||
@@ -47,7 +50,7 @@ end | |||
47 | 50 | ||
48 | --- Returns true if protocol does not require additional tools. | 51 | --- Returns true if protocol does not require additional tools. |
49 | -- @param protocol The protocol name | 52 | -- @param protocol The protocol name |
50 | function dir.is_basic_protocol(protocol: string): boolean --? extra type (enum) | 53 | function dir.is_basic_protocol(protocol: string): boolean |
51 | return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" | 54 | return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" |
52 | end | 55 | end |
53 | 56 | ||
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl new file mode 100644 index 00000000..b0ca56c7 --- /dev/null +++ b/src/luarocks/fs.d.tl | |||
@@ -0,0 +1,13 @@ | |||
1 | local record fs | ||
2 | verbose: function(): FILE | boolean, string, integer | ||
3 | load_fns: function(fs_table: FsTable, inits: {any:any}): function | ||
4 | load_platform_fns: function(patt: any, inits: {any:any}): string | ||
5 | init: function | ||
6 | change_dir_to_root: function | ||
7 | record FsTable | ||
8 | end | ||
9 | |||
10 | --... | ||
11 | end | ||
12 | |||
13 | return fs | ||
diff --git a/src/luarocks/fs-original.lua b/src/luarocks/fs.lua index a8156a21..a8156a21 100644 --- a/src/luarocks/fs-original.lua +++ b/src/luarocks/fs.lua | |||
diff --git a/src/luarocks/fs.tl b/src/luarocks/fs.tl deleted file mode 100644 index c31d3b5a..00000000 --- a/src/luarocks/fs.tl +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | |||
2 | --- Proxy module for filesystem and platform abstractions. | ||
3 | -- All code using "fs" code should require "luarocks.fs", | ||
4 | -- and not the various platform-specific implementations. | ||
5 | -- However, see the documentation of the implementation | ||
6 | -- for the API reference. | ||
7 | |||
8 | local pairs = pairs --? | ||
9 | |||
10 | local record fs | ||
11 | |||
12 | end | ||
13 | |||
14 | -- To avoid a loop when loading the other fs modules. | ||
15 | package.loaded["luarocks.fs"] = fs | ||
16 | |||
17 | local cfg = require("luarocks.core.cfg") | ||
18 | |||
19 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end --! | ||
20 | |||
21 | math.randomseed(os.time()) | ||
22 | |||
23 | local fs_is_verbose = false | ||
24 | |||
25 | do | ||
26 | local old_popen, old_execute: function(string, string): (FILE, string), function(string): (boolean, string, integer) --! () around output to seperate | ||
27 | |||
28 | -- patch io.popen and os.execute to display commands in verbose mode | ||
29 | function fs.verbose() | ||
30 | fs_is_verbose = true | ||
31 | |||
32 | if old_popen or old_execute then return end --? == nil! | ||
33 | old_popen = io.popen | ||
34 | -- luacheck: push globals io os | ||
35 | io.popen = function(one: string, two: string): FILE, string | ||
36 | if two == nil then | ||
37 | print("\nio.popen: ", one) | ||
38 | else | ||
39 | print("\nio.popen: ", one, "Mode:", two) | ||
40 | end | ||
41 | return old_popen(one, two) | ||
42 | end | ||
43 | |||
44 | old_execute = os.execute | ||
45 | os.execute = function(cmd: string): boolean, string, integer | ||
46 | -- redact api keys if present | ||
47 | print("\nos.execute: ", (cmd:gsub("(/api/[^/]+/)([^/]+)/", function(cap: string, key): string return cap.."<redacted>/" end)) ) --! key is unused | ||
48 | local a, b, c = old_execute(cmd) | ||
49 | if type(a) == "boolean" then | ||
50 | print((a and ".........." or "##########") .. ": " .. tostring(c) .. (b == "exit" and "" or " (" .. tostring(b) .. ")")) | ||
51 | elseif type(a) == "number" then --! "a" needs to be a boolean | ||
52 | print(((a == 0) and ".........." or "##########") .. ": " .. tostring(a)) | ||
53 | end | ||
54 | return a, b, c | ||
55 | end | ||
56 | -- luacheck: pop | ||
57 | end | ||
58 | end | ||
59 | |||
60 | do | ||
61 | local skip_verbose_wrap = { | ||
62 | ["current_dir"] = true, | ||
63 | } | ||
64 | |||
65 | local function load_fns(fs_table, inits) | ||
66 | for name, fn in pairs(fs_table) do | ||
67 | if name ~= "init" and not fs[name] then | ||
68 | if skip_verbose_wrap[name] then | ||
69 | fs[name] = fn | ||
70 | else | ||
71 | fs[name] = function(...) | ||
72 | if fs_is_verbose then | ||
73 | local args = pack(...) | ||
74 | for i=1, args.n do | ||
75 | local arg = args[i] | ||
76 | local pok, v = pcall(string.format, "%q", arg) | ||
77 | args[i] = pok and v or tostring(arg) | ||
78 | end | ||
79 | print("fs." .. name .. "(" .. table.concat(args, ", ") .. ")") | ||
80 | end | ||
81 | return fn(...) | ||
82 | end | ||
83 | end | ||
84 | end | ||
85 | end | ||
86 | if fs_table.init then | ||
87 | table.insert(inits, fs_table.init) | ||
88 | end | ||
89 | end | ||
90 | |||
91 | local function load_platform_fns(patt, inits) | ||
92 | local each_platform = cfg.each_platform | ||
93 | |||
94 | -- FIXME A quick hack for the experimental Windows build | ||
95 | if os.getenv("LUAROCKS_CROSS_COMPILING") then | ||
96 | each_platform = function() | ||
97 | local i = 0 | ||
98 | local plats = { "linux", "unix" } | ||
99 | return function() | ||
100 | i = i + 1 | ||
101 | return plats[i] | ||
102 | end | ||
103 | end | ||
104 | end | ||
105 | |||
106 | for platform in each_platform("most-specific-first") do | ||
107 | local ok, fs_plat = pcall(require, patt:format(platform)) | ||
108 | if ok and fs_plat then | ||
109 | load_fns(fs_plat, inits) | ||
110 | end | ||
111 | end | ||
112 | end | ||
113 | |||
114 | function fs.init() | ||
115 | local inits = {} | ||
116 | |||
117 | if fs.current_dir then | ||
118 | -- unload luarocks fs so it can be reloaded using all modules | ||
119 | -- providing extra functionality in the current package paths | ||
120 | for k, _ in pairs(fs) do | ||
121 | if k ~= "init" and k ~= "verbose" then | ||
122 | fs[k] = nil | ||
123 | end | ||
124 | end | ||
125 | for m, _ in pairs(package.loaded) do | ||
126 | if m:match("luarocks%.fs%.") then | ||
127 | package.loaded[m] = nil | ||
128 | end | ||
129 | end | ||
130 | end | ||
131 | |||
132 | -- Load platform-specific functions | ||
133 | load_platform_fns("luarocks.fs.%s", inits) | ||
134 | |||
135 | -- Load platform-independent pure-Lua functionality | ||
136 | load_fns(require("luarocks.fs.lua"), inits) | ||
137 | |||
138 | -- Load platform-specific fallbacks for missing Lua modules | ||
139 | load_platform_fns("luarocks.fs.%s.tools", inits) | ||
140 | |||
141 | -- Load platform-independent external tool functionality | ||
142 | load_fns(require("luarocks.fs.tools"), inits) | ||
143 | |||
144 | -- Run platform-specific initializations after everything is loaded | ||
145 | for _, init in ipairs(inits) do | ||
146 | init() | ||
147 | end | ||
148 | end | ||
149 | end | ||
150 | |||
151 | return fs | ||
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 41855aae..f556cb03 100644 --- a/src/luarocks/util.tl +++ b/src/luarocks/util.tl | |||
@@ -20,8 +20,6 @@ util.printerr = core.printerr | |||
20 | util.warning = core.warning | 20 | util.warning = core.warning |
21 | util.keys = core.keys | 21 | util.keys = core.keys |
22 | 22 | ||
23 | local unpack = unpack or table.unpack --! | ||
24 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end --! | ||
25 | 23 | ||
26 | local scheduled_functions: {integer: {string: any}} = {} --? infered from line 48-51 | 24 | local scheduled_functions: {integer: {string: any}} = {} --? infered from line 48-51 |
27 | 25 | ||
@@ -35,7 +33,7 @@ local scheduled_functions: {integer: {string: any}} = {} --? infered from line 4 | |||
35 | function util.schedule_function(f: function(), ...:any): {string:any} | 33 | function util.schedule_function(f: function(), ...:any): {string:any} |
36 | assert(type(f) == "function") | 34 | assert(type(f) == "function") |
37 | 35 | ||
38 | local item = { fn = f, args = pack(...) } | 36 | local item = { fn = f, args = table.pack(...) } |
39 | table.insert(scheduled_functions, item) | 37 | table.insert(scheduled_functions, item) |
40 | return item | 38 | return item |
41 | end | 39 | end |
@@ -65,7 +63,7 @@ function util.run_scheduled_functions() | |||
65 | end | 63 | end |
66 | for i = #scheduled_functions, 1, -1 do | 64 | for i = #scheduled_functions, 1, -1 do |
67 | local item = scheduled_functions[i] | 65 | local item = scheduled_functions[i] |
68 | item.fn(unpack(item.args, 1, item.args.n)) | 66 | item.fn(table.unpack(item.args, 1, item.args.n)) |
69 | end | 67 | end |
70 | end | 68 | end |
71 | 69 | ||