From c94a7f83e3d9f3fb7cd023efee33a4434af5c349 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 6 Apr 2021 19:04:26 -0600 Subject: cut down on warning spam --- src/makefile/macro.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/makefile/macro.rs b/src/makefile/macro.rs index c8a9542..6a456af 100644 --- a/src/makefile/macro.rs +++ b/src/makefile/macro.rs @@ -1,11 +1,8 @@ -#[cfg(feature = "full")] use std::cell::RefCell; use std::collections::HashMap; -#[cfg(feature = "full")] use std::collections::HashSet; use std::env; use std::fmt; -#[cfg(feature = "full")] use std::rc::Rc; use eyre::{bail, Result, WrapErr}; @@ -102,6 +99,7 @@ pub struct Set<'parent, 'lookup> { pub to_eval: Rc>>, #[cfg(feature = "full")] pub exported: ExportConfig, + warnings: Rc>>, } impl<'parent, 'lookup> Set<'parent, 'lookup> { @@ -114,6 +112,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { to_eval: Rc::new(RefCell::new(Vec::new())), #[cfg(feature = "full")] exported: ExportConfig::only(), + warnings: Default::default(), } } @@ -206,6 +205,13 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { self.data.extend(other); } + fn warn(&self, text: String) { + if !self.warnings.borrow().contains(&text) { + log::warn!("{}", &text); + self.warnings.borrow_mut().insert(text); + } + } + pub fn expand(&self, text: &TokenString) -> Result { let mut result = String::new(); for token in text.tokens() { @@ -224,7 +230,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { } else { self.get(&name).map_or_else( || { - log::warn!("undefined macro {}", name); + self.warn(format!("undefined macro {}", name)); Ok(String::new()) }, |x| self.expand(&x.text), @@ -294,6 +300,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { to_eval: Rc::clone(&self.to_eval), #[cfg(feature = "full")] exported: self.exported.same_type(), + warnings: Rc::clone(&self.warnings), } } @@ -306,6 +313,7 @@ impl<'parent, 'lookup> Set<'parent, 'lookup> { to_eval: Rc::clone(&self.to_eval), #[cfg(feature = "full")] exported: self.exported.same_type(), + warnings: Rc::clone(&self.warnings), } } -- cgit v1.2.3