From d64e044ae288afdae80bc5e479d902d7f98cb6ea Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 14 Apr 2021 19:26:39 -0600 Subject: never try twice to infer a target --- src/makefile/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/makefile') diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index d7cc25e..7cc16c5 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -1,4 +1,5 @@ use std::cell::{Cell, RefCell}; +use std::collections::HashSet; use std::env; use std::fmt; use std::path::{Path, PathBuf}; @@ -44,6 +45,7 @@ pub struct Makefile<'a> { targets: DynamicTargetSet, pub first_non_special_target: Option, args: &'a Args, + already_inferred: RefCell>, // TODO borrow warnings from Python version } @@ -123,6 +125,7 @@ impl<'a> Makefile<'a> { targets, first_non_special_target, args, + already_inferred: Default::default(), } } @@ -170,6 +173,10 @@ impl<'a> Makefile<'a> { if banned_names.contains(&name) { bail!("no infinite recursion allowed"); } + if self.already_inferred.borrow().contains(name) { + return Ok(()); + } + self.already_inferred.borrow_mut().insert(name.to_owned()); log::trace!("inferring {}, stack = {:?}", name, banned_names); let mut new_target = None; @@ -519,6 +526,7 @@ mod test { targets: Default::default(), first_non_special_target: None, args: &args, + already_inferred: Default::default(), }; let target = file.get_target("this-is-a-test-case")?; -- cgit v1.2.3