aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-15 00:23:01 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:49:17 +0300
commit949c0e66a12d4f9d6ad9df560647b41329d9a5f7 (patch)
tree83c6f1cf1fb3376791adf7a17f6247c90eefa521
parent568a5ea1ad0ed1612a92203cb3dd10ff0265c04c (diff)
downloadluarocks-949c0e66a12d4f9d6ad9df560647b41329d9a5f7.tar.gz
luarocks-949c0e66a12d4f9d6ad9df560647b41329d9a5f7.tar.bz2
luarocks-949c0e66a12d4f9d6ad9df560647b41329d9a5f7.zip
converted path and added to fs and cfg
-rw-r--r--src/luarocks/core/cfg.d.tl5
-rw-r--r--src/luarocks/core/path.tl1
-rw-r--r--src/luarocks/fs.d.tl6
-rw-r--r--src/luarocks/path-original.lua (renamed from src/luarocks/path.lua)0
-rw-r--r--src/luarocks/path.tl255
-rw-r--r--src/luarocks/util.tl53
6 files changed, 312 insertions, 8 deletions
diff --git a/src/luarocks/core/cfg.d.tl b/src/luarocks/core/cfg.d.tl
index a741baaa..68d110c3 100644
--- a/src/luarocks/core/cfg.d.tl
+++ b/src/luarocks/core/cfg.d.tl
@@ -4,12 +4,17 @@ local record cfg
4 make_defaults: function(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any} 4 make_defaults: function(lua_version: string, target_cpu: string, platforms: {any: any}, home: string): {any: any}
5 use_defaults: function(cfg, defaults: {any: any}) 5 use_defaults: function(cfg, defaults: {any: any})
6 root_dir: string | Tree 6 root_dir: string | Tree
7 rocks_dir: string
7 rocks_subdir: string 8 rocks_subdir: string
8 lua_modules_path: string 9 lua_modules_path: string
9 lib_modules_path: string 10 lib_modules_path: string
10 rocks_trees: {string| Tree} 11 rocks_trees: {string| Tree}
11 lua_version: string 12 lua_version: string
12 deps_mode: string 13 deps_mode: string
14 deploy_bin_dir: string
15 deploy_lua_dir: string
16 deploy_lib_dir: string
17 lib_extension: string
13 record Tree 18 record Tree
14 root: string 19 root: string
15 rocks_dir: string 20 rocks_dir: string
diff --git a/src/luarocks/core/path.tl b/src/luarocks/core/path.tl
index e1bdc8de..213c0d69 100644
--- a/src/luarocks/core/path.tl
+++ b/src/luarocks/core/path.tl
@@ -1,4 +1,3 @@
1
2--- Core LuaRocks-specific path handling functions. 1--- Core LuaRocks-specific path handling functions.
3local record path 2local record path
4end 3end
diff --git a/src/luarocks/fs.d.tl b/src/luarocks/fs.d.tl
index b0ca56c7..6a8d7520 100644
--- a/src/luarocks/fs.d.tl
+++ b/src/luarocks/fs.d.tl
@@ -6,8 +6,10 @@ local record fs
6 change_dir_to_root: function 6 change_dir_to_root: function
7 record FsTable 7 record FsTable
8 end 8 end
9 9 -- util
10 --... 10 is_dir: function(dir: string): boolean
11 dir: function(dir: string): function(): string --? right iterator
12 is_file: function(file: string): boolean
11end 13end
12 14
13return fs 15return fs
diff --git a/src/luarocks/path.lua b/src/luarocks/path-original.lua
index 19657c83..19657c83 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path-original.lua
diff --git a/src/luarocks/path.tl b/src/luarocks/path.tl
new file mode 100644
index 00000000..93fb6aae
--- /dev/null
+++ b/src/luarocks/path.tl
@@ -0,0 +1,255 @@
1
2--- LuaRocks-specific path handling functions.
3-- All paths are configured in this module, making it a single
4-- point where the layout of the local installation is defined in LuaRocks.
5
6local cfg = require("luarocks.core.cfg")
7local core = require("luarocks.core.path")
8local dir = require("luarocks.dir")
9-- local util = require("luarocks.util") --! crashes teal
10
11local type Tree = cfg.Tree
12
13local record path
14 rocks_dir: function(string | Tree): string
15 versioned_name: function(string, string, string, string): string
16 path_to_module: function(string): string
17 deploy_lua_dir: function(string | Tree): string
18 deploy_lib_dir: function(string | Tree): string
19 map_trees: function(string, function(...: any): any..., ...: string): {any}
20 rocks_tree_to_string: function(string | Tree): string
21end
22
23path.rocks_dir = core.rocks_dir
24path.versioned_name = core.versioned_name
25path.path_to_module = core.path_to_module
26path.deploy_lua_dir = core.deploy_lua_dir
27path.deploy_lib_dir = core.deploy_lib_dir
28path.map_trees = core.map_trees
29path.rocks_tree_to_string = core.rocks_tree_to_string
30
31--- Infer rockspec filename from a rock filename.
32-- @param rock_name string: Pathname of a rock file.
33-- @return string: Filename of the rockspec, without path.
34function path.rockspec_name_from_rock(rock_name: string): string
35 local base_name = dir.base_name(rock_name)
36 return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec"
37end
38
39function path.root_from_rocks_dir(rocks_dir: string): string
40 return "" --! temp
41 -- return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") --! only depends here on util
42end
43
44function path.root_dir(tree: string | Tree): string
45 if tree is string then
46 return tree
47 else
48 return tree.root
49 end
50end
51
52function path.deploy_bin_dir(tree: string | Tree): string
53 return dir.path(path.root_dir(tree), "bin")
54end
55
56function path.manifest_file(tree: string | Tree): string
57 return dir.path(path.rocks_dir(tree), "manifest")
58end
59
60--- Get the directory for all versions of a package in a tree.
61-- @param name string: The package name.
62-- @return string: The resulting path -- does not guarantee that
63-- @param tree string or nil: If given, specifies the local tree to use.
64-- the package (and by extension, the path) exists.
65function path.versions_dir(name: string, tree: string | Tree): string
66 assert(not name:match("/"))
67 return dir.path(path.rocks_dir(tree), name)
68end
69
70--- Get the local installation directory (prefix) for a package.
71-- @param name string: The package name.
72-- @param version string: The package version.
73-- @param tree string or nil: If given, specifies the local tree to use.
74-- @return string: The resulting path -- does not guarantee that
75-- the package (and by extension, the path) exists.
76function path.install_dir(name: string, version: string, tree: string | Tree): string
77 assert(not name:match("/"))
78 return dir.path(path.rocks_dir(tree), name, version)
79end
80
81--- Get the local filename of the rockspec of an installed rock.
82-- @param name string: The package name.
83-- @param version string: The package version.
84-- @param tree string or nil: If given, specifies the local tree to use.
85-- @return string: The resulting path -- does not guarantee that
86-- the package (and by extension, the file) exists.
87function path.rockspec_file(name: string, version: string, tree: string | Tree): string
88 assert(not name:match("/"))
89 return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec")
90end
91
92--- Get the local filename of the rock_manifest file of an installed rock.
93-- @param name string: The package name.
94-- @param version string: The package version.
95-- @param tree string or nil: If given, specifies the local tree to use.
96-- @return string: The resulting path -- does not guarantee that
97-- the package (and by extension, the file) exists.
98function path.rock_manifest_file(name: string, version: string, tree: string | Tree): string
99 assert(not name:match("/"))
100 return dir.path(path.rocks_dir(tree), name, version, "rock_manifest")
101end
102
103--- Get the local filename of the rock_namespace file of an installed rock.
104-- @param name string: The package name (without a namespace).
105-- @param version string: The package version.
106-- @param tree string or nil: If given, specifies the local tree to use.
107-- @return string: The resulting path -- does not guarantee that
108-- the package (and by extension, the file) exists.
109function path.rock_namespace_file(name: string, version: string, tree: string | Tree): string
110 assert(not name:match("/"))
111 return dir.path(path.rocks_dir(tree), name, version, "rock_namespace")
112end
113
114--- Get the local installation directory for C libraries of a package.
115-- @param name string: The package name.
116-- @param version string: The package version.
117-- @param tree string or nil: If given, specifies the local tree to use.
118-- @return string: The resulting path -- does not guarantee that
119-- the package (and by extension, the path) exists.
120function path.lib_dir(name: string, version: string, tree: string | Tree): string
121 assert(not name:match("/"))
122 return dir.path(path.rocks_dir(tree), name, version, "lib")
123end
124
125--- Get the local installation directory for Lua modules of a package.
126-- @param name string: The package name.
127-- @param version string: The package version.
128-- @param tree string or nil: If given, specifies the local tree to use.
129-- @return string: The resulting path -- does not guarantee that
130-- the package (and by extension, the path) exists.
131function path.lua_dir(name: string, version: string, tree: string | Tree): string
132 assert(not name:match("/"))
133 return dir.path(path.rocks_dir(tree), name, version, "lua")
134end
135
136--- Get the local installation directory for documentation of a package.
137-- @param name string: The package name.
138-- @param version string: The package version.
139-- @param tree string or nil: If given, specifies the local tree to use.
140-- @return string: The resulting path -- does not guarantee that
141-- the package (and by extension, the path) exists.
142function path.doc_dir(name: string, version: string, tree: string | Tree): string
143 assert(not name:match("/"))
144 return dir.path(path.rocks_dir(tree), name, version, "doc")
145end
146
147--- Get the local installation directory for configuration files of a package.
148-- @param name string: The package name.
149-- @param version string: The package version.
150-- @param tree string or nil: If given, specifies the local tree to use.
151-- @return string: The resulting path -- does not guarantee that
152-- the package (and by extension, the path) exists.
153function path.conf_dir(name: string, version: string, tree: string | Tree): string
154 assert(not name:match("/"))
155 return dir.path(path.rocks_dir(tree), name, version, "conf")
156end
157
158--- Get the local installation directory for command-line scripts
159-- of a package.
160-- @param name string: The package name.
161-- @param version string: The package version.
162-- @param tree string or nil: If given, specifies the local tree to use.
163-- @return string: The resulting path -- does not guarantee that
164-- the package (and by extension, the path) exists.
165function path.bin_dir(name: string, version: string, tree: string | Tree): string
166 assert(not name:match("/"))
167 return dir.path(path.rocks_dir(tree), name, version, "bin")
168end
169
170--- Extract name, version and arch of a rock filename,
171-- or name, version and "rockspec" from a rockspec name.
172-- @param file_name string: pathname of a rock or rockspec
173-- @return (string, string, string) or nil: name, version and arch
174-- or nil if name could not be parsed
175function path.parse_name(file_name: string): string
176 if file_name:match("%.rock$") then
177 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$")
178 else
179 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.(rockspec)")
180 end
181end
182
183--- Make a rockspec or rock URL.
184-- @param pathname string: Base URL or pathname.
185-- @param name string: Package name.
186-- @param version string: Package version.
187-- @param arch string: Architecture identifier, or "rockspec" or "installed".
188-- @return string: A URL or pathname following LuaRocks naming conventions.
189function path.make_url(pathname: string, name: string, version: string, arch: string): string
190 assert(not name:match("/"))
191 local filename = name.."-"..version
192 if arch == "installed" then
193 filename = dir.path(name, version, filename..".rockspec")
194 elseif arch == "rockspec" then
195 filename = filename..".rockspec"
196 else
197 filename = filename.."."..arch..".rock"
198 end
199 return dir.path(pathname, filename)
200end
201
202--- Obtain the directory name where a module should be stored.
203-- For example, on Unix, "foo.bar.baz" will return "foo/bar".
204-- @param mod string: A module name in Lua dot-separated format.
205-- @return string: A directory name using the platform's separator.
206function path.module_to_path(mod: string): string
207 return (mod:gsub("[^.]*$", ""):gsub("%.", "/"))
208end
209
210function path.use_tree(tree: Tree)
211 cfg.root_dir = tree
212 cfg.rocks_dir = path.rocks_dir(tree)
213 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
214 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
215 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
216end
217
218function path.add_to_package_paths(tree: string | Tree)
219 package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";"
220 .. dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";"
221 .. package.path
222 package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";"
223 .. package.cpath
224end
225
226--- Get the namespace of a locally-installed rock, if any.
227-- @param name string: The rock name, without a namespace.
228-- @param version string: The rock version.
229-- @param tree string: The local tree to use.
230-- @return string?: The namespace if it exists, or nil.
231function path.read_namespace(name: string, version: string, tree: string | Tree): string
232 assert(not name:match("/"))
233
234 local namespace: string
235 local fd = io.open(path.rock_namespace_file(name, version, tree), "r")
236 if fd then
237 namespace = fd:read("*a")
238 fd:close()
239 end
240 return namespace
241end
242
243function path.package_paths(deps_mode: string): string, string
244 local lpaths = {}
245 local lcpaths = {}
246 path.map_trees(deps_mode, function(tree: string | Tree)
247 local root = path.root_dir(tree)
248 table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?.lua"))
249 table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?/init.lua"))
250 table.insert(lcpaths, dir.path(root, cfg.lib_modules_path, "?." .. cfg.lib_extension))
251 end)
252 return table.concat(lpaths, ";"), table.concat(lcpaths, ";")
253end
254
255return path
diff --git a/src/luarocks/util.tl b/src/luarocks/util.tl
index a8233f31..a9fc8394 100644
--- a/src/luarocks/util.tl
+++ b/src/luarocks/util.tl
@@ -25,14 +25,57 @@ local record util
25 args: {any: any} 25 args: {any: any}
26 end 26 end
27 27
28 record Rockspec 28 record Source
29 name: string 29 url: string
30 version: string --? 30 end
31
32 record Description
33 summary: string
34 detailed: string
35 homepage: string
36 issues_url: string
37 maintainer: string
38 license: string
39 end
40
41 record Test
42 type: string
43 platforms: {{string: any}}
44 end
45
46 record Rockspec -- luarocks-dev-1.rockspec
47 rockspec_format: string
48 name: string --? package
49 version: string
50 source: {Source}
51 description: Description
52 test_dependencies: {string}
53 test: Test
54 end
55
56 record Parser --?
57 option: function(Parser, ...: string): Parser
58 argname: function(Parser, string): Parser
59 choices: function(Parser, {string}): Parser
60 flag: function(Parser, string): Parser
61 hidden: function(Parser, boolean): Parser
31 end 62 end
32end 63end
33 64
65util.cleanup_path = core.cleanup_path
66util.split_string = core.split_string
67util.sortedpairs = core.sortedpairs
68util.deep_merge = core.deep_merge
69util.deep_merge_under = core.deep_merge_under
70util.popen_read = core.popen_read
71util.show_table = core.show_table
72util.printerr = core.printerr
73util.warning = core.warning
74util.keys = core.keys
75
34local type Fn = util.Fn 76local type Fn = util.Fn
35local type Rockspec = util.Rockspec 77local type Rockspec = util.Rockspec
78local type Parser = util.Parser
36 79
37local scheduled_functions: {Fn} = {} --? infered from line 48-51 80local scheduled_functions: {Fn} = {} --? infered from line 48-51
38 81
@@ -229,7 +272,7 @@ function util.format_rock_name(name: string, namespace: string, version: string)
229 return (namespace and namespace.."/" or "")..name..(version and " "..version or "") 272 return (namespace and namespace.."/" or "")..name..(version and " "..version or "")
230end 273end
231 274
232function util.deps_mode_option(parser: {string: any}, program: string) --? type of parser 275function util.deps_mode_option(parser: Parser, program: string)
233 local cfg = require("luarocks.core.cfg") 276 local cfg = require("luarocks.core.cfg")
234 277
235 parser:option("--deps-mode", "How to handle dependencies. Four modes are supported:\n".. 278 parser:option("--deps-mode", "How to handle dependencies. Four modes are supported:\n"..
@@ -286,7 +329,7 @@ local function collect_rockspecs(versions: {string: vers.Version}, paths: {strin
286 329
287 if fs.is_dir(subdir) then 330 if fs.is_dir(subdir) then
288 for file in fs.dir(subdir) do 331 for file in fs.dir(subdir) do
289 file = dir.path(subdir, file) -- path: function(...: string): string 332 file = dir.path(subdir, file)
290 333
291 if file:match("rockspec$") and fs.is_file(file) then 334 if file:match("rockspec$") and fs.is_file(file) then
292 local rock, version = path.parse_name(file) 335 local rock, version = path.parse_name(file)