diff --git a/src/cargo.rs b/src/cargo.rs index e31d0a6..ad7269f 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -3,13 +3,13 @@ use std::path::{Path, PathBuf}; use std::process::{Command, ExitStatus}; use std::{env, fmt}; -use toml::{Value, map::Map}; +use toml::{map::Map, Value}; use cli::Args; use errors::*; use extensions::CommandExt; -use util; use sysroot::XargoMode; +use util; use xargo::Home; #[derive(Clone)] @@ -50,7 +50,7 @@ impl Rustflags { pub fn encode(mut self, home: &Home) -> String { self.flags.push("--sysroot".to_owned()); self.flags.push(home.display().to_string()); // FIXME: we shouldn't use display, we should keep the OsString - // As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`. + // As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`. self.flags.join("\x1f") } } @@ -75,7 +75,7 @@ impl Rustdocflags { pub fn encode(mut self, home: &Home) -> String { self.flags.push("--sysroot".to_owned()); self.flags.push(home.display().to_string()); // FIXME: we shouldn't use display, we should keep the OsString - // As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`. + // As per CARGO_ENCODED_RUSTFLAGS docs, the separator is `0x1f`. self.flags.join("\x1f") } } @@ -84,19 +84,17 @@ pub fn rustdocflags(config: Option<&Config>, target: &str) -> Result, target: &str, tool: &str) -> Result> { // TODO: would be nice to also support the CARGO_ENCODED_ env vars if let Some(t) = env::var_os(tool.to_uppercase()) { - return Ok( - t.to_string_lossy() - .split_whitespace() - .map(|w| w.to_owned()) - .collect(), - ); + return Ok(t + .to_string_lossy() + .split_whitespace() + .map(|w| w.to_owned()) + .collect()); } if let Some(config) = config.as_ref() { @@ -109,7 +107,8 @@ fn flags(config: Option<&Config>, target: &str, tool: &str) -> Result, target: &str, tool: &str) -> Result Command { } pub fn run(args: &Args, verbose: bool) -> Result { - command() - .args(args.all()) - .run_and_get_status(verbose) + command().args(args.all()).run_and_get_status(verbose) } pub struct Config { @@ -171,8 +167,9 @@ pub struct Config { impl Config { pub fn target(&self) -> Result> { if let Some(v) = self.table.get("build").and_then(|t| t.get("target")) { - Ok(Some(v.as_str() - .ok_or_else(|| format!(".cargo/config: build.target must be a string"))?)) + Ok(Some(v.as_str().ok_or_else(|| { + format!(".cargo/config: build.target must be a string") + })?)) } else { Ok(None) } @@ -236,7 +233,7 @@ pub struct Toml { impl Toml { /// `profile.release` part of `Cargo.toml` - pub fn profile(&self) -> Option { + pub fn profile(&self) -> Option> { self.table .get("profile") .and_then(|t| t.get("release")) @@ -262,7 +259,7 @@ pub fn root(mode: XargoMode, manifest_path: Option<&str>) -> Result // Don't require a 'Cargo.toml' to exist when 'xargo-check' is used let name = match mode { XargoMode::Build => "Cargo.toml", - XargoMode::Check => "Xargo.toml" + XargoMode::Check => "Xargo.toml", }; let cd = match manifest_path { diff --git a/src/cli.rs b/src/cli.rs index 9668c01..3424577 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -7,7 +7,7 @@ pub struct Args { subcommand: Option, target: Option, message_format: Option, - manifest_path: Option, // path to the Cargo toml file given in --manifest-path + manifest_path: Option, // path to the Cargo toml file given in --manifest-path } impl Args { diff --git a/src/errors.rs b/src/errors.rs index b2cc251..a675285 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,3 +1,4 @@ #![allow(unknown_lints)] #![allow(unused_doc_comments)] +#![allow(unexpected_cfgs)] error_chain!(); diff --git a/src/extensions.rs b/src/extensions.rs index 10d0293..5a9ff50 100644 --- a/src/extensions.rs +++ b/src/extensions.rs @@ -1,5 +1,5 @@ -use std::io::Write; use std::io; +use std::io::Write; use std::process::{Command, ExitStatus}; use errors::*; @@ -42,7 +42,8 @@ impl CommandExt for Command { writeln!(io::stderr(), "+ {:?}", self).ok(); } - let out = self.output() + let out = self + .output() .chain_err(|| format!("couldn't execute `{:?}`", self))?; if out.status.success() { diff --git a/src/flock.rs b/src/flock.rs index 09b98ba..7861009 100644 --- a/src/flock.rs +++ b/src/flock.rs @@ -6,8 +6,8 @@ use std::io::Write; use std::path::{Display, Path, PathBuf}; use std::{fs, io}; -use fs2::FileExt; use fs2; +use fs2::FileExt; #[derive(PartialEq)] enum State { @@ -107,15 +107,14 @@ impl Filesystem { match state { State::Exclusive => { - acquire( - msg, - &path, - &|| f.try_lock_exclusive(), - &|| f.lock_exclusive(), - )?; + acquire(msg, &path, &|| f.try_lock_exclusive(), &|| { + f.lock_exclusive() + })?; } State::Shared => { - acquire(msg, &path, &|| f.try_lock_shared(), &|| f.lock_shared())?; + acquire(msg, &path, &|| Ok(f.try_lock_shared()?), &|| { + f.lock_shared() + })?; } } @@ -125,7 +124,7 @@ impl Filesystem { }) } - pub fn display(&self) -> Display { + pub fn display(&self) -> Display<'_> { self.path.display() } } @@ -173,13 +172,12 @@ fn acquire( match try() { Ok(_) => return Ok(()), #[cfg(target_os = "macos")] - Err(ref e) if e.raw_os_error() == Some(::libc::ENOTSUP) => - { - return Ok(()) + Err(ref e) if e.raw_os_error() == Some(::libc::ENOTSUP) => return Ok(()), + Err(e) => { + if e.raw_os_error() != fs2::lock_contended_error().raw_os_error() { + return Err(e); + } } - Err(e) => if e.raw_os_error() != fs2::lock_contended_error().raw_os_error() { - return Err(e); - }, } writeln!( @@ -187,7 +185,8 @@ fn acquire( "{:>12} waiting for file lock on {}", "Blocking", msg - ).ok(); + ) + .ok(); block() } diff --git a/src/lib.rs b/src/lib.rs index 9f8da8a..67ae114 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,19 +2,22 @@ #[macro_use] extern crate error_chain; +extern crate dirs; extern crate fs2; -#[cfg(any(all(target_os = "linux", not(target_env = "musl")), target_os = "macos"))] +#[cfg(any( + all(target_os = "linux", not(target_env = "musl")), + target_os = "macos" +))] extern crate libc; extern crate rustc_version; extern crate serde_json; extern crate tempdir; extern crate toml; extern crate walkdir; -extern crate dirs; use std::hash::{Hash, Hasher}; use std::io::Write; -use std::path::{Path}; +use std::path::Path; use std::process::ExitStatus; use std::{env, io, process}; @@ -100,9 +103,11 @@ pub fn main_inner(xargo_mode: XargoMode) { process::exit(1) } - Ok(Some(status)) => if !status.success() { - process::exit(status.code().unwrap_or(1)) - }, + Ok(Some(status)) => { + if !status.success() { + process::exit(status.code().unwrap_or(1)) + } + } Ok(None) => {} } } @@ -122,7 +127,8 @@ fn run(cargo_mode: XargoMode) -> Result> { io::stderr(), concat!("xargo ", env!("CARGO_PKG_VERSION"), "{}"), include_str!(concat!(env!("OUT_DIR"), "/commit-info.txt")) - ).ok(); + ) + .ok(); return cargo::run(&args, verbose).map(Some); } @@ -136,11 +142,13 @@ fn run(cargo_mode: XargoMode) -> Result> { "The XARGO_RUST_SRC env variable must be set and point to the \ Rust source directory when working with the 'dev' channel", )?, - Channel::Nightly => if let Some(src) = rustc::Src::from_env() { - src - } else { - sysroot.src()? - }, + Channel::Nightly => { + if let Some(src) = rustc::Src::from_env() { + src + } else { + sysroot.src()? + } + } Channel::Stable | Channel::Beta => { eprintln!( "ERROR: the sysroot can't be built for the {:?} channel. \ @@ -199,13 +207,13 @@ fn run(cargo_mode: XargoMode) -> Result> { &meta, config.as_ref(), verbose, - ).map(Some); + ) + .map(Some); } else { - return Ok(None) + return Ok(None); } } } cargo::run(&args, verbose).map(Some) } - diff --git a/src/rustc.rs b/src/rustc.rs index 8f97f71..43a2d6a 100644 --- a/src/rustc.rs +++ b/src/rustc.rs @@ -5,13 +5,13 @@ use std::process::Command; pub use rustc_version::version_meta as version; -use serde_json::Value; use serde_json; +use serde_json::Value; +use cargo::Root; use errors::*; use extensions::CommandExt; use {rustc, util}; -use cargo::Root; fn command() -> Command { env::var_os("RUSTC") @@ -32,10 +32,8 @@ pub fn sysroot(verbose: bool) -> Result { command() .args(&["--print", "sysroot"]) .run_and_get_stdout(verbose) - .map(|l| { - Sysroot { - path: PathBuf::from(l.trim()), - } + .map(|l| Sysroot { + path: PathBuf::from(l.trim()), }) } /// Path to Rust source @@ -74,22 +72,32 @@ impl Sysroot { pub fn src(&self) -> Result { let src = self.path().join("lib").join("rustlib").join("src"); - if src.join("rust").join("src").join("libstd").join("Cargo.toml").is_file() { + if src + .join("rust") + .join("src") + .join("libstd") + .join("Cargo.toml") + .is_file() + { return Ok(Src { path: src.join("rust").join("src"), }); } - if src.join("rust").join("library").join("std").join("Cargo.toml").is_file() { + if src + .join("rust") + .join("library") + .join("std") + .join("Cargo.toml") + .is_file() + { return Ok(Src { path: src.join("rust").join("library"), }); } - Err( - "`rust-src` component not found. Run `rustup component add \ - rust-src`.", - )? + Err("`rust-src` component not found. Run `rustup component add \ + rust-src`.")? } } diff --git a/src/sysroot.rs b/src/sysroot.rs index 935df04..58b65cb 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -1,5 +1,5 @@ -use std::collections::BTreeMap; use std::collections::hash_map::DefaultHasher; +use std::collections::BTreeMap; use std::hash::{Hash, Hasher}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; @@ -7,15 +7,15 @@ use std::{env, fs}; use rustc_version::VersionMeta; use tempdir::TempDir; -use toml::{value::Table, Value, map::Map}; +use toml::{map::Map, value::Table, Value}; -use CompilationMode; use cargo::{Root, Rustflags}; use errors::*; use extensions::CommandExt; use rustc::{Src, Sysroot, Target}; use util; use xargo::Home; +use CompilationMode; use {cargo, xargo}; fn profile() -> &'static str { @@ -115,10 +115,15 @@ version = "0.0.0" } // rust-src comes with a lockfile for libstd. Use it. - let src_parent = src.path().parent().map(Path::to_path_buf).unwrap_or_else(|| src.path().join("..")); + let src_parent = src + .path() + .parent() + .map(Path::to_path_buf) + .unwrap_or_else(|| src.path().join("..")); let lockfile = src_parent.join("Cargo.lock"); let target_lockfile = td.join("Cargo.lock"); - fs::copy(lockfile, &target_lockfile).chain_err(|| "Cargo.lock file is missing from source dir")?; + fs::copy(lockfile, &target_lockfile) + .chain_err(|| "Cargo.lock file is missing from source dir")?; let mut perms = fs::metadata(&target_lockfile) .chain_err(|| "Cargo.lock file is missing from target dir")? @@ -185,7 +190,7 @@ version = "0.0.0" match cargo_mode { XargoMode::Build => cmd.arg("build"), - XargoMode::Check => cmd.arg("check") + XargoMode::Check => cmd.arg("check"), }; cmd.arg("--release"); @@ -352,7 +357,12 @@ pub fn update( &dst, )?; - let bin_src = sysroot.path().join("lib").join("rustlib").join(&meta.host).join("bin"); + let bin_src = sysroot + .path() + .join("lib") + .join("rustlib") + .join(&meta.host) + .join("bin"); // copy the Rust linker if it exists if bin_src.exists() { let bin_dst = lock.parent().join("bin"); @@ -421,10 +431,7 @@ impl Blueprint { /// Add $CRATE to `patch` section, as needed to build libstd. fn add_patch(patch: &mut Table, src_path: &Path, crate_: &str) -> Result<()> { // Old sysroots have this in `src/tools/$CRATE`, new sysroots in `library/$CRATE`. - let paths = [ - src_path.join(crate_), - src_path.join("tools").join(crate_), - ]; + let paths = [src_path.join(crate_), src_path.join("tools").join(crate_)]; if let Some(path) = paths.iter().find(|p| p.exists()) { // add crate to patch section (if not specified) fn table_entry<'a>(table: &'a mut Table, key: &str) -> Result<&'a mut Table> { @@ -479,11 +486,14 @@ impl Blueprint { .as_table() .cloned() .ok_or_else(|| format!("Xargo.toml: `patch` must be a table"))?, - None => Table::new() + None => Table::new(), }; for (k1, v) in patch.iter_mut() { - for (k2, v) in v.as_table_mut_or_err(|| format!("patch.{}", k1))?.iter_mut() { + for (k2, v) in v + .as_table_mut_or_err(|| format!("patch.{}", k1))? + .iter_mut() + { let krate = v.as_table_mut_or_err(|| format!("patch.{}.{}", k1, k2))?; make_path_absolute(krate, base_path, || format!("patch.{}.{}", k1, k2))?; @@ -525,15 +535,17 @@ impl Blueprint { deps } - (Some(value), None) | (None, Some(value)) => if let Some(table) = value.as_table() { - table.clone() - } else { - Err(format!( - "Xargo.toml: target.{}.dependencies must be \ + (Some(value), None) | (None, Some(value)) => { + if let Some(table) = value.as_table() { + table.clone() + } else { + Err(format!( + "Xargo.toml: target.{}.dependencies must be \ a table", - target - ))? - }, + target + ))? + } + } (None, None) => { // If no dependencies were listed, we assume `core` and `compiler_builtins` as the // dependencies @@ -549,13 +561,9 @@ impl Blueprint { // reference compiler-builtins with `version = "*"`, // the corresponding version of compiler_builtins matching the used std // is selected because of the copied `Cargo.lock`-file from std. - cb.insert("version".to_owned(), - Value::String("*".to_owned())); + cb.insert("version".to_owned(), Value::String("*".to_owned())); cb.insert("stage".to_owned(), Value::Integer(1)); - t.insert( - "compiler_builtins".to_owned(), - Value::Table(cb), - ); + t.insert("compiler_builtins".to_owned(), Value::Table(cb)); t } }; @@ -577,10 +585,7 @@ impl Blueprint { // No path and no git given. This might be in the sysroot, but if we don't find it there we assume it comes from crates.io. // Current sysroots call it just "std" (etc), but older sysroots use "libstd" (etc), // so we check both. - let paths = [ - src.path().join(&k), - src.path().join(format!("lib{}", k)), - ]; + let paths = [src.path().join(&k), src.path().join(format!("lib{}", k))]; if let Some(path) = paths.iter().find(|p| p.exists()) { map.insert("path".to_owned(), Value::String(path.display().to_string())); } diff --git a/src/util.rs b/src/util.rs index 0fc5023..ae2c80f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,7 +1,7 @@ +use std::fs; use std::fs::File; use std::io::{Read, Write}; use std::path::Path; -use std::fs; use toml::Value; use walkdir::WalkDir; @@ -31,15 +31,14 @@ pub fn cp_r(src: &Path, dst: &Path) -> Result<()> { })?; let dst_file = dst.join(relative_path); - let metadata = e.metadata().chain_err(|| { - format!("Could not retrieve metadata of `{}`", e.path().display()) - })?; + let metadata = e + .metadata() + .chain_err(|| format!("Could not retrieve metadata of `{}`", e.path().display()))?; if metadata.is_dir() { // ensure the destination directory exists - fs::create_dir_all(&dst_file).chain_err(|| { - format!("Could not create directory `{}`", dst_file.display()) - })?; + fs::create_dir_all(&dst_file) + .chain_err(|| format!("Could not create directory `{}`", dst_file.display()))?; } else { // else copy the file fs::copy(&src_file, &dst_file).chain_err(|| { @@ -61,8 +60,10 @@ pub fn mkdir(path: &Path) -> Result<()> { /// Parses `path` as TOML pub fn parse(path: &Path) -> Result { - Ok(toml::from_str(&read(path)?) - .map_err(|_| format!("{} is not valid TOML", path.display()))?) + Ok( + toml::from_str(&read(path)?) + .map_err(|_| format!("{} is not valid TOML", path.display()))?, + ) } pub fn read(path: &Path) -> Result { diff --git a/src/xargo.rs b/src/xargo.rs index fd966c7..578da98 100644 --- a/src/xargo.rs +++ b/src/xargo.rs @@ -1,17 +1,17 @@ +use std::io::{self, Write}; use std::path::{Display, Path, PathBuf}; use std::process::ExitStatus; use std::{env, mem}; -use std::io::{self, Write}; -use toml::Value; use rustc_version::VersionMeta; +use toml::Value; -use CompilationMode; use cargo::{Config, Root, Rustflags, Subcommand}; use cli::Args; use errors::*; use extensions::CommandExt; use flock::{FileLock, Filesystem}; +use CompilationMode; use {cargo, util}; pub fn run( @@ -52,7 +52,7 @@ pub struct Home { } impl Home { - pub fn display(&self) -> Display { + pub fn display(&self) -> Display<'_> { self.path.display() } @@ -64,18 +64,14 @@ impl Home { let fs = self.path(triple); fs.open_ro(".sentinel", &format!("{}'s sysroot", triple)) - .chain_err(|| { - format!("couldn't lock {}'s sysroot as read-only", triple) - }) + .chain_err(|| format!("couldn't lock {}'s sysroot as read-only", triple)) } pub fn lock_rw(&self, triple: &str) -> Result { let fs = self.path(triple); fs.open_rw(".sentinel", &format!("{}'s sysroot", triple)) - .chain_err(|| { - format!("couldn't lock {}'s sysroot as read-only", triple) - }) + .chain_err(|| format!("couldn't lock {}'s sysroot as read-only", triple)) } } @@ -125,9 +121,11 @@ impl Toml { /// content of this 'Xargo.toml' pub fn toml(root: &Root) -> Result<(Option<&Path>, Option)> { if let Some(p) = util::search(root.path(), "Xargo.toml") { - Ok((Some(p), util::parse(&p.join("Xargo.toml")).map(|t| Some(Toml { table: t }))?)) - } - else { + Ok(( + Some(p), + util::parse(&p.join("Xargo.toml")).map(|t| Some(Toml { table: t }))?, + )) + } else { Ok((None, None)) } } diff --git a/tests/smoke.rs b/tests/smoke.rs index b8160cc..c4748bb 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -4,10 +4,10 @@ extern crate error_chain; #[macro_use] extern crate lazy_static; +extern crate dirs; extern crate parking_lot; extern crate rustc_version; extern crate tempdir; -extern crate dirs; use std::fs::OpenOptions; use std::io::Write; @@ -22,6 +22,7 @@ use errors::*; mod errors { #![allow(unused_doc_comments)] + #![allow(unexpected_cfgs)] error_chain!(); } @@ -30,7 +31,7 @@ macro_rules! run { if let Err(e) = run() { panic!("{}", e) } - } + }; } // Returns Xargo's "home" @@ -38,11 +39,9 @@ fn home() -> Result { if let Some(h) = env::var_os("XARGO_HOME") { Ok(PathBuf::from(h)) } else { - Ok( - dirs::home_dir() - .ok_or_else(|| "couldn't find your home directory. Is $HOME set?")? - .join(".xargo"), - ) + Ok(dirs::home_dir() + .ok_or_else(|| "couldn't find your home directory. Is $HOME set?")? + .join(".xargo")) } } @@ -59,7 +58,8 @@ fn cleanup(target: &str) -> Result<()> { fn exists(krate: &str, target: &str) -> Result { let p = home()?.join("lib/rustlib").join(target).join("lib"); - for e in fs::read_dir(&p).chain_err(|| format!("couldn't read the directory {}", p.display()))? + for e in + fs::read_dir(&p).chain_err(|| format!("couldn't read the directory {}", p.display()))? { let e = e.chain_err(|| { format!( @@ -81,15 +81,17 @@ fn host() -> String { } fn mkdir(path: &Path) -> Result<()> { - fs::create_dir(path).chain_err(|| { - format!("couldn't create the directory {}", path.display()) - }) + fs::create_dir(path).chain_err(|| format!("couldn't create the directory {}", path.display())) } fn sysroot_was_built(stderr: &str, target: &str) -> bool { stderr.lines().filter(|l| l.starts_with("+")).any(|l| { - l.contains("cargo") && l.contains("build") && l.contains("--target") && l.contains(target) - && l.contains("-p") && l.contains("core") + l.contains("cargo") + && l.contains("build") + && l.contains("--target") + && l.contains(target) + && l.contains("-p") + && l.contains("core") }) } @@ -134,7 +136,8 @@ trait CommandExt { impl CommandExt for Command { fn run(&mut self) -> Result<()> { - let status = self.status() + let status = self + .status() .chain_err(|| format!("couldn't execute `{:?}`", self))?; if status.success() { @@ -149,7 +152,8 @@ impl CommandExt for Command { } fn run_and_get_stderr(&mut self) -> Result { - let out = self.output() + let out = self + .output() .chain_err(|| format!("couldn't execute `{:?}`", self))?; let stderr = String::from_utf8(out.stderr) @@ -177,15 +181,19 @@ struct Project { } /// Create a simple project -fn create_simple_project(project_path: &Path, name: &'static str, library_source: &'static str) -> Result<()> { +fn create_simple_project( + project_path: &Path, + name: &'static str, + library_source: &'static str, +) -> Result<()> { xargo()? .args(&["init", "-q", "--lib", "--vcs", "none", "--name", name]) .current_dir(project_path) .run()?; - write(&project_path.join("src/lib.rs"), false, library_source)?; + write(&project_path.join("src/lib.rs"), false, library_source)?; - Ok(()) + Ok(()) } impl Project { @@ -210,7 +218,8 @@ impl Project { } "#; - let td = TempDir::new_in(dir, "xargo").chain_err(|| "couldn't create a temporary directory")?; + let td = + TempDir::new_in(dir, "xargo").chain_err(|| "couldn't create a temporary directory")?; create_simple_project(td.path(), name, "#![no_std]")?; write(&td.path().join(format!("{}.json", name)), false, JSON)?; @@ -245,21 +254,26 @@ impl Project { .run_and_get_stderr() } - fn build_from_workdir_and_get_stderr(&self, target: Option<&str>, working_dir: &Path) -> Result { + fn build_from_workdir_and_get_stderr( + &self, + target: Option<&str>, + working_dir: &Path, + ) -> Result { let mut cmd = xargo()?; // set RUST_TARGET_PATH since target json file not in working dir cmd.env("RUST_TARGET_PATH", &self.td.path()); cmd.arg("build"); - cmd.args(&["--manifest-path", &self.td.path().join("Cargo.toml").to_str().unwrap()]); + cmd.args(&[ + "--manifest-path", + &self.td.path().join("Cargo.toml").to_str().unwrap(), + ]); if let Some(target) = target { cmd.args(&["--target", target]); } - cmd.arg("-v") - .current_dir(working_dir) - .run_and_get_stderr() + cmd.arg("-v").current_dir(working_dir).run_and_get_stderr() } /// Appends a string to the project `Cargo.toml` @@ -283,7 +297,6 @@ impl Project { Ok(()) } - /// Adds a `Xargo.toml` to the project fn xargo_toml(&self, toml: &str) -> Result<()> { write(&self.td.path().join("Xargo.toml"), false, toml) @@ -349,7 +362,10 @@ impl HProject { fn build(&self, verb: &str) -> Result<()> { // Calling "run_and_get_stderr" to be less verbose - xargo()?.arg(verb).current_dir(self.td.path()).run_and_get_stderr()?; + xargo()? + .arg(verb) + .current_dir(self.td.path()) + .run_and_get_stderr()?; Ok(()) } @@ -369,7 +385,11 @@ impl HProject { } /// Runs `xargo-check` with the specified subcommand - fn xargo_check_subcommand(&self, subcommand: Option<&str>, target: Option<&str>) -> Result { + fn xargo_check_subcommand( + &self, + subcommand: Option<&str>, + target: Option<&str>, + ) -> Result { let mut cmd = xargo_check()?; if let Some(subcommand) = subcommand { cmd.arg(subcommand); @@ -377,11 +397,8 @@ impl HProject { if let Some(target) = target { cmd.args(&["--target", target]); } - cmd - .current_dir(self.td.path()) - .run_and_get_stderr() + cmd.current_dir(self.td.path()).run_and_get_stderr() } - } impl Drop for HProject { @@ -422,7 +439,9 @@ fn target_dependencies() { mkdir(stage1_path.as_path())?; create_simple_project(stage1_path.as_path(), STAGE1, "#![no_std]")?; - write(&td.path().join("Xargo.toml"), false, + write( + &td.path().join("Xargo.toml"), + false, r#" [target.thumbv7m-none-eabi.dependencies.alloc] @@ -478,7 +497,8 @@ fn build_outside_project_dir() { "#, )?; // This `workdir` is from where `xargo build` is invoked. It is different from the project dir. - let workdir = TempDir::new("xargo_workdir").chain_err(|| "couldn't create a temporary directory")?; + let workdir = + TempDir::new("xargo_workdir").chain_err(|| "couldn't create a temporary directory")?; project.build_from_workdir(TARGET, &workdir.path())?; @@ -649,7 +669,8 @@ rustflags = ["--cfg", 'xargo="y e s"'] assert!( stderr.contains(r#"'xargo="y e s"'"#), - "unexpected stderr:\n{}", stderr + "unexpected stderr:\n{}", + stderr ); Ok(()) @@ -676,12 +697,10 @@ panic = "abort" let stderr = project.build_and_get_stderr(Some(TARGET))?; - assert!( - stderr - .lines() - .filter(|l| !l.starts_with("+") && l.contains("--release")) - .all(|l| l.contains("-C") && l.contains("panic=abort")) - ); + assert!(stderr + .lines() + .filter(|l| !l.starts_with("+") && l.contains("--release")) + .all(|l| l.contains("-C") && l.contains("panic=abort"))); Ok(()) } @@ -745,7 +764,10 @@ fn specification_changed() { assert!(sysroot_was_built(&stderr, TARGET)); write( - &project.td.path().join("thumbv6m-specification_changed-eabi.json"), + &project + .td + .path() + .join("thumbv6m-specification_changed-eabi.json"), false, JSON, )?; @@ -787,7 +809,10 @@ fn unchanged_specification() { assert!(sysroot_was_built(&stderr, TARGET)); write( - &project.td.path().join("thumbv6m-unchanged_specification-eabi.json"), + &project + .td + .path() + .join("thumbv6m-unchanged_specification-eabi.json"), false, JSON, )?; @@ -903,19 +928,20 @@ tag = "1.0.47" )?; let stderr = project.build_and_get_stderr()?; - assert!(stderr - .lines() - .any(|line| line.contains("Compiling cc ") + assert!( + stderr.lines().any(|line| line.contains("Compiling cc ") && line.contains("https://github.com/alexcrichton/cc-rs")), - "Looks like patching did not work. stderr:\n{}", stderr + "Looks like patching did not work. stderr:\n{}", + stderr ); Ok(()) } // Only run this on pinned nightlies, to avoid having to update the version number all the time. - let is_pinned = std::env::var("TRAVIS_RUST_VERSION").ok().map_or(false, - |var| var.starts_with("nightly-")); + let is_pinned = std::env::var("TRAVIS_RUST_VERSION") + .ok() + .map_or(false, |var| var.starts_with("nightly-")); if is_pinned { run!() } @@ -948,7 +974,11 @@ fn cargo_check_check_no_ctoml() { // windows-gnu specifically needs some extra files to be copied for full builds; // make sure check-builds work without those files. let stderr = project.xargo_check_subcommand(None, Some(TARGET))?; - assert!(stderr.contains("Checking core"), "Looks like checking did not work. stderr:\n{}", stderr); + assert!( + stderr.contains("Checking core"), + "Looks like checking did not work. stderr:\n{}", + stderr + ); Ok(()) }