From dc9f24cd5b5cd9ae3e0aa86e661fc0cf30ac63ef Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Thu, 15 Apr 2021 00:19:09 -0600 Subject: ignore missing targets if they're phony shout out to the gnu make docs for never mentioning that this works this way --- src/makefile/mod.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index 981636b..764328f 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -326,7 +326,17 @@ impl<'a> Makefile<'a> { } pub fn update_target(&self, name: &str) -> Result<()> { - self.get_target(name)?.borrow().update(self) + let target = self.get_target(name); + match target { + // TODO make this less janky + Err(err) + if err.to_string().contains(" not found!") + && self.special_target_has_prereq(".PHONY", name) => + { + Ok(()) + } + _ => target?.borrow().update(self), + } } fn expand_macros(&self, text: &TokenString, target: Option<&Target>) -> Result { @@ -535,4 +545,40 @@ mod test { assert_eq!(target.borrow().stem, Some("test".to_owned())); Ok(()) } + + #[cfg(feature = "full")] + #[test] + fn missing_phony_targets_ignored() -> R { + let args = Args::empty(); + let target = Target { + name: "all".to_owned(), + prerequisites: vec!["missing".to_owned()], + commands: vec![], + stem: None, + already_updated: Cell::new(false), + }; + let phony = Target { + name: ".PHONY".to_string(), + prerequisites: vec!["missing".to_owned()], + commands: vec![], + stem: None, + already_updated: Cell::new(false), + }; + + let targets = DynamicTargetSet::default(); + targets.put(target); + targets.put(phony); + let file = Makefile { + inference_rules: vec![], + builtin_inference_rules: vec![], + macros: MacroSet::new(), + targets, + first_non_special_target: None, + args: &args, + already_inferred: Default::default(), + }; + + assert!(file.update_target("all").is_ok()); + Ok(()) + } } -- cgit v1.2.3