summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-15 23:03:49 +0800
committerruki <[email protected]>2025-09-15 23:03:49 +0800
commitf2e4d4c3060f8eb94a25c1ed7878911287c60b8c (patch)
tree7613a8be7d02a4b671640eb749c06e311a9a013b
parent8dd95eed45b43db8ba7adf3342e60a043908fae5 (diff)
improve clang-tidy
-rw-r--r--xmake/modules/private/check/checkers/clang/tidy.lua45
1 files changed, 28 insertions, 17 deletions
diff --git a/xmake/modules/private/check/checkers/clang/tidy.lua b/xmake/modules/private/check/checkers/clang/tidy.lua
index 14df46a62..d7c7374ac 100644
--- a/xmake/modules/private/check/checkers/clang/tidy.lua
+++ b/xmake/modules/private/check/checkers/clang/tidy.lua
@@ -44,14 +44,14 @@ local options = {
{nil, "checks", "kv", nil, "Set the given checks.",
"e.g.",
" - xmake check clang.tidy --checks=\"*\""},
- {"f", "files", "v", nil, "Set files path with pattern",
+ {"f", "files", "kv", 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.",
+ {nil, "targets", "vs", nil, "Check the sourcefiles of the given target.",
".e.g",
" - xmake check clang.tidy",
- " - xmake check clang.tidy [target]"}
+ " - xmake check clang.tidy [targets]"}
}
-- show checks list
@@ -110,7 +110,8 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
table.insert(argv, "--quiet")
end
-- https://github.com/llvm/llvm-project/pull/120547
- if clang_tidy.version and semver.compare(clang_tidy.version, "19.1.6") > 0 and #sourcefiles > 32 then
+ local arguments_maxn = 32
+ if clang_tidy.version and semver.compare(clang_tidy.version, "19.1.6") > 0 and #sourcefiles > arguments_maxn then
for _, sourcefile in ipairs(sourcefiles) do
if not path.is_absolute(sourcefile) then
sourcefile = path.absolute(sourcefile, projectdir)
@@ -122,21 +123,29 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
argv = {"@" .. argsfile}
os.execv(clang_tidy.program, argv, {curdir = projectdir})
os.rm(argsfile)
- elseif #sourcefiles <= 32 then
- for _, sourcefile in ipairs(sourcefiles) do
- if not path.is_absolute(sourcefile) then
- sourcefile = path.absolute(sourcefile, projectdir)
- end
- table.insert(argv, sourcefile)
- end
- os.execv(clang_tidy.program, argv, {curdir = projectdir})
else
+ -- split sourcefiles
+ local sourcefiles_argv = {}
+ local sourcefiles_jobs = {}
for _, sourcefile in ipairs(sourcefiles) do
if not path.is_absolute(sourcefile) then
sourcefile = path.absolute(sourcefile, projectdir)
end
- os.execv(clang_tidy.program, table.join(argv, sourcefile), {curdir = projectdir})
+ table.insert(sourcefiles_argv, sourcefile)
+ if #sourcefiles_argv >= arguments_maxn then
+ table.insert(sourcefiles_jobs, sourcefiles_argv)
+ sourcefiles_argv = {}
+ end
+ end
+ if #sourcefiles_argv > 0 then
+ table.insert(sourcefiles_jobs, sourcefiles_argv)
end
+
+ -- run clang-tidy
+ runjobs("checker.tidy", function (index, total, opt)
+ local argv = sourcefiles_jobs[index]
+ os.execv(clang_tidy.program, argv, {curdir = projectdir})
+ end, {total = #sourcefiles_jobs, comax = opt.jobs or os.default_njob()})
end
end
@@ -178,9 +187,12 @@ function _check(clang_tidy, opt)
end
end
else
- local targetname = opt.target
- if targetname then
- _add_target_files(sourcefiles, project.target(targetname))
+ local targetnames = opt.targets
+ if targetnames then
+ for _, targetname in ipairs(targetnames) do
+ local target = assert(project.target(targetname), "unknown target(%s)", targetname)
+ _add_target_files(sourcefiles, target)
+ end
else
for _, target in ipairs(project.ordertargets()) do
_add_target_files(sourcefiles, target)
@@ -219,7 +231,6 @@ function main(argv)
clang_tidy = find_tool("clang-tidy", {force = true, version = true})
end
assert(clang_tidy, "clang-tidy not found!")
- print(clang_tidy)
-- list checks
if args.list then