-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for --error-format
now that it has been stablized
#2982
Comments
cc @matklad |
One question is how to untangle Cargo output from the compiler's output. That is, if we simply add
I see three options:
I'd suggest to go with the option |
Option 👍 for option |
In the case of |
I think that 2 is a fine choice to take for now, it's certainly the most conservative. That being said, though, I'd also like to make Cargo as amenable to external tools as possible, so I wouldn't mind Cargo also printing out json status updates for itself. I'd personally expect cc @rust-lang/tools |
rustw also basically does option 2, but I'd love for Cargo to output JSON as well as the compiler |
It looks to me like there is no way to distinguish which crate the JSON corresponds to. Is that true? |
I might expect Cargo itself to have a JSON output format that is a superset of the rustc JSON output. (Edit: I see @nrc said the same thing). |
Yes, I think Cargo would need its own JSON format that wraps Rustc's. |
Note that Cargo would have a very difficult time capturing the output of the compiler and then adding its own json. It could, but it wouldn't be an easy thing to do. |
@alexcrichton why? Is it not just redirecting stdout? |
Yes, looks like it is indeed impossible to trace error messages back to target and package. You can get an approximate answer by inspecting the path to the file, but this will break at least when the same file is used by multiple targets. This is actually a very compelling reason to wrap compiler's output. But such wrapping would be incompatible with option 2 😦 In the ideal world each compilation may have a unique identity such that it is possible to connect compiler invocation command line, errors, recompilation causality chains, etc. |
I've started the work on option 2 variant here: matklad@c9a6062 |
@nrc in order to preserve live updates we'd have to stream the output, e.g. capture it on the fly. Cargo does this for build scripts today so some of the work is implemented, but it's in general a pretty hairy prospect. Additionally it unfortunately disables colors, but I guess that doesn't matter for JSON? |
ah, streaming, yeah, I'd been thinking about that for the compiler too. It is a pain.It seems solvable in the long term though (and necessary). Yeah, I'd assume JSON errors would disable colours in any case - it's not meant to be user-readable. |
Add --message-format flag. Closes #2982 This adds a `--message-format` flag with values `human` or `json-v1` to commands that may trigger compilation. After the discussion in the issue I am no longer sure that this is a way to go: * Looks like it buys nothing compared to `RUST_FLAGS` approach: a flag is more useful on the command line, but from the tool point of view there should be no significant differences between a flag and an environmental variable. * Looks like we really want to wrap compiler's messages into our own json to tie them to particular compilation.
It would be great if Cargo could add support for
--error-format
now that it has been stabilized and merged into rust-master.This would be a big win for IDEs as we could move away from using
RUSTFLAGS
.The text was updated successfully, but these errors were encountered: