Skip to content

Commit 00d9bc7

Browse files
authored
refactor: unify doc command with stderr filtering (#35)
1 parent fcf0359 commit 00d9bc7

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

src/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn generate_single_target_doc(
213213

214214
debug!("Running rustdoc for {}: {:?}", target.name, cmd);
215215

216-
let status = cmd.status()?;
216+
let status = verus::run_filtered_command(&mut cmd)?;
217217
if !status.success() {
218218
return Err(format!("rustdoc failed for target: {}", target.name).into());
219219
}

src/verus.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ pub fn exec_verify(targets: &[VerusTarget], options: &ExtraOptions) -> Result<()
649649
);
650650
debug!(">> {:?}", cmd);
651651

652-
let status = run_verify_command(cmd).unwrap_or_else(|e| {
652+
let status = run_filtered_command(cmd).unwrap_or_else(|e| {
653653
error!("Error during verification: {}", e);
654654
});
655655

@@ -718,7 +718,7 @@ const VERUS_SPEC_WARNING_START: &str =
718718
const VERUS_SPEC_WARNING_END: &str =
719719
"= note: this warning originates in the attribute macro `verus_spec`";
720720

721-
fn run_verify_command(cmd: &mut Command) -> std::io::Result<std::process::ExitStatus> {
721+
pub fn run_filtered_command(cmd: &mut Command) -> std::io::Result<std::process::ExitStatus> {
722722
let configured_color = std::env::var_os("CARGO_TERM_COLOR");
723723
if should_force_cargo_color(std::io::stderr().is_terminal(), configured_color.as_deref()) {
724724
// Piping stderr for filtering would otherwise make Cargo disable the
@@ -730,14 +730,21 @@ fn run_verify_command(cmd: &mut Command) -> std::io::Result<std::process::ExitSt
730730
let child_stderr = child.stderr.take().ok_or_else(|| {
731731
std::io::Error::new(
732732
std::io::ErrorKind::Other,
733-
"could not capture the verification process stderr",
733+
"could not capture the process stderr",
734734
)
735735
})?;
736736

737737
let filter_result =
738738
filter_verus_spec_warnings(BufReader::new(child_stderr), &mut std::io::stderr().lock());
739739
let status_result = child.wait();
740740

741+
// If stderr filtering failed (e.g. the writer closed), don't leave the
742+
// child process orphaned and running during a long `make` flow.
743+
if filter_result.is_err() {
744+
let _ = child.kill();
745+
let _ = child.wait();
746+
}
747+
741748
filter_result?;
742749
status_result
743750
}
@@ -892,7 +899,7 @@ pub fn exec_build(targets: &[VerusTarget], options: &ExtraOptions) -> Result<(),
892899
);
893900
debug!(">> {:?}", cmd);
894901

895-
let status = cmd.status().unwrap_or_else(|e| {
902+
let status = run_filtered_command(cmd).unwrap_or_else(|e| {
896903
error!("Error during build: {}", e);
897904
});
898905

0 commit comments

Comments
 (0)