Skip to content

Commit 30f9b71

Browse files
committed
improve clang-tidy
1 parent 3260d85 commit 30f9b71

File tree

1 file changed

+32
-8
lines changed
  • xmake/modules/private/check/checkers/clang

1 file changed

+32
-8
lines changed

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

+32-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
-- imports
2222
import("core.base.option")
2323
import("core.base.task")
24+
import("core.base.semver")
2425
import("core.project.config")
2526
import("core.project.project")
2627
import("lib.detect.find_tool")
@@ -108,13 +109,35 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
108109
if opt.quiet then
109110
table.insert(argv, "--quiet")
110111
end
111-
for _, sourcefile in ipairs(sourcefiles) do
112-
if not path.is_absolute(sourcefile) then
113-
sourcefile = path.absolute(sourcefile, projectdir)
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
114+
for _, sourcefile in ipairs(sourcefiles) do
115+
if not path.is_absolute(sourcefile) then
116+
sourcefile = path.absolute(sourcefile, projectdir)
117+
end
118+
table.insert(argv, sourcefile)
119+
end
120+
local argsfile = os.tmpfile() .. ".args.txt"
121+
io.writefile(argsfile, os.args(argv))
122+
argv = {"@" .. argsfile}
123+
os.execv(clang_tidy.program, argv, {curdir = projectdir})
124+
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+
else
134+
for _, sourcefile in ipairs(sourcefiles) do
135+
if not path.is_absolute(sourcefile) then
136+
sourcefile = path.absolute(sourcefile, projectdir)
137+
end
138+
os.execv(clang_tidy.program, table.join(argv, sourcefile), {curdir = projectdir})
114139
end
115-
table.insert(argv, sourcefile)
116140
end
117-
os.execv(clang_tidy, argv, {curdir = projectdir})
118141
end
119142

120143
-- do check
@@ -167,7 +190,7 @@ function main(argv)
167190

168191
-- find clang-tidy
169192
local packages = {}
170-
local clang_tidy = find_tool("clang-tidy")
193+
local clang_tidy = find_tool("clang-tidy", {version = true})
171194
if not clang_tidy then
172195
table.join2(packages, install_packages("llvm"))
173196
end
@@ -179,17 +202,18 @@ function main(argv)
179202

180203
-- we need to force detect and flush detect cache after loading all environments
181204
if not clang_tidy then
182-
clang_tidy = find_tool("clang-tidy", {force = true})
205+
clang_tidy = find_tool("clang-tidy", {force = true, version = true})
183206
end
184207
assert(clang_tidy, "clang-tidy not found!")
208+
print(clang_tidy)
185209

186210
-- list checks
187211
if args.list then
188212
_show_list(clang_tidy.program)
189213
elseif args.create then
190214
_create_config(clang_tidy.program, args)
191215
else
192-
_check(clang_tidy.program, args)
216+
_check(clang_tidy, args)
193217
end
194218
os.setenvs(oldenvs)
195219
end

0 commit comments

Comments
 (0)