Skip to content

Commit a7c1a06

Browse files
committed
Fix rebuild for code generation
1 parent 0901547 commit a7c1a06

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

spdlog/build.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,28 @@ fn generate_code_test_utils() -> Result<(), Box<dyn Error>> {
3434
fs::create_dir(&out_dir)?;
3535
}
3636

37-
let input = fs::read_to_string("src/test_utils/common.rs")?;
37+
let input = read_code("src/test_utils/common.rs")?;
3838

39-
write_generated_code(
39+
fs::write(
4040
out_dir.join("common_for_doc_test.rs"),
4141
format!("mod test_utils {{\n{}\n}}", input)
4242
.lines()
4343
.map(|line| format!("# {}\n", line))
4444
.collect::<String>(),
4545
)?;
46-
write_generated_code(
46+
fs::write(
4747
out_dir.join("common_for_integration_test.rs"),
4848
format!("#[allow(dead_code)]\nmod test_utils {{\n{}\n}}", input),
4949
)?;
50-
write_generated_code(
50+
fs::write(
5151
out_dir.join("common_for_unit_test.rs"),
5252
input.replace("spdlog::", "crate::"),
5353
)?;
5454

5555
Ok(())
5656
}
5757

58-
fn write_generated_code(
59-
path: impl AsRef<Path>,
60-
contents: impl AsRef<[u8]>,
61-
) -> Result<(), Box<dyn Error>> {
58+
fn read_code(path: impl AsRef<Path>) -> Result<String, Box<dyn Error>> {
6259
println!("cargo:rerun-if-changed={}", path.as_ref().display());
63-
fs::write(path, contents)?;
64-
Ok(())
60+
Ok(fs::read_to_string(path)?)
6561
}

0 commit comments

Comments
 (0)