find_prolog_files(&mut libraries, "", &lib_path);
libraries.write_all(b"\n m\n };\n}\n").unwrap();
- let instructions_path = Path::new("src/instructions.rs");
+ let instructions_path = Path::new(&out_dir).join("instructions.rs");
let mut instructions_file = File::create(&instructions_path).unwrap();
let quoted_output = generate_instructions_rs();
.spawn().unwrap()
.wait().unwrap();
- let static_atoms_path = Path::new("src/static_atoms.rs");
+ let static_atoms_path = Path::new(&out_dir).join("static_atoms.rs");
let mut static_atoms_file = File::create(&static_atoms_path).unwrap();
- let quoted_output = index_static_strings();
+ let quoted_output = index_static_strings(&instructions_path);
static_atoms_file
.write_all(quoted_output.to_string().as_bytes())
}
}
-pub fn index_static_strings() -> TokenStream {
+pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStream {
use quote::*;
use std::ffi::OsStr;
let mut visitor = StaticStrVisitor::new();
- for entry in WalkDir::new("src/").into_iter().filter_entry(filter_rust_files) {
- let entry = entry.unwrap();
-
- if entry.path().is_dir() {
- continue;
- }
+ fn process_filepath(path: &std::path::Path) -> std::result::Result<syn::File, ()> {
+ let mut src = String::new();
- let mut file = match File::open(entry.path()) {
+ let mut file = match File::open(path) {
Ok(file) => file,
- Err(_) => continue,
+ Err(_) => return Err(()),
};
- let mut src = String::new();
-
match file.read_to_string(&mut src) {
Ok(_) => {}
Err(e) => {
let syntax = match syn::parse_file(&src) {
Ok(s) => s,
Err(e) => {
- panic!("parse error: {} in file {:?}", e, entry.path());
+ panic!("parse error: {} in file {:?}", e, path);
}
};
+ Ok(syntax)
+ }
+
+ for entry in WalkDir::new("src/")
+ .into_iter()
+ .filter_entry(filter_rust_files)
+ {
+ let entry = entry.unwrap();
+
+ if entry.path().is_dir() {
+ continue;
+ }
+
+ let syntax = match process_filepath(entry.path()) {
+ Ok(syntax) => syntax,
+ Err(_) => continue,
+ };
visitor.visit_file(&syntax);
}
- let indices = (0 .. visitor.static_strs.len()).map(|i| i << 3);
+ match process_filepath(instruction_rs_path) {
+ Ok(syntax) => visitor.visit_file(&syntax),
+ Err(_) => {}
+ }
+
+ let indices = (0..visitor.static_strs.len()).map(|i| i << 3);
let indices_iter = indices.clone();
let static_strs_len = visitor.static_strs.len();