diff options
| author | ruki <[email protected]> | 2025-11-19 14:02:54 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-19 14:02:54 +0800 |
| commit | f28284fbeb96285ae796bd2389e94d79a70d9c25 (patch) | |
| tree | 85feefd80a1b9534e0eeab595a1d0b148d0f3045 /xmake/modules | |
| parent | 9eb2b81c1d3bab990f8b1ddcec2cdd30be47f0b2 (diff) | |
| parent | 0c6c01bde88616f1d7c17556e76cc892ecdaa5bd (diff) | |
Merge pull request #7038 from xmake-io/progress
improve clang-tidy output for multi-line progress mode
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/private/check/checkers/clang/tidy.lua | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/xmake/modules/private/check/checkers/clang/tidy.lua b/xmake/modules/private/check/checkers/clang/tidy.lua index 03de479f8..fc42a77cc 100644 --- a/xmake/modules/private/check/checkers/clang/tidy.lua +++ b/xmake/modules/private/check/checkers/clang/tidy.lua @@ -83,6 +83,48 @@ function _add_target_files(sourcefiles, target) end end +-- check a single sourcefile +function _check_sourcefile(clang_tidy, sourcefile, opt) + progress.show(opt.progress_percent, "clang-tidy.analyzing %s", sourcefile) + try + { + function () + local outdata, errdata = os.iorunv(clang_tidy.program, opt.tidy_argv, {curdir = opt.projectdir}) + return (outdata or "") .. (errdata or "") + end, + catch + { + function (errors) + -- execution failed or returned non-zero + local error_text = "" + if type(errors) == "table" then + error_text = (errors.stdout or "") .. (errors.stderr or "") + if #error_text:trim() == 0 then + error_text = errors.errors or "check failed" + end + else + error_text = tostring(errors) + end + progress.show_output("${color.error}%s:\n%s", sourcefile, error_text) + progress.show_abort() + raise(error_text) + end + }, + finally + { + function (ok, outdata, errdata) + -- show output if any + if ok then + local output = (outdata or "") .. (errdata or "") + if output and #output:trim() > 0 then + progress.show_output("${color.warning}%s:\n%s", sourcefile, output) + end + end + end + } + } +end + -- check sourcefiles function _check_sourcefiles(clang_tidy, sourcefiles, opt) opt = opt or {} @@ -111,13 +153,16 @@ function _check_sourcefiles(clang_tidy, sourcefiles, opt) table.insert(argv, "--quiet") end - local analyze_time = os.mclock() -- run clang-tidy - runjobs("checker.tidy", function (index, total, opt) + local analyze_time = os.mclock() + runjobs("checker.tidy", function (index, total, job_opt) local sourcefile = sourcefiles[index] local tidy_argv = table.join(argv, {sourcefile}) - progress.show(index * 100 / total, "clang-tidy.analyzing %s", sourcefile) - os.execv(clang_tidy.program, tidy_argv, {curdir = projectdir}) + _check_sourcefile(clang_tidy, sourcefile, { + tidy_argv = tidy_argv, + projectdir = projectdir, + progress_percent = index * 100 / total + }) end, {total = #sourcefiles, comax = opt.jobs or os.default_njob()}) analyze_time = os.mclock() - analyze_time progress.show(100, "${color.success}clang-tidy analyzed %d files, spent %.3fs", #sourcefiles, analyze_time / 1000) |
