From b39a55d547a5c80298626cb46ff9e338d4729e10 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 21 Feb 2023 23:16:23 +0800 Subject: rewrite check targets --- xmake/actions/build/check.lua | 83 +++++++++++++++++++++++++++++ xmake/actions/build/main.lua | 4 ++ xmake/rules/c++/xmake.lua | 3 -- xmake/rules/cuda/xmake.lua | 3 -- xmake/rules/objc++/xmake.lua | 3 -- xmake/rules/swift/xmake.lua | 2 - xmake/rules/utils/check_targets/checker.lua | 50 ----------------- xmake/rules/utils/check_targets/xmake.lua | 25 --------- xmake/rules/vala/xmake.lua | 3 -- 9 files changed, 87 insertions(+), 89 deletions(-) create mode 100644 xmake/actions/build/check.lua delete mode 100644 xmake/rules/utils/check_targets/checker.lua delete mode 100644 xmake/rules/utils/check_targets/xmake.lua diff --git a/xmake/actions/build/check.lua b/xmake/actions/build/check.lua new file mode 100644 index 000000000..5907ae5b0 --- /dev/null +++ b/xmake/actions/build/check.lua @@ -0,0 +1,83 @@ +--!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 +-- + +-- imports +import("core.base.option") +import("core.project.project") +import("private.check.checker") + +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("private.check.checkers." .. name, {anonymous = true})({ + target = target, show = _show}) + end + end +end + +function main(targetname) + + -- get targets + local targets = {} + if targetname then + table.insert(targets, project.target(targetname)) + else + for _, target in pairs(project.targets()) do + if target:is_enabled() then + local group = target:get("group") + if (target:is_default() and not group_pattern) or option.get("all") or (group_pattern and group and group:match(group_pattern)) then + table.insert(targets, target) + end + end + end + end + + -- do check + local checkers = checker.checkers() + for name, info in table.orderpairs(checkers) do + -- just do some faster checkers + if info.timely then + local check = import("private.check.checkers." .. name, {anonymous = true}) + for _, target in ipairs(targets) do + check({target = target, show = _show}) + end + end + end +end diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua index 50e84dc93..355b7753a 100644 --- a/xmake/actions/build/main.lua +++ b/xmake/actions/build/main.lua @@ -32,6 +32,7 @@ import("build") import("build_files") import("cleaner") import("statistics") +import("check", {alias = "check_targets"}) import("private.cache.build_cache") import("private.service.remote_build.action", {alias = "remote_build_action"}) @@ -170,6 +171,9 @@ function main() { function () + -- do check + check_targets(targetname) + -- do rules before building _do_project_rules("build_before") diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 3d160ab65..bc67941d9 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -52,9 +52,6 @@ rule("c++") -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled add_deps("utils.symbols.extract") - -- check targets - add_deps("utils.check.targets") - -- check licenses add_deps("utils.check.licenses") diff --git a/xmake/rules/cuda/xmake.lua b/xmake/rules/cuda/xmake.lua index d46784169..543df54b8 100644 --- a/xmake/rules/cuda/xmake.lua +++ b/xmake/rules/cuda/xmake.lua @@ -33,6 +33,3 @@ rule("cuda") -- inherit links and linkdirs of all dependent targets by default add_deps("utils.inherit.links") - -- check targets - add_deps("utils.check.targets") - diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua index 65ba757b8..447c12176 100644 --- a/xmake/rules/objc++/xmake.lua +++ b/xmake/rules/objc++/xmake.lua @@ -63,6 +63,3 @@ rule("objc++") -- we attempt to extract symbols to the independent file and -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled add_deps("utils.symbols.extract") - - -- check targets - add_deps("utils.check.targets") diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua index 4a44fcb13..5ebd919c9 100644 --- a/xmake/rules/swift/xmake.lua +++ b/xmake/rules/swift/xmake.lua @@ -32,5 +32,3 @@ rule("swift") -- support `add_files("src/*.o")` to merge object files to target add_deps("utils.merge.object") - -- check targets - add_deps("utils.check.targets") diff --git a/xmake/rules/utils/check_targets/checker.lua b/xmake/rules/utils/check_targets/checker.lua deleted file mode 100644 index e4fa31ce7..000000000 --- a/xmake/rules/utils/check_targets/checker.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("private.check.checker") - -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("private.check.checkers." .. name, {anonymous = true})({ - 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 deleted file mode 100644 index 35f58bc37..000000000 --- a/xmake/rules/utils/check_targets/xmake.lua +++ /dev/null @@ -1,25 +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 xmake.lua --- - -rule("utils.check.targets") - before_build(function (target) - import("checker").check_target(target) - end) - diff --git a/xmake/rules/vala/xmake.lua b/xmake/rules/vala/xmake.lua index 8f1431fca..c71effd05 100644 --- a/xmake/rules/vala/xmake.lua +++ b/xmake/rules/vala/xmake.lua @@ -165,9 +165,6 @@ rule("vala") -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled add_deps("utils.symbols.extract") - -- check targets - add_deps("utils.check.targets") - -- check licenses add_deps("utils.check.licenses") -- cgit v1.3.1