don't genrate code in src/

[Outputs of Build Script](https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script) states that only files in $OUT_DIR may be modified
This commit is contained in:
Skgland
2022-01-10 19:59:21 +01:00
parent bcacb49c05
commit a5de329712
5 changed files with 43 additions and 21 deletions

View File

@@ -3037,11 +3037,13 @@ pub fn generate_instructions_rs() -> TokenStream {
}
#[macro_export]
macro_rules! instr {
macro_rules! _instr {
#(
#instr_macro_arms
);*
}
pub use _instr as instr; // https://github.com/rust-lang/rust/pull/52234#issuecomment-976702997
}
}

View File

@@ -84,7 +84,7 @@ impl<'ast> Visit<'ast> for StaticStrVisitor {
}
}
pub fn index_static_strings() -> TokenStream {
pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStream {
use quote::*;
use std::ffi::OsStr;
@@ -103,20 +103,14 @@ pub fn index_static_strings() -> TokenStream {
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;
}
let mut file = match File::open(entry.path()) {
Ok(file) => file,
Err(_) => continue,
};
fn process_filepath(path: &std::path::Path) -> std::result::Result<syn::File, ()> {
let mut src = String::new();
let mut file = match File::open(path) {
Ok(file) => file,
Err(_) => return Err(()),
};
match file.read_to_string(&mut src) {
Ok(_) => {}
Err(e) => {
@@ -127,14 +121,36 @@ pub fn index_static_strings() -> TokenStream {
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();