189: write generated code to disk for easier inspection r=japaric a=japaric

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`

Co-authored-by: Jorge Aparicio <jorge@japaric.io>
This commit is contained in:
bors[bot] 2019-05-09 19:53:56 +00:00
commit 6acb156482
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()
}