diff options
| author | ruki <[email protected]> | 2026-04-07 23:39:20 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-04-07 23:39:20 +0800 |
| commit | 59c749bda81f4c0a99d41ee31adfbf931cd578f2 (patch) | |
| tree | d08a14f5acdab2bdc711596c9f857098337b716b | |
| parent | 4a13e671f0ba99feca8daf4a1706e9bcb4ccfa67 (diff) | |
add utils.checker
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/private/check/checker.lua | 11 | ||||
| -rw-r--r-- | xmake/modules/private/check/checkers/syntax.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/utils/checker.lua | 37 | ||||
| -rw-r--r-- | xmake/plugins/check/main.lua | 2 |
6 files changed, 55 insertions, 8 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 02a562e06..8928263d8 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -22,7 +22,6 @@ import("core.base.option") import("core.base.global") import("core.base.hashset") -import("core.cache.memcache") import("core.project.project") import("core.project.policy") import("core.language.language") @@ -30,6 +29,7 @@ import("private.utils.toolchain", {alias = "toolchain_utils"}) import("private.tools.vstool") import("core.tools.cl.parse_include") import("private.cache.build_cache") +import("utils.checker") import("private.service.distcc_build.client", {alias = "distcc_build_client"}) import("utils.progress") @@ -97,7 +97,7 @@ end -- is syntax check enabled? function _is_syntax_check() - return memcache.get("syntax_check", "enabled") or false + return checker.is_running("syntax") end -- make the symbol flags diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index d390d8884..43d51a1e1 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -31,6 +31,7 @@ import("core.project.project") import("core.language.language") import("utils.progress") import("private.cache.build_cache") +import("utils.checker") import("private.service.distcc_build.client", {alias = "distcc_build_client"}) import("rules.c++.modules.support", {rootdir = os.programdir()}) @@ -76,7 +77,7 @@ end -- is syntax check enabled? function _is_syntax_check() - return memcache.get("syntax_check", "enabled") or false + return checker.is_running("syntax") end -- get `-MMD -MF depfile.d` flags, some old gcc does not support it at same time diff --git a/xmake/modules/private/check/checker.lua b/xmake/modules/private/check/checker.lua index 6d43eecb9..083c5b9c9 100644 --- a/xmake/modules/private/check/checker.lua +++ b/xmake/modules/private/check/checker.lua @@ -20,6 +20,7 @@ -- imports import("core.base.option") +import("core.cache.memcache") -- get all checkers function checkers() @@ -105,6 +106,16 @@ function update_stats(level, count) stats[level] = (stats[level] or 0) + count end +-- mark a checker as running (called internally by checker implementations) +function start(name) + memcache.set("__checker_running", name, true) +end + +-- mark a checker as stopped (called internally by checker implementations) +function stop(name) + memcache.set("__checker_running", name, false) +end + -- show stats function show_stats() local stats = _g.stats or {} diff --git a/xmake/modules/private/check/checkers/syntax.lua b/xmake/modules/private/check/checkers/syntax.lua index 7da098871..53aab1803 100644 --- a/xmake/modules/private/check/checkers/syntax.lua +++ b/xmake/modules/private/check/checkers/syntax.lua @@ -21,7 +21,6 @@ -- imports import("core.base.option") import("core.base.task") -import("core.cache.memcache") import("core.project.project") import("actions.build.build_files", {rootdir = os.programdir(), alias = "build_files"}) import("actions.build.build", {rootdir = os.programdir(), alias = "build"}) @@ -102,10 +101,7 @@ function _validate_and_enable_targets(opt) end end - -- enable syntax-only via memcache - if #cpp_targets > 0 then - memcache.set("syntax_check", "enabled", true) - end + -- no valid targets found? -- if no C++ target found, return false to skip checking if #cpp_targets == 0 then diff --git a/xmake/modules/utils/checker.lua b/xmake/modules/utils/checker.lua new file mode 100644 index 000000000..e02b3f3d7 --- /dev/null +++ b/xmake/modules/utils/checker.lua @@ -0,0 +1,37 @@ +--!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, Xmake Open Source Community. +-- +-- @author ruki +-- @file checker.lua +-- + +-- imports +import("core.cache.memcache") + +-- is the given checker running? +-- +-- @param name the checker name, e.g. "syntax", "clang.tidy" +-- +-- @usage +-- +-- import("utils.checker") +-- if checker.is_running("syntax") then +-- -- we are in `xmake check syntax` mode +-- end +-- +function is_running(name) + return memcache.get("__checker_running", name) or false +end diff --git a/xmake/plugins/check/main.lua b/xmake/plugins/check/main.lua index 10e5587a1..92b670297 100644 --- a/xmake/plugins/check/main.lua +++ b/xmake/plugins/check/main.lua @@ -80,7 +80,9 @@ function _check(group_or_name, arguments) if showstats == nil and info and info.showstats ~= nil then showstats = info.showstats end + checker.start(name) import("private.check.checkers." .. name, {anonymous = true})(arguments) + checker.stop(name) end if showstats ~= false then checker.show_stats() |
