Skip to content

Commit 17f204f

Browse files
authored
Rollup merge of #70698 - nikomatsakis:x-py-json-output, r=Mark-Simulacrum
bootstrap: add `--json-output` for rust-analyzer Motivation is that this allows us to customize rust-analyzer's "cargo watch" integration to run x.py. You simply have to set the command to run to be `x.py --json-output` r? @Mark-Simulacrum -- feel free to make changes, this is quick and dirty for sure
2 parents 4f0a791 + e992565 commit 17f204f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/bootstrap/compile.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,11 @@ pub fn stream_cargo(
911911
}
912912
// Instruct Cargo to give us json messages on stdout, critically leaving
913913
// stderr as piped so we can get those pretty colors.
914-
let mut message_format = String::from("json-render-diagnostics");
914+
let mut message_format = if builder.config.json_output {
915+
String::from("json")
916+
} else {
917+
String::from("json-render-diagnostics")
918+
};
915919
if let Some(s) = &builder.config.rustc_error_format {
916920
message_format.push_str(",json-diagnostic-");
917921
message_format.push_str(s);

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct Config {
4848
pub ignore_git: bool,
4949
pub exclude: Vec<PathBuf>,
5050
pub rustc_error_format: Option<String>,
51+
pub json_output: bool,
5152
pub test_compare_mode: bool,
5253
pub llvm_libunwind: bool,
5354

@@ -415,6 +416,7 @@ impl Config {
415416
let mut config = Config::default_opts();
416417
config.exclude = flags.exclude;
417418
config.rustc_error_format = flags.rustc_error_format;
419+
config.json_output = flags.json_output;
418420
config.on_fail = flags.on_fail;
419421
config.stage = flags.stage;
420422
config.jobs = flags.jobs.map(threads_from_config);

src/bootstrap/flags.rs

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub struct Flags {
3131
pub incremental: bool,
3232
pub exclude: Vec<PathBuf>,
3333
pub rustc_error_format: Option<String>,
34+
pub json_output: bool,
3435
pub dry_run: bool,
3536

3637
// This overrides the deny-warnings configuration option,
@@ -156,6 +157,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
156157
"VALUE",
157158
);
158159
opts.optopt("", "error-format", "rustc error format", "FORMAT");
160+
opts.optflag("", "json-output", "use message-format=json");
159161
opts.optopt(
160162
"",
161163
"llvm-skip-rebuild",
@@ -503,6 +505,7 @@ Arguments:
503505
dry_run: matches.opt_present("dry-run"),
504506
on_fail: matches.opt_str("on-fail"),
505507
rustc_error_format: matches.opt_str("error-format"),
508+
json_output: matches.opt_present("json-output"),
506509
keep_stage: matches
507510
.opt_strs("keep-stage")
508511
.into_iter()

0 commit comments

Comments
 (0)