diff options
| author | ruki <[email protected]> | 2023-02-01 00:48:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-02-01 00:48:23 +0800 |
| commit | c638e5b6111c919b46a676f7eefcc7fead324874 (patch) | |
| tree | 6b090579059981912438ee4c1ab8ca21e823819f | |
| parent | 4a9e0dffebbd750cf0f0fa24fbed2d5307c67b90 (diff) | |
show checkers list
| -rw-r--r-- | xmake/core/project/policy.lua | 3 | ||||
| -rw-r--r-- | xmake/plugins/check/checker.lua | 60 | ||||
| -rw-r--r-- | xmake/plugins/check/main.lua | 21 | ||||
| -rw-r--r-- | xmake/plugins/check/xmake.lua | 16 |
4 files changed, 96 insertions, 4 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 86c790cd9..1a466aa68 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -33,8 +33,7 @@ local string = require("base/string") function policy.policies() local policies = policy._POLICIES if not policies then - policies = - { + policies = { -- we will check and ignore all unsupported flags by default, but we can also pass `{force = true}` to force to set flags, e.g. add_ldflags("-static", {force = true}) ["check.auto_ignore_flags"] = {description = "Enable check and ignore unsupported flags automatically.", default = true, type = "boolean"}, -- we will map gcc flags to the current compiler and linker by default. diff --git a/xmake/plugins/check/checker.lua b/xmake/plugins/check/checker.lua new file mode 100644 index 000000000..148c21059 --- /dev/null +++ b/xmake/plugins/check/checker.lua @@ -0,0 +1,60 @@ +--!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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file checker.lua +-- + +-- imports +import("core.base.option") + +-- get all checkers +function checkers() + local checkers = _g._CHECKERS + if not checkers then + checkers = { + -- target api checkers + ["api.target.languages"] = {description = "Check languages configuration in target."}, + ["api.target.packages"] = {description = "Check packages configuration in target."}, + -- clang tidy checker + ["clang.tidy"] = {description = "Check project code using clang-tidy."} + } + _g._CHECKERS = checkers + end + return checkers +end + +-- complete checkers +function complete(complete, opt) + return try + { + function () + local list = {} + for name, _ in table.orderpairs(checkers()) do + if not complete then + if #list < 16 then + table.insert(list, name) + else + table.insert(list, "...") + end + elseif k:startswith(complete) then + table.insert(list, name) + end + end + return list + end + } +end diff --git a/xmake/plugins/check/main.lua b/xmake/plugins/check/main.lua index 8b34cbcaf..4e862a6ad 100644 --- a/xmake/plugins/check/main.lua +++ b/xmake/plugins/check/main.lua @@ -20,6 +20,27 @@ -- imports import("core.base.option") +import("core.base.text") +import("checker") + +function _show_list() + local tbl = {align = 'l', sep = " "} + local checkers = checker.checkers() + local groups = {} + for name, info in table.orderpairs(checkers) do + local groupname = name:split(".", {plain = true})[1] + if not groups[groupname] then + table.insert(tbl, {}) + table.insert(tbl, {groupname:sub(1, 1):upper() .. groupname:sub(2) .. " checkers:"}) + groups[groupname] = true + end + table.insert(tbl, {{" " .. name, style = "${color.dump.string}"}, info.description}) + end + cprint(text.table(tbl)) +end function main() + if option.get("list") then + return _show_list() + end end diff --git a/xmake/plugins/check/xmake.lua b/xmake/plugins/check/xmake.lua index 38fe742ba..aa3d8ab67 100644 --- a/xmake/plugins/check/xmake.lua +++ b/xmake/plugins/check/xmake.lua @@ -27,8 +27,20 @@ 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 = {"warn", "error", "all"}}, - {nil, "checkers", "vs", nil, "Use the given checkers to check project."} + {nil, "level", "kv", "all", "Just show information for the given level.", values = {"warning", "error", "all"}}, + {nil, "checkers", "v", "api", "Use the given checkers to check project.", + "e.g.", + " - xmake check api", + " - xmake check --level=error api.target", + " - xmake check api.target.languages", + "", + "The supported checkers list:", + values = function (complete, opt) + return import("plugins.check.checker", {rootdir = os.programdir()}).complete(complete, opt) + end}, + {nil, "arguments", "vs", nil, "Set the checker arguments.", + "e.g.", + " - xmake check clang.tidy [arguments]"} } } |
