Skip to content

Commit 62f8ed1

Browse files
committed
Added false-by-default verbose option flag
1 parent 09bc835 commit 62f8ed1

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,17 @@ impl Builder {
433433
self
434434
}
435435

436+
/// Set to output verbose messages
437+
pub fn verbose(mut self) -> Self {
438+
self.options.verbose = true;
439+
self
440+
}
441+
442+
/// Is set to output verbose messages
443+
pub fn is_verbose(&self) -> bool {
444+
return self.options.verbose;
445+
}
446+
436447
/// Generate the Rust bindings using the options built up thus far.
437448
pub fn generate<'ctx>(self) -> Result<Bindings<'ctx>, ()> {
438449
Bindings::generate(self.options, None)
@@ -543,16 +554,19 @@ pub struct BindgenOptions {
543554
/// See the builder method description for more details.
544555
pub conservative_inline_namespaces: bool,
545556

546-
/// Wether to keep documentation comments in the generated output. See the
557+
/// Whether to keep documentation comments in the generated output. See the
547558
/// documentation for more details.
548559
pub generate_comments: bool,
549560

550-
/// Wether to whitelist types recursively. Defaults to true.
561+
/// Whether to whitelist types recursively. Defaults to true.
551562
pub whitelist_recursively: bool,
552563

553564
/// Intead of emitting 'use objc;' to files generated from objective c files,
554565
/// generate '#[macro_use] extern crate objc;'
555566
pub objc_extern_crate: bool,
567+
568+
/// Whether we should print verbose messages.
569+
pub verbose: bool,
556570
}
557571

558572
/// TODO(emilio): This is sort of a lie (see the error message that results from
@@ -605,6 +619,7 @@ impl Default for BindgenOptions {
605619
generate_comments: true,
606620
whitelist_recursively: true,
607621
objc_extern_crate: false,
622+
verbose: false,
608623
}
609624
}
610625
}

src/main.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,16 @@ pub fn main() {
4646
match builder_from_flags(bind_args.into_iter()) {
4747
Ok((builder, output)) => {
4848

49+
let verbose = (&builder).is_verbose();
4950
let builder_result =
5051
panic::catch_unwind(||
5152
builder.generate().expect("Unable to generate bindings")
5253
);
5354

5455
if builder_result.is_err() {
55-
println!("Bindgen unexpectedly panicked");
56-
println!("This may be caused by one of the known-unsupported \
57-
things (https://github.com/servo/rust-bindgen#c), \
58-
please modify the bindgen flags to work around it as \
59-
described in https://github.com/servo/rust-bindgen#c");
60-
println!("Otherwise, please file an issue at \
61-
https://github.com/servo/rust-bindgen/issues/new");
56+
if verbose {
57+
print_verbose_err();
58+
}
6259
std::process::exit(1);
6360
}
6461

@@ -74,3 +71,13 @@ pub fn main() {
7471
}
7572
};
7673
}
74+
75+
fn print_verbose_err() {
76+
println!("Bindgen unexpectedly panicked");
77+
println!("This may be caused by one of the known-unsupported \
78+
things (https://github.com/servo/rust-bindgen#c), \
79+
please modify the bindgen flags to work around it as \
80+
described in https://github.com/servo/rust-bindgen#c");
81+
println!("Otherwise, please file an issue at \
82+
https://github.com/servo/rust-bindgen/issues/new");
83+
}

src/options.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ pub fn builder_from_flags<I>(args: I)
175175
.takes_value(true)
176176
.multiple(true)
177177
.number_of_values(1),
178+
Arg::with_name("verbose")
179+
.long("verbose")
180+
.help("Print verbose error messages"),
178181
]) // .args()
179182
.get_matches_from(args);
180183

@@ -346,5 +349,9 @@ pub fn builder_from_flags<I>(args: I)
346349
Box::new(io::BufWriter::new(io::stdout())) as Box<io::Write>
347350
};
348351

352+
if matches.is_present("verbose") {
353+
builder = builder.verbose();
354+
}
355+
349356
Ok((builder, output))
350357
}

0 commit comments

Comments
 (0)