Skip to content

Commit

Permalink
remove_dir_all CI build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
StatisMike committed Feb 20, 2024
1 parent 3b7c674 commit cc1f412
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 23 additions & 1 deletion godot-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ const NEXT_MINOR_VERSION: u8 = 3;

pub fn clear_dir(dir: &Path, watch: &mut StopWatch) {
if dir.exists() {
std::fs::remove_dir_all(dir).unwrap_or_else(|e| panic!("failed to delete dir: {e}"));
remove_dir_all_safe(dir);
watch.record("delete_gen_dir");
}
std::fs::create_dir_all(dir).unwrap_or_else(|e| panic!("failed to create dir: {e}"));
Expand Down Expand Up @@ -161,3 +161,25 @@ pub fn emit_godot_version_cfg() {
println!(r#"cargo:rustc-cfg=gdextension_exact_api="{major}.{minor}""#);
}
}

// Function for safely removal of build directory. Workaround for errors happening during CI builds:
// https://github.com/godot-rust/gdext/issues/616
pub fn remove_dir_all_safe(path: &std::path::Path) {
let mut retry_count = 0;

while retry_count <= 5 && path.exists() {
match std::fs::remove_dir_all(path) {
Ok(_) => break,
Err(err) => {
if retry_count >= 5 {
panic!(
"cannot remove directory: {path_display} after 5 tries with error: {err}",
path_display = path.display()
)
}
retry_count += 1;
std::thread::sleep(std::time::Duration::from_millis(10));
}
}
}
}
4 changes: 1 addition & 3 deletions godot-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ fn main() {
// struggle with static analysis when symbols are outside the crate directory (April 2023).
let gen_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen"));

if gen_path.exists() {
std::fs::remove_dir_all(gen_path).unwrap_or_else(|e| panic!("failed to delete dir: {e}"));
}
godot_bindings::remove_dir_all_safe(gen_path);

godot_codegen::generate_core_files(gen_path);
println!("cargo:rerun-if-changed=build.rs");
Expand Down

0 comments on commit cc1f412

Please sign in to comment.