Stream: t-compiler

Topic: x.py error format


nikomatsakis (Mar 30 2020 at 22:01, on Zulip):

So i'm trying to use rust-analyzer with the compiler

nikomatsakis (Mar 30 2020 at 22:02, on Zulip):

In order to properly integrate, I need a way to run x.py check with options like:

--workspace --message-format=json --manifest-path /home/nmatsakis/versioned/rust-3/Cargo.toml --all-targets

nikomatsakis (Mar 30 2020 at 22:02, on Zulip):

in particular the json format

nikomatsakis (Mar 30 2020 at 22:02, on Zulip):

but I can't seem to find equivalent options to x.py check

nikomatsakis (Mar 30 2020 at 22:02, on Zulip):

is there some way to thread those options through that I'm missing?

nikomatsakis (Mar 30 2020 at 22:04, on Zulip):

x.py --error-format json gives me some strange errors:

> ./x.py check --error-format json
Updating only changed submodules
Submodules updated in 0.03 seconds
    Finished dev [unoptimized] target(s) in 0.17s
Checking rustdoc artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
Checking std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
error: invalid message format specifier: `json-diagnostic-json`
command did not execute successfully: "/home/nmatsakis/versioned/rust-3/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "check" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "16" "--release" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/home/nmatsakis/versioned/rust-3/src/libtest/Cargo.toml" "--message-format" "json-render-diagnostics,json-diagnostic-json"
expected success, got: exit code: 101
failed to run: /home/nmatsakis/versioned/rust-3/build/bootstrap/debug/bootstrap check --error-format json
Build completed unsuccessfully in 0:00:01
simulacrum (Mar 30 2020 at 22:18, on Zulip):

we do not currently support passing cargo flags like that

simulacrum (Mar 30 2020 at 22:19, on Zulip):

try RUSTFLAGS= perhaps? Not sure if that'll work though

nikomatsakis (Mar 30 2020 at 22:19, on Zulip):

hmmm interesting

nikomatsakis (Mar 30 2020 at 22:20, on Zulip):

didn't seem to work

nikomatsakis (Mar 30 2020 at 22:20, on Zulip):

well it's probably that the rustc flag is something different

nikomatsakis (Mar 30 2020 at 22:20, on Zulip):

to be clear, I don't really need to be able to pass general flags

nikomatsakis (Mar 30 2020 at 22:20, on Zulip):

(I mean that'd be great but..)

nikomatsakis (Mar 30 2020 at 22:20, on Zulip):

mostly I just want the json output I think

nikomatsakis (Mar 30 2020 at 22:21, on Zulip):

maybe i'll add it

simulacrum (Mar 30 2020 at 22:48, on Zulip):

I'd be happy to support JSON output , yeah

simulacrum (Mar 30 2020 at 22:49, on Zulip):

I think we already get it in fact

simulacrum (Mar 30 2020 at 22:49, on Zulip):

so it should be pretty straightforward hopefully

nikomatsakis (Mar 31 2020 at 01:07, on Zulip):

simulacrum said:

we do not currently support passing cargo flags like that

so, reading the source, there is CARGOFLAGS, but since we append --message-format=json-render-diagnostics, adding --message-format=json seems to have no effect

nikomatsakis (Mar 31 2020 at 01:20, on Zulip):

ok, I added some really hack code to support ./x.py --json-output and that... seems to work

nikomatsakis (Mar 31 2020 at 01:20, on Zulip):

which is.. pretty nifty

simulacrum (Mar 31 2020 at 11:59, on Zulip):

@nikomatsakis I'd love a PR, especially if you have the config options to get rust-analyzer auto checking working in the rustc tree :)

simulacrum (Mar 31 2020 at 11:59, on Zulip):

(I can take a look at cleaning things up myself with the initial branch, too)

nikomatsakis (Mar 31 2020 at 16:56, on Zulip):

right now it still takes a bit of manual fiddling, but we could fix that

nikomatsakis (Mar 31 2020 at 16:56, on Zulip):

what I had to do was

nikomatsakis (Mar 31 2020 at 16:57, on Zulip):

create a cargo-rustc-build executable that does

nikomatsakis (Mar 31 2020 at 16:57, on Zulip):
./x.py check --json-output
nikomatsakis (Mar 31 2020 at 16:57, on Zulip):

( json-output being the flag I added )

nikomatsakis (Mar 31 2020 at 16:57, on Zulip):

and then configure the cargo command for rustc directories to run rustc-build as the command

nikomatsakis (Mar 31 2020 at 16:57, on Zulip):

I could open a PR to add the flag and then open a rustc-dev-guide PR explaining the setup

nikomatsakis (Mar 31 2020 at 16:58, on Zulip):

there's probably better ways to do it

nikomatsakis (Mar 31 2020 at 16:58, on Zulip):

in particular, it might be nice if we were able to "pipe through" the options that rust-analyzer is giving us, instead of me just hardcoding things when invoking x.py

simulacrum (Mar 31 2020 at 17:10, on Zulip):

yeah, I think I'd just want the flag for now, we can think about expanding it further

simulacrum (Mar 31 2020 at 17:11, on Zulip):

I've been doing some thinking recently about how x.py should behave better for this sort of use case

matklad (Apr 02 2020 at 12:32, on Zulip):

@nikomatsakis rust-analyzer's side of implementaiton is here: https://github.com/rust-analyzer/rust-analyzer/pull/3825

Now it is possible to set arbitrary command for on-the-fly error checking.

matklad (Apr 02 2020 at 12:37, on Zulip):

The relevant config should look like this:

14:36:43|~/projects/rust|master✓
λ bat -p ./.vscode/settings.json
{
    "rust-analyzer.checkOnSave.overrideCommand": [
        "./x.py",
        "check",
        "--json-output"
    ]
}
simulacrum (Apr 02 2020 at 12:41, on Zulip):

Great! We should definitely get json-output upstreamed in that case.

eddyb (Apr 02 2020 at 13:58, on Zulip):

I wonder if --error-output=json would be a better thing to expose this as or if it really doesn't matter

simulacrum (Apr 02 2020 at 13:59, on Zulip):

uh, well, I mean, we could expose the error-format option, though I don't know to what extent (i.e. I wouldn't want to necessarily spend time supporting all the permutations, just JSON for rust-analyzer, I think)

eddyb (Apr 02 2020 at 14:00, on Zulip):

hmm are there still permutations? I was under the impression that all the JSON flags are under --json now

simulacrum (Apr 02 2020 at 14:00, on Zulip):

ah, perhaps

simulacrum (Apr 02 2020 at 14:00, on Zulip):

I meant that rustbuild itself also needs JSON

simulacrum (Apr 02 2020 at 14:00, on Zulip):

(just from Cargo though)

simulacrum (Apr 02 2020 at 14:01, on Zulip):

but if it's e.g. a match statement that just always enables cargo's json as needed, then I'm happy

nikomatsakis (Apr 02 2020 at 14:02, on Zulip):

I'll open a PR against rustbuild, I don't care what the option is

simulacrum (Apr 02 2020 at 14:03, on Zulip):

yeah just some groundwork (whatever you have locally) would be helpful, I can polish it up if needed -- though I don't care too much how things look if they work :)

eddyb (Apr 02 2020 at 14:16, on Zulip):

--error-format= would be nice because I think it could allow using the shorter errors but idk if those have been made to work

eddyb (Apr 02 2020 at 14:16, on Zulip):

I think they hide the labels instead of rendering them differently, which is a shame

nikomatsakis (Apr 02 2020 at 14:39, on Zulip):

@simulacrum opened https://github.com/rust-lang/rust/pull/70698/

Last update: Jun 04 2020 at 18:30UTC