diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-07-27 19:23:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-27 19:23:18 -0500 |
commit | 0e39721b6c72b574026a0802792c4e95f0d83e68 (patch) | |
tree | d0a788cf8d0236621cd6eaaef25ba1c41397e370 | |
parent | 0fab51e501f45727169516f605de31e7e1d19a62 (diff) | |
parent | 05b1550f0450cea997dc5dff4083aa4b09d01aae (diff) |
Auto merge of #860 - emilio:issue-848, r=fitzgenv0.29.0
lib: Filter out include paths when looking for clang paths.
Fixes #848
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 29 | ||||
-rw-r--r-- | tests/expectations/tests/issue-848-replacement-system-include.rs | 24 | ||||
-rw-r--r-- | tests/headers/issue-848-replacement-system-include.hpp | 7 | ||||
-rw-r--r-- | tests/headers/issue-848/an-include.h | 17 |
6 files changed, 78 insertions, 3 deletions
@@ -1,6 +1,6 @@ [root] name = "bindgen" -version = "0.28.0" +version = "0.29.0" dependencies = [ "aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -13,7 +13,7 @@ name = "bindgen" readme = "README.md" repository = "https://github.com/rust-lang-nursery/rust-bindgen" documentation = "https://docs.rs/bindgen" -version = "0.28.0" +version = "0.29.0" build = "build.rs" exclude = [ @@ -1162,8 +1162,35 @@ impl<'ctx> Bindings<'ctx> { options.build(); + // Filter out include paths and similar stuff, so we don't incorrectly + // promote them to `-isystem`. + let clang_args_for_clang_sys = { + let mut last_was_include_prefix = false; + options.clang_args.iter().filter(|arg| { + if last_was_include_prefix { + last_was_include_prefix = false; + return false; + } + + let arg = &**arg; + + // https://clang.llvm.org/docs/ClangCommandLineReference.html + // -isystem and -isystem-after are harmless. + if arg == "-I" || arg == "--include-directory" { + last_was_include_prefix = true; + return false; + } + + if arg.starts_with("-I") || arg.starts_with("--include-directory=") { + return false; + } + + true + }).cloned().collect::<Vec<_>>() + }; + // TODO: Make this path fixup configurable? - if let Some(clang) = clang_sys::support::Clang::find(None, &options.clang_args) { + if let Some(clang) = clang_sys::support::Clang::find(None, &clang_args_for_clang_sys) { // If --target is specified, assume caller knows what they're doing // and don't mess with include paths for them let has_target_arg = options.clang_args diff --git a/tests/expectations/tests/issue-848-replacement-system-include.rs b/tests/expectations/tests/issue-848-replacement-system-include.rs new file mode 100644 index 00000000..14083705 --- /dev/null +++ b/tests/expectations/tests/issue-848-replacement-system-include.rs @@ -0,0 +1,24 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +/// This is intended to replace another type, but won't if we treat this include +/// as a system include, because clang doesn't parse comments there. +/// +/// See #848. +/// +/// <div rustbindgen replaces="nsTArray"></div> +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct nsTArray<T> { + pub m: *mut T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, +} +impl <T> Default for nsTArray<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +extern "C" { + pub fn func() -> *mut nsTArray<::std::os::raw::c_int>; +} diff --git a/tests/headers/issue-848-replacement-system-include.hpp b/tests/headers/issue-848-replacement-system-include.hpp new file mode 100644 index 00000000..e95c823f --- /dev/null +++ b/tests/headers/issue-848-replacement-system-include.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: -- -Itests/headers/issue-848 + +#include "an-include.h" + +extern "C" { + nsTArray<int>* func(); +} diff --git a/tests/headers/issue-848/an-include.h b/tests/headers/issue-848/an-include.h new file mode 100644 index 00000000..0421d19f --- /dev/null +++ b/tests/headers/issue-848/an-include.h @@ -0,0 +1,17 @@ +template<typename T> +class nsTArray { + void* mBuffer; +}; + +/** + * This is intended to replace another type, but won't if we treat this include + * as a system include, because clang doesn't parse comments there. + * + * See #848. + * + * <div rustbindgen replaces="nsTArray"></div> + */ +template<typename T> +class nsTArray_Simple { + T* m; +}; |