|
1 | 1 | use std::{
|
2 | 2 | path::{Path, PathBuf},
|
3 | 3 | process::Command,
|
4 |
| - str::from_utf8, |
5 | 4 | sync::mpsc::Receiver,
|
6 | 5 | };
|
7 | 6 |
|
@@ -91,13 +90,6 @@ pub(crate) fn run_make(config: &BuildConfig, arg: &Path) -> BuildStatus {
|
91 | 90 | ..Default::default()
|
92 | 91 | };
|
93 | 92 | };
|
94 |
| - match run_make_cmd(config, cwd, arg) { |
95 |
| - Ok(status) => status, |
96 |
| - Err(e) => BuildStatus { success: false, stderr: e.to_string(), ..Default::default() }, |
97 |
| - } |
98 |
| -} |
99 |
| - |
100 |
| -fn run_make_cmd(config: &BuildConfig, cwd: &Path, arg: &Path) -> Result<BuildStatus> { |
101 | 93 | let make = config.custom_make.as_deref().unwrap_or("make");
|
102 | 94 | let make_args = config.custom_args.as_deref().unwrap_or(&[]);
|
103 | 95 | #[cfg(not(windows))]
|
@@ -144,15 +136,23 @@ fn run_make_cmd(config: &BuildConfig, cwd: &Path, arg: &Path) -> Result<BuildSta
|
144 | 136 | cmdline.push(' ');
|
145 | 137 | cmdline.push_str(shell_escape::escape(arg.to_string_lossy()).as_ref());
|
146 | 138 | }
|
147 |
| - let output = command.output().map_err(|e| anyhow!("Failed to execute build: {e}"))?; |
148 |
| - let stdout = from_utf8(&output.stdout).context("Failed to process stdout")?; |
149 |
| - let stderr = from_utf8(&output.stderr).context("Failed to process stderr")?; |
150 |
| - Ok(BuildStatus { |
151 |
| - success: output.status.code().unwrap_or(-1) == 0, |
152 |
| - cmdline, |
153 |
| - stdout: stdout.to_string(), |
154 |
| - stderr: stderr.to_string(), |
155 |
| - }) |
| 139 | + let output = match command.output() { |
| 140 | + Ok(output) => output, |
| 141 | + Err(e) => { |
| 142 | + return BuildStatus { |
| 143 | + success: false, |
| 144 | + cmdline, |
| 145 | + stdout: Default::default(), |
| 146 | + stderr: e.to_string(), |
| 147 | + }; |
| 148 | + } |
| 149 | + }; |
| 150 | + // Try from_utf8 first to avoid copying the buffer if it's valid, then fall back to from_utf8_lossy |
| 151 | + let stdout = String::from_utf8(output.stdout) |
| 152 | + .unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned()); |
| 153 | + let stderr = String::from_utf8(output.stderr) |
| 154 | + .unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned()); |
| 155 | + BuildStatus { success: output.status.success(), cmdline, stdout, stderr } |
156 | 156 | }
|
157 | 157 |
|
158 | 158 | fn run_build(
|
|
0 commit comments