Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing failed CI builds caused by remove_dir_all failure #618

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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_reliable(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_reliable(path: &std::path::Path) {
let mut retry_count = 0;

while path.exists() {
match std::fs::remove_dir_all(path) {
Ok(_) => break,
Err(err) => {
assert_ne!(
retry_count,
5,
"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_reliable(gen_path);

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