Skip to content

Commit a366584

Browse files
committed
fix(xcodebuild): ignoring build failure
1 parent 3f6428e commit a366584

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

src/xcode.rs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::ffi;
55
use std::fmt::Debug;
66
use std::path::{Path, PathBuf};
77
use std::process::{ExitStatus, Stdio};
8+
use tap::Pipe;
89
use tokio::fs;
910
use tokio::io::AsyncWriteExt;
1011
use tokio::process::Command;
@@ -18,29 +19,43 @@ where
1819
S: AsRef<ffi::OsStr>,
1920
{
2021
tracing::info!("Building {:?}", root);
21-
let output = Command::new("/usr/bin/xcodebuild")
22+
let mut result = Command::new("/usr/bin/xcodebuild")
2223
.arg("build")
2324
.args(args)
2425
.stdout(Stdio::piped())
25-
.stderr(Stdio::null())
26+
.stderr(Stdio::piped())
2627
.current_dir(root)
2728
.spawn()?
2829
.wait_with_output()
29-
.await
30-
.map(|o| String::from_utf8(o.stdout))??
31-
.split("\n")
32-
.map(|s| s.to_string())
33-
.collect();
30+
.await?;
31+
32+
let is_successful = result.status.success();
33+
let output = if is_successful {
34+
result.stdout
35+
} else {
36+
result.stdout.extend(result.stderr);
37+
result.stdout
38+
}
39+
.pipe(String::from_utf8)?
40+
.split("\n")
41+
.map(|s| s.to_string())
42+
.collect();
43+
44+
if is_successful {
45+
return Ok(output);
46+
}
47+
48+
output.iter().for_each(|s| {
49+
tracing::error!("{s}");
50+
});
51+
let output = output
52+
.into_iter()
53+
.filter(|s| s.starts_with("error:"))
54+
.map(|s| s.strip_prefix("error:").map(|s| s.to_string()))
55+
.flatten()
56+
.collect::<Vec<_>>();
3457

35-
// TODO: Check xcodebuild build output if it contains failure
36-
//
37-
// Command succeed (return 0 status) but the output contains failure! need to be handled
38-
// somehow as errror
39-
tracing::trace!(
40-
"xcodebuild output: \n{:#?}\n\n\n---------------------------------- end",
41-
output
42-
);
43-
Ok(output)
58+
anyhow::bail!("{}", output.join("\n"));
4459
}
4560

4661
/// run xcodebuild clean with extra arguments

0 commit comments

Comments
 (0)