Skip to content

Commit a1745f8

Browse files
committed
Remove the dependency on failure
1 parent 89e9c50 commit a1745f8

File tree

5 files changed

+20
-121
lines changed

5 files changed

+20
-121
lines changed

Cargo.lock

Lines changed: 0 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,3 @@ locate-cargo-manifest = "0.1.0"
1919
[dependencies.cargo_metadata]
2020
version = "0.7.4"
2121
default-features = false
22-
23-
[dependencies.failure]
24-
version = "0.1.5"
25-
default-features = false
26-
features = ["std"]

src/config.rs

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::ErrorString;
2-
use failure::{Error, ResultExt};
32
use std::path::PathBuf;
43
use toml::Value;
54

@@ -16,17 +15,17 @@ pub(crate) fn read_config(manifest_path: PathBuf) -> Result<Config, ErrorString>
1615
Ok(config)
1716
}
1817

19-
pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, Error> {
18+
pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, ErrorString> {
2019
use std::{fs::File, io::Read};
2120
let cargo_toml: Value = {
2221
let mut content = String::new();
2322
File::open(&manifest_path)
24-
.with_context(|e| format!("Failed to open Cargo.toml: {}", e))?
23+
.map_err(|e| format!("Failed to open Cargo.toml: {}", e))?
2524
.read_to_string(&mut content)
26-
.with_context(|e| format!("Failed to read Cargo.toml: {}", e))?;
25+
.map_err(|e| format!("Failed to read Cargo.toml: {}", e))?;
2726
content
2827
.parse::<Value>()
29-
.with_context(|e| format!("Failed to parse Cargo.toml: {}", e))?
28+
.map_err(|e| format!("Failed to parse Cargo.toml: {}", e))?
3029
};
3130

3231
let metadata = cargo_toml
@@ -41,31 +40,12 @@ pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, Error>
4140
}
4241
.into());
4342
}
44-
Some(metadata) => metadata.as_table().ok_or(format_err!(
43+
Some(metadata) => metadata.as_table().ok_or(format!(
4544
"Bootimage configuration invalid: {:?}",
4645
metadata
4746
))?,
4847
};
4948

50-
/*
51-
* The user shouldn't specify any features if they're using a precompiled bootloader, as we
52-
* don't actually compile it.
53-
*/
54-
if cargo_toml
55-
.get("dependencies")
56-
.and_then(|table| table.get("bootloader_precompiled"))
57-
.and_then(|table| {
58-
table
59-
.get("features")
60-
.or_else(|| table.get("default-features"))
61-
})
62-
.is_some()
63-
{
64-
return Err(format_err!(
65-
"Can't change features of precompiled bootloader!"
66-
));
67-
}
68-
6949
let mut config = ConfigBuilder {
7050
manifest_path: Some(manifest_path),
7151
..Default::default()
@@ -79,12 +59,12 @@ pub(crate) fn read_config_inner(manifest_path: PathBuf) -> Result<Config, Error>
7959
for value in array {
8060
match value {
8161
Value::String(s) => command.push(s),
82-
_ => Err(format_err!("run-command must be a list of strings"))?,
62+
_ => Err(format!("run-command must be a list of strings"))?,
8363
}
8464
}
8565
config.run_command = Some(command);
8666
}
87-
(key, value) => Err(format_err!(
67+
(key, value) => Err(format!(
8868
"unexpected `package.metadata.bootimage` \
8969
key `{}` with value `{}`",
9070
key,

src/main.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[macro_use]
2-
extern crate failure;
3-
41
use args::Args;
52
use std::{fmt, process};
63

@@ -44,7 +41,7 @@ fn run() -> Result<(), ErrorString> {
4441
}
4542
}
4643

47-
struct ErrorString(Box<dyn fmt::Display>);
44+
struct ErrorString(Box<dyn fmt::Display + Send>);
4845

4946
impl ErrorString {
5047
fn display(&self) -> &dyn fmt::Display {
@@ -60,7 +57,7 @@ impl fmt::Debug for ErrorString {
6057

6158
impl<T> From<T> for ErrorString
6259
where
63-
T: fmt::Display + 'static,
60+
T: fmt::Display + Send + 'static,
6461
{
6562
fn from(err: T) -> Self {
6663
ErrorString(Box::new(err))

src/subcommand/test.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
use crate::args::Args;
2-
use crate::config;
3-
use crate::subcommand::build;
4-
use failure::{Error, ResultExt};
1+
use crate::{args::Args, config, subcommand::build, ErrorString};
2+
use std::{io::Write, path::PathBuf, time::Duration, fs, io, process};
53
use rayon::prelude::*;
6-
use std::io::Write;
7-
use std::path::PathBuf;
8-
use std::time::Duration;
9-
use std::{fs, io, process};
104
use wait_timeout::ChildExt;
115

12-
pub(crate) fn test(mut args: Args) -> Result<(), crate::ErrorString> {
6+
pub(crate) fn test(mut args: Args) -> Result<(), ErrorString> {
137
let builder = bootimage::Builder::new(args.manifest_path().clone())?;
148
let config = config::read_config(builder.kernel_manifest_path().to_owned())?;
159
args.apply_default_target(&config, builder.kernel_root());
@@ -56,33 +50,33 @@ pub(crate) fn test(mut args: Args) -> Result<(), crate::ErrorString> {
5650
command.stderr(process::Stdio::null());
5751
let mut child = command
5852
.spawn()
59-
.with_context(|e| format_err!("Failed to launch QEMU: {:?}\n{}", command, e))?;
53+
.map_err(|e| format!("Failed to launch QEMU: {:?}\n{}", command, e))?;
6054
let timeout = Duration::from_secs(60);
6155
match child
6256
.wait_timeout(timeout)
63-
.with_context(|e| format!("Failed to wait with timeout: {}", e))?
57+
.map_err(|e| format!("Failed to wait with timeout: {}", e))?
6458
{
6559
None => {
6660
child
6761
.kill()
68-
.with_context(|e| format!("Failed to kill QEMU: {}", e))?;
62+
.map_err(|e| format!("Failed to kill QEMU: {}", e))?;
6963
child
7064
.wait()
71-
.with_context(|e| format!("Failed to wait for QEMU process: {}", e))?;
65+
.map_err(|e| format!("Failed to wait for QEMU process: {}", e))?;
7266
test_result = TestResult::TimedOut;
7367
writeln!(io::stderr(), "Timed Out")?;
7468
}
7569
Some(exit_status) => {
76-
let output = fs::read_to_string(&output_file).with_context(|e| {
77-
format_err!("Failed to read test output file {}: {}", output_file, e)
70+
let output = fs::read_to_string(&output_file).map_err(|e| {
71+
format!("Failed to read test output file {}: {}", output_file, e)
7872
})?;
7973
test_result = handle_exit_status(exit_status, &output, &target.name)?;
8074
}
8175
}
8276

8377
Ok((target.name.clone(), test_result))
8478
})
85-
.collect::<Result<Vec<(String, TestResult)>, Error>>()?;
79+
.collect::<Result<Vec<(String, TestResult)>, ErrorString>>()?;
8680

8781
println!("");
8882
if tests.iter().all(|t| t.1 == TestResult::Ok) {
@@ -101,7 +95,7 @@ fn handle_exit_status(
10195
exit_status: process::ExitStatus,
10296
output: &str,
10397
target_name: &str,
104-
) -> Result<TestResult, Error> {
98+
) -> Result<TestResult, ErrorString> {
10599
match exit_status.code() {
106100
None => {
107101
writeln!(io::stderr(), "FAIL: No Exit Code.")?;

0 commit comments

Comments
 (0)