From 2dc46ac96e4c6721b0aa5248ba49e06307fc7cf4 Mon Sep 17 00:00:00 2001 From: Emilio Cobos Álvarez Date: Fri, 26 Jan 2018 21:09:42 +0100 Subject: lib: Add a way to override rustfmt path. I'll need it to format some stuff on mozilla-central. --- src/lib.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d7a1f2be..c2315e05 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1079,6 +1079,12 @@ impl Builder { self } + /// Sets an explicit path to rustfmt, to be used when rustfmt is enabled. + pub fn with_rustfmt>(mut self, path: P) -> Self { + self.options.rustfmt_path = Some(path.into()); + self + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate(mut self) -> Result { self.options.input_header = self.input_headers.pop(); @@ -1216,6 +1222,9 @@ struct BindgenOptions { /// generated code. opaque_types: RegexSet, + /// The explicit rustfmt path. + rustfmt_path: Option, + /// The set of types that we should have bindings for in the generated /// code. /// @@ -1441,6 +1450,7 @@ impl Default for BindgenOptions { rust_features: rust_target.into(), blacklisted_types: Default::default(), opaque_types: Default::default(), + rustfmt_path: Default::default(), whitelisted_types: Default::default(), whitelisted_functions: Default::default(), whitelisted_vars: Default::default(), @@ -1709,10 +1719,19 @@ impl Bindings { return Ok(Cow::Borrowed(source)); } - let rustfmt = which::which("rustfmt") - .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_owned()))?; + let rustfmt = match self.options.rustfmt_path { + Some(ref p) => Cow::Borrowed(p), + None => { + let path = which::which("rustfmt") + .map_err(|e| { + io::Error::new(io::ErrorKind::Other, e.to_owned()) + })?; + + Cow::Owned(path) + } + }; - let mut cmd = Command::new(rustfmt); + let mut cmd = Command::new(&*rustfmt); cmd .stdin(Stdio::piped()) -- cgit v1.2.3