xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.04k stars 786 forks source link

"error:" prefix for command error breaks parsing of xmake's output #1955

Closed xaizek closed 2 years ago

xaizek commented 2 years ago

Describe the bug

Output of build systems are often processed to find errors. Errors are identified by looking for error:, note:, warning:, etc. and part of the line to the left of it is taken to be a path. xmake adds "error: " prefix on the first line which breaks extraction of file name for the first error. That's very annoying as it makes Vim look for a file that doesn't exist.

Expected behavior

I think "error: " should just be printed on its own line. Maybe make it more verbose like "External command has failed with the output:", because currently it can be mistaken for part of command's output.

Error output

[ 60%]: ccache compiling.debug src/main.cpp
error: src/main.cpp:304:60: error: no match for ‘operator|’ (operand types are ‘uint64_t’ {aka ‘long unsigned int’} and ‘std::optional<long unsigned int>’)

Related Environment

xmake v2.6.2 (v.2.5.9 behaved the same)

waruqi commented 2 years ago

I cannot modify it currently, because all xmake IDE and editor plugins (vscode, vsxmake, sublime, idea ..), as well as third-party plugins (qt creator, vs ..), already rely on the current output format to parse the error output. If I modify it, they will all be broken.

waruqi commented 2 years ago

But you can add a custom theme in ~/.xmake/themes/mytheme.lua (copy https://github.com/xmake-io/xmake/blob/master/xmake/themes/default/xmake.lua and modify it)

Modify default error prefix text:

theme("mytheme")
     -- ...
     set_text("error", "Custom Error Output:\n")

then switch to your theme

xmake g --theme=mytheme
xaizek commented 2 years ago

What's the rationale for the current format? Was it really necessary to do it this way and should I try to handle it in Vim? I imagine it made things harder for all of the plugins or maybe it resolves some ambiguity?

Didn't know about themes, will give it a try.

waruqi commented 2 years ago

At present, all official xmake plugins and third-party plugins have been supported, only the error: prefix needs to be parsed, which is not complicated.

xaizek commented 2 years ago

Thanks but with

set_text("error", "")

I still get leading ": ":

[ 10%]: ccache compiling.debug src/main.cpp
: src/main.cpp:304:60: error: no match for ‘operator|’ (operand types are ‘uint64_t’ {aka ‘long unsigned int’} and ‘std::optional<long unsigned int>’)

so themes can't address this.

Solved it in Vim with:

let &errorformat = 'error: %f:%l:%c:%m,'.&errorformat

Still think its a weird thing to prepend.

SirLynix commented 2 years ago

It would be a good and harmless fix to remove xmake prefix when the text is empty. ex:

set_text("error", "prefix")

=>

[ 10%]: ccache compiling.debug src/main.cpp
prefix: src/main.cpp:304:60: error: 
set_text("error", "")

=>

[ 10%]: ccache compiling.debug src/main.cpp
src/main.cpp:304:60: error: