Skip to content

Commit

Permalink
Auto merge of rust-lang#817 - fitzgen:include-comments-in-preprocesse…
Browse files Browse the repository at this point in the history
…d-file, r=emilio

Preserve comments when dumping preprocessed input headers

It should be really easy to generate standalone, isolated test cases for bindgen bugs now \o/

See each commit for further details.

r? @emilio
  • Loading branch information
bors-servo authored Jul 18, 2017
2 parents 63de24e + 02da653 commit 10ea03c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
10 changes: 7 additions & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
// files, and therefore any `#include` harms reproducibility. Additionally,
// the test case isn't minimal since the included file almost assuredly
// contains things that aren't necessary to reproduce the bug, and makes
// tracking it down much more difficult. If necessary, see
// tracking it down much more difficult.
//
// Use the `--dump-preprocessed-input` flag or the
// `bindgen::Builder::dump_preprocessed_input` method to make your test case
// standalone and without `#include`s, and then use C-Reduce to minimize it:
// https://github.com/servo/rust-bindgen/blob/master/CONTRIBUTING.md#using-creduce-to-minimize-test-cases
```

Expand Down Expand Up @@ -59,8 +63,8 @@ bindings is missing a field that exists in the C/C++ struct, note that here.
<details>

```
Insert debug logging when running bindgen with the `RUST_LOG=bindgen` environment
variable set.
Insert debug logging when running bindgen (not when compiling bindgen's output)
with the `RUST_LOG=bindgen` environment variable set.
```

</details>
5 changes: 0 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,6 @@ Afterwards, there should be a `__bindgen.i` or `__bindgen.ii` file containing
the combined and preprocessed input headers, which is usable as an isolated,
standalone test case.

Note that the preprocessor likely removed all comments, so if the bug you're
trying to pin down involves source annotations (for example, `/** <div
rustbindgen opaque> */`), then you will have to manually reapply them to the
preprocessed file.

### Writing a Predicate Script

Writing a `predicate.sh` script for a `bindgen` test case is fairly
Expand Down
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ use std::fs::{File, OpenOptions};
use std::iter;
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::process::{Command, Stdio};
use std::sync::Arc;

use syntax::ast;
Expand Down Expand Up @@ -870,14 +870,27 @@ impl Builder {

let mut cmd = Command::new(&clang.path);
cmd.arg("-save-temps")
.arg("-E")
.arg("-C")
.arg("-c")
.arg(&wrapper_path);
.arg(&wrapper_path)
.stdout(Stdio::piped());

for a in &self.options.clang_args {
cmd.arg(a);
}

if cmd.spawn()?.wait()?.success() {
let mut child = cmd.spawn()?;

let mut preprocessed = child.stdout.take().unwrap();
let mut file = File::create(if is_cpp {
"__bindgen.ii"
} else {
"__bindgen.i"
})?;
io::copy(&mut preprocessed, &mut file)?;

if child.wait()?.success() {
Ok(())
} else {
Err(io::Error::new(io::ErrorKind::Other,
Expand Down
2 changes: 2 additions & 0 deletions tests/headers/arg_keyword.hpp
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// This comment exists to ensure that `--dump-preprocessed-input` doesn't strip
// comments.
void foo(const char* type);

0 comments on commit 10ea03c

Please sign in to comment.