Ignore line-endings when checking generated files for freshness

closes #2184
This commit is contained in:
Aleksey Kladov 2019-11-06 12:40:28 +03:00
parent 4fbb36db9b
commit 5efd99a6e0

View file

@ -46,7 +46,7 @@ pub enum Mode {
/// With verify = false, /// With verify = false,
fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
match fs::read_to_string(path) { match fs::read_to_string(path) {
Ok(ref old_contents) if old_contents == contents => { Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => {
return Ok(()); return Ok(());
} }
_ => (), _ => (),
@ -56,7 +56,11 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
} }
eprintln!("updating {}", path.display()); eprintln!("updating {}", path.display());
fs::write(path, contents)?; fs::write(path, contents)?;
Ok(()) return Ok(());
fn normalize(s: &str) -> String {
s.replace("\r\n", "\n")
}
} }
fn reformat(text: impl std::fmt::Display) -> Result<String> { fn reformat(text: impl std::fmt::Display) -> Result<String> {