From 457bcbfd1116f0b3330f9b409395beabffe6ca18 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 14 Apr 2021 11:51:38 -0600 Subject: keep track of sources for inference rules too --- src/makefile/mod.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'src/makefile/mod.rs') diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs index eb06939..228a170 100644 --- a/src/makefile/mod.rs +++ b/src/makefile/mod.rs @@ -7,6 +7,14 @@ use std::rc::Rc; use eyre::{bail, eyre, Result, WrapErr}; +use command_line::CommandLine; +use inference_rules::InferenceRule; +use input::FinishedMakefileReader; +pub use input::MakefileReader; +use r#macro::{Macro, Set as MacroSet}; +use target::Target; +use token::TokenString; + use crate::args::Args; mod command_line; @@ -21,13 +29,14 @@ mod pattern; mod target; mod token; -use command_line::CommandLine; -use inference_rules::InferenceRule; -use input::FinishedMakefileReader; -pub use input::MakefileReader; -use r#macro::{Macro, Set as MacroSet, Source as MacroSource}; -use target::Target; -use token::TokenString; +#[derive(Debug, Clone, Eq, PartialEq)] +pub enum ItemSource { + File { name: String, line: usize }, + CommandLineOrMakeflags, + Environment, + Builtin, + FunctionCall, +} pub struct Makefile<'a> { inference_rules: Vec, @@ -63,7 +72,7 @@ impl<'a> Makefile<'a> { macros.set( name.into(), Macro { - source: MacroSource::CommandLineOrMakeflags, + source: ItemSource::CommandLineOrMakeflags, text: TokenString::text(value), #[cfg(feature = "full")] eagerly_expanded: false, @@ -78,7 +87,7 @@ impl<'a> Makefile<'a> { macros.set( "MAKECMDGOALS".to_owned(), Macro { - source: MacroSource::Builtin, + source: ItemSource::Builtin, text: TokenString::text(make_cmd_goals.join(" ")), #[cfg(feature = "full")] eagerly_expanded: false, @@ -89,7 +98,7 @@ impl<'a> Makefile<'a> { macros.set( "CURDIR".to_owned(), Macro { - source: MacroSource::Builtin, + source: ItemSource::Builtin, text: TokenString::text(curdir.to_string_lossy()), #[cfg(feature = "full")] eagerly_expanded: false, @@ -229,6 +238,7 @@ impl<'a> Makefile<'a> { }) .collect::>>(); if let Some(prereqs) = prereq_paths { + log::trace!("oh {} is a {:#?}", name, rule); new_target = Some(Target { name: name.into(), prerequisites: prereqs, @@ -264,6 +274,7 @@ impl<'a> Makefile<'a> { false }; if !self.targets.borrow().contains_key(name) || exists_but_infer_anyway { + log::trace!("trying to infer for {}", name); self.infer_target(name, vec![], vec![])?; } @@ -429,6 +440,7 @@ fn builtin_inference_rules() -> Vec { $($cmd:literal)+)+} => { vec![$( InferenceRule::new_suffix( + ItemSource::Builtin, prepend_dot!($($second)?).into(), concat!(".", stringify!($first)).into(), vec![$(CommandLine::from($cmd.parse().unwrap())),+], @@ -501,6 +513,7 @@ mod test { fn stem() -> R { let args = Args::empty(); let rule = InferenceRule { + source: ItemSource::Builtin, products: vec!["this-is-a-%-case".to_owned()], prerequisites: vec![], commands: vec![], -- cgit v1.2.3