From cc144a302f36d39b88b6d1bd5f1de13987e46cb0 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Thu, 2 Sep 2021 16:00:58 -0700 Subject: [PATCH] change proc-macro debugging code to be feature gated --- .gitignore | 1 + .../Cargo.toml | 3 +++ .../src/lib.rs | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) 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(), -- 2.30.2