@@ -44,14 +44,14 @@ local options = {
44
44
{nil , " checks" , " kv" , nil , " Set the given checks." ,
45
45
" e.g." ,
46
46
" - 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" ,
48
48
" e.g." ,
49
49
" - xmake check clang.tidy -f src/main.c" ,
50
50
" - 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." ,
52
52
" .e.g" ,
53
53
" - xmake check clang.tidy" ,
54
- " - xmake check clang.tidy [target ]" }
54
+ " - xmake check clang.tidy [targets ]" }
55
55
}
56
56
57
57
-- show checks list
@@ -110,7 +110,8 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
110
110
table.insert (argv , " --quiet" )
111
111
end
112
112
-- 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
114
115
for _ , sourcefile in ipairs (sourcefiles ) do
115
116
if not path .is_absolute (sourcefile ) then
116
117
sourcefile = path .absolute (sourcefile , projectdir )
@@ -122,21 +123,29 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
122
123
argv = {" @" .. argsfile }
123
124
os .execv (clang_tidy .program , argv , {curdir = projectdir })
124
125
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 })
133
126
else
127
+ -- split sourcefiles
128
+ local sourcefiles_argv = {}
129
+ local sourcefiles_jobs = {}
134
130
for _ , sourcefile in ipairs (sourcefiles ) do
135
131
if not path .is_absolute (sourcefile ) then
136
132
sourcefile = path .absolute (sourcefile , projectdir )
137
133
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 )
139
142
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 ()})
140
149
end
141
150
end
142
151
@@ -178,9 +187,12 @@ function _check(clang_tidy, opt)
178
187
end
179
188
end
180
189
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
184
196
else
185
197
for _ , target in ipairs (project .ordertargets ()) do
186
198
_add_target_files (sourcefiles , target )
@@ -219,7 +231,6 @@ function main(argv)
219
231
clang_tidy = find_tool (" clang-tidy" , {force = true , version = true })
220
232
end
221
233
assert (clang_tidy , " clang-tidy not found!" )
222
- print (clang_tidy )
223
234
224
235
-- list checks
225
236
if args .list then
0 commit comments