Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
20 changes: 9 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T>(path: &Path) -> Result<T, failure::Error>
fn parse<T>(path: &Path) -> Result<T>
where
T: for<'de> serde::Deserialize<'de>,
{
Expand All @@ -52,7 +52,7 @@ where
impl Context {
/* Constructors */
/// Get a context structure from a built artifact.
fn from_artifact(metadata: Metadata, artifact: &Artifact) -> Result<Self, failure::Error> {
fn from_artifact(metadata: Metadata, artifact: &Artifact) -> Result<Self> {
// 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
Expand Down Expand Up @@ -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<Self, failure::Error> {
fn from_flag(metadata: Metadata, target_flag: Option<&str>) -> Result<Self> {
let meta = rustc_version::version_meta()?;
let host = meta.host;
let host_target_name = host;
Expand All @@ -106,8 +106,8 @@ impl Context {
Self::from_target_name(target_name)
}

fn from_target_name(target_name: &str) -> Result<Self, failure::Error> {
let cfg = Cfg::of(target_name)?;
fn from_target_name(target_name: &str) -> Result<Self> {
let cfg = Cfg::of(target_name).map_err(|e| e.compat())?;

Ok(Context {
cfg,
Expand Down Expand Up @@ -167,9 +167,7 @@ impl<'a> BuildType<'a> {
}
}

fn determine_artifact(
matches: &clap::ArgMatches,
) -> Result<(Metadata, Option<Artifact>), failure::Error> {
fn determine_artifact(matches: &clap::ArgMatches) -> Result<(Metadata, Option<Artifact>)> {
let verbose = matches.is_present("verbose");
let target_flag = matches.value_of("target");

Expand Down Expand Up @@ -281,7 +279,7 @@ fn determine_artifact(
Ok((metadata, wanted_artifact))
}

pub fn run(tool: Tool, examples: Option<&str>) -> Result<i32, failure::Error> {
pub fn run(tool: Tool, examples: Option<&str>) -> Result<i32> {
let name = tool.name();
let about = format!(
"Proxy for the `llvm-{}` tool shipped with the Rust toolchain.",
Expand Down
8 changes: 4 additions & 4 deletions src/rustc.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::env;
use std::path::PathBuf;
use std::process::Command;

use failure::Error;
use std::env;
use anyhow::Result;

pub fn sysroot() -> Result<String, Error> {
pub fn sysroot() -> Result<String> {
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
Ok(String::from_utf8(output.stdout)?.trim().to_owned())
}

// See: https://github.com/rust-lang/rust/blob/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/bootstrap/dist.rs#L2334-L2341
pub fn rustlib() -> Result<PathBuf, Error> {
pub fn rustlib() -> Result<PathBuf> {
let sysroot = sysroot()?;
let mut pathbuf = PathBuf::from(sysroot);
pathbuf.push("lib");
Expand Down
6 changes: 3 additions & 3 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<PathBuf, Error> {
pub fn path(self) -> Result<PathBuf> {
let mut path = rustlib()?;
path.push(self.exe());
Ok(path)
Expand Down