Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0759fc3d authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Move macro debugging to OUT_DIR

Follow up of CL:2008615.

Bug: 200732080
Tag: #floss
Test: Build Floss with build.py

Change-Id: I750bf034828a72e2fbfbc6efd900713e74b68452
parent 3a4272f5
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -13,8 +13,20 @@ use syn::{Expr, FnArg, ItemTrait, Meta, Pat, TraitItem};

use crate::proc_macro::TokenStream;

const OUTPUT_DEBUG: bool = false;

fn debug_output_to_file(gen: &proc_macro2::TokenStream, filename: String) {
    let path = Path::new(filename.as_str());
    if !OUTPUT_DEBUG {
        return;
    }

    let filepath = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap())
        .join(filename)
        .to_str()
        .unwrap()
        .to_string();

    let path = Path::new(&filepath);
    let mut file = File::create(&path).unwrap();
    file.write_all(gen.to_string().as_bytes()).unwrap();
}
@@ -120,7 +132,7 @@ pub fn btif_callbacks_dispatcher(attr: TokenStream, item: TokenStream) -> TokenS
    };

    // TODO: Have a simple framework to turn on/off macro-generated code debug.
    debug_output_to_file(&gen, format!("/tmp/out-{}.rs", fn_ident.to_string()));
    debug_output_to_file(&gen, format!("out-{}.rs", fn_ident.to_string()));

    gen.into()
}