Skip to content

Commit

Permalink
Enable --rustfmt-bindings by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
harlanhaskins committed Sep 22, 2017
1 parent becdc79 commit 89b4dbc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1412,7 +1412,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(),
}
Expand Down Expand Up @@ -1604,10 +1604,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);
Expand Down
22 changes: 17 additions & 5 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 89b4dbc

Please sign in to comment.