diff options
| author | ruki <[email protected]> | 2026-01-14 11:58:50 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-14 11:58:50 +0800 |
| commit | cc4413cbac8b55ad099c0463c96a45e9b1703dc3 (patch) | |
| tree | f83f32438edd0f36ca96993da7b717679b14be71 /xmake/modules | |
| parent | e23ba1229f3efe827bfb5c9d6cb7042665b507de (diff) | |
| parent | a07a54f06c1341f9082b967d0c8205b214cc04e3 (diff) | |
Merge pull request #7214 from xmake-io/cl
Improve warnings output
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 67 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl/parse_include.lua | 24 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 21 | ||||
| -rw-r--r-- | xmake/modules/core/tools/nvcc.lua | 24 |
4 files changed, 98 insertions, 38 deletions
diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index e5f8f7eaf..34be37513 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -696,6 +696,52 @@ function compargv(self, sourcefile, objectfile, flags, opt) return self:program(), (opt and opt.rawargs) and argv or winos.cmdargv(argv) end +-- show warnings +function _show_warnings(self, output, sourcefile) + local lines = {} + local has_warnings = false + local has_source_dependencies = _has_source_dependencies(self) + for _, line in ipairs(output:split("\n", {plain = true})) do + line = line:rtrim() + if #line > 0 then + local skip = false + + -- filter includes notes: "Note: including file: xxx.h" + if not has_source_dependencies and parse_include.has_include_note(line) then + skip = true + end + + -- filter source filename echo + -- + -- e.g. + -- main.cpp <-- skip it + -- src\main.cpp(2): warning C5295: #warning xxx + -- + if not skip then + -- we don't need use isfile() to check it, because it's too slow + if sourcefile:endswith(line) and not line:find(":", 1, true) then + skip = true + end + end + + if not skip then + table.insert(lines, line) + if line:find("warning", 1, true) then + has_warnings = true + end + end + end + end + + if has_warnings and #lines > 0 then + if not option.get("diagnosis") then + lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines)) + end + local warnings = table.concat(lines, "\r\n") + progress.show_output("${color.warning}%s", warnings) + end +end + -- compile the source file function compile(self, sourcefile, objectfile, dependinfo, flags, opt) @@ -760,7 +806,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) -- filter includes notes: "Note: including file: xxx.h", @note maybe not english language for _, line in ipairs(tostring(errors):split("\n", {plain = true})) do line = line:rtrim() - if not parse_include(line) then + if not parse_include.has_include_note(line) then results = results .. line .. "\r\n" end end @@ -774,28 +820,13 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) finally { function (ok, outdata, errdata) - - -- show warnings? if ok and policy.build_warnings(opt) then local output = outdata or "" if #output:trim() == 0 then output = errdata or "" end - if #output:trim() > 0 then - local lines = {} - for _, line in ipairs(output:split("\n", {plain = true})) do - line = line:rtrim() - if line:match("warning %a+[0-9]+%s*:") then - table.insert(lines, line) - end - end - if #lines > 0 then - if not option.get("diagnosis") then - lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines)) - end - local warnings = table.concat(lines, "\r\n") - progress.show_output("${color.warning}%s", warnings) - end + if #output > 0 then + _show_warnings(self, output, sourcefile) end end end diff --git a/xmake/modules/core/tools/cl/parse_include.lua b/xmake/modules/core/tools/cl/parse_include.lua index 597e033f8..3541c28df 100644 --- a/xmake/modules/core/tools/cl/parse_include.lua +++ b/xmake/modules/core/tools/cl/parse_include.lua @@ -87,17 +87,27 @@ function get_include_notes() return notes end --- main entry -function main(line) +-- has include note? +function has_include_note(line) + local note = _g.note + if note and line:startswith(note) then + return note + end + local notes = get_include_notes() for idx, note in ipairs(notes) do if line:startswith(note) then - -- optimization: move this note to head - if idx ~= 1 then - table.insert(notes, 1, note) - end - return line:sub(#note):trim() + _g.note = note + return note end end end +-- parse note includes +function main(line) + local note = has_include_note(line) + if note then + return line:sub(#note):trim() + end +end + diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index c1a98b752..6fc7a641b 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -912,6 +912,18 @@ function add_sourceflags(self, sourcefile, fileconfig, target, targetkind) end end +-- show warnings +function _show_warnings(self, output) + local lines = output:split('\n', {plain = true}) + if #lines > 0 then + if not option.get("diagnosis") then + lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines)) + end + local warnings = table.concat(lines, "\n") + progress.show_output("${color.warning}%s", warnings) + end +end + -- make the link arguments list function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) @@ -1064,14 +1076,7 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) function (ok, outdata, errdata) -- show warnings? if ok and errdata and #errdata > 0 and policy.build_warnings(opt) then - local lines = errdata:split('\n', {plain = true}) - if #lines > 0 then - if not option.get("diagnosis") then - lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines)) - end - local warnings = table.concat(lines, "\n") - progress.show_output("${color.warning}%s", warnings) - end + _show_warnings(self, errdata) end -- generate the dependent includes diff --git a/xmake/modules/core/tools/nvcc.lua b/xmake/modules/core/tools/nvcc.lua index 27f0340f5..41ae28274 100644 --- a/xmake/modules/core/tools/nvcc.lua +++ b/xmake/modules/core/tools/nvcc.lua @@ -326,6 +326,18 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt) os.runv(program, argv, {envs = self:runenvs()}) end +-- show warnings +function _show_warnings(self, output) + local lines = output:split('\n', {plain = true}) + if #lines > 0 then + if not option.get("diagnosis") then + lines = table.slice(lines, 1, (#lines > 16 and 16 or #lines)) + end + local warnings = table.concat(lines, "\n") + progress.show_output("${color.warning}%s", warnings) + end +end + -- support `-MD -MF depfile.d`? function _has_flags_md_mf(self) local has_md_mf = _g._HAS_MD_MF @@ -446,11 +458,13 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) }, finally { - function (ok, warnings) - - -- print some warnings - if warnings and #warnings > 0 and policy.build_warnings(opt) then - progress.show_output("${color.warning}%s", table.concat(table.slice(warnings:split('\n', {plain = true}), 1, 8), '\n')) + function (ok, outdata, errdata) + -- show warnings? + if ok and policy.build_warnings(opt) then + local output = (outdata or "") .. (errdata or "") + if #output > 0 then + _show_warnings(self, output) + end end -- generate the dependent includes |
