diff options
-rw-r--r-- | rockspec | 2 | ||||
-rw-r--r-- | src/luarocks/build.lua | 91 | ||||
-rw-r--r-- | src/luarocks/cfg.lua | 2 | ||||
-rw-r--r-- | src/luarocks/command_line.lua | 18 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 3 | ||||
-rw-r--r-- | src/luarocks/install.lua | 2 | ||||
-rw-r--r-- | src/luarocks/pack.lua | 2 | ||||
-rw-r--r-- | src/luarocks/path.lua | 34 | ||||
-rw-r--r-- | src/luarocks/search.lua | 5 |
9 files changed, 92 insertions, 67 deletions
@@ -1,5 +1,5 @@ | |||
1 | package = "LuaRocks" | 1 | package = "LuaRocks" |
2 | local VER = "2.0.4.1" | 2 | local VER = "2.0.5" |
3 | local REV = "1" | 3 | local REV = "1" |
4 | version = VER.."-"..REV | 4 | version = VER.."-"..REV |
5 | 5 | ||
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 5bb3c3f7..77dd1dad 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
@@ -14,33 +14,39 @@ local manif = require("luarocks.manif") | |||
14 | local cfg = require("luarocks.cfg") | 14 | local cfg = require("luarocks.cfg") |
15 | 15 | ||
16 | help_summary = "Build/compile a rock." | 16 | help_summary = "Build/compile a rock." |
17 | help_arguments = "{<rockspec>|<rock>|<name> [<version>]}" | 17 | help_arguments = "[--pack-binary-rock] {<rockspec>|<rock>|<name> [<version>]}" |
18 | help = [[ | 18 | help = [[ |
19 | Build a rock, compiling its C parts if any. | 19 | Build and install a rock, compiling its C parts if any. |
20 | Argument may be a rockspec file, a source rock file | 20 | Argument may be a rockspec file, a source rock file |
21 | or the name of a rock to be fetched from a repository. | 21 | or the name of a rock to be fetched from a repository. |
22 | |||
23 | If --pack-binary-rock is passed, the rock is not installed; | ||
24 | instead, a .rock file with the contents of compilation is produced | ||
25 | in the current directory. | ||
22 | ]] | 26 | ]] |
23 | 27 | ||
24 | --- Install files to a given location. | 28 | --- Install files to a given location. |
25 | -- Takes a table where the array part is a list of filenames to be copied. | 29 | -- Takes a table where the array part is a list of filenames to be copied. |
26 | -- In the hash part, other keys are identifiers in Lua module format, | 30 | -- In the hash part, other keys, if is_module_path is set, are identifiers |
27 | -- to indicate which subdirectory the file should be copied to. For example, | 31 | -- in Lua module format, to indicate which subdirectory the file should be |
28 | -- install_files({["foo.bar"] = "src/bar.lua"}, "boo") will copy src/bar.lua | 32 | -- copied to. For example, install_files({["foo.bar"] = "src/bar.lua"}, "boo") |
29 | -- to boo/foo. | 33 | -- will copy src/bar.lua to boo/foo. |
30 | -- @param files table or nil: A table containing a list of files to copy in | 34 | -- @param files table or nil: A table containing a list of files to copy in |
31 | -- the format described above. If nil is passed, this function is a no-op. | 35 | -- the format described above. If nil is passed, this function is a no-op. |
32 | -- Directories should be delimited by forward slashes as in internet URLs. | 36 | -- Directories should be delimited by forward slashes as in internet URLs. |
33 | -- @param location string: The base directory files should be copied to. | 37 | -- @param location string: The base directory files should be copied to. |
38 | -- @param is_module_path boolean: True if string keys in files should be | ||
39 | -- interpreted as dotted module paths. | ||
34 | -- @return boolean or (nil, string): True if succeeded or | 40 | -- @return boolean or (nil, string): True if succeeded or |
35 | -- nil and an error message. | 41 | -- nil and an error message. |
36 | local function install_files(files, location) | 42 | local function install_files(files, location, is_module_path) |
37 | assert(type(files) == "table" or not files) | 43 | assert(type(files) == "table" or not files) |
38 | assert(type(location) == "string") | 44 | assert(type(location) == "string") |
39 | if files then | 45 | if files then |
40 | for k, file in pairs(files) do | 46 | for k, file in pairs(files) do |
41 | local dest = location | 47 | local dest = location |
42 | if type(k) == "string" then | 48 | if type(k) == "string" then |
43 | dest = dir.path(location, path.module_to_path(k)) | 49 | dest = is_module_path and dir.path(location, path.module_to_path(k)) or k |
44 | end | 50 | end |
45 | fs.make_dir(dest) | 51 | fs.make_dir(dest) |
46 | local ok = fs.copy(dir.path(file), dest) | 52 | local ok = fs.copy(dir.path(file), dest) |
@@ -143,14 +149,14 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode) | |||
143 | end | 149 | end |
144 | 150 | ||
145 | local dirs = { | 151 | local dirs = { |
146 | lua = path.lua_dir(name, version), | 152 | lua = { name = path.lua_dir(name, version), is_module_path = true }, |
147 | lib = path.lib_dir(name, version), | 153 | lib = { name = path.lib_dir(name, version), is_module_path = true }, |
148 | conf = path.conf_dir(name, version), | 154 | conf = { name = path.conf_dir(name, version), is_module_path = false }, |
149 | bin = path.bin_dir(name, version), | 155 | bin = { name = path.bin_dir(name, version), is_module_path = false }, |
150 | } | 156 | } |
151 | 157 | ||
152 | for _, d in pairs(dirs) do | 158 | for _, d in pairs(dirs) do |
153 | fs.make_dir(d) | 159 | fs.make_dir(d.name) |
154 | end | 160 | end |
155 | local rollback = util.schedule_function(function() | 161 | local rollback = util.schedule_function(function() |
156 | fs.delete(path.install_dir(name, version)) | 162 | fs.delete(path.install_dir(name, version)) |
@@ -188,7 +194,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode) | |||
188 | 194 | ||
189 | if build.install then | 195 | if build.install then |
190 | for id, install_dir in pairs(dirs) do | 196 | for id, install_dir in pairs(dirs) do |
191 | ok, err = install_files(build.install[id], install_dir) | 197 | ok, err = install_files(build.install[id], install_dir.name, install_dir.is_module_path) |
192 | if not ok then | 198 | if not ok then |
193 | return nil, err | 199 | return nil, err |
194 | end | 200 | end |
@@ -206,7 +212,7 @@ function build_rockspec(rockspec_file, need_to_fetch, minimal_mode) | |||
206 | end | 212 | end |
207 | 213 | ||
208 | for _, d in pairs(dirs) do | 214 | for _, d in pairs(dirs) do |
209 | fs.remove_dir_if_empty(d) | 215 | fs.remove_dir_if_empty(d.name) |
210 | end | 216 | end |
211 | 217 | ||
212 | fs.pop_dir() | 218 | fs.pop_dir() |
@@ -267,6 +273,42 @@ function build_rock(rock_file, need_to_fetch) | |||
267 | return ok, err, errcode | 273 | return ok, err, errcode |
268 | end | 274 | end |
269 | 275 | ||
276 | local function do_build(name, version) | ||
277 | if name:match("%.rockspec$") then | ||
278 | return build_rockspec(name, true) | ||
279 | elseif name:match("%.src%.rock$") then | ||
280 | return build_rock(name, false) | ||
281 | elseif name:match("%.all%.rock$") then | ||
282 | local install = require("luarocks.install") | ||
283 | return install.install_binary_rock(name) | ||
284 | elseif name:match("%.rock$") then | ||
285 | return build_rock(name, true) | ||
286 | elseif not name:match(dir.separator) then | ||
287 | local search = require("luarocks.search") | ||
288 | return search.act_on_src_or_rockspec(run, name:lower(), version) | ||
289 | end | ||
290 | return nil, "Don't know what to do with "..name | ||
291 | end | ||
292 | |||
293 | local function pack_binary_rock(name, version) | ||
294 | local temp_dir = fs.make_temp_dir("luarocks-build-pack-"..dir.base_name(name)) | ||
295 | if not temp_dir then | ||
296 | return nil, "Failed creating temporary directory." | ||
297 | end | ||
298 | util.schedule_function(fs.delete, temp_dir) | ||
299 | |||
300 | path.use_tree(temp_dir) | ||
301 | local ok, err = do_build(name, version) | ||
302 | if not ok then | ||
303 | return nil, err | ||
304 | end | ||
305 | local rname, rversion = path.parse_name(name) | ||
306 | if not rname then | ||
307 | rname, rversion = name, version | ||
308 | end | ||
309 | return pack.pack_binary_rock(rname, rversion) | ||
310 | end | ||
311 | |||
270 | --- Driver function for "build" command. | 312 | --- Driver function for "build" command. |
271 | -- @param name string: A local or remote rockspec or rock file. | 313 | -- @param name string: A local or remote rockspec or rock file. |
272 | -- If a package name is given, forwards the request to "search" and, | 314 | -- If a package name is given, forwards the request to "search" and, |
@@ -284,19 +326,10 @@ function run(...) | |||
284 | 326 | ||
285 | local ok, err = fs.check_command_permissions(flags) | 327 | local ok, err = fs.check_command_permissions(flags) |
286 | if not ok then return nil, err end | 328 | if not ok then return nil, err end |
287 | 329 | ||
288 | if name:match("%.rockspec$") then | 330 | if flags["pack-binary-rock"] then |
289 | return build_rockspec(name, true) | 331 | return pack_binary_rock(name, version) |
290 | elseif name:match("%.src%.rock$") then | 332 | else |
291 | return build_rock(name, false) | 333 | return do_build(name, version) |
292 | elseif name:match("%.all%.rock$") then | ||
293 | local install = require("luarocks.install") | ||
294 | return install.install_binary_rock(name) | ||
295 | elseif name:match("%.rock$") then | ||
296 | return build_rock(name, true) | ||
297 | elseif not name:match(dir.separator) then | ||
298 | local search = require("luarocks.search") | ||
299 | return search.act_on_src_or_rockspec(run, name:lower(), version) | ||
300 | end | 334 | end |
301 | return nil, "Don't know what to do with "..name | ||
302 | end | 335 | end |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 43f10e6b..2b48d576 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
@@ -24,7 +24,7 @@ end | |||
24 | 24 | ||
25 | _M.config = config | 25 | _M.config = config |
26 | 26 | ||
27 | program_version = "2.0.4.1" | 27 | program_version = "2.0.5" |
28 | user_agent = "LuaRocks/"..program_version | 28 | user_agent = "LuaRocks/"..program_version |
29 | 29 | ||
30 | local persist = require("luarocks.persist") | 30 | local persist = require("luarocks.persist") |
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 50502257..02793c5a 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
@@ -15,7 +15,7 @@ local function die(message) | |||
15 | 15 | ||
16 | local ok, err = pcall(util.run_scheduled_functions) | 16 | local ok, err = pcall(util.run_scheduled_functions) |
17 | if not ok then | 17 | if not ok then |
18 | util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at luarocks-developers@lists.luaforge.net):\n"..err) | 18 | util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at luarocks-developers@lists.sourceforge.net):\n"..err) |
19 | end | 19 | end |
20 | util.printerr("\nError: "..message) | 20 | util.printerr("\nError: "..message) |
21 | os.exit(1) | 21 | os.exit(1) |
@@ -33,14 +33,6 @@ local function is_writable(tree) | |||
33 | end | 33 | end |
34 | end | 34 | end |
35 | 35 | ||
36 | local function use_tree(tree) | ||
37 | cfg.root_dir = tree | ||
38 | cfg.rocks_dir = path.rocks_dir(tree) | ||
39 | cfg.deploy_bin_dir = path.deploy_bin_dir(tree) | ||
40 | cfg.deploy_lua_dir = path.deploy_lua_dir(tree) | ||
41 | cfg.deploy_lib_dir = path.deploy_lib_dir(tree) | ||
42 | end | ||
43 | |||
44 | --- Main command-line processor. | 36 | --- Main command-line processor. |
45 | -- Parses input arguments and calls the appropriate driver function | 37 | -- Parses input arguments and calls the appropriate driver function |
46 | -- to execute the action requested on the command-line, forwarding | 38 | -- to execute the action requested on the command-line, forwarding |
@@ -97,12 +89,12 @@ function run_command(...) | |||
97 | die("Argument error: use --to=<path>") | 89 | die("Argument error: use --to=<path>") |
98 | end | 90 | end |
99 | local root_dir = fs.absolute_name(flags["to"]) | 91 | local root_dir = fs.absolute_name(flags["to"]) |
100 | use_tree(root_dir) | 92 | path.use_tree(root_dir) |
101 | elseif flags["local"] then | 93 | elseif flags["local"] then |
102 | use_tree(cfg.home_tree) | 94 | path.use_tree(cfg.home_tree) |
103 | else | 95 | else |
104 | local trees = cfg.rocks_trees | 96 | local trees = cfg.rocks_trees |
105 | use_tree(trees[#trees]) | 97 | path.use_tree(trees[#trees]) |
106 | end | 98 | end |
107 | 99 | ||
108 | if type(cfg.root_dir) == "string" then | 100 | if type(cfg.root_dir) == "string" then |
@@ -142,7 +134,7 @@ function run_command(...) | |||
142 | if commands[command] then | 134 | if commands[command] then |
143 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) | 135 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) |
144 | die(debug.traceback("LuaRocks "..cfg.program_version | 136 | die(debug.traceback("LuaRocks "..cfg.program_version |
145 | .." bug (please report at luarocks-developers@lists.luaforge.net).\n" | 137 | .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" |
146 | ..err, 2)) | 138 | ..err, 2)) |
147 | end) | 139 | end) |
148 | if xp and (not ok) then | 140 | if xp and (not ok) then |
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 0a748b0e..1a7e4eff 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -159,8 +159,7 @@ end | |||
159 | -- a crossplatform way. | 159 | -- a crossplatform way. |
160 | function change_dir_to_root() | 160 | function change_dir_to_root() |
161 | table.insert(dir_stack, lfs.currentdir()) | 161 | table.insert(dir_stack, lfs.currentdir()) |
162 | -- TODO Does this work on Windows? | 162 | lfs.chdir("/") -- works on Windows too |
163 | lfs.chdir("/") | ||
164 | end | 163 | end |
165 | 164 | ||
166 | --- Change working directory to the previous in the dir stack. | 165 | --- Change working directory to the previous in the dir stack. |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index d7d87192..e99b4ce0 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
@@ -28,7 +28,7 @@ or a filename of a locally available rock. | |||
28 | function install_binary_rock(rock_file) | 28 | function install_binary_rock(rock_file) |
29 | assert(type(rock_file) == "string") | 29 | assert(type(rock_file) == "string") |
30 | 30 | ||
31 | local name, version, arch = path.parse_rock_name(rock_file) | 31 | local name, version, arch = path.parse_name(rock_file) |
32 | if not name then | 32 | if not name then |
33 | return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." | 33 | return nil, "Filename "..rock_file.." does not match format 'name-version-revision.arch.rock'." |
34 | end | 34 | end |
diff --git a/src/luarocks/pack.lua b/src/luarocks/pack.lua index e22bdc38..b85b7460 100644 --- a/src/luarocks/pack.lua +++ b/src/luarocks/pack.lua | |||
@@ -80,7 +80,7 @@ end | |||
80 | -- @param version string or nil: A version number may also be passed. | 80 | -- @param version string or nil: A version number may also be passed. |
81 | -- @return string or (nil, string): The filename of the resulting | 81 | -- @return string or (nil, string): The filename of the resulting |
82 | -- .src.rock file; or nil and an error message. | 82 | -- .src.rock file; or nil and an error message. |
83 | local function pack_binary_rock(name, version) | 83 | function pack_binary_rock(name, version) |
84 | assert(type(name) == "string") | 84 | assert(type(name) == "string") |
85 | assert(type(version) == "string" or not version) | 85 | assert(type(version) == "string" or not version) |
86 | 86 | ||
diff --git a/src/luarocks/path.lua b/src/luarocks/path.lua index fe241aa5..8c795e8b 100644 --- a/src/luarocks/path.lua +++ b/src/luarocks/path.lua | |||
@@ -193,22 +193,18 @@ function bin_dir(name, version, repo) | |||
193 | return dir.path(rocks_dir(repo), name, version, "bin") | 193 | return dir.path(rocks_dir(repo), name, version, "bin") |
194 | end | 194 | end |
195 | 195 | ||
196 | --- Extract name, version and arch of a rock filename. | 196 | --- Extract name, version and arch of a rock filename, |
197 | -- @param rock_file string: pathname of a rock | 197 | -- or name, version and "rockspec" from a rockspec name. |
198 | -- @param file_name string: pathname of a rock or rockspec | ||
198 | -- @return (string, string, string) or nil: name, version and arch | 199 | -- @return (string, string, string) or nil: name, version and arch |
199 | -- of rock, or nil if name could not be parsed | 200 | -- or nil if name could not be parsed |
200 | function parse_rock_name(rock_file) | 201 | function parse_name(file_name) |
201 | assert(type(rock_file) == "string") | 202 | assert(type(file_name) == "string") |
202 | return dir.base_name(rock_file):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") | 203 | if file_name:match("%.rock$") then |
203 | end | 204 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.([^.]+)%.rock$") |
204 | 205 | else | |
205 | --- Extract name and version of a rockspec filename. | 206 | return dir.base_name(file_name):match("(.*)-([^-]+-%d+)%.(rockspec)") |
206 | -- @param rockspec_file string: pathname of a rockspec | 207 | end |
207 | -- @return (string, string) or nil: name and version | ||
208 | -- of rockspec, or nil if name could not be parsed | ||
209 | function parse_rockspec_name(rockspec_file) | ||
210 | assert(type(rockspec_file) == "string") | ||
211 | return dir.base_name(rockspec_file):match("(.*)-([^-]+-%d+)%.(rockspec)") | ||
212 | end | 208 | end |
213 | 209 | ||
214 | --- Make a rockspec or rock URL. | 210 | --- Make a rockspec or rock URL. |
@@ -301,6 +297,14 @@ function versioned_name(file, prefix, name, version) | |||
301 | return dir.path(prefix, name_version.."-"..rest) | 297 | return dir.path(prefix, name_version.."-"..rest) |
302 | end | 298 | end |
303 | 299 | ||
300 | function use_tree(tree) | ||
301 | cfg.root_dir = tree | ||
302 | cfg.rocks_dir = rocks_dir(tree) | ||
303 | cfg.deploy_bin_dir = deploy_bin_dir(tree) | ||
304 | cfg.deploy_lua_dir = deploy_lua_dir(tree) | ||
305 | cfg.deploy_lib_dir = deploy_lib_dir(tree) | ||
306 | end | ||
307 | |||
304 | --- Driver function for "path" command. | 308 | --- Driver function for "path" command. |
305 | -- @return boolean This function always succeeds. | 309 | -- @return boolean This function always succeeds. |
306 | function run(...) | 310 | function run(...) |
diff --git a/src/luarocks/search.lua b/src/luarocks/search.lua index 493c2f45..127bba19 100644 --- a/src/luarocks/search.lua +++ b/src/luarocks/search.lua | |||
@@ -138,10 +138,7 @@ function disk_search(repo, query, results) | |||
138 | 138 | ||
139 | for _, name in pairs(fs.list_dir(repo)) do | 139 | for _, name in pairs(fs.list_dir(repo)) do |
140 | local pathname = dir.path(repo, name) | 140 | local pathname = dir.path(repo, name) |
141 | local rname, rversion, rarch = path.parse_rock_name(name) | 141 | local rname, rversion, rarch = path.parse_name(name) |
142 | if not rname then | ||
143 | rname, rversion, rarch = path.parse_rockspec_name(name) | ||
144 | end | ||
145 | if fs.is_dir(pathname) then | 142 | if fs.is_dir(pathname) then |
146 | for _, version in pairs(fs.list_dir(pathname)) do | 143 | for _, version in pairs(fs.list_dir(pathname)) do |
147 | if version:match("-%d+$") then | 144 | if version:match("-%d+$") then |