diff options
| author | ruki <[email protected]> | 2025-12-03 00:52:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-12-03 00:52:16 +0800 |
| commit | d66186fac83f009715e4d3307b47e361954fa708 (patch) | |
| tree | dc5191d6d7b8d93ca70394430e78b2859d7c4cea /xmake/modules | |
| parent | 3aca93627b3cada55db8d0215d6ff87ca418ceab (diff) | |
add xmake check syntax
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/action/build/build_binary.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/target.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/check/checker.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/check/checkers/syntax.lua | 85 |
4 files changed, 104 insertions, 9 deletions
diff --git a/xmake/modules/private/action/build/build_binary.lua b/xmake/modules/private/action/build/build_binary.lua index 581b2dde9..47884fd44 100644 --- a/xmake/modules/private/action/build/build_binary.lua +++ b/xmake/modules/private/action/build/build_binary.lua @@ -23,6 +23,7 @@ import("build_object") import("private.action.build.target", {alias = "target_buildutils"}) function main(jobgraph, target, opt) + opt = opt or {} local objects_group = target:fullname() .. "/objects" local jobsize = jobgraph:size() jobgraph:group(objects_group, function () @@ -30,13 +31,16 @@ function main(jobgraph, target, opt) end) local has_object_jobs = jobgraph:size() > jobsize - -- @note We always need the link task, even if the current target does not have any object files - -- https://github.com/xmake-io/xmake-repo/pull/7479#issuecomment-3007049158 - local link_group = target:fullname() .. "/link" - jobgraph:group(link_group, function () - target_buildutils.add_linkjobs(jobgraph, target, opt) - end) - if has_object_jobs then - jobgraph:add_orders(objects_group, link_group) + -- skip link jobs if linkjobs is disabled + if opt.linkjobs ~= false then + -- @note We always need the link task, even if the current target does not have any object files + -- https://github.com/xmake-io/xmake-repo/pull/7479#issuecomment-3007049158 + local link_group = target:fullname() .. "/link" + jobgraph:group(link_group, function () + target_buildutils.add_linkjobs(jobgraph, target, opt) + end) + if has_object_jobs then + jobgraph:add_orders(objects_group, link_group) + end end end diff --git a/xmake/modules/private/action/build/target.lua b/xmake/modules/private/action/build/target.lua index 280610e71..e906d4ee8 100644 --- a/xmake/modules/private/action/build/target.lua +++ b/xmake/modules/private/action/build/target.lua @@ -701,6 +701,10 @@ end -- add link jobs for the given target function add_linkjobs(jobgraph, target, opt) opt = table.clone(opt or {}) + -- skip link jobs if linkjobs is disabled + if opt.linkjobs == false then + return + end opt.job_kind = "link" local with_stages = opt.with_stages local group, group_before, group_after diff --git a/xmake/modules/private/check/checker.lua b/xmake/modules/private/check/checker.lua index 6ff8b3864..6d43eecb9 100644 --- a/xmake/modules/private/check/checker.lua +++ b/xmake/modules/private/check/checker.lua @@ -59,7 +59,9 @@ function checkers() -- cuda checkers ["cuda.devlink"] = {description = "Check devlink for targets.", build_failure = true}, -- clang tidy checker - ["clang.tidy"] = {description = "Check project code using clang-tidy.", showstats = false} + ["clang.tidy"] = {description = "Check project code using clang-tidy.", showstats = false}, + -- syntax checker + ["syntax"] = {description = "Check the project sourcecode syntax without linking.", showstats = false} } _g._CHECKERS = checkers end diff --git a/xmake/modules/private/check/checkers/syntax.lua b/xmake/modules/private/check/checkers/syntax.lua new file mode 100644 index 000000000..f0a04386a --- /dev/null +++ b/xmake/modules/private/check/checkers/syntax.lua @@ -0,0 +1,85 @@ +--!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 syntax.lua +-- + +-- imports +import("core.base.option") +import("core.base.task") +import("core.project.config") +import("core.project.project") +import("actions.build.build_files", {rootdir = os.programdir(), alias = "build_files"}) +import("actions.build.build", {rootdir = os.programdir(), alias = "build"}) +import("utils.progress") + +-- the syntax check options +local options = { + {'f', "files", "kv", nil, "Check the given source files.", + "e.g.", + " - xmake check syntax -f src/foo.cpp", + " - xmake check syntax -f 'src/*.cpp'"}, + {nil, "targets", "vs", nil, "Check the sourcefiles of the given target.", + "e.g.", + " - xmake check syntax", + " - xmake check syntax [targets]"} +} + +-- do check +function _check(opt) + opt = opt or {} + + local sourcefiles = opt.files + local targetnames = opt.targets + local check_time = os.mclock() + if sourcefiles then + build_files(targetnames, {sourcefiles = sourcefiles, linkjobs = false}) + else + build(targetnames, {linkjobs = false}) + end + check_time = os.mclock() - check_time + progress.show(100, "${color.success}syntax check ok, spent %.3fs", check_time / 1000) +end + +function main(argv) + -- parse arguments + local args = option.parse(argv or {}, options, "Check the project sourcecode syntax without linking." + , "" + , "Usage: xmake check syntax [options]") + + -- lock the whole project + project.lock() + + -- enable syntax-only policy and disable ccache via config + config.set("policies", "build.c++.syntax_only,build.ccache:n") + + -- config it first + task.run("config", {}, {disable_dump = true}) + + -- enter project directory + local oldir = os.cd(project.directory()) + + -- do check + _check(args) + + -- leave project directory + os.cd(oldir) + + -- unlock the whole project + project.unlock() +end + |
