diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-09-25 13:10:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-25 13:10:42 -0500 |
commit | 9113b7b51b189a4a8e4c2d59d8403e3f947239fe (patch) | |
tree | 40e8c19dd44fae3b1953dd6720136b9e726e3133 | |
parent | 8f3c5753e3c61b715771dec1614170eb7bd3e214 (diff) | |
parent | 89b4dbc55abb037aba2556052e15fc91c95da9cd (diff) |
Auto merge of #1022 - harlanhaskins:rustfmt-by-default, r=fitzgen
Enable --rustfmt-bindings by default
This patch flips --rustfmt-bindings to --no-rustfmt-bindings and enables
formatting by default. If rustfmt is not accessible, a warning is
printed and the bindings are printed unformatted.
Addresses #977.
-rw-r--r-- | src/lib.rs | 10 | ||||
-rw-r--r-- | src/options.rs | 22 |
2 files changed, 21 insertions, 11 deletions
@@ -492,7 +492,7 @@ impl Builder { } if !self.options.rustfmt_bindings { - output_vector.push("--rustfmt-bindings".into()); + output_vector.push("--no-rustfmt-bindings".into()); } if let Some(path) = self.options @@ -1416,7 +1416,7 @@ impl Default for BindgenOptions { enable_mangling: true, prepend_enum_name: true, time_phases: false, - rustfmt_bindings: false, + rustfmt_bindings: true, rustfmt_configuration_file: None, no_partialeq_types: Default::default(), } @@ -1608,10 +1608,8 @@ impl Bindings { let rustfmt = if let Ok(rustfmt) = which::which("rustfmt") { rustfmt } else { - return Err(io::Error::new( - io::ErrorKind::Other, - "Rustfmt activated, but it could not be found in global path.", - )); + warn!("Not running rustfmt because it does not exist in PATH"); + return Ok(()); }; let mut cmd = Command::new(rustfmt); diff --git a/src/options.rs b/src/options.rs index d8a98641..aec4a2bd 100644 --- a/src/options.rs +++ b/src/options.rs @@ -257,15 +257,19 @@ where Useful when debugging bindgen, using C-Reduce, or when \ filing issues. The resulting file will be named \ something like `__bindgen.i` or `__bindgen.ii`."), + Arg::with_name("no-rustfmt-bindings") + .long("no-rustfmt-bindings") + .help("Do not format the generated bindings with rustfmt."), Arg::with_name("rustfmt-bindings") .long("rustfmt-bindings") - .help("Format the generated bindings with rustfmt. \ - Rustfmt needs to be in the global PATH."), + .help("Format the generated bindings with rustfmt. DEPRECATED: \ + --rustfmt-bindings is now enabled by default. Disable \ + with --no-rustfmt-bindings."), Arg::with_name("rustfmt-configuration-file") .long("rustfmt-configuration-file") .help("The absolute path to the rustfmt configuration file. \ The configuration file will be used for formatting the bindings. \ - Setting this parameter, will automatically set --rustfmt-bindings.") + This parameter is incompatible with --no-rustfmt-bindings.") .value_name("path") .takes_value(true) .multiple(false) @@ -529,13 +533,21 @@ where builder.dump_preprocessed_input()?; } - if matches.is_present("rustfmt-bindings") { - builder = builder.rustfmt_bindings(true); + let no_rustfmt_bindings = matches.is_present("no-rustfmt-bindings"); + if no_rustfmt_bindings { + builder = builder.rustfmt_bindings(false); } if let Some(path_str) = matches.value_of("rustfmt-configuration-file") { let path = PathBuf::from(path_str); + if no_rustfmt_bindings { + return Err(Error::new( + ErrorKind::Other, + "Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings" + )); + } + if !path.is_absolute() { return Err(Error::new( ErrorKind::Other, |