From: Jacob Lifshay Date: Thu, 2 Sep 2021 23:00:58 +0000 (-0700) Subject: change proc-macro debugging code to be feature gated X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cc144a302f36d39b88b6d1bd5f1de13987e46cb0;p=power-instruction-analyzer.git change proc-macro debugging code to be feature gated --- diff --git a/.gitignore b/.gitignore index c7acde7..54c4c80 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__ *.pyc /output-for-* +/proc-macro-out.rs diff --git a/power-instruction-analyzer-proc-macro/Cargo.toml b/power-instruction-analyzer-proc-macro/Cargo.toml index 6b1b193..c2cc3a0 100644 --- a/power-instruction-analyzer-proc-macro/Cargo.toml +++ b/power-instruction-analyzer-proc-macro/Cargo.toml @@ -15,3 +15,6 @@ proc-macro = true quote = "1.0" proc-macro2 = "1.0" syn = { version = "1.0", features = ["full", "parsing", "extra-traits"] } + +[features] +debug-proc-macro = [] diff --git a/power-instruction-analyzer-proc-macro/src/lib.rs b/power-instruction-analyzer-proc-macro/src/lib.rs index 923363b..cd6d342 100644 --- a/power-instruction-analyzer-proc-macro/src/lib.rs +++ b/power-instruction-analyzer-proc-macro/src/lib.rs @@ -16,13 +16,18 @@ pub fn instructions(input: TokenStream) -> TokenStream { let input = parse_macro_input!(input as Instructions); match input.to_tokens() { Ok(retval) => { - fs::write( - Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("out.rs"), - retval.to_string(), - ) - .unwrap(); - quote! { - include!(concat!(env!("CARGO_MANIFEST_DIR"), "/out.rs")); + if cfg!(feature = "debug-proc-macro") { + fs::write( + Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap()) + .join("proc-macro-out.rs"), + retval.to_string(), + ) + .unwrap(); + quote! { + include!(concat!(env!("CARGO_MANIFEST_DIR"), "/proc-macro-out.rs")); + } + } else { + retval } } Err(err) => err.to_compile_error(),