diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index c5bc049..8fa4efd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use std::env; use std::fs::metadata; use std::io::stdin; use std::path::PathBuf; +use std::rc::Rc; use eyre::{bail, Result}; @@ -63,18 +64,42 @@ fn main() -> Result<()> { // TODO dump command-line macros into environment // TODO add SHELL macro let mut makefile = Makefile::new(&args); + let paths = Default::default(); for filename in &args.makefile { if filename == &PathBuf::from("-") { let macros = makefile.macros.with_overlay(); - let file = MakefileReader::read(&args, macros, stdin().lock(), "-")?.finish(); + let file = MakefileReader::read(&args, macros, stdin().lock(), "-", Rc::clone(&paths))? + .finish(); makefile.extend(file)?; } else { let macros = makefile.macros.with_overlay(); - let file = MakefileReader::read_file(&args, macros, filename)?.finish(); + let file = + MakefileReader::read_file(&args, macros, filename, Rc::clone(&paths))?.finish(); makefile.extend(file)?; }; } + let makefiles_outdated = paths + .borrow() + .iter() + .filter(|path| { + makefile + .get_target(path) + .map_or(false, |target| !target.borrow().is_up_to_date(&makefile)) + }) + .cloned() + .collect::<Vec<_>>(); + for outdated in makefiles_outdated { + eprintln!("makefile {} out of date, rebuilding", outdated); + makefile.update_target(&outdated)?; + let macros = makefile.macros.with_overlay(); + let file = + MakefileReader::read_file(&args, macros, &outdated, Default::default())?.finish(); + // TODO forget the stale data + // TODO reread all the things, not just this one + makefile.extend(file)?; + } + if args.print_everything { println!("{}", &makefile); } else { |