diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-12-01 10:02:57 +0100 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2013-12-01 10:02:57 +0100 |
| commit | 03cc9208fbeec8065365cbd5d5c124a327b47a4a (patch) | |
| tree | b4b72d0347dab497b91cef35304af026cad39d1e | |
| parent | 62c74024f52d6aa256dfbe3c978496d1a22a444f (diff) | |
| download | luarocks-03cc9208fbeec8065365cbd5d5c124a327b47a4a.tar.gz luarocks-03cc9208fbeec8065365cbd5d5c124a327b47a4a.tar.bz2 luarocks-03cc9208fbeec8065365cbd5d5c124a327b47a4a.zip | |
refactored debug output. Now all is set by using `verbose = true` in the config file instead of manually uncommenting code.
Also moved to platform independent code, from Windows only
| -rw-r--r-- | install.bat | 1 | ||||
| -rw-r--r-- | src/luarocks/fs.lua | 45 | ||||
| -rw-r--r-- | src/luarocks/fs/lua.lua | 4 | ||||
| -rw-r--r-- | src/luarocks/fs/win32/tools.lua | 16 |
4 files changed, 31 insertions, 35 deletions
diff --git a/install.bat b/install.bat index 26255502..22f72e13 100644 --- a/install.bat +++ b/install.bat | |||
| @@ -709,6 +709,7 @@ rocks_trees = { | |||
| 709 | end | 709 | end |
| 710 | f:write(S" LUALIB = '$LUA_LIBNAME'\n") | 710 | f:write(S" LUALIB = '$LUA_LIBNAME'\n") |
| 711 | f:write("}\n") | 711 | f:write("}\n") |
| 712 | f:write("verbose = false -- set to 'true' to enable verbose output\n") | ||
| 712 | f:close() | 713 | f:close() |
| 713 | print(S"Created LuaRocks config file: $CONFIG_FILE") | 714 | print(S"Created LuaRocks config file: $CONFIG_FILE") |
| 714 | else | 715 | else |
diff --git a/src/luarocks/fs.lua b/src/luarocks/fs.lua index e002c7ba..2d799da2 100644 --- a/src/luarocks/fs.lua +++ b/src/luarocks/fs.lua | |||
| @@ -11,6 +11,32 @@ module("luarocks.fs", package.seeall) | |||
| 11 | 11 | ||
| 12 | local cfg = require("luarocks.cfg") | 12 | local cfg = require("luarocks.cfg") |
| 13 | 13 | ||
| 14 | local pack = table.pack or function(...) return { n = select("#", ...), ... } end | ||
| 15 | local unpack = table.unpack or unpack | ||
| 16 | |||
| 17 | if cfg.verbose then -- patch io.popen and os.execute to display commands in verbose mode | ||
| 18 | old_popen = io.popen | ||
| 19 | io.popen = function(one, two) | ||
| 20 | if two == nil then | ||
| 21 | print("\nio.popen: ", one) | ||
| 22 | else | ||
| 23 | print("\nio.popen: ", one, "Mode:", two) | ||
| 24 | end | ||
| 25 | return old_popen(one, two) | ||
| 26 | end | ||
| 27 | |||
| 28 | old_exec = os.execute | ||
| 29 | os.execute = function(cmd) | ||
| 30 | print("\nos.execute: ", cmd) | ||
| 31 | local code = pack(old_exec(cmd)) | ||
| 32 | print("Results: "..tostring(code.n)) | ||
| 33 | for i = 1,code.n do | ||
| 34 | print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) | ||
| 35 | end | ||
| 36 | return unpack(code, 1, code.n) | ||
| 37 | end | ||
| 38 | end | ||
| 39 | |||
| 14 | local function load_fns(fs_table) | 40 | local function load_fns(fs_table) |
| 15 | for name, fn in pairs(fs_table) do | 41 | for name, fn in pairs(fs_table) do |
| 16 | if not _M[name] then | 42 | if not _M[name] then |
| @@ -38,22 +64,3 @@ load_fns(fs_lua) | |||
| 38 | local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") | 64 | local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") |
| 39 | if ok and fs_plat_tools then load_fns(fs_plat_tools) end | 65 | if ok and fs_plat_tools then load_fns(fs_plat_tools) end |
| 40 | 66 | ||
| 41 | -- uncomment below for further debugging than 'verbose=true' in config file | ||
| 42 | -- code below will also catch commands outside of fs.execute() | ||
| 43 | -- especially uses of io.popen(). | ||
| 44 | --[[ | ||
| 45 | old_exec = os.execute | ||
| 46 | os.execute = function(cmd) | ||
| 47 | print("os.execute: ", cmd) | ||
| 48 | return old_exec(cmd) | ||
| 49 | end | ||
| 50 | old_popen = io.popen | ||
| 51 | io.popen = function(one, two) | ||
| 52 | if two == nil then | ||
| 53 | print("io.popen: ", one) | ||
| 54 | else | ||
| 55 | print("io.popen: ", one, "Mode:", two) | ||
| 56 | end | ||
| 57 | return old_popen(one, two) | ||
| 58 | end | ||
| 59 | --]] | ||
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index f9ec43ba..5f7d6c37 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -106,6 +106,7 @@ end | |||
| 106 | 106 | ||
| 107 | --- Run the given command, quoting its arguments, silencing its output. | 107 | --- Run the given command, quoting its arguments, silencing its output. |
| 108 | -- The command is executed in the current directory in the dir stack. | 108 | -- The command is executed in the current directory in the dir stack. |
| 109 | -- Silencing is omitted if 'verbose' mode is enabled. | ||
| 109 | -- @param command string: The command to be executed. No quoting/escaping | 110 | -- @param command string: The command to be executed. No quoting/escaping |
| 110 | -- is applied. | 111 | -- is applied. |
| 111 | -- @param ... Strings containing additional arguments, which will be quoted. | 112 | -- @param ... Strings containing additional arguments, which will be quoted. |
| @@ -113,7 +114,7 @@ end | |||
| 113 | -- otherwise. | 114 | -- otherwise. |
| 114 | function execute_quiet(command, ...) | 115 | function execute_quiet(command, ...) |
| 115 | assert(type(command) == "string") | 116 | assert(type(command) == "string") |
| 116 | if cfg.verbose then | 117 | if cfg.verbose then -- omit silencing output |
| 117 | return fs.execute_string(quote_args(command, ...)) | 118 | return fs.execute_string(quote_args(command, ...)) |
| 118 | else | 119 | else |
| 119 | return fs.execute_string(fs.quiet(quote_args(command, ...))) | 120 | return fs.execute_string(fs.quiet(quote_args(command, ...))) |
| @@ -150,7 +151,6 @@ if lfs_ok then | |||
| 150 | -- @return boolean: true if command succeeds (status code 0), false | 151 | -- @return boolean: true if command succeeds (status code 0), false |
| 151 | -- otherwise. | 152 | -- otherwise. |
| 152 | function execute_string(cmd) | 153 | function execute_string(cmd) |
| 153 | if cfg.verbose then print("Executing: "..cmd) end | ||
| 154 | local code = os.execute(cmd) | 154 | local code = os.execute(cmd) |
| 155 | return (code == 0 or code == true) | 155 | return (code == 0 or code == true) |
| 156 | end | 156 | end |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 1d302288..0ec46314 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
| @@ -12,10 +12,6 @@ local dir_stack = {} | |||
| 12 | 12 | ||
| 13 | local vars = cfg.variables | 13 | local vars = cfg.variables |
| 14 | 14 | ||
| 15 | local function pack(...) | ||
| 16 | return { n = select("#", ...), ... } | ||
| 17 | end | ||
| 18 | |||
| 19 | --- Strip the last extension of a filename. | 15 | --- Strip the last extension of a filename. |
| 20 | -- Example: "foo.tar.gz" becomes "foo.tar". | 16 | -- Example: "foo.tar.gz" becomes "foo.tar". |
| 21 | -- If filename has no dots, returns it unchanged. | 17 | -- If filename has no dots, returns it unchanged. |
| @@ -60,16 +56,8 @@ end | |||
| 60 | -- otherwise. | 56 | -- otherwise. |
| 61 | function execute_string(cmd) | 57 | function execute_string(cmd) |
| 62 | cmd = command_at(fs.current_dir(), cmd) | 58 | cmd = command_at(fs.current_dir(), cmd) |
| 63 | if cfg.verbose then print("Executing: "..tostring(cmd)) end | 59 | local code = os.execute(cmd) |
| 64 | local code = pack(os.execute(cmd)) | 60 | if code == 0 or code == true then |
| 65 | if cfg.verbose then | ||
| 66 | print("Results: "..tostring(code.n)) | ||
| 67 | for i = 1,code.n do | ||
| 68 | print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) | ||
| 69 | end | ||
| 70 | print() | ||
| 71 | end | ||
| 72 | if code[1] == 0 or code[1] == true then | ||
| 73 | return true | 61 | return true |
| 74 | else | 62 | else |
| 75 | return false | 63 | return false |
