aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-22 17:48:57 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-10-21 13:30:51 -0300
commit091c6a54952f1d67400a5c3b4da5ee2f469e0484 (patch)
tree4a57101c637971788bf6b527faad9ad073da6802 /src
parent1e5e7ba13a5230955785cd3989beabb60418c2a9 (diff)
downloadluarocks-091c6a54952f1d67400a5c3b4da5ee2f469e0484.tar.gz
luarocks-091c6a54952f1d67400a5c3b4da5ee2f469e0484.tar.bz2
luarocks-091c6a54952f1d67400a5c3b4da5ee2f469e0484.zip
Teal: convert luarocks.pack
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/pack.tl (renamed from src/luarocks/pack.lua)44
1 files changed, 24 insertions, 20 deletions
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.tl
index 731f49dd..8bb284f7 100644
--- a/src/luarocks/pack.lua
+++ b/src/luarocks/pack.tl
@@ -1,8 +1,7 @@
1 1
2-- Create rock files, packing sources or binaries. 2-- Create rock files, packing sources or binaries.
3local pack = {} 3local record pack
4 4end
5local unpack = unpack or table.unpack
6 5
7local queries = require("luarocks.queries") 6local queries = require("luarocks.queries")
8local path = require("luarocks.path") 7local path = require("luarocks.path")
@@ -16,6 +15,12 @@ local manif = require("luarocks.manif")
16local search = require("luarocks.search") 15local search = require("luarocks.search")
17local signing = require("luarocks.signing") 16local signing = require("luarocks.signing")
18 17
18local type Tree = require("luarocks.core.types.tree").Tree
19
20local type Query = require("luarocks.core.types.query").Query
21
22local type Entry = require("luarocks.core.types.rockmanifest").RockManifest.Entry
23
19--- Create a source rock. 24--- Create a source rock.
20-- Packages a rockspec and its required source files in a rock 25-- Packages a rockspec and its required source files in a rock
21-- file with the .src.rock extension, which can later be built and 26-- file with the .src.rock extension, which can later be built and
@@ -23,12 +28,11 @@ local signing = require("luarocks.signing")
23-- @param rockspec_file string: An URL or pathname for a rockspec file. 28-- @param rockspec_file string: An URL or pathname for a rockspec file.
24-- @return string or (nil, string): The filename of the resulting 29-- @return string or (nil, string): The filename of the resulting
25-- .src.rock file; or nil and an error message. 30-- .src.rock file; or nil and an error message.
26function pack.pack_source_rock(rockspec_file) 31function pack.pack_source_rock(rockspec_file: string): string, string
27 assert(type(rockspec_file) == "string")
28 32
29 local rockspec, err = fetch.load_rockspec(rockspec_file) 33 local rockspec, errload = fetch.load_rockspec(rockspec_file)
30 if err then 34 if errload then
31 return nil, "Error loading rockspec: "..err 35 return nil, "Error loading rockspec: "..errload
32 end 36 end
33 rockspec_file = rockspec.local_abs_filename 37 rockspec_file = rockspec.local_abs_filename
34 38
@@ -45,8 +49,8 @@ function pack.pack_source_rock(rockspec_file)
45 if not source_file then 49 if not source_file then
46 return nil, source_dir 50 return nil, source_dir
47 end 51 end
48 local ok, err = fs.change_dir(source_dir) 52 local ok, errchange = fs.change_dir(source_dir)
49 if not ok then return nil, err end 53 if not ok then return nil, errchange end
50 54
51 fs.delete(rock_file) 55 fs.delete(rock_file)
52 fs.copy(rockspec_file, source_dir, "read") 56 fs.copy(rockspec_file, source_dir, "read")
@@ -59,14 +63,14 @@ function pack.pack_source_rock(rockspec_file)
59 return rock_file 63 return rock_file
60end 64end
61 65
62local function copy_back_files(name, version, file_tree, deploy_dir, pack_dir, perms) 66local function copy_back_files(name: string, version: string, file_tree: {string: any}, deploy_dir: string, pack_dir: string, perms?: string): boolean, string
63 local ok, err = fs.make_dir(pack_dir) 67 local ok, err = fs.make_dir(pack_dir)
64 if not ok then return nil, err end 68 if not ok then return nil, err end
65 for file, sub in pairs(file_tree) do 69 for file, sub in pairs(file_tree) do
66 local source = dir.path(deploy_dir, file) 70 local source = dir.path(deploy_dir, file)
67 local target = dir.path(pack_dir, file) 71 local target = dir.path(pack_dir, file)
68 if type(sub) == "table" then 72 if sub is {string: any} then
69 local ok, err = copy_back_files(name, version, sub, source, target) 73 ok, err = copy_back_files(name, version, sub, source, target)
70 if not ok then return nil, err end 74 if not ok then return nil, err end
71 else 75 else
72 local versioned = path.versioned_name(source, deploy_dir, name, version) 76 local versioned = path.versioned_name(source, deploy_dir, name, version)
@@ -85,7 +89,7 @@ end
85-- @param tree string or nil: An optional tree to pick the package from. 89-- @param tree string or nil: An optional tree to pick the package from.
86-- @return string or (nil, string): The filename of the resulting 90-- @return string or (nil, string): The filename of the resulting
87-- .src.rock file; or nil and an error message. 91-- .src.rock file; or nil and an error message.
88function pack.pack_installed_rock(query, tree) 92function pack.pack_installed_rock(query: Query, tree: string | Tree): string, string
89 93
90 local name, version, repo, repo_url = search.pick_installed_rock(query, tree) 94 local name, version, repo, repo_url = search.pick_installed_rock(query, tree)
91 if not name then 95 if not name then
@@ -109,12 +113,12 @@ function pack.pack_installed_rock(query, tree)
109 113
110 local is_binary = false 114 local is_binary = false
111 if rock_manifest.lib then 115 if rock_manifest.lib then
112 local ok, err = copy_back_files(name, version, rock_manifest.lib, path.deploy_lib_dir(repo), dir.path(temp_dir, "lib"), "exec") 116 local ok, err = copy_back_files(name, version, (rock_manifest.lib as {string: Entry}), path.deploy_lib_dir(repo), dir.path(temp_dir, "lib"), "exec")
113 if not ok then return nil, "Failed copying back files: " .. err end 117 if not ok then return nil, "Failed copying back files: " .. err end
114 is_binary = true 118 is_binary = true
115 end 119 end
116 if rock_manifest.lua then 120 if rock_manifest.lua then
117 local ok, err = copy_back_files(name, version, rock_manifest.lua, path.deploy_lua_dir(repo), dir.path(temp_dir, "lua"), "read") 121 local ok, err = copy_back_files(name, version, (rock_manifest.lua as {string: Entry}), path.deploy_lua_dir(repo), dir.path(temp_dir, "lua"), "read")
118 if not ok then return nil, "Failed copying back files: " .. err end 122 if not ok then return nil, "Failed copying back files: " .. err end
119 end 123 end
120 124
@@ -124,7 +128,7 @@ function pack.pack_installed_rock(query, tree)
124 rock_file = rock_file:gsub("%."..cfg.arch:gsub("%-","%%-").."%.", ".all.") 128 rock_file = rock_file:gsub("%."..cfg.arch:gsub("%-","%%-").."%.", ".all.")
125 end 129 end
126 fs.delete(rock_file) 130 fs.delete(rock_file)
127 ok, err = fs.zip(rock_file, unpack(fs.list_dir())) 131 ok, err = fs.zip(rock_file, table.unpack(fs.list_dir()))
128 if not ok then 132 if not ok then
129 return nil, "Failed packing " .. rock_file .. " - " .. err 133 return nil, "Failed packing " .. rock_file .. " - " .. err
130 end 134 end
@@ -133,11 +137,11 @@ function pack.pack_installed_rock(query, tree)
133 return rock_file 137 return rock_file
134end 138end
135 139
136function pack.report_and_sign_local_file(file, err, sign) 140function pack.report_and_sign_local_file(file: string, err: string, sign: boolean): boolean, string
137 if err then 141 if err then
138 return nil, err 142 return nil, err
139 end 143 end
140 local sigfile 144 local sigfile: string
141 if sign then 145 if sign then
142 sigfile, err = signing.sign_file(file) 146 sigfile, err = signing.sign_file(file)
143 util.printout() 147 util.printout()
@@ -152,7 +156,7 @@ function pack.report_and_sign_local_file(file, err, sign)
152 return true 156 return true
153end 157end
154 158
155function pack.pack_binary_rock(name, namespace, version, sign, cmd) 159function pack.pack_binary_rock(name: string, namespace: string, version: string, sign: boolean, cmd: function(): (string, string)): boolean, string
156 160
157 -- The --pack-binary-rock option for "luarocks build" basically performs 161 -- The --pack-binary-rock option for "luarocks build" basically performs
158 -- "luarocks build" on a temporary tree and then "luarocks pack". The 162 -- "luarocks build" on a temporary tree and then "luarocks pack". The