Skip to content

Commit 5d9c48e

Browse files
author
bors-servo
authored
Auto merge of #330 - emilio:error, r=xidorn
lib: Return error early if there are any error diagnostics. r? @fitzgen This is a rebase of #280
2 parents 5d91489 + 8a60512 commit 5d9c48e

File tree

7 files changed

+56
-31
lines changed

7 files changed

+56
-31
lines changed

bindgen/src/main.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,6 @@ pub fn main() {
4242
_ => {}
4343
}
4444

45-
if let Some(clang) = clang_sys::support::Clang::find(None) {
46-
let has_clang_args =
47-
bind_args.iter().rposition(|arg| *arg == "--").is_some();
48-
if !has_clang_args {
49-
bind_args.push("--".to_owned());
50-
}
51-
52-
// If --target is specified, assume caller knows what they're doing and
53-
// don't mess with
54-
// include paths for them
55-
let has_target_arg = bind_args.iter()
56-
.rposition(|arg| arg.starts_with("--target"))
57-
.is_some();
58-
if !has_target_arg {
59-
// TODO: distinguish C and C++ paths? C++'s should be enough, I
60-
// guess.
61-
for path in clang.cpp_search_paths.into_iter() {
62-
if let Ok(path) = path.into_os_string().into_string() {
63-
bind_args.push("-isystem".to_owned());
64-
bind_args.push(path);
65-
}
66-
}
67-
}
68-
}
69-
7045
match builder_from_flags(bind_args.into_iter()) {
7146
Ok((builder, output)) => {
7247
let mut bindings = builder.generate()

libbindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ license = "BSD-3-Clause"
1212
name = "libbindgen"
1313
readme = "README.md"
1414
repository = "https://github.com/servo/rust-bindgen"
15-
version = "0.1.1"
15+
version = "0.1.2"
1616
workspace = ".."
1717

1818
[dev-dependencies]

libbindgen/src/lib.rs

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ impl Builder {
168168
/// Set the input C/C++ header.
169169
pub fn header<T: Into<String>>(mut self, header: T) -> Builder {
170170
let header = header.into();
171-
self.options.input_header = Some(header.clone());
172-
self.clang_arg(header)
171+
self.options.input_header = Some(header);
172+
self
173173
}
174174

175175
/// Generate a C/C++ file that includes the header and has dummy uses of
@@ -504,13 +504,36 @@ impl<'ctx> Bindings<'ctx> {
504504
///
505505
/// Deprecated - use a `Builder` instead
506506
#[deprecated]
507-
pub fn generate(options: BindgenOptions,
507+
pub fn generate(mut options: BindgenOptions,
508508
span: Option<Span>)
509509
-> Result<Bindings<'ctx>, ()> {
510510
let span = span.unwrap_or(DUMMY_SP);
511511

512+
// TODO: Make this path fixup configurable?
513+
if let Some(clang) = clang_sys::support::Clang::find(None) {
514+
// If --target is specified, assume caller knows what they're doing
515+
// and don't mess with include paths for them
516+
let has_target_arg = options.clang_args.iter()
517+
.rposition(|arg| arg.starts_with("--target"))
518+
.is_some();
519+
if !has_target_arg {
520+
// TODO: distinguish C and C++ paths? C++'s should be enough, I
521+
// guess.
522+
for path in clang.cpp_search_paths.into_iter() {
523+
if let Ok(path) = path.into_os_string().into_string() {
524+
options.clang_args.push("-isystem".to_owned());
525+
options.clang_args.push(path);
526+
}
527+
}
528+
}
529+
}
530+
531+
if let Some(h) = options.input_header.as_ref() {
532+
options.clang_args.push(h.clone())
533+
}
534+
512535
let mut context = BindgenContext::new(options);
513-
parse(&mut context);
536+
try!(parse(&mut context));
514537

515538
let module = ast::Mod {
516539
inner: span,
@@ -624,14 +647,20 @@ pub fn parse_one(ctx: &mut BindgenContext,
624647
}
625648

626649
/// Parse the Clang AST into our `Item` internal representation.
627-
fn parse(context: &mut BindgenContext) {
650+
fn parse(context: &mut BindgenContext) -> Result<(), ()> {
628651
use clang::Diagnostic;
629652
use clangll::*;
630653

654+
let mut any_error = false;
631655
for d in context.translation_unit().diags().iter() {
632656
let msg = d.format(Diagnostic::default_opts());
633657
let is_err = d.severity() >= CXDiagnostic_Error;
634658
println!("{}, err: {}", msg, is_err);
659+
any_error |= is_err;
660+
}
661+
662+
if any_error {
663+
return Err(());
635664
}
636665

637666
let cursor = context.translation_unit().cursor();
@@ -646,6 +675,7 @@ fn parse(context: &mut BindgenContext) {
646675

647676
assert!(context.current_module() == context.root_module(),
648677
"How did this happen?");
678+
Ok(())
649679
}
650680

651681
/// Extracted Clang version data
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct Foo<T> {
10+
pub bar: ::std::os::raw::c_int,
11+
pub _phantom_0: ::std::marker::PhantomData<T>,
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// bindgen-flags: -- -x c++ --std=c++11
2+
3+
template<typename T>
4+
struct Foo {
5+
int bar;
6+
};

libbindgen/tests/headers/empty_template_param_name.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// bindgen-flags: -- -std=c++11
2+
13
template<typename...> using __void_t = void;
24

35
template<typename _Iterator, typename = __void_t<>>

0 commit comments

Comments
 (0)