diff options
| author | ruki <[email protected]> | 2023-02-02 22:32:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-02-02 22:32:04 +0800 |
| commit | 947a170bddb00dd99ee332f6cd14443efcce0f59 (patch) | |
| tree | b39e348ef84cb209826b9c7b4bf8131a45a1ee45 | |
| parent | dd97043117dfb6e6b634574137e95a800d774afd (diff) | |
add version checker
| -rw-r--r-- | xmake/plugins/check/checker.lua | 1 | ||||
| -rw-r--r-- | xmake/plugins/check/checkers/api/api_checker.lua | 27 | ||||
| -rw-r--r-- | xmake/plugins/check/checkers/api/target/version.lua | 41 |
3 files changed, 63 insertions, 6 deletions
diff --git a/xmake/plugins/check/checker.lua b/xmake/plugins/check/checker.lua index fb3cf11b7..6a5f6276d 100644 --- a/xmake/plugins/check/checker.lua +++ b/xmake/plugins/check/checker.lua @@ -27,6 +27,7 @@ function checkers() if not checkers then checkers = { -- target api checkers + ["api.target.version"] = {description = "Check version configuration in target."}, ["api.target.languages"] = {description = "Check languages configuration in target."}, ["api.target.packages"] = {description = "Check packages configuration in target."}, -- clang tidy checker diff --git a/xmake/plugins/check/checkers/api/api_checker.lua b/xmake/plugins/check/checkers/api/api_checker.lua index ba7e81255..52a494a47 100644 --- a/xmake/plugins/check/checkers/api/api_checker.lua +++ b/xmake/plugins/check/checkers/api/api_checker.lua @@ -70,10 +70,17 @@ function _show(apiname, value, target, opt) end _g.showed = _g.showed or {} local showed = _g.showed - local infostr = string.format("%s%s: unknown %s value '%s'", sourcetips, level_tips, apiname, value) - local probable_value = _get_most_probable_value(value, opt.valueset) - if probable_value then - infostr = string.format("%s, it may be '%s'", infostr, probable_value) + local infostr + if opt.showstr then + infostr = string.format("%s%s: %s", sourcetips, level_tips, opt.showstr) + else + infostr = string.format("%s%s: unknown %s value '%s'", sourcetips, level_tips, apiname, value) + end + if opt.valueset then + local probable_value = _get_most_probable_value(value, opt.valueset) + if probable_value then + infostr = string.format("%s, it may be '%s'", infostr, probable_value) + end end if not showed[infostr] then cprint(infostr) @@ -86,11 +93,19 @@ end function check_targets(apiname, opt) opt = opt or {} local level = opt.level or "warning" - local valueset = hashset.from(opt.values) + local valueset = opt.values and hashset.from(opt.values) or hashset.new() for _, target in pairs(project.targets()) do local values = target:get(apiname) for _, value in ipairs(values) do - if not valueset:has(value) then + if opt.check then + local ok, errors = opt.check(target, value) + if not ok then + local reported = _show(apiname, value, target, {showstr = errors, level = level}) + if reported then + checker.update_stats(level) + end + end + elseif not valueset:has(value) then local reported = _show(apiname, value, target, {valueset = valueset, level = level}) if reported then checker.update_stats(level) diff --git a/xmake/plugins/check/checkers/api/target/version.lua b/xmake/plugins/check/checkers/api/target/version.lua new file mode 100644 index 000000000..d4759aee4 --- /dev/null +++ b/xmake/plugins/check/checkers/api/target/version.lua @@ -0,0 +1,41 @@ +--!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 packages.lua +-- + +-- imports +import("core.base.semver") +import(".api_checker") + +function main() + api_checker.check_targets("version", {check = function(target, value) + local errors + local ok = try { + function() + semver.new(value) + return true + end, + catch { + function (errs) + errors = errs + end + } + } + return ok, errors + end, level = "error"}) +end |
