better error handling
This commit is contained in:
parent
72c46447c1
commit
79189561c6
16
build.rs
16
build.rs
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
io::{ Error, Write },
|
io::{ Error, Write },
|
||||||
process::{ Command, exit, Stdio },
|
process::{ Command, Stdio },
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -51,11 +51,9 @@ fn main() -> Result<(), Error> {
|
|||||||
|
|
||||||
let output = process.wait_with_output()?.stdout;
|
let output = process.wait_with_output()?.stdout;
|
||||||
|
|
||||||
let headers = String::from_utf8(output).unwrap_or_else( |e| {
|
let headers = String::from_utf8(output).map_err(|e| {
|
||||||
Error::other(e.to_string());
|
Error::other(e.to_string())
|
||||||
/* Exit with status 1 because we’re bootstrapping sysexits.h, silly! */
|
})?;
|
||||||
exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
/* Split headers by spaces because cpp(1) returns more than one */
|
/* Split headers by spaces because cpp(1) returns more than one */
|
||||||
for h in headers.split(' ') {
|
for h in headers.split(' ') {
|
||||||
@ -73,11 +71,9 @@ fn main() -> Result<(), Error> {
|
|||||||
.header(header)
|
.header(header)
|
||||||
.parse_callbacks(Box::new(CargoCallbacks::new()))
|
.parse_callbacks(Box::new(CargoCallbacks::new()))
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Unable to generate bindings.");
|
.map_err(|e| Error::other(e.to_string()))?;
|
||||||
|
|
||||||
bindings
|
bindings.write_to_file(PathBuf::from("src/").join("lib.rs"))?;
|
||||||
.write_to_file(PathBuf::from("src/").join("lib.rs"))
|
|
||||||
.expect("Couldn't write bindings!");
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user