From 13ccb4b49b6955191ff13f7adaf3694208370c9c Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 16 Nov 2019 07:57:53 +0100 Subject: [PATCH 1/4] Update version to `0.2.0-alpha.1`. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6c19993f7..e4befed2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["cross", "compilation", "testing", "tool"] license = "MIT OR Apache-2.0" name = "cross" repository = "https://github.com/rust-embedded/cross" -version = "0.1.16" +version = "0.2.0-alpha.1" edition = "2018" [dependencies] From 61cf7710e12e1aa8d9c9e77e45636a3b80fe978e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 16 Nov 2019 07:58:00 +0100 Subject: [PATCH 2/4] Update dependencies. --- Cargo.lock | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5fe8a9262..be7e890a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,10 +11,10 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.38" +version = "0.3.40" 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)", + "backtrace-sys 0.1.32 (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.65 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -22,21 +22,21 @@ dependencies = [ [[package]] name = "backtrace-sys" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.45" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -46,17 +46,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cross" -version = "0.1.16" +version = "0.2.0-alpha.1" 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)", + "home 0.5.1 (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.65 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "which 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -66,13 +66,13 @@ name = "error-chain" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.38 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.40 (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" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -94,8 +94,8 @@ name = "nix" version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "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)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.47 (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.65 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -134,15 +134,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "toml" -version = "0.5.3" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -184,13 +184,13 @@ 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.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.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 backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" +"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" +"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +"checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" "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 home 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a3753954f7bd71f0e671afb8b5a992d1724cf43b7f95a563cd4a0bde94659ca8" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum nix 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" @@ -199,8 +199,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "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" -"checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724" +"checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0" +"checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum which 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5475d47078209a02e60614f7ba5e645ef3ed60f771920ac1906d7c1cc65024c8" From 3d4004cf62de81c0bb9fffcae045cbeed449211d Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 16 Nov 2019 07:58:31 +0100 Subject: [PATCH 3/4] Fix `clippy` warnings. --- src/cargo.rs | 8 ++++---- src/cli.rs | 4 ++-- src/docker.rs | 4 ++-- src/interpreter.rs | 2 +- src/main.rs | 9 ++++----- src/rustc.rs | 4 ++-- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index 01ce9fdf3..5534b37da 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -19,15 +19,15 @@ pub enum Subcommand { } impl Subcommand { - pub fn needs_docker(&self) -> bool { - match *self { + pub fn needs_docker(self) -> bool { + match self { Subcommand::Other => false, _ => true, } } - pub fn needs_interpreter(&self) -> bool { - match *self { + pub fn needs_interpreter(self) -> bool { + match self { Subcommand::Run | Subcommand::Test | Subcommand::Bench => true, _ => false, } diff --git a/src/cli.rs b/src/cli.rs index 2401566f7..ec6a40267 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -36,8 +36,8 @@ pub fn parse(target_list: &TargetList) -> Args { } Args { - all: all, + all, subcommand: sc, - target: target, + target, } } diff --git a/src/docker.rs b/src/docker.rs index 79c5554bf..70626d1e4 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -134,12 +134,12 @@ pub fn run(target: &Target, } if let Ok(value) = env::var("DOCKER_OPTS") { - let opts: Vec<&str> = value.split(" ").collect(); + let opts: Vec<&str> = value.split(' ').collect(); docker.args(&opts); } docker - .args(&["-e", &format!("CROSS_RUNNER={}", runner.unwrap_or_else(|| String::new()))]) + .args(&["-e", &format!("CROSS_RUNNER={}", runner.unwrap_or_else(String::new))]) .args(&["-v", &format!("{}:/xargo:Z", xargo_dir.display())]) .args(&["-v", &format!("{}:/cargo:Z", cargo_dir.display())]) // Prevent `bin` from being mounted inside the Docker container. diff --git a/src/interpreter.rs b/src/interpreter.rs index 39adb468f..6cd90729f 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -7,7 +7,7 @@ use crate::Target; /// Checks if the interpreters have been registered in the host system pub fn is_registered(target: &Target) -> Result { if file::read("/proc/sys/fs/binfmt_misc/status")?.trim() != "enabled" { - Err("host system doesn't have binfmt_misc support")? + return Err("host system doesn't have binfmt_misc support".into()); } let ok = if target.is_windows() { diff --git a/src/main.rs b/src/main.rs index 0bcac5365..25730a57f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -225,7 +225,7 @@ fn run() -> Result { if host.is_supported(args.target.as_ref()) { let target = args.target - .unwrap_or(Target::from(host.triple(), &target_list)); + .unwrap_or_else(|| Target::from(host.triple(), &target_list)); let toml = toml(&root)?; let sysroot = rustc::sysroot(&host, &target, verbose)?; @@ -254,10 +254,9 @@ fn run() -> Result { rustup::install_component("rust-src", toolchain, verbose)?; } - if args.subcommand.map(|sc| sc == Subcommand::Clippy).unwrap_or(false) { - if !rustup::component_is_installed("clippy", toolchain, verbose)? { - rustup::install_component("clippy", toolchain, verbose)?; - } + if args.subcommand.map(|sc| sc == Subcommand::Clippy).unwrap_or(false) && + !rustup::component_is_installed("clippy", toolchain, verbose)? { + rustup::install_component("clippy", toolchain, verbose)?; } let needs_interpreter = args.subcommand.map(|sc| sc.needs_interpreter()).unwrap_or(false); diff --git a/src/rustc.rs b/src/rustc.rs index cdaddf44b..20fdc4841 100644 --- a/src/rustc.rs +++ b/src/rustc.rs @@ -28,13 +28,13 @@ impl VersionMetaExt for VersionMeta { } fn needs_interpreter(&self) -> bool { - !(self.semver >= Version { + self.semver < Version { major: 1, minor: 19, patch: 0, pre: vec![], build: vec![], - }) + } } } From 2758bb5e147af64276e61d0cac7810fc22f57804 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 16 Nov 2019 08:05:27 +0100 Subject: [PATCH 4/4] Refactor `CommandExt`. --- src/extensions.rs | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/extensions.rs b/src/extensions.rs index c2800ba0e..96cc91cba 100644 --- a/src/extensions.rs +++ b/src/extensions.rs @@ -3,53 +3,50 @@ use std::process::{Command, ExitStatus}; use crate::errors::*; pub trait CommandExt { + fn print_verbose(&self, verbose: bool); + fn status_result(&self, status: ExitStatus) -> Result<()>; fn run(&mut self, verbose: bool) -> Result<()>; fn run_and_get_status(&mut self, verbose: bool) -> Result; fn run_and_get_stdout(&mut self, verbose: bool) -> Result; } impl CommandExt for Command { - /// Runs the command to completion - fn run(&mut self, verbose: bool) -> Result<()> { - let status = self.run_and_get_status(verbose)?; + fn print_verbose(&self, verbose: bool) { + if verbose { + println!("+ {:?}", self); + } + } + fn status_result(&self, status: ExitStatus) -> Result<()> { if status.success() { Ok(()) } else { - Err(format!("`{:?}` failed with exit code: {:?}", - self, - status.code()))? + Err(format!("`{:?}` failed with exit code: {:?}", self, status.code()).into()) } } /// Runs the command to completion - fn run_and_get_status(&mut self, verbose: bool) -> Result { - if verbose { - println!("+ {:?}", self); - } + fn run(&mut self, verbose: bool) -> Result<()> { + let status = self.run_and_get_status(verbose)?; + self.status_result(status) + } + /// Runs the command to completion + fn run_and_get_status(&mut self, verbose: bool) -> Result { + self.print_verbose(verbose); self.status() .chain_err(|| format!("couldn't execute `{:?}`", self)) } /// Runs the command to completion and returns its stdout fn run_and_get_stdout(&mut self, verbose: bool) -> Result { - if verbose { - println!("+ {:?}", self); - } - + self.print_verbose(verbose); let out = self.output() .chain_err(|| format!("couldn't execute `{:?}`", self))?; - if out.status.success() { - Ok(String::from_utf8(out.stdout).chain_err(|| { - format!("`{:?}` output was not UTF-8", - self) - })?) - } else { - Err(format!("`{:?}` failed with exit code: {:?}", - self, - out.status.code()))? - } + self.status_result(out.status)?; + + Ok(String::from_utf8(out.stdout) + .chain_err(|| format!("`{:?}` output was not UTF-8", self))?) } }