From a417523fa990c258509696507d1ce05f85dedbc4 Mon Sep 17 00:00:00 2001 From: Zero Date: Wed, 20 May 2020 23:29:41 +0930 Subject: [PATCH] Move from failure to anyhow --- CHANGELOG.md | 1 + Cargo.toml | 2 +- src/lib.rs | 20 +++++++++----------- src/rustc.rs | 8 ++++---- src/tool.rs | 6 +++--- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a64026..c789713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Changed help output to more closely reflect the help command of `cargo` subcommands - Removed `walkdir` dependency by using expected path to tool executable - Updated `cargo_metadata 0.9 -> 0.10` +- Replaced `failure` dependency with [`anyhow`](https://github.com/dtolnay/anyhow) ## [v0.2.0] - 2020-04-11 diff --git a/Cargo.toml b/Cargo.toml index 574ac2a..954cf44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,10 @@ version = "0.2.0" [dependencies] cargo_metadata = "0.10" clap = "2.33" -failure = "0.1" regex = "1.3" rustc-cfg = "0.4" rustc-demangle = "0.1" rustc_version = "0.2" serde = "1.0" toml = "0.5" +anyhow = "1.0" diff --git a/src/lib.rs b/src/lib.rs index a71167f..333f93c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,11 +3,11 @@ use std::io::{self, BufReader, Write}; use std::path::{Component, Path}; use std::process::{Command, Stdio}; -use std::{env, str}; +use std::str; +use anyhow::{bail, Result}; use cargo_metadata::{Artifact, CargoOpt, Message, Metadata, MetadataCommand}; use clap::{App, AppSettings, Arg}; -use failure::bail; use rustc_cfg::Cfg; pub use tool::Tool; @@ -36,7 +36,7 @@ fn search<'p>(path: &'p Path, file: &str) -> Option<&'p Path> { path.ancestors().find(|dir| dir.join(file).exists()) } -fn parse(path: &Path) -> Result +fn parse(path: &Path) -> Result where T: for<'de> serde::Deserialize<'de>, { @@ -52,7 +52,7 @@ where impl Context { /* Constructors */ /// Get a context structure from a built artifact. - fn from_artifact(metadata: Metadata, artifact: &Artifact) -> Result { + fn from_artifact(metadata: Metadata, artifact: &Artifact) -> Result { // Currently there is no clean way to get the target triple from cargo so we can only make // an approximation, we do this by extracting the target triple from the artifacts path. // For more info on the path structure see: https://doc.rust-lang.org/cargo/guide/build-cache.html @@ -81,7 +81,7 @@ impl Context { /// Get a context structure from a provided target flag, used when cargo /// was not used to build the binary. - fn from_flag(metadata: Metadata, target_flag: Option<&str>) -> Result { + fn from_flag(metadata: Metadata, target_flag: Option<&str>) -> Result { let meta = rustc_version::version_meta()?; let host = meta.host; let host_target_name = host; @@ -106,8 +106,8 @@ impl Context { Self::from_target_name(target_name) } - fn from_target_name(target_name: &str) -> Result { - let cfg = Cfg::of(target_name)?; + fn from_target_name(target_name: &str) -> Result { + let cfg = Cfg::of(target_name).map_err(|e| e.compat())?; Ok(Context { cfg, @@ -167,9 +167,7 @@ impl<'a> BuildType<'a> { } } -fn determine_artifact( - matches: &clap::ArgMatches, -) -> Result<(Metadata, Option), failure::Error> { +fn determine_artifact(matches: &clap::ArgMatches) -> Result<(Metadata, Option)> { let verbose = matches.is_present("verbose"); let target_flag = matches.value_of("target"); @@ -281,7 +279,7 @@ fn determine_artifact( Ok((metadata, wanted_artifact)) } -pub fn run(tool: Tool, examples: Option<&str>) -> Result { +pub fn run(tool: Tool, examples: Option<&str>) -> Result { let name = tool.name(); let about = format!( "Proxy for the `llvm-{}` tool shipped with the Rust toolchain.", diff --git a/src/rustc.rs b/src/rustc.rs index b29858b..2797b60 100644 --- a/src/rustc.rs +++ b/src/rustc.rs @@ -1,10 +1,10 @@ +use std::env; use std::path::PathBuf; use std::process::Command; -use failure::Error; -use std::env; +use anyhow::Result; -pub fn sysroot() -> Result { +pub fn sysroot() -> Result { let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into()); let output = Command::new(rustc).arg("--print").arg("sysroot").output()?; // Note: We must trim() to remove the `\n` from the end of stdout @@ -12,7 +12,7 @@ pub fn sysroot() -> Result { } // See: https://github.com/rust-lang/rust/blob/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/bootstrap/dist.rs#L2334-L2341 -pub fn rustlib() -> Result { +pub fn rustlib() -> Result { let sysroot = sysroot()?; let mut pathbuf = PathBuf::from(sysroot); pathbuf.push("lib"); diff --git a/src/tool.rs b/src/tool.rs index b711149..99948b7 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use std::process::Command; use std::{env, process}; -use failure::Error; +use anyhow::Result; use crate::rustc::rustlib; @@ -38,11 +38,11 @@ impl Tool { pub fn exe(self) -> String { match self { Tool::Lld => format!("rust-lld{}", EXE_SUFFIX), - _ => format!("llvm-{}{}", self.name(), EXE_SUFFIX) + _ => format!("llvm-{}{}", self.name(), EXE_SUFFIX), } } - pub fn path(self) -> Result { + pub fn path(self) -> Result { let mut path = rustlib()?; path.push(self.exe()); Ok(path)