summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-07-27 19:23:18 -0500
committerGitHub <noreply@github.com>2017-07-27 19:23:18 -0500
commit0e39721b6c72b574026a0802792c4e95f0d83e68 (patch)
treed0a788cf8d0236621cd6eaaef25ba1c41397e370
parent0fab51e501f45727169516f605de31e7e1d19a62 (diff)
parent05b1550f0450cea997dc5dff4083aa4b09d01aae (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.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs29
-rw-r--r--tests/expectations/tests/issue-848-replacement-system-include.rs24
-rw-r--r--tests/headers/issue-848-replacement-system-include.hpp7
-rw-r--r--tests/headers/issue-848/an-include.h17
6 files changed, 78 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 690c0a16..3f0f65df 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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)",
diff --git a/Cargo.toml b/Cargo.toml
index 91ef7279..d384b8bf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 = [
diff --git a/src/lib.rs b/src/lib.rs
index 4eeb95f4..f2aa10a6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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;
+};