aboutsummaryrefslogtreecommitdiff
path: root/src/makefile/mod.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-04-01 17:44:50 -0600
committerMelody Horn <melody@boringcactus.com>2021-04-01 17:44:50 -0600
commit093e58de2ffc8243e6ff929f50a2aaa6ef60848b (patch)
treebe2003c6fd8d774f9462f4c0bd2ddae2af92f238 /src/makefile/mod.rs
parente1128fe55d91ca60086de45c911b4568d2eec9ee (diff)
downloadmakers-093e58de2ffc8243e6ff929f50a2aaa6ef60848b.tar.gz
makers-093e58de2ffc8243e6ff929f50a2aaa6ef60848b.zip
slightly fancier errors
Diffstat (limited to 'src/makefile/mod.rs')
-rw-r--r--src/makefile/mod.rs36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/makefile/mod.rs b/src/makefile/mod.rs
index 1fb5935..af8ca81 100644
--- a/src/makefile/mod.rs
+++ b/src/makefile/mod.rs
@@ -7,7 +7,7 @@ use std::io::{BufRead, BufReader};
use std::path::Path;
use std::rc::Rc;
-use anyhow::{bail, Context};
+use eyre::{bail, eyre, Context, Result};
use lazy_static::lazy_static;
use regex::Regex;
@@ -133,7 +133,7 @@ impl<'a> Makefile<'a> {
}
}
- pub fn and_read_file(&mut self, path: impl AsRef<Path>) -> anyhow::Result<()> {
+ pub fn and_read_file(&mut self, path: impl AsRef<Path>) -> Result<()> {
let file = File::open(path);
// TODO handle errors
let file = file.context("couldn't open makefile!")?;
@@ -141,7 +141,7 @@ impl<'a> Makefile<'a> {
self.and_read(file_reader)
}
- pub fn and_read(&mut self, source: impl BufRead) -> anyhow::Result<()> {
+ pub fn and_read(&mut self, source: impl BufRead) -> Result<()> {
let mut lines_iter = source
.lines()
.enumerate()
@@ -235,12 +235,12 @@ impl<'a> Makefile<'a> {
&mut self,
line_tokens: &TokenString,
line_number: usize,
- lines_iter: &mut impl Iterator<Item = (usize, anyhow::Result<String>)>,
- ) -> anyhow::Result<()> {
+ lines_iter: &mut impl Iterator<Item = (usize, Result<String>)>,
+ ) -> Result<()> {
let mut lines_iter = lines_iter.peekable();
let (targets, not_targets) = line_tokens
.split_once(':')
- .with_context(|| format!("read_rule couldn't find a ':' on line {}", line_number))?;
+ .ok_or_else(|| eyre!("read_rule couldn't find a ':' on line {}", line_number))?;
let targets = self.expand_macros(&targets, None)?;
let targets = targets.split_whitespace().collect::<Vec<_>>();
let (prerequisites, mut commands) = match not_targets.split_once(';') {
@@ -350,10 +350,10 @@ impl<'a> Makefile<'a> {
Ok(())
}
- fn read_macro(&mut self, line_tokens: &TokenString, line_number: usize) -> anyhow::Result<()> {
+ fn read_macro(&mut self, line_tokens: &TokenString, line_number: usize) -> Result<()> {
let (name, mut value) = line_tokens
.split_once('=')
- .with_context(|| format!("read_rule couldn't find a ':' on line {}", line_number))?;
+ .ok_or_else(|| eyre!("read_rule couldn't find a ':' on line {}", line_number))?;
let name = self.expand_macros(&name, None)?;
// GNUisms are annoying, but popular
let mut expand_value = false;
@@ -418,7 +418,7 @@ impl<'a> Makefile<'a> {
}
}
- pub fn get_target(&self, name: &str) -> anyhow::Result<Rc<RefCell<Target>>> {
+ pub fn get_target(&self, name: &str) -> Result<Rc<RefCell<Target>>> {
// TODO implement .POSIX
let follow_gnu = true;
@@ -513,19 +513,23 @@ impl<'a> Makefile<'a> {
}
let targets = self.targets.borrow();
- Ok(Rc::clone(targets.get(name).context("Target not found!")?))
+ Ok(Rc::clone(
+ targets
+ .get(name)
+ .ok_or_else(|| eyre!("Target not found!"))?,
+ ))
}
- pub fn update_target(&self, name: &str) -> anyhow::Result<()> {
+ pub fn update_target(&self, name: &str) -> Result<()> {
self.get_target(name)?.borrow().update(self)
}
- fn expand_macros(&self, text: &TokenString, target: Option<&Target>) -> anyhow::Result<String> {
+ fn expand_macros(&self, text: &TokenString, target: Option<&Target>) -> Result<String> {
let target = target.cloned();
let lookup_internal = move |name: &str| {
let target = target
.as_ref()
- .context("internal macro but no current target!")?;
+ .ok_or_else(|| eyre!("internal macro but no current target!"))?;
let macro_pieces = if name.starts_with('@') {
// The $@ shall evaluate to the full target name of the
// current target.
@@ -564,7 +568,7 @@ impl<'a> Makefile<'a> {
.map(|x| {
Path::new(&x)
.parent()
- .context("no parent")
+ .ok_or_else(|| eyre!("no parent"))
.map(|x| x.to_string_lossy().into())
})
.collect::<Result<_, _>>()?
@@ -574,7 +578,7 @@ impl<'a> Makefile<'a> {
.map(|x| {
Path::new(&x)
.file_name()
- .context("no filename")
+ .ok_or_else(|| eyre!("no filename"))
.map(|x| x.to_string_lossy().into())
})
.collect::<Result<_, _>>()?
@@ -695,7 +699,7 @@ mod test {
use super::*;
- type R = anyhow::Result<()>;
+ type R = Result<()>;
fn empty_makefile(args: &Args) -> Makefile {
Makefile {