summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-02-01 22:52:27 +0800
committerruki <[email protected]>2023-02-01 22:52:27 +0800
commita4325b99fd3c359c213818f17509c5b3d3aaceb2 (patch)
treef8f57b433b3d0593fb96de039278c2c9d13e909d
parent1d5b2c93ffbd1c97d663f6d4ffcf5f9964a0b04e (diff)
show api results
-rw-r--r--xmake/plugins/check/checkers/api/api_checker.lua39
-rw-r--r--xmake/plugins/check/checkers/api/target/languages.lua2
-rw-r--r--xmake/plugins/check/main.lua8
-rw-r--r--xmake/plugins/check/xmake.lua2
4 files changed, 48 insertions, 3 deletions
diff --git a/xmake/plugins/check/checkers/api/api_checker.lua b/xmake/plugins/check/checkers/api/api_checker.lua
index d57d0f094..934f27c1a 100644
--- a/xmake/plugins/check/checkers/api/api_checker.lua
+++ b/xmake/plugins/check/checkers/api/api_checker.lua
@@ -18,5 +18,42 @@
-- @file api_checker.lua
--
-function check()
+-- imports
+import("core.base.option")
+import("core.base.hashset")
+import("core.project.project")
+
+-- show result
+function _show(apiname, value, target, opt)
+ opt = opt or {}
+
+ -- match level?
+ local level = opt.level
+ local level_option = option.get("level")
+ if level_option and level_option ~= "all" and level_option ~= level then
+ return
+ end
+
+ -- do show
+ local level_tips = "note"
+ if level == "warning" then
+ level_tips = "${color.warning}${text.warning}${clear}"
+ elseif level == "error" then
+ level_tips = "${color.error}${text.error}${clear}"
+ end
+ cprint("%s: unknown %s value(%s) in target(%s)!", level_tips, apiname, value, target:name())
+end
+
+-- check api configuration in targets
+function check_targets(apiname, opt)
+ opt = opt or {}
+ local valueset = hashset.from(opt.values)
+ for _, target in pairs(project.targets()) do
+ local values = target:get(apiname)
+ for _, value in ipairs(values) do
+ if not valueset:has(value) then
+ _show(apiname, value, target, {level = "warning"})
+ end
+ end
+ end
end
diff --git a/xmake/plugins/check/checkers/api/target/languages.lua b/xmake/plugins/check/checkers/api/target/languages.lua
index 9d6d3ca83..9831bc2f5 100644
--- a/xmake/plugins/check/checkers/api/target/languages.lua
+++ b/xmake/plugins/check/checkers/api/target/languages.lua
@@ -36,5 +36,5 @@ function main()
table.insert(languages, "gnu" .. value:sub(2))
end
end
- api_checker.check({values = languages})
+ api_checker.check_targets("languages", {values = languages})
end
diff --git a/xmake/plugins/check/main.lua b/xmake/plugins/check/main.lua
index e2479526d..da57e437d 100644
--- a/xmake/plugins/check/main.lua
+++ b/xmake/plugins/check/main.lua
@@ -21,6 +21,7 @@
-- imports
import("core.base.option")
import("core.base.text")
+import("core.project.config")
import("checker")
-- show checkers list
@@ -54,6 +55,11 @@ end
-- do check
function _check(group_or_name, arguments)
+
+ -- load config
+ config.load()
+
+ -- get checkers
local checked_checkers = {}
local checkers = checker.checkers()
if checkers[group_or_name] then
@@ -66,6 +72,8 @@ function _check(group_or_name, arguments)
end
end
assert(#checked_checkers > 0, "checker(%s) not found!", group_or_name)
+
+ -- do checkers
for _, name in ipairs(checked_checkers) do
import("checkers." .. name, {anonymous = true})(arguments)
end
diff --git a/xmake/plugins/check/xmake.lua b/xmake/plugins/check/xmake.lua
index aa3d8ab67..0aadc0c8f 100644
--- a/xmake/plugins/check/xmake.lua
+++ b/xmake/plugins/check/xmake.lua
@@ -27,7 +27,7 @@ task("check")
options = {
{'l', "list", "k", nil, "Show all supported checkers list."},
{nil, "info", "kv", nil, "Show the given checker information."},
- {nil, "level", "kv", "all", "Just show information for the given level.", values = {"warning", "error", "all"}},
+ {nil, "level", "kv", "all", "Just show information for the given level.", values = {"note", "warning", "error", "all"}},
{nil, "checkers", "v", "api", "Use the given checkers to check project.",
"e.g.",
" - xmake check api",