diff options
author | 2019-05-09 19:53:56 +0000 | |
---|---|---|
committer | 2019-05-09 19:53:56 +0000 | |
commit | 6acb156482f8dfeba6348f05ac231727906c138d (patch) | |
tree | eecaff60a715a5c0eefe5c7a1555d5457fb90f5a /macros/src | |
parent | 3b68816a75366a0fc2918c68e2a05c68283801f2 (diff) | |
parent | d4eb4d2c47c905b3634410a7fdfea84fe1e8cee0 (diff) | |
download | rtic-6acb156482f8dfeba6348f05ac231727906c138d.tar.gz rtic-6acb156482f8dfeba6348f05ac231727906c138d.tar.zst rtic-6acb156482f8dfeba6348f05ac231727906c138d.zip |
Merge #189
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>
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/lib.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 441d6b5e..736289cb 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -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() } |