Skip to content

Commit f125ce1

Browse files
committed
remove_dir_all CI build fix
1 parent 3b7c674 commit f125ce1

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

godot-bindings/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ const NEXT_MINOR_VERSION: u8 = 3;
128128

129129
pub fn clear_dir(dir: &Path, watch: &mut StopWatch) {
130130
if dir.exists() {
131-
std::fs::remove_dir_all(dir).unwrap_or_else(|e| panic!("failed to delete dir: {e}"));
131+
remove_dir_all_reliable(dir);
132132
watch.record("delete_gen_dir");
133133
}
134134
std::fs::create_dir_all(dir).unwrap_or_else(|e| panic!("failed to create dir: {e}"));
@@ -161,3 +161,25 @@ pub fn emit_godot_version_cfg() {
161161
println!(r#"cargo:rustc-cfg=gdextension_exact_api="{major}.{minor}""#);
162162
}
163163
}
164+
165+
// Function for safely removal of build directory. Workaround for errors happening during CI builds:
166+
// https://github.com/godot-rust/gdext/issues/616
167+
pub fn remove_dir_all_reliable(path: &std::path::Path) {
168+
let mut retry_count = 0;
169+
170+
while path.exists() {
171+
match std::fs::remove_dir_all(path) {
172+
Ok(_) => break,
173+
Err(err) => {
174+
if retry_count >= 5 {
175+
panic!(
176+
"cannot remove directory: {path_display} after 5 tries with error: {err}",
177+
path_display = path.display()
178+
)
179+
}
180+
retry_count += 1;
181+
std::thread::sleep(std::time::Duration::from_millis(10));
182+
}
183+
}
184+
}
185+
}

godot-core/build.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ fn main() {
1212
// struggle with static analysis when symbols are outside the crate directory (April 2023).
1313
let gen_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/gen"));
1414

15-
if gen_path.exists() {
16-
std::fs::remove_dir_all(gen_path).unwrap_or_else(|e| panic!("failed to delete dir: {e}"));
17-
}
15+
godot_bindings::remove_dir_all_reliable(gen_path);
1816

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

0 commit comments

Comments
 (0)