Skip to content

Commit f2e4d4c

Browse files
committed
improve clang-tidy
1 parent 8dd95ee commit f2e4d4c

File tree

1 file changed

+28
-17
lines changed
  • xmake/modules/private/check/checkers/clang

1 file changed

+28
-17
lines changed

xmake/modules/private/check/checkers/clang/tidy.lua

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ local options = {
4444
{nil, "checks", "kv", nil, "Set the given checks.",
4545
"e.g.",
4646
" - xmake check clang.tidy --checks=\"*\""},
47-
{"f", "files", "v", nil, "Set files path with pattern",
47+
{"f", "files", "kv", nil, "Set files path with pattern",
4848
"e.g.",
4949
" - xmake check clang.tidy -f src/main.c",
5050
" - xmake check clang.tidy -f 'src/*.c" .. path.envsep() .. "src/**.cpp'"},
51-
{nil, "target", "v", nil, "Check the sourcefiles of the given target.",
51+
{nil, "targets", "vs", nil, "Check the sourcefiles of the given target.",
5252
".e.g",
5353
" - xmake check clang.tidy",
54-
" - xmake check clang.tidy [target]"}
54+
" - xmake check clang.tidy [targets]"}
5555
}
5656

5757
-- show checks list
@@ -110,7 +110,8 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
110110
table.insert(argv, "--quiet")
111111
end
112112
-- https://github.com/llvm/llvm-project/pull/120547
113-
if clang_tidy.version and semver.compare(clang_tidy.version, "19.1.6") > 0 and #sourcefiles > 32 then
113+
local arguments_maxn = 32
114+
if clang_tidy.version and semver.compare(clang_tidy.version, "19.1.6") > 0 and #sourcefiles > arguments_maxn then
114115
for _, sourcefile in ipairs(sourcefiles) do
115116
if not path.is_absolute(sourcefile) then
116117
sourcefile = path.absolute(sourcefile, projectdir)
@@ -122,21 +123,29 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
122123
argv = {"@" .. argsfile}
123124
os.execv(clang_tidy.program, argv, {curdir = projectdir})
124125
os.rm(argsfile)
125-
elseif #sourcefiles <= 32 then
126-
for _, sourcefile in ipairs(sourcefiles) do
127-
if not path.is_absolute(sourcefile) then
128-
sourcefile = path.absolute(sourcefile, projectdir)
129-
end
130-
table.insert(argv, sourcefile)
131-
end
132-
os.execv(clang_tidy.program, argv, {curdir = projectdir})
133126
else
127+
-- split sourcefiles
128+
local sourcefiles_argv = {}
129+
local sourcefiles_jobs = {}
134130
for _, sourcefile in ipairs(sourcefiles) do
135131
if not path.is_absolute(sourcefile) then
136132
sourcefile = path.absolute(sourcefile, projectdir)
137133
end
138-
os.execv(clang_tidy.program, table.join(argv, sourcefile), {curdir = projectdir})
134+
table.insert(sourcefiles_argv, sourcefile)
135+
if #sourcefiles_argv >= arguments_maxn then
136+
table.insert(sourcefiles_jobs, sourcefiles_argv)
137+
sourcefiles_argv = {}
138+
end
139+
end
140+
if #sourcefiles_argv > 0 then
141+
table.insert(sourcefiles_jobs, sourcefiles_argv)
139142
end
143+
144+
-- run clang-tidy
145+
runjobs("checker.tidy", function (index, total, opt)
146+
local argv = sourcefiles_jobs[index]
147+
os.execv(clang_tidy.program, argv, {curdir = projectdir})
148+
end, {total = #sourcefiles_jobs, comax = opt.jobs or os.default_njob()})
140149
end
141150
end
142151

@@ -178,9 +187,12 @@ function _check(clang_tidy, opt)
178187
end
179188
end
180189
else
181-
local targetname = opt.target
182-
if targetname then
183-
_add_target_files(sourcefiles, project.target(targetname))
190+
local targetnames = opt.targets
191+
if targetnames then
192+
for _, targetname in ipairs(targetnames) do
193+
local target = assert(project.target(targetname), "unknown target(%s)", targetname)
194+
_add_target_files(sourcefiles, target)
195+
end
184196
else
185197
for _, target in ipairs(project.ordertargets()) do
186198
_add_target_files(sourcefiles, target)
@@ -219,7 +231,6 @@ function main(argv)
219231
clang_tidy = find_tool("clang-tidy", {force = true, version = true})
220232
end
221233
assert(clang_tidy, "clang-tidy not found!")
222-
print(clang_tidy)
223234

224235
-- list checks
225236
if args.list then

0 commit comments

Comments
 (0)