From b2645ea919d159f7883c0d7001eaee528dddc371 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Tue, 13 Apr 2021 21:08:51 -0600 Subject: don't clobber .SUFFIXES when an include finishes --- src/makefile/input.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/makefile/input.rs b/src/makefile/input.rs index 6860e80..e2bff65 100644 --- a/src/makefile/input.rs +++ b/src/makefile/input.rs @@ -166,6 +166,7 @@ pub struct MakefileReader<'a, 'parent, R: BufRead> { pub inference_rules: Vec, pub macros: MacroSet<'parent, 'static>, pub targets: HashMap, + built_in_targets: HashMap, pub first_non_special_target: Option, pub failed_includes: Vec, args: &'a Args, @@ -221,6 +222,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { inference_rules: Vec::new(), macros, targets: HashMap::new(), + built_in_targets: HashMap::new(), first_non_special_target: None, failed_includes: Vec::new(), args, @@ -229,9 +231,9 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { #[cfg(feature = "full")] conditional_stack: Vec::new(), }; - // TODO be smart about this instead + // TODO be smart about this instead, please if !args.no_builtin_rules { - reader.targets.insert( + reader.built_in_targets.insert( ".SUFFIXES".to_owned(), Target { name: ".SUFFIXES".into(), @@ -528,7 +530,11 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { } fn special_target_has_prereq(&self, target: &str, name: &str, empty_counts: bool) -> bool { - match self.targets.get(target) { + match self + .targets + .get(target) + .or_else(|| self.built_in_targets.get(target)) + { Some(target) => { (empty_counts && target.prerequisites.is_empty()) || target.prerequisites.iter().any(|e| e == name) @@ -683,9 +689,14 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { Some(inference) } else { log::info!( - "looks like {:?} is not a suffix rule because .SUFFIXES is {:?}", + "{}:{}: looks like {:?} is not a suffix rule because .SUFFIXES is {:?}", + &self.file_name, + line_number, inference, - self.targets.get(".SUFFIXES").map(|x| &x.prerequisites) + self.targets + .get(".SUFFIXES") + .or_else(|| self.built_in_targets.get(".SUFFIXES")) + .map(|x| &x.prerequisites) ); None } @@ -713,6 +724,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> { if self.first_non_special_target.is_none() && !target.starts_with('.') { self.first_non_special_target = Some(target.into()); } + // TODO handle appending to built-in (it's Complicated) match self.targets.get_mut(target) { Some(old_target) if commands.is_empty() -- cgit v1.2.3