Skip to content

Use a consistent style everywhere. #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ yourself.
* [Running All Tests](#tests-all)
* [Running a Single, Specific Test](#tests-one)
* [Authoring New Tests](#tests-new)
* [Automatic Code Formatting](#formatting)
* [Debug Logging](#logs)

## Code of Conduct <span id="coc"/>
Expand Down Expand Up @@ -95,6 +96,27 @@ specify the required features at the top of the test header in a similar manner:
// bingden-features: llvm_stable
```

## Automatic code formatting <span id="formatting"/>

There's a `rustfmt.toml` file in the repo. Ideally changes should be consistent
with the style, though that's not enforced right now.

[`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) can catch and fix
automatically all the coding style issues it finds. In order to use it it
suffices to do:

```
$ cargo fmt
```

For it to work, you need to have `rustfmt` installed. To do so:

```
$ cargo install rustfmt
```

And ensure `~/.cargo/bin` is on your path.

## Debug Logging <span id="logs"/>

To help debug what `bindgen` is doing, you can define the environment variable
Expand Down
10 changes: 10 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
max_width = 80
format_strings = false
fn_brace_style = "SameLineWhere"
item_brace_style = "SameLineWhere"
struct_lit_multiline_style = "ForceMulti"
where_trailing_comma = true
reorder_imports = true
reorder_imported_names = true
normalize_comments = false
write_mode = "Overwrite"
52 changes: 32 additions & 20 deletions src/bin/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ extern crate log;
extern crate clang_sys;
extern crate rustc_serialize;

use bindgen::{Bindings, BindgenOptions, LinkType};
use bindgen::{BindgenOptions, Bindings, LinkType};
use std::default::Default;
use std::env;
use std::fs;
use std::io;
use std::path;
use std::process;
use std::env;
use std::fs;

const USAGE: &'static str = "
Usage:
Expand Down Expand Up @@ -119,31 +119,37 @@ fn parse_args_or_exit(args: Vec<String>) -> (BindgenOptions, Box<io::Write>) {
options.links.push((lib, LinkType::Static));
}
"--framework-link" => {
let lib = iter.next().expect("--framework-link needs an argument");
let lib = iter.next()
.expect("--framework-link needs an argument");
options.links.push((lib, LinkType::Framework));
}
"--raw-line" => {
let line = iter.next().expect("--raw-line needs an argument");
options.raw_lines.push(line);
}
"--opaque-type" => {
let ty_canonical_name = iter.next().expect("--opaque-type expects a type");
let ty_canonical_name = iter.next()
.expect("--opaque-type expects a type");
options.opaque_types.insert(ty_canonical_name);
}
"--blacklist-type" => {
let ty_canonical_name = iter.next().expect("--blacklist-type expects a type");
let ty_canonical_name = iter.next()
.expect("--blacklist-type expects a type");
options.hidden_types.insert(ty_canonical_name);
}
"--whitelist-type" => {
let ty_pat = iter.next().expect("--whitelist-type expects a type pattern");
let ty_pat = iter.next()
.expect("--whitelist-type expects a type pattern");
options.whitelisted_types.insert(&ty_pat);
}
"--whitelist-function" => {
let function_pat = iter.next().expect("--whitelist-function expects a pattern");
let function_pat = iter.next()
.expect("--whitelist-function expects a pattern");
options.whitelisted_functions.insert(&function_pat);
}
"--whitelist-var" => {
let var_pat = iter.next().expect("--whitelist-var expects a pattern");
let var_pat = iter.next()
.expect("--whitelist-var expects a pattern");
options.whitelisted_vars.insert(&var_pat);
}
"--" => {
Expand Down Expand Up @@ -202,25 +208,31 @@ fn parse_args_or_exit(args: Vec<String>) -> (BindgenOptions, Box<io::Write>) {

pub fn main() {
log::set_logger(|max_log_level| {
use env_logger::Logger;
let env_logger = Logger::new();
max_log_level.set(env_logger.filter());
Box::new(env_logger)
}).expect("Failed to set logger.");
use env_logger::Logger;
let env_logger = Logger::new();
max_log_level.set(env_logger.filter());
Box::new(env_logger)
})
.expect("Failed to set logger.");

let mut bind_args: Vec<_> = env::args().collect();

if let Some(clang) = clang_sys::support::Clang::find(None) {
let has_clang_args = bind_args.iter().rposition(|arg| *arg == "--").is_some();
let has_clang_args =
bind_args.iter().rposition(|arg| *arg == "--").is_some();
if !has_clang_args {
bind_args.push("--".to_owned());
}

// If --target is specified, assume caller knows what they're doing and don't mess with
// If --target is specified, assume caller knows what they're doing and
// don't mess with
// include paths for them
let has_target_arg = bind_args.iter().rposition(|arg| arg.starts_with("--target")).is_some();
let has_target_arg = bind_args.iter()
.rposition(|arg| arg.starts_with("--target"))
.is_some();
if !has_target_arg {
// TODO: distinguish C and C++ paths? C++'s should be enough, I guess.
// TODO: distinguish C and C++ paths? C++'s should be enough, I
// guess.
for path in clang.cpp_search_paths.into_iter() {
if let Ok(path) = path.into_os_string().into_string() {
bind_args.push("-isystem".to_owned());
Expand All @@ -233,8 +245,8 @@ pub fn main() {
let (options, out) = parse_args_or_exit(bind_args);

let bindings = Bindings::generate(options, None)
.expect("Unable to generate bindings");
.expect("Unable to generate bindings");

bindings.write(out)
.expect("Unable to write bindings to file.");
.expect("Unable to write bindings to file.");
}
Loading