diff --git a/Cargo.lock b/Cargo.lock index d6e9b2880..dda00a2d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,11 +11,11 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.37" +version = "0.3.38" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -41,7 +41,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -50,6 +50,7 @@ version = "0.1.16" dependencies = [ "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", + "home 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -64,10 +65,19 @@ name = "error-chain" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "home" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -83,9 +93,9 @@ name = "nix" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -103,6 +113,11 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "scopeguard" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "semver" version = "0.9.0" @@ -160,17 +175,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" -"checksum backtrace 0.3.37 (registry+https://github.com/rust-lang/crates.io-index)" = "5180c5a20655b14a819b652fd2378fa5f1697b6c9ddad3e695c2f9cedf6df4e2" +"checksum backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)" = "690a62be8920ccf773ee00ef0968649b0e724cda8bd5b12286302b4ae955fdf5" "checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" -"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" +"checksum bitflags 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a606a02debe2813760609f57a64a2ffd27d9fdf5b2f133eaca0b248dd92cdd2" "checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" -"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" +"checksum home 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c07c315e106bd6f83f026a20ddaeef2706782e490db1dcdd37caad38a0e895b3" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" "checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "9796c9b7ba2ffe7a9ce53c2287dfc48080f4b2b362fcc245a259b3a7201119dd" diff --git a/Cargo.toml b/Cargo.toml index 9fd22ed39..8e4c6ccb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,12 @@ license = "MIT OR Apache-2.0" name = "cross" repository = "https://github.com/rust-embedded/cross" version = "0.1.16" +edition = "2018" [dependencies] atty = "0.2" error-chain = "0.12" +home = "0.5" lazy_static = "1.0" libc = "0.2.18" rustc_version = "0.2" diff --git a/src/cargo.rs b/src/cargo.rs index 4a04d731e..01ce9fdf3 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -2,8 +2,8 @@ use std::path::{Path, PathBuf}; use std::process::{Command, ExitStatus}; use std::{env, fs}; -use errors::*; -use extensions::CommandExt; +use crate::errors::*; +use crate::extensions::CommandExt; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Subcommand { diff --git a/src/cli.rs b/src/cli.rs index 6894aaba8..2401566f7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,8 +1,8 @@ use std::env; -use Target; -use cargo::Subcommand; -use rustc::TargetList; +use crate::Target; +use crate::cargo::Subcommand; +use crate::rustc::TargetList; pub struct Args { pub all: Vec, diff --git a/src/docker.rs b/src/docker.rs index 4ac273351..e4f33bba9 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -3,13 +3,15 @@ use std::process::{Command, ExitStatus}; use std::{env, fs}; use atty::Stream; +use error_chain::bail; +use lazy_static::lazy_static; use semver::{Version, VersionReq}; -use {Target, Toml}; -use cargo::Root; -use errors::*; -use extensions::CommandExt; -use id; +use crate::{Target, Toml}; +use crate::cargo::Root; +use crate::errors::*; +use crate::extensions::CommandExt; +use crate::id; const DOCKER_IMAGES: &[&str] = &include!(concat!(env!("OUT_DIR"), "/docker-images.rs")); @@ -76,10 +78,8 @@ pub fn run(target: &Target, verbose: bool) -> Result { let root = root.path(); - let home_dir = env::home_dir().ok_or_else(|| "couldn't get home directory. Is $HOME not set?")?; - let cargo_dir = env::var_os("CARGO_HOME") - .map(PathBuf::from) - .unwrap_or_else(|| home_dir.join(".cargo")); + let home_dir = home::home_dir().ok_or_else(|| "could not find home directory")?; + let cargo_dir = home::cargo_home()?; let xargo_dir = env::var_os("XARGO_HOME") .map(PathBuf::from) .unwrap_or_else(|| home_dir.join(".xargo")); diff --git a/src/errors.rs b/src/errors.rs index 73613511b..7b902fd73 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,3 +1,9 @@ #![allow(unused_doc_comments)] -error_chain!(); +use error_chain::error_chain; + +error_chain! { + foreign_links { + Io(std::io::Error); + } +} diff --git a/src/extensions.rs b/src/extensions.rs index 27ced011a..c2800ba0e 100644 --- a/src/extensions.rs +++ b/src/extensions.rs @@ -1,6 +1,6 @@ use std::process::{Command, ExitStatus}; -use errors::*; +use crate::errors::*; pub trait CommandExt { fn run(&mut self, verbose: bool) -> Result<()>; diff --git a/src/file.rs b/src/file.rs index 40427768c..636ceed3e 100644 --- a/src/file.rs +++ b/src/file.rs @@ -2,7 +2,7 @@ use std::fs::File; use std::io::Read; use std::path::Path; -use errors::*; +use crate::errors::*; pub fn read

(path: P) -> Result where P: AsRef diff --git a/src/interpreter.rs b/src/interpreter.rs index f7d828742..39adb468f 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -1,8 +1,8 @@ use std::path::Path; -use errors::*; -use file; -use Target; +use crate::errors::*; +use crate::file; +use crate::Target; /// Checks if the interpreters have been registered in the host system pub fn is_registered(target: &Target) -> Result { diff --git a/src/main.rs b/src/main.rs index 7f62ccac6..0bcac5365 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,4 @@ -#![deny(missing_debug_implementations)] - -extern crate atty; -#[macro_use] -extern crate error_chain; -#[macro_use] -extern crate lazy_static; -extern crate libc; -extern crate rustc_version; -extern crate semver; -extern crate toml; - -#[cfg(not(target_os = "windows"))] -extern crate nix; - -#[cfg(target_os = "windows")] -extern crate winapi; +#![deny(missing_debug_implementations, rust_2018_idioms)] mod cargo; mod cli; @@ -31,14 +15,15 @@ use std::io::Write; use std::process::ExitStatus; use std::{env, io, process}; +use error_chain::bail; use toml::{Value, value::Table}; -use cargo::{Root, Subcommand}; -use errors::*; -use rustc::{TargetList, VersionMetaExt}; +use self::cargo::{Root, Subcommand}; +use self::errors::*; +use self::rustc::{TargetList, VersionMetaExt}; #[allow(non_camel_case_types)] -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub enum Host { Other, diff --git a/src/rustc.rs b/src/rustc.rs index d36e74e2c..cdaddf44b 100644 --- a/src/rustc.rs +++ b/src/rustc.rs @@ -3,9 +3,9 @@ use std::process::Command; use rustc_version::{Version, VersionMeta}; -use {Host, Target}; -use errors::*; -use extensions::CommandExt; +use crate::{Host, Target}; +use crate::errors::*; +use crate::extensions::CommandExt; pub struct TargetList { triples: Vec, diff --git a/src/rustup.rs b/src/rustup.rs index 6fbf646eb..9aa982a6c 100644 --- a/src/rustup.rs +++ b/src/rustup.rs @@ -1,8 +1,8 @@ use std::process::Command; -use Target; -use errors::*; -use extensions::CommandExt; +use crate::Target; +use crate::errors::*; +use crate::extensions::CommandExt; #[derive(Debug)] pub struct AvailableTargets {