Skip to content

Commit 4a9a4d0

Browse files
committed
migrate cargo streaming to new bootstrap command streaming API's
1 parent 069c9e8 commit 4a9a4d0

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::ffi::OsStr;
1212
use std::io::BufReader;
1313
use std::io::prelude::*;
1414
use std::path::{Path, PathBuf};
15-
use std::process::Stdio;
1615
use std::{env, fs, str};
1716

1817
use serde_derive::Deserialize;
@@ -2511,11 +2510,11 @@ pub fn stream_cargo(
25112510
cb: &mut dyn FnMut(CargoMessage<'_>),
25122511
) -> bool {
25132512
let mut cmd = cargo.into_cmd();
2513+
cmd.do_not_cache();
25142514

25152515
#[cfg(feature = "tracing")]
25162516
let _run_span = crate::trace_cmd!(cmd);
25172517

2518-
let cargo = cmd.as_command_mut();
25192518
// Instruct Cargo to give us json messages on stdout, critically leaving
25202519
// stderr as piped so we can get those pretty colors.
25212520
let mut message_format = if builder.config.json_output {
@@ -2527,27 +2526,26 @@ pub fn stream_cargo(
25272526
message_format.push_str(",json-diagnostic-");
25282527
message_format.push_str(s);
25292528
}
2530-
cargo.arg("--message-format").arg(message_format).stdout(Stdio::piped());
2529+
cmd.arg("--message-format").arg(message_format);
25312530

25322531
for arg in tail_args {
2533-
cargo.arg(arg);
2532+
cmd.arg(arg);
25342533
}
25352534

2536-
builder.verbose(|| println!("running: {cargo:?}"));
2535+
builder.verbose(|| println!("running: {cmd:?}"));
25372536

2538-
if builder.config.dry_run() {
2537+
let streaming_command = cmd.start_capture_stdout(&builder.config.exec_ctx).stream();
2538+
2539+
if streaming_command.is_none() {
25392540
return true;
25402541
}
25412542

2542-
let mut child = match cargo.spawn() {
2543-
Ok(child) => child,
2544-
Err(e) => panic!("failed to execute command: {cargo:?}\nERROR: {e}"),
2545-
};
2543+
let mut streaming_command = streaming_command.unwrap();
25462544

25472545
// Spawn Cargo slurping up its JSON output. We'll start building up the
25482546
// `deps` array of all files it generated along with a `toplevel` array of
25492547
// files we need to probe for later.
2550-
let stdout = BufReader::new(child.stdout.take().unwrap());
2548+
let stdout = BufReader::new(streaming_command.stdout.take().unwrap());
25512549
for line in stdout.lines() {
25522550
let line = t!(line);
25532551
match serde_json::from_str::<CargoMessage<'_>>(&line) {
@@ -2564,13 +2562,14 @@ pub fn stream_cargo(
25642562
}
25652563

25662564
// Make sure Cargo actually succeeded after we read all of its stdout.
2567-
let status = t!(child.wait());
2565+
let status = t!(streaming_command.wait());
25682566
if builder.is_verbose() && !status.success() {
25692567
eprintln!(
2570-
"command did not execute successfully: {cargo:?}\n\
2568+
"command did not execute successfully: {cmd:?}\n\
25712569
expected success, got: {status}"
25722570
);
25732571
}
2572+
25742573
status.success()
25752574
}
25762575

0 commit comments

Comments
 (0)