From 79cce58804ae2d5c6eb0bdceec662295ddd846a7 Mon Sep 17 00:00:00 2001 From: Mateo Kuruk Miccino Date: Sun, 24 Sep 2023 20:00:39 -0300 Subject: [PATCH 1/2] chore: copy rust lib only when it changes --- rust/xtask/src/install_dependency.rs | 31 +++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/rust/xtask/src/install_dependency.rs b/rust/xtask/src/install_dependency.rs index 814db848..3bca8da8 100644 --- a/rust/xtask/src/install_dependency.rs +++ b/rust/xtask/src/install_dependency.rs @@ -156,6 +156,31 @@ pub fn get_godot_executable_path() -> Option { Some(os_url) } +fn copy_if_modified, Q: AsRef>(src: P, dest: Q) -> io::Result<()> { + let src_path = src.as_ref(); + let dest_path = dest.as_ref(); + + // Obtener los metadatos del archivo de origen y destino + let metadata_src = fs::metadata(src_path); + let metadata_dest = fs::metadata(dest_path); + + // Si ambos archivos existen, comparamos sus tiempos de modificación + if metadata_src.is_ok() && metadata_dest.is_ok() { + let time_src = metadata_src?.modified()?; + let time_dest = metadata_dest?.modified()?; + + // Si el archivo de destino es más reciente o igual al de origen, no copiamos + if time_dest >= time_src { + println!("Skip copy, equal file {}", dest_path.to_string_lossy()); + return Ok(()); + } + } + + // Si el archivo de destino no existe o es más antiguo, copiamos el archivo de origen al destino + fs::copy(src_path, dest_path).map(|_| println!("Copying {}", dest_path.to_string_lossy()))?; + Ok(()) +} + pub fn copy_library(debug_mode: bool) -> Result<(), anyhow::Error> { let os = env::consts::OS; let arch = env::consts::ARCH; @@ -174,14 +199,14 @@ pub fn copy_library(debug_mode: bool) -> Result<(), anyhow::Error> { }; let source_folder = format!("{RUST_LIB_PROJECT_FOLDER}{source_folder}"); - println!("Copying {source_folder:?}"); + let source_file = adjust_canonicalization(fs::canonicalize(source_folder)?.join(file_name.clone())); let lib_folder = format!("{GODOT_PROJECT_FOLDER}lib/"); let destination_file = adjust_canonicalization(fs::canonicalize(lib_folder.as_str())?.join(file_name)); - fs::copy(source_file, destination_file)?; + copy_if_modified(source_file, destination_file)?; copy_ffmpeg_libraries(lib_folder)?; @@ -203,7 +228,7 @@ pub fn copy_ffmpeg_libraries(dest_folder: String) -> Result<(), anyhow::Error> { if file_name.ends_with(".dll") { let dest_path = format!("{dest_folder}{file_name}"); - fs::copy(entry.path(), dest_path)?; + copy_if_modified(entry.path(), dest_path)?; } } } From 717385d3960a4e2d51943b52981e5382511b0b56 Mon Sep 17 00:00:00 2001 From: Mateo Kuruk Miccino Date: Mon, 25 Sep 2023 14:30:25 -0300 Subject: [PATCH 2/2] english comments --- rust/xtask/src/install_dependency.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/xtask/src/install_dependency.rs b/rust/xtask/src/install_dependency.rs index 3bca8da8..d1ee3904 100644 --- a/rust/xtask/src/install_dependency.rs +++ b/rust/xtask/src/install_dependency.rs @@ -160,23 +160,23 @@ fn copy_if_modified, Q: AsRef>(src: P, dest: Q) -> io::Resu let src_path = src.as_ref(); let dest_path = dest.as_ref(); - // Obtener los metadatos del archivo de origen y destino + // Obtain the metadata of the source and destination file let metadata_src = fs::metadata(src_path); let metadata_dest = fs::metadata(dest_path); - // Si ambos archivos existen, comparamos sus tiempos de modificación + // If both files exist, we compare their modification times if metadata_src.is_ok() && metadata_dest.is_ok() { let time_src = metadata_src?.modified()?; let time_dest = metadata_dest?.modified()?; - // Si el archivo de destino es más reciente o igual al de origen, no copiamos + // If the destination file is more recent or equal to the source file, we do not copy if time_dest >= time_src { println!("Skip copy, equal file {}", dest_path.to_string_lossy()); return Ok(()); } } - // Si el archivo de destino no existe o es más antiguo, copiamos el archivo de origen al destino + // If the destination file does not exist or is older, we copy the source file to the destination fs::copy(src_path, dest_path).map(|_| println!("Copying {}", dest_path.to_string_lossy()))?; Ok(()) }