From 07b4b35c44d488fea2916e7d985f60f923ed0e4c Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Sun, 10 Nov 2024 21:28:27 -0700 Subject: fix that with no default features --- src/makefile/macro.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/makefile/macro.rs') diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs index beae404..b135f42 100644 --- a/src/makefile/macro.rs +++ b/src/makefile/macro.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use std::collections::HashSet; use std::env; use std::fmt; +#[cfg(feature = "full")] use std::io::BufRead; use std::rc::Rc; @@ -10,6 +11,7 @@ use std::rc::Rc; use super::functions; use super::token::{Token, TokenString}; use super::ItemSource; +#[cfg(feature = "full")] use crate::makefile::eval_context::DeferredEvalContext; use eyre::{bail, Result, WrapErr}; #[cfg(not(feature = "full"))] @@ -203,10 +205,10 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { } } - pub fn expand( + pub fn expand<#[cfg(feature = "full")] R: BufRead>( &self, text: &TokenString, - mut eval_context: Option<&mut DeferredEvalContext>, + #[cfg(feature = "full")] mut eval_context: Option<&mut DeferredEvalContext>, ) -> Result { let mut result = String::new(); for token in text.tokens() { @@ -214,7 +216,11 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { Token::Text(t) => result.push_str(t), Token::MacroExpansion { name, replacement } => { let name = self - .expand(name, eval_context.as_deref_mut()) + .expand( + name, + #[cfg(feature = "full")] + eval_context.as_deref_mut(), + ) .wrap_err_with(|| format!("while expanding \"{}\"", name))?; let internal_macro_names = &['@', '?', '<', '*', '^'][..]; let internal_macro_suffices = &['D', 'F'][..]; @@ -232,14 +238,22 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { Ok(String::new()) }, |x| { - self.expand(&x.text, eval_context.as_deref_mut()) - .wrap_err_with(|| format!("while expanding \"{}\"", &x.text)) + self.expand( + &x.text, + #[cfg(feature = "full")] + eval_context.as_deref_mut(), + ) + .wrap_err_with(|| format!("while expanding \"{}\"", &x.text)) }, )? }; let macro_value = match replacement { Some((subst1, subst2)) => { - let subst1 = self.expand(subst1, eval_context.as_deref_mut())?; + let subst1 = self.expand( + subst1, + #[cfg(feature = "full")] + eval_context.as_deref_mut(), + )?; #[cfg(feature = "full")] { let (subst1, subst2) = if subst1.contains('%') { @@ -457,6 +471,7 @@ fn builtins() -> Vec<(&'static str, TokenString)> { #[cfg(test)] mod test { use super::*; + #[cfg(feature = "full")] use crate::makefile::functions::NO_EVAL; type R = Result<()>; @@ -474,7 +489,11 @@ mod test { }, ); assert_eq!( - macros.expand(&"$(oof:;=?)".parse()?, NO_EVAL)?, + macros.expand( + &"$(oof:;=?)".parse()?, + #[cfg(feature = "full")] + NO_EVAL + )?, "bruh? swag? yeet?" ); Ok(()) -- cgit v1.2.3