aboutsummaryrefslogtreecommitdiff
path: root/src/makefile
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-06 16:48:26 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-06 16:48:26 -0600
commit1884c0484b71a197eb12e7e65354b30802035602 (patch)
tree43647e4a22027019e53a3f375e6c5cdbf4704015 /src/makefile
parente18364423529e5d76c381f99c655a6b48ecca030 (diff)
downloadmakers-1884c0484b71a197eb12e7e65354b30802035602.tar.gz
makers-1884c0484b71a197eb12e7e65354b30802035602.zip
include filename in some error logs
Diffstat (limited to 'src/makefile')
-rw-r--r--src/makefile/input.rs50
1 files changed, 35 insertions, 15 deletions
diff --git a/src/makefile/input.rs b/src/makefile/input.rs
index 283842f..2f8de49 100644
--- a/src/makefile/input.rs
+++ b/src/makefile/input.rs
@@ -145,6 +145,7 @@ impl<T, E: StdError + Send + Sync + 'static, I: Iterator<Item = Result<T, E>>> I
}
pub struct MakefileReader<'a, 'parent, R: BufRead> {
+ file_name: String,
pub inference_rules: Vec<InferenceRule>,
pub macros: MacroSet<'parent, 'static>,
pub targets: HashMap<String, Target>,
@@ -182,17 +183,24 @@ impl<'a, 'parent> MakefileReader<'a, 'parent, BufReader<File>> {
},
);
}
- let file = File::open(path);
+ let file = File::open(path.as_ref());
// TODO handle errors
let file = file.context("couldn't open makefile!")?;
let file_reader = BufReader::new(file);
- Self::read(args, macros, file_reader)
+ Self::read(args, macros, file_reader, path.as_ref().to_string_lossy())
}
}
impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
- pub fn read(args: &'a Args, macros: MacroSet<'parent, 'static>, source: R) -> Result<Self> {
+ pub fn read(
+ args: &'a Args,
+ macros: MacroSet<'parent, 'static>,
+ source: R,
+ name: impl Into<String>,
+ ) -> Result<Self> {
+ let name = name.into();
let mut reader = Self {
+ file_name: name.clone(),
inference_rules: Vec::new(),
macros,
targets: HashMap::new(),
@@ -220,7 +228,9 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
},
);
}
- reader.read_all()?;
+ reader
+ .read_all()
+ .wrap_err_with(|| format!("while reading {}", name))?;
Ok(reader)
}
@@ -250,7 +260,12 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
} else {
if !original_line.starts_with('-') {
// TODO handle non-file-not-found errors
- log::error!("included makefile {} not found", field);
+ log::error!(
+ "{}:{}: included makefile {} not found",
+ &self.file_name,
+ line_number,
+ field
+ );
self.failed_includes.push(field.to_owned());
}
}
@@ -285,10 +300,14 @@ impl<'a, 'parent, R: BufRead> MakefileReader<'a, 'parent, R> {
let eval = self.macros.to_eval.take();
for eval in eval {
let child_macros = self.macros.with_overlay();
- let child =
- MakefileReader::read(self.args, child_macros, Cursor::new(eval))
- .context("while evaling")?
- .finish();
+ let child = MakefileReader::read(
+ self.args,
+ child_macros,
+ Cursor::new(eval),
+ "<eval>",
+ )
+ .context("while evaling")?
+ .finish();
self.extend(child);
}
}
@@ -727,7 +746,8 @@ a: $(x) b \\
\t\td
\tfoo";
let args = Args::empty();
- let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file))?.finish();
+ let makefile =
+ MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?.finish();
assert_eq!(
makefile.targets["a"].prerequisites,
vec!["3", "4", "5", "b", "c", "d"]
@@ -748,7 +768,7 @@ worked = perhaps
endif
";
let args = Args::empty();
- let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file))?;
+ let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
assert_eq!(
makefile.expand_macros(&TokenString::r#macro("worked"))?,
"yes"
@@ -766,7 +786,7 @@ ifeq (1,1)
endif
";
let args = Args::empty();
- let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file))?;
+ let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
assert_eq!(makefile.targets["a"].commands.len(), 1);
Ok(())
}
@@ -781,7 +801,7 @@ baz
endef
";
let args = Args::empty();
- let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file))?;
+ let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
assert_eq!(
makefile.expand_macros(&TokenString::r#macro("foo"))?,
"bar\nbaz"
@@ -803,7 +823,7 @@ endif
FOO = bar
";
let args = Args::empty();
- let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file))?;
+ let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
assert_eq!(makefile.expand_macros(&TokenString::r#macro("FOO"))?, "bar",);
Ok(())
}
@@ -845,7 +865,7 @@ clean:
";
let args = Args::empty();
- let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file))?;
+ let makefile = MakefileReader::read(&args, MacroSet::new(), Cursor::new(file), "")?;
assert!(makefile.targets.contains_key("server"));
Ok(())
}