aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-16 17:58:04 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-16 17:58:04 +0300
commit228a07b1531a090a6d4421f07bd9593946b07c2e (patch)
tree6b41e44c2b685046f3c46ce7b3e0bc419ad8c1db
parent8ee47fb70d06da6878454aa800b44264a76c36b9 (diff)
downloadluarocks-228a07b1531a090a6d4421f07bd9593946b07c2e.tar.gz
luarocks-228a07b1531a090a6d4421f07bd9593946b07c2e.tar.bz2
luarocks-228a07b1531a090a6d4421f07bd9593946b07c2e.zip
downloads
-rw-r--r--src/luarocks/build/make.tl1
-rw-r--r--src/luarocks/cmd.tl58
-rw-r--r--src/luarocks/cmd/doc.lua2
-rw-r--r--src/luarocks/cmd/download.lua9
-rw-r--r--src/luarocks/cmd/lint.lua2
-rw-r--r--src/luarocks/cmd/new_version.lua2
-rw-r--r--src/luarocks/core/cfg.d.tl5
-rw-r--r--src/luarocks/core/hardcoded-original.lua6
-rw-r--r--src/luarocks/core/hardcoded.tl6
-rw-r--r--src/luarocks/core/types/tree.d.tl1
-rw-r--r--src/luarocks/download.tl63
-rw-r--r--src/luarocks/fs.d.tl2
-rw-r--r--src/luarocks/fun.tl11
-rw-r--r--src/luarocks/path.tl2
-rw-r--r--src/luarocks/util.tl2
15 files changed, 107 insertions, 65 deletions
diff --git a/src/luarocks/build/make.tl b/src/luarocks/build/make.tl
index 58fc6e2e..4107bca1 100644
--- a/src/luarocks/build/make.tl
+++ b/src/luarocks/build/make.tl
@@ -64,7 +64,6 @@ function make.run(rockspec: Rockspec, not_install: boolean): boolean, string, st
64 end 64 end
65 65
66 util.warn_if_not_used(build.build_variables, { CFLAGS=true }, "variable %s was not passed in build_variables") 66 util.warn_if_not_used(build.build_variables, { CFLAGS=true }, "variable %s was not passed in build_variables")
67-- Here, `util.warn_if_not_used(build.build_variables, { CFLAGS=true }, "variable %s was not passed in build_variables")` isn't the type of `build.build_variables`, `{string: string}`, like `variables`
68 util.variable_substitutions(build.build_variables, rockspec.variables) 67 util.variable_substitutions(build.build_variables, rockspec.variables)
69 util.variable_substitutions(build.install_variables, rockspec.variables) 68 util.variable_substitutions(build.install_variables, rockspec.variables)
70 69
diff --git a/src/luarocks/cmd.tl b/src/luarocks/cmd.tl
index e7ea3b19..93fa85dc 100644
--- a/src/luarocks/cmd.tl
+++ b/src/luarocks/cmd.tl
@@ -1,6 +1,17 @@
1 1
2--- Functions for command-line scripts. 2--- Functions for command-line scripts.
3local record cmd 3local record cmd
4 record Args
5 tree: string
6 global: boolean
7 deps_mode: string
8 ["local"]: boolean --!
9 project_tree: string
10 server: string
11 dev: boolean
12 only_server: string --!
13 end
14 errorcodes: {string: integer}
4end 15end
5 16
6local manif = require("luarocks.manif") 17local manif = require("luarocks.manif")
@@ -13,10 +24,14 @@ local fun = require("luarocks.fun")
13local fs = require("luarocks.fs") 24local fs = require("luarocks.fs")
14local argparse = require("luarocks.vendor.argparse") 25local argparse = require("luarocks.vendor.argparse")
15 26
16local unpack = table.unpack or unpack 27local type t = require("luarocks.core.types.tree")
17local pack = table.pack or function(...) return { n = select("#", ...), ... } end 28local type Tree = t.Tree
18 29
19local hc_ok, hardcoded = pcall(require, "luarocks.core.hardcoded") 30local type Args = cmd.Args
31
32-- local pack = table.pack or function(...) return { n = select("#", ...), ... } end
33
34local hc_ok, hardcoded: boolean, {string: string} = pcall(require, "luarocks.core.hardcoded")
20if not hc_ok then 35if not hc_ok then
21 hardcoded = {} 36 hardcoded = {}
22end 37end
@@ -45,19 +60,20 @@ local function check_popen()
45 end 60 end
46end 61end
47 62
48local process_tree_args 63local process_tree_args: function(Args, string): boolean, string
49do 64do
50 local function replace_tree(args, root, tree) 65 local function replace_tree(args: Args, root: string, tree?: Tree)
51 root = dir.normalize(root) 66 root = dir.normalize(root)
52 args.tree = root 67 args.tree = root
53 path.use_tree(tree or root) 68 path.use_tree(tree or root)
54 end 69 end
55 70
56 local function strip_trailing_slashes() 71 local function strip_trailing_slashes()
57 if type(cfg.root_dir) == "string" then 72 local cfg_root_dir = cfg.root_dir
58 cfg.root_dir = cfg.root_dir:gsub("/+$", "") 73 if cfg_root_dir is string then
74 cfg.root_dir = (cfg.root_dir as string):gsub("/+$", "")
59 else 75 else
60 cfg.root_dir.root = cfg.root_dir.root:gsub("/+$", "") 76 (cfg.root_dir as Tree).root = (cfg.root_dir as Tree).root:gsub("/+$", "")
61 end 77 end
62 cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "") 78 cfg.rocks_dir = cfg.rocks_dir:gsub("/+$", "")
63 cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "") 79 cfg.deploy_bin_dir = cfg.deploy_bin_dir:gsub("/+$", "")
@@ -65,9 +81,9 @@ do
65 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") 81 cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "")
66 end 82 end
67 83
68 local function set_named_tree(args, name) 84 local function set_named_tree(args: Args, name: string): boolean, string
69 for _, tree in ipairs(cfg.rocks_trees) do 85 for _, tree in ipairs(cfg.rocks_trees) do
70 if type(tree) == "table" and name == tree.name then 86 if tree is Tree and name == tree.name then
71 if not tree.root then 87 if not tree.root then
72 return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field." 88 return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field."
73 end 89 end
@@ -78,7 +94,7 @@ do
78 return false 94 return false
79 end 95 end
80 96
81 process_tree_args = function(args, project_dir) 97 process_tree_args = function(args: Args, project_dir: string): boolean, string
82 98
83 if args.global then 99 if args.global then
84 local ok, err = set_named_tree(args, "system") 100 local ok, err = set_named_tree(args, "system")
@@ -134,16 +150,22 @@ do
134 end 150 end
135end 151end
136 152
137local function process_server_args(args) 153local function process_server_args(args: Args): boolean, string
138 if args.server then 154 if args.server then
139 local protocol, pathname = dir.split_url(args.server) 155 local protocol, pathname = dir.split_url(args.server)
140 table.insert(cfg.rocks_servers, 1, protocol.."://"..pathname) 156 table.insert(cfg.rocks_servers, 1, protocol.."://"..pathname)
141 end 157 end
142 158
143 if args.dev then 159 if args.dev then
144 local append_dev = function(s) return dir.path(s, "dev") end 160 for i, server in ipairs(cfg.rocks_servers) do
145 local dev_servers = fun.traverse(cfg.rocks_servers, append_dev) 161 if server is string then
146 cfg.rocks_servers = fun.concat(dev_servers, cfg.rocks_servers) 162 cfg.rocks_servers[i] = dir.path(server, "dev")
163 else
164 for j, mirror in ipairs(server) do
165 server[j] = dir.path(mirror, "dev")
166 end
167 end
168 end
147 end 169 end
148 170
149 if args.only_server then 171 if args.only_server then
@@ -159,7 +181,7 @@ local function process_server_args(args)
159 return true 181 return true
160end 182end
161 183
162local function error_handler(err) 184local function error_handler(err: string): string
163 if not debug then 185 if not debug then
164 return err 186 return err
165 end 187 end
@@ -180,8 +202,8 @@ end
180--- Display an error message and exit. 202--- Display an error message and exit.
181-- @param message string: The error message. 203-- @param message string: The error message.
182-- @param exitcode number: the exitcode to use 204-- @param exitcode number: the exitcode to use
183local function die(message, exitcode) 205local function die(message: string, exitcode: number)
184 assert(type(message) == "string", "bad error, expected string, got: " .. type(message)) 206 assert(type(message) == "string", "bad error, expected string, got: " .. type(message)) --!
185 assert(exitcode == nil or type(exitcode) == "number", "bad error, expected number, got: " .. type(exitcode) .. " - " .. tostring(exitcode)) 207 assert(exitcode == nil or type(exitcode) == "number", "bad error, expected number, got: " .. type(exitcode) .. " - " .. tostring(exitcode))
186 util.printerr("\nError: "..message) 208 util.printerr("\nError: "..message)
187 209
diff --git a/src/luarocks/cmd/doc.lua b/src/luarocks/cmd/doc.lua
index a3117007..cae929cb 100644
--- a/src/luarocks/cmd/doc.lua
+++ b/src/luarocks/cmd/doc.lua
@@ -47,7 +47,7 @@ local function try_to_open_homepage(name, namespace, version)
47 util.schedule_function(fs.delete, temp_dir) 47 util.schedule_function(fs.delete, temp_dir)
48 local ok, err = fs.change_dir(temp_dir) 48 local ok, err = fs.change_dir(temp_dir)
49 if not ok then return nil, err end 49 if not ok then return nil, err end
50 local filename, err = download.download("rockspec", name, namespace, version) 50 local filename, err = download.download_file("rockspec", name, namespace, version)
51 if not filename then return nil, err end 51 if not filename then return nil, err end
52 local rockspec, err = fetch.load_local_rockspec(filename) 52 local rockspec, err = fetch.load_local_rockspec(filename)
53 if not rockspec then return nil, err end 53 if not rockspec then return nil, err end
diff --git a/src/luarocks/cmd/download.lua b/src/luarocks/cmd/download.lua
index eae82439..23433d30 100644
--- a/src/luarocks/cmd/download.lua
+++ b/src/luarocks/cmd/download.lua
@@ -44,8 +44,13 @@ function cmd_download.command(args)
44 arch = args.arch 44 arch = args.arch
45 end 45 end
46 46
47 local dl, err = download.download(arch, args.name, args.namespace, args.version, args.all, args.check_lua_versions) 47 if args.all then
48 return dl and true, err 48 local ok, err = download.download_all(arch, args.name, args.namespace, args.version)
49 return ok, err
50 else
51 local dl, err = download.download_file(arch, args.name, args.namespace, args.version, args.check_lua_versions)
52 return dl and true, err
53 end
49end 54end
50 55
51return cmd_download 56return cmd_download
diff --git a/src/luarocks/cmd/lint.lua b/src/luarocks/cmd/lint.lua
index 738503ce..421803e1 100644
--- a/src/luarocks/cmd/lint.lua
+++ b/src/luarocks/cmd/lint.lua
@@ -21,7 +21,7 @@ function lint.command(args)
21 local filename = args.rockspec 21 local filename = args.rockspec
22 if not filename:match(".rockspec$") then 22 if not filename:match(".rockspec$") then
23 local err 23 local err
24 filename, err = download.download("rockspec", filename:lower()) 24 filename, err = download.download_file("rockspec", filename:lower())
25 if not filename then 25 if not filename then
26 return nil, err 26 return nil, err
27 end 27 end
diff --git a/src/luarocks/cmd/new_version.lua b/src/luarocks/cmd/new_version.lua
index ccba9335..2ec084e0 100644
--- a/src/luarocks/cmd/new_version.lua
+++ b/src/luarocks/cmd/new_version.lua
@@ -161,7 +161,7 @@ function new_version.command(args)
161 return nil, err 161 return nil, err
162 end 162 end
163 else 163 else
164 filename, err = download.download("rockspec", args.rock:lower()) 164 filename, err = download.download_file("rockspec", args.rock:lower())
165 if not filename then 165 if not filename then
166 return nil, err 166 return nil, err
167 end 167 end
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl
index 409d2441..5903a49f 100644
--- a/src/luarocks/core/cfg.d.tl
+++ b/src/luarocks/core/cfg.d.tl
@@ -89,6 +89,11 @@ local record cfg
89 -- make 89 -- make
90 makefile: string 90 makefile: string
91 make: string 91 make: string
92 -- cmd
93 local_by_default: boolean
94 fs_use_modules: boolean
95 is_binary: boolean
96 program_version: string
92end 97end
93 98
94return cfg \ No newline at end of file 99return cfg \ No newline at end of file
diff --git a/src/luarocks/core/hardcoded-original.lua b/src/luarocks/core/hardcoded-original.lua
new file mode 100644
index 00000000..52b89fa5
--- /dev/null
+++ b/src/luarocks/core/hardcoded-original.lua
@@ -0,0 +1,6 @@
1return {
2SYSCONFDIR = "/home/victor/Documents/luarocks/testrun/testing_lrprefix-5.4/etc/luarocks",
3LUA_DIR = "/usr",
4LUA_BINDIR = "/usr/bin",
5LUA = "/usr/bin/lua",
6}
diff --git a/src/luarocks/core/hardcoded.tl b/src/luarocks/core/hardcoded.tl
new file mode 100644
index 00000000..52b89fa5
--- /dev/null
+++ b/src/luarocks/core/hardcoded.tl
@@ -0,0 +1,6 @@
1return {
2SYSCONFDIR = "/home/victor/Documents/luarocks/testrun/testing_lrprefix-5.4/etc/luarocks",
3LUA_DIR = "/usr",
4LUA_BINDIR = "/usr/bin",
5LUA = "/usr/bin/lua",
6}
diff --git a/src/luarocks/core/types/tree.d.tl b/src/luarocks/core/types/tree.d.tl
index df54def9..6af23f37 100644
--- a/src/luarocks/core/types/tree.d.tl
+++ b/src/luarocks/core/types/tree.d.tl
@@ -1,5 +1,6 @@
1local record tree 1local record tree
2 record Tree 2 record Tree
3 name: string
3 root: string 4 root: string
4 rocks_dir: string 5 rocks_dir: string
5 lua_dir: string 6 lua_dir: string
diff --git a/src/luarocks/download.tl b/src/luarocks/download.tl
index 43a57d8f..508f74b4 100644
--- a/src/luarocks/download.tl
+++ b/src/luarocks/download.tl
@@ -25,43 +25,50 @@ local function get_file(filename: string): string, string
25 end 25 end
26end 26end
27 27
28function download.download(arch: string, name: string, namespace: string, version: string, all, check_lua_versions: boolean): string, string 28function download.download_all(arch: string, name: string, namespace: string, version: string): boolean, string
29 local substring = (all and name == "") 29 local substring = (name == "")
30 local query = queries.new(name, namespace, version, substring, arch) 30 local query = queries.new(name, namespace, version, substring, arch)
31 local search_err: string 31 local search_err: string
32 32
33 if all then 33 local results = search.search_repos(query)
34 local results = search.search_repos(query) 34 local has_result = false
35 local has_result = false 35 local all_ok = true
36 local all_ok = true 36 local any_err = ""
37 local any_err = "" 37 for name, result in pairs(results) do -- luacheck: ignore 422
38 for name, result in pairs(results) do -- luacheck: ignore 422 38 for version, items in pairs(result) do -- luacheck: ignore 422
39 for version, items in pairs(result) do -- luacheck: ignore 422 39 for _, item in ipairs(items) do
40 for _, item in ipairs(items) do 40 -- Ignore provided rocks.
41 -- Ignore provided rocks. 41 if item.arch ~= "installed" then
42 if item.arch ~= "installed" then 42 has_result = true
43 has_result = true 43 local filename = path.make_url(item.repo, name, version, item.arch)
44 local filename = path.make_url(item.repo, name, version, item.arch) 44 local ok, err = get_file(filename)
45 local ok, err = get_file(filename) 45 if not ok then
46 if not ok then 46 all_ok = false
47 all_ok = false 47 any_err = any_err .. "\n" .. err
48 any_err = any_err .. "\n" .. err
49 end
50 end 48 end
51 end 49 end
52 end 50 end
53 end 51 end
52 end
54 53
55 if has_result then 54 if has_result then
56 return all_ok, any_err 55 return all_ok, any_err
57 end 56 end
58 else 57
59 local url: string 58 local rock = util.format_rock_name(name, namespace, version)
60 url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions) 59 return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".")
61 if url then 60end
62 return get_file(url) 61
63 end 62function download.download_file(arch: string, name: string, namespace: string, version: string, check_lua_versions?: boolean): string, string
63 local query = queries.new(name, namespace, version, false, arch)
64 local search_err: string
65
66 local url: string
67 url, search_err = search.find_rock_checking_lua_versions(query, check_lua_versions)
68 if url then
69 return get_file(url)
64 end 70 end
71
65 local rock = util.format_rock_name(name, namespace, version) 72 local rock = util.format_rock_name(name, namespace, version)
66 return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".") 73 return nil, "Could not find a result named "..rock..(search_err and ": "..search_err or ".")
67end 74end
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl
index b72bd35a..93555b08 100644
--- a/src/luarocks/fs.d.tl
+++ b/src/luarocks/fs.d.tl
@@ -67,6 +67,8 @@ local record fs
67 execute_env: function({any: any}, string, ...:string): boolean 67 execute_env: function({any: any}, string, ...:string): boolean
68 -- pack 68 -- pack
69 zip: function(string, ...:string): boolean, string 69 zip: function(string, ...:string): boolean, string
70 -- cmd
71 is_superuser: function(): boolean
70end 72end
71 73
72return fs 74return fs
diff --git a/src/luarocks/fun.tl b/src/luarocks/fun.tl
index e2d43d5d..5d581af5 100644
--- a/src/luarocks/fun.tl
+++ b/src/luarocks/fun.tl
@@ -44,17 +44,6 @@ function fun.filter<K>(xs: {K}, f: function): {K}
44 return rs 44 return rs
45end 45end
46 46
47function fun.traverse<K, V>(t: {K}, f: function(K): V): {V} | V --? right or {any} | any
48 return fun.map(t, function(x: K): {V} | V
49 -- return x is table and fun.traverse(x, f) or f(x) --?
50 if x is {any} then
51 return fun.traverse(x, f)
52 else
53 return f(x)
54 end
55 end)
56end
57
58function fun.reverse_in<K>(t: {K}): {K} 47function fun.reverse_in<K>(t: {K}): {K}
59 for i = 1, math.floor(#t/2) do 48 for i = 1, math.floor(#t/2) do
60 local m, n = i, #t - i + 1 49 local m, n = i, #t - i + 1
diff --git a/src/luarocks/path.tl b/src/luarocks/path.tl
index 65c425d3..d6a06b5d 100644
--- a/src/luarocks/path.tl
+++ b/src/luarocks/path.tl
@@ -207,7 +207,7 @@ function path.module_to_path(mod: string): string
207 return (mod:gsub("[^.]*$", ""):gsub("%.", "/")) 207 return (mod:gsub("[^.]*$", ""):gsub("%.", "/"))
208end 208end
209 209
210function path.use_tree(tree: Tree) 210function path.use_tree(tree: string | Tree)
211 cfg.root_dir = tree 211 cfg.root_dir = tree
212 cfg.rocks_dir = path.rocks_dir(tree) 212 cfg.rocks_dir = path.rocks_dir(tree)
213 cfg.deploy_bin_dir = path.deploy_bin_dir(tree) 213 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
diff --git a/src/luarocks/util.tl b/src/luarocks/util.tl
index d57de5e8..5e22e840 100644
--- a/src/luarocks/util.tl
+++ b/src/luarocks/util.tl
@@ -112,7 +112,7 @@ local var_format_pattern = "%$%((%a[%a%d_]+)%)"
112-- @param needed_set: a set where keys are the names of 112-- @param needed_set: a set where keys are the names of
113-- needed variables. 113-- needed variables.
114-- @param msg string: the warning message to display. 114-- @param msg string: the warning message to display.
115function util.warn_if_not_used(var_defs: {string: string}, needed_set: {string: string}, msg: string) 115function util.warn_if_not_used(var_defs: {string: string}, needed_set: {string: boolean}, msg: string)
116 local seen = {} 116 local seen = {}
117 for _, val in pairs(var_defs) do 117 for _, val in pairs(var_defs) do
118 for used in val:gmatch(var_format_pattern) do 118 for used in val:gmatch(var_format_pattern) do