summaryrefslogtreecommitdiffstats
path: root/config_macros.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-06-21 12:23:01 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-06-21 12:23:01 +0300
commitf8cef3290e185408e71f353a010e762313c6ec65 (patch)
treebb0cc9826f88c3d02cf2793999ea2360a749be79 /config_macros.rs
parent0169025d503519f5223c9d29ae0c955177a91a6b (diff)
config_macros.rs: try rustfmt on generated module
Diffstat (limited to 'config_macros.rs')
-rw-r--r--config_macros.rs63
1 files changed, 36 insertions, 27 deletions
diff --git a/config_macros.rs b/config_macros.rs
index 7ce5a0ce..7e1cf49d 100644
--- a/config_macros.rs
+++ b/config_macros.rs
@@ -153,33 +153,42 @@ use super::*;
}
}
- /*
- let mut rustfmt = Command::new("rustfmt")
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .stderr(Stdio::piped())
- .spawn()
- .expect("failed to execute rustfmt");
-
- {
- // limited borrow of stdin
- let stdin = rustfmt
- .stdin
- .as_mut()
- .expect("failed to get rustfmt stdin");
- stdin
- .write_all(output_string.as_bytes())
- .expect("failed to write to rustfmit stdin");
- }
+ let rustfmt_closure = move |output_file: &mut File, output_string: &str| {
+ let mut rustfmt = Command::new("rustfmt")
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .stderr(Stdio::piped())
+ .spawn()
+ .map_err(|err| format!("failed to execute rustfmt {}", err))?;
+
+ {
+ // limited borrow of stdin
+ let stdin = rustfmt
+ .stdin
+ .as_mut()
+ .ok_or("failed to get rustfmt stdin")?;
+ stdin
+ .write_all(output_string.as_bytes())
+ .map_err(|err| format!("failed to write to rustfmt stdin {}", err))?;
+ }
- let output = rustfmt
- .wait_with_output()
- .expect("failed to wait on rustfmt child");
- if !output.stderr.is_empty() {
- panic!(format!("{}", String::from_utf8_lossy(&output.stderr)));
- }
+ let output = rustfmt
+ .wait_with_output()
+ .map_err(|err| format!("failed to wait on rustfmt child {}", err))?;
+ if !output.stderr.is_empty() {
+ return Err(format!(
+ "rustfmt invocation replied with: `{}`",
+ String::from_utf8_lossy(&output.stderr)
+ ));
+ }
- output_file.write_all(&output.stdout).unwrap();
- */
- output_file.write_all(output_string.as_bytes()).unwrap();
+ output_file
+ .write_all(&output.stdout)
+ .expect("failed to write to src/conf/overrides.rs");
+ Ok(())
+ };
+ if let Err(err) = rustfmt_closure(&mut output_file, &output_string) {
+ println!("Tried rustfmt on overrides module, got error: {}", err);
+ output_file.write_all(output_string.as_bytes()).unwrap();
+ }
}