Skip to content

Commit

Permalink
improve diagnosis info
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Nov 4, 2018
1 parent 9d22026 commit d3d05b0
Show file tree
Hide file tree
Showing 20 changed files with 62 additions and 85 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@
* Improve compilation dependences
* Support *.xz for extractor
* [#249](https://github.com/tboox/xmake/pull/249): revise progress formatting to space-leading three digit percentages
* [#247](https://github.com/tboox/xmake/pull/247): Add `-D` and `--diagnosis` instead of `--backtrace`

## v2.2.2

Expand Down Expand Up @@ -511,6 +512,7 @@
* 改进编译依赖,对源文件列表的改动进行依赖判断
* 支持解压*.xz文件
* [#249](https://github.com/tboox/xmake/pull/249): 改进编译进度信息显示格式
* [#247](https://github.com/tboox/xmake/pull/247): 添加`-D``--diagnosis`去替换`--backtrace`,改进诊断信息显示

## v2.2.2

Expand Down
2 changes: 1 addition & 1 deletion xmake/actions/build/statistics.lua
Expand Up @@ -74,7 +74,7 @@ function post()

-- init argument list
local argv = {"lua", path.join(os.scriptdir(), "statistics.lua")}
for _, name in ipairs({"root", "file", "project", "backtrace", "verbose", "quiet", "yes"}) do
for _, name in ipairs({"root", "file", "project", "diagnosis", "verbose", "quiet", "yes"}) do
local value = option.get(name)
if type(value) == "string" then
table.insert(argv, "--" .. name .. "=" .. value)
Expand Down
2 changes: 1 addition & 1 deletion xmake/actions/config/main.lua
Expand Up @@ -47,7 +47,7 @@ function _option_filter(name)
, profile = true
, project = true
, verbose = true
, backtrace = true
, diagnosis = true
, require = true
}
return not options[name]
Expand Down
2 changes: 1 addition & 1 deletion xmake/actions/config/menuconf.lua
Expand Up @@ -84,7 +84,7 @@ function app:_filter_option(name)
, profile = true
, project = true
, verbose = true
, backtrace = true
, diagnosis = true
, require = true
, version = true
, help = true
Expand Down
2 changes: 1 addition & 1 deletion xmake/core/base/coroutine.lua
Expand Up @@ -42,7 +42,7 @@ function coroutine.resume(co, ...)

-- get errors
local errors = results
if option.get("backtrace") then
if option.get("diagnosis") then
errors = debug.traceback(co, results)
elseif type(results) == "string" then
-- remove the prefix info
Expand Down
29 changes: 16 additions & 13 deletions xmake/core/base/task.lua
Expand Up @@ -130,22 +130,25 @@ function task._translate_menu(menu)
end

-- add common options
table.insert(options, 1, {'q', "quiet", "k", nil, "Quiet operation." })
table.insert(options, 2, {'y', "yes", "k", nil, "Input yes by default if need user confirm." })
table.insert(options, 3, {'v', "verbose", "k", nil, "Print lots of verbose information." })
table.insert(options, 4, {nil, "root", "k", nil, "Allow to run xmake as root." })
table.insert(options, 5, {nil, "backtrace", "k", nil, "Print backtrace information for debugging." })
table.insert(options, 6, {nil, "profile", "k", nil, "Print performance data for debugging." })
table.insert(options, 7, {nil, "version", "k", nil, "Print the version number and exit." })
table.insert(options, 8, {'h', "help", "k", nil, "Print this help message and exit." })
table.insert(options, 9, {})
table.insert(options, 10, {'F', "file", "kv", nil, "Read a given xmake.lua file." })
table.insert(options, 11, {'P', "project", "kv", nil, "Change to the given project directory."
table.insert(options, 1, {'q', "quiet", "k", nil, "Quiet operation." })
table.insert(options, 2, {'y', "yes", "k", nil, "Input yes by default if need user confirm." })
table.insert(options, 3, {'v', "verbose", "k", nil, "Print lots of verbose information for users." })
table.insert(options, 4, {nil, "root", "k", nil, "Allow to run xmake as root." })
table.insert(options, 5, {'D', "diagnosis", "k", nil, "Print lots of diagnosis information (backtrace, check info ..) only for developers."
, "And we can append -v to get more whole information."
, " e.g. $ xmake -v -D"})
table.insert(options, 6, {nil, "profile", "k", nil, "Print performance data only for developers." })
table.insert(options, 7, {nil, "version", "k", nil, "Print the version number and exit." })
table.insert(options, 8, {'h', "help", "k", nil, "Print this help message and exit." })
table.insert(options, 9, {nil, "backtrace", "k", nil, "Please uses -D or --diagnosis instead of it. (deprecated)"})
table.insert(options, 10, {})
table.insert(options, 11, {'F', "file", "kv", nil, "Read a given xmake.lua file." })
table.insert(options, 12, {'P', "project", "kv", nil, "Change to the given project directory."
, "Search priority:"
, " 1. The Given Command Argument"
, " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
, " 3. The Current Directory" })
table.insert(options, 12, {})
, " 3. The Current Directory" })
table.insert(options, 13, {})

end

Expand Down
45 changes: 6 additions & 39 deletions xmake/core/base/utils.lua
Expand Up @@ -133,29 +133,22 @@ function utils.cprintf(format, ...)
end
end

-- the verbose function
function utils.verbose(format, ...)

-- enable verbose?
-- print the verbose information
function utils.vprint(format, ...)
if option.get("verbose") and format ~= nil then
utils.print(format, ...)
end
end

-- the verbose error function
function utils.verror(format, ...)

-- enable verbose?
-- print the verbose information without newline
function utils.vprintf(format, ...)
if option.get("verbose") and format ~= nil then
utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...))
log:flush()
utils.printf(format, ...)
end
end

-- the error function
-- print the error information
function utils.error(format, ...)

-- trace
if format ~= nil then
utils.cprint("${bright red}error: ${clear}" .. string.tryformat(format, ...))
log:flush()
Expand Down Expand Up @@ -190,31 +183,5 @@ function utils.ifelse(a, b, c)
if a then return b else return c end
end

-- call functions
function utils.call(funcs, pred, ...)

-- check
assert(funcs)

-- call all
for _, func in ipairs(table.wrap(funcs)) do

-- check
assert(type(func) == "function")

-- call it
local result = func(...)

-- exists predicate?
if pred and type(pred) == "function" then
if not pred(name, result) then return false end
-- failed?
elseif not result then return false end
end

-- ok
return true
end

-- return module
return utils
5 changes: 5 additions & 0 deletions xmake/core/main.lua
Expand Up @@ -197,6 +197,11 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily.
end
end

-- check deprecated options, TODO it will be removed after v2.3.0
if option.get("backtrace") then
deprecated.add("-D or --diagnosis", "--backtrace")
end

-- start profiling
if option.get("profile") then
profiler:start()
Expand Down
2 changes: 1 addition & 1 deletion xmake/core/sandbox/modules/coroutine.lua
Expand Up @@ -45,7 +45,7 @@ function sandbox_coroutine.resume(co, ...)

-- get errors
local errors = results
if option.get("backtrace") then
if option.get("diagnosis") then
errors = debug.traceback(co, results)
elseif type(results) == "string" then
-- remove the prefix info
Expand Down
2 changes: 1 addition & 1 deletion xmake/core/sandbox/modules/import/core/base/task.lua
Expand Up @@ -42,7 +42,7 @@ function sandbox_core_base_task.run(taskname, options, ...)
options = table.wrap(options)

-- inherit some parent options
for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet", "yes", "root", "profile"}) do
for _, name in ipairs({"file", "project", "diagnosis", "verbose", "quiet", "yes", "root", "profile"}) do
if not options[name] and option.get(name) then
options[name] = option.get(name)
end
Expand Down
4 changes: 2 additions & 2 deletions xmake/core/sandbox/modules/import/lib/detect/find_program.lua
Expand Up @@ -69,8 +69,8 @@ function sandbox_lib_detect_find_program._check(program, opt)
end

-- check failed? print verbose error info
if not ok then
utils.verror(errors)
if not ok and option.get("diagnosis") then
utils.cprint("${yellow}checkinfo: ${clear dim}" .. errors)
end

-- ok?
Expand Down
Expand Up @@ -77,8 +77,8 @@ function sandbox_lib_detect_find_programver.main(program, opt)
local command = opt.command
if type(command) == "function" then
ok, outdata = sandbox.load(command)
if not ok then
utils.verror(outdata)
if not ok and outdata and option.get("diagnosis") then
utils.cprint("${yellow}checkinfo: ${clear dim}" .. outdata)
end
else
ok, outdata = os.iorunv(program, {command or "--version"})
Expand All @@ -89,8 +89,8 @@ function sandbox_lib_detect_find_programver.main(program, opt)
local parse = opt.parse
if type(parse) == "function" then
ok, result = sandbox.load(parse, outdata)
if not ok then
utils.verror(result)
if not ok and result and option.get("diagnosis") then
utils.cprint("${yellow}checkinfo: ${clear dim}" .. result)
result = nil
end
elseif parse == nil or type(parse) == "string" then
Expand Down
2 changes: 1 addition & 1 deletion xmake/core/sandbox/modules/try.lua
Expand Up @@ -35,7 +35,7 @@ local sandbox_try = sandbox_try or {}
function sandbox_try._traceback(errors)

-- not verbose?
if not option.get("backtrace") then
if not option.get("diagnosis") then
if errors then
-- remove the prefix info
local _, pos = errors:find(":%d+: ")
Expand Down
4 changes: 2 additions & 2 deletions xmake/core/sandbox/modules/utils.lua
Expand Up @@ -143,14 +143,14 @@ function sandbox_utils.cprintf(format, ...)
end
end

-- print() if enable verbose
-- print the verbose information
function sandbox_utils.vprint(format, ...)
if option.get("verbose") then
sandbox_utils.print(format, ...)
end
end

-- vprintf() if enable verbose
-- print the verbose information without newline
function sandbox_utils.vprintf(format, ...)
if option.get("verbose") then
sandbox_utils.printf(format, ...)
Expand Down
4 changes: 2 additions & 2 deletions xmake/core/sandbox/sandbox.lua
Expand Up @@ -36,8 +36,8 @@ local option = require("base/option")
-- traceback
function sandbox._traceback(errors)

-- not verbose?
if not option.get("backtrace") then
-- only print error info without backtrace if not diagnosis?
if not option.get("diagnosis") then
if errors then
-- remove the prefix info
local _, pos = errors:find(":%d+: ")
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/core/tools/gcc.lua
Expand Up @@ -491,7 +491,7 @@ function _compile1(self, sourcefile, objectfile, dependinfo, flags)
function (ok, warnings)

-- print some warnings
if warnings and #warnings > 0 and (option.get("verbose") or option.get("warning")) then
if warnings and #warnings > 0 and (option.get("diagnosis") or option.get("warning")) then
cprint("${yellow}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
end
end
Expand Down
8 changes: 4 additions & 4 deletions xmake/modules/lib/detect/check_cxsnippets.lua
Expand Up @@ -197,7 +197,7 @@ function main(snippets, opt)
os.tryrm(binaryfile)

-- trace
if opt.verbose or option.get("verbose") then
if opt.verbose or option.get("verbose") or option.get("diagnosis") then
local kind = ifelse(sourcekind == "cc", "c", "c++")
if #includes > 0 then
cprint("checking for the %s includes %s ... %s", kind, table.concat(includes, ", "), ifelse(ok, "${green}ok", "${red}no"))
Expand All @@ -214,9 +214,9 @@ function main(snippets, opt)
for _, snippet in ipairs(snippets) do
cprint("checking for the %s snippet %s ... %s", kind, snippet:sub(1, 16), ifelse(ok, "${green}ok", "${red}no"))
end
if errors and #errors > 0 then
cprint("${dim red}check error:${clear}${dim} %s", errors)
end
end
if errors and #errors > 0 and option.get("diagnosis") then
cprint("${yellow}checkinfo:${clear dim} %s", errors)
end

-- ok?
Expand Down
8 changes: 4 additions & 4 deletions xmake/modules/lib/detect/has_flags.lua
Expand Up @@ -115,11 +115,11 @@ function main(name, flags, opt)
_g._checking = nil

-- trace
if option.get("verbose") or opt.verbose then
if option.get("verbose") or option.get("diagnosis") or opt.verbose then
cprint("checking for the flags(%s) %s ... %s", path.filename(tool.program), table.concat(flags, " "), ifelse(result, "${green}ok", "${red}no"))
if errors and #errors > 0 then
cprint("${dim red}check error:${clear}${dim} %s", errors:trim())
end
end
if errors and #errors > 0 and option.get("diagnosis") then
cprint("${yellow}checkinfo:${clear dim} %s", errors:trim())
end

-- save result to cache
Expand Down
12 changes: 6 additions & 6 deletions xmake/modules/package/tools/xmake.lua
Expand Up @@ -54,8 +54,8 @@ function install(package, configs)
if option.get("verbose") then
table.insert(argv, "-v")
end
if option.get("backtrace") then
table.insert(argv, "--backtrace")
if option.get("diagnosis") then
table.insert(argv, "--diagnosis")
end
os.vrunv("xmake", argv)

Expand All @@ -64,8 +64,8 @@ function install(package, configs)
if option.get("verbose") then
table.insert(argv, "-v")
end
if option.get("backtrace") then
table.insert(argv, "--backtrace")
if option.get("diagnosis") then
table.insert(argv, "--diagnosis")
end
os.vrunv("xmake", argv)

Expand All @@ -74,8 +74,8 @@ function install(package, configs)
if option.get("verbose") then
table.insert(argv, "-v")
end
if option.get("backtrace") then
table.insert(argv, "--backtrace")
if option.get("diagnosis") then
table.insert(argv, "--diagnosis")
end
os.vrunv("xmake", argv)
end
2 changes: 1 addition & 1 deletion xmake/modules/privilege/sudo.lua
Expand Up @@ -79,7 +79,7 @@ function _lua(runner, luafile, luaargv)

-- init argv
local argv = {"lua", "--root"}
for _, name in ipairs({"file", "project", "backtrace", "verbose", "quiet", "yes"}) do
for _, name in ipairs({"file", "project", "diagnosis", "verbose", "quiet", "yes"}) do
local value = option.get(name)
if type(value) == "string" then
table.insert(argv, "--" .. name .. "=" .. value)
Expand Down

0 comments on commit d3d05b0

Please sign in to comment.