diff options
| author | ruki <[email protected]> | 2020-05-13 22:49:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-13 10:55:19 +0800 |
| commit | fca9ba9a046d4b6fc940b6a147528921a41e02a7 (patch) | |
| tree | 92ebbc3656f662492d37fa47fe80153528fc9dd6 | |
| parent | 33049b3e71655463b5975d9992cf9db6f0c5c693 (diff) | |
add wprint
| -rw-r--r-- | xmake/core/base/deprecated.lua | 43 | ||||
| -rw-r--r-- | xmake/core/base/utils.lua | 35 | ||||
| -rw-r--r-- | xmake/core/main.lua | 9 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/utils.lua | 5 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/wprint.lua | 23 |
5 files changed, 62 insertions, 53 deletions
diff --git a/xmake/core/base/deprecated.lua b/xmake/core/base/deprecated.lua index ec9ebacab..1d41389d8 100644 --- a/xmake/core/base/deprecated.lua +++ b/xmake/core/base/deprecated.lua @@ -24,46 +24,13 @@ local deprecated = deprecated or {} -- add deprecated entry function deprecated.add(newformat, oldformat, ...) - -- the entries - deprecated._ENTRIES = deprecated._ENTRIES or {} - - -- the old and new entries + local utils = require("base/utils") local old = string.format(oldformat, ...) local new = newformat and string.format(newformat, ...) or false - - -- add it - deprecated._ENTRIES[old] = new -end - --- dump all deprecated entries -function deprecated.dump() - - -- lazy load modules to avoid loop - local utils = require("base/utils") - local option = require("base/option") - - -- dump one or more .. - local index = 0 - deprecated._ENTRIES = deprecated._ENTRIES or {} - for old, new in pairs(deprecated._ENTRIES) do - - -- trace - if index == 0 then - print("") - end - - -- show more? - if not option.get("verbose") and index > 0 then - utils.cprint("${bright color.warning}deprecated:${clear} add -v for getting more ..") - break - end - - if new then - utils.cprint("${bright color.warning}deprecated:${clear} please uses %s instead of %s", new, old) - else - utils.cprint("${bright color.warning}deprecated:${clear} please remove %s", old) - end - index = index + 1 + if new then + utils.warning("%s is deprecated, please uses %s instead of it", old, new) + else + utils.warning("%s is deprecated, please remove it", old) end end diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index 605a4d028..d19be86b7 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -235,27 +235,42 @@ function utils.error(format, ...) end end --- the warning function +-- add warning message function utils.warning(format, ...) -- check assert(format) -- format message - local msg = "${bright color.warning}${text.warning}: ${color.warning}" .. string.tryformat(format, ...) + local args = table.pack(...) + local msg = (args.n > 0 and string.tryformat(format, ...) or format) -- init warnings - utils._WARNINGS = utils._WARNINGS or {} local warnings = utils._WARNINGS - - -- trace only once - if not warnings[msg] then - utils.cprint(msg) - warnings[msg] = true + if not warnings then + warnings = {} + utils._WARNINGS = warnings end - -- flush - log:flush() + -- add warning msg + table.insert(warnings, msg) +end + +-- show warnings +function utils.show_warnings() + local warnings = utils._WARNINGS + if warnings then + for idx, msg in ipairs(table.unique(warnings)) do + if idx == 1 then + print("") + end + if not option.get("verbose") and idx > 1 then + utils.cprint("${bright color.warning}${text.warning}: ${color.warning}add -v for getting more warnings ..") + break + end + utils.cprint("${bright color.warning}${text.warning}: ${color.warning}%s", msg) + end + end end -- ifelse, a? b : c diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 11dd59ec8..63270ee15 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -29,7 +29,6 @@ local utils = require("base/utils") local option = require("base/option") local table = require("base/table") local global = require("base/global") -local deprecated = require("base/deprecated") local privilege = require("base/privilege") local task = require("base/task") local colors = require("base/colors") @@ -206,6 +205,9 @@ function main._exit(errors) utils.error(errors) end + -- show warnings + utils.show_warnings() + -- close log log:close() @@ -286,10 +288,7 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily. if not ok then return main._exit(errors) end - - -- dump deprecated entries - deprecated.dump() - + -- stop profiling -- profiler:stop() diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua index 485622336..0440667b0 100644 --- a/xmake/core/sandbox/modules/utils.lua +++ b/xmake/core/sandbox/modules/utils.lua @@ -167,6 +167,11 @@ function sandbox_utils.dprintf(format, ...) end end +-- print the warning information +function sandbox_utils.wprint(format, ...) + utils.warning(vformat(format, ...)) +end + -- clear the current terminal line function sandbox_utils.clearline() diff --git a/xmake/core/sandbox/modules/wprint.lua b/xmake/core/sandbox/modules/wprint.lua new file mode 100644 index 000000000..360743a7d --- /dev/null +++ b/xmake/core/sandbox/modules/wprint.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file wprint.lua +-- + +-- load module +return require("sandbox/modules/utils").wprint + |
