diff options
| author | ruki <[email protected]> | 2018-11-04 22:20:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-11-04 22:20:13 +0800 |
| commit | d3d05b0c620dbfc318d4c693bc2fb7b556d51d3c (patch) | |
| tree | a91579ba8362498e531c01081d8fe80906da142d /xmake/core | |
| parent | 9d22026291016915298cd4cf8b004bef4b6faaec (diff) | |
improve diagnosis info
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/coroutine.lua | 2 | ||||
| -rw-r--r-- | xmake/core/base/task.lua | 29 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 45 | ||||
| -rw-r--r-- | xmake/core/main.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/coroutine.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/base/task.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_program.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/find_programver.lua | 8 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/try.lua | 2 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/sandbox.lua | 4 |
11 files changed, 41 insertions, 66 deletions
diff --git a/xmake/core/base/coroutine.lua b/xmake/core/base/coroutine.lua index dca56423d..651294361 100644 --- a/xmake/core/base/coroutine.lua +++ b/xmake/core/base/coroutine.lua @@ -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 diff --git a/xmake/core/base/task.lua b/xmake/core/base/task.lua index 63e00d716..b6a5d7d15 100644 --- a/xmake/core/base/task.lua +++ b/xmake/core/base/task.lua @@ -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 diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index b3f143ba3..bc1370f3a 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -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() @@ -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 diff --git a/xmake/core/main.lua b/xmake/core/main.lua index f724cfa2d..a5e7b269b 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -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() diff --git a/xmake/core/sandbox/modules/coroutine.lua b/xmake/core/sandbox/modules/coroutine.lua index 680543937..949b08ee9 100644 --- a/xmake/core/sandbox/modules/coroutine.lua +++ b/xmake/core/sandbox/modules/coroutine.lua @@ -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 diff --git a/xmake/core/sandbox/modules/import/core/base/task.lua b/xmake/core/sandbox/modules/import/core/base/task.lua index 3b33f5fbd..c0a82a784 100644 --- a/xmake/core/sandbox/modules/import/core/base/task.lua +++ b/xmake/core/sandbox/modules/import/core/base/task.lua @@ -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 diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua index dbeb4a47e..c5690dd3c 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_program.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_program.lua @@ -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? diff --git a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua index 276cd7a1d..ef616e8cd 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/find_programver.lua @@ -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"}) @@ -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 diff --git a/xmake/core/sandbox/modules/try.lua b/xmake/core/sandbox/modules/try.lua index 4b8206bc9..b257e1af8 100644 --- a/xmake/core/sandbox/modules/try.lua +++ b/xmake/core/sandbox/modules/try.lua @@ -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+: ") diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 5e3ae6113..3516c7990 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -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, ...) diff --git a/xmake/core/sandbox/sandbox.lua b/xmake/core/sandbox/sandbox.lua index 2ac54b827..d1a6c8c55 100644 --- a/xmake/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/sandbox.lua @@ -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+: ") |
