Write the generated file only if its content has actually changed. This avoids bumping the mtime on `stub_map_generated.rs` when nothing changed, which in turn prevents `rustc` from unnecessarily recompiling the main crate.
(content: &str)
| 651 | /// changed, which in turn prevents `rustc` from unnecessarily recompiling |
| 652 | /// the main crate. |
| 653 | fn write_if_changed(content: &str) { |
| 654 | let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set"); |
| 655 | let dest_path = Path::new(&out_dir).join("stub_map_generated.rs"); |
| 656 | |
| 657 | if let Ok(existing) = fs::read_to_string(&dest_path) |
| 658 | && existing == content |
| 659 | { |
| 660 | return; |
| 661 | } |
| 662 | |
| 663 | fs::write(&dest_path, content).expect("Failed to write generated stub map"); |
| 664 | } |
no outgoing calls
no test coverage detected