aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-14 23:50:30 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-14 23:50:30 -0600
commitb162ce1d581d2f3352a2d878e037bd9949e9dace (patch)
treead2ee39942f5635729ac63e0b595eca2aed9518a /src/main.rs
parent5a72fb28fb69a476437141a4eb898d6d001dd281 (diff)
downloadmakers-b162ce1d581d2f3352a2d878e037bd9949e9dace.tar.gz
makers-b162ce1d581d2f3352a2d878e037bd9949e9dace.zip
rebuild out-of-date makefiles, kinda
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs29
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 {