Skip to content

Commit 7822b4a

Browse files
committed
feat: retry xcodegen at least three times.
Getting errors from objc NS side with Xcodegen being already created or it can't be overwritten.
1 parent 18697f0 commit 7822b4a

File tree

3 files changed

+33
-51
lines changed

3 files changed

+33
-51
lines changed

src/state/workspace.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,26 @@ impl Workspace {
111111
/// Update .compile commands
112112
#[cfg(feature = "xcodegen")]
113113
pub async fn update_xcodeproj(&mut self, update_config: bool) -> Result<()> {
114-
match xcodegen::generate(&self.root).await {
115-
Ok(msg) => {
116-
tracing::info!("Updated {}.xcodeproj", self.name());
117-
tracing::trace!("{:?}", msg);
118-
if update_config {
119-
tracing::info!("Updated internal state.{}.project", self.name());
120-
self.project = Project::new_from_project_yml(
121-
self.root.clone(),
122-
xcodegen::config_path(self),
123-
)
124-
.await?;
114+
tracing::info!("Updating {}.xcodeproj", self.name());
115+
116+
let retry_count = 0;
117+
while retry_count < 3 {
118+
if let Ok(code) = xcodegen::generate(&self.root).await {
119+
if code.success() {
120+
if update_config {
121+
tracing::info!("Updating State.{}.Project", self.name());
122+
self.project = Project::new_from_project_yml(
123+
self.root.clone(),
124+
xcodegen::config_path(self),
125+
)
126+
.await?;
127+
}
128+
return Ok(());
125129
}
126-
Ok(())
127-
}
128-
Err(e) => {
129-
tracing::error!("xcodegen generate: {:#?}", e);
130-
Err(e)
131130
}
132131
}
132+
133+
anyhow::bail!("Fail to update_xcodeproj")
133134
}
134135

135136
pub fn get_ignore_patterns(&self) -> Option<Vec<String>> {

src/xcode/actions.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ where
1818
I: IntoIterator<Item = S>,
1919
S: AsRef<ffi::OsStr>,
2020
{
21-
tracing::debug!("Building {:?}", root);
21+
tracing::info!("Building {:?}", root);
2222
let output = Command::new("/usr/bin/xcodebuild")
2323
.arg("build")
2424
.args(args)
@@ -47,7 +47,7 @@ where
4747
I: IntoIterator<Item = S>,
4848
S: AsRef<ffi::OsStr>,
4949
{
50-
tracing::debug!("Cleaning {:?}", root);
50+
tracing::info!("Cleaning {:?}", root);
5151

5252
Command::new("/usr/bin/xcodebuild")
5353
.arg("clean")
@@ -63,22 +63,20 @@ where
6363

6464
#[cfg(feature = "serial")]
6565
pub async fn update_compiled_commands(root: &PathBuf, build_log: Vec<String>) -> Result<()> {
66-
fs::write(
67-
root.join(".compile"),
68-
Compiliation::new(build_log).to_json()?,
69-
)
70-
.await?;
71-
tracing::info!("Updated Compiled Commands");
66+
let path = root.join(".compile");
67+
tracing::info!("Updating {:?}", path);
68+
fs::write(path, Compiliation::new(build_log).to_json()?).await?;
7269
Ok(())
7370
}
7471

7572
pub async fn ensure_server_config_file(root: &PathBuf) -> Result<()> {
7673
let path = root.join("buildServer.json");
7774
if fs::File::open(&path).await.is_ok() {
78-
tracing::debug!("buildServer.json exists.");
7975
return Ok(());
8076
}
8177

78+
tracing::info!("Creating {:?}", path);
79+
8280
let mut file = fs::File::create(path).await?;
8381
let config = json! ({
8482
"name": "XcodeBase Server",
@@ -99,7 +97,5 @@ pub async fn ensure_server_config_file(root: &PathBuf) -> Result<()> {
9997
file.sync_all().await?;
10098
file.shutdown().await?;
10199

102-
tracing::debug!("buildServer.json created!");
103-
104100
Ok(())
105101
}

src/xcodegen/mod.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::fmt::Debug;
22
use std::path::{Path, PathBuf};
3+
use std::process::ExitStatus;
34

4-
use anyhow::Result;
5+
use anyhow::{Context, Result};
56

67
use crate::Workspace;
78

@@ -22,33 +23,17 @@ fn xcodgen() -> tokio::process::Command {
2223
}
2324

2425
// Run xcodgen generate
25-
pub async fn generate<P: AsRef<Path> + Debug>(root: P) -> Result<Vec<String>> {
26-
let output = xcodgen()
26+
pub async fn generate<P: AsRef<Path> + Debug>(root: P) -> Result<ExitStatus> {
27+
xcodgen()
2728
.current_dir(root)
28-
.stdout(std::process::Stdio::piped())
29-
.stderr(std::process::Stdio::piped())
29+
.stdout(std::process::Stdio::null())
30+
.stderr(std::process::Stdio::null())
3031
.arg("generate")
3132
.arg("-c")
32-
.spawn()
33-
.expect("Failed to start xcodeGen.")
34-
.wait_with_output()
33+
.spawn()?
34+
.wait()
3535
.await
36-
.expect("Failed to run xcodeGen.");
37-
38-
if output.status.code().unwrap().ne(&0) {
39-
anyhow::bail!(
40-
"{:#?}",
41-
String::from_utf8(output.stderr)?
42-
.split("\n")
43-
.map(|s| s.to_string())
44-
.collect::<Vec<String>>()
45-
)
46-
} else {
47-
Ok(String::from_utf8(output.stdout)?
48-
.split("\n")
49-
.map(|s| s.to_string())
50-
.collect())
51-
}
36+
.context("xcodegen generate")
5237
}
5338

5439
// NOTE: passing workspace in-case in the future we would allow configurability of project.yml path

0 commit comments

Comments
 (0)