From 0fdcff1909b28c5f61587ff5031c67e2880b84fc Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 23 Dec 2025 21:38:56 +0930 Subject: don't write unnecessarily from azalea-client's build script --- azalea-client/build.rs | 26 ++++++++++++++++---------- azalea/src/bot.rs | 4 ++-- 2 files changed, 18 insertions(+), 12 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); } diff --git a/azalea/src/bot.rs b/azalea/src/bot.rs index 8410f0b1..33293466 100644 --- a/azalea/src/bot.rs +++ b/azalea/src/bot.rs @@ -86,8 +86,8 @@ fn stop_jumping(mut query: Query<(&mut Jumping, &mut Bot)>) { } } -/// A trait that adds a few additional functions to [`Client`] that help with -/// making bots. +/// A trait that adds a few additional functions to +/// [`Client`](azalea_client::Client) that help with making bots. pub trait BotClientExt { /// Queue a jump for the next tick. fn jump(&self); -- cgit v1.2.3