diff options
| author | mat <git@matdoes.dev> | 2025-12-23 21:38:56 +0930 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-12-23 06:39:01 -0530 |
| commit | 0fdcff1909b28c5f61587ff5031c67e2880b84fc (patch) | |
| tree | 9a80012d7e74305dcbd458934d57d1f9a9de86ae /azalea-client | |
| parent | 82e3d46ca319badcbc584cf902aeebcbd30948b9 (diff) | |
| download | azalea-drasl-0fdcff1909b28c5f61587ff5031c67e2880b84fc.tar.xz | |
don't write unnecessarily from azalea-client's build script
Diffstat (limited to 'azalea-client')
| -rw-r--r-- | azalea-client/build.rs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/azalea-client/build.rs b/azalea-client/build.rs index 49ef62db..156f73a6 100644 --- a/azalea-client/build.rs +++ b/azalea-client/build.rs @@ -1,11 +1,12 @@ use std::{ - fs::{self, File}, - io::Write, + fmt::Write, + fs::{self}, + path::Path, }; fn main() { // Tell Cargo that if the given file changes, to rerun this build script. - println!("cargo::rerun-if-changed=tests"); + println!("cargo::rerun-if-changed=tests/simulation"); let Ok(paths) = fs::read_dir("tests/simulation") else { return; @@ -29,15 +30,20 @@ fn main() { modules.push(mod_name); } - let Ok(mut mod_rs) = File::create("tests/simulation/mod.rs") else { - return; - }; - let _ = writeln!( - mod_rs, - "// This file is @generated by `azalea-client/build.rs`.\n" - ); + let mut mod_rs = String::new(); + + mod_rs.push_str("// This file is @generated by `azalea-client/build.rs`.\n\n"); modules.sort(); for mod_name in modules { let _ = writeln!(mod_rs, "mod {mod_name};"); } + + let mod_rs_path = Path::new("tests/simulation/mod.rs"); + + let existing_mod_rs = fs::read_to_string(mod_rs_path).unwrap_or_default(); + if mod_rs == existing_mod_rs { + // this would cause the build script to run again + return; + } + let _ = fs::write(mod_rs_path, mod_rs); } |
