Skip to content

Commit 9113b7b

Browse files
author
bors-servo
authored
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.
2 parents 8f3c575 + 89b4dbc commit 9113b7b

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/lib.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl Builder {
492492
}
493493

494494
if !self.options.rustfmt_bindings {
495-
output_vector.push("--rustfmt-bindings".into());
495+
output_vector.push("--no-rustfmt-bindings".into());
496496
}
497497

498498
if let Some(path) = self.options
@@ -1416,7 +1416,7 @@ impl Default for BindgenOptions {
14161416
enable_mangling: true,
14171417
prepend_enum_name: true,
14181418
time_phases: false,
1419-
rustfmt_bindings: false,
1419+
rustfmt_bindings: true,
14201420
rustfmt_configuration_file: None,
14211421
no_partialeq_types: Default::default(),
14221422
}
@@ -1608,10 +1608,8 @@ impl Bindings {
16081608
let rustfmt = if let Ok(rustfmt) = which::which("rustfmt") {
16091609
rustfmt
16101610
} else {
1611-
return Err(io::Error::new(
1612-
io::ErrorKind::Other,
1613-
"Rustfmt activated, but it could not be found in global path.",
1614-
));
1611+
warn!("Not running rustfmt because it does not exist in PATH");
1612+
return Ok(());
16151613
};
16161614

16171615
let mut cmd = Command::new(rustfmt);

src/options.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,19 @@ where
257257
Useful when debugging bindgen, using C-Reduce, or when \
258258
filing issues. The resulting file will be named \
259259
something like `__bindgen.i` or `__bindgen.ii`."),
260+
Arg::with_name("no-rustfmt-bindings")
261+
.long("no-rustfmt-bindings")
262+
.help("Do not format the generated bindings with rustfmt."),
260263
Arg::with_name("rustfmt-bindings")
261264
.long("rustfmt-bindings")
262-
.help("Format the generated bindings with rustfmt. \
263-
Rustfmt needs to be in the global PATH."),
265+
.help("Format the generated bindings with rustfmt. DEPRECATED: \
266+
--rustfmt-bindings is now enabled by default. Disable \
267+
with --no-rustfmt-bindings."),
264268
Arg::with_name("rustfmt-configuration-file")
265269
.long("rustfmt-configuration-file")
266270
.help("The absolute path to the rustfmt configuration file. \
267271
The configuration file will be used for formatting the bindings. \
268-
Setting this parameter, will automatically set --rustfmt-bindings.")
272+
This parameter is incompatible with --no-rustfmt-bindings.")
269273
.value_name("path")
270274
.takes_value(true)
271275
.multiple(false)
@@ -529,13 +533,21 @@ where
529533
builder.dump_preprocessed_input()?;
530534
}
531535

532-
if matches.is_present("rustfmt-bindings") {
533-
builder = builder.rustfmt_bindings(true);
536+
let no_rustfmt_bindings = matches.is_present("no-rustfmt-bindings");
537+
if no_rustfmt_bindings {
538+
builder = builder.rustfmt_bindings(false);
534539
}
535540

536541
if let Some(path_str) = matches.value_of("rustfmt-configuration-file") {
537542
let path = PathBuf::from(path_str);
538543

544+
if no_rustfmt_bindings {
545+
return Err(Error::new(
546+
ErrorKind::Other,
547+
"Cannot supply both --rustfmt-configuration-file and --no-rustfmt-bindings"
548+
));
549+
}
550+
539551
if !path.is_absolute() {
540552
return Err(Error::new(
541553
ErrorKind::Other,

0 commit comments

Comments
 (0)