From 7cf0fc363c183f8342d16d907a7bc4bafb5c4225 Mon Sep 17 00:00:00 2001 From: Sprite Date: Wed, 11 Oct 2023 16:49:32 +0800 Subject: [PATCH] Fix rebuild for codegen --- spdlog/build.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/spdlog/build.rs b/spdlog/build.rs index 086b91b..6183071 100644 --- a/spdlog/build.rs +++ b/spdlog/build.rs @@ -34,20 +34,20 @@ fn generate_code_test_utils() -> Result<(), Box> { fs::create_dir(&out_dir)?; } - let input = fs::read_to_string("src/test_utils/common.rs")?; + let input = read_code("src/test_utils/common.rs")?; - write_generated_code( + fs::write( out_dir.join("common_for_doc_test.rs"), format!("mod test_utils {{\n{}\n}}", input) .lines() .map(|line| format!("# {}\n", line)) .collect::(), )?; - write_generated_code( + fs::write( out_dir.join("common_for_integration_test.rs"), format!("#[allow(dead_code)]\nmod test_utils {{\n{}\n}}", input), )?; - write_generated_code( + fs::write( out_dir.join("common_for_unit_test.rs"), input.replace("spdlog::", "crate::"), )?; @@ -55,11 +55,7 @@ fn generate_code_test_utils() -> Result<(), Box> { Ok(()) } -fn write_generated_code( - path: impl AsRef, - contents: impl AsRef<[u8]>, -) -> Result<(), Box> { +fn read_code(path: impl AsRef) -> Result> { println!("cargo:rerun-if-changed={}", path.as_ref().display()); - fs::write(path, contents)?; - Ok(()) + Ok(fs::read_to_string(path)?) }