diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2014-01-03 14:26:43 -0200 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-01-03 14:26:43 -0200 |
| commit | f4b271c51c1c05db92a9a12ca39c2ec5208937e0 (patch) | |
| tree | 52093e6fbbcbf39f1348661f0ac016b8b9072784 /src | |
| parent | 8927752c7b90f3ed5a6265aebaf3f63ee19bb8ad (diff) | |
| parent | 5abe779e56af672a935d0fb9d4d83e85d853f3f8 (diff) | |
| download | luarocks-f4b271c51c1c05db92a9a12ca39c2ec5208937e0.tar.gz luarocks-f4b271c51c1c05db92a9a12ca39c2ec5208937e0.tar.bz2 luarocks-f4b271c51c1c05db92a9a12ca39c2ec5208937e0.zip | |
Merge branch 'master' of github.com:keplerproject/luarocks
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/build.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/cfg.lua | 17 | ||||
| -rw-r--r-- | src/luarocks/command_line.lua | 11 | ||||
| -rw-r--r-- | src/luarocks/help.lua | 12 | ||||
| -rw-r--r-- | src/luarocks/install.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/make.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/remove.lua | 6 |
7 files changed, 41 insertions, 23 deletions
diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 5555d94a..ec269023 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua | |||
| @@ -351,8 +351,8 @@ end | |||
| 351 | -- if returned a result, installs the matching rock. | 351 | -- if returned a result, installs the matching rock. |
| 352 | -- @param version string: When passing a package name, a version number may | 352 | -- @param version string: When passing a package name, a version number may |
| 353 | -- also be given. | 353 | -- also be given. |
| 354 | -- @return boolean or (nil, string): True if build was successful; nil and an | 354 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an |
| 355 | -- error message otherwise. | 355 | -- error message otherwise. exitcode is optionally returned. |
| 356 | function run(...) | 356 | function run(...) |
| 357 | local flags, name, version = util.parse_flags(...) | 357 | local flags, name, version = util.parse_flags(...) |
| 358 | if type(name) ~= "string" then | 358 | if type(name) ~= "string" then |
| @@ -364,7 +364,7 @@ function run(...) | |||
| 364 | return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags)) | 364 | return pack.pack_binary_rock(name, version, do_build, name, version, deps.get_deps_mode(flags)) |
| 365 | else | 365 | else |
| 366 | local ok, err = fs.check_command_permissions(flags) | 366 | local ok, err = fs.check_command_permissions(flags) |
| 367 | if not ok then return nil, err end | 367 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end |
| 368 | ok, err = do_build(name, version, deps.get_deps_mode(flags)) | 368 | ok, err = do_build(name, version, deps.get_deps_mode(flags)) |
| 369 | if not ok then return nil, err end | 369 | if not ok then return nil, err end |
| 370 | local name, version = ok, err | 370 | local name, version = ok, err |
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index 2904146b..87777b86 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua | |||
| @@ -35,6 +35,21 @@ major_version = program_version:match("([^.]%.[^.])") | |||
| 35 | 35 | ||
| 36 | local persist = require("luarocks.persist") | 36 | local persist = require("luarocks.persist") |
| 37 | 37 | ||
| 38 | _M.errorcodes = setmetatable({ | ||
| 39 | OK = 0, | ||
| 40 | UNSPECIFIED = 1, | ||
| 41 | PERMISSIONDENIED = 2, | ||
| 42 | },{ | ||
| 43 | __index = function(t, key) | ||
| 44 | local val = rawget(t, key) | ||
| 45 | if not val then | ||
| 46 | error("'"..tostring(key).."' is not a valid errorcode", 2) | ||
| 47 | end | ||
| 48 | return val | ||
| 49 | end | ||
| 50 | }) | ||
| 51 | |||
| 52 | |||
| 38 | local popen_ok, popen_result = pcall(io.popen, "") | 53 | local popen_ok, popen_result = pcall(io.popen, "") |
| 39 | if popen_ok then | 54 | if popen_ok then |
| 40 | if popen_result then | 55 | if popen_result then |
| @@ -43,7 +58,7 @@ if popen_ok then | |||
| 43 | else | 58 | else |
| 44 | io.stderr:write("Your version of Lua does not support io.popen,\n") | 59 | io.stderr:write("Your version of Lua does not support io.popen,\n") |
| 45 | io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") | 60 | io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") |
| 46 | os.exit(1) | 61 | os.exit(_M.errorcodes.UNSPECIFIED) |
| 47 | end | 62 | end |
| 48 | 63 | ||
| 49 | -- System detection: | 64 | -- System detection: |
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index b98084e0..e79b1442 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua | |||
| @@ -12,7 +12,8 @@ local program = util.this_program("luarocks") | |||
| 12 | 12 | ||
| 13 | --- Display an error message and exit. | 13 | --- Display an error message and exit. |
| 14 | -- @param message string: The error message. | 14 | -- @param message string: The error message. |
| 15 | local function die(message) | 15 | -- @param exitcode number: the exitcode to use |
| 16 | local function die(message, exitcode) | ||
| 16 | assert(type(message) == "string") | 17 | assert(type(message) == "string") |
| 17 | 18 | ||
| 18 | local ok, err = pcall(util.run_scheduled_functions) | 19 | local ok, err = pcall(util.run_scheduled_functions) |
| @@ -20,7 +21,7 @@ local function die(message) | |||
| 20 | util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at luarocks-developers@lists.sourceforge.net):\n"..err) | 21 | util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at luarocks-developers@lists.sourceforge.net):\n"..err) |
| 21 | end | 22 | end |
| 22 | util.printerr("\nError: "..message) | 23 | util.printerr("\nError: "..message) |
| 23 | os.exit(1) | 24 | os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) |
| 24 | end | 25 | end |
| 25 | 26 | ||
| 26 | local function replace_tree(flags, args, tree) | 27 | local function replace_tree(flags, args, tree) |
| @@ -83,7 +84,7 @@ function run_command(...) | |||
| 83 | util.printout(program.." "..cfg.program_version) | 84 | util.printout(program.." "..cfg.program_version) |
| 84 | util.printout(program_description) | 85 | util.printout(program_description) |
| 85 | util.printout() | 86 | util.printout() |
| 86 | os.exit(0) | 87 | os.exit(cfg.errorcodes.OK) |
| 87 | elseif flags["help"] or #nonflags == 0 then | 88 | elseif flags["help"] or #nonflags == 0 then |
| 88 | command = "help" | 89 | command = "help" |
| 89 | args = nonflags | 90 | args = nonflags |
| @@ -184,13 +185,13 @@ function run_command(...) | |||
| 184 | -- I'm not changing this now to avoid messing with the run() | 185 | -- I'm not changing this now to avoid messing with the run() |
| 185 | -- interface, which I know some people use (even though | 186 | -- interface, which I know some people use (even though |
| 186 | -- I never published it as a public API...) | 187 | -- I never published it as a public API...) |
| 187 | local xp, ok, err = xpcall(function() return commands[command].run(unpack(args)) end, function(err) | 188 | local xp, ok, err, exitcode = xpcall(function() return commands[command].run(unpack(args)) end, function(err) |
| 188 | die(debug.traceback("LuaRocks "..cfg.program_version | 189 | die(debug.traceback("LuaRocks "..cfg.program_version |
| 189 | .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" | 190 | .." bug (please report at luarocks-developers@lists.sourceforge.net).\n" |
| 190 | ..err, 2)) | 191 | ..err, 2)) |
| 191 | end) | 192 | end) |
| 192 | if xp and (not ok) then | 193 | if xp and (not ok) then |
| 193 | die(err) | 194 | die(err, exitcode) |
| 194 | end | 195 | end |
| 195 | else | 196 | else |
| 196 | die("Unknown command: "..command) | 197 | die("Unknown command: "..command) |
diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 33c684ad..2774dc41 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua | |||
| @@ -8,6 +8,7 @@ module("luarocks.help", package.seeall) | |||
| 8 | 8 | ||
| 9 | local util = require("luarocks.util") | 9 | local util = require("luarocks.util") |
| 10 | local cfg = require("luarocks.cfg") | 10 | local cfg = require("luarocks.cfg") |
| 11 | local dir = require("luarocks.dir") | ||
| 11 | 12 | ||
| 12 | local program = util.this_program("luarocks") | 13 | local program = util.this_program("luarocks") |
| 13 | 14 | ||
| @@ -81,19 +82,20 @@ function run(...) | |||
| 81 | end | 82 | end |
| 82 | print_section("CONFIGURATION") | 83 | print_section("CONFIGURATION") |
| 83 | util.printout("\tLua version: " .. cfg.lua_version) | 84 | util.printout("\tLua version: " .. cfg.lua_version) |
| 84 | util.printout("\tSystem configuration file: ".. sys_file .. " (" .. get_status(sys_ok) ..")") | 85 | util.printout("\tConfiguration files:") |
| 86 | util.printout("\t\tSystem: ".. dir.normalize(sys_file) .. " (" .. get_status(sys_ok) ..")") | ||
| 85 | if home_file then | 87 | if home_file then |
| 86 | util.printout("\tUser configuration file: ".. home_file .. " (" .. get_status(home_ok) ..")\n") | 88 | util.printout("\t\tUser : ".. dir.normalize(home_file) .. " (" .. get_status(home_ok) ..")\n") |
| 87 | else | 89 | else |
| 88 | util.printout("\tUser configuration file disabled in this LuaRocks installation.\n") | 90 | util.printout("\t\tUser : disabled in this LuaRocks installation.\n") |
| 89 | end | 91 | end |
| 90 | util.printout("\tRocks trees in use: ") | 92 | util.printout("\tRocks trees in use: ") |
| 91 | for _, tree in ipairs(cfg.rocks_trees) do | 93 | for _, tree in ipairs(cfg.rocks_trees) do |
| 92 | if type(tree) == "string" then | 94 | if type(tree) == "string" then |
| 93 | util.printout("\t\t"..tree) | 95 | util.printout("\t\t"..dir.normalize(tree)) |
| 94 | else | 96 | else |
| 95 | local name = tree.name and " (\""..tree.name.."\")" or "" | 97 | local name = tree.name and " (\""..tree.name.."\")" or "" |
| 96 | util.printout("\t\t"..tree.root..name) | 98 | util.printout("\t\t"..dir.normalize(tree.root)..name) |
| 97 | end | 99 | end |
| 98 | end | 100 | end |
| 99 | else | 101 | else |
diff --git a/src/luarocks/install.lua b/src/luarocks/install.lua index c181d612..b28e6282 100644 --- a/src/luarocks/install.lua +++ b/src/luarocks/install.lua | |||
| @@ -120,8 +120,8 @@ end | |||
| 120 | -- if returned a result, installs the matching rock. | 120 | -- if returned a result, installs the matching rock. |
| 121 | -- @param version string: When passing a package name, a version number | 121 | -- @param version string: When passing a package name, a version number |
| 122 | -- may also be given. | 122 | -- may also be given. |
| 123 | -- @return boolean or (nil, string): True if installation was | 123 | -- @return boolean or (nil, string, exitcode): True if installation was |
| 124 | -- successful, nil and an error message otherwise. | 124 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
| 125 | function run(...) | 125 | function run(...) |
| 126 | local flags, name, version = util.parse_flags(...) | 126 | local flags, name, version = util.parse_flags(...) |
| 127 | if type(name) ~= "string" then | 127 | if type(name) ~= "string" then |
| @@ -129,7 +129,7 @@ function run(...) | |||
| 129 | end | 129 | end |
| 130 | 130 | ||
| 131 | local ok, err = fs.check_command_permissions(flags) | 131 | local ok, err = fs.check_command_permissions(flags) |
| 132 | if not ok then return nil, err end | 132 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end |
| 133 | 133 | ||
| 134 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then | 134 | if name:match("%.rockspec$") or name:match("%.src%.rock$") then |
| 135 | util.printout("Using "..name.."... switching to 'build' mode") | 135 | util.printout("Using "..name.."... switching to 'build' mode") |
diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index eef49d0c..3999e39f 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua | |||
| @@ -40,8 +40,8 @@ To install rocks, you'll normally want to use the "install" and | |||
| 40 | 40 | ||
| 41 | --- Driver function for "make" command. | 41 | --- Driver function for "make" command. |
| 42 | -- @param name string: A local rockspec. | 42 | -- @param name string: A local rockspec. |
| 43 | -- @return boolean or (nil, string): True if build was successful; nil and an | 43 | -- @return boolean or (nil, string, exitcode): True if build was successful; nil and an |
| 44 | -- error message otherwise. | 44 | -- error message otherwise. exitcode is optionally returned. |
| 45 | function run(...) | 45 | function run(...) |
| 46 | local flags, rockspec = util.parse_flags(...) | 46 | local flags, rockspec = util.parse_flags(...) |
| 47 | assert(type(rockspec) == "string" or not rockspec) | 47 | assert(type(rockspec) == "string" or not rockspec) |
| @@ -73,7 +73,7 @@ function run(...) | |||
| 73 | return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.get_deps_mode(flags)) | 73 | return pack.pack_binary_rock(rspec.name, rspec.version, build.build_rockspec, rockspec, false, true, deps.get_deps_mode(flags)) |
| 74 | else | 74 | else |
| 75 | local ok, err = fs.check_command_permissions(flags) | 75 | local ok, err = fs.check_command_permissions(flags) |
| 76 | if not ok then return nil, err end | 76 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end |
| 77 | ok, err = build.build_rockspec(rockspec, false, true, deps.get_deps_mode(flags)) | 77 | ok, err = build.build_rockspec(rockspec, false, true, deps.get_deps_mode(flags)) |
| 78 | if not ok then return nil, err end | 78 | if not ok then return nil, err end |
| 79 | local name, version = ok, err | 79 | local name, version = ok, err |
diff --git a/src/luarocks/remove.lua b/src/luarocks/remove.lua index 5a6e4dc5..f2f6997b 100644 --- a/src/luarocks/remove.lua +++ b/src/luarocks/remove.lua | |||
| @@ -132,8 +132,8 @@ end | |||
| 132 | -- a specific version; otherwise, try to remove all versions. | 132 | -- a specific version; otherwise, try to remove all versions. |
| 133 | -- @param version string: When passing a package name, a version number | 133 | -- @param version string: When passing a package name, a version number |
| 134 | -- may also be given. | 134 | -- may also be given. |
| 135 | -- @return boolean or (nil, string): True if removal was | 135 | -- @return boolean or (nil, string, exitcode): True if removal was |
| 136 | -- successful, nil and an error message otherwise. | 136 | -- successful, nil and an error message otherwise. exitcode is optionally returned. |
| 137 | function run(...) | 137 | function run(...) |
| 138 | local flags, name, version = util.parse_flags(...) | 138 | local flags, name, version = util.parse_flags(...) |
| 139 | 139 | ||
| @@ -144,7 +144,7 @@ function run(...) | |||
| 144 | local deps_mode = flags["deps-mode"] or cfg.deps_mode | 144 | local deps_mode = flags["deps-mode"] or cfg.deps_mode |
| 145 | 145 | ||
| 146 | local ok, err = fs.check_command_permissions(flags) | 146 | local ok, err = fs.check_command_permissions(flags) |
| 147 | if not ok then return nil, err end | 147 | if not ok then return nil, err, cfg.errorcodes.PERMISSIONDENIED end |
| 148 | 148 | ||
| 149 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") | 149 | local rock_type = name:match("%.(rock)$") or name:match("%.(rockspec)$") |
| 150 | local filename = name | 150 | local filename = name |
