Helper to execute an external process and generate a helpful error message on failure.
(&self, cmd: &mut Command)
| 1042 | /// Helper to execute an external process and generate a helpful error |
| 1043 | /// message on failure. |
| 1044 | fn run_command(&self, cmd: &mut Command) -> Result<()> { |
| 1045 | if self.opts.inherit_stderr { |
| 1046 | cmd.stderr(Stdio::inherit()); |
| 1047 | } |
| 1048 | let output = cmd |
| 1049 | .output() |
| 1050 | .with_context(|| format!("failed to spawn {cmd:?}"))?; |
| 1051 | if output.status.success() { |
| 1052 | return Ok(()); |
| 1053 | } |
| 1054 | |
| 1055 | let mut error = format!( |
| 1056 | "\ |
| 1057 | command execution failed |
| 1058 | command: {cmd:?} |
| 1059 | status: {}", |
| 1060 | output.status, |
| 1061 | ); |
| 1062 | |
| 1063 | if !output.stdout.is_empty() { |
| 1064 | error.push_str(&format!( |
| 1065 | "\nstdout:\n {}", |
| 1066 | String::from_utf8_lossy(&output.stdout).replace("\n", "\n ") |
| 1067 | )); |
| 1068 | } |
| 1069 | if !output.stderr.is_empty() { |
| 1070 | error.push_str(&format!( |
| 1071 | "\nstderr:\n {}", |
| 1072 | String::from_utf8_lossy(&output.stderr).replace("\n", "\n ") |
| 1073 | )); |
| 1074 | } |
| 1075 | |
| 1076 | bail!("{error}") |
| 1077 | } |
| 1078 | |
| 1079 | /// Converts the WASIp1 module at `p1` to a component using the information |
| 1080 | /// stored within `compile`. |
no test coverage detected