@@ -26,6 +26,7 @@ import("core.project.config")
26
26
import (" core.project.project" )
27
27
import (" lib.detect.find_tool" )
28
28
import (" async.runjobs" )
29
+ import (" utils.progress" )
29
30
import (" private.action.require.impl.packagenv" )
30
31
import (" private.action.require.impl.install_packages" )
31
32
@@ -44,14 +45,14 @@ local options = {
44
45
{nil , " checks" , " kv" , nil , " Set the given checks." ,
45
46
" e.g." ,
46
47
" - xmake check clang.tidy --checks=\" *\" " },
47
- {" f" , " files" , " v " , nil , " Set files path with pattern" ,
48
+ {" f" , " files" , " kv " , nil , " Set files path with pattern" ,
48
49
" e.g." ,
49
50
" - xmake check clang.tidy -f src/main.c" ,
50
51
" - xmake check clang.tidy -f 'src/*.c" .. path .envsep () .. " src/**.cpp'" },
51
- {nil , " target " , " v " , nil , " Check the sourcefiles of the given target." ,
52
+ {nil , " targets " , " vs " , nil , " Check the sourcefiles of the given target." ,
52
53
" .e.g" ,
53
54
" - xmake check clang.tidy" ,
54
- " - xmake check clang.tidy [target ]" }
55
+ " - xmake check clang.tidy [targets ]" }
55
56
}
56
57
57
58
-- show checks list
@@ -110,33 +111,44 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
110
111
table.insert (argv , " --quiet" )
111
112
end
112
113
-- 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
114
+ local arguments_maxn = 32
115
+ if clang_tidy .version and semver .compare (clang_tidy .version , " 19.1.6" ) > 0 and # sourcefiles > arguments_maxn then
114
116
for _ , sourcefile in ipairs (sourcefiles ) do
115
117
if not path .is_absolute (sourcefile ) then
116
118
sourcefile = path .absolute (sourcefile , projectdir )
117
119
end
118
120
table.insert (argv , sourcefile )
119
121
end
122
+ progress .show (100 , " clang-tidy.analyzing %s .. %d" , sourcefiles [1 ], # sourcefiles )
120
123
local argsfile = os .tmpfile () .. " .args.txt"
121
124
io .writefile (argsfile , os .args (argv ))
122
125
argv = {" @" .. argsfile }
123
- os .execv (clang_tidy .program , argv , {curdir = projectdir })
126
+ os .vrunv (clang_tidy .program , argv , {curdir = projectdir })
124
127
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
128
else
129
+ -- split sourcefiles
130
+ local sourcefiles_argv = {}
131
+ local sourcefiles_jobs = {}
134
132
for _ , sourcefile in ipairs (sourcefiles ) do
135
133
if not path .is_absolute (sourcefile ) then
136
134
sourcefile = path .absolute (sourcefile , projectdir )
137
135
end
138
- os .execv (clang_tidy .program , table .join (argv , sourcefile ), {curdir = projectdir })
136
+ table.insert (sourcefiles_argv , sourcefile )
137
+ if # sourcefiles_argv >= arguments_maxn then
138
+ table.insert (sourcefiles_jobs , sourcefiles_argv )
139
+ sourcefiles_argv = {}
140
+ end
141
+ end
142
+ if # sourcefiles_argv > 0 then
143
+ table.insert (sourcefiles_jobs , sourcefiles_argv )
139
144
end
145
+
146
+ -- run clang-tidy
147
+ runjobs (" checker.tidy" , function (index , total , opt )
148
+ local tidy_argv = sourcefiles_jobs [index ]
149
+ progress .show (index * 100 / total , " clang-tidy.analyzing %s .. %d" , tidy_argv [1 ], # tidy_argv )
150
+ os .vrunv (clang_tidy .program , tidy_argv , {curdir = projectdir })
151
+ end , {total = # sourcefiles_jobs , comax = opt .jobs or os .default_njob ()})
140
152
end
141
153
end
142
154
@@ -178,9 +190,12 @@ function _check(clang_tidy, opt)
178
190
end
179
191
end
180
192
else
181
- local targetname = opt .target
182
- if targetname then
183
- _add_target_files (sourcefiles , project .target (targetname ))
193
+ local targetnames = opt .targets
194
+ if targetnames then
195
+ for _ , targetname in ipairs (targetnames ) do
196
+ local target = assert (project .target (targetname ), " unknown target(%s)" , targetname )
197
+ _add_target_files (sourcefiles , target )
198
+ end
184
199
else
185
200
for _ , target in ipairs (project .ordertargets ()) do
186
201
_add_target_files (sourcefiles , target )
@@ -219,7 +234,6 @@ function main(argv)
219
234
clang_tidy = find_tool (" clang-tidy" , {force = true , version = true })
220
235
end
221
236
assert (clang_tidy , " clang-tidy not found!" )
222
- print (clang_tidy )
223
237
224
238
-- list checks
225
239
if args .list then
0 commit comments