write generated code to disk for easier inspection

now that the generated code is actually readable let's make it easier to access

this commit also documents how to inspect the generated code via
`rtfm-expansion.rs` and `cargo-expand`
This commit is contained in:
Jorge Aparicio 2019-05-08 14:08:09 +02:00
parent bc024f1979
commit d4eb4d2c47
2 changed files with 74 additions and 1 deletions

View file

@ -4,6 +4,8 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use std::{fs, path::Path};
use syn::parse_macro_input;
mod analyze;
@ -304,5 +306,12 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
let analysis = analyze::app(&app);
// Code generation
codegen::app(&input.ident, &app, &analysis).into()
let ts = codegen::app(&input.ident, &app, &analysis);
// Try to write the expanded code to disk
if Path::new("target").exists() {
fs::write("target/rtfm-expansion.rs", ts.to_string()).ok();
}
ts.into()
}