fix libafl_qemu_sys unnecessarily rebuilding. (#1938)
This commit is contained in:
parent
04d87ccc89
commit
b3ddab3bce
@ -1,4 +1,4 @@
|
|||||||
use std::{fs, path::Path};
|
use std::{collections::hash_map, fs, hash::Hasher, io::Read, path::Path};
|
||||||
|
|
||||||
use bindgen::{BindgenError, Bindings};
|
use bindgen::{BindgenError, Bindings};
|
||||||
|
|
||||||
@ -88,7 +88,31 @@ pub fn generate(
|
|||||||
clang_args: Vec<String>,
|
clang_args: Vec<String>,
|
||||||
) -> Result<Bindings, BindgenError> {
|
) -> Result<Bindings, BindgenError> {
|
||||||
let wrapper_h = build_dir.join("wrapper.h");
|
let wrapper_h = build_dir.join("wrapper.h");
|
||||||
fs::write(&wrapper_h, WRAPPER_HEADER).expect("Unable to write wrapper.h");
|
let existing_wrapper_h = fs::File::open(&wrapper_h);
|
||||||
|
let mut must_rewrite_wrapper = true;
|
||||||
|
|
||||||
|
// Check if equivalent wrapper file already exists without relying on filesystem timestamp.
|
||||||
|
if let Ok(mut wrapper_file) = existing_wrapper_h {
|
||||||
|
let mut existing_wrapper_content = Vec::with_capacity(WRAPPER_HEADER.len());
|
||||||
|
wrapper_file
|
||||||
|
.read_to_end(existing_wrapper_content.as_mut())
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let mut existing_wrapper_hasher = hash_map::DefaultHasher::new();
|
||||||
|
existing_wrapper_hasher.write(existing_wrapper_content.as_ref());
|
||||||
|
|
||||||
|
let mut wrapper_h_hasher = hash_map::DefaultHasher::new();
|
||||||
|
wrapper_h_hasher.write(WRAPPER_HEADER.as_bytes());
|
||||||
|
|
||||||
|
// Check if wrappers are the same
|
||||||
|
if existing_wrapper_hasher.finish() == wrapper_h_hasher.finish() {
|
||||||
|
must_rewrite_wrapper = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if must_rewrite_wrapper {
|
||||||
|
fs::write(&wrapper_h, WRAPPER_HEADER).expect("Unable to write wrapper.h");
|
||||||
|
}
|
||||||
|
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
.derive_debug(true)
|
.derive_debug(true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user