diff options
author | V1K1NGbg <victor@ilchev.com> | 2024-08-22 17:49:00 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-10-21 13:30:51 -0300 |
commit | 8286ac6ca0a0d17b72132c5cfab4eadea7c5d384 (patch) | |
tree | a1f0014658ab3a15fae405c9ebe9f960ccd60df8 | |
parent | ef6ae68c57b74430654987f159af1f1e902f67c2 (diff) | |
download | luarocks-8286ac6ca0a0d17b72132c5cfab4eadea7c5d384.tar.gz luarocks-8286ac6ca0a0d17b72132c5cfab4eadea7c5d384.tar.bz2 luarocks-8286ac6ca0a0d17b72132c5cfab4eadea7c5d384.zip |
Teal: convert luarocks.manif
-rw-r--r-- | src/luarocks/manif.tl (renamed from src/luarocks/manif.lua) | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.tl index a4ddda11..23ed081b 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.tl | |||
@@ -2,7 +2,15 @@ | |||
2 | -- Manifest files describe the contents of a LuaRocks tree or server. | 2 | -- Manifest files describe the contents of a LuaRocks tree or server. |
3 | -- They are loaded into manifest tables, which are then used for | 3 | -- They are loaded into manifest tables, which are then used for |
4 | -- performing searches, matching dependencies, etc. | 4 | -- performing searches, matching dependencies, etc. |
5 | local manif = {} | 5 | local record manif |
6 | cache_manifest: function(string, string, Manifest) | ||
7 | load_rocks_tree_manifests: function(? string): {Tree_manifest} | ||
8 | scan_dependencies: function(string, string, {Tree_manifest}, {any : any}) | ||
9 | rock_manifest_cache: {string: RockManifest} | ||
10 | end | ||
11 | |||
12 | local type RockManifest = require("luarocks.core.types.rockmanifest").RockManifest | ||
13 | local type Entry = require("luarocks.core.types.rockmanifest").RockManifest.Entry | ||
6 | 14 | ||
7 | local core = require("luarocks.core.manif") | 15 | local core = require("luarocks.core.manif") |
8 | local persist = require("luarocks.persist") | 16 | local persist = require("luarocks.persist") |
@@ -15,13 +23,18 @@ local util = require("luarocks.util") | |||
15 | local queries = require("luarocks.queries") | 23 | local queries = require("luarocks.queries") |
16 | local type_manifest = require("luarocks.type.manifest") | 24 | local type_manifest = require("luarocks.type.manifest") |
17 | 25 | ||
26 | local type Tree = require("luarocks.core.types.tree").Tree | ||
27 | local type Manifest = require("luarocks.core.types.manifest").Manifest | ||
28 | local type Tree_manifest = require("luarocks.core.types.manifest").Tree_manifest | ||
29 | local type Query = require("luarocks.core.types.query").Query | ||
30 | |||
18 | manif.cache_manifest = core.cache_manifest | 31 | manif.cache_manifest = core.cache_manifest |
19 | manif.load_rocks_tree_manifests = core.load_rocks_tree_manifests | 32 | manif.load_rocks_tree_manifests = core.load_rocks_tree_manifests |
20 | manif.scan_dependencies = core.scan_dependencies | 33 | manif.scan_dependencies = core.scan_dependencies |
21 | 34 | ||
22 | manif.rock_manifest_cache = {} | 35 | manif.rock_manifest_cache = {} |
23 | 36 | ||
24 | local function check_manifest(repo_url, manifest, globals) | 37 | local function check_manifest(repo_url: string, manifest: Manifest, globals: {string: any}): Manifest, string, string |
25 | local ok, err = type_manifest.check(manifest, globals) | 38 | local ok, err = type_manifest.check(manifest, globals) |
26 | if not ok then | 39 | if not ok then |
27 | core.cache_manifest(repo_url, cfg.lua_version, nil) | 40 | core.cache_manifest(repo_url, cfg.lua_version, nil) |
@@ -30,17 +43,17 @@ local function check_manifest(repo_url, manifest, globals) | |||
30 | return manifest | 43 | return manifest |
31 | end | 44 | end |
32 | 45 | ||
33 | local postprocess_dependencies | 46 | local postprocess_dependencies: function(Manifest) |
34 | do | 47 | do |
35 | local postprocess_check = setmetatable({}, { __mode = "k" }) | 48 | local postprocess_check = setmetatable({}, { __mode = "k" }) |
36 | postprocess_dependencies = function(manifest) | 49 | postprocess_dependencies = function(manifest: Manifest) |
37 | if postprocess_check[manifest] then | 50 | if postprocess_check[manifest] then |
38 | return | 51 | return |
39 | end | 52 | end |
40 | if manifest.dependencies then | 53 | if manifest.dependencies then |
41 | for name, versions in pairs(manifest.dependencies) do | 54 | for _, versions in pairs(manifest.dependencies) do |
42 | for version, entries in pairs(versions) do | 55 | for _, entries in pairs(versions) do |
43 | for k, v in pairs(entries) do | 56 | for k, v in ipairs(entries) do |
44 | entries[k] = queries.from_persisted_table(v) | 57 | entries[k] = queries.from_persisted_table(v) |
45 | end | 58 | end |
46 | end | 59 | end |
@@ -50,16 +63,15 @@ do | |||
50 | end | 63 | end |
51 | end | 64 | end |
52 | 65 | ||
53 | function manif.load_rock_manifest(name, version, root) | 66 | function manif.load_rock_manifest(name: string, version: string, root?: string | Tree): {string: Entry}, string |
54 | assert(type(name) == "string" and not name:match("/")) | 67 | assert(not name:match("/")) |
55 | assert(type(version) == "string") | ||
56 | 68 | ||
57 | local name_version = name.."/"..version | 69 | local name_version = name.."/"..version |
58 | if manif.rock_manifest_cache[name_version] then | 70 | if manif.rock_manifest_cache[name_version] then |
59 | return manif.rock_manifest_cache[name_version].rock_manifest | 71 | return manif.rock_manifest_cache[name_version].rock_manifest |
60 | end | 72 | end |
61 | local pathname = path.rock_manifest_file(name, version, root) | 73 | local pathname = path.rock_manifest_file(name, version, root) |
62 | local rock_manifest = persist.load_into_table(pathname) | 74 | local rock_manifest = persist.load_into_table(pathname) as RockManifest |
63 | if not rock_manifest then | 75 | if not rock_manifest then |
64 | return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks tree?" | 76 | return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks tree?" |
65 | end | 77 | end |
@@ -76,9 +88,7 @@ end | |||
76 | -- if a versioned manifest was not found. | 88 | -- if a versioned manifest was not found. |
77 | -- @return table or (nil, string, [string]): A table representing the manifest, | 89 | -- @return table or (nil, string, [string]): A table representing the manifest, |
78 | -- or nil followed by an error message and an optional error code. | 90 | -- or nil followed by an error message and an optional error code. |
79 | function manif.load_manifest(repo_url, lua_version, versioned_only) | 91 | function manif.load_manifest(repo_url: string, lua_version?: string, versioned_only?: boolean): Manifest, string, string |
80 | assert(type(repo_url) == "string") | ||
81 | assert(type(lua_version) == "string" or not lua_version) | ||
82 | lua_version = lua_version or cfg.lua_version | 92 | lua_version = lua_version or cfg.lua_version |
83 | 93 | ||
84 | local cached_manifest = core.get_cached_manifest(repo_url, lua_version) | 94 | local cached_manifest = core.get_cached_manifest(repo_url, lua_version) |
@@ -94,7 +104,7 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
94 | } | 104 | } |
95 | 105 | ||
96 | local protocol, repodir = dir.split_url(repo_url) | 106 | local protocol, repodir = dir.split_url(repo_url) |
97 | local pathname, from_cache | 107 | local pathname, from_cache: string, boolean |
98 | if protocol == "file" then | 108 | if protocol == "file" then |
99 | for _, filename in ipairs(filenames) do | 109 | for _, filename in ipairs(filenames) do |
100 | pathname = dir.path(repodir, filename) | 110 | pathname = dir.path(repodir, filename) |
@@ -103,7 +113,7 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
103 | end | 113 | end |
104 | end | 114 | end |
105 | else | 115 | else |
106 | local err, errcode | 116 | local err, errcode: string, string |
107 | for _, filename in ipairs(filenames) do | 117 | for _, filename in ipairs(filenames) do |
108 | pathname, err, errcode, from_cache = fetch.fetch_caching(dir.path(repo_url, filename), "no_mirror") | 118 | pathname, err, errcode, from_cache = fetch.fetch_caching(dir.path(repo_url, filename), "no_mirror") |
109 | if pathname then | 119 | if pathname then |
@@ -132,32 +142,28 @@ function manif.load_manifest(repo_url, lua_version, versioned_only) | |||
132 | pathname = nozip | 142 | pathname = nozip |
133 | end | 143 | end |
134 | local manifest, err, errcode = core.manifest_loader(pathname, repo_url, lua_version) | 144 | local manifest, err, errcode = core.manifest_loader(pathname, repo_url, lua_version) |
135 | if not manifest then | 145 | if not manifest and err is string then --! |
136 | return nil, err, errcode | 146 | return nil, err, errcode |
137 | end | 147 | end |
138 | 148 | ||
139 | postprocess_dependencies(manifest) | 149 | postprocess_dependencies(manifest) |
140 | return check_manifest(repo_url, manifest, err) | 150 | return check_manifest(repo_url, manifest, err as {string: any}) |
141 | end | 151 | end |
142 | 152 | ||
143 | --- Get type and name of an item (a module or a command) provided by a file. | 153 | --- Get type and name of an item (a module or a command) provided by a file. |
144 | -- @param deploy_type string: rock manifest subtree the file comes from ("bin", "lua", or "lib"). | 154 | -- @param deploy_type string: rock manifest subtree the file comes from ("bin", "lua", or "lib"). |
145 | -- @param file_path string: path to the file relatively to deploy_type subdirectory. | 155 | -- @param file_path string: path to the file relatively to deploy_type subdirectory. |
146 | -- @return (string, string): item type ("module" or "command") and name. | 156 | -- @return (string, string): item type ("module" or "command") and name. |
147 | function manif.get_provided_item(deploy_type, file_path) | 157 | function manif.get_provided_item(deploy_type: string, file_path: string): string, string |
148 | assert(type(deploy_type) == "string") | ||
149 | assert(type(file_path) == "string") | ||
150 | local item_type = deploy_type == "bin" and "command" or "module" | 158 | local item_type = deploy_type == "bin" and "command" or "module" |
151 | local item_name = item_type == "command" and file_path or path.path_to_module(file_path) | 159 | local item_name = item_type == "command" and file_path or path.path_to_module(file_path) |
152 | return item_type, item_name | 160 | return item_type, item_name |
153 | end | 161 | end |
154 | 162 | ||
155 | local function get_providers(item_type, item_name, repo) | 163 | local function get_providers(item_type: string, item_name: string, repo: string | Tree): {string} |
156 | assert(type(item_type) == "string") | ||
157 | assert(type(item_name) == "string") | ||
158 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) | 164 | local rocks_dir = path.rocks_dir(repo or cfg.root_dir) |
159 | local manifest = manif.load_manifest(rocks_dir) | 165 | local manifest = manif.load_manifest(rocks_dir) |
160 | return manifest and manifest[item_type .. "s"][item_name] | 166 | return manifest and (manifest as {string: {string: {string}}})[item_type .. "s"][item_name] |
161 | end | 167 | end |
162 | 168 | ||
163 | --- Given a name of a module or a command, figure out which rock name and version | 169 | --- Given a name of a module or a command, figure out which rock name and version |
@@ -167,14 +173,14 @@ end | |||
167 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. | 173 | -- @param root string or nil: A local root dir for a rocks tree. If not given, the default is used. |
168 | -- @return (string, string) or nil: name and version of the provider rock or nil if there | 174 | -- @return (string, string) or nil: name and version of the provider rock or nil if there |
169 | -- is no provider. | 175 | -- is no provider. |
170 | function manif.get_current_provider(item_type, item_name, repo) | 176 | function manif.get_current_provider(item_type: string, item_name: string, repo?: string | Tree): string, string |
171 | local providers = get_providers(item_type, item_name, repo) | 177 | local providers = get_providers(item_type, item_name, repo) |
172 | if providers then | 178 | if providers then |
173 | return providers[1]:match("([^/]*)/([^/]*)") | 179 | return providers[1]:match("([^/]*)/([^/]*)") |
174 | end | 180 | end |
175 | end | 181 | end |
176 | 182 | ||
177 | function manif.get_next_provider(item_type, item_name, repo) | 183 | function manif.get_next_provider(item_type: string, item_name: string, repo?: string | Tree): string, string |
178 | local providers = get_providers(item_type, item_name, repo) | 184 | local providers = get_providers(item_type, item_name, repo) |
179 | if providers and providers[2] then | 185 | if providers and providers[2] then |
180 | return providers[2]:match("([^/]*)/([^/]*)") | 186 | return providers[2]:match("([^/]*)/([^/]*)") |
@@ -189,15 +195,13 @@ end | |||
189 | -- or "all", to use all trees. | 195 | -- or "all", to use all trees. |
190 | -- @return table: An array of strings listing installed | 196 | -- @return table: An array of strings listing installed |
191 | -- versions of a package, and a table indicating where they are found. | 197 | -- versions of a package, and a table indicating where they are found. |
192 | function manif.get_versions(dep, deps_mode) | 198 | function manif.get_versions(dep: Query, deps_mode: string): {string}, {string: string | Tree} |
193 | assert(type(dep) == "table") | ||
194 | assert(type(deps_mode) == "string") | ||
195 | 199 | ||
196 | local name = dep.name | 200 | local name: string = dep.name |
197 | local namespace = dep.namespace | 201 | local namespace: string = dep.namespace |
198 | 202 | ||
199 | local version_set = {} | 203 | local version_set = {} |
200 | path.map_trees(deps_mode, function(tree) | 204 | path.map_trees(deps_mode, function(tree: string | Tree) |
201 | local manifest = manif.load_manifest(path.rocks_dir(tree)) | 205 | local manifest = manif.load_manifest(path.rocks_dir(tree)) |
202 | 206 | ||
203 | if manifest and manifest.repository[name] then | 207 | if manifest and manifest.repository[name] then |