Skip to content

Commit

Permalink
chore: add some more debugging to forge bind
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 18, 2024
1 parent 7e323c2 commit eebb601
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions crates/sol-macro-gen/src/sol_macro_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,27 +139,28 @@ edition = "2021"
)?;

// Write src
let parse_error = |name: &str| {
format!("failed to parse generated tokens as an AST for {name};\nthis is likely a bug")
};
for instance in &self.instances {
let name = instance.name.to_lowercase();
let contents = instance.expansion.as_ref().unwrap().to_string();
let contents = instance.expansion.as_ref().unwrap();

if !single_file {
let path = src.join(format!("{name}.rs"));
let file = syn::parse_file(&contents)?;
let contents = prettyplease::unparse(&file);

fs::write(path.clone(), contents).wrap_err("Failed to write file")?;
writeln!(&mut lib_contents, "pub mod {name};")?;
} else {
let name = instance.name.to_lowercase();
let path = src.join(format!("{name}.rs"));
let file = syn::parse2(contents.clone())
.wrap_err_with(|| parse_error(&format!("{}:{}", path.display(), name)))?;
let contents = prettyplease::unparse(&file);
if single_file {
write!(&mut lib_contents, "{contents}")?;
} else {
fs::write(path, contents).wrap_err("failed to write to file")?;
writeln!(&mut lib_contents, "pub mod {name};")?;
}
}

let lib_path = src.join("lib.rs");
let lib_file = syn::parse_file(&lib_contents)?;

let lib_file = syn::parse_file(&lib_contents).wrap_err_with(|| parse_error("lib.rs"))?;
let lib_contents = prettyplease::unparse(&lib_file);

fs::write(lib_path, lib_contents).wrap_err("Failed to write lib.rs")?;

Ok(())
Expand Down

0 comments on commit eebb601

Please sign in to comment.