diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2013-12-26 05:46:17 -0800 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2013-12-26 05:46:17 -0800 |
| commit | 1ab1f451a67196c081382b9a47c51de2ad16042b (patch) | |
| tree | ed67f90fe99114394b32208e227e3748946d58ff /src | |
| parent | cd2b8957b519ee01f15c481e13e21ff7f6fa22a0 (diff) | |
| parent | 57c4c60f352c0bbecdb28b0f5c27831b48f653a2 (diff) | |
| download | luarocks-1ab1f451a67196c081382b9a47c51de2ad16042b.tar.gz luarocks-1ab1f451a67196c081382b9a47c51de2ad16042b.tar.bz2 luarocks-1ab1f451a67196c081382b9a47c51de2ad16042b.zip | |
Merge pull request #211 from Tieske/exitcodes
Win defaults, /SELFCONTAINED option
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/install.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/make.lua | 6 | ||||
| -rw-r--r-- | src/luarocks/remove.lua | 6 |
6 files changed, 34 insertions, 18 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/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 |
