Skip to content

Commit 8c78d7a

Browse files
authored
Rollup merge of #133875 - onur-ozkan:early-return-rustfmt, r=jieyouxu
handle `--json-output` properly Because `rustfmt` doesn't support JSON output, `x test --json-output` doesn't respect the `--json-output` flag during formatting step. This change makes that `x test` skips the formatting step if `--json-output` is specified. In addition, resolves #133855 with the 2nd commit.
2 parents bfbbe95 + 31c4057 commit 8c78d7a

File tree

1 file changed

+26
-11
lines changed
  • src/bootstrap/src/core/build_steps

1 file changed

+26
-11
lines changed

Diff for: src/bootstrap/src/core/build_steps/test.rs

+26-11
Original file line numberDiff line numberDiff line change
@@ -1070,23 +1070,33 @@ impl Step for Tidy {
10701070
}
10711071

10721072
if builder.config.channel == "dev" || builder.config.channel == "nightly" {
1073-
builder.info("fmt check");
1074-
if builder.initial_rustfmt().is_none() {
1075-
let inferred_rustfmt_dir = builder.initial_sysroot.join("bin");
1076-
eprintln!(
1077-
"\
1073+
if !builder.config.json_output {
1074+
builder.info("fmt check");
1075+
if builder.initial_rustfmt().is_none() {
1076+
let inferred_rustfmt_dir = builder.initial_sysroot.join("bin");
1077+
eprintln!(
1078+
"\
10781079
ERROR: no `rustfmt` binary found in {PATH}
10791080
INFO: `rust.channel` is currently set to \"{CHAN}\"
10801081
HELP: if you are testing a beta branch, set `rust.channel` to \"beta\" in the `config.toml` file
10811082
HELP: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to `x.py test`",
1082-
PATH = inferred_rustfmt_dir.display(),
1083-
CHAN = builder.config.channel,
1083+
PATH = inferred_rustfmt_dir.display(),
1084+
CHAN = builder.config.channel,
1085+
);
1086+
crate::exit!(1);
1087+
}
1088+
let all = false;
1089+
crate::core::build_steps::format::format(
1090+
builder,
1091+
!builder.config.cmd.bless(),
1092+
all,
1093+
&[],
1094+
);
1095+
} else {
1096+
eprintln!(
1097+
"WARNING: `--json-output` is not supported on rustfmt, formatting will be skipped"
10841098
);
1085-
crate::exit!(1);
10861099
}
1087-
let all = false;
1088-
crate::core::build_steps::format::format(builder, !builder.config.cmd.bless(), all, &[
1089-
]);
10901100
}
10911101

10921102
builder.info("tidy check");
@@ -2624,6 +2634,11 @@ fn prepare_cargo_test(
26242634
if builder.kind == Kind::Test && !builder.fail_fast {
26252635
cargo.arg("--no-fail-fast");
26262636
}
2637+
2638+
if builder.config.json_output {
2639+
cargo.arg("--message-format=json");
2640+
}
2641+
26272642
match builder.doc_tests {
26282643
DocTests::Only => {
26292644
cargo.arg("--doc");

0 commit comments

Comments
 (0)