aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorV1K1NGbg <victor@ilchev.com>2024-07-30 12:07:11 +0300
committerV1K1NGbg <victor@ilchev.com>2024-08-05 20:51:31 +0300
commit7a42b3bc6709000c4809a3ca4ec9fbaed2c3f0a8 (patch)
treee56d931ad6b0a9b4dc2f89519edada5b36e7b3df
parentb026e7250ff05b675cafd92cefb1a2f640b16bc1 (diff)
downloadluarocks-7a42b3bc6709000c4809a3ca4ec9fbaed2c3f0a8.tar.gz
luarocks-7a42b3bc6709000c4809a3ca4ec9fbaed2c3f0a8.tar.bz2
luarocks-7a42b3bc6709000c4809a3ca4ec9fbaed2c3f0a8.zip
test path
-rw-r--r--src/luarocks/path-incomplete.lua254
-rw-r--r--src/luarocks/path-original.lua263
-rw-r--r--src/luarocks/path.lua269
3 files changed, 393 insertions, 393 deletions
diff --git a/src/luarocks/path-incomplete.lua b/src/luarocks/path-incomplete.lua
deleted file mode 100644
index 65c1a7d2..00000000
--- a/src/luarocks/path-incomplete.lua
+++ /dev/null
@@ -1,254 +0,0 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local package = _tl_compat and _tl_compat.package or package; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table
2
3
4
5
6local cfg = require("luarocks.core.cfg")
7local core = require("luarocks.core.path")
8local dir = require("luarocks.dir")
9local util = require("luarocks.core.util")
10
11
12
13local path = {}
14
15
16
17
18
19
20
21
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
31function path.root_dir(tree)
32 if type(tree) == "string" then
33 return tree
34 else
35 return tree.root
36 end
37end
38
39
40
41
42function path.rockspec_name_from_rock(rock_name)
43 local base_name = dir.base_name(rock_name)
44 return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec"
45end
46
47function path.root_from_rocks_dir(rocks_dir)
48 return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$")
49end
50
51function path.deploy_bin_dir(tree)
52 return dir.path(path.root_dir(tree), "bin")
53end
54
55function path.manifest_file(tree)
56 return dir.path(path.rocks_dir(tree), "manifest")
57end
58
59
60
61
62
63
64function path.versions_dir(name, tree)
65 assert(not name:match("/"))
66 return dir.path(path.rocks_dir(tree), name)
67end
68
69
70
71
72
73
74
75function path.install_dir(name, version, tree)
76 assert(not name:match("/"))
77 return dir.path(path.rocks_dir(tree), name, version)
78end
79
80
81
82
83
84
85
86function path.rockspec_file(name, version, tree)
87 assert(not name:match("/"))
88 return dir.path(path.rocks_dir(tree), name, version, name .. "-" .. version .. ".rockspec")
89end
90
91
92
93
94
95
96
97function path.rock_manifest_file(name, version, tree)
98 assert(not name:match("/"))
99 return dir.path(path.rocks_dir(tree), name, version, "rock_manifest")
100end
101
102
103
104
105
106
107
108function path.rock_namespace_file(name, version, tree)
109 assert(not name:match("/"))
110 return dir.path(path.rocks_dir(tree), name, version, "rock_namespace")
111end
112
113
114
115
116
117
118
119function path.lib_dir(name, version, tree)
120 assert(not name:match("/"))
121 return dir.path(path.rocks_dir(tree), name, version, "lib")
122end
123
124
125
126
127
128
129
130function path.lua_dir(name, version, tree)
131 assert(not name:match("/"))
132 return dir.path(path.rocks_dir(tree), name, version, "lua")
133end
134
135
136
137
138
139
140
141function path.doc_dir(name, version, tree)
142 assert(not name:match("/"))
143 return dir.path(path.rocks_dir(tree), name, version, "doc")
144end
145
146
147
148
149
150
151
152function path.conf_dir(name, version, tree)
153 assert(not name:match("/"))
154 return dir.path(path.rocks_dir(tree), name, version, "conf")
155end
156
157
158
159
160
161
162
163
164function path.bin_dir(name, version, tree)
165 assert(not name:match("/"))
166 return dir.path(path.rocks_dir(tree), name, version, "bin")
167end
168
169
170
171
172
173
174function path.parse_name(file_name)
175 if file_name:match("%.rock$") then
176 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$")
177 else
178 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.(rockspec)")
179 end
180end
181
182
183
184
185
186
187
188function path.make_url(pathname, name, version, arch)
189 assert(not name:match("/"))
190 local filename = name .. "-" .. version
191 if arch == "installed" then
192 filename = dir.path(name, version, filename .. ".rockspec")
193 elseif arch == "rockspec" then
194 filename = filename .. ".rockspec"
195 else
196 filename = filename .. "." .. arch .. ".rock"
197 end
198 return dir.path(pathname, filename)
199end
200
201
202
203
204
205function path.module_to_path(mod)
206 return (mod:gsub("[^.]*$", ""):gsub("%.", "/"))
207end
208
209function path.use_tree(tree)
210 cfg.root_dir = tree
211 cfg.rocks_dir = path.rocks_dir(tree)
212 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
213 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
214 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
215end
216
217function path.add_to_package_paths(tree)
218 package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";" ..
219 dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";" ..
220 package.path
221 package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";" ..
222 package.cpath
223end
224
225
226
227
228
229
230function path.read_namespace(name, version, tree)
231 assert(not name:match("/"))
232
233 local namespace
234 local fd = io.open(path.rock_namespace_file(name, version, tree), "r")
235 if fd then
236 namespace = fd:read("*a")
237 fd:close()
238 end
239 return namespace
240end
241
242function path.package_paths(deps_mode)
243 local lpaths = {}
244 local lcpaths = {}
245 path.map_trees(deps_mode, function(tree)
246 local root = path.root_dir(tree)
247 table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?.lua"))
248 table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?/init.lua"))
249 table.insert(lcpaths, dir.path(root, cfg.lib_modules_path, "?." .. cfg.lib_extension))
250 end)
251 return table.concat(lpaths, ";"), table.concat(lcpaths, ";")
252end
253
254return path
diff --git a/src/luarocks/path-original.lua b/src/luarocks/path-original.lua
new file mode 100644
index 00000000..19657c83
--- /dev/null
+++ b/src/luarocks/path-original.lua
@@ -0,0 +1,263 @@
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.
5local path = {}
6
7local core = require("luarocks.core.path")
8local dir = require("luarocks.dir")
9local cfg = require("luarocks.core.cfg")
10local util = require("luarocks.util")
11
12path.rocks_dir = core.rocks_dir
13path.versioned_name = core.versioned_name
14path.path_to_module = core.path_to_module
15path.deploy_lua_dir = core.deploy_lua_dir
16path.deploy_lib_dir = core.deploy_lib_dir
17path.map_trees = core.map_trees
18path.rocks_tree_to_string = core.rocks_tree_to_string
19
20--- Infer rockspec filename from a rock filename.
21-- @param rock_name string: Pathname of a rock file.
22-- @return string: Filename of the rockspec, without path.
23function path.rockspec_name_from_rock(rock_name)
24 assert(type(rock_name) == "string")
25 local base_name = dir.base_name(rock_name)
26 return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec"
27end
28
29function path.root_from_rocks_dir(rocks_dir)
30 assert(type(rocks_dir) == "string")
31 return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$")
32end
33
34function path.root_dir(tree)
35 if type(tree) == "string" then
36 return tree
37 else
38 assert(type(tree) == "table")
39 return tree.root
40 end
41end
42
43function path.deploy_bin_dir(tree)
44 return dir.path(path.root_dir(tree), "bin")
45end
46
47function path.manifest_file(tree)
48 return dir.path(path.rocks_dir(tree), "manifest")
49end
50
51--- Get the directory for all versions of a package in a tree.
52-- @param name string: The package name.
53-- @return string: The resulting path -- does not guarantee that
54-- @param tree string or nil: If given, specifies the local tree to use.
55-- the package (and by extension, the path) exists.
56function path.versions_dir(name, tree)
57 assert(type(name) == "string" and not name:match("/"))
58 return dir.path(path.rocks_dir(tree), name)
59end
60
61--- Get the local installation directory (prefix) for a package.
62-- @param name string: The package name.
63-- @param version string: The package version.
64-- @param tree string or nil: If given, specifies the local tree to use.
65-- @return string: The resulting path -- does not guarantee that
66-- the package (and by extension, the path) exists.
67function path.install_dir(name, version, tree)
68 assert(type(name) == "string" and not name:match("/"))
69 assert(type(version) == "string")
70 return dir.path(path.rocks_dir(tree), name, version)
71end
72
73--- Get the local filename of the rockspec of an installed rock.
74-- @param name string: The package name.
75-- @param version string: The package version.
76-- @param tree string or nil: If given, specifies the local tree to use.
77-- @return string: The resulting path -- does not guarantee that
78-- the package (and by extension, the file) exists.
79function path.rockspec_file(name, version, tree)
80 assert(type(name) == "string" and not name:match("/"))
81 assert(type(version) == "string")
82 return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec")
83end
84
85--- Get the local filename of the rock_manifest file of an installed rock.
86-- @param name string: The package name.
87-- @param version string: The package version.
88-- @param tree string or nil: If given, specifies the local tree to use.
89-- @return string: The resulting path -- does not guarantee that
90-- the package (and by extension, the file) exists.
91function path.rock_manifest_file(name, version, tree)
92 assert(type(name) == "string" and not name:match("/"))
93 assert(type(version) == "string")
94 return dir.path(path.rocks_dir(tree), name, version, "rock_manifest")
95end
96
97--- Get the local filename of the rock_namespace file of an installed rock.
98-- @param name string: The package name (without a namespace).
99-- @param version string: The package version.
100-- @param tree string or nil: If given, specifies the local tree to use.
101-- @return string: The resulting path -- does not guarantee that
102-- the package (and by extension, the file) exists.
103function path.rock_namespace_file(name, version, tree)
104 assert(type(name) == "string" and not name:match("/"))
105 assert(type(version) == "string")
106 return dir.path(path.rocks_dir(tree), name, version, "rock_namespace")
107end
108
109--- Get the local installation directory for C libraries of a package.
110-- @param name string: The package name.
111-- @param version string: The package version.
112-- @param tree string or nil: If given, specifies the local tree to use.
113-- @return string: The resulting path -- does not guarantee that
114-- the package (and by extension, the path) exists.
115function path.lib_dir(name, version, tree)
116 assert(type(name) == "string" and not name:match("/"))
117 assert(type(version) == "string")
118 return dir.path(path.rocks_dir(tree), name, version, "lib")
119end
120
121--- Get the local installation directory for Lua modules of a package.
122-- @param name string: The package name.
123-- @param version string: The package version.
124-- @param tree string or nil: If given, specifies the local tree to use.
125-- @return string: The resulting path -- does not guarantee that
126-- the package (and by extension, the path) exists.
127function path.lua_dir(name, version, tree)
128 assert(type(name) == "string" and not name:match("/"))
129 assert(type(version) == "string")
130 return dir.path(path.rocks_dir(tree), name, version, "lua")
131end
132
133--- Get the local installation directory for documentation of a package.
134-- @param name string: The package name.
135-- @param version string: The package version.
136-- @param tree string or nil: If given, specifies the local tree to use.
137-- @return string: The resulting path -- does not guarantee that
138-- the package (and by extension, the path) exists.
139function path.doc_dir(name, version, tree)
140 assert(type(name) == "string" and not name:match("/"))
141 assert(type(version) == "string")
142 return dir.path(path.rocks_dir(tree), name, version, "doc")
143end
144
145--- Get the local installation directory for configuration files of a package.
146-- @param name string: The package name.
147-- @param version string: The package version.
148-- @param tree string or nil: If given, specifies the local tree to use.
149-- @return string: The resulting path -- does not guarantee that
150-- the package (and by extension, the path) exists.
151function path.conf_dir(name, version, tree)
152 assert(type(name) == "string" and not name:match("/"))
153 assert(type(version) == "string")
154 return dir.path(path.rocks_dir(tree), name, version, "conf")
155end
156
157--- Get the local installation directory for command-line scripts
158-- of a package.
159-- @param name string: The package name.
160-- @param version string: The package version.
161-- @param tree string or nil: If given, specifies the local tree to use.
162-- @return string: The resulting path -- does not guarantee that
163-- the package (and by extension, the path) exists.
164function path.bin_dir(name, version, tree)
165 assert(type(name) == "string" and not name:match("/"))
166 assert(type(version) == "string")
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)
176 assert(type(file_name) == "string")
177 if file_name:match("%.rock$") then
178 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$")
179 else
180 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.(rockspec)")
181 end
182end
183
184--- Make a rockspec or rock URL.
185-- @param pathname string: Base URL or pathname.
186-- @param name string: Package name.
187-- @param version string: Package version.
188-- @param arch string: Architecture identifier, or "rockspec" or "installed".
189-- @return string: A URL or pathname following LuaRocks naming conventions.
190function path.make_url(pathname, name, version, arch)
191 assert(type(pathname) == "string")
192 assert(type(name) == "string" and not name:match("/"))
193 assert(type(version) == "string")
194 assert(type(arch) == "string")
195
196 local filename = name.."-"..version
197 if arch == "installed" then
198 filename = dir.path(name, version, filename..".rockspec")
199 elseif arch == "rockspec" then
200 filename = filename..".rockspec"
201 else
202 filename = filename.."."..arch..".rock"
203 end
204 return dir.path(pathname, filename)
205end
206
207--- Obtain the directory name where a module should be stored.
208-- For example, on Unix, "foo.bar.baz" will return "foo/bar".
209-- @param mod string: A module name in Lua dot-separated format.
210-- @return string: A directory name using the platform's separator.
211function path.module_to_path(mod)
212 assert(type(mod) == "string")
213 return (mod:gsub("[^.]*$", ""):gsub("%.", "/"))
214end
215
216function path.use_tree(tree)
217 cfg.root_dir = tree
218 cfg.rocks_dir = path.rocks_dir(tree)
219 cfg.deploy_bin_dir = path.deploy_bin_dir(tree)
220 cfg.deploy_lua_dir = path.deploy_lua_dir(tree)
221 cfg.deploy_lib_dir = path.deploy_lib_dir(tree)
222end
223
224function path.add_to_package_paths(tree)
225 package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";"
226 .. dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";"
227 .. package.path
228 package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";"
229 .. package.cpath
230end
231
232--- Get the namespace of a locally-installed rock, if any.
233-- @param name string: The rock name, without a namespace.
234-- @param version string: The rock version.
235-- @param tree string: The local tree to use.
236-- @return string?: The namespace if it exists, or nil.
237function path.read_namespace(name, version, tree)
238 assert(type(name) == "string" and not name:match("/"))
239 assert(type(version) == "string")
240 assert(type(tree) == "string")
241
242 local namespace
243 local fd = io.open(path.rock_namespace_file(name, version, tree), "r")
244 if fd then
245 namespace = fd:read("*a")
246 fd:close()
247 end
248 return namespace
249end
250
251function path.package_paths(deps_mode)
252 local lpaths = {}
253 local lcpaths = {}
254 path.map_trees(deps_mode, function(tree)
255 local root = path.root_dir(tree)
256 table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?.lua"))
257 table.insert(lpaths, dir.path(root, cfg.lua_modules_path, "?/init.lua"))
258 table.insert(lcpaths, dir.path(root, cfg.lib_modules_path, "?." .. cfg.lib_extension))
259 end)
260 return table.concat(lpaths, ";"), table.concat(lcpaths, ";")
261end
262
263return path
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua
index 19657c83..65c1a7d2 100644
--- a/src/luarocks/path.lua
+++ b/src/luarocks/path.lua
@@ -1,13 +1,24 @@
1local _tl_compat; if (tonumber((_VERSION or ''):match('[%d.]*$')) or 0) < 5.3 then local p, m = pcall(require, 'compat53.module'); if p then _tl_compat = m end end; local assert = _tl_compat and _tl_compat.assert or assert; local io = _tl_compat and _tl_compat.io or io; local package = _tl_compat and _tl_compat.package or package; local string = _tl_compat and _tl_compat.string or string; local table = _tl_compat and _tl_compat.table or table
2
1 3
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.
5local path = {}
6 4
5
6local cfg = require("luarocks.core.cfg")
7local core = require("luarocks.core.path") 7local core = require("luarocks.core.path")
8local dir = require("luarocks.dir") 8local dir = require("luarocks.dir")
9local cfg = require("luarocks.core.cfg") 9local util = require("luarocks.core.util")
10local util = require("luarocks.util") 10
11
12
13local path = {}
14
15
16
17
18
19
20
21
11 22
12path.rocks_dir = core.rocks_dir 23path.rocks_dir = core.rocks_dir
13path.versioned_name = core.versioned_name 24path.versioned_name = core.versioned_name
@@ -17,29 +28,26 @@ path.deploy_lib_dir = core.deploy_lib_dir
17path.map_trees = core.map_trees 28path.map_trees = core.map_trees
18path.rocks_tree_to_string = core.rocks_tree_to_string 29path.rocks_tree_to_string = core.rocks_tree_to_string
19 30
20--- Infer rockspec filename from a rock filename. 31function path.root_dir(tree)
21-- @param rock_name string: Pathname of a rock file. 32 if type(tree) == "string" then
22-- @return string: Filename of the rockspec, without path. 33 return tree
34 else
35 return tree.root
36 end
37end
38
39
40
41
23function path.rockspec_name_from_rock(rock_name) 42function path.rockspec_name_from_rock(rock_name)
24 assert(type(rock_name) == "string")
25 local base_name = dir.base_name(rock_name) 43 local base_name = dir.base_name(rock_name)
26 return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec" 44 return base_name:match("(.*)%.[^.]*.rock") .. ".rockspec"
27end 45end
28 46
29function path.root_from_rocks_dir(rocks_dir) 47function path.root_from_rocks_dir(rocks_dir)
30 assert(type(rocks_dir) == "string")
31 return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$") 48 return rocks_dir:match("(.*)" .. util.matchquote(cfg.rocks_subdir) .. ".*$")
32end 49end
33 50
34function path.root_dir(tree)
35 if type(tree) == "string" then
36 return tree
37 else
38 assert(type(tree) == "table")
39 return tree.root
40 end
41end
42
43function path.deploy_bin_dir(tree) 51function path.deploy_bin_dir(tree)
44 return dir.path(path.root_dir(tree), "bin") 52 return dir.path(path.root_dir(tree), "bin")
45end 53end
@@ -48,132 +56,122 @@ function path.manifest_file(tree)
48 return dir.path(path.rocks_dir(tree), "manifest") 56 return dir.path(path.rocks_dir(tree), "manifest")
49end 57end
50 58
51--- Get the directory for all versions of a package in a tree. 59
52-- @param name string: The package name. 60
53-- @return string: The resulting path -- does not guarantee that 61
54-- @param tree string or nil: If given, specifies the local tree to use. 62
55-- the package (and by extension, the path) exists. 63
56function path.versions_dir(name, tree) 64function path.versions_dir(name, tree)
57 assert(type(name) == "string" and not name:match("/")) 65 assert(not name:match("/"))
58 return dir.path(path.rocks_dir(tree), name) 66 return dir.path(path.rocks_dir(tree), name)
59end 67end
60 68
61--- Get the local installation directory (prefix) for a package. 69
62-- @param name string: The package name. 70
63-- @param version string: The package version. 71
64-- @param tree string or nil: If given, specifies the local tree to use. 72
65-- @return string: The resulting path -- does not guarantee that 73
66-- the package (and by extension, the path) exists. 74
67function path.install_dir(name, version, tree) 75function path.install_dir(name, version, tree)
68 assert(type(name) == "string" and not name:match("/")) 76 assert(not name:match("/"))
69 assert(type(version) == "string")
70 return dir.path(path.rocks_dir(tree), name, version) 77 return dir.path(path.rocks_dir(tree), name, version)
71end 78end
72 79
73--- Get the local filename of the rockspec of an installed rock. 80
74-- @param name string: The package name. 81
75-- @param version string: The package version. 82
76-- @param tree string or nil: If given, specifies the local tree to use. 83
77-- @return string: The resulting path -- does not guarantee that 84
78-- the package (and by extension, the file) exists. 85
79function path.rockspec_file(name, version, tree) 86function path.rockspec_file(name, version, tree)
80 assert(type(name) == "string" and not name:match("/")) 87 assert(not name:match("/"))
81 assert(type(version) == "string") 88 return dir.path(path.rocks_dir(tree), name, version, name .. "-" .. version .. ".rockspec")
82 return dir.path(path.rocks_dir(tree), name, version, name.."-"..version..".rockspec")
83end 89end
84 90
85--- Get the local filename of the rock_manifest file of an installed rock. 91
86-- @param name string: The package name. 92
87-- @param version string: The package version. 93
88-- @param tree string or nil: If given, specifies the local tree to use. 94
89-- @return string: The resulting path -- does not guarantee that 95
90-- the package (and by extension, the file) exists. 96
91function path.rock_manifest_file(name, version, tree) 97function path.rock_manifest_file(name, version, tree)
92 assert(type(name) == "string" and not name:match("/")) 98 assert(not name:match("/"))
93 assert(type(version) == "string")
94 return dir.path(path.rocks_dir(tree), name, version, "rock_manifest") 99 return dir.path(path.rocks_dir(tree), name, version, "rock_manifest")
95end 100end
96 101
97--- Get the local filename of the rock_namespace file of an installed rock. 102
98-- @param name string: The package name (without a namespace). 103
99-- @param version string: The package version. 104
100-- @param tree string or nil: If given, specifies the local tree to use. 105
101-- @return string: The resulting path -- does not guarantee that 106
102-- the package (and by extension, the file) exists. 107
103function path.rock_namespace_file(name, version, tree) 108function path.rock_namespace_file(name, version, tree)
104 assert(type(name) == "string" and not name:match("/")) 109 assert(not name:match("/"))
105 assert(type(version) == "string")
106 return dir.path(path.rocks_dir(tree), name, version, "rock_namespace") 110 return dir.path(path.rocks_dir(tree), name, version, "rock_namespace")
107end 111end
108 112
109--- Get the local installation directory for C libraries of a package. 113
110-- @param name string: The package name. 114
111-- @param version string: The package version. 115
112-- @param tree string or nil: If given, specifies the local tree to use. 116
113-- @return string: The resulting path -- does not guarantee that 117
114-- the package (and by extension, the path) exists. 118
115function path.lib_dir(name, version, tree) 119function path.lib_dir(name, version, tree)
116 assert(type(name) == "string" and not name:match("/")) 120 assert(not name:match("/"))
117 assert(type(version) == "string")
118 return dir.path(path.rocks_dir(tree), name, version, "lib") 121 return dir.path(path.rocks_dir(tree), name, version, "lib")
119end 122end
120 123
121--- Get the local installation directory for Lua modules of a package. 124
122-- @param name string: The package name. 125
123-- @param version string: The package version. 126
124-- @param tree string or nil: If given, specifies the local tree to use. 127
125-- @return string: The resulting path -- does not guarantee that 128
126-- the package (and by extension, the path) exists. 129
127function path.lua_dir(name, version, tree) 130function path.lua_dir(name, version, tree)
128 assert(type(name) == "string" and not name:match("/")) 131 assert(not name:match("/"))
129 assert(type(version) == "string")
130 return dir.path(path.rocks_dir(tree), name, version, "lua") 132 return dir.path(path.rocks_dir(tree), name, version, "lua")
131end 133end
132 134
133--- Get the local installation directory for documentation of a package. 135
134-- @param name string: The package name. 136
135-- @param version string: The package version. 137
136-- @param tree string or nil: If given, specifies the local tree to use. 138
137-- @return string: The resulting path -- does not guarantee that 139
138-- the package (and by extension, the path) exists. 140
139function path.doc_dir(name, version, tree) 141function path.doc_dir(name, version, tree)
140 assert(type(name) == "string" and not name:match("/")) 142 assert(not name:match("/"))
141 assert(type(version) == "string")
142 return dir.path(path.rocks_dir(tree), name, version, "doc") 143 return dir.path(path.rocks_dir(tree), name, version, "doc")
143end 144end
144 145
145--- Get the local installation directory for configuration files of a package. 146
146-- @param name string: The package name. 147
147-- @param version string: The package version. 148
148-- @param tree string or nil: If given, specifies the local tree to use. 149
149-- @return string: The resulting path -- does not guarantee that 150
150-- the package (and by extension, the path) exists. 151
151function path.conf_dir(name, version, tree) 152function path.conf_dir(name, version, tree)
152 assert(type(name) == "string" and not name:match("/")) 153 assert(not name:match("/"))
153 assert(type(version) == "string")
154 return dir.path(path.rocks_dir(tree), name, version, "conf") 154 return dir.path(path.rocks_dir(tree), name, version, "conf")
155end 155end
156 156
157--- Get the local installation directory for command-line scripts 157
158-- of a package. 158
159-- @param name string: The package name. 159
160-- @param version string: The package version. 160
161-- @param tree string or nil: If given, specifies the local tree to use. 161
162-- @return string: The resulting path -- does not guarantee that 162
163-- the package (and by extension, the path) exists. 163
164function path.bin_dir(name, version, tree) 164function path.bin_dir(name, version, tree)
165 assert(type(name) == "string" and not name:match("/")) 165 assert(not name:match("/"))
166 assert(type(version) == "string")
167 return dir.path(path.rocks_dir(tree), name, version, "bin") 166 return dir.path(path.rocks_dir(tree), name, version, "bin")
168end 167end
169 168
170--- Extract name, version and arch of a rock filename, 169
171-- or name, version and "rockspec" from a rockspec name. 170
172-- @param file_name string: pathname of a rock or rockspec 171
173-- @return (string, string, string) or nil: name, version and arch 172
174-- or nil if name could not be parsed 173
175function path.parse_name(file_name) 174function path.parse_name(file_name)
176 assert(type(file_name) == "string")
177 if file_name:match("%.rock$") then 175 if file_name:match("%.rock$") then
178 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") 176 return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$")
179 else 177 else
@@ -181,35 +179,30 @@ function path.parse_name(file_name)
181 end 179 end
182end 180end
183 181
184--- Make a rockspec or rock URL.
185-- @param pathname string: Base URL or pathname.
186-- @param name string: Package name.
187-- @param version string: Package version.
188-- @param arch string: Architecture identifier, or "rockspec" or "installed".
189-- @return string: A URL or pathname following LuaRocks naming conventions.
190function path.make_url(pathname, name, version, arch)
191 assert(type(pathname) == "string")
192 assert(type(name) == "string" and not name:match("/"))
193 assert(type(version) == "string")
194 assert(type(arch) == "string")
195 182
196 local filename = name.."-"..version 183
184
185
186
187
188function path.make_url(pathname, name, version, arch)
189 assert(not name:match("/"))
190 local filename = name .. "-" .. version
197 if arch == "installed" then 191 if arch == "installed" then
198 filename = dir.path(name, version, filename..".rockspec") 192 filename = dir.path(name, version, filename .. ".rockspec")
199 elseif arch == "rockspec" then 193 elseif arch == "rockspec" then
200 filename = filename..".rockspec" 194 filename = filename .. ".rockspec"
201 else 195 else
202 filename = filename.."."..arch..".rock" 196 filename = filename .. "." .. arch .. ".rock"
203 end 197 end
204 return dir.path(pathname, filename) 198 return dir.path(pathname, filename)
205end 199end
206 200
207--- Obtain the directory name where a module should be stored. 201
208-- For example, on Unix, "foo.bar.baz" will return "foo/bar". 202
209-- @param mod string: A module name in Lua dot-separated format. 203
210-- @return string: A directory name using the platform's separator. 204
211function path.module_to_path(mod) 205function path.module_to_path(mod)
212 assert(type(mod) == "string")
213 return (mod:gsub("[^.]*$", ""):gsub("%.", "/")) 206 return (mod:gsub("[^.]*$", ""):gsub("%.", "/"))
214end 207end
215 208
@@ -222,22 +215,20 @@ function path.use_tree(tree)
222end 215end
223 216
224function path.add_to_package_paths(tree) 217function path.add_to_package_paths(tree)
225 package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";" 218 package.path = dir.path(path.deploy_lua_dir(tree), "?.lua") .. ";" ..
226 .. dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";" 219 dir.path(path.deploy_lua_dir(tree), "?/init.lua") .. ";" ..
227 .. package.path 220 package.path
228 package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";" 221 package.cpath = dir.path(path.deploy_lib_dir(tree), "?." .. cfg.lib_extension) .. ";" ..
229 .. package.cpath 222 package.cpath
230end 223end
231 224
232--- Get the namespace of a locally-installed rock, if any. 225
233-- @param name string: The rock name, without a namespace. 226
234-- @param version string: The rock version. 227
235-- @param tree string: The local tree to use. 228
236-- @return string?: The namespace if it exists, or nil. 229
237function path.read_namespace(name, version, tree) 230function path.read_namespace(name, version, tree)
238 assert(type(name) == "string" and not name:match("/")) 231 assert(not name:match("/"))
239 assert(type(version) == "string")
240 assert(type(tree) == "string")
241 232
242 local namespace 233 local namespace
243 local fd = io.open(path.rock_namespace_file(name, version, tree), "r") 234 local fd = io.open(path.rock_namespace_file(name, version, tree), "r")