Skip to content

Commit b891d9a

Browse files
committed
migrate cargo streaming to new bootstrap command streaming API's
1 parent 3f3f12c commit b891d9a

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

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

Lines changed: 10 additions & 14 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;
@@ -2507,7 +2506,6 @@ pub fn stream_cargo(
25072506
#[cfg(feature = "tracing")]
25082507
let _run_span = crate::trace_cmd!(cmd);
25092508

2510-
let cargo = cmd.as_command_mut();
25112509
// Instruct Cargo to give us json messages on stdout, critically leaving
25122510
// stderr as piped so we can get those pretty colors.
25132511
let mut message_format = if builder.config.json_output {
@@ -2519,27 +2517,24 @@ pub fn stream_cargo(
25192517
message_format.push_str(",json-diagnostic-");
25202518
message_format.push_str(s);
25212519
}
2522-
cargo.arg("--message-format").arg(message_format).stdout(Stdio::piped());
2520+
cmd.arg("--message-format").arg(message_format);
25232521

25242522
for arg in tail_args {
2525-
cargo.arg(arg);
2523+
cmd.arg(arg);
25262524
}
25272525

2528-
builder.verbose(|| println!("running: {cargo:?}"));
2526+
builder.verbose(|| println!("running: {cmd:?}"));
25292527

2530-
if builder.config.dry_run() {
2531-
return true;
2532-
}
2528+
let streaming_command = cmd.stream_capture_stdout(&builder.config.exec_ctx);
25332529

2534-
let mut child = match cargo.spawn() {
2535-
Ok(child) => child,
2536-
Err(e) => panic!("failed to execute command: {cargo:?}\nERROR: {e}"),
2530+
let Some(mut streaming_command) = streaming_command else {
2531+
return true;
25372532
};
25382533

25392534
// Spawn Cargo slurping up its JSON output. We'll start building up the
25402535
// `deps` array of all files it generated along with a `toplevel` array of
25412536
// files we need to probe for later.
2542-
let stdout = BufReader::new(child.stdout.take().unwrap());
2537+
let stdout = BufReader::new(streaming_command.stdout.take().unwrap());
25432538
for line in stdout.lines() {
25442539
let line = t!(line);
25452540
match serde_json::from_str::<CargoMessage<'_>>(&line) {
@@ -2556,13 +2551,14 @@ pub fn stream_cargo(
25562551
}
25572552

25582553
// Make sure Cargo actually succeeded after we read all of its stdout.
2559-
let status = t!(child.wait());
2554+
let status = t!(streaming_command.wait());
25602555
if builder.is_verbose() && !status.success() {
25612556
eprintln!(
2562-
"command did not execute successfully: {cargo:?}\n\
2557+
"command did not execute successfully: {cmd:?}\n\
25632558
expected success, got: {status}"
25642559
);
25652560
}
2561+
25662562
status.success()
25672563
}
25682564

src/bootstrap/src/utils/exec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl<'a> BootstrapCommand {
221221
}
222222

223223
/// Spawn the command in background, while capturing and returning stdout, and printing stderr.
224+
/// Returns None in dry-mode
224225
#[track_caller]
225226
pub fn stream_capture_stdout(
226227
&'a mut self,

0 commit comments

Comments
 (0)