extern crate capnpc;
use std::env::var;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;
use std::path::PathBuf;
fn fix(path: PathBuf) {
let original_contents = {
let mut file = File::open(&path).expect(&format!(
"Expected to be able to open the autogenerated source at {:?}",
&path
));
let mut contents = String::new();
file.read_to_string(&mut contents).expect(&format!(
"Expected to be able to read the autogenerated source at {:?}",
&path
));
contents
};
let fixed_contents = original_contents.replace("::indradb_capnp::", "::autogen::");
let mut file = File::create(&path).expect(&format!(
"Expected to be able to open the autogenerated source at {:?}",
&path
));
file.write_all(fixed_contents.as_bytes()).expect(&format!(
"Expected to be able to write to the autogenerated source at {:?}",
&path
));
}
fn main() {
capnpc::CompilerCommand::new()
.file("indradb.capnp")
.run()
.expect("Expected to be able to compile capnp schemas");
fix(Path::new(&var("OUT_DIR").expect("Expected `OUT_DIR` environmental variable")).join("indradb_capnp.rs"));
}