From c132818b561fcd538e7e4f830c4b3cff1d9fcd16 Mon Sep 17 00:00:00 2001 From: Matt Johnston <matt@ucc.asn.au> Date: Thu, 22 Sep 2022 21:54:19 +0800 Subject: [PATCH] Add SSHWIRE_DEBUG env var for debug output --- sshwire_derive/src/lib.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sshwire_derive/src/lib.rs b/sshwire_derive/src/lib.rs index 5a7d95c..7f8e282 100644 --- a/sshwire_derive/src/lib.rs +++ b/sshwire_derive/src/lib.rs @@ -1,6 +1,10 @@ //! Used in conjunction with `sshwire.rs` and `packets.rs` +//! +//! `SSHWIRE_DEBUG` environment variable can be set at build time +//! to write generated files to the `target/` directory. use std::collections::HashSet; +use std::env; use proc_macro::Delimiter; use virtue::generate::FnSelfArg; @@ -8,6 +12,8 @@ use virtue::parse::{Attribute, AttributeLocation, EnumBody, StructBody}; use virtue::utils::{parse_tagged_attribute, ParsedAttribute}; use virtue::prelude::*; +const ENV_SSHWIRE_DEBUG: &'static str = &"SSHWIRE_DEBUG"; + #[proc_macro_derive(SSHEncode, attributes(sshwire))] pub fn derive_encode(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let r = encode_inner(input).unwrap_or_else(|e| e.into_token_stream()); @@ -31,7 +37,9 @@ fn encode_inner(input: TokenStream) -> Result<TokenStream> { encode_enum(&mut gen, &att, body)?; } } - gen.export_to_file("SSHEncode"); + if env::var(ENV_SSHWIRE_DEBUG).is_ok() { + gen.export_to_file("SSHEncode"); + } gen.finish() } @@ -47,7 +55,9 @@ fn decode_inner(input: TokenStream) -> Result<TokenStream> { decode_enum(&mut gen, &att, body)?; } } - gen.export_to_file("SSHDecode"); + if env::var(ENV_SSHWIRE_DEBUG).is_ok() { + gen.export_to_file("SSHDecode"); + } gen.finish() } -- GitLab