diff options
Diffstat (limited to 'src/makefile/mod.rs')
-rw-r--r-- | src/makefile/mod.rs | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index 9b2f626..4a0c5e3 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -8,7 +8,9 @@ use std::rc::Rc; use eyre::{bail, eyre, Result, WrapErr}; use command_line::CommandLine; -use inference_rules::InferenceRule; +#[cfg(feature = "full")] +use functions::NO_EVAL; +use inference_rules::{InferenceRule, InferenceRuleSet}; use input::FinishedMakefileReader; pub use input::MakefileReader; use lookup_internal::LookupInternal; @@ -19,8 +21,6 @@ use target::{DynamicTargetSet, Target}; use token::TokenString; use crate::args::Args; -#[cfg(feature = "full")] -use crate::makefile::functions::NO_EVAL; mod command_line; #[cfg(feature = "full")] @@ -34,6 +34,7 @@ mod input; mod lookup_internal; mod r#macro; mod macro_scope; +mod parse; mod pattern; mod target; mod token; @@ -52,7 +53,7 @@ pub enum ItemSource { } pub struct Makefile<'a> { - inference_rules: Vec<InferenceRule>, + inference_rules: InferenceRuleSet, builtin_inference_rules: Vec<InferenceRule>, pub macros: MacroSet, targets: DynamicTargetSet, @@ -132,7 +133,7 @@ impl<'a> Makefile<'a> { } Makefile { - inference_rules: vec![], + inference_rules: InferenceRuleSet::default(), builtin_inference_rules: inference_rules, macros, targets, @@ -144,11 +145,7 @@ impl<'a> Makefile<'a> { pub fn extend(&mut self, new: FinishedMakefileReader) -> Result<()> { self.inference_rules.extend(new.inference_rules); - self.macros.extend( - new.macros, - #[cfg(feature = "full")] - new.macro_exports, - ); + self.macros.extend(new.macros); for (_, target) in new.targets { self.targets.put(target); } @@ -212,7 +209,12 @@ impl<'a> Makefile<'a> { .inference_rules .iter() .chain(self.builtin_inference_rules.iter()) - .filter(|rule| !banned_rules.contains(rule)) + .filter(|rule| { + !banned_rules.iter().any(|banned_rule| { + banned_rule.products == rule.products + && banned_rule.prerequisites == rule.prerequisites + }) + }) .filter(|rule| rule.matches(name).unwrap_or(false)); for rule in inference_rule_candidates { log::trace!( @@ -271,6 +273,7 @@ impl<'a> Makefile<'a> { .first_match(name)? .and_then(|x| x.get(1).map(|x| x.as_str().to_owned())), already_updated: Cell::new(false), + macros: MacroSet::new(), }); break; } @@ -313,6 +316,7 @@ impl<'a> Makefile<'a> { commands, stem: None, already_updated: Cell::new(false), + macros: MacroSet::new(), }); } else { // if it already exists, it counts as up-to-date @@ -323,6 +327,7 @@ impl<'a> Makefile<'a> { commands: vec![], stem: None, already_updated: Cell::new(true), + macros: MacroSet::new(), }); } } @@ -355,6 +360,7 @@ impl<'a> Makefile<'a> { MacroScopeStack::default() .with_scope(&self.macros) .with_scope(&LookupInternal::new(target, &|name| self.get_target(name))) + .with_scope(&target.map(|target| &target.macros)) .expand( text, #[cfg(feature = "full")] @@ -409,6 +415,7 @@ fn builtin_inference_rules() -> Vec<InferenceRule> { prepend_dot!($($second)?).into(), concat!(".", stringify!($first)).into(), vec![$(CommandLine::from($cmd.parse().unwrap())),+], + MacroSet::new(), ) ),+] }; @@ -464,6 +471,7 @@ fn builtin_targets() -> Vec<Target> { commands: vec![], stem: None, already_updated: Cell::new(false), + macros: MacroSet::new(), }] } @@ -482,9 +490,10 @@ mod test { products: vec!["this-is-a-%-case".to_owned()], prerequisites: vec![], commands: vec![], + macros: MacroSet::new(), }; let file = Makefile { - inference_rules: vec![rule], + inference_rules: vec![rule].into(), builtin_inference_rules: vec![], macros: MacroSet::new(), targets: Default::default(), @@ -508,6 +517,7 @@ mod test { commands: vec![], stem: None, already_updated: Cell::new(false), + macros: MacroSet::new(), }; let phony = Target { name: ".PHONY".to_string(), @@ -515,13 +525,14 @@ mod test { commands: vec![], stem: None, already_updated: Cell::new(false), + macros: MacroSet::new(), }; let targets = DynamicTargetSet::default(); targets.put(target); targets.put(phony); let file = Makefile { - inference_rules: vec![], + inference_rules: InferenceRuleSet::default(), builtin_inference_rules: vec![], macros: MacroSet::new(), targets, |