summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index b59c9271..d7aa537e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,6 +32,7 @@ extern crate quote;
extern crate proc_macro2;
extern crate regex;
extern crate shlex;
+#[cfg(feature = "which-rustfmt")]
extern crate which;
#[cfg(feature = "logging")]
@@ -1900,18 +1901,21 @@ impl Bindings {
}
/// Gets the rustfmt path to rustfmt the generated bindings.
- fn rustfmt_path<'a>(&'a self) -> io::Result<Cow<'a, PathBuf>> {
+ fn rustfmt_path<'a>(&'a self) -> io::Result<Option<Cow<'a, PathBuf>>> {
debug_assert!(self.options.rustfmt_bindings);
if let Some(ref p) = self.options.rustfmt_path {
- return Ok(Cow::Borrowed(p));
+ return Ok(Some(Cow::Borrowed(p)));
}
if let Ok(rustfmt) = env::var("RUSTFMT") {
- return Ok(Cow::Owned(rustfmt.into()));
+ return Ok(Some(Cow::Owned(rustfmt.into())));
}
+ #[cfg(feature = "which-rustfmt")]
match which::which("rustfmt") {
- Ok(p) => Ok(Cow::Owned(p)),
+ Ok(p) => Ok(Some(Cow::Owned(p))),
Err(e) => Err(io::Error::new(io::ErrorKind::Other, format!("{}", e))),
}
+ #[cfg(not(feature = "which-rustfmt"))]
+ Ok(None)
}
/// Checks if rustfmt_bindings is set and runs rustfmt on the string
@@ -1926,7 +1930,11 @@ impl Bindings {
return Ok(Cow::Borrowed(source));
}
- let rustfmt = self.rustfmt_path()?;
+ let rustfmt = if let Some(rustfmt) = self.rustfmt_path()? {
+ rustfmt
+ } else {
+ return Ok(Cow::Borrowed(source));
+ };
let mut cmd = Command::new(&*rustfmt);
cmd