diff options
-rw-r--r-- | src/lib.rs | 19 | ||||
-rw-r--r-- | src/main.rs | 21 | ||||
-rw-r--r-- | src/options.rs | 7 |
3 files changed, 38 insertions, 9 deletions
@@ -433,6 +433,17 @@ impl Builder { self } + /// Set to output verbose messages + pub fn verbose(mut self) -> Self { + self.options.verbose = true; + self + } + + /// Is set to output verbose messages + pub fn is_verbose(&self) -> bool { + return self.options.verbose; + } + /// Generate the Rust bindings using the options built up thus far. pub fn generate<'ctx>(self) -> Result<Bindings<'ctx>, ()> { Bindings::generate(self.options, None) @@ -543,16 +554,19 @@ pub struct BindgenOptions { /// See the builder method description for more details. pub conservative_inline_namespaces: bool, - /// Wether to keep documentation comments in the generated output. See the + /// Whether to keep documentation comments in the generated output. See the /// documentation for more details. pub generate_comments: bool, - /// Wether to whitelist types recursively. Defaults to true. + /// Whether to whitelist types recursively. Defaults to true. pub whitelist_recursively: bool, /// Intead of emitting 'use objc;' to files generated from objective c files, /// generate '#[macro_use] extern crate objc;' pub objc_extern_crate: bool, + + /// Whether we should print verbose messages. + pub verbose: bool, } /// TODO(emilio): This is sort of a lie (see the error message that results from @@ -605,6 +619,7 @@ impl Default for BindgenOptions { generate_comments: true, whitelist_recursively: true, objc_extern_crate: false, + verbose: false, } } } diff --git a/src/main.rs b/src/main.rs index c5d2b063..a73b0fee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,19 +46,16 @@ pub fn main() { match builder_from_flags(bind_args.into_iter()) { Ok((builder, output)) => { + let verbose = (&builder).is_verbose(); let builder_result = panic::catch_unwind(|| builder.generate().expect("Unable to generate bindings") ); if builder_result.is_err() { - println!("Bindgen unexpectedly panicked"); - println!("This may be caused by one of the known-unsupported \ - things (https://github.com/servo/rust-bindgen#c), \ - please modify the bindgen flags to work around it as \ - described in https://github.com/servo/rust-bindgen#c"); - println!("Otherwise, please file an issue at \ - https://github.com/servo/rust-bindgen/issues/new"); + if verbose { + print_verbose_err(); + } std::process::exit(1); } @@ -74,3 +71,13 @@ pub fn main() { } }; } + +fn print_verbose_err() { + println!("Bindgen unexpectedly panicked"); + println!("This may be caused by one of the known-unsupported \ + things (https://github.com/servo/rust-bindgen#c), \ + please modify the bindgen flags to work around it as \ + described in https://github.com/servo/rust-bindgen#c"); + println!("Otherwise, please file an issue at \ + https://github.com/servo/rust-bindgen/issues/new"); +} diff --git a/src/options.rs b/src/options.rs index 535eac4b..f341b5dd 100644 --- a/src/options.rs +++ b/src/options.rs @@ -175,6 +175,9 @@ pub fn builder_from_flags<I>(args: I) .takes_value(true) .multiple(true) .number_of_values(1), + Arg::with_name("verbose") + .long("verbose") + .help("Print verbose error messages"), ]) // .args() .get_matches_from(args); @@ -346,5 +349,9 @@ pub fn builder_from_flags<I>(args: I) Box::new(io::BufWriter::new(io::stdout())) as Box<io::Write> }; + if matches.is_present("verbose") { + builder = builder.verbose(); + } + Ok((builder, output)) } |