Skip to content

Commit 7966566

Browse files
author
bors-servo
authored
Auto merge of rust-lang#183 - emilio:try-fmt-again, r=fitzgen
rustfmt the world. Homu isn't listening to rust-lang#180 apparently so hopefully it'll know about this one.
2 parents dfa2e8c + 7e6a0ab commit 7966566

20 files changed

+1522
-1047
lines changed

CONTRIBUTING.md

+22
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ yourself.
1212
* [Running All Tests](#tests-all)
1313
* [Running a Single, Specific Test](#tests-one)
1414
* [Authoring New Tests](#tests-new)
15+
* [Automatic Code Formatting](#formatting)
1516
* [Debug Logging](#logs)
1617

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

99+
## Automatic code formatting <span id="formatting"/>
100+
101+
There's a `rustfmt.toml` file in the repo. Ideally changes should be consistent
102+
with the style, though that's not enforced right now.
103+
104+
[`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) can catch and fix
105+
automatically all the coding style issues it finds. In order to use it it
106+
suffices to do:
107+
108+
```
109+
$ cargo fmt
110+
```
111+
112+
For it to work, you need to have `rustfmt` installed. To do so:
113+
114+
```
115+
$ cargo install rustfmt
116+
```
117+
118+
And ensure `~/.cargo/bin` is on your path.
119+
98120
## Debug Logging <span id="logs"/>
99121

100122
To help debug what `bindgen` is doing, you can define the environment variable

rustfmt.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
max_width = 80
2+
format_strings = false
3+
fn_brace_style = "SameLineWhere"
4+
item_brace_style = "SameLineWhere"
5+
struct_lit_multiline_style = "ForceMulti"
6+
where_trailing_comma = true
7+
reorder_imports = true
8+
reorder_imported_names = true
9+
normalize_comments = false
10+
write_mode = "Overwrite"

src/bin/bindgen.rs

+32-20
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ extern crate log;
88
extern crate clang_sys;
99
extern crate rustc_serialize;
1010

11-
use bindgen::{Bindings, BindgenOptions, LinkType};
11+
use bindgen::{BindgenOptions, Bindings, LinkType};
1212
use std::default::Default;
13+
use std::env;
14+
use std::fs;
1315
use std::io;
1416
use std::path;
1517
use std::process;
16-
use std::env;
17-
use std::fs;
1818

1919
const USAGE: &'static str = "
2020
Usage:
@@ -119,31 +119,37 @@ fn parse_args_or_exit(args: Vec<String>) -> (BindgenOptions, Box<io::Write>) {
119119
options.links.push((lib, LinkType::Static));
120120
}
121121
"--framework-link" => {
122-
let lib = iter.next().expect("--framework-link needs an argument");
122+
let lib = iter.next()
123+
.expect("--framework-link needs an argument");
123124
options.links.push((lib, LinkType::Framework));
124125
}
125126
"--raw-line" => {
126127
let line = iter.next().expect("--raw-line needs an argument");
127128
options.raw_lines.push(line);
128129
}
129130
"--opaque-type" => {
130-
let ty_canonical_name = iter.next().expect("--opaque-type expects a type");
131+
let ty_canonical_name = iter.next()
132+
.expect("--opaque-type expects a type");
131133
options.opaque_types.insert(ty_canonical_name);
132134
}
133135
"--blacklist-type" => {
134-
let ty_canonical_name = iter.next().expect("--blacklist-type expects a type");
136+
let ty_canonical_name = iter.next()
137+
.expect("--blacklist-type expects a type");
135138
options.hidden_types.insert(ty_canonical_name);
136139
}
137140
"--whitelist-type" => {
138-
let ty_pat = iter.next().expect("--whitelist-type expects a type pattern");
141+
let ty_pat = iter.next()
142+
.expect("--whitelist-type expects a type pattern");
139143
options.whitelisted_types.insert(&ty_pat);
140144
}
141145
"--whitelist-function" => {
142-
let function_pat = iter.next().expect("--whitelist-function expects a pattern");
146+
let function_pat = iter.next()
147+
.expect("--whitelist-function expects a pattern");
143148
options.whitelisted_functions.insert(&function_pat);
144149
}
145150
"--whitelist-var" => {
146-
let var_pat = iter.next().expect("--whitelist-var expects a pattern");
151+
let var_pat = iter.next()
152+
.expect("--whitelist-var expects a pattern");
147153
options.whitelisted_vars.insert(&var_pat);
148154
}
149155
"--" => {
@@ -202,25 +208,31 @@ fn parse_args_or_exit(args: Vec<String>) -> (BindgenOptions, Box<io::Write>) {
202208

203209
pub fn main() {
204210
log::set_logger(|max_log_level| {
205-
use env_logger::Logger;
206-
let env_logger = Logger::new();
207-
max_log_level.set(env_logger.filter());
208-
Box::new(env_logger)
209-
}).expect("Failed to set logger.");
211+
use env_logger::Logger;
212+
let env_logger = Logger::new();
213+
max_log_level.set(env_logger.filter());
214+
Box::new(env_logger)
215+
})
216+
.expect("Failed to set logger.");
210217

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

213220
if let Some(clang) = clang_sys::support::Clang::find(None) {
214-
let has_clang_args = bind_args.iter().rposition(|arg| *arg == "--").is_some();
221+
let has_clang_args =
222+
bind_args.iter().rposition(|arg| *arg == "--").is_some();
215223
if !has_clang_args {
216224
bind_args.push("--".to_owned());
217225
}
218226

219-
// If --target is specified, assume caller knows what they're doing and don't mess with
227+
// If --target is specified, assume caller knows what they're doing and
228+
// don't mess with
220229
// include paths for them
221-
let has_target_arg = bind_args.iter().rposition(|arg| arg.starts_with("--target")).is_some();
230+
let has_target_arg = bind_args.iter()
231+
.rposition(|arg| arg.starts_with("--target"))
232+
.is_some();
222233
if !has_target_arg {
223-
// TODO: distinguish C and C++ paths? C++'s should be enough, I guess.
234+
// TODO: distinguish C and C++ paths? C++'s should be enough, I
235+
// guess.
224236
for path in clang.cpp_search_paths.into_iter() {
225237
if let Ok(path) = path.into_os_string().into_string() {
226238
bind_args.push("-isystem".to_owned());
@@ -233,8 +245,8 @@ pub fn main() {
233245
let (options, out) = parse_args_or_exit(bind_args);
234246

235247
let bindings = Bindings::generate(options, None)
236-
.expect("Unable to generate bindings");
248+
.expect("Unable to generate bindings");
237249

238250
bindings.write(out)
239-
.expect("Unable to write bindings to file.");
251+
.expect("Unable to write bindings to file.");
240252
}

0 commit comments

Comments
 (0)