aboutsummaryrefslogtreecommitdiff
path: root/src/makefile
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-06 14:22:19 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-06 14:22:19 -0600
commit455b77bdbc78729c4175e27a949327c9836b8794 (patch)
tree4f19ff3d9195cad8989e6b12a75394ca86065b38 /src/makefile
parent5a101a96ada9ddbd4be54c46cd7d0125825c2283 (diff)
downloadmakers-455b77bdbc78729c4175e27a949327c9836b8794.tar.gz
makers-455b77bdbc78729c4175e27a949327c9836b8794.zip
if an included makefile didn't exist, try building it
Diffstat (limited to 'src/makefile')
-rw-r--r--src/makefile/input.rs17
-rw-r--r--src/makefile/mod.rs14
2 files changed, 26 insertions, 5 deletions
diff --git a/src/makefile/input.rs b/src/makefile/input.rs
index 5883590..700bf4b 100644
--- a/src/makefile/input.rs
+++ b/src/makefile/input.rs
@@ -147,6 +147,7 @@ pub struct MakefileReader<'a, 'parent, R: BufRead> {
pub macros: MacroSet<'parent, 'static>,
pub targets: HashMap<String, Target>,
pub first_non_special_target: Option<String>,
+ pub failed_includes: Vec<String>,
args: &'a Args,
lines_iter: Peekable<LineNumbers<String, IoError, Lines<R>>>,
// join with escaped_newline_replacement to get the actual line
@@ -194,6 +195,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
macros,
targets: HashMap::new(),
first_non_special_target: None,
+ failed_includes: Vec::new(),
args,
lines_iter: source.lines().line_numbered().peekable(),
pending_line: None,
@@ -235,9 +237,15 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
for field in fields {
let child_macros = self.macros.with_overlay();
let child = MakefileReader::read_file(self.args, child_macros, field)
- .with_context(|| format!("while including {}", field))?
- .finish();
- self.extend(child);
+ .with_context(|| format!("while including {}", field));
+ if let Ok(child) = child {
+ let child = child.finish();
+ self.extend(child);
+ } else {
+ // TODO handle non-file-not-found errors
+ log::error!("included makefile {} not found", field);
+ self.failed_includes.push(field.to_owned());
+ }
}
continue;
}
@@ -655,6 +663,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
macros: self.macros.data,
targets: self.targets,
first_non_special_target: self.first_non_special_target,
+ failed_includes: self.failed_includes,
}
}
@@ -665,6 +674,7 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
if self.first_non_special_target.is_none() {
self.first_non_special_target = new.first_non_special_target;
}
+ self.failed_includes.extend(new.failed_includes);
}
}
@@ -673,6 +683,7 @@ pub struct FinishedMakefileReader {
pub macros: HashMap<String, Macro>,
pub targets: HashMap<String, Target>,
pub first_non_special_target: Option<String>,
+ pub failed_includes: Vec<String>,
}
#[cfg(test)]
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs
index aab5054..f17ba64 100644
--- a/src/makefile/mod.rs
+++ b/src/makefile/mod.rs
@@ -5,7 +5,7 @@ use std::fmt;
use std::path::{Path, PathBuf};
use std::rc::Rc;
-use eyre::{bail, eyre, Result};
+use eyre::{bail, eyre, Result, WrapErr};
use crate::args::Args;
@@ -108,7 +108,7 @@ impl<'a> Makefile<'a> {
}
}
- pub fn extend(&mut self, new: FinishedMakefileReader) {
+ pub fn extend(&mut self, new: FinishedMakefileReader) -> Result<()> {
self.inference_rules.extend(new.inference_rules);
self.macros.extend(new.macros);
self.targets.borrow_mut().extend(
@@ -119,6 +119,16 @@ impl<'a> Makefile<'a> {
if self.first_non_special_target.is_none() {
self.first_non_special_target = new.first_non_special_target;
}
+ for failed_include in new.failed_includes {
+ // try rebuilding
+ self.update_target(&failed_include).wrap_err_with(|| {
+ format!("while building missing included file {}", &failed_include)
+ })?;
+ let macros = self.macros.with_overlay();
+ let file = MakefileReader::read_file(self.args, macros, failed_include)?.finish();
+ self.extend(file)?;
+ }
+ Ok(())
}
fn special_target_has_prereq(&self, target: &str, name: &str) -> bool {