diff options
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); } |
