Skip to content

Commit f28284f

Browse files
authored
Merge pull request #7038 from xmake-io/progress
improve clang-tidy output for multi-line progress mode
2 parents 9eb2b81 + 0c6c01b commit f28284f

File tree

1 file changed

+49
-4
lines changed
  • xmake/modules/private/check/checkers/clang

1 file changed

+49
-4
lines changed

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

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,48 @@ function _add_target_files(sourcefiles, target)
8383
end
8484
end
8585

86+
-- check a single sourcefile
87+
function _check_sourcefile(clang_tidy, sourcefile, opt)
88+
progress.show(opt.progress_percent, "clang-tidy.analyzing %s", sourcefile)
89+
try
90+
{
91+
function ()
92+
local outdata, errdata = os.iorunv(clang_tidy.program, opt.tidy_argv, {curdir = opt.projectdir})
93+
return (outdata or "") .. (errdata or "")
94+
end,
95+
catch
96+
{
97+
function (errors)
98+
-- execution failed or returned non-zero
99+
local error_text = ""
100+
if type(errors) == "table" then
101+
error_text = (errors.stdout or "") .. (errors.stderr or "")
102+
if #error_text:trim() == 0 then
103+
error_text = errors.errors or "check failed"
104+
end
105+
else
106+
error_text = tostring(errors)
107+
end
108+
progress.show_output("${color.error}%s:\n%s", sourcefile, error_text)
109+
progress.show_abort()
110+
raise(error_text)
111+
end
112+
},
113+
finally
114+
{
115+
function (ok, outdata, errdata)
116+
-- show output if any
117+
if ok then
118+
local output = (outdata or "") .. (errdata or "")
119+
if output and #output:trim() > 0 then
120+
progress.show_output("${color.warning}%s:\n%s", sourcefile, output)
121+
end
122+
end
123+
end
124+
}
125+
}
126+
end
127+
86128
-- check sourcefiles
87129
function _check_sourcefiles(clang_tidy, sourcefiles, opt)
88130
opt = opt or {}
@@ -111,13 +153,16 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt)
111153
table.insert(argv, "--quiet")
112154
end
113155

114-
local analyze_time = os.mclock()
115156
-- run clang-tidy
116-
runjobs("checker.tidy", function (index, total, opt)
157+
local analyze_time = os.mclock()
158+
runjobs("checker.tidy", function (index, total, job_opt)
117159
local sourcefile = sourcefiles[index]
118160
local tidy_argv = table.join(argv, {sourcefile})
119-
progress.show(index * 100 / total, "clang-tidy.analyzing %s", sourcefile)
120-
os.execv(clang_tidy.program, tidy_argv, {curdir = projectdir})
161+
_check_sourcefile(clang_tidy, sourcefile, {
162+
tidy_argv = tidy_argv,
163+
projectdir = projectdir,
164+
progress_percent = index * 100 / total
165+
})
121166
end, {total = #sourcefiles, comax = opt.jobs or os.default_njob()})
122167
analyze_time = os.mclock() - analyze_time
123168
progress.show(100, "${color.success}clang-tidy analyzed %d files, spent %.3fs", #sourcefiles, analyze_time / 1000)

0 commit comments

Comments
 (0)