diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-01-26 16:06:24 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-26 16:06:24 -0600 |
commit | 4d1c95410d1b4ab55b1f7248ad11bbefda71bcc8 (patch) | |
tree | 9744ec46f8b82f187416bea13c98bea3276c771c | |
parent | 56bbbb0a157b589929cb648c7aad9803270de816 (diff) | |
parent | b16e09ce556137b9b76fa229b1c804afbc88fd99 (diff) |
Auto merge of #1236 - emilio:with-rustfmt, r=fitzgen
lib: Add a way to override rustfmt path.
I'll need it to format some stuff on mozilla-central.
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 25 |
3 files changed, 24 insertions, 5 deletions
@@ -23,7 +23,7 @@ dependencies = [ [[package]] name = "bindgen" -version = "0.32.2" +version = "0.32.3" dependencies = [ "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -13,7 +13,7 @@ name = "bindgen" readme = "README.md" repository = "https://github.com/rust-lang-nursery/rust-bindgen" documentation = "https://docs.rs/bindgen" -version = "0.32.2" +version = "0.32.3" build = "build.rs" include = [ @@ -1079,6 +1079,12 @@ impl Builder { self } + /// Sets an explicit path to rustfmt, to be used when rustfmt is enabled. + pub fn with_rustfmt<P: Into<PathBuf>>(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<Bindings, ()> { 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<PathBuf>, + /// 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()) |