Skip to content

Commit 6dc4b3c

Browse files
Stop swalling signals in build_system when running sub-commands
1 parent 0f87072 commit 6dc4b3c

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

build_system/src/utils.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,30 @@ use std::collections::HashMap;
22
use std::ffi::OsStr;
33
use std::fmt::Debug;
44
use std::fs;
5+
#[cfg(unix)]
6+
use std::os::unix::process::ExitStatusExt;
57
use std::path::{Path, PathBuf};
68
use std::process::{Command, ExitStatus, Output};
79

10+
fn exec_command(
11+
input: &[&dyn AsRef<OsStr>],
12+
cwd: Option<&Path>,
13+
env: Option<&HashMap<String, String>>,
14+
) -> Result<ExitStatus, String> {
15+
let status = get_command_inner(input, cwd, env)
16+
.spawn()
17+
.map_err(|e| command_error(input, &cwd, e))?
18+
.wait()
19+
.map_err(|e| command_error(input, &cwd, e))?;
20+
#[cfg(unix)]
21+
{
22+
if let Some(signal) = status.signal() {
23+
return Err(command_error(input, &cwd, format!("Process received signal {}", signal)));
24+
}
25+
}
26+
Ok(status)
27+
}
28+
829
fn get_command_inner(
930
input: &[&dyn AsRef<OsStr>],
1031
cwd: Option<&Path>,
@@ -89,11 +110,7 @@ pub fn run_command_with_output(
89110
input: &[&dyn AsRef<OsStr>],
90111
cwd: Option<&Path>,
91112
) -> Result<(), String> {
92-
let exit_status = get_command_inner(input, cwd, None)
93-
.spawn()
94-
.map_err(|e| command_error(input, &cwd, e))?
95-
.wait()
96-
.map_err(|e| command_error(input, &cwd, e))?;
113+
let exit_status = exec_command(input, cwd, None)?;
97114
check_exit_status(input, cwd, exit_status, None, true)?;
98115
Ok(())
99116
}
@@ -103,11 +120,7 @@ pub fn run_command_with_output_and_env(
103120
cwd: Option<&Path>,
104121
env: Option<&HashMap<String, String>>,
105122
) -> Result<(), String> {
106-
let exit_status = get_command_inner(input, cwd, env)
107-
.spawn()
108-
.map_err(|e| command_error(input, &cwd, e))?
109-
.wait()
110-
.map_err(|e| command_error(input, &cwd, e))?;
123+
let exit_status = exec_command(input, cwd, env)?;
111124
check_exit_status(input, cwd, exit_status, None, true)?;
112125
Ok(())
113126
}
@@ -117,11 +130,7 @@ pub fn run_command_with_output_and_env_no_err(
117130
cwd: Option<&Path>,
118131
env: Option<&HashMap<String, String>>,
119132
) -> Result<(), String> {
120-
let exit_status = get_command_inner(input, cwd, env)
121-
.spawn()
122-
.map_err(|e| command_error(input, &cwd, e))?
123-
.wait()
124-
.map_err(|e| command_error(input, &cwd, e))?;
133+
let exit_status = exec_command(input, cwd, env)?;
125134
check_exit_status(input, cwd, exit_status, None, false)?;
126135
Ok(())
127136
}

0 commit comments

Comments
 (0)