From 1ceae4d5e4b2786c395a705f7c89601e6ef8aedc Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:45:39 +0800 Subject: check targets in rule --- xmake/plugins/check/checkers/api/api_checker.lua | 114 +++++++++++++-------- .../check/checkers/api/target/includedirs.lua | 7 +- xmake/rules/utils/check_targets/check_targets.lua | 45 +++++--- 3 files changed, 108 insertions(+), 58 deletions(-) diff --git a/xmake/plugins/check/checkers/api/api_checker.lua b/xmake/plugins/check/checkers/api/api_checker.lua index 60bdeac8c..79e4809bd 100644 --- a/xmake/plugins/check/checkers/api/api_checker.lua +++ b/xmake/plugins/check/checkers/api/api_checker.lua @@ -38,6 +38,25 @@ function _get_most_probable_value(value, valueset) return result end +function _do_show(str, opt) + _g.showed = _g.showed or {} + local showed = _g.showed + local infostr + if str then + infostr = string.format("%s: %s: %s", opt.sourcetips, opt.level_tips, str) + else + infostr = string.format("%s: %s: unknown %s value '%s'", opt.sourcetips, opt.level_tips, opt.apiname, opt.value) + end + if opt.probable_value then + infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value) + end + if not showed[infostr] then + cprint(infostr) + showed[infostr] = true + return true + end +end + -- show result function _show(apiname, value, target, opt) opt = opt or {} @@ -52,40 +71,70 @@ function _show(apiname, value, target, opt) local sourceinfo = target:sourceinfo(apiname, value) or {} local sourcetips = sourceinfo.file or "" if sourceinfo.line then - sourcetips = sourcetips .. ":" .. (sourceinfo.line or -1) .. ": " + sourcetips = sourcetips .. ":" .. (sourceinfo.line or -1) end if #sourcetips == 0 then sourcetips = string.format("target(%s)", target:name()) end - -- do show + -- get level tips 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 + + -- get probable value + local probable_value + if opt.valueset then + probable_value = _get_most_probable_value(value, opt.valueset) + end + if apiname:endswith("s") then apiname = apiname:sub(1, #apiname - 1) end - _g.showed = _g.showed or {} - local showed = _g.showed - 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) + + -- do show + return (opt.show or _do_show)(opt.showstr, { + apiname = apiname, + sourcetips = sourcetips, + level_tips = level_tips, + value = value, + probable_value = probable_value}) +end + +-- check target +function _check_target(target, apiname, valueset, level, opt) + local target_valueset = valueset + if type(opt.values) == "function" then + local target_values = opt.values(target) + if target_values then + target_valueset = hashset.from(target_values) end end - if not showed[infostr] then - cprint(infostr) - showed[infostr] = true - return true + local values = target:get(apiname) + for _, value in ipairs(values) do + if opt.check then + local ok, errors = opt.check(target, value) + if not ok then + local reported = _show(apiname, value, target, { + show = opt.show, + showstr = errors, + level = level}) + if reported then + checker.update_stats(level) + end + end + elseif not target_valueset:has(value) then + local reported = _show(apiname, value, target, { + show = opt.show, + valueset = target_valueset, + level = level}) + if reported then + checker.update_stats(level) + end + end end end @@ -99,30 +148,11 @@ function check_targets(apiname, opt) else valueset = hashset.new() end - for _, target in pairs(project.targets()) do - local target_valueset = valueset - if type(opt.values) == "function" then - local target_values = opt.values(target) - if target_values then - target_valueset = hashset.from(target_values) - end - end - local values = target:get(apiname) - for _, value in ipairs(values) do - 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 target_valueset:has(value) then - local reported = _show(apiname, value, target, {valueset = target_valueset, level = level}) - if reported then - checker.update_stats(level) - end - end + if opt.target then + _check_target(opt.target, apiname, valueset, level, opt) + else + for _, target in pairs(project.targets()) do + _check_target(target, apiname, valueset, level, opt) end end end diff --git a/xmake/plugins/check/checkers/api/target/includedirs.lua b/xmake/plugins/check/checkers/api/target/includedirs.lua index 5fcafef0f..a78431fef 100644 --- a/xmake/plugins/check/checkers/api/target/includedirs.lua +++ b/xmake/plugins/check/checkers/api/target/includedirs.lua @@ -21,11 +21,12 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("includedirs", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("includedirs", table.join(opt, {check = function(target, value) if not os.isdir(value) then return false, string.format("includedir '%s' not found", value) end return true - end}) + end})) end diff --git a/xmake/rules/utils/check_targets/check_targets.lua b/xmake/rules/utils/check_targets/check_targets.lua index a5073cfa0..803466dfa 100644 --- a/xmake/rules/utils/check_targets/check_targets.lua +++ b/xmake/rules/utils/check_targets/check_targets.lua @@ -18,22 +18,41 @@ -- @file check_targets.lua -- --- get values from target -function _get_values_from_target(target, name) - local values = table.wrap(target:get(name)) - table.join2(values, target:get_from_opts(name)) - table.join2(values, target:get_from_pkgs(name)) - return values +import("plugins.check.checker", {rootdir = os.programdir()}) + +function _show(str, opt) + _g.showed = _g.showed or {} + local showed = _g.showed + local infostr + if str then + infostr = string.format("%s${clear}: %s", opt.sourcetips, str) + else + infostr = string.format("%s${clear}: unknown %s value '%s'", opt.sourcetips, opt.apiname, opt.value) + end + if opt.probable_value then + infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value) + end + if not showed[infostr] then + wprint(infostr) + showed[infostr] = true + end end --- main entry function main(target) - for _, name in ipairs({"includedirs", "frameworkdirs", "linkdirs"}) do - for _, value in ipairs(_get_values_from_target(target, name)) do - if not os.isdir(value) then - local sourceinfo = target:sourceinfo(name, value) or {} - wprint("%s:%d: %s '%s' not found in %s(%s)", sourceinfo.file or "", sourceinfo.line or -1, name, value, target:type(), target:name()) - end + + -- get checkers + local checked_checkers = {} + local checkers = checker.checkers() + for name, _ in table.orderpairs(checkers) do + if name:startswith("api.target.") then + table.insert(checked_checkers, name) end end + + -- do checkers + for _, name in ipairs(checked_checkers) do + local info = checkers[name] + import("plugins.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ + target = target, show = _show}) + end end -- cgit v1.3.1 From 2e04812cae7e38d9b097b40cce90b34ec6fb8fca Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:47:16 +0800 Subject: improve target checkers --- xmake/plugins/check/checkers/api/target/asflags.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/cflags.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/configfiles.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/cxflags.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/cxxflags.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/exceptions.lua | 5 +++-- xmake/plugins/check/checkers/api/target/files.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/fpmodels.lua | 5 +++-- xmake/plugins/check/checkers/api/target/frameworkdirs.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/headerfiles.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/installfiles.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/kind.lua | 5 +++-- xmake/plugins/check/checkers/api/target/languages.lua | 5 +++-- xmake/plugins/check/checkers/api/target/ldflags.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/linkdirs.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/optimize.lua | 5 +++-- xmake/plugins/check/checkers/api/target/packages.lua | 5 +++-- xmake/plugins/check/checkers/api/target/shflags.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/strip.lua | 5 +++-- xmake/plugins/check/checkers/api/target/symbols.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/vectorexts.lua | 5 +++-- xmake/plugins/check/checkers/api/target/version.lua | 7 ++++--- xmake/plugins/check/checkers/api/target/warnings.lua | 5 +++-- 23 files changed, 83 insertions(+), 60 deletions(-) diff --git a/xmake/plugins/check/checkers/api/target/asflags.lua b/xmake/plugins/check/checkers/api/target/asflags.lua index ad98a329b..07de9c4ec 100644 --- a/xmake/plugins/check/checkers/api/target/asflags.lua +++ b/xmake/plugins/check/checkers/api/target/asflags.lua @@ -22,12 +22,13 @@ import("core.tool.compiler") import(".api_checker") -function main() - api_checker.check_targets("asflags", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("asflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("as") if not compinst:has_flags(value) then return false, string.format("%s: unknown assembler flag '%s'", compinst:name(), value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/cflags.lua b/xmake/plugins/check/checkers/api/target/cflags.lua index df9a34830..db35a7bcf 100644 --- a/xmake/plugins/check/checkers/api/target/cflags.lua +++ b/xmake/plugins/check/checkers/api/target/cflags.lua @@ -22,12 +22,13 @@ import("core.tool.compiler") import(".api_checker") -function main() - api_checker.check_targets("cflags", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("cflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("cc") if not compinst:has_flags(value) then return false, string.format("%s: unknown c compiler flag '%s'", compinst:name(), value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/configfiles.lua b/xmake/plugins/check/checkers/api/target/configfiles.lua index 5819278c0..a8965eebe 100644 --- a/xmake/plugins/check/checkers/api/target/configfiles.lua +++ b/xmake/plugins/check/checkers/api/target/configfiles.lua @@ -21,12 +21,13 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("configfiles", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("configfiles", table.join(opt, {check = function(target, value) local configfiles = os.files(value) if not configfiles or #configfiles == 0 then return false, string.format("configfiles '%s' not found", value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/cxflags.lua b/xmake/plugins/check/checkers/api/target/cxflags.lua index 9c8df747a..ba09366e0 100644 --- a/xmake/plugins/check/checkers/api/target/cxflags.lua +++ b/xmake/plugins/check/checkers/api/target/cxflags.lua @@ -22,12 +22,13 @@ import("core.tool.compiler") import(".api_checker") -function main() - api_checker.check_targets("cxflags", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("cxflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("cxx") if not compinst:has_flags(value) then return false, string.format("%s: unknown c/c++ compiler flag '%s'", compinst:name(), value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/cxxflags.lua b/xmake/plugins/check/checkers/api/target/cxxflags.lua index 6756b07d4..84660cfa4 100644 --- a/xmake/plugins/check/checkers/api/target/cxxflags.lua +++ b/xmake/plugins/check/checkers/api/target/cxxflags.lua @@ -22,12 +22,13 @@ import("core.tool.compiler") import(".api_checker") -function main() - api_checker.check_targets("cxxflags", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("cxxflags", table.join(opt, {check = function(target, value) local compinst = target:compiler("cxx") if not compinst:has_flags(value) then return false, string.format("%s: unknown c++ compiler flag '%s'", compinst:name(), value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/exceptions.lua b/xmake/plugins/check/checkers/api/target/exceptions.lua index 551595e7b..e9570a894 100644 --- a/xmake/plugins/check/checkers/api/target/exceptions.lua +++ b/xmake/plugins/check/checkers/api/target/exceptions.lua @@ -21,6 +21,7 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("exceptions", {values = {"none", "cxx", "objc", "no-cxx", "no-objc"}}) +function main(opt) + opt = opt or {} + api_checker.check_targets("exceptions", table.join(opt, {values = {"none", "cxx", "objc", "no-cxx", "no-objc"}})) end diff --git a/xmake/plugins/check/checkers/api/target/files.lua b/xmake/plugins/check/checkers/api/target/files.lua index dfc4eda89..a523a7413 100644 --- a/xmake/plugins/check/checkers/api/target/files.lua +++ b/xmake/plugins/check/checkers/api/target/files.lua @@ -21,12 +21,13 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("files", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("files", table.join(opt, {check = function(target, value) local files = os.files(value) if not files or #files == 0 then return false, string.format("files '%s' not found", value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/fpmodels.lua b/xmake/plugins/check/checkers/api/target/fpmodels.lua index 25c6c239b..61231109e 100644 --- a/xmake/plugins/check/checkers/api/target/fpmodels.lua +++ b/xmake/plugins/check/checkers/api/target/fpmodels.lua @@ -21,6 +21,7 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("fpmodels", {values = {"none", "precise", "fast", "strict", "except", "noexcept"}}) +function main(opt) + opt = opt or {} + api_checker.check_targets("fpmodels", table.join(opt, {values = {"none", "precise", "fast", "strict", "except", "noexcept"}})) end diff --git a/xmake/plugins/check/checkers/api/target/frameworkdirs.lua b/xmake/plugins/check/checkers/api/target/frameworkdirs.lua index f21629fe5..088aa7114 100644 --- a/xmake/plugins/check/checkers/api/target/frameworkdirs.lua +++ b/xmake/plugins/check/checkers/api/target/frameworkdirs.lua @@ -21,11 +21,12 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("frameworkdirs", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("frameworkdirs", table.join(opt, {check = function(target, value) if not os.isdir(value) then return false, string.format("frameworkdir '%s' not found", value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/headerfiles.lua b/xmake/plugins/check/checkers/api/target/headerfiles.lua index 5777f27f8..af262b91c 100644 --- a/xmake/plugins/check/checkers/api/target/headerfiles.lua +++ b/xmake/plugins/check/checkers/api/target/headerfiles.lua @@ -21,13 +21,14 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("headerfiles", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("headerfiles", table.join(opt, {check = function(target, value) value = value:gsub("[()]", "") local headerfiles = os.files(value) if not headerfiles or #headerfiles == 0 then return false, string.format("headerfiles '%s' not found", value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/installfiles.lua b/xmake/plugins/check/checkers/api/target/installfiles.lua index cdf0a927e..7a294f60f 100644 --- a/xmake/plugins/check/checkers/api/target/installfiles.lua +++ b/xmake/plugins/check/checkers/api/target/installfiles.lua @@ -21,13 +21,14 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("installfiles", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("installfiles", table.join(opt, {check = function(target, value) value = value:gsub("[()]", "") local installfiles = os.files(value) if not installfiles or #installfiles == 0 then return false, string.format("installfiles '%s' not found", value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/kind.lua b/xmake/plugins/check/checkers/api/target/kind.lua index e84bf890d..127f78ad5 100644 --- a/xmake/plugins/check/checkers/api/target/kind.lua +++ b/xmake/plugins/check/checkers/api/target/kind.lua @@ -21,6 +21,7 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("kind", {values = {"object", "binary", "static", "shared", "headeronly", "phony"}}) +function main(opt) + opt = opt or {} + api_checker.check_targets("kind", table.join(opt, {values = {"object", "binary", "static", "shared", "headeronly", "phony"}})) end diff --git a/xmake/plugins/check/checkers/api/target/languages.lua b/xmake/plugins/check/checkers/api/target/languages.lua index 9831bc2f5..f01499225 100644 --- a/xmake/plugins/check/checkers/api/target/languages.lua +++ b/xmake/plugins/check/checkers/api/target/languages.lua @@ -21,7 +21,8 @@ -- imports import(".api_checker") -function main() +function main(opt) + opt = opt or {} local values = { "ansi", "c89", "c90", "c99", "c11", "c17", "clatest", "cxx98", "cxx11", "cxx14", "cxx17", "cxx1z", "cxx20", "cxx2a", "cxx23", "cxx2b", "cxxlatest" @@ -36,5 +37,5 @@ function main() table.insert(languages, "gnu" .. value:sub(2)) end end - api_checker.check_targets("languages", {values = languages}) + api_checker.check_targets("languages", table.join(opt, {values = languages})) end diff --git a/xmake/plugins/check/checkers/api/target/ldflags.lua b/xmake/plugins/check/checkers/api/target/ldflags.lua index efe176aa5..e06d5bb09 100644 --- a/xmake/plugins/check/checkers/api/target/ldflags.lua +++ b/xmake/plugins/check/checkers/api/target/ldflags.lua @@ -22,8 +22,9 @@ import("core.tool.compiler") import(".api_checker") -function main() - api_checker.check_targets("ldflags", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("ldflags", table.join(opt, {check = function(target, value) if target:is_binary() then local linker = target:linker() if not linker:has_flags(value) then @@ -31,5 +32,5 @@ function main() end end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/linkdirs.lua b/xmake/plugins/check/checkers/api/target/linkdirs.lua index 3980f2eae..3f05bfa16 100644 --- a/xmake/plugins/check/checkers/api/target/linkdirs.lua +++ b/xmake/plugins/check/checkers/api/target/linkdirs.lua @@ -21,11 +21,12 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("linkdirs", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("linkdirs", table.join(opt, {check = function(target, value) if not os.isdir(value) then return false, string.format("linkdir '%s' not found", value) end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/optimize.lua b/xmake/plugins/check/checkers/api/target/optimize.lua index c8bc6eb60..99731ba19 100644 --- a/xmake/plugins/check/checkers/api/target/optimize.lua +++ b/xmake/plugins/check/checkers/api/target/optimize.lua @@ -21,6 +21,7 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("optimize", {values = {"none", "fast", "faster", "fastest", "smallest", "aggressive"}}) +function main(opt) + opt = opt or {} + api_checker.check_targets("optimize", table.join(opt, {values = {"none", "fast", "faster", "fastest", "smallest", "aggressive"}})) end diff --git a/xmake/plugins/check/checkers/api/target/packages.lua b/xmake/plugins/check/checkers/api/target/packages.lua index e34f602db..994ea5c2a 100644 --- a/xmake/plugins/check/checkers/api/target/packages.lua +++ b/xmake/plugins/check/checkers/api/target/packages.lua @@ -22,11 +22,12 @@ import("core.project.project") import(".api_checker") -function main() +function main(opt) + opt = opt or {} local packages = {} local requires = project.required_packages() if requires then table.join2(packages, table.orderkeys(requires)) end - api_checker.check_targets("packages", {values = packages, level = "note"}) + api_checker.check_targets("packages", table.join(opt, {values = packages, level = "note"})) end diff --git a/xmake/plugins/check/checkers/api/target/shflags.lua b/xmake/plugins/check/checkers/api/target/shflags.lua index bb518015a..20b2f6a05 100644 --- a/xmake/plugins/check/checkers/api/target/shflags.lua +++ b/xmake/plugins/check/checkers/api/target/shflags.lua @@ -22,8 +22,9 @@ import("core.tool.compiler") import(".api_checker") -function main() - api_checker.check_targets("shflags", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("shflags", table.join(opt, {check = function(target, value) if target:is_shared() then local linker = target:linker() if not linker:has_flags(value) then @@ -31,5 +32,5 @@ function main() end end return true - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/strip.lua b/xmake/plugins/check/checkers/api/target/strip.lua index cf14c607b..c6074bc12 100644 --- a/xmake/plugins/check/checkers/api/target/strip.lua +++ b/xmake/plugins/check/checkers/api/target/strip.lua @@ -21,6 +21,7 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("strip", {values = {"none", "debug", "all"}}) +function main(opt) + opt = opt or {} + api_checker.check_targets("strip", table.join(opt, {values = {"none", "debug", "all"}})) end diff --git a/xmake/plugins/check/checkers/api/target/symbols.lua b/xmake/plugins/check/checkers/api/target/symbols.lua index 8f4472a9b..839bd0ede 100644 --- a/xmake/plugins/check/checkers/api/target/symbols.lua +++ b/xmake/plugins/check/checkers/api/target/symbols.lua @@ -21,13 +21,14 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("symbols", {values = function (target) +function main(opt) + opt = opt or {} + api_checker.check_targets("symbols", table.join(opt, {values = function (target) local values = {"none", "debug", "hidden", "hidden_cxx"} if target:is_plat("windows") and (target:has_tool("cc", "cl") or target:has_tool("cxx", "cl")) then table.insert(values, "edit") table.insert(values, "embed") end return values - end}) + end})) end diff --git a/xmake/plugins/check/checkers/api/target/vectorexts.lua b/xmake/plugins/check/checkers/api/target/vectorexts.lua index dc6a1a755..77f9ee48c 100644 --- a/xmake/plugins/check/checkers/api/target/vectorexts.lua +++ b/xmake/plugins/check/checkers/api/target/vectorexts.lua @@ -21,6 +21,7 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("vectorexts", {values = {"none", "sse", "sse2", "sse3", "ssse3", "avx", "avx2", "neon"}}) +function main(opt) + opt = opt or {} + api_checker.check_targets("vectorexts", table.join(opt, {values = {"none", "sse", "sse2", "sse3", "ssse3", "avx", "avx2", "neon"}})) end diff --git a/xmake/plugins/check/checkers/api/target/version.lua b/xmake/plugins/check/checkers/api/target/version.lua index e476cd8d4..889864f5b 100644 --- a/xmake/plugins/check/checkers/api/target/version.lua +++ b/xmake/plugins/check/checkers/api/target/version.lua @@ -22,8 +22,9 @@ import("core.base.semver") import(".api_checker") -function main() - api_checker.check_targets("version", {check = function(target, value) +function main(opt) + opt = opt or {} + api_checker.check_targets("version", table.join(opt, {check = function(target, value) local errors local ok = try { function() @@ -37,5 +38,5 @@ function main() } } return ok, errors - end, level = "error"}) + end, level = "error"})) end diff --git a/xmake/plugins/check/checkers/api/target/warnings.lua b/xmake/plugins/check/checkers/api/target/warnings.lua index 2d2159e91..4e6cf5794 100644 --- a/xmake/plugins/check/checkers/api/target/warnings.lua +++ b/xmake/plugins/check/checkers/api/target/warnings.lua @@ -21,6 +21,7 @@ -- imports import(".api_checker") -function main() - api_checker.check_targets("warnings", {values = {"none", "less", "more", "all", "allextra", "everything", "error"}}) +function main(opt) + opt = opt or {} + api_checker.check_targets("warnings", table.join(opt, {values = {"none", "less", "more", "all", "allextra", "everything", "error"}})) end -- cgit v1.3.1 From 0975a3fd60b71a31806a51f3556201f107a33d2e Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:48:59 +0800 Subject: add more timely checkers --- xmake/core/project/target.lua | 4 ++-- xmake/plugins/check/checker.lua | 24 +++++++++++------------ xmake/rules/utils/check_targets/check_targets.lua | 17 ++++------------ 3 files changed, 18 insertions(+), 27 deletions(-) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 7e07503c8..79c5f0546 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1381,7 +1381,7 @@ function _instance:fileconfig(sourcefile) local results = os.match(filepath) if #results == 0 and not fileconfig.always_added then local sourceinfo = self:sourceinfo("files", filepath) or {} - utils.warning("%s:%d: cannot match add_files(\"%s\") in %s(%s)", sourceinfo.file or "", sourceinfo.line or -1, filepath, self:type(), self:name()) + utils.warning("%s:%d${clear}: cannot match add_files(\"%s\") in %s(%s)", sourceinfo.file or "", sourceinfo.line or -1, filepath, self:type(), self:name()) end -- process source files @@ -1505,7 +1505,7 @@ function _instance:sourcefiles() end if #results == 0 then local sourceinfo = self:sourceinfo("files", file) or {} - utils.warning("%s:%d: cannot match %s_files(\"%s\") in %s(%s)", sourceinfo.file or "", sourceinfo.line or -1, (removed and "remove" or "add"), file, self:type(), self:name()) + utils.warning("%s:%d${clear}: cannot match %s_files(\"%s\") in %s(%s)", sourceinfo.file or "", sourceinfo.line or -1, (removed and "remove" or "add"), file, self:type(), self:name()) end -- process source files diff --git a/xmake/plugins/check/checker.lua b/xmake/plugins/check/checker.lua index a6b8bb995..e80050849 100644 --- a/xmake/plugins/check/checker.lua +++ b/xmake/plugins/check/checker.lua @@ -28,23 +28,23 @@ function checkers() checkers = { -- target api checkers ["api.target.version"] = {description = "Check version configuration in target."}, - ["api.target.kind"] = {description = "Check kind configuration in target."}, - ["api.target.strip"] = {description = "Check strip configuration in target."}, - ["api.target.optimize"] = {description = "Check optimize configuration in target."}, - ["api.target.symbols"] = {description = "Check symbols configuration in target."}, - ["api.target.fpmodels"] = {description = "Check fpmodels configuration in target."}, - ["api.target.warnings"] = {description = "Check warnings configuration in target."}, - ["api.target.languages"] = {description = "Check languages configuration in target."}, - ["api.target.vectorexts"] = {description = "Check vectorexts configuration in target."}, - ["api.target.exceptions"] = {description = "Check exceptions configuration in target."}, + ["api.target.kind"] = {description = "Check kind configuration in target.", timely = true}, + ["api.target.strip"] = {description = "Check strip configuration in target.", timely = true}, + ["api.target.optimize"] = {description = "Check optimize configuration in target.", timely = true}, + ["api.target.symbols"] = {description = "Check symbols configuration in target.", timely = true}, + ["api.target.fpmodels"] = {description = "Check fpmodels configuration in target.", timely = true}, + ["api.target.warnings"] = {description = "Check warnings configuration in target.", timely = true}, + ["api.target.languages"] = {description = "Check languages configuration in target.", timely = true}, + ["api.target.vectorexts"] = {description = "Check vectorexts configuration in target.", timely = true}, + ["api.target.exceptions"] = {description = "Check exceptions configuration in target.", timely = true}, ["api.target.packages"] = {description = "Check packages configuration in target."}, ["api.target.files"] = {description = "Check files configuration in target."}, ["api.target.headerfiles"] = {description = "Check header files configuration in target."}, ["api.target.installfiles"] = {description = "Check install files configuration in target."}, ["api.target.configfiles"] = {description = "Check config files configuration in target."}, - ["api.target.linkdirs"] = {description = "Check linkdirs configuration in target."}, - ["api.target.includedirs"] = {description = "Check includedirs configuration in target."}, - ["api.target.frameworkdirs"] = {description = "Check frameworkdirs configuration in target."}, + ["api.target.linkdirs"] = {description = "Check linkdirs configuration in target.", timely = true}, + ["api.target.includedirs"] = {description = "Check includedirs configuration in target.", timely = true}, + ["api.target.frameworkdirs"] = {description = "Check frameworkdirs configuration in target.", timely = true}, ["api.target.cflags"] = {description = "Check c compiler flags configuration in target."}, ["api.target.cxflags"] = {description = "Check c/c++ compiler flags configuration in target."}, ["api.target.cxxflags"] = {description = "Check c++ compiler flags configuration in target."}, diff --git a/xmake/rules/utils/check_targets/check_targets.lua b/xmake/rules/utils/check_targets/check_targets.lua index 803466dfa..a32f757ea 100644 --- a/xmake/rules/utils/check_targets/check_targets.lua +++ b/xmake/rules/utils/check_targets/check_targets.lua @@ -39,20 +39,11 @@ function _show(str, opt) end function main(target) - - -- get checkers - local checked_checkers = {} local checkers = checker.checkers() - for name, _ in table.orderpairs(checkers) do - if name:startswith("api.target.") then - table.insert(checked_checkers, name) + for name, info in table.orderpairs(checkers) do + if name:startswith("api.target.") and info.timely then + import("plugins.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ + target = target, show = _show}) end end - - -- do checkers - for _, name in ipairs(checked_checkers) do - local info = checkers[name] - import("plugins.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ - target = target, show = _show}) - end end -- cgit v1.3.1 From 5ffe5163eb24e95943410e193afb4569e4464fb1 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:49:42 +0800 Subject: improve checker list --- xmake/rules/utils/check_targets/check_targets.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xmake/rules/utils/check_targets/check_targets.lua b/xmake/rules/utils/check_targets/check_targets.lua index a32f757ea..cf15eac39 100644 --- a/xmake/rules/utils/check_targets/check_targets.lua +++ b/xmake/rules/utils/check_targets/check_targets.lua @@ -41,7 +41,8 @@ end function main(target) local checkers = checker.checkers() for name, info in table.orderpairs(checkers) do - if name:startswith("api.target.") and info.timely then + -- just do some faster checkers + if info.timely then import("plugins.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ target = target, show = _show}) end -- cgit v1.3.1 From f3ee66f6c97ec3c4963aaf12b4b87891b27ad972 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:50:41 +0800 Subject: add devlink checker stub --- xmake/plugins/check/checker.lua | 2 ++ xmake/plugins/check/checkers/cuda/devlink.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 xmake/plugins/check/checkers/cuda/devlink.lua diff --git a/xmake/plugins/check/checker.lua b/xmake/plugins/check/checker.lua index e80050849..f599b69ca 100644 --- a/xmake/plugins/check/checker.lua +++ b/xmake/plugins/check/checker.lua @@ -51,6 +51,8 @@ function checkers() ["api.target.asflags"] = {description = "Check assembler flags configuration in target."}, ["api.target.ldflags"] = {description = "Check binary linker flags configuration in target."}, ["api.target.shflags"] = {description = "Check shared library linker flags configuration in target."}, + -- cuda checkers + ["cuda.devlink"] = {description = "Check devlink for targets.", timely = true}, -- clang tidy checker ["clang.tidy"] = {description = "Check project code using clang-tidy.", showstats = false} } diff --git a/xmake/plugins/check/checkers/cuda/devlink.lua b/xmake/plugins/check/checkers/cuda/devlink.lua new file mode 100644 index 000000000..a2b29cd3b --- /dev/null +++ b/xmake/plugins/check/checkers/cuda/devlink.lua @@ -0,0 +1,27 @@ +--!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 devlink.lua +-- + +-- imports +import("core.base.option") + +function main(opt) + print("devlink") +end + -- cgit v1.3.1 From fea53d6126d9685ae5736743d92e6cb3b0470497 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:54:41 +0800 Subject: implement cuda devlink checker --- xmake/plugins/check/checkers/cuda/devlink.lua | 26 +++++++++++++++++++++++++- xmake/rules/cuda/env/xmake.lua | 5 +++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/xmake/plugins/check/checkers/cuda/devlink.lua b/xmake/plugins/check/checkers/cuda/devlink.lua index a2b29cd3b..fee6bb637 100644 --- a/xmake/plugins/check/checkers/cuda/devlink.lua +++ b/xmake/plugins/check/checkers/cuda/devlink.lua @@ -20,8 +20,32 @@ -- imports import("core.base.option") +import("core.project.project") + +-- https://github.com/xmake-io/xmake/issues/1976#issuecomment-1427378799 +function _check_target(target, opt) + if target:is_binary() then + local sourcebatches = target:sourcebatches() + if sourcebatches and not sourcebatches["cuda.build"] then + for _, dep in ipairs(target:orderdeps()) do + if dep:is_static() then + sourcebatches = dep:sourcebatches() + if sourcebatches and sourcebatches["cuda.build"] and not dep:values("cuda.build.devlink") then + wprint('target(%s)${clear}: cuda device link is not performed! specify set_values("cuda.build.devlink", true) to enable it', dep:name()) + end + end + end + end + end +end function main(opt) - print("devlink") + if opt.target then + _check_target(opt.target, opt) + else + for _, target in pairs(project.targets()) do + _check_target(target, opt) + end + end end diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index d36482901..559774466 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -23,16 +23,17 @@ rule("cuda.env") on_load(function (target) import("detect.sdks.find_cuda") - + --[[ local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK not found!") if cuda then target:data_set("cuda", cuda) - end + end]] end) after_load(function (target) import("core.platform.platform") + if true then return end -- get cuda sdk local cuda = assert(target:data("cuda"), "Cuda SDK not found!") -- cgit v1.3.1 From 5678e3f25fdeb5dc94b0ac6ad8db1fee0385daf6 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:56:50 +0800 Subject: use devlink policy --- xmake/core/project/policy.lua | 2 ++ xmake/plugins/check/checkers/cuda/devlink.lua | 7 +++++-- xmake/plugins/project/cmake/cmakelists.lua | 2 +- xmake/plugins/project/vstudio/impl/vs201x.lua | 2 +- xmake/rules/cuda/devlink/xmake.lua | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua index 52f13c9b7..56fbc2219 100644 --- a/xmake/core/project/policy.lua +++ b/xmake/core/project/policy.lua @@ -60,6 +60,8 @@ function policy.policies() ["build.c++.msvc.fallbackscanner"] = {description = "Force msvc fallback module dependency scanner.", default = false, type = "boolean"}, -- force C++ modules fallback dependency scanner for gcc ["build.c++.gcc.fallbackscanner"] = {description = "Force gcc fallback module dependency scanner.", default = false, type = "boolean"}, + -- enable cuda device link + ["build.cuda.devlink"] = {description = "Enable Cuda devlink.", type = "boolean"}, -- preprocessor configuration for ccache/distcc, we can disable linemarkers to speed up preprocess ["preprocessor.linemarkers"] = {description = "Enable linemarkers for preprocessor.", default = true, type = "boolean"}, -- preprocessor configuration for ccache/distcc, we can disable it to avoid cache object file with __DATE__, __TIME__ diff --git a/xmake/plugins/check/checkers/cuda/devlink.lua b/xmake/plugins/check/checkers/cuda/devlink.lua index fee6bb637..4281b5a8d 100644 --- a/xmake/plugins/check/checkers/cuda/devlink.lua +++ b/xmake/plugins/check/checkers/cuda/devlink.lua @@ -30,8 +30,11 @@ function _check_target(target, opt) for _, dep in ipairs(target:orderdeps()) do if dep:is_static() then sourcebatches = dep:sourcebatches() - if sourcebatches and sourcebatches["cuda.build"] and not dep:values("cuda.build.devlink") then - wprint('target(%s)${clear}: cuda device link is not performed! specify set_values("cuda.build.devlink", true) to enable it', dep:name()) + if sourcebatches and sourcebatches["cuda.build"] then + local devlink = dep:policy("build.cuda.devlink") or dep:values("cuda.build.devlink") + if not devlink then + wprint('target(%s)${clear}: cuda device link is not performed! specify set_policy("build.cuda.devlink", true) to enable it', dep:name()) + end end end end diff --git a/xmake/plugins/project/cmake/cmakelists.lua b/xmake/plugins/project/cmake/cmakelists.lua index 945b280bd..b3d614985 100644 --- a/xmake/plugins/project/cmake/cmakelists.lua +++ b/xmake/plugins/project/cmake/cmakelists.lua @@ -345,7 +345,7 @@ function _add_target_sources(cmakelists, target, outputdir) cmakelists:print(")") if has_cuda then cmakelists:print("set_target_properties(%s PROPERTIES CUDA_SEPARABLE_COMPILATION ON)", target:name()) - local devlink = target:values("cuda.build.devlink") + local devlink = target:policy("build.cuda.devlink") or target:values("cuda.build.devlink") if devlink ~= nil then cmakelists:print("set_target_properties(%s PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS %s)", target:name(), devlink and "ON" or "OFF") end diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 3ba257720..4811a0f74 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -316,7 +316,7 @@ function _make_targetinfo(mode, arch, target, vcxprojdir) targetinfo.culinkflags = linkinst:linkflags({target = target}) -- save cuda devlink status - targetinfo.cudevlink = target:values("cuda.build.devlink") + targetinfo.cudevlink = target:policy("build.cuda.devlink") or target:values("cuda.build.devlink") end -- save execution dir (when executed from VS) diff --git a/xmake/rules/cuda/devlink/xmake.lua b/xmake/rules/cuda/devlink/xmake.lua index da3bf8aef..b04acc883 100644 --- a/xmake/rules/cuda/devlink/xmake.lua +++ b/xmake/rules/cuda/devlink/xmake.lua @@ -37,7 +37,7 @@ rule("cuda.build.devlink") import("utils.progress") -- disable devlink? - local devlink = target:values("cuda.build.devlink") + local devlink = target:policy("build.cuda.devlink") or target:values("cuda.build.devlink") if devlink == false then return end -- cgit v1.3.1 From 27c69b5a6b23f1b597c320a6404c4612c6625cf3 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Feb 2023 22:57:01 +0800 Subject: add comment --- xmake/rules/cuda/devlink/xmake.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xmake/rules/cuda/devlink/xmake.lua b/xmake/rules/cuda/devlink/xmake.lua index b04acc883..0e0a513df 100644 --- a/xmake/rules/cuda/devlink/xmake.lua +++ b/xmake/rules/cuda/devlink/xmake.lua @@ -37,6 +37,9 @@ rule("cuda.build.devlink") import("utils.progress") -- disable devlink? + -- + -- @note cuda.build.devlink value will be deprecated + -- local devlink = target:policy("build.cuda.devlink") or target:values("cuda.build.devlink") if devlink == false then return -- cgit v1.3.1 From 52272f424a743e905b2817148caad12538d39ebc Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 21 Feb 2023 00:41:15 +0800 Subject: revert cuda --- xmake/rules/cuda/env/xmake.lua | 4 +- xmake/rules/utils/check_targets/check_targets.lua | 50 ----------------------- xmake/rules/utils/check_targets/checker.lua | 50 +++++++++++++++++++++++ xmake/rules/utils/check_targets/xmake.lua | 6 ++- 4 files changed, 55 insertions(+), 55 deletions(-) delete mode 100644 xmake/rules/utils/check_targets/check_targets.lua create mode 100644 xmake/rules/utils/check_targets/checker.lua diff --git a/xmake/rules/cuda/env/xmake.lua b/xmake/rules/cuda/env/xmake.lua index 559774466..cb4833dd3 100644 --- a/xmake/rules/cuda/env/xmake.lua +++ b/xmake/rules/cuda/env/xmake.lua @@ -23,17 +23,15 @@ rule("cuda.env") on_load(function (target) import("detect.sdks.find_cuda") - --[[ local cuda = assert(find_cuda(nil, {verbose = true}), "Cuda SDK not found!") if cuda then target:data_set("cuda", cuda) - end]] + end end) after_load(function (target) import("core.platform.platform") - if true then return end -- get cuda sdk local cuda = assert(target:data("cuda"), "Cuda SDK not found!") diff --git a/xmake/rules/utils/check_targets/check_targets.lua b/xmake/rules/utils/check_targets/check_targets.lua deleted file mode 100644 index cf15eac39..000000000 --- a/xmake/rules/utils/check_targets/check_targets.lua +++ /dev/null @@ -1,50 +0,0 @@ ---!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 check_targets.lua --- - -import("plugins.check.checker", {rootdir = os.programdir()}) - -function _show(str, opt) - _g.showed = _g.showed or {} - local showed = _g.showed - local infostr - if str then - infostr = string.format("%s${clear}: %s", opt.sourcetips, str) - else - infostr = string.format("%s${clear}: unknown %s value '%s'", opt.sourcetips, opt.apiname, opt.value) - end - if opt.probable_value then - infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value) - end - if not showed[infostr] then - wprint(infostr) - showed[infostr] = true - end -end - -function main(target) - local checkers = checker.checkers() - for name, info in table.orderpairs(checkers) do - -- just do some faster checkers - if info.timely then - import("plugins.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ - target = target, show = _show}) - end - end -end diff --git a/xmake/rules/utils/check_targets/checker.lua b/xmake/rules/utils/check_targets/checker.lua new file mode 100644 index 000000000..70b21450b --- /dev/null +++ b/xmake/rules/utils/check_targets/checker.lua @@ -0,0 +1,50 @@ +--!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 check_targets.lua +-- + +import("plugins.check.checker", {rootdir = os.programdir()}) + +function _show(str, opt) + _g.showed = _g.showed or {} + local showed = _g.showed + local infostr + if str then + infostr = string.format("%s${clear}: %s", opt.sourcetips, str) + else + infostr = string.format("%s${clear}: unknown %s value '%s'", opt.sourcetips, opt.apiname, opt.value) + end + if opt.probable_value then + infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value) + end + if not showed[infostr] then + wprint(infostr) + showed[infostr] = true + end +end + +function check_target(target) + local checkers = checker.checkers() + for name, info in table.orderpairs(checkers) do + -- just do some faster checkers + if info.timely then + import("plugins.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ + target = target, show = _show}) + end + end +end diff --git a/xmake/rules/utils/check_targets/xmake.lua b/xmake/rules/utils/check_targets/xmake.lua index c14d4854e..553678793 100644 --- a/xmake/rules/utils/check_targets/xmake.lua +++ b/xmake/rules/utils/check_targets/xmake.lua @@ -18,7 +18,9 @@ -- @file xmake.lua -- --- define rule: utils.check.targets rule("utils.check.targets") - before_build("check_targets") + add_deps("utils.check.project") + before_build(function (target) + import("checker").check_target(target) + end) -- cgit v1.3.1 From 559f90b555e5227716a6762d545c9c2171fef55c Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 21 Feb 2023 00:41:27 +0800 Subject: remove unused deps --- xmake/rules/utils/check_targets/xmake.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/xmake/rules/utils/check_targets/xmake.lua b/xmake/rules/utils/check_targets/xmake.lua index 553678793..35f58bc37 100644 --- a/xmake/rules/utils/check_targets/xmake.lua +++ b/xmake/rules/utils/check_targets/xmake.lua @@ -19,7 +19,6 @@ -- rule("utils.check.targets") - add_deps("utils.check.project") before_build(function (target) import("checker").check_target(target) end) -- cgit v1.3.1 From e0ac2fd899e03be83ad506616e0dab931ea69969 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 21 Feb 2023 00:43:15 +0800 Subject: move checker --- xmake/modules/private/check/checker.lua | 105 ++++++++++++ .../private/check/checkers/api/api_checker.lua | 158 ++++++++++++++++++ .../private/check/checkers/api/target/asflags.lua | 34 ++++ .../private/check/checkers/api/target/cflags.lua | 34 ++++ .../check/checkers/api/target/configfiles.lua | 33 ++++ .../private/check/checkers/api/target/cxflags.lua | 34 ++++ .../private/check/checkers/api/target/cxxflags.lua | 34 ++++ .../check/checkers/api/target/exceptions.lua | 27 ++++ .../private/check/checkers/api/target/files.lua | 33 ++++ .../private/check/checkers/api/target/fpmodels.lua | 27 ++++ .../check/checkers/api/target/frameworkdirs.lua | 32 ++++ .../check/checkers/api/target/headerfiles.lua | 34 ++++ .../check/checkers/api/target/includedirs.lua | 32 ++++ .../check/checkers/api/target/installfiles.lua | 34 ++++ .../private/check/checkers/api/target/kind.lua | 27 ++++ .../check/checkers/api/target/languages.lua | 41 +++++ .../private/check/checkers/api/target/ldflags.lua | 36 +++++ .../private/check/checkers/api/target/linkdirs.lua | 32 ++++ .../private/check/checkers/api/target/optimize.lua | 27 ++++ .../private/check/checkers/api/target/packages.lua | 33 ++++ .../private/check/checkers/api/target/shflags.lua | 36 +++++ .../private/check/checkers/api/target/strip.lua | 27 ++++ .../private/check/checkers/api/target/symbols.lua | 34 ++++ .../check/checkers/api/target/vectorexts.lua | 27 ++++ .../private/check/checkers/api/target/version.lua | 42 +++++ .../private/check/checkers/api/target/warnings.lua | 27 ++++ .../modules/private/check/checkers/clang/tidy.lua | 179 +++++++++++++++++++++ .../private/check/checkers/cuda/devlink.lua | 54 +++++++ xmake/plugins/check/checker.lua | 105 ------------ xmake/plugins/check/checkers/api/api_checker.lua | 158 ------------------ .../plugins/check/checkers/api/target/asflags.lua | 34 ---- xmake/plugins/check/checkers/api/target/cflags.lua | 34 ---- .../check/checkers/api/target/configfiles.lua | 33 ---- .../plugins/check/checkers/api/target/cxflags.lua | 34 ---- .../plugins/check/checkers/api/target/cxxflags.lua | 34 ---- .../check/checkers/api/target/exceptions.lua | 27 ---- xmake/plugins/check/checkers/api/target/files.lua | 33 ---- .../plugins/check/checkers/api/target/fpmodels.lua | 27 ---- .../check/checkers/api/target/frameworkdirs.lua | 32 ---- .../check/checkers/api/target/headerfiles.lua | 34 ---- .../check/checkers/api/target/includedirs.lua | 32 ---- .../check/checkers/api/target/installfiles.lua | 34 ---- xmake/plugins/check/checkers/api/target/kind.lua | 27 ---- .../check/checkers/api/target/languages.lua | 41 ----- .../plugins/check/checkers/api/target/ldflags.lua | 36 ----- .../plugins/check/checkers/api/target/linkdirs.lua | 32 ---- .../plugins/check/checkers/api/target/optimize.lua | 27 ---- .../plugins/check/checkers/api/target/packages.lua | 33 ---- .../plugins/check/checkers/api/target/shflags.lua | 36 ----- xmake/plugins/check/checkers/api/target/strip.lua | 27 ---- .../plugins/check/checkers/api/target/symbols.lua | 34 ---- .../check/checkers/api/target/vectorexts.lua | 27 ---- .../plugins/check/checkers/api/target/version.lua | 42 ----- .../plugins/check/checkers/api/target/warnings.lua | 27 ---- xmake/plugins/check/checkers/clang/tidy.lua | 179 --------------------- xmake/plugins/check/checkers/cuda/devlink.lua | 54 ------- xmake/plugins/check/main.lua | 4 +- xmake/rules/utils/check_targets/checker.lua | 4 +- 58 files changed, 1277 insertions(+), 1277 deletions(-) create mode 100644 xmake/modules/private/check/checker.lua create mode 100644 xmake/modules/private/check/checkers/api/api_checker.lua create mode 100644 xmake/modules/private/check/checkers/api/target/asflags.lua create mode 100644 xmake/modules/private/check/checkers/api/target/cflags.lua create mode 100644 xmake/modules/private/check/checkers/api/target/configfiles.lua create mode 100644 xmake/modules/private/check/checkers/api/target/cxflags.lua create mode 100644 xmake/modules/private/check/checkers/api/target/cxxflags.lua create mode 100644 xmake/modules/private/check/checkers/api/target/exceptions.lua create mode 100644 xmake/modules/private/check/checkers/api/target/files.lua create mode 100644 xmake/modules/private/check/checkers/api/target/fpmodels.lua create mode 100644 xmake/modules/private/check/checkers/api/target/frameworkdirs.lua create mode 100644 xmake/modules/private/check/checkers/api/target/headerfiles.lua create mode 100644 xmake/modules/private/check/checkers/api/target/includedirs.lua create mode 100644 xmake/modules/private/check/checkers/api/target/installfiles.lua create mode 100644 xmake/modules/private/check/checkers/api/target/kind.lua create mode 100644 xmake/modules/private/check/checkers/api/target/languages.lua create mode 100644 xmake/modules/private/check/checkers/api/target/ldflags.lua create mode 100644 xmake/modules/private/check/checkers/api/target/linkdirs.lua create mode 100644 xmake/modules/private/check/checkers/api/target/optimize.lua create mode 100644 xmake/modules/private/check/checkers/api/target/packages.lua create mode 100644 xmake/modules/private/check/checkers/api/target/shflags.lua create mode 100644 xmake/modules/private/check/checkers/api/target/strip.lua create mode 100644 xmake/modules/private/check/checkers/api/target/symbols.lua create mode 100644 xmake/modules/private/check/checkers/api/target/vectorexts.lua create mode 100644 xmake/modules/private/check/checkers/api/target/version.lua create mode 100644 xmake/modules/private/check/checkers/api/target/warnings.lua create mode 100644 xmake/modules/private/check/checkers/clang/tidy.lua create mode 100644 xmake/modules/private/check/checkers/cuda/devlink.lua delete mode 100644 xmake/plugins/check/checker.lua delete mode 100644 xmake/plugins/check/checkers/api/api_checker.lua delete mode 100644 xmake/plugins/check/checkers/api/target/asflags.lua delete mode 100644 xmake/plugins/check/checkers/api/target/cflags.lua delete mode 100644 xmake/plugins/check/checkers/api/target/configfiles.lua delete mode 100644 xmake/plugins/check/checkers/api/target/cxflags.lua delete mode 100644 xmake/plugins/check/checkers/api/target/cxxflags.lua delete mode 100644 xmake/plugins/check/checkers/api/target/exceptions.lua delete mode 100644 xmake/plugins/check/checkers/api/target/files.lua delete mode 100644 xmake/plugins/check/checkers/api/target/fpmodels.lua delete mode 100644 xmake/plugins/check/checkers/api/target/frameworkdirs.lua delete mode 100644 xmake/plugins/check/checkers/api/target/headerfiles.lua delete mode 100644 xmake/plugins/check/checkers/api/target/includedirs.lua delete mode 100644 xmake/plugins/check/checkers/api/target/installfiles.lua delete mode 100644 xmake/plugins/check/checkers/api/target/kind.lua delete mode 100644 xmake/plugins/check/checkers/api/target/languages.lua delete mode 100644 xmake/plugins/check/checkers/api/target/ldflags.lua delete mode 100644 xmake/plugins/check/checkers/api/target/linkdirs.lua delete mode 100644 xmake/plugins/check/checkers/api/target/optimize.lua delete mode 100644 xmake/plugins/check/checkers/api/target/packages.lua delete mode 100644 xmake/plugins/check/checkers/api/target/shflags.lua delete mode 100644 xmake/plugins/check/checkers/api/target/strip.lua delete mode 100644 xmake/plugins/check/checkers/api/target/symbols.lua delete mode 100644 xmake/plugins/check/checkers/api/target/vectorexts.lua delete mode 100644 xmake/plugins/check/checkers/api/target/version.lua delete mode 100644 xmake/plugins/check/checkers/api/target/warnings.lua delete mode 100644 xmake/plugins/check/checkers/clang/tidy.lua delete mode 100644 xmake/plugins/check/checkers/cuda/devlink.lua diff --git a/xmake/modules/private/check/checker.lua b/xmake/modules/private/check/checker.lua new file mode 100644 index 000000000..f599b69ca --- /dev/null +++ b/xmake/modules/private/check/checker.lua @@ -0,0 +1,105 @@ +--!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.version"] = {description = "Check version configuration in target."}, + ["api.target.kind"] = {description = "Check kind configuration in target.", timely = true}, + ["api.target.strip"] = {description = "Check strip configuration in target.", timely = true}, + ["api.target.optimize"] = {description = "Check optimize configuration in target.", timely = true}, + ["api.target.symbols"] = {description = "Check symbols configuration in target.", timely = true}, + ["api.target.fpmodels"] = {description = "Check fpmodels configuration in target.", timely = true}, + ["api.target.warnings"] = {description = "Check warnings configuration in target.", timely = true}, + ["api.target.languages"] = {description = "Check languages configuration in target.", timely = true}, + ["api.target.vectorexts"] = {description = "Check vectorexts configuration in target.", timely = true}, + ["api.target.exceptions"] = {description = "Check exceptions configuration in target.", timely = true}, + ["api.target.packages"] = {description = "Check packages configuration in target."}, + ["api.target.files"] = {description = "Check files configuration in target."}, + ["api.target.headerfiles"] = {description = "Check header files configuration in target."}, + ["api.target.installfiles"] = {description = "Check install files configuration in target."}, + ["api.target.configfiles"] = {description = "Check config files configuration in target."}, + ["api.target.linkdirs"] = {description = "Check linkdirs configuration in target.", timely = true}, + ["api.target.includedirs"] = {description = "Check includedirs configuration in target.", timely = true}, + ["api.target.frameworkdirs"] = {description = "Check frameworkdirs configuration in target.", timely = true}, + ["api.target.cflags"] = {description = "Check c compiler flags configuration in target."}, + ["api.target.cxflags"] = {description = "Check c/c++ compiler flags configuration in target."}, + ["api.target.cxxflags"] = {description = "Check c++ compiler flags configuration in target."}, + ["api.target.asflags"] = {description = "Check assembler flags configuration in target."}, + ["api.target.ldflags"] = {description = "Check binary linker flags configuration in target."}, + ["api.target.shflags"] = {description = "Check shared library linker flags configuration in target."}, + -- cuda checkers + ["cuda.devlink"] = {description = "Check devlink for targets.", timely = true}, + -- clang tidy checker + ["clang.tidy"] = {description = "Check project code using clang-tidy.", showstats = false} + } + _g._CHECKERS = checkers + end + return checkers +end + +-- complete checkers +function complete(complete, opt) + return try + { + function () + local list = {} + local groupstats = {} + for name, _ in table.orderpairs(checkers()) do + local groupname = name:split(".", {plain = true})[1] + groupstats[groupname] = (groupstats[groupname] or 0) + 1 + if not complete then + local limit = 16 + if groupstats[groupname] < limit then + table.insert(list, name) + elseif groupstats[groupname] == limit then + table.insert(list, "...") + end + elseif name:startswith(complete) then + table.insert(list, name) + end + end + return list + end + } +end + +-- update stats +function update_stats(level, count) + local stats = _g.stats + if not stats then + stats = {} + _g.stats = stats + end + count = count or 1 + stats[level] = (stats[level] or 0) + count +end + +-- show stats +function show_stats() + local stats = _g.stats or {} + cprint("${bright}%d${clear} notes, ${color.warning}%d${clear} warnings, ${color.error}%d${clear} errors", stats.note or 0, stats.warning or 0, stats.error or 0) +end diff --git a/xmake/modules/private/check/checkers/api/api_checker.lua b/xmake/modules/private/check/checkers/api/api_checker.lua new file mode 100644 index 000000000..79e4809bd --- /dev/null +++ b/xmake/modules/private/check/checkers/api/api_checker.lua @@ -0,0 +1,158 @@ +--!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 api_checker.lua +-- + +-- imports +import("core.base.option") +import("core.base.hashset") +import("core.project.project") +import("..checker") + +-- get the most probable value +function _get_most_probable_value(value, valueset) + local result + local mindist + for v in valueset:keys() do + local dist = value:levenshtein(v) + if not mindist or dist < mindist then + mindist = dist + result = v + end + end + return result +end + +function _do_show(str, opt) + _g.showed = _g.showed or {} + local showed = _g.showed + local infostr + if str then + infostr = string.format("%s: %s: %s", opt.sourcetips, opt.level_tips, str) + else + infostr = string.format("%s: %s: unknown %s value '%s'", opt.sourcetips, opt.level_tips, opt.apiname, opt.value) + end + if opt.probable_value then + infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value) + end + if not showed[infostr] then + cprint(infostr) + showed[infostr] = true + return true + end +end + +-- show result +function _show(apiname, value, target, opt) + opt = opt or {} + + -- match level? verbose: note/warning/error, default: warning/error + local level = opt.level + if not option.get("verbose") and level == "note" then + return + end + + -- get source information + local sourceinfo = target:sourceinfo(apiname, value) or {} + local sourcetips = sourceinfo.file or "" + if sourceinfo.line then + sourcetips = sourcetips .. ":" .. (sourceinfo.line or -1) + end + if #sourcetips == 0 then + sourcetips = string.format("target(%s)", target:name()) + end + + -- get level tips + 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 + + -- get probable value + local probable_value + if opt.valueset then + probable_value = _get_most_probable_value(value, opt.valueset) + end + + if apiname:endswith("s") then + apiname = apiname:sub(1, #apiname - 1) + end + + -- do show + return (opt.show or _do_show)(opt.showstr, { + apiname = apiname, + sourcetips = sourcetips, + level_tips = level_tips, + value = value, + probable_value = probable_value}) +end + +-- check target +function _check_target(target, apiname, valueset, level, opt) + local target_valueset = valueset + if type(opt.values) == "function" then + local target_values = opt.values(target) + if target_values then + target_valueset = hashset.from(target_values) + end + end + local values = target:get(apiname) + for _, value in ipairs(values) do + if opt.check then + local ok, errors = opt.check(target, value) + if not ok then + local reported = _show(apiname, value, target, { + show = opt.show, + showstr = errors, + level = level}) + if reported then + checker.update_stats(level) + end + end + elseif not target_valueset:has(value) then + local reported = _show(apiname, value, target, { + show = opt.show, + valueset = target_valueset, + level = level}) + if reported then + checker.update_stats(level) + end + end + end +end + +-- check api configuration in targets +function check_targets(apiname, opt) + opt = opt or {} + local level = opt.level or "warning" + local valueset + if opt.values and type(opt.values) ~= "function" then + valueset = hashset.from(opt.values) + else + valueset = hashset.new() + end + if opt.target then + _check_target(opt.target, apiname, valueset, level, opt) + else + for _, target in pairs(project.targets()) do + _check_target(target, apiname, valueset, level, opt) + end + end +end diff --git a/xmake/modules/private/check/checkers/api/target/asflags.lua b/xmake/modules/private/check/checkers/api/target/asflags.lua new file mode 100644 index 000000000..07de9c4ec --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/asflags.lua @@ -0,0 +1,34 @@ +--!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 asflags.lua +-- + +-- imports +import("core.tool.compiler") +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("asflags", table.join(opt, {check = function(target, value) + local compinst = target:compiler("as") + if not compinst:has_flags(value) then + return false, string.format("%s: unknown assembler flag '%s'", compinst:name(), value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/cflags.lua b/xmake/modules/private/check/checkers/api/target/cflags.lua new file mode 100644 index 000000000..db35a7bcf --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/cflags.lua @@ -0,0 +1,34 @@ +--!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 cflags.lua +-- + +-- imports +import("core.tool.compiler") +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("cflags", table.join(opt, {check = function(target, value) + local compinst = target:compiler("cc") + if not compinst:has_flags(value) then + return false, string.format("%s: unknown c compiler flag '%s'", compinst:name(), value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/configfiles.lua b/xmake/modules/private/check/checkers/api/target/configfiles.lua new file mode 100644 index 000000000..a8965eebe --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/configfiles.lua @@ -0,0 +1,33 @@ +--!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 configfiles.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("configfiles", table.join(opt, {check = function(target, value) + local configfiles = os.files(value) + if not configfiles or #configfiles == 0 then + return false, string.format("configfiles '%s' not found", value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/cxflags.lua b/xmake/modules/private/check/checkers/api/target/cxflags.lua new file mode 100644 index 000000000..ba09366e0 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/cxflags.lua @@ -0,0 +1,34 @@ +--!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 cxflags.lua +-- + +-- imports +import("core.tool.compiler") +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("cxflags", table.join(opt, {check = function(target, value) + local compinst = target:compiler("cxx") + if not compinst:has_flags(value) then + return false, string.format("%s: unknown c/c++ compiler flag '%s'", compinst:name(), value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/cxxflags.lua b/xmake/modules/private/check/checkers/api/target/cxxflags.lua new file mode 100644 index 000000000..84660cfa4 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/cxxflags.lua @@ -0,0 +1,34 @@ +--!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 cxxflags.lua +-- + +-- imports +import("core.tool.compiler") +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("cxxflags", table.join(opt, {check = function(target, value) + local compinst = target:compiler("cxx") + if not compinst:has_flags(value) then + return false, string.format("%s: unknown c++ compiler flag '%s'", compinst:name(), value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/exceptions.lua b/xmake/modules/private/check/checkers/api/target/exceptions.lua new file mode 100644 index 000000000..e9570a894 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/exceptions.lua @@ -0,0 +1,27 @@ +--!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 exceptions.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("exceptions", table.join(opt, {values = {"none", "cxx", "objc", "no-cxx", "no-objc"}})) +end diff --git a/xmake/modules/private/check/checkers/api/target/files.lua b/xmake/modules/private/check/checkers/api/target/files.lua new file mode 100644 index 000000000..a523a7413 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/files.lua @@ -0,0 +1,33 @@ +--!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 files.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("files", table.join(opt, {check = function(target, value) + local files = os.files(value) + if not files or #files == 0 then + return false, string.format("files '%s' not found", value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/fpmodels.lua b/xmake/modules/private/check/checkers/api/target/fpmodels.lua new file mode 100644 index 000000000..61231109e --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/fpmodels.lua @@ -0,0 +1,27 @@ +--!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 fpmodels.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("fpmodels", table.join(opt, {values = {"none", "precise", "fast", "strict", "except", "noexcept"}})) +end diff --git a/xmake/modules/private/check/checkers/api/target/frameworkdirs.lua b/xmake/modules/private/check/checkers/api/target/frameworkdirs.lua new file mode 100644 index 000000000..088aa7114 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/frameworkdirs.lua @@ -0,0 +1,32 @@ +--!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 frameworkdirs.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("frameworkdirs", table.join(opt, {check = function(target, value) + if not os.isdir(value) then + return false, string.format("frameworkdir '%s' not found", value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/headerfiles.lua b/xmake/modules/private/check/checkers/api/target/headerfiles.lua new file mode 100644 index 000000000..af262b91c --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/headerfiles.lua @@ -0,0 +1,34 @@ +--!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 headerfiles.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("headerfiles", table.join(opt, {check = function(target, value) + value = value:gsub("[()]", "") + local headerfiles = os.files(value) + if not headerfiles or #headerfiles == 0 then + return false, string.format("headerfiles '%s' not found", value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/includedirs.lua b/xmake/modules/private/check/checkers/api/target/includedirs.lua new file mode 100644 index 000000000..a78431fef --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/includedirs.lua @@ -0,0 +1,32 @@ +--!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 includedirs.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("includedirs", table.join(opt, {check = function(target, value) + if not os.isdir(value) then + return false, string.format("includedir '%s' not found", value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/installfiles.lua b/xmake/modules/private/check/checkers/api/target/installfiles.lua new file mode 100644 index 000000000..7a294f60f --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/installfiles.lua @@ -0,0 +1,34 @@ +--!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 installfiles.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("installfiles", table.join(opt, {check = function(target, value) + value = value:gsub("[()]", "") + local installfiles = os.files(value) + if not installfiles or #installfiles == 0 then + return false, string.format("installfiles '%s' not found", value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/kind.lua b/xmake/modules/private/check/checkers/api/target/kind.lua new file mode 100644 index 000000000..127f78ad5 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/kind.lua @@ -0,0 +1,27 @@ +--!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 kind.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("kind", table.join(opt, {values = {"object", "binary", "static", "shared", "headeronly", "phony"}})) +end diff --git a/xmake/modules/private/check/checkers/api/target/languages.lua b/xmake/modules/private/check/checkers/api/target/languages.lua new file mode 100644 index 000000000..f01499225 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/languages.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 languages.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + local values = { + "ansi", "c89", "c90", "c99", "c11", "c17", "clatest", + "cxx98", "cxx11", "cxx14", "cxx17", "cxx1z", "cxx20", "cxx2a", "cxx23", "cxx2b", "cxxlatest" + } + local languages = {} + for _, value in ipairs(values) do + table.insert(languages, value) + if value:find("xx", 1, true) then + table.insert(languages, (value:gsub("xx", "++"))) + end + if value:startswith("c") then + table.insert(languages, "gnu" .. value:sub(2)) + end + end + api_checker.check_targets("languages", table.join(opt, {values = languages})) +end diff --git a/xmake/modules/private/check/checkers/api/target/ldflags.lua b/xmake/modules/private/check/checkers/api/target/ldflags.lua new file mode 100644 index 000000000..e06d5bb09 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/ldflags.lua @@ -0,0 +1,36 @@ +--!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 ldflags.lua +-- + +-- imports +import("core.tool.compiler") +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("ldflags", table.join(opt, {check = function(target, value) + if target:is_binary() then + local linker = target:linker() + if not linker:has_flags(value) then + return false, string.format("%s: unknown linker flag '%s'", linker:name(), value) + end + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/linkdirs.lua b/xmake/modules/private/check/checkers/api/target/linkdirs.lua new file mode 100644 index 000000000..3f05bfa16 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/linkdirs.lua @@ -0,0 +1,32 @@ +--!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 linkdirs.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("linkdirs", table.join(opt, {check = function(target, value) + if not os.isdir(value) then + return false, string.format("linkdir '%s' not found", value) + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/optimize.lua b/xmake/modules/private/check/checkers/api/target/optimize.lua new file mode 100644 index 000000000..99731ba19 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/optimize.lua @@ -0,0 +1,27 @@ +--!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 optimize.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("optimize", table.join(opt, {values = {"none", "fast", "faster", "fastest", "smallest", "aggressive"}})) +end diff --git a/xmake/modules/private/check/checkers/api/target/packages.lua b/xmake/modules/private/check/checkers/api/target/packages.lua new file mode 100644 index 000000000..994ea5c2a --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/packages.lua @@ -0,0 +1,33 @@ +--!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.project.project") +import(".api_checker") + +function main(opt) + opt = opt or {} + local packages = {} + local requires = project.required_packages() + if requires then + table.join2(packages, table.orderkeys(requires)) + end + api_checker.check_targets("packages", table.join(opt, {values = packages, level = "note"})) +end diff --git a/xmake/modules/private/check/checkers/api/target/shflags.lua b/xmake/modules/private/check/checkers/api/target/shflags.lua new file mode 100644 index 000000000..20b2f6a05 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/shflags.lua @@ -0,0 +1,36 @@ +--!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 shflags.lua +-- + +-- imports +import("core.tool.compiler") +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("shflags", table.join(opt, {check = function(target, value) + if target:is_shared() then + local linker = target:linker() + if not linker:has_flags(value) then + return false, string.format("%s: unknown linker flag '%s'", linker:name(), value) + end + end + return true + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/strip.lua b/xmake/modules/private/check/checkers/api/target/strip.lua new file mode 100644 index 000000000..c6074bc12 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/strip.lua @@ -0,0 +1,27 @@ +--!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 strip.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("strip", table.join(opt, {values = {"none", "debug", "all"}})) +end diff --git a/xmake/modules/private/check/checkers/api/target/symbols.lua b/xmake/modules/private/check/checkers/api/target/symbols.lua new file mode 100644 index 000000000..839bd0ede --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/symbols.lua @@ -0,0 +1,34 @@ +--!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 symbols.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("symbols", table.join(opt, {values = function (target) + local values = {"none", "debug", "hidden", "hidden_cxx"} + if target:is_plat("windows") and (target:has_tool("cc", "cl") or target:has_tool("cxx", "cl")) then + table.insert(values, "edit") + table.insert(values, "embed") + end + return values + end})) +end diff --git a/xmake/modules/private/check/checkers/api/target/vectorexts.lua b/xmake/modules/private/check/checkers/api/target/vectorexts.lua new file mode 100644 index 000000000..77f9ee48c --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/vectorexts.lua @@ -0,0 +1,27 @@ +--!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 vectorexts.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("vectorexts", table.join(opt, {values = {"none", "sse", "sse2", "sse3", "ssse3", "avx", "avx2", "neon"}})) +end diff --git a/xmake/modules/private/check/checkers/api/target/version.lua b/xmake/modules/private/check/checkers/api/target/version.lua new file mode 100644 index 000000000..889864f5b --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/version.lua @@ -0,0 +1,42 @@ +--!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 version.lua +-- + +-- imports +import("core.base.semver") +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("version", table.join(opt, {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 diff --git a/xmake/modules/private/check/checkers/api/target/warnings.lua b/xmake/modules/private/check/checkers/api/target/warnings.lua new file mode 100644 index 000000000..4e6cf5794 --- /dev/null +++ b/xmake/modules/private/check/checkers/api/target/warnings.lua @@ -0,0 +1,27 @@ +--!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 warnings.lua +-- + +-- imports +import(".api_checker") + +function main(opt) + opt = opt or {} + api_checker.check_targets("warnings", table.join(opt, {values = {"none", "less", "more", "all", "allextra", "everything", "error"}})) +end diff --git a/xmake/modules/private/check/checkers/clang/tidy.lua b/xmake/modules/private/check/checkers/clang/tidy.lua new file mode 100644 index 000000000..9b0d9b21e --- /dev/null +++ b/xmake/modules/private/check/checkers/clang/tidy.lua @@ -0,0 +1,179 @@ +--!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 tidy.lua +-- + +-- imports +import("core.base.option") +import("core.base.task") +import("core.project.config") +import("core.project.project") +import("lib.detect.find_tool") +import("private.async.runjobs") +import("private.action.require.impl.packagenv") +import("private.action.require.impl.install_packages") + +-- the clang.tidy options +local options = { + {"l", "list", "k", nil, "Show the clang-tidy checks list."}, + {'j', "jobs", "kv", tostring(os.default_njob()), + "Set the number of parallel check jobs."}, + {nil, "create", "k", nil, "Create a .clang-tidy file."}, + {nil, "configfile", "kv", nil, "Specify the path of .clang-tidy or custom config file"}, + {nil, "checks", "kv", nil, "Set the given checks.", + "e.g.", + " - xmake check clang.tidy --checks=\"*\""}, + {'f', "files", "v", nil, "Set files path with pattern", + "e.g.", + " - xmake check clang.tidy -f src/main.c", + " - xmake check clang.tidy -f 'src/*.c" .. path.envsep() .. "src/**.cpp'"}, + {nil, "target", "v", nil, "Check the sourcefiles of the given target.", + ".e.g", + " - xmake check clang.tidy", + " - xmake check clang.tidy [target]"} +} + +-- show checks list +function _show_list(clang_tidy) + os.execv(clang_tidy, {"--list-checks"}) +end + +-- create .clang-tidy config file +function _create_config(clang_tidy, opt) + local projectdir = project.directory() + local argv = {"--dump-config"} + if opt.checks then + table.insert(argv, "--checks=" .. opt.checks) + end + os.execv(clang_tidy, argv, {stdout = path.join(projectdir, ".clang-tidy"), curdir = projectdir}) +end + +-- add sourcefiles in target +function _add_target_files(sourcefiles, target) + table.join2(sourcefiles, (target:sourcefiles())) +end + +-- check sourcefile +function _check_sourcefile(clang_tidy, sourcefile, opt) + opt = opt or {} + local projectdir = project.directory() + local argv = {} + if opt.checks then + table.insert(argv, "--checks=" .. opt.checks) + end + if opt.compdbfile then + table.insert(argv, "-p") + table.insert(argv, opt.compdbfile) + end + if opt.configfile then + table.insert(argv, "--config-file=" .. opt.configfile) + end + if not path.is_absolute(sourcefile) then + sourcefile = path.absolute(sourcefile, projectdir) + end + table.insert(argv, sourcefile) + os.execv(clang_tidy, argv, {curdir = projectdir}) +end + +-- do check +function _check(clang_tidy, opt) + opt = opt or {} + + -- generate compile_commands.json first + local filename = "compile_commands.json" + local filepath = filename + if not os.isfile(filepath) then + local outputdir = os.tmpfile() .. ".dir" + filepath = outputdir and path.join(outputdir, filename) or filename + task.run("project", {quiet = true, kind = "compile_commands", lsp = "clangd", outputdir = outputdir}) + end + opt.compdbfile = filepath + + -- get sourcefiles + local sourcefiles = {} + if opt.files then + local files = path.splitenv(opt.files) + for _, file in ipairs(files) do + for _, filepath in ipairs(os.files(file)) do + table.insert(sourcefiles, filepath) + end + end + else + local targetname = opt.target + if targetname then + _add_target_files(sourcefiles, project.target(targetname)) + else + for _, target in ipairs(project.ordertargets()) do + _add_target_files(sourcefiles, target) + end + end + end + + -- check files + local jobs = tonumber(opt.jobs or "1") + runjobs("check_files", function (index) + local sourcefile = sourcefiles[index] + if sourcefile then + _check_sourcefile(clang_tidy, sourcefile, opt) + end + end, {total = #sourcefiles, + comax = jobs, + isolate = true}) +end + +function main(argv) + + -- parse arguments + local args = option.parse(argv or {}, options, "Use clang-tidy to check project code." + , "" + , "Usage: xmake check clang.tidy [options]") + + -- enter the environments of llvm + local oldenvs = packagenv.enter("llvm") + + -- find clang-tidy + local packages = {} + local clang_tidy = find_tool("clang-tidy") + if not clang_tidy then + table.join2(packages, install_packages("llvm")) + end + + -- enter the environments of installed packages + for _, instance in ipairs(packages) do + instance:envs_enter() + end + + -- we need force to detect and flush detect cache after loading all environments + if not clang_tidy then + clang_tidy = find_tool("clang-tidy", {force = true}) + end + assert(clang_tidy, "clang-tidy not found!") + + -- list checks + if args.list then + _show_list(clang_tidy.program) + elseif args.create then + _create_config(clang_tidy.program, args) + else + _check(clang_tidy.program, args) + end + + -- done + os.setenvs(oldenvs) +end + diff --git a/xmake/modules/private/check/checkers/cuda/devlink.lua b/xmake/modules/private/check/checkers/cuda/devlink.lua new file mode 100644 index 000000000..4281b5a8d --- /dev/null +++ b/xmake/modules/private/check/checkers/cuda/devlink.lua @@ -0,0 +1,54 @@ +--!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 devlink.lua +-- + +-- imports +import("core.base.option") +import("core.project.project") + +-- https://github.com/xmake-io/xmake/issues/1976#issuecomment-1427378799 +function _check_target(target, opt) + if target:is_binary() then + local sourcebatches = target:sourcebatches() + if sourcebatches and not sourcebatches["cuda.build"] then + for _, dep in ipairs(target:orderdeps()) do + if dep:is_static() then + sourcebatches = dep:sourcebatches() + if sourcebatches and sourcebatches["cuda.build"] then + local devlink = dep:policy("build.cuda.devlink") or dep:values("cuda.build.devlink") + if not devlink then + wprint('target(%s)${clear}: cuda device link is not performed! specify set_policy("build.cuda.devlink", true) to enable it', dep:name()) + end + end + end + end + end + end +end + +function main(opt) + if opt.target then + _check_target(opt.target, opt) + else + for _, target in pairs(project.targets()) do + _check_target(target, opt) + end + end +end + diff --git a/xmake/plugins/check/checker.lua b/xmake/plugins/check/checker.lua deleted file mode 100644 index f599b69ca..000000000 --- a/xmake/plugins/check/checker.lua +++ /dev/null @@ -1,105 +0,0 @@ ---!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.version"] = {description = "Check version configuration in target."}, - ["api.target.kind"] = {description = "Check kind configuration in target.", timely = true}, - ["api.target.strip"] = {description = "Check strip configuration in target.", timely = true}, - ["api.target.optimize"] = {description = "Check optimize configuration in target.", timely = true}, - ["api.target.symbols"] = {description = "Check symbols configuration in target.", timely = true}, - ["api.target.fpmodels"] = {description = "Check fpmodels configuration in target.", timely = true}, - ["api.target.warnings"] = {description = "Check warnings configuration in target.", timely = true}, - ["api.target.languages"] = {description = "Check languages configuration in target.", timely = true}, - ["api.target.vectorexts"] = {description = "Check vectorexts configuration in target.", timely = true}, - ["api.target.exceptions"] = {description = "Check exceptions configuration in target.", timely = true}, - ["api.target.packages"] = {description = "Check packages configuration in target."}, - ["api.target.files"] = {description = "Check files configuration in target."}, - ["api.target.headerfiles"] = {description = "Check header files configuration in target."}, - ["api.target.installfiles"] = {description = "Check install files configuration in target."}, - ["api.target.configfiles"] = {description = "Check config files configuration in target."}, - ["api.target.linkdirs"] = {description = "Check linkdirs configuration in target.", timely = true}, - ["api.target.includedirs"] = {description = "Check includedirs configuration in target.", timely = true}, - ["api.target.frameworkdirs"] = {description = "Check frameworkdirs configuration in target.", timely = true}, - ["api.target.cflags"] = {description = "Check c compiler flags configuration in target."}, - ["api.target.cxflags"] = {description = "Check c/c++ compiler flags configuration in target."}, - ["api.target.cxxflags"] = {description = "Check c++ compiler flags configuration in target."}, - ["api.target.asflags"] = {description = "Check assembler flags configuration in target."}, - ["api.target.ldflags"] = {description = "Check binary linker flags configuration in target."}, - ["api.target.shflags"] = {description = "Check shared library linker flags configuration in target."}, - -- cuda checkers - ["cuda.devlink"] = {description = "Check devlink for targets.", timely = true}, - -- clang tidy checker - ["clang.tidy"] = {description = "Check project code using clang-tidy.", showstats = false} - } - _g._CHECKERS = checkers - end - return checkers -end - --- complete checkers -function complete(complete, opt) - return try - { - function () - local list = {} - local groupstats = {} - for name, _ in table.orderpairs(checkers()) do - local groupname = name:split(".", {plain = true})[1] - groupstats[groupname] = (groupstats[groupname] or 0) + 1 - if not complete then - local limit = 16 - if groupstats[groupname] < limit then - table.insert(list, name) - elseif groupstats[groupname] == limit then - table.insert(list, "...") - end - elseif name:startswith(complete) then - table.insert(list, name) - end - end - return list - end - } -end - --- update stats -function update_stats(level, count) - local stats = _g.stats - if not stats then - stats = {} - _g.stats = stats - end - count = count or 1 - stats[level] = (stats[level] or 0) + count -end - --- show stats -function show_stats() - local stats = _g.stats or {} - cprint("${bright}%d${clear} notes, ${color.warning}%d${clear} warnings, ${color.error}%d${clear} errors", stats.note or 0, stats.warning or 0, stats.error or 0) -end diff --git a/xmake/plugins/check/checkers/api/api_checker.lua b/xmake/plugins/check/checkers/api/api_checker.lua deleted file mode 100644 index 79e4809bd..000000000 --- a/xmake/plugins/check/checkers/api/api_checker.lua +++ /dev/null @@ -1,158 +0,0 @@ ---!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 api_checker.lua --- - --- imports -import("core.base.option") -import("core.base.hashset") -import("core.project.project") -import("..checker") - --- get the most probable value -function _get_most_probable_value(value, valueset) - local result - local mindist - for v in valueset:keys() do - local dist = value:levenshtein(v) - if not mindist or dist < mindist then - mindist = dist - result = v - end - end - return result -end - -function _do_show(str, opt) - _g.showed = _g.showed or {} - local showed = _g.showed - local infostr - if str then - infostr = string.format("%s: %s: %s", opt.sourcetips, opt.level_tips, str) - else - infostr = string.format("%s: %s: unknown %s value '%s'", opt.sourcetips, opt.level_tips, opt.apiname, opt.value) - end - if opt.probable_value then - infostr = string.format("%s, it may be '%s'", infostr, opt.probable_value) - end - if not showed[infostr] then - cprint(infostr) - showed[infostr] = true - return true - end -end - --- show result -function _show(apiname, value, target, opt) - opt = opt or {} - - -- match level? verbose: note/warning/error, default: warning/error - local level = opt.level - if not option.get("verbose") and level == "note" then - return - end - - -- get source information - local sourceinfo = target:sourceinfo(apiname, value) or {} - local sourcetips = sourceinfo.file or "" - if sourceinfo.line then - sourcetips = sourcetips .. ":" .. (sourceinfo.line or -1) - end - if #sourcetips == 0 then - sourcetips = string.format("target(%s)", target:name()) - end - - -- get level tips - 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 - - -- get probable value - local probable_value - if opt.valueset then - probable_value = _get_most_probable_value(value, opt.valueset) - end - - if apiname:endswith("s") then - apiname = apiname:sub(1, #apiname - 1) - end - - -- do show - return (opt.show or _do_show)(opt.showstr, { - apiname = apiname, - sourcetips = sourcetips, - level_tips = level_tips, - value = value, - probable_value = probable_value}) -end - --- check target -function _check_target(target, apiname, valueset, level, opt) - local target_valueset = valueset - if type(opt.values) == "function" then - local target_values = opt.values(target) - if target_values then - target_valueset = hashset.from(target_values) - end - end - local values = target:get(apiname) - for _, value in ipairs(values) do - if opt.check then - local ok, errors = opt.check(target, value) - if not ok then - local reported = _show(apiname, value, target, { - show = opt.show, - showstr = errors, - level = level}) - if reported then - checker.update_stats(level) - end - end - elseif not target_valueset:has(value) then - local reported = _show(apiname, value, target, { - show = opt.show, - valueset = target_valueset, - level = level}) - if reported then - checker.update_stats(level) - end - end - end -end - --- check api configuration in targets -function check_targets(apiname, opt) - opt = opt or {} - local level = opt.level or "warning" - local valueset - if opt.values and type(opt.values) ~= "function" then - valueset = hashset.from(opt.values) - else - valueset = hashset.new() - end - if opt.target then - _check_target(opt.target, apiname, valueset, level, opt) - else - for _, target in pairs(project.targets()) do - _check_target(target, apiname, valueset, level, opt) - end - end -end diff --git a/xmake/plugins/check/checkers/api/target/asflags.lua b/xmake/plugins/check/checkers/api/target/asflags.lua deleted file mode 100644 index 07de9c4ec..000000000 --- a/xmake/plugins/check/checkers/api/target/asflags.lua +++ /dev/null @@ -1,34 +0,0 @@ ---!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 asflags.lua --- - --- imports -import("core.tool.compiler") -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("asflags", table.join(opt, {check = function(target, value) - local compinst = target:compiler("as") - if not compinst:has_flags(value) then - return false, string.format("%s: unknown assembler flag '%s'", compinst:name(), value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/cflags.lua b/xmake/plugins/check/checkers/api/target/cflags.lua deleted file mode 100644 index db35a7bcf..000000000 --- a/xmake/plugins/check/checkers/api/target/cflags.lua +++ /dev/null @@ -1,34 +0,0 @@ ---!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 cflags.lua --- - --- imports -import("core.tool.compiler") -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("cflags", table.join(opt, {check = function(target, value) - local compinst = target:compiler("cc") - if not compinst:has_flags(value) then - return false, string.format("%s: unknown c compiler flag '%s'", compinst:name(), value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/configfiles.lua b/xmake/plugins/check/checkers/api/target/configfiles.lua deleted file mode 100644 index a8965eebe..000000000 --- a/xmake/plugins/check/checkers/api/target/configfiles.lua +++ /dev/null @@ -1,33 +0,0 @@ ---!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 configfiles.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("configfiles", table.join(opt, {check = function(target, value) - local configfiles = os.files(value) - if not configfiles or #configfiles == 0 then - return false, string.format("configfiles '%s' not found", value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/cxflags.lua b/xmake/plugins/check/checkers/api/target/cxflags.lua deleted file mode 100644 index ba09366e0..000000000 --- a/xmake/plugins/check/checkers/api/target/cxflags.lua +++ /dev/null @@ -1,34 +0,0 @@ ---!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 cxflags.lua --- - --- imports -import("core.tool.compiler") -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("cxflags", table.join(opt, {check = function(target, value) - local compinst = target:compiler("cxx") - if not compinst:has_flags(value) then - return false, string.format("%s: unknown c/c++ compiler flag '%s'", compinst:name(), value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/cxxflags.lua b/xmake/plugins/check/checkers/api/target/cxxflags.lua deleted file mode 100644 index 84660cfa4..000000000 --- a/xmake/plugins/check/checkers/api/target/cxxflags.lua +++ /dev/null @@ -1,34 +0,0 @@ ---!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 cxxflags.lua --- - --- imports -import("core.tool.compiler") -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("cxxflags", table.join(opt, {check = function(target, value) - local compinst = target:compiler("cxx") - if not compinst:has_flags(value) then - return false, string.format("%s: unknown c++ compiler flag '%s'", compinst:name(), value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/exceptions.lua b/xmake/plugins/check/checkers/api/target/exceptions.lua deleted file mode 100644 index e9570a894..000000000 --- a/xmake/plugins/check/checkers/api/target/exceptions.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!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 exceptions.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("exceptions", table.join(opt, {values = {"none", "cxx", "objc", "no-cxx", "no-objc"}})) -end diff --git a/xmake/plugins/check/checkers/api/target/files.lua b/xmake/plugins/check/checkers/api/target/files.lua deleted file mode 100644 index a523a7413..000000000 --- a/xmake/plugins/check/checkers/api/target/files.lua +++ /dev/null @@ -1,33 +0,0 @@ ---!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 files.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("files", table.join(opt, {check = function(target, value) - local files = os.files(value) - if not files or #files == 0 then - return false, string.format("files '%s' not found", value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/fpmodels.lua b/xmake/plugins/check/checkers/api/target/fpmodels.lua deleted file mode 100644 index 61231109e..000000000 --- a/xmake/plugins/check/checkers/api/target/fpmodels.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!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 fpmodels.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("fpmodels", table.join(opt, {values = {"none", "precise", "fast", "strict", "except", "noexcept"}})) -end diff --git a/xmake/plugins/check/checkers/api/target/frameworkdirs.lua b/xmake/plugins/check/checkers/api/target/frameworkdirs.lua deleted file mode 100644 index 088aa7114..000000000 --- a/xmake/plugins/check/checkers/api/target/frameworkdirs.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!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 frameworkdirs.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("frameworkdirs", table.join(opt, {check = function(target, value) - if not os.isdir(value) then - return false, string.format("frameworkdir '%s' not found", value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/headerfiles.lua b/xmake/plugins/check/checkers/api/target/headerfiles.lua deleted file mode 100644 index af262b91c..000000000 --- a/xmake/plugins/check/checkers/api/target/headerfiles.lua +++ /dev/null @@ -1,34 +0,0 @@ ---!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 headerfiles.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("headerfiles", table.join(opt, {check = function(target, value) - value = value:gsub("[()]", "") - local headerfiles = os.files(value) - if not headerfiles or #headerfiles == 0 then - return false, string.format("headerfiles '%s' not found", value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/includedirs.lua b/xmake/plugins/check/checkers/api/target/includedirs.lua deleted file mode 100644 index a78431fef..000000000 --- a/xmake/plugins/check/checkers/api/target/includedirs.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!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 includedirs.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("includedirs", table.join(opt, {check = function(target, value) - if not os.isdir(value) then - return false, string.format("includedir '%s' not found", value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/installfiles.lua b/xmake/plugins/check/checkers/api/target/installfiles.lua deleted file mode 100644 index 7a294f60f..000000000 --- a/xmake/plugins/check/checkers/api/target/installfiles.lua +++ /dev/null @@ -1,34 +0,0 @@ ---!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 installfiles.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("installfiles", table.join(opt, {check = function(target, value) - value = value:gsub("[()]", "") - local installfiles = os.files(value) - if not installfiles or #installfiles == 0 then - return false, string.format("installfiles '%s' not found", value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/kind.lua b/xmake/plugins/check/checkers/api/target/kind.lua deleted file mode 100644 index 127f78ad5..000000000 --- a/xmake/plugins/check/checkers/api/target/kind.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!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 kind.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("kind", table.join(opt, {values = {"object", "binary", "static", "shared", "headeronly", "phony"}})) -end diff --git a/xmake/plugins/check/checkers/api/target/languages.lua b/xmake/plugins/check/checkers/api/target/languages.lua deleted file mode 100644 index f01499225..000000000 --- a/xmake/plugins/check/checkers/api/target/languages.lua +++ /dev/null @@ -1,41 +0,0 @@ ---!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 languages.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - local values = { - "ansi", "c89", "c90", "c99", "c11", "c17", "clatest", - "cxx98", "cxx11", "cxx14", "cxx17", "cxx1z", "cxx20", "cxx2a", "cxx23", "cxx2b", "cxxlatest" - } - local languages = {} - for _, value in ipairs(values) do - table.insert(languages, value) - if value:find("xx", 1, true) then - table.insert(languages, (value:gsub("xx", "++"))) - end - if value:startswith("c") then - table.insert(languages, "gnu" .. value:sub(2)) - end - end - api_checker.check_targets("languages", table.join(opt, {values = languages})) -end diff --git a/xmake/plugins/check/checkers/api/target/ldflags.lua b/xmake/plugins/check/checkers/api/target/ldflags.lua deleted file mode 100644 index e06d5bb09..000000000 --- a/xmake/plugins/check/checkers/api/target/ldflags.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!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 ldflags.lua --- - --- imports -import("core.tool.compiler") -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("ldflags", table.join(opt, {check = function(target, value) - if target:is_binary() then - local linker = target:linker() - if not linker:has_flags(value) then - return false, string.format("%s: unknown linker flag '%s'", linker:name(), value) - end - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/linkdirs.lua b/xmake/plugins/check/checkers/api/target/linkdirs.lua deleted file mode 100644 index 3f05bfa16..000000000 --- a/xmake/plugins/check/checkers/api/target/linkdirs.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!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 linkdirs.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("linkdirs", table.join(opt, {check = function(target, value) - if not os.isdir(value) then - return false, string.format("linkdir '%s' not found", value) - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/optimize.lua b/xmake/plugins/check/checkers/api/target/optimize.lua deleted file mode 100644 index 99731ba19..000000000 --- a/xmake/plugins/check/checkers/api/target/optimize.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!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 optimize.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("optimize", table.join(opt, {values = {"none", "fast", "faster", "fastest", "smallest", "aggressive"}})) -end diff --git a/xmake/plugins/check/checkers/api/target/packages.lua b/xmake/plugins/check/checkers/api/target/packages.lua deleted file mode 100644 index 994ea5c2a..000000000 --- a/xmake/plugins/check/checkers/api/target/packages.lua +++ /dev/null @@ -1,33 +0,0 @@ ---!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.project.project") -import(".api_checker") - -function main(opt) - opt = opt or {} - local packages = {} - local requires = project.required_packages() - if requires then - table.join2(packages, table.orderkeys(requires)) - end - api_checker.check_targets("packages", table.join(opt, {values = packages, level = "note"})) -end diff --git a/xmake/plugins/check/checkers/api/target/shflags.lua b/xmake/plugins/check/checkers/api/target/shflags.lua deleted file mode 100644 index 20b2f6a05..000000000 --- a/xmake/plugins/check/checkers/api/target/shflags.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!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 shflags.lua --- - --- imports -import("core.tool.compiler") -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("shflags", table.join(opt, {check = function(target, value) - if target:is_shared() then - local linker = target:linker() - if not linker:has_flags(value) then - return false, string.format("%s: unknown linker flag '%s'", linker:name(), value) - end - end - return true - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/strip.lua b/xmake/plugins/check/checkers/api/target/strip.lua deleted file mode 100644 index c6074bc12..000000000 --- a/xmake/plugins/check/checkers/api/target/strip.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!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 strip.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("strip", table.join(opt, {values = {"none", "debug", "all"}})) -end diff --git a/xmake/plugins/check/checkers/api/target/symbols.lua b/xmake/plugins/check/checkers/api/target/symbols.lua deleted file mode 100644 index 839bd0ede..000000000 --- a/xmake/plugins/check/checkers/api/target/symbols.lua +++ /dev/null @@ -1,34 +0,0 @@ ---!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 symbols.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("symbols", table.join(opt, {values = function (target) - local values = {"none", "debug", "hidden", "hidden_cxx"} - if target:is_plat("windows") and (target:has_tool("cc", "cl") or target:has_tool("cxx", "cl")) then - table.insert(values, "edit") - table.insert(values, "embed") - end - return values - end})) -end diff --git a/xmake/plugins/check/checkers/api/target/vectorexts.lua b/xmake/plugins/check/checkers/api/target/vectorexts.lua deleted file mode 100644 index 77f9ee48c..000000000 --- a/xmake/plugins/check/checkers/api/target/vectorexts.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!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 vectorexts.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("vectorexts", table.join(opt, {values = {"none", "sse", "sse2", "sse3", "ssse3", "avx", "avx2", "neon"}})) -end diff --git a/xmake/plugins/check/checkers/api/target/version.lua b/xmake/plugins/check/checkers/api/target/version.lua deleted file mode 100644 index 889864f5b..000000000 --- a/xmake/plugins/check/checkers/api/target/version.lua +++ /dev/null @@ -1,42 +0,0 @@ ---!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 version.lua --- - --- imports -import("core.base.semver") -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("version", table.join(opt, {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 diff --git a/xmake/plugins/check/checkers/api/target/warnings.lua b/xmake/plugins/check/checkers/api/target/warnings.lua deleted file mode 100644 index 4e6cf5794..000000000 --- a/xmake/plugins/check/checkers/api/target/warnings.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!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 warnings.lua --- - --- imports -import(".api_checker") - -function main(opt) - opt = opt or {} - api_checker.check_targets("warnings", table.join(opt, {values = {"none", "less", "more", "all", "allextra", "everything", "error"}})) -end diff --git a/xmake/plugins/check/checkers/clang/tidy.lua b/xmake/plugins/check/checkers/clang/tidy.lua deleted file mode 100644 index 9b0d9b21e..000000000 --- a/xmake/plugins/check/checkers/clang/tidy.lua +++ /dev/null @@ -1,179 +0,0 @@ ---!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 tidy.lua --- - --- imports -import("core.base.option") -import("core.base.task") -import("core.project.config") -import("core.project.project") -import("lib.detect.find_tool") -import("private.async.runjobs") -import("private.action.require.impl.packagenv") -import("private.action.require.impl.install_packages") - --- the clang.tidy options -local options = { - {"l", "list", "k", nil, "Show the clang-tidy checks list."}, - {'j', "jobs", "kv", tostring(os.default_njob()), - "Set the number of parallel check jobs."}, - {nil, "create", "k", nil, "Create a .clang-tidy file."}, - {nil, "configfile", "kv", nil, "Specify the path of .clang-tidy or custom config file"}, - {nil, "checks", "kv", nil, "Set the given checks.", - "e.g.", - " - xmake check clang.tidy --checks=\"*\""}, - {'f', "files", "v", nil, "Set files path with pattern", - "e.g.", - " - xmake check clang.tidy -f src/main.c", - " - xmake check clang.tidy -f 'src/*.c" .. path.envsep() .. "src/**.cpp'"}, - {nil, "target", "v", nil, "Check the sourcefiles of the given target.", - ".e.g", - " - xmake check clang.tidy", - " - xmake check clang.tidy [target]"} -} - --- show checks list -function _show_list(clang_tidy) - os.execv(clang_tidy, {"--list-checks"}) -end - --- create .clang-tidy config file -function _create_config(clang_tidy, opt) - local projectdir = project.directory() - local argv = {"--dump-config"} - if opt.checks then - table.insert(argv, "--checks=" .. opt.checks) - end - os.execv(clang_tidy, argv, {stdout = path.join(projectdir, ".clang-tidy"), curdir = projectdir}) -end - --- add sourcefiles in target -function _add_target_files(sourcefiles, target) - table.join2(sourcefiles, (target:sourcefiles())) -end - --- check sourcefile -function _check_sourcefile(clang_tidy, sourcefile, opt) - opt = opt or {} - local projectdir = project.directory() - local argv = {} - if opt.checks then - table.insert(argv, "--checks=" .. opt.checks) - end - if opt.compdbfile then - table.insert(argv, "-p") - table.insert(argv, opt.compdbfile) - end - if opt.configfile then - table.insert(argv, "--config-file=" .. opt.configfile) - end - if not path.is_absolute(sourcefile) then - sourcefile = path.absolute(sourcefile, projectdir) - end - table.insert(argv, sourcefile) - os.execv(clang_tidy, argv, {curdir = projectdir}) -end - --- do check -function _check(clang_tidy, opt) - opt = opt or {} - - -- generate compile_commands.json first - local filename = "compile_commands.json" - local filepath = filename - if not os.isfile(filepath) then - local outputdir = os.tmpfile() .. ".dir" - filepath = outputdir and path.join(outputdir, filename) or filename - task.run("project", {quiet = true, kind = "compile_commands", lsp = "clangd", outputdir = outputdir}) - end - opt.compdbfile = filepath - - -- get sourcefiles - local sourcefiles = {} - if opt.files then - local files = path.splitenv(opt.files) - for _, file in ipairs(files) do - for _, filepath in ipairs(os.files(file)) do - table.insert(sourcefiles, filepath) - end - end - else - local targetname = opt.target - if targetname then - _add_target_files(sourcefiles, project.target(targetname)) - else - for _, target in ipairs(project.ordertargets()) do - _add_target_files(sourcefiles, target) - end - end - end - - -- check files - local jobs = tonumber(opt.jobs or "1") - runjobs("check_files", function (index) - local sourcefile = sourcefiles[index] - if sourcefile then - _check_sourcefile(clang_tidy, sourcefile, opt) - end - end, {total = #sourcefiles, - comax = jobs, - isolate = true}) -end - -function main(argv) - - -- parse arguments - local args = option.parse(argv or {}, options, "Use clang-tidy to check project code." - , "" - , "Usage: xmake check clang.tidy [options]") - - -- enter the environments of llvm - local oldenvs = packagenv.enter("llvm") - - -- find clang-tidy - local packages = {} - local clang_tidy = find_tool("clang-tidy") - if not clang_tidy then - table.join2(packages, install_packages("llvm")) - end - - -- enter the environments of installed packages - for _, instance in ipairs(packages) do - instance:envs_enter() - end - - -- we need force to detect and flush detect cache after loading all environments - if not clang_tidy then - clang_tidy = find_tool("clang-tidy", {force = true}) - end - assert(clang_tidy, "clang-tidy not found!") - - -- list checks - if args.list then - _show_list(clang_tidy.program) - elseif args.create then - _create_config(clang_tidy.program, args) - else - _check(clang_tidy.program, args) - end - - -- done - os.setenvs(oldenvs) -end - diff --git a/xmake/plugins/check/checkers/cuda/devlink.lua b/xmake/plugins/check/checkers/cuda/devlink.lua deleted file mode 100644 index 4281b5a8d..000000000 --- a/xmake/plugins/check/checkers/cuda/devlink.lua +++ /dev/null @@ -1,54 +0,0 @@ ---!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 devlink.lua --- - --- imports -import("core.base.option") -import("core.project.project") - --- https://github.com/xmake-io/xmake/issues/1976#issuecomment-1427378799 -function _check_target(target, opt) - if target:is_binary() then - local sourcebatches = target:sourcebatches() - if sourcebatches and not sourcebatches["cuda.build"] then - for _, dep in ipairs(target:orderdeps()) do - if dep:is_static() then - sourcebatches = dep:sourcebatches() - if sourcebatches and sourcebatches["cuda.build"] then - local devlink = dep:policy("build.cuda.devlink") or dep:values("cuda.build.devlink") - if not devlink then - wprint('target(%s)${clear}: cuda device link is not performed! specify set_policy("build.cuda.devlink", true) to enable it', dep:name()) - end - end - end - end - end - end -end - -function main(opt) - if opt.target then - _check_target(opt.target, opt) - else - for _, target in pairs(project.targets()) do - _check_target(target, opt) - end - end -end - diff --git a/xmake/plugins/check/main.lua b/xmake/plugins/check/main.lua index 9ec6d03fd..5ee89ae3e 100644 --- a/xmake/plugins/check/main.lua +++ b/xmake/plugins/check/main.lua @@ -22,7 +22,7 @@ import("core.base.option") import("core.base.text") import("core.project.config") -import("checker") +import("private.check.checker") -- show checkers list function _show_list() @@ -80,7 +80,7 @@ function _check(group_or_name, arguments) if showstats == nil and info and info.showstats ~= nil then showstats = info.showstats end - import("checkers." .. name, {anonymous = true})(arguments) + import("private.check.checkers." .. name, {anonymous = true})(arguments) end if showstats ~= false then checker.show_stats() diff --git a/xmake/rules/utils/check_targets/checker.lua b/xmake/rules/utils/check_targets/checker.lua index 70b21450b..c6cbd4bf1 100644 --- a/xmake/rules/utils/check_targets/checker.lua +++ b/xmake/rules/utils/check_targets/checker.lua @@ -18,7 +18,7 @@ -- @file check_targets.lua -- -import("plugins.check.checker", {rootdir = os.programdir()}) +import("private.check.checker", {rootdir = os.programdir()}) function _show(str, opt) _g.showed = _g.showed or {} @@ -43,7 +43,7 @@ function check_target(target) for name, info in table.orderpairs(checkers) do -- just do some faster checkers if info.timely then - import("plugins.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ + import("private.check.checkers." .. name, {anonymous = true, rootdir = os.programdir()})({ target = target, show = _show}) end end -- cgit v1.3.1 From 9b095fdc709852158c6414a79915384fead9b313 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 21 Feb 2023 22:31:17 +0800 Subject: fix import errors --- xmake/modules/private/check/checker.lua | 2 +- xmake/plugins/check/xmake.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/private/check/checker.lua b/xmake/modules/private/check/checker.lua index f599b69ca..9396f825f 100644 --- a/xmake/modules/private/check/checker.lua +++ b/xmake/modules/private/check/checker.lua @@ -52,7 +52,7 @@ function checkers() ["api.target.ldflags"] = {description = "Check binary linker flags configuration in target."}, ["api.target.shflags"] = {description = "Check shared library linker flags configuration in target."}, -- cuda checkers - ["cuda.devlink"] = {description = "Check devlink for targets.", timely = true}, + ["cuda.devlink"] = {description = "Check devlink for targets."}, -- clang tidy checker ["clang.tidy"] = {description = "Check project code using clang-tidy.", showstats = false} } diff --git a/xmake/plugins/check/xmake.lua b/xmake/plugins/check/xmake.lua index d4a7dc19a..c04f2ffff 100644 --- a/xmake/plugins/check/xmake.lua +++ b/xmake/plugins/check/xmake.lua @@ -35,7 +35,7 @@ task("check") "", "The supported checkers list:", values = function (complete, opt) - return import("plugins.check.checker", {rootdir = os.programdir()}).complete(complete, opt) + return import("private.check.checker", {rootdir = os.programdir()}).complete(complete, opt) end}, {nil, "arguments", "vs", nil, "Set the checker arguments.", "e.g.", -- cgit v1.3.1 From 0fc0959c413b6cb1900f59fee403502f7b8ae2e8 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 21 Feb 2023 22:31:57 +0800 Subject: remove rootdir --- xmake/plugins/check/xmake.lua | 2 +- xmake/rules/utils/check_targets/checker.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/plugins/check/xmake.lua b/xmake/plugins/check/xmake.lua index c04f2ffff..08b4cf87d 100644 --- a/xmake/plugins/check/xmake.lua +++ b/xmake/plugins/check/xmake.lua @@ -35,7 +35,7 @@ task("check") "", "The supported checkers list:", values = function (complete, opt) - return import("private.check.checker", {rootdir = os.programdir()}).complete(complete, opt) + return import("private.check.checker").complete(complete, opt) end}, {nil, "arguments", "vs", nil, "Set the checker arguments.", "e.g.", diff --git a/xmake/rules/utils/check_targets/checker.lua b/xmake/rules/utils/check_targets/checker.lua index c6cbd4bf1..f752f9149 100644 --- a/xmake/rules/utils/check_targets/checker.lua +++ b/xmake/rules/utils/check_targets/checker.lua @@ -18,7 +18,7 @@ -- @file check_targets.lua -- -import("private.check.checker", {rootdir = os.programdir()}) +import("private.check.checker") function _show(str, opt) _g.showed = _g.showed or {} -- cgit v1.3.1