Skip to content

Commit

Permalink
Renames format-* command-line arguments to rustfmt-*
Browse files Browse the repository at this point in the history
The --rustfmt-configuration-file command-line argument automatically activates --rustfmt-bindings.
  • Loading branch information
bkchr committed Aug 14, 2017
1 parent 31f6ced commit 35627a8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
30 changes: 17 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,16 @@ impl Builder {
);
}

if !self.options.format_bindings {
output_vector.push("--format-bindings".into());
if !self.options.rustfmt_bindings {
output_vector.push("--rustfmt-bindings".into());
}

if let Some(path) = self.options.format_configuration_file.as_ref().and_then(
|f| f.to_str()) {
output_vector.push("--format-configuration-file".into());
if let Some(path) = self.options
.rustfmt_configuration_file
.as_ref()
.and_then(|f| f.to_str())
{
output_vector.push("--rustfmt-configuration-file".into());
output_vector.push(path.into());
}

Expand Down Expand Up @@ -852,15 +855,16 @@ impl Builder {
}

/// Set whether rustfmt should format the generated bindings.
pub fn format_bindings(mut self, doit: bool) -> Self {
self.options.format_bindings = doit;
pub fn rustfmt_bindings(mut self, doit: bool) -> Self {
self.options.rustfmt_bindings = doit;
self
}

/// Set the absolute path to the rustfmt configuration file, if None, the standard rustfmt
/// options are used.
pub fn format_configuration_file(mut self, path: Option<PathBuf>) -> Self {
self.options.format_configuration_file = path;
pub fn rustfmt_configuration_file(mut self, path: Option<PathBuf>) -> Self {
self = self.rustfmt_bindings(true);
self.options.rustfmt_configuration_file = path;
self
}

Expand Down Expand Up @@ -1125,11 +1129,11 @@ pub struct BindgenOptions {
rust_features: RustFeatures,

/// Whether rustfmt should format the generated bindings.
pub format_bindings: bool,
pub rustfmt_bindings: bool,

/// The absolute path to the rustfmt configuration file, if None, the standard rustfmt
/// options are used.
pub format_configuration_file: Option<PathBuf>,
pub rustfmt_configuration_file: Option<PathBuf>,
}

/// TODO(emilio): This is sort of a lie (see the error message that results from
Expand Down Expand Up @@ -1214,8 +1218,8 @@ impl Default for BindgenOptions {
objc_extern_crate: false,
enable_mangling: true,
prepend_enum_name: true,
format_bindings: true,
format_configuration_file: None,
rustfmt_bindings: true,
rustfmt_configuration_file: None,
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ 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("format-bindings")
.long("format-bindings")
Arg::with_name("rustfmt-bindings")
.long("rustfmt-bindings")
.help("Format the generated bindings with rustfmt. \
Rustfmt needs to be in the global PATH."),
Arg::with_name("format-configuration-file")
.long("format-configuration-file")
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 \
(when enabled by --format-bindings).")
The configuration file will be used for formatting the bindings. \
Setting this parameter, will automatically set --rustfmt-bindings.")
.value_name("path")
.takes_value(true)
.multiple(false)
Expand Down Expand Up @@ -472,25 +472,25 @@ where
builder.dump_preprocessed_input()?;
}

if matches.is_present("format-bindings") {
builder = builder.format_bindings(true);
if matches.is_present("rustfmt-bindings") {
builder = builder.rustfmt_bindings(true);
}

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

if !path.is_absolute() {
return Err(Error::new(ErrorKind::Other,
"--format-configuration--file needs to be an absolute path!"));
"--rustfmt-configuration--file needs to be an absolute path!"));
}

if path.to_str().is_none() {
return Err(
Error::new(ErrorKind::Other,
"--format-configuration-file contains non-valid UTF8 characters."));
"--rustfmt-configuration-file contains non-valid UTF8 characters."));
}

builder = builder.format_configuration_file(Some(path));
builder = builder.rustfmt_configuration_file(Some(path));
}

let verbose = matches.is_present("verbose");
Expand Down

0 comments on commit 35627a8

Please sign in to comment.