From b162ce1d581d2f3352a2d878e037bd9949e9dace Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 14 Apr 2021 23:50:30 -0600 Subject: rebuild out-of-date makefiles, kinda --- src/main.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/main.rs') 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::>(); + 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 { -- cgit v1.2.3