aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-08-13 16:05:27 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-13 16:05:27 +0300
commit6f0efdcc78f793c28645850e95d5cdb33698996f (patch)
treeb87cf311c016a7fdd4f01add9286d40d47146f5c
parentcd7f62b9bd1b91fb18d798e408bf41936b0f9bb9 (diff)
downloadluarocks-6f0efdcc78f793c28645850e95d5cdb33698996f.tar.gz
luarocks-6f0efdcc78f793c28645850e95d5cdb33698996f.tar.bz2
luarocks-6f0efdcc78f793c28645850e95d5cdb33698996f.zip
manif changes
-rw-r--r--src/luarocks/core/cfg.d.tl3
-rw-r--r--src/luarocks/core/types/rockmanifest.d.tl2
-rw-r--r--src/luarocks/core/types/rockspec.tl2
-rw-r--r--src/luarocks/fs.d.tl2
-rw-r--r--src/luarocks/manif.lua4
-rw-r--r--src/luarocks/manif.tl4
-rw-r--r--src/luarocks/path.lua1
-rw-r--r--src/luarocks/path.tl2
-rw-r--r--src/luarocks/repos.tl59
-rw-r--r--src/luarocks/test/busted.tl2
-rw-r--r--src/luarocks/test/command.tl2
11 files changed, 47 insertions, 36 deletions
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl
index c2502d5a..bd07e527 100644
--- a/src/luarocks/core/cfg.d.tl
+++ b/src/luarocks/core/cfg.d.tl
@@ -73,6 +73,9 @@ local record cfg
73 runtime_external_deps_subdirs: {string: string} 73 runtime_external_deps_subdirs: {string: string}
74 external_lib_extension: string 74 external_lib_extension: string
75 external_deps_dirs: {string} 75 external_deps_dirs: {string}
76 -- repos
77 hooks_enabled: boolean
78 wrap_bin_scripts: boolean
76end 79end
77 80
78return cfg \ No newline at end of file 81return cfg \ No newline at end of file
diff --git a/src/luarocks/core/types/rockmanifest.d.tl b/src/luarocks/core/types/rockmanifest.d.tl
index 59fec9f1..dbcb0380 100644
--- a/src/luarocks/core/types/rockmanifest.d.tl
+++ b/src/luarocks/core/types/rockmanifest.d.tl
@@ -1,7 +1,7 @@
1local record rockmanifest 1local record rockmanifest
2 record RockManifest 2 record RockManifest
3 type Entry = string | {string: Entry} 3 type Entry = string | {string: Entry}
4 rock_manifest: {string: Entry} 4 entries: {string: Entry}
5 end 5 end
6end 6end
7return rockmanifest \ No newline at end of file 7return rockmanifest \ No newline at end of file
diff --git a/src/luarocks/core/types/rockspec.tl b/src/luarocks/core/types/rockspec.tl
index 37aacf7d..2375b888 100644
--- a/src/luarocks/core/types/rockspec.tl
+++ b/src/luarocks/core/types/rockspec.tl
@@ -83,7 +83,7 @@ local record rockspec
83 83
84 record Hooks 84 record Hooks
85 post_install: string 85 post_install: string
86 86 substituted_variables: boolean
87 end 87 end
88 88
89 record Deploy 89 record Deploy
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl
index c2b2af33..e946f642 100644
--- a/src/luarocks/fs.d.tl
+++ b/src/luarocks/fs.d.tl
@@ -49,6 +49,8 @@ local record fs
49 check_md5: function(string, string): boolean, string 49 check_md5: function(string, string): boolean, string
50 -- git 50 -- git
51 command_at: function(string, string, ?boolean): string 51 command_at: function(string, string, ?boolean): string
52 -- repos
53 is_actual_binary: function(string): boolean
52end 54end
53 55
54return fs 56return fs
diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua
index 437ebe3b..754ad985 100644
--- a/src/luarocks/manif.lua
+++ b/src/luarocks/manif.lua
@@ -72,7 +72,7 @@ function manif.load_rock_manifest(name, version, root)
72 72
73 local name_version = name .. "/" .. version 73 local name_version = name .. "/" .. version
74 if manif.rock_manifest_cache[name_version] then 74 if manif.rock_manifest_cache[name_version] then
75 return manif.rock_manifest_cache[name_version].rock_manifest 75 return manif.rock_manifest_cache[name_version].entries
76 end 76 end
77 local pathname = path.rock_manifest_file(name, version, root) 77 local pathname = path.rock_manifest_file(name, version, root)
78 local rock_manifest = persist.load_into_table(pathname) 78 local rock_manifest = persist.load_into_table(pathname)
@@ -80,7 +80,7 @@ function manif.load_rock_manifest(name, version, root)
80 return nil, "rock_manifest file not found for " .. name .. " " .. version .. " - not a LuaRocks tree?" 80 return nil, "rock_manifest file not found for " .. name .. " " .. version .. " - not a LuaRocks tree?"
81 end 81 end
82 manif.rock_manifest_cache[name_version] = rock_manifest 82 manif.rock_manifest_cache[name_version] = rock_manifest
83 return rock_manifest.rock_manifest 83 return rock_manifest.entries
84end 84end
85 85
86 86
diff --git a/src/luarocks/manif.tl b/src/luarocks/manif.tl
index 7a003021..13c48aa8 100644
--- a/src/luarocks/manif.tl
+++ b/src/luarocks/manif.tl
@@ -72,7 +72,7 @@ function manif.load_rock_manifest(name: string, version: string, root?: string |
72 72
73 local name_version = name.."/"..version 73 local name_version = name.."/"..version
74 if manif.rock_manifest_cache[name_version] then 74 if manif.rock_manifest_cache[name_version] then
75 return manif.rock_manifest_cache[name_version].rock_manifest 75 return manif.rock_manifest_cache[name_version].entries
76 end 76 end
77 local pathname = path.rock_manifest_file(name, version, root) 77 local pathname = path.rock_manifest_file(name, version, root)
78 local rock_manifest = persist.load_into_table(pathname) as RockManifest 78 local rock_manifest = persist.load_into_table(pathname) as RockManifest
@@ -80,7 +80,7 @@ function manif.load_rock_manifest(name: string, version: string, root?: string |
80 return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks tree?" 80 return nil, "rock_manifest file not found for "..name.." "..version.." - not a LuaRocks tree?"
81 end 81 end
82 manif.rock_manifest_cache[name_version] = rock_manifest 82 manif.rock_manifest_cache[name_version] = rock_manifest
83 return rock_manifest.rock_manifest 83 return rock_manifest.entries
84end 84end
85 85
86--- Load a local or remote manifest describing a repository. 86--- Load a local or remote manifest describing a repository.
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 65c1a7d2..5a77cf68 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -10,6 +10,7 @@ local util = require("luarocks.core.util")
10 10
11 11
12 12
13
13local path = {} 14local path = {}
14 15
15 16
diff --git a/src/luarocks/path.tl b/src/luarocks/path.tl
index 1a19fe16..a75d7b83 100644
--- a/src/luarocks/path.tl
+++ b/src/luarocks/path.tl
@@ -62,7 +62,7 @@ end
62-- @return string: The resulting path -- does not guarantee that 62-- @return string: The resulting path -- does not guarantee that
63-- @param tree string or nil: If given, specifies the local tree to use. 63-- @param tree string or nil: If given, specifies the local tree to use.
64-- the package (and by extension, the path) exists. 64-- the package (and by extension, the path) exists.
65function path.versions_dir(name: string, tree: string | Tree): string 65function path.versions_dir(name: string, tree?: string | Tree): string
66 assert(not name:match("/")) 66 assert(not name:match("/"))
67 return dir.path(path.rocks_dir(tree), name) 67 return dir.path(path.rocks_dir(tree), name)
68end 68end
diff --git a/src/luarocks/repos.tl b/src/luarocks/repos.tl
index 3bfd5849..e6044b81 100644
--- a/src/luarocks/repos.tl
+++ b/src/luarocks/repos.tl
@@ -11,6 +11,13 @@ local dir = require("luarocks.dir")
11local manif = require("luarocks.manif") 11local manif = require("luarocks.manif")
12local vers = require("luarocks.core.vers") 12local vers = require("luarocks.core.vers")
13 13
14local type rm = require("luarocks.core.types.rockmanifest")
15local type RockManifest = rm.RockManifest
16local type Entry = RockManifest.Entry
17
18local type r = require("luarocks.core.types.rockspec")
19local type Rockspec = r.Rockspec
20
14-- Tree of files installed by a package are stored 21-- Tree of files installed by a package are stored
15-- in its rock manifest. Some of these files have to 22-- in its rock manifest. Some of these files have to
16-- be deployed to locations where Lua can load them as 23-- be deployed to locations where Lua can load them as
@@ -51,20 +58,20 @@ function repos.is_installed(name: string, version: string): boolean
51 return fs.is_dir(path.install_dir(name, version)) 58 return fs.is_dir(path.install_dir(name, version))
52end 59end
53 60
54function repos.recurse_rock_manifest_entry(entry, action): boolean, string 61function repos.recurse_rock_manifest_entry(entry: Entry, action: (function(string): boolean, string)): boolean, string
55 assert(type(action) == "function") 62 assert(type(action) == "function")
56 63
57 if entry == nil then 64 if entry == nil then
58 return true 65 return true
59 end 66 end
60 67
61 local function do_recurse_rock_manifest_entry(tree, parent_path) 68 local function do_recurse_rock_manifest_entry(tree: Entry, parent_path?: string): boolean, string
62 69
63 for file, sub in pairs(tree) do 70 for file, sub in pairs(tree as {string: any}) do --!
64 local sub_path = (parent_path and (parent_path .. "/") or "") .. file 71 local sub_path = (parent_path and (parent_path .. "/") or "") .. file
65 local ok, err -- luacheck: ignore 231 72 local ok, err: boolean, string -- luacheck: ignore 231
66 73
67 if type(sub) == "table" then 74 if sub is Entry then
68 ok, err = do_recurse_rock_manifest_entry(sub, sub_path) 75 ok, err = do_recurse_rock_manifest_entry(sub, sub_path)
69 else 76 else
70 ok, err = action(sub_path) 77 ok, err = action(sub_path)
@@ -77,9 +84,9 @@ function repos.recurse_rock_manifest_entry(entry, action): boolean, string
77 return do_recurse_rock_manifest_entry(entry) 84 return do_recurse_rock_manifest_entry(entry)
78end 85end
79 86
80local function store_package_data(result, rock_manifest, deploy_type) 87local function store_package_data(result: {string: string}, rock_manifest: {string : Entry}, deploy_type: string)
81 if rock_manifest[deploy_type] then 88 if rock_manifest[deploy_type] then
82 repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path) 89 repos.recurse_rock_manifest_entry(rock_manifest[deploy_type], function(file_path: string): boolean, string
83 local _, item_name = manif.get_provided_item(deploy_type, file_path) 90 local _, item_name = manif.get_provided_item(deploy_type, file_path)
84 result[item_name] = file_path 91 result[item_name] = file_path
85 return true 92 return true
@@ -96,9 +103,8 @@ end
96-- relative to "lib" or "lua" rock manifest subtree. 103-- relative to "lib" or "lua" rock manifest subtree.
97-- If no modules are found or if package name or version 104-- If no modules are found or if package name or version
98-- are invalid, an empty table is returned. 105-- are invalid, an empty table is returned.
99function repos.package_modules(name, version) 106function repos.package_modules(name: string, version: string): {string: string}
100 assert(type(name) == "string" and not name:match("/")) 107 assert(not name:match("/"))
101 assert(type(version) == "string")
102 108
103 local result = {} 109 local result = {}
104 local rock_manifest = manif.load_rock_manifest(name, version) 110 local rock_manifest = manif.load_rock_manifest(name, version)
@@ -117,9 +123,8 @@ end
117-- relative to "bin" rock manifest subtree. 123-- relative to "bin" rock manifest subtree.
118-- If no commands are found or if package name or version 124-- If no commands are found or if package name or version
119-- are invalid, an empty table is returned. 125-- are invalid, an empty table is returned.
120function repos.package_commands(name, version) 126function repos.package_commands(name: string, version: string): {string: string}
121 assert(type(name) == "string" and not name:match("/")) 127 assert(not name:match("/"))
122 assert(type(version) == "string")
123 128
124 local result = {} 129 local result = {}
125 local rock_manifest = manif.load_rock_manifest(name, version) 130 local rock_manifest = manif.load_rock_manifest(name, version)
@@ -134,13 +139,16 @@ end
134-- @param version string: version of an installed rock 139-- @param version string: version of an installed rock
135-- @return boolean: returns true if rock contains platform-specific 140-- @return boolean: returns true if rock contains platform-specific
136-- binary executables, or false if it is a pure-Lua rock. 141-- binary executables, or false if it is a pure-Lua rock.
137function repos.has_binaries(name, version) 142function repos.has_binaries(name: string, version: string): boolean
138 assert(type(name) == "string" and not name:match("/")) 143 assert(not name:match("/"))
139 assert(type(version) == "string")
140 144
141 local rock_manifest = manif.load_rock_manifest(name, version) 145 local entries = manif.load_rock_manifest(name, version)
142 if rock_manifest and rock_manifest.bin then 146 if not entries then
143 for bin_name, md5 in pairs(rock_manifest.bin) do 147 return false
148 end
149 local bin = entries["bin"]
150 if bin is {string:Entry} then
151 for bin_name, md5 in pairs(bin) do
144 -- TODO verify that it is the same file. If it isn't, find the actual command. 152 -- TODO verify that it is the same file. If it isn't, find the actual command.
145 if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, bin_name)) then 153 if fs.is_actual_binary(dir.path(cfg.deploy_bin_dir, bin_name)) then
146 return true 154 return true
@@ -150,9 +158,7 @@ function repos.has_binaries(name, version)
150 return false 158 return false
151end 159end
152 160
153function repos.run_hook(rockspec, hook_name) 161function repos.run_hook(rockspec: Rockspec, hook_name: string): boolean, string
154 assert(rockspec:type() == "rockspec")
155 assert(type(hook_name) == "string")
156 162
157 local hooks = rockspec.hooks 163 local hooks = rockspec.hooks
158 if not hooks then 164 if not hooks then
@@ -164,10 +170,10 @@ function repos.run_hook(rockspec, hook_name)
164 end 170 end
165 171
166 if not hooks.substituted_variables then 172 if not hooks.substituted_variables then
167 util.variable_substitutions(hooks, rockspec.variables) 173 util.variable_substitutions(hooks as {string: string}, rockspec.variables)
168 hooks.substituted_variables = true 174 hooks.substituted_variables = true
169 end 175 end
170 local hook = hooks[hook_name] 176 local hook = (hooks as {string: string})[hook_name]
171 if hook then 177 if hook then
172 util.printout(hook) 178 util.printout(hook)
173 if not fs.execute(hook) then 179 if not fs.execute(hook) then
@@ -177,8 +183,7 @@ function repos.run_hook(rockspec, hook_name)
177 return true 183 return true
178end 184end
179 185
180function repos.should_wrap_bin_scripts(rockspec) 186function repos.should_wrap_bin_scripts(rockspec: Rockspec): boolean
181 assert(rockspec:type() == "rockspec")
182 187
183 if cfg.wrap_bin_scripts ~= nil then 188 if cfg.wrap_bin_scripts ~= nil then
184 return cfg.wrap_bin_scripts 189 return cfg.wrap_bin_scripts
@@ -189,7 +194,7 @@ function repos.should_wrap_bin_scripts(rockspec)
189 return true 194 return true
190end 195end
191 196
192local function find_suffixed(file, suffix) 197local function find_suffixed(file: string, suffix: string)
193 local filenames = {file} 198 local filenames = {file}
194 if suffix and suffix ~= "" then 199 if suffix and suffix ~= "" then
195 table.insert(filenames, 1, file .. suffix) 200 table.insert(filenames, 1, file .. suffix)
diff --git a/src/luarocks/test/busted.tl b/src/luarocks/test/busted.tl
index a3f80644..c0ac5503 100644
--- a/src/luarocks/test/busted.tl
+++ b/src/luarocks/test/busted.tl
@@ -18,7 +18,7 @@ function busted.detect_type(): boolean
18 return false 18 return false
19end 19end
20 20
21function busted.run_tests(test: Test, args: {string}): boolean, string --! Test type 21function busted.run_tests(test: Test, args: {string}): boolean, string
22 if not test then 22 if not test then
23 test = {} 23 test = {}
24 end 24 end
diff --git a/src/luarocks/test/command.tl b/src/luarocks/test/command.tl
index 1369cba4..843367b2 100644
--- a/src/luarocks/test/command.tl
+++ b/src/luarocks/test/command.tl
@@ -15,7 +15,7 @@ function command.detect_type(): boolean
15 return false 15 return false
16end 16end
17 17
18function command.run_tests(test: Test, args: {string}): boolean, string --! Test type 18function command.run_tests(test: Test, args: {string}): boolean, string
19 if not test then 19 if not test then
20 test = { 20 test = {
21 script = "test.lua" 21 script = "test.lua"