From 7857e9f871caaf0b95f9eba9c4cdefb5046a9b2a Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 13 Apr 2021 20:53:44 -0600 Subject: spell SUFFIXES correctly smdh --- src/makefile/input.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/makefile/input.rs b/src/makefile/input.rs index cb53966..6860e80 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -527,10 +527,11 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { } } - fn special_target_has_prereq(&self, target: &str, name: &str) -> bool { + fn special_target_has_prereq(&self, target: &str, name: &str, empty_counts: bool) -> bool { match self.targets.get(target) { Some(target) => { - target.prerequisites.is_empty() || target.prerequisites.iter().any(|e| e == name) + (empty_counts && target.prerequisites.is_empty()) + || target.prerequisites.iter().any(|e| e == name) } None => false, } @@ -675,9 +676,9 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { // don't interpret things like `.tmp: ; mkdir -p $@` as single-suffix rules let inference_match = inference_match.and_then(|inference| { - if self.special_target_has_prereq(".SUFFIXES", inference.s1) + if self.special_target_has_prereq(".SUFFIXES", inference.s1, false) && (inference.s2.is_empty() - || self.special_target_has_prereq(".SUFFIXES", inference.s2)) + || self.special_target_has_prereq(".SUFFIXES", inference.s2, false)) { Some(inference) } else { @@ -715,7 +716,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { match self.targets.get_mut(target) { Some(old_target) if commands.is_empty() - && !(target == ".SUFIXES" && prerequisites.is_empty()) => + && !(target == ".SUFFIXES" && prerequisites.is_empty()) => { let new_prerequisites = prerequisites .iter() @@ -1074,14 +1075,33 @@ info: #[test] fn sdafjijsafjdoisdf() -> R { - let file = "\ + let file = " cursed: \techo this uses the bash variable '$$#' and all that \\ \techo yeah its value is $$# and it's really cool +"; + let args = Args::empty(); + let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?; + let _makefile = makefile.finish(); + Ok(()) + } + + #[test] + fn double_suffix_rule() -> R { + let file = " +.c.o: +\techo yeet +.SUFFIXES: +.l.a: +\techo hey +.SUFFIXES: .test .post +.post.test: +\techo hiiii "; let args = Args::empty(); let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?; let makefile = makefile.finish(); + assert_eq!(makefile.inference_rules.len(), 2); Ok(()) } } -- cgit v1.2.3