diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-07-13 01:05:25 +0300 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:49:17 +0300 |
commit | fdf700420bc30d98ba0070c539bde97fdbfd6344 (patch) | |
tree | d3933a57f53cb044fd1b7c844c29e0b14493fba3 | |
parent | 0da4377efd0ead57548bdb708792db8542a0b53e (diff) | |
download | luarocks-fdf700420bc30d98ba0070c539bde97fdbfd6344.tar.gz luarocks-fdf700420bc30d98ba0070c539bde97fdbfd6344.tar.bz2 luarocks-fdf700420bc30d98ba0070c539bde97fdbfd6344.zip |
abandon manif + tests dir
-rw-r--r-- | src/luarocks/core/manif-incomplete.lua (renamed from src/luarocks/core/manif-original.lua) | 99 | ||||
-rw-r--r-- | src/luarocks/core/manif.lua | 99 | ||||
-rw-r--r-- | src/luarocks/dir-original.lua | 63 | ||||
-rw-r--r-- | src/luarocks/dir.lua | 50 |
4 files changed, 189 insertions, 122 deletions
diff --git a/src/luarocks/core/manif-original.lua b/src/luarocks/core/manif-incomplete.lua index 3925f636..c64795dc 100644 --- a/src/luarocks/core/manif-original.lua +++ b/src/luarocks/core/manif-incomplete.lua | |||
@@ -1,6 +1,4 @@ | |||
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 assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table | |
2 | --- Core functions for querying manifest files. | ||
3 | local manif = {} | ||
4 | 2 | ||
5 | local persist = require("luarocks.core.persist") | 3 | local persist = require("luarocks.core.persist") |
6 | local cfg = require("luarocks.core.cfg") | 4 | local cfg = require("luarocks.core.cfg") |
@@ -8,53 +6,84 @@ local dir = require("luarocks.core.dir") | |||
8 | local util = require("luarocks.core.util") | 6 | local util = require("luarocks.core.util") |
9 | local vers = require("luarocks.core.vers") | 7 | local vers = require("luarocks.core.vers") |
10 | local path = require("luarocks.core.path") | 8 | local path = require("luarocks.core.path") |
11 | local require = nil | ||
12 | -------------------------------------------------------------------------------- | ||
13 | 9 | ||
14 | -- Table with repository identifiers as keys and tables mapping | 10 | |
15 | -- Lua versions to cached loaded manifests as values. | 11 | |
12 | |||
13 | local manif = {DependencyVersion = {}, Manifest = {}, Tree_manifest = {}, } | ||
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 | |||
16 | local manifest_cache = {} | 44 | local manifest_cache = {} |
17 | 45 | ||
18 | --- Cache a loaded manifest. | 46 | |
19 | -- @param repo_url string: The repository identifier. | 47 | |
20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 48 | |
21 | -- @param manifest table: the manifest to be cached. | 49 | |
22 | function manif.cache_manifest(repo_url, lua_version, manifest) | 50 | function manif.cache_manifest(repo_url, lua_version, manifest) |
23 | lua_version = lua_version or cfg.lua_version | 51 | lua_version = lua_version or cfg.lua_version |
24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} | 52 | manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} |
25 | manifest_cache[repo_url][lua_version] = manifest | 53 | manifest_cache.repository[repo_url][lua_version] = manifest |
26 | end | 54 | end |
27 | 55 | ||
28 | --- Attempt to get cached loaded manifest. | 56 | |
29 | -- @param repo_url string: The repository identifier. | 57 | |
30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 58 | |
31 | -- @return table or nil: loaded manifest or nil if cache is empty. | 59 | |
32 | function manif.get_cached_manifest(repo_url, lua_version) | 60 | function manif.get_cached_manifest(repo_url, lua_version) |
33 | lua_version = lua_version or cfg.lua_version | 61 | lua_version = lua_version or cfg.lua_version |
34 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] | 62 | return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] |
35 | end | 63 | end |
36 | 64 | ||
37 | --- Back-end function that actually loads the manifest | 65 | |
38 | -- and stores it in the manifest cache. | 66 | |
39 | -- @param file string: The local filename of the manifest file. | 67 | |
40 | -- @param repo_url string: The repository identifier. | 68 | |
41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 69 | |
42 | -- @return table or (nil, string, string): the manifest or nil, | 70 | |
43 | -- error message and error code ("open", "load", "run"). | 71 | |
44 | function manif.manifest_loader(file, repo_url, lua_version) | 72 | function manif.manifest_loader(file, repo_url, lua_version) |
45 | local manifest, err, errcode = persist.load_into_table(file) | 73 | local manifest, err, errcode = persist.load_into_table(file) |
46 | if not manifest then | 74 | if not manifest and type(err) == "string" then |
47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode | 75 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode |
48 | end | 76 | end |
77 | |||
49 | manif.cache_manifest(repo_url, lua_version, manifest) | 78 | manif.cache_manifest(repo_url, lua_version, manifest) |
50 | return manifest, err, errcode | 79 | return manifest, err, errcode |
51 | end | 80 | end |
52 | 81 | ||
53 | --- Load a local manifest describing a repository. | 82 | |
54 | -- This is used by the luarocks.loader only. | 83 | |
55 | -- @param repo_url string: URL or pathname for the repository. | 84 | |
56 | -- @return table or (nil, string, string): A table representing the manifest, | 85 | |
57 | -- or nil followed by an error message and an error code, see manifest_loader. | 86 | |
58 | function manif.fast_load_local_manifest(repo_url) | 87 | function manif.fast_load_local_manifest(repo_url) |
59 | assert(type(repo_url) == "string") | 88 | assert(type(repo_url) == "string") |
60 | 89 | ||
@@ -64,15 +93,15 @@ function manif.fast_load_local_manifest(repo_url) | |||
64 | end | 93 | end |
65 | 94 | ||
66 | local pathname = dir.path(repo_url, "manifest") | 95 | local pathname = dir.path(repo_url, "manifest") |
67 | return manif.manifest_loader(pathname, repo_url, nil, true) | 96 | return manif.manifest_loader(pathname, repo_url, nil) |
68 | end | 97 | end |
69 | 98 | ||
70 | function manif.load_rocks_tree_manifests(deps_mode) | 99 | function manif.load_rocks_tree_manifests(deps_mode) |
71 | local trees = {} | 100 | local trees = {} |
72 | path.map_trees(deps_mode, function(tree) | 101 | path.map_trees(deps_mode, function(tree) |
73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) | 102 | local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
74 | if manifest then | 103 | if manifest then |
75 | table.insert(trees, {tree=tree, manifest=manifest}) | 104 | table.insert(trees, { tree = tree, manifest = manifest }) |
76 | end | 105 | end |
77 | end) | 106 | end) |
78 | return trees | 107 | return trees |
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index c64795dc..3925f636 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua | |||
@@ -1,4 +1,6 @@ | |||
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 assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local table = _tl_compat and _tl_compat.table or table | 1 | |
2 | --- Core functions for querying manifest files. | ||
3 | local manif = {} | ||
2 | 4 | ||
3 | local persist = require("luarocks.core.persist") | 5 | local persist = require("luarocks.core.persist") |
4 | local cfg = require("luarocks.core.cfg") | 6 | local cfg = require("luarocks.core.cfg") |
@@ -6,84 +8,53 @@ local dir = require("luarocks.core.dir") | |||
6 | local util = require("luarocks.core.util") | 8 | local util = require("luarocks.core.util") |
7 | local vers = require("luarocks.core.vers") | 9 | local vers = require("luarocks.core.vers") |
8 | local path = require("luarocks.core.path") | 10 | local path = require("luarocks.core.path") |
11 | local require = nil | ||
12 | -------------------------------------------------------------------------------- | ||
9 | 13 | ||
10 | 14 | -- Table with repository identifiers as keys and tables mapping | |
11 | 15 | -- Lua versions to cached loaded manifests as values. | |
12 | |||
13 | local manif = {DependencyVersion = {}, Manifest = {}, Tree_manifest = {}, } | ||
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 | local manifest_cache = {} | 16 | local manifest_cache = {} |
45 | 17 | ||
46 | 18 | --- Cache a loaded manifest. | |
47 | 19 | -- @param repo_url string: The repository identifier. | |
48 | 20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
49 | 21 | -- @param manifest table: the manifest to be cached. | |
50 | function manif.cache_manifest(repo_url, lua_version, manifest) | 22 | function manif.cache_manifest(repo_url, lua_version, manifest) |
51 | lua_version = lua_version or cfg.lua_version | 23 | lua_version = lua_version or cfg.lua_version |
52 | manifest_cache.repository[repo_url] = manifest_cache.repository[repo_url] or {} | 24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} |
53 | manifest_cache.repository[repo_url][lua_version] = manifest | 25 | manifest_cache[repo_url][lua_version] = manifest |
54 | end | 26 | end |
55 | 27 | ||
56 | 28 | --- Attempt to get cached loaded manifest. | |
57 | 29 | -- @param repo_url string: The repository identifier. | |
58 | 30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
59 | 31 | -- @return table or nil: loaded manifest or nil if cache is empty. | |
60 | function manif.get_cached_manifest(repo_url, lua_version) | 32 | function manif.get_cached_manifest(repo_url, lua_version) |
61 | lua_version = lua_version or cfg.lua_version | 33 | lua_version = lua_version or cfg.lua_version |
62 | return manifest_cache.repository[repo_url] and manifest_cache.repository[repo_url][lua_version] | 34 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] |
63 | end | 35 | end |
64 | 36 | ||
65 | 37 | --- Back-end function that actually loads the manifest | |
66 | 38 | -- and stores it in the manifest cache. | |
67 | 39 | -- @param file string: The local filename of the manifest file. | |
68 | 40 | -- @param repo_url string: The repository identifier. | |
69 | 41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | |
70 | 42 | -- @return table or (nil, string, string): the manifest or nil, | |
71 | 43 | -- error message and error code ("open", "load", "run"). | |
72 | function manif.manifest_loader(file, repo_url, lua_version) | 44 | function manif.manifest_loader(file, repo_url, lua_version) |
73 | local manifest, err, errcode = persist.load_into_table(file) | 45 | local manifest, err, errcode = persist.load_into_table(file) |
74 | if not manifest and type(err) == "string" then | 46 | if not manifest then |
75 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode | 47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode |
76 | end | 48 | end |
77 | |||
78 | manif.cache_manifest(repo_url, lua_version, manifest) | 49 | manif.cache_manifest(repo_url, lua_version, manifest) |
79 | return manifest, err, errcode | 50 | return manifest, err, errcode |
80 | end | 51 | end |
81 | 52 | ||
82 | 53 | --- Load a local manifest describing a repository. | |
83 | 54 | -- This is used by the luarocks.loader only. | |
84 | 55 | -- @param repo_url string: URL or pathname for the repository. | |
85 | 56 | -- @return table or (nil, string, string): A table representing the manifest, | |
86 | 57 | -- or nil followed by an error message and an error code, see manifest_loader. | |
87 | function manif.fast_load_local_manifest(repo_url) | 58 | function manif.fast_load_local_manifest(repo_url) |
88 | assert(type(repo_url) == "string") | 59 | assert(type(repo_url) == "string") |
89 | 60 | ||
@@ -93,15 +64,15 @@ function manif.fast_load_local_manifest(repo_url) | |||
93 | end | 64 | end |
94 | 65 | ||
95 | local pathname = dir.path(repo_url, "manifest") | 66 | local pathname = dir.path(repo_url, "manifest") |
96 | return manif.manifest_loader(pathname, repo_url, nil) | 67 | return manif.manifest_loader(pathname, repo_url, nil, true) |
97 | end | 68 | end |
98 | 69 | ||
99 | function manif.load_rocks_tree_manifests(deps_mode) | 70 | function manif.load_rocks_tree_manifests(deps_mode) |
100 | local trees = {} | 71 | local trees = {} |
101 | path.map_trees(deps_mode, function(tree) | 72 | path.map_trees(deps_mode, function(tree) |
102 | local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) | 73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
103 | if manifest then | 74 | if manifest then |
104 | table.insert(trees, { tree = tree, manifest = manifest }) | 75 | table.insert(trees, {tree=tree, manifest=manifest}) |
105 | end | 76 | end |
106 | end) | 77 | end) |
107 | return trees | 78 | return trees |
diff --git a/src/luarocks/dir-original.lua b/src/luarocks/dir-original.lua new file mode 100644 index 00000000..be89e37b --- /dev/null +++ b/src/luarocks/dir-original.lua | |||
@@ -0,0 +1,63 @@ | |||
1 | |||
2 | --- Generic utilities for handling pathnames. | ||
3 | local dir = {} | ||
4 | |||
5 | local core = require("luarocks.core.dir") | ||
6 | |||
7 | dir.path = core.path | ||
8 | dir.split_url = core.split_url | ||
9 | dir.normalize = core.normalize | ||
10 | |||
11 | local dir_sep = package.config:sub(1, 1) | ||
12 | |||
13 | --- Strip the path off a path+filename. | ||
14 | -- @param pathname string: A path+name, such as "/a/b/c" | ||
15 | -- or "\a\b\c". | ||
16 | -- @return string: The filename without its path, such as "c". | ||
17 | function dir.base_name(pathname) | ||
18 | assert(type(pathname) == "string") | ||
19 | |||
20 | local b | ||
21 | b = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes | ||
22 | b = b:gsub("/*$", "") -- drop trailing slashes | ||
23 | b = b:match(".*[/\\]([^/\\]*)") -- match last component | ||
24 | b = b or pathname -- fallback to original if no slashes | ||
25 | |||
26 | return b | ||
27 | end | ||
28 | |||
29 | --- Strip the name off a path+filename. | ||
30 | -- @param pathname string: A path+name, such as "/a/b/c". | ||
31 | -- @return string: The filename without its path, such as "/a/b". | ||
32 | -- For entries such as "/a/b/", "/a" is returned. If there are | ||
33 | -- no directory separators in input, "" is returned. | ||
34 | function dir.dir_name(pathname) | ||
35 | assert(type(pathname) == "string") | ||
36 | |||
37 | local d | ||
38 | d = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes | ||
39 | d = d:gsub("/*$", "") -- drop trailing slashes | ||
40 | d = d:match("(.*)[/]+[^/]*") -- match all components but the last | ||
41 | d = d or "" -- switch to "" if there's no match | ||
42 | d = d:gsub("/", dir_sep) -- decanonicalize to native slashes | ||
43 | |||
44 | return d | ||
45 | end | ||
46 | |||
47 | --- Returns true if protocol does not require additional tools. | ||
48 | -- @param protocol The protocol name | ||
49 | function dir.is_basic_protocol(protocol) | ||
50 | return protocol == "http" or protocol == "https" or protocol == "ftp" or protocol == "file" | ||
51 | end | ||
52 | |||
53 | function dir.deduce_base_dir(url) | ||
54 | -- for extensions like foo.tar.gz, "gz" is stripped first | ||
55 | local known_exts = {} | ||
56 | for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do | ||
57 | known_exts[ext] = "" | ||
58 | end | ||
59 | local base = dir.base_name(url) | ||
60 | return (base:gsub("%.([^.]*)$", known_exts):gsub("%.tar", "")) | ||
61 | end | ||
62 | |||
63 | return dir | ||
diff --git a/src/luarocks/dir.lua b/src/luarocks/dir.lua index be89e37b..f54f1458 100644 --- a/src/luarocks/dir.lua +++ b/src/luarocks/dir.lua | |||
@@ -1,7 +1,11 @@ | |||
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 assert = _tl_compat and _tl_compat.assert or assert; local ipairs = _tl_compat and _tl_compat.ipairs or ipairs; local package = _tl_compat and _tl_compat.package or package; local string = _tl_compat and _tl_compat.string or string | ||
1 | 2 | ||
2 | --- Generic utilities for handling pathnames. | ||
3 | local dir = {} | 3 | local dir = {} |
4 | 4 | ||
5 | |||
6 | |||
7 | |||
8 | |||
5 | local core = require("luarocks.core.dir") | 9 | local core = require("luarocks.core.dir") |
6 | 10 | ||
7 | dir.path = core.path | 11 | dir.path = core.path |
@@ -10,50 +14,50 @@ dir.normalize = core.normalize | |||
10 | 14 | ||
11 | local dir_sep = package.config:sub(1, 1) | 15 | local dir_sep = package.config:sub(1, 1) |
12 | 16 | ||
13 | --- Strip the path off a path+filename. | 17 | |
14 | -- @param pathname string: A path+name, such as "/a/b/c" | 18 | |
15 | -- or "\a\b\c". | 19 | |
16 | -- @return string: The filename without its path, such as "c". | 20 | |
17 | function dir.base_name(pathname) | 21 | function dir.base_name(pathname) |
18 | assert(type(pathname) == "string") | 22 | assert(type(pathname) == "string") |
19 | 23 | ||
20 | local b | 24 | local b |
21 | b = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes | 25 | b = pathname:gsub("[/\\]", "/") |
22 | b = b:gsub("/*$", "") -- drop trailing slashes | 26 | b = b:gsub("/*$", "") |
23 | b = b:match(".*[/\\]([^/\\]*)") -- match last component | 27 | b = b:match(".*[/\\]([^/\\]*)") |
24 | b = b or pathname -- fallback to original if no slashes | 28 | b = b or pathname |
25 | 29 | ||
26 | return b | 30 | return b |
27 | end | 31 | end |
28 | 32 | ||
29 | --- Strip the name off a path+filename. | 33 | |
30 | -- @param pathname string: A path+name, such as "/a/b/c". | 34 | |
31 | -- @return string: The filename without its path, such as "/a/b". | 35 | |
32 | -- For entries such as "/a/b/", "/a" is returned. If there are | 36 | |
33 | -- no directory separators in input, "" is returned. | 37 | |
34 | function dir.dir_name(pathname) | 38 | function dir.dir_name(pathname) |
35 | assert(type(pathname) == "string") | 39 | assert(type(pathname) == "string") |
36 | 40 | ||
37 | local d | 41 | local d |
38 | d = pathname:gsub("[/\\]", "/") -- canonicalize to forward slashes | 42 | d = pathname:gsub("[/\\]", "/") |
39 | d = d:gsub("/*$", "") -- drop trailing slashes | 43 | d = d:gsub("/*$", "") |
40 | d = d:match("(.*)[/]+[^/]*") -- match all components but the last | 44 | d = d:match("(.*)[/]+[^/]*") |
41 | d = d or "" -- switch to "" if there's no match | 45 | d = d or "" |
42 | d = d:gsub("/", dir_sep) -- decanonicalize to native slashes | 46 | d = d:gsub("/", dir_sep) |
43 | 47 | ||
44 | return d | 48 | return d |
45 | end | 49 | end |
46 | 50 | ||
47 | --- Returns true if protocol does not require additional tools. | 51 | |
48 | -- @param protocol The protocol name | 52 | |
49 | function dir.is_basic_protocol(protocol) | 53 | function dir.is_basic_protocol(protocol) |
50 | 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" |
51 | end | 55 | end |
52 | 56 | ||
53 | function dir.deduce_base_dir(url) | 57 | function dir.deduce_base_dir(url) |
54 | -- for extensions like foo.tar.gz, "gz" is stripped first | 58 | |
55 | local known_exts = {} | 59 | local known_exts = {} |
56 | for _, ext in ipairs{"zip", "git", "tgz", "tar", "gz", "bz2"} do | 60 | for _, ext in ipairs({ "zip", "git", "tgz", "tar", "gz", "bz2" }) do |
57 | known_exts[ext] = "" | 61 | known_exts[ext] = "" |
58 | end | 62 | end |
59 | local base = dir.base_name(url) | 63 | local base = dir.base_name(url) |