Skip to content

fix: match diagnostics by format instead of OS - #339

Merged
waruqi merged 1 commit into
xmake-io:devfrom
Left-Hand:fix/diagnose-by-format-not-os
Aug 17, 2026
Merged

waruqi merged 1 commit into
xmake-io:devfrom
Left-Hand:fix/diagnose-by-format-not-os

Conversation

@Left-Hand

Copy link
Copy Markdown
Contributor

Problem

ProblemList.diagnose() picks which regex to use based on the OS:

const isWin = os.platform() == "win32";
let matches = isWin ? rOutputMsvc.exec(textLine) : rOutputGcc.exec(textLine);

This assumes Windows ⇒ MSVC and non-Windows ⇒ GCC/Clang. But on Windows it is common to use a GCC or Clang toolchain (e.g. cross-compilers like riscv32-wch-elf-gcc, arm-none-eabi-gcc, or plain MinGW/Clang). In that case every GCC/Clang diagnostic line is pushed through the MSVC regex, which cannot match file:line:col: error: message, so all errors/warnings are silently dropped from the Problems panel.

Fix

Match by format instead of by OS: try the GCC/Clang regex first, then fall back to the MSVC regex.

let matches = rOutputGcc.exec(textLine);
let isGcc = true;
if (!matches) {
    matches = rOutputMsvc.exec(textLine);
    isGcc = false;
}

Why this is safe for MSVC users

The two regexes are mutually exclusive in practice:

  • The GCC regex requires a :line:col: sequence followed by error|warning, e.g. file.cpp:12:5: error: ....
  • The MSVC regex requires (line): error C1234: ... / warning C1234: ....

MSVC's file(line): error C1234: msg shape has no :line:col: sequence, so the GCC regex never matches it and it still falls through to the MSVC regex — behavior for MSVC users is unchanged. The only behavioral change is that GCC/Clang diagnostics now work on Windows.

Validation

  • npm run compile passes cleanly.
  • Manually verified the dispatch against representative GCC, Clang, and MSVC lines (GCC/Clang → GCC regex; MSVC → MSVC regex; no cross-match).

This is the companion fix to the logfile CRLF / control-char fixes already submitted to xmake-io/xmake (#7711, #7712), which make the XMAKE_LOGFILE content parseable. This PR fixes the other half of the pipeline — the regex that consumes it.

The old code picked the regex by os.platform() == 'win32', assuming
>> Windows => MSVC and non-Windows => GCC/Clang. This drops every GCC/Clang
>> error on Windows (e.g. cross-compilers like riscv32-wch-elf-gcc).
>>
>> Match by format instead: try the GCC/Clang regex first, then fall back to
>> the MSVC regex. This is a no-op for MSVC users (the GCC regex cannot match
>> MSVC's 'file(line): error C1234: msg' shape) and fixes GCC/Clang on Windows.
@waruqi
waruqi merged commit c2eb736 into xmake-io:dev Aug 17, 2026
6 checks passed
waruqi pushed a commit that referenced this pull request Aug 18, 2026
Follow-up to #339: format-based regex dispatch is in place, but on Windows the XMAKE_LOGFILE still uses CRLF line endings. splitting on '\n' leaves a trailing '\r' on each line, and the gcc/clang regex ends with '\$' (while '.' does not match '\r'), so diagnostics still fail to match. Split on /\r?\n/ so the trailing \r is consumed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants