aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/codegen.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/codegen.rs')
-rw-r--r--xtask/src/codegen.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 2f56c5ad0..e3f9ccada 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -32,7 +32,7 @@ pub(crate) use self::{
32#[derive(Debug, PartialEq, Eq, Clone, Copy)] 32#[derive(Debug, PartialEq, Eq, Clone, Copy)]
33pub(crate) enum Mode { 33pub(crate) enum Mode {
34 Overwrite, 34 Overwrite,
35 Verify, 35 Ensure,
36} 36}
37 37
38impl flags::Codegen { 38impl flags::Codegen {
@@ -59,12 +59,19 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
59 } 59 }
60 _ => (), 60 _ => (),
61 } 61 }
62 if mode == Mode::Verify { 62 let return_error = match mode {
63 anyhow::bail!("`{}` is not up-to-date", path.display()); 63 Mode::Overwrite => false,
64 } 64 Mode::Ensure => true,
65 };
65 eprintln!("updating {}", path.display()); 66 eprintln!("updating {}", path.display());
66 write_file(path, contents)?; 67 write_file(path, contents)?;
67 return Ok(()); 68
69 return if return_error {
70 let path = path.strip_prefix(&project_root()).unwrap_or(path);
71 anyhow::bail!("`{}` was not up-to-date, updating", path.display());
72 } else {
73 Ok(())
74 };
68 75
69 fn normalize(s: &str) -> String { 76 fn normalize(s: &str) -> String {
70 s.replace("\r\n", "\n") 77 s.replace("\r\n", "\n")