aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:49:06 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commit89e3d89c96d2b18c61e085fd4b1fd490dfe0fe5a (patch)
treee6fc978bf3fcaf554577124d3b9420656088394d
parent124027953feb4d373089f0a6d75fd42ec956da47 (diff)
downloadluarocks-89e3d89c96d2b18c61e085fd4b1fd490dfe0fe5a.tar.gz
luarocks-89e3d89c96d2b18c61e085fd4b1fd490dfe0fe5a.tar.bz2
luarocks-89e3d89c96d2b18c61e085fd4b1fd490dfe0fe5a.zip
Teal: convert luarocks.core.manif
-rw-r--r--src/luarocks/core/manif.tl (renamed from src/luarocks/core/manif.lua)48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/luarocks/core/manif.lua b/src/luarocks/core/manif.tl
index 3925f636..f75bf28e 100644
--- a/src/luarocks/core/manif.lua
+++ b/src/luarocks/core/manif.tl
@@ -1,6 +1,7 @@
1 1
2--- Core functions for querying manifest files. 2--- Core functions for querying manifest files.
3local manif = {} 3local record manif
4end
4 5
5local persist = require("luarocks.core.persist") 6local persist = require("luarocks.core.persist")
6local cfg = require("luarocks.core.cfg") 7local cfg = require("luarocks.core.cfg")
@@ -8,18 +9,27 @@ local dir = require("luarocks.core.dir")
8local util = require("luarocks.core.util") 9local util = require("luarocks.core.util")
9local vers = require("luarocks.core.vers") 10local vers = require("luarocks.core.vers")
10local path = require("luarocks.core.path") 11local path = require("luarocks.core.path")
11local require = nil 12
12-------------------------------------------------------------------------------- 13--------------------------------------------------------------------------------
13 14
15local type Tree = require("luarocks.core.types.tree").Tree
16
17local type Query = require("luarocks.core.types.query").Query
18
19local type Manifest = require("luarocks.core.types.manifest").Manifest
20local type Tree_manifest = require("luarocks.core.types.manifest").Tree_manifest
21
22
23
14-- Table with repository identifiers as keys and tables mapping 24-- Table with repository identifiers as keys and tables mapping
15-- Lua versions to cached loaded manifests as values. 25-- Lua versions to cached loaded manifests as values.
16local manifest_cache = {} 26local manifest_cache: {string: {string: Manifest}} = {}
17 27
18--- Cache a loaded manifest. 28--- Cache a loaded manifest.
19-- @param repo_url string: The repository identifier. 29-- @param repo_url string: The repository identifier.
20-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. 30-- @param lua_version string: Lua version in "5.x" format, defaults to installed version.
21-- @param manifest table: the manifest to be cached. 31-- @param manifest table: the manifest to be cached.
22function manif.cache_manifest(repo_url, lua_version, manifest) 32function manif.cache_manifest(repo_url: string, lua_version: string, manifest: Manifest)
23 lua_version = lua_version or cfg.lua_version 33 lua_version = lua_version or cfg.lua_version
24 manifest_cache[repo_url] = manifest_cache[repo_url] or {} 34 manifest_cache[repo_url] = manifest_cache[repo_url] or {}
25 manifest_cache[repo_url][lua_version] = manifest 35 manifest_cache[repo_url][lua_version] = manifest
@@ -29,7 +39,7 @@ end
29-- @param repo_url string: The repository identifier. 39-- @param repo_url string: The repository identifier.
30-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. 40-- @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. 41-- @return table or nil: loaded manifest or nil if cache is empty.
32function manif.get_cached_manifest(repo_url, lua_version) 42function manif.get_cached_manifest(repo_url: string, lua_version?: string): Manifest
33 lua_version = lua_version or cfg.lua_version 43 lua_version = lua_version or cfg.lua_version
34 return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version] 44 return manifest_cache[repo_url] and manifest_cache[repo_url][lua_version]
35end 45end
@@ -41,13 +51,14 @@ end
41-- @param lua_version string: Lua version in "5.x" format, defaults to installed version. 51-- @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, 52-- @return table or (nil, string, string): the manifest or nil,
43-- error message and error code ("open", "load", "run"). 53-- error message and error code ("open", "load", "run").
44function manif.manifest_loader(file, repo_url, lua_version) 54function manif.manifest_loader(file: string, repo_url: string, lua_version: string): Manifest, string | {any: any}, string
45 local manifest, err, errcode = persist.load_into_table(file) 55 local manifest, err, errcode: {any: any}, {any: any} | string, string = persist.load_into_table(file)
46 if not manifest then 56 if not manifest and err is string then
47 return nil, "Failed loading manifest for "..repo_url..": "..err, errcode 57 return nil, "Failed loading manifest for "..repo_url..": " .. err, errcode
48 end 58 end
49 manif.cache_manifest(repo_url, lua_version, manifest) 59
50 return manifest, err, errcode 60 manif.cache_manifest(repo_url, lua_version, manifest as Manifest) -- No runtime check if manifest is actually a Manifest!
61 return manifest as Manifest, err, errcode
51end 62end
52 63
53--- Load a local manifest describing a repository. 64--- Load a local manifest describing a repository.
@@ -55,8 +66,7 @@ end
55-- @param repo_url string: URL or pathname for the repository. 66-- @param repo_url string: URL or pathname for the repository.
56-- @return table or (nil, string, string): A table representing the manifest, 67-- @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. 68-- or nil followed by an error message and an error code, see manifest_loader.
58function manif.fast_load_local_manifest(repo_url) 69function manif.fast_load_local_manifest(repo_url: string): Manifest, string | {any: any}, string
59 assert(type(repo_url) == "string")
60 70
61 local cached_manifest = manif.get_cached_manifest(repo_url) 71 local cached_manifest = manif.get_cached_manifest(repo_url)
62 if cached_manifest then 72 if cached_manifest then
@@ -64,13 +74,13 @@ function manif.fast_load_local_manifest(repo_url)
64 end 74 end
65 75
66 local pathname = dir.path(repo_url, "manifest") 76 local pathname = dir.path(repo_url, "manifest")
67 return manif.manifest_loader(pathname, repo_url, nil, true) 77 return manif.manifest_loader(pathname, repo_url, nil)
68end 78end
69 79
70function manif.load_rocks_tree_manifests(deps_mode) 80function manif.load_rocks_tree_manifests(deps_mode?: string): {Tree_manifest}
71 local trees = {} 81 local trees = {}
72 path.map_trees(deps_mode, function(tree) 82 path.map_trees(deps_mode, function(tree: Tree)
73 local manifest, err = manif.fast_load_local_manifest(path.rocks_dir(tree)) 83 local manifest= manif.fast_load_local_manifest(path.rocks_dir(tree))
74 if manifest then 84 if manifest then
75 table.insert(trees, {tree=tree, manifest=manifest}) 85 table.insert(trees, {tree=tree, manifest=manifest})
76 end 86 end
@@ -78,7 +88,7 @@ function manif.load_rocks_tree_manifests(deps_mode)
78 return trees 88 return trees
79end 89end
80 90
81function manif.scan_dependencies(name, version, tree_manifests, dest) 91function manif.scan_dependencies(name: string, version: string, tree_manifests: {Tree_manifest}, dest: {any: any})
82 if dest[name] then 92 if dest[name] then
83 return 93 return
84 end 94 end
@@ -87,7 +97,7 @@ function manif.scan_dependencies(name, version, tree_manifests, dest)
87 for _, tree in ipairs(tree_manifests) do 97 for _, tree in ipairs(tree_manifests) do
88 local manifest = tree.manifest 98 local manifest = tree.manifest
89 99
90 local pkgdeps 100 local pkgdeps: {Query}
91 if manifest.dependencies and manifest.dependencies[name] then 101 if manifest.dependencies and manifest.dependencies[name] then
92 pkgdeps = manifest.dependencies[name][version] 102 pkgdeps = manifest.dependencies[name][version]
93 end 103 end