diff options
Diffstat (limited to 'src/makefile')
-rw-r--r-- | src/makefile/mod.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index e004586..c81526b 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -5,7 +5,7 @@ use std::fmt; use std::path::{Path, PathBuf}; use std::rc::Rc; -use eyre::{eyre, Result}; +use eyre::{bail, eyre, Result}; use crate::args::Args; @@ -36,6 +36,7 @@ pub struct Makefile<'a> { pub first_non_special_target: Option<String>, args: &'a Args, // TODO borrow warnings from Python version + fucking_bullshit_recursion_stack: RefCell<Vec<String>>, } impl<'a> Makefile<'a> { @@ -73,6 +74,7 @@ impl<'a> Makefile<'a> { targets: RefCell::new(targets), first_non_special_target, args, + fucking_bullshit_recursion_stack: RefCell::new(Vec::new()), } } @@ -101,6 +103,16 @@ impl<'a> Makefile<'a> { } pub fn get_target(&self, name: &str) -> Result<Rc<RefCell<Target>>> { + if self + .fucking_bullshit_recursion_stack + .borrow() + .contains(&name.to_owned()) + { + bail!("no infinite recursion allowed"); + } + self.fucking_bullshit_recursion_stack + .borrow_mut() + .push(name.to_owned()); // TODO implement .POSIX let follow_gnu = cfg!(feature = "full"); @@ -206,6 +218,8 @@ impl<'a> Makefile<'a> { .insert(new_target.name.clone(), Rc::new(RefCell::new(new_target))); } + self.fucking_bullshit_recursion_stack.borrow_mut().pop(); + let targets = self.targets.borrow(); Ok(Rc::clone( targets |