diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-06-10 02:17:46 +0200 |
---|---|---|
committer | V1K1NGbg <victor@ilchev.com> | 2024-08-05 20:49:17 +0300 |
commit | 6bb0459cfbe0c6da37e9765532f3419df0242871 (patch) | |
tree | 88e0966f0834cf45c00d884ab05e9344f6c1f3a3 | |
parent | b7defd249f11528024d73c3ed02474787ec4bb35 (diff) | |
download | luarocks-6bb0459cfbe0c6da37e9765532f3419df0242871.tar.gz luarocks-6bb0459cfbe0c6da37e9765532f3419df0242871.tar.bz2 luarocks-6bb0459cfbe0c6da37e9765532f3419df0242871.zip |
core.manif - converted
-rw-r--r-- | src/luarocks/core/manif-original.lua | 114 | ||||
-rw-r--r-- | src/luarocks/core/manif.lua | 56 | ||||
-rw-r--r-- | src/luarocks/core/manif.tl | 121 |
3 files changed, 263 insertions, 28 deletions
diff --git a/src/luarocks/core/manif-original.lua b/src/luarocks/core/manif-original.lua new file mode 100644 index 00000000..3925f636 --- /dev/null +++ b/src/luarocks/core/manif-original.lua | |||
@@ -0,0 +1,114 @@ | |||
1 | |||
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") | ||
7 | local dir = require("luarocks.core.dir") | ||
8 | local util = require("luarocks.core.util") | ||
9 | local vers = require("luarocks.core.vers") | ||
10 | local path = require("luarocks.core.path") | ||
11 | local require = nil | ||
12 | -------------------------------------------------------------------------------- | ||
13 | |||
14 | -- Table with repository identifiers as keys and tables mapping | ||
15 | -- Lua versions to cached loaded manifests as values. | ||
16 | local manifest_cache = {} | ||
17 | |||
18 | --- Cache a loaded manifest. | ||
19 | -- @param repo_url string: The repository identifier. | ||
20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | ||
21 | -- @param manifest table: the manifest to be cached. | ||
22 | function manif.cache_manifest(repo_url, lua_version, manifest) | ||
23 | lua_version = lua_version or cfg.lua_version | ||
24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} | ||
25 | manifest_cache[repo_url][lua_version] = manifest | ||
26 | end | ||
27 | |||
28 | --- Attempt to get cached loaded manifest. | ||
29 | -- @param repo_url string: The repository identifier. | ||
30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | ||
31 | -- @return table or nil: loaded manifest or nil if cache is empty. | ||
32 | function manif.get_cached_manifest(repo_url, lua_version) | ||
33 | lua_version = lua_version or cfg.lua_version | ||
34 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] | ||
35 | end | ||
36 | |||
37 | --- Back-end function that actually loads the manifest | ||
38 | -- and stores it in the manifest cache. | ||
39 | -- @param file string: The local filename of the manifest file. | ||
40 | -- @param repo_url string: The repository identifier. | ||
41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | ||
42 | -- @return table or (nil, string, string): the manifest or nil, | ||
43 | -- error message and error code ("open", "load", "run"). | ||
44 | function manif.manifest_loader(file, repo_url, lua_version) | ||
45 | local manifest, err, errcode = persist.load_into_table(file) | ||
46 | if not manifest then | ||
47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode | ||
48 | end | ||
49 | manif.cache_manifest(repo_url, lua_version, manifest) | ||
50 | return manifest, err, errcode | ||
51 | end | ||
52 | |||
53 | --- Load a local manifest describing a repository. | ||
54 | -- This is used by the luarocks.loader only. | ||
55 | -- @param repo_url string: URL or pathname for the repository. | ||
56 | -- @return table or (nil, string, string): A table representing the manifest, | ||
57 | -- or nil followed by an error message and an error code, see manifest_loader. | ||
58 | function manif.fast_load_local_manifest(repo_url) | ||
59 | assert(type(repo_url) == "string") | ||
60 | |||
61 | local cached_manifest = manif.get_cached_manifest(repo_url) | ||
62 | if cached_manifest then | ||
63 | return cached_manifest | ||
64 | end | ||
65 | |||
66 | local pathname = dir.path(repo_url, "manifest") | ||
67 | return manif.manifest_loader(pathname, repo_url, nil, true) | ||
68 | end | ||
69 | |||
70 | function manif.load_rocks_tree_manifests(deps_mode) | ||
71 | local trees = {} | ||
72 | path.map_trees(deps_mode, function(tree) | ||
73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) | ||
74 | if manifest then | ||
75 | table.insert(trees, {tree=tree, manifest=manifest}) | ||
76 | end | ||
77 | end) | ||
78 | return trees | ||
79 | end | ||
80 | |||
81 | function manif.scan_dependencies(name, version, tree_manifests, dest) | ||
82 | if dest[name] then | ||
83 | return | ||
84 | end | ||
85 | dest[name] = version | ||
86 | |||
87 | for _, tree in ipairs(tree_manifests) do | ||
88 | local manifest = tree.manifest | ||
89 | |||
90 | local pkgdeps | ||
91 | if manifest.dependencies and manifest.dependencies[name] then | ||
92 | pkgdeps = manifest.dependencies[name][version] | ||
93 | end | ||
94 | if pkgdeps then | ||
95 | for _, dep in ipairs(pkgdeps) do | ||
96 | local pkg, constraints = dep.name, dep.constraints | ||
97 | |||
98 | for _, t in ipairs(tree_manifests) do | ||
99 | local entries = t.manifest.repository[pkg] | ||
100 | if entries then | ||
101 | for ver, _ in util.sortedpairs(entries, vers.compare_versions) do | ||
102 | if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then | ||
103 | manif.scan_dependencies(pkg, ver, tree_manifests, dest) | ||
104 | end | ||
105 | end | ||
106 | end | ||
107 | end | ||
108 | end | ||
109 | return | ||
110 | end | ||
111 | end | ||
112 | end | ||
113 | |||
114 | return manif | ||
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.lua index 3925f636..ea3a04a7 100644 --- a/src/luarocks/core/manif.lua +++ b/src/luarocks/core/manif.lua | |||
@@ -1,5 +1,5 @@ | |||
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 | ||
2 | --- Core functions for querying manifest files. | ||
3 | local manif = {} | 3 | local manif = {} |
4 | 4 | ||
5 | local persist = require("luarocks.core.persist") | 5 | local persist = require("luarocks.core.persist") |
@@ -9,52 +9,52 @@ local util = require("luarocks.core.util") | |||
9 | local vers = require("luarocks.core.vers") | 9 | local vers = require("luarocks.core.vers") |
10 | local path = require("luarocks.core.path") | 10 | local path = require("luarocks.core.path") |
11 | local require = nil | 11 | local require = nil |
12 | -------------------------------------------------------------------------------- | ||
13 | 12 | ||
14 | -- Table with repository identifiers as keys and tables mapping | 13 | |
15 | -- Lua versions to cached loaded manifests as values. | 14 | |
15 | |||
16 | local manifest_cache = {} | 16 | local manifest_cache = {} |
17 | 17 | ||
18 | --- Cache a loaded manifest. | 18 | |
19 | -- @param repo_url string: The repository identifier. | 19 | |
20 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 20 | |
21 | -- @param manifest table: the manifest to be cached. | 21 | |
22 | function manif.cache_manifest(repo_url, lua_version, manifest) | 22 | function manif.cache_manifest(repo_url, lua_version, manifest) |
23 | lua_version = lua_version or cfg.lua_version | 23 | lua_version = lua_version or cfg.lua_version |
24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} | 24 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} |
25 | manifest_cache[repo_url][lua_version] = manifest | 25 | manifest_cache[repo_url][lua_version] = manifest |
26 | end | 26 | end |
27 | 27 | ||
28 | --- Attempt to get cached loaded manifest. | 28 | |
29 | -- @param repo_url string: The repository identifier. | 29 | |
30 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 30 | |
31 | -- @return table or nil: loaded manifest or nil if cache is empty. | 31 | |
32 | function manif.get_cached_manifest(repo_url, lua_version) | 32 | function manif.get_cached_manifest(repo_url, lua_version) |
33 | lua_version = lua_version or cfg.lua_version | 33 | lua_version = lua_version or cfg.lua_version |
34 | 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] |
35 | end | 35 | end |
36 | 36 | ||
37 | --- Back-end function that actually loads the manifest | 37 | |
38 | -- and stores it in the manifest cache. | 38 | |
39 | -- @param file string: The local filename of the manifest file. | 39 | |
40 | -- @param repo_url string: The repository identifier. | 40 | |
41 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | 41 | |
42 | -- @return table or (nil, string, string): the manifest or nil, | 42 | |
43 | -- error message and error code ("open", "load", "run"). | 43 | |
44 | function manif.manifest_loader(file, repo_url, lua_version) | 44 | function manif.manifest_loader(file, repo_url, lua_version) |
45 | local manifest, err, errcode = persist.load_into_table(file) | 45 | local manifest, err, errcode = persist.load_into_table(file) |
46 | if not manifest then | 46 | if not manifest then |
47 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode | 47 | return nil, "Failed loading manifest for " .. repo_url .. ": " .. err, errcode |
48 | end | 48 | end |
49 | manif.cache_manifest(repo_url, lua_version, manifest) | 49 | manif.cache_manifest(repo_url, lua_version, manifest) |
50 | return manifest, err, errcode | 50 | return manifest, err, errcode |
51 | end | 51 | end |
52 | 52 | ||
53 | --- Load a local manifest describing a repository. | 53 | |
54 | -- This is used by the luarocks.loader only. | 54 | |
55 | -- @param repo_url string: URL or pathname for the repository. | 55 | |
56 | -- @return table or (nil, string, string): A table representing the manifest, | 56 | |
57 | -- or nil followed by an error message and an error code, see manifest_loader. | 57 | |
58 | function manif.fast_load_local_manifest(repo_url) | 58 | function manif.fast_load_local_manifest(repo_url) |
59 | assert(type(repo_url) == "string") | 59 | assert(type(repo_url) == "string") |
60 | 60 | ||
@@ -64,15 +64,15 @@ function manif.fast_load_local_manifest(repo_url) | |||
64 | end | 64 | end |
65 | 65 | ||
66 | local pathname = dir.path(repo_url, "manifest") | 66 | local pathname = dir.path(repo_url, "manifest") |
67 | return manif.manifest_loader(pathname, repo_url, nil, true) | 67 | return manif.manifest_loader(pathname, repo_url, nil) |
68 | end | 68 | end |
69 | 69 | ||
70 | function manif.load_rocks_tree_manifests(deps_mode) | 70 | function manif.load_rocks_tree_manifests(deps_mode) |
71 | local trees = {} | 71 | local trees = {} |
72 | path.map_trees(deps_mode, function(tree) | 72 | path.map_trees(deps_mode, function(tree) |
73 | local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) | 73 | local manifest = manif.fast_load_local_manifest(path.rocks_dir(tree)) |
74 | if manifest then | 74 | if manifest then |
75 | table.insert(trees, {tree=tree, manifest=manifest}) | 75 | table.insert(trees, { tree = tree, manifest = manifest }) |
76 | end | 76 | end |
77 | end) | 77 | end) |
78 | return trees | 78 | return trees |
diff --git a/src/luarocks/core/manif.tl b/src/luarocks/core/manif.tl new file mode 100644 index 00000000..a2378f71 --- /dev/null +++ b/src/luarocks/core/manif.tl | |||
@@ -0,0 +1,121 @@ | |||
1 | |||
2 | --- Core functions for querying manifest files. | ||
3 | local record manif | ||
4 | cache_manifest: function(repo_url: string, lua_version: string, manifest: {any: any}) --? manif.cache_manifest | ||
5 | get_cached_manifest: function(repo_url: string, lua_version: string): any | ||
6 | manifest_loader: function(file: string, repo_url: string, lua_version: string): {any: any} | nil, string, string | ||
7 | fast_load_local_manifest: function(repo_url: string): any | nil, string, string | ||
8 | load_rocks_tree_manifests: function(deps_mode: string): {any: any} | ||
9 | scan_dependencies: function(name: any, version: any, tree_manifests: {{any: {any: {any: {any: {{any: any}}}}}}}, dest: {any: any}) | ||
10 | end | ||
11 | |||
12 | local persist = require("luarocks.core.persist") --! | ||
13 | local cfg = require("luarocks.core.cfg") | ||
14 | local dir = require("luarocks.core.dir") | ||
15 | local util = require("luarocks.core.util") | ||
16 | local vers = require("luarocks.core.vers") | ||
17 | local path = require("luarocks.core.path") | ||
18 | local require = nil --! | ||
19 | -------------------------------------------------------------------------------- | ||
20 | |||
21 | -- Table with repository identifiers as keys and tables mapping | ||
22 | -- Lua versions to cached loaded manifests as values. | ||
23 | local manifest_cache: {any: {any: any}} = {} --? | ||
24 | |||
25 | --- Cache a loaded manifest. | ||
26 | -- @param repo_url string: The repository identifier. | ||
27 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | ||
28 | -- @param manifest table: the manifest to be cached. | ||
29 | function manif.cache_manifest(repo_url: string, lua_version: string, manifest: {any: any}) | ||
30 | lua_version = lua_version or cfg.lua_version | ||
31 | manifest_cache[repo_url] = manifest_cache[repo_url] or {} | ||
32 | manifest_cache[repo_url][lua_version] = manifest | ||
33 | end | ||
34 | |||
35 | --- Attempt to get cached loaded manifest. | ||
36 | -- @param repo_url string: The repository identifier. | ||
37 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | ||
38 | -- @return table or nil: loaded manifest or nil if cache is empty. | ||
39 | function manif.get_cached_manifest(repo_url: string, lua_version: string): any --? {any: any} | ||
40 | lua_version = lua_version or cfg.lua_version | ||
41 | return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] | ||
42 | end | ||
43 | |||
44 | --- Back-end function that actually loads the manifest | ||
45 | -- and stores it in the manifest cache. | ||
46 | -- @param file string: The local filename of the manifest file. | ||
47 | -- @param repo_url string: The repository identifier. | ||
48 | -- @param lua_version string: Lua version in "5.x" format, defaults to installed version. | ||
49 | -- @return table or (nil, string, string): the manifest or nil, | ||
50 | -- error message and error code ("open", "load", "run"). | ||
51 | function manif.manifest_loader(file: string, repo_url: string, lua_version: string): {any: any} | nil, string, string | ||
52 | local manifest, err, errcode: {any: any} | nil, string, string = persist.load_into_table(file) --? | ||
53 | if not manifest then | ||
54 | return nil, "Failed loading manifest for "..repo_url..": "..err, errcode | ||
55 | end | ||
56 | manif.cache_manifest(repo_url, lua_version, manifest) | ||
57 | return manifest, err, errcode | ||
58 | end | ||
59 | |||
60 | --- Load a local manifest describing a repository. | ||
61 | -- This is used by the luarocks.loader only. | ||
62 | -- @param repo_url string: URL or pathname for the repository. | ||
63 | -- @return table or (nil, string, string): A table representing the manifest, | ||
64 | -- or nil followed by an error message and an error code, see manifest_loader. | ||
65 | function manif.fast_load_local_manifest(repo_url: string): any | nil, string, string --? {any: any} | ||
66 | assert(type(repo_url) == "string") | ||
67 | |||
68 | local cached_manifest = manif.get_cached_manifest(repo_url) | ||
69 | if cached_manifest then | ||
70 | return cached_manifest | ||
71 | end | ||
72 | |||
73 | local pathname = dir.path(repo_url, "manifest") | ||
74 | return manif.manifest_loader(pathname, repo_url, nil) --? return manif.manifest_loader(pathname, repo_url, nil, true) | ||
75 | end | ||
76 | |||
77 | function manif.load_rocks_tree_manifests(deps_mode: string): {any: any} --? {any: any} | ||
78 | local trees = {} | ||
79 | path.map_trees(deps_mode, function(tree) | ||
80 | local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree)) --? err not used | ||
81 | if manifest then | ||
82 | table.insert(trees, {tree=tree, manifest=manifest}) | ||
83 | end | ||
84 | end) | ||
85 | return trees | ||
86 | end | ||
87 | |||
88 | function manif.scan_dependencies(name: any, version: any, tree_manifests: {{any: {any: {any: {any: {{any: any}}}}}}}, dest: {any: any}) --? string or number, {{any: {any: {any: {any: {{any: any}}}}}}}??? | ||
89 | if dest[name] then | ||
90 | return | ||
91 | end | ||
92 | dest[name] = version | ||
93 | |||
94 | for _, tree in ipairs(tree_manifests) do | ||
95 | local manifest = tree.manifest | ||
96 | |||
97 | local pkgdeps: {{any: any}} | ||
98 | if manifest.dependencies and manifest.dependencies[name] then | ||
99 | pkgdeps = manifest.dependencies[name][version] | ||
100 | end | ||
101 | if pkgdeps then | ||
102 | for _, dep in ipairs(pkgdeps) do | ||
103 | local pkg, constraints = dep.name, dep.constraints | ||
104 | |||
105 | for _, t in ipairs(tree_manifests) do | ||
106 | local entries = t.manifest.repository[pkg] | ||
107 | if entries then | ||
108 | for ver, _ in util.sortedpairs(entries, vers.compare_versions) do --! | ||
109 | if (not constraints) or vers.match_constraints(vers.parse_version(ver), constraints) then | ||
110 | manif.scan_dependencies(pkg, ver, tree_manifests, dest) | ||
111 | end | ||
112 | end | ||
113 | end | ||
114 | end | ||
115 | end | ||
116 | return | ||
117 | end | ||
118 | end | ||
119 | end | ||
120 | |||
121 | return manif | ||