From 03cc9208fbeec8065365cbd5d5c124a327b47a4a Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Sun, 1 Dec 2013 10:02:57 +0100 Subject: 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 --- install.bat | 1 + src/luarocks/fs.lua | 45 ++++++++++++++++++++++++----------------- src/luarocks/fs/lua.lua | 4 ++-- 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 = { end f:write(S" LUALIB = '$LUA_LIBNAME'\n") f:write("}\n") + f:write("verbose = false -- set to 'true' to enable verbose output\n") f:close() print(S"Created LuaRocks config file: $CONFIG_FILE") 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) local cfg = require("luarocks.cfg") +local pack = table.pack or function(...) return { n = select("#", ...), ... } end +local unpack = table.unpack or unpack + +if cfg.verbose then -- patch io.popen and os.execute to display commands in verbose mode + old_popen = io.popen + io.popen = function(one, two) + if two == nil then + print("\nio.popen: ", one) + else + print("\nio.popen: ", one, "Mode:", two) + end + return old_popen(one, two) + end + + old_exec = os.execute + os.execute = function(cmd) + print("\nos.execute: ", cmd) + local code = pack(old_exec(cmd)) + print("Results: "..tostring(code.n)) + for i = 1,code.n do + print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) + end + return unpack(code, 1, code.n) + end +end + local function load_fns(fs_table) for name, fn in pairs(fs_table) do if not _M[name] then @@ -38,22 +64,3 @@ load_fns(fs_lua) local ok, fs_plat_tools = pcall(require, "luarocks.fs."..loaded_platform..".tools") if ok and fs_plat_tools then load_fns(fs_plat_tools) end --- uncomment below for further debugging than 'verbose=true' in config file --- code below will also catch commands outside of fs.execute() --- especially uses of io.popen(). ---[[ -old_exec = os.execute -os.execute = function(cmd) - print("os.execute: ", cmd) - return old_exec(cmd) -end -old_popen = io.popen -io.popen = function(one, two) - if two == nil then - print("io.popen: ", one) - else - print("io.popen: ", one, "Mode:", two) - end - return old_popen(one, two) -end ---]] 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 --- Run the given command, quoting its arguments, silencing its output. -- The command is executed in the current directory in the dir stack. +-- Silencing is omitted if 'verbose' mode is enabled. -- @param command string: The command to be executed. No quoting/escaping -- is applied. -- @param ... Strings containing additional arguments, which will be quoted. @@ -113,7 +114,7 @@ end -- otherwise. function execute_quiet(command, ...) assert(type(command) == "string") - if cfg.verbose then + if cfg.verbose then -- omit silencing output return fs.execute_string(quote_args(command, ...)) else return fs.execute_string(fs.quiet(quote_args(command, ...))) @@ -150,7 +151,6 @@ if lfs_ok then -- @return boolean: true if command succeeds (status code 0), false -- otherwise. function execute_string(cmd) - if cfg.verbose then print("Executing: "..cmd) end local code = os.execute(cmd) return (code == 0 or code == true) 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 = {} local vars = cfg.variables -local function pack(...) - return { n = select("#", ...), ... } -end - --- Strip the last extension of a filename. -- Example: "foo.tar.gz" becomes "foo.tar". -- If filename has no dots, returns it unchanged. @@ -60,16 +56,8 @@ end -- otherwise. function execute_string(cmd) cmd = command_at(fs.current_dir(), cmd) - if cfg.verbose then print("Executing: "..tostring(cmd)) end - local code = pack(os.execute(cmd)) - if cfg.verbose then - print("Results: "..tostring(code.n)) - for i = 1,code.n do - print(" "..tostring(i).." ("..type(code[i]).."): "..tostring(code[i])) - end - print() - end - if code[1] == 0 or code[1] == true then + local code = os.execute(cmd) + if code == 0 or code == true then return true else return false -- cgit v1.2.3-55-g6feb