diff --git a/Cargo.lock b/Cargo.lock index 96f58ff9ed0..6bc9a63f136 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,26 +4,27 @@ version = "0.1.0" dependencies = [ "advapi32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "docopt 0.6.56 (registry+https://github.com/rust-lang/crates.io-index)", + "docopt 0.6.57 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "git2-curl 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "glob 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "flate2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "git2-curl 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "glob 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git)", "kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", "registry 0.1.0", - "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", - "tar 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tempdir 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "tar 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "threadpool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -60,17 +61,17 @@ dependencies = [ "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "docopt" -version = "0.6.56" +version = "0.6.57" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -84,7 +85,7 @@ dependencies = [ [[package]] name = "flate2" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -93,40 +94,40 @@ dependencies = [ [[package]] name = "gcc" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "git2" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "git2-curl" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "curl 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "git2 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.28 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "glob" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hamcrest" version = "0.1.0" -source = "git+https://github.com/carllerche/hamcrest-rust.git#80e7a1cbd6db9ec20bb1d61920e55a1af91a9eb2" +source = "git+https://github.com/carllerche/hamcrest-rust.git#0a87716b6fe9a3feb4afc829923e0121285b8c50" [[package]] name = "kernel32-sys" @@ -143,14 +144,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libgit2-sys" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "libssh2-sys 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "libssh2-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -163,13 +164,13 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -177,7 +178,7 @@ name = "libz-sys" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -198,7 +199,16 @@ name = "miniz-sys" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num_cpus" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -207,15 +217,15 @@ name = "openssl-sys" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "libressl-pnacl-sys 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "pkg-config" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -225,7 +235,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.3.3" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -242,12 +252,12 @@ name = "registry" version = "0.1.0" dependencies = [ "curl 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-serialize" -version = "0.3.10" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -257,20 +267,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "tar" -version = "0.2.7" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "tempdir" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "term" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -284,19 +294,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "time" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "gcc 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "gcc 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "toml" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -305,7 +315,7 @@ version = "0.2.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6f8cac34256..070a1623d84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ regex = "0.1.18" threadpool = "0.1.1" libc = "0.1.2" registry = { path = "src/registry" } +num_cpus = "0.1" [target.i686-pc-windows-gnu] dependencies = { winapi = "0.1", advapi32-sys = "0.1", kernel32-sys = "0.1" } diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 83ad3087f6f..a0490a96dcc 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -1,4 +1,4 @@ -#![feature(core, exit_status, fs_ext)] +#![cfg_attr(unix, feature(fs_ext))] extern crate cargo; extern crate env_logger; @@ -153,18 +153,18 @@ fn execute(flags: Flags, config: &Config) -> CliResult> { } fn find_closest(cmd: &str) -> Option { - match list_commands().iter() - // doing it this way (instead of just .min_by(|c| - // c.lev_distance(cmd))) allows us to only make - // suggestions that have an edit distance of - // 3 or less - .map(|c| (lev_distance(&c, cmd), c)) - .filter(|&(d, _): &(usize, &String)| d < 4) - .min_by(|&(d, _)| d) { - Some((_, c)) => { - Some(c.to_string()) - }, - None => None + let cmds = list_commands(); + // Only consider candidates with a lev_distance of 3 or less so we don't + // suggest out-of-the-blue options. + let mut filtered = cmds.iter().map(|c| (lev_distance(&c, cmd), c)) + .filter(|&(d, _)| d < 4) + .collect::>(); + filtered.sort_by(|a, b| a.0.cmp(&b.0)); + + if filtered.len() == 0 { + None + } else { + Some(filtered[0].1.to_string()) } } @@ -245,7 +245,7 @@ fn is_executable(path: &Path) -> bool { } #[cfg(windows)] fn is_executable(path: &Path) -> bool { - fs::metadata(path).map(|m| m.is_file()) == Ok(true) + fs::metadata(path).map(|m| m.is_file()).unwrap_or(false) } /// Get `Command` to run given command. diff --git a/src/bin/read_manifest.rs b/src/bin/read_manifest.rs index d72f2a8cba3..bd8f9e36658 100644 --- a/src/bin/read_manifest.rs +++ b/src/bin/read_manifest.rs @@ -1,4 +1,5 @@ use std::path::Path; +use std::error::Error; use cargo::core::{Package, Source}; use cargo::util::{CliResult, CliError, Config}; diff --git a/src/bin/verify_project.rs b/src/bin/verify_project.rs index dcef2c4798d..076cfc2db6a 100644 --- a/src/bin/verify_project.rs +++ b/src/bin/verify_project.rs @@ -1,10 +1,11 @@ use std::collections::HashMap; -use std::env; use std::fs::File; use std::io::prelude::*; +use std::process; -use toml; use cargo::util::{CliResult, Config}; +use rustc_serialize::json; +use toml; pub type Error = HashMap; @@ -32,10 +33,10 @@ pub fn execute(args: Flags, config: &Config) -> CliResult> { let file = File::open(&args.flag_manifest_path); match file.and_then(|mut f| f.read_to_string(&mut contents)) { Ok(_) => {}, - Err(e) => return fail("invalid", &format!("error reading file: {}", e)) + Err(e) => fail("invalid", &format!("error reading file: {}", e)) }; match toml::Parser::new(&contents).parse() { - None => return fail("invalid", "invalid-format"), + None => fail("invalid", "invalid-format"), Some(..) => {} }; @@ -44,9 +45,9 @@ pub fn execute(args: Flags, config: &Config) -> CliResult> { Ok(Some(h)) } -fn fail(reason: &str, value: &str) -> CliResult>{ +fn fail(reason: &str, value: &str) -> ! { let mut h = HashMap::new(); h.insert(reason.to_string(), value.to_string()); - env::set_exit_status(1); - Ok(Some(h)) + println!("{}", json::encode(&h).unwrap()); + process::exit(1) } diff --git a/src/cargo/core/package_id.rs b/src/cargo/core/package_id.rs index 336ee96ecef..992e06b9e40 100644 --- a/src/cargo/core/package_id.rs +++ b/src/cargo/core/package_id.rs @@ -1,5 +1,5 @@ use std::cmp::Ordering; -use std::error::{Error, FromError}; +use std::error::Error; use std::fmt::{self, Formatter}; use std::hash::Hash; use std::hash; @@ -108,8 +108,8 @@ impl CargoError for PackageIdError { fn is_human(&self) -> bool { true } } -impl FromError for Box { - fn from_error(t: PackageIdError) -> Box { Box::new(t) } +impl From for Box { + fn from(t: PackageIdError) -> Box { Box::new(t) } } #[derive(PartialEq, Eq, Hash, Clone, RustcEncodable, Debug)] diff --git a/src/cargo/core/package_id_spec.rs b/src/cargo/core/package_id_spec.rs index e65c599805e..d69a461bc71 100644 --- a/src/cargo/core/package_id_spec.rs +++ b/src/cargo/core/package_id_spec.rs @@ -26,7 +26,7 @@ impl PackageIdSpec { } } } - let mut parts = spec.splitn(1, ':'); + let mut parts = spec.splitn(2, ':'); let name = parts.next().unwrap(); let version = match parts.next() { Some(version) => Some(try!(Version::parse(version).map_err(human))), @@ -69,7 +69,7 @@ impl PackageIdSpec { })); match frag { Some(fragment) => { - let mut parts = fragment.splitn(1, ':'); + let mut parts = fragment.splitn(2, ':'); let name_or_version = parts.next().unwrap(); match parts.next() { Some(part) => { diff --git a/src/cargo/core/resolver/mod.rs b/src/cargo/core/resolver/mod.rs index 8c2f7b8f6d4..a33614dc108 100644 --- a/src/cargo/core/resolver/mod.rs +++ b/src/cargo/core/resolver/mod.rs @@ -541,7 +541,7 @@ fn build_features(s: &Summary, method: Method) // form `foo` and we need to recurse to enable the feature `foo` for our // own package, which may end up enabling more features or just enabling // a dependency. - let mut parts = feat.splitn(1, '/'); + let mut parts = feat.splitn(2, '/'); let feat_or_package = parts.next().unwrap(); match parts.next() { Some(feat) => { diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index f186e342e5d..8a89c55466d 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -99,7 +99,7 @@ impl SourceId { /// 656c58fb7c5ef5f12bc747f".to_string()); /// ``` pub fn from_url(string: String) -> SourceId { - let mut parts = string.splitn(1, '+'); + let mut parts = string.splitn(2, '+'); let kind = parts.next().unwrap(); let url = parts.next().unwrap(); diff --git a/src/cargo/core/summary.rs b/src/cargo/core/summary.rs index 53513855270..81445d2a3cb 100644 --- a/src/cargo/core/summary.rs +++ b/src/cargo/core/summary.rs @@ -34,7 +34,7 @@ impl Summary { } for (feature, list) in features.iter() { for dep in list.iter() { - let mut parts = dep.splitn(1, '/'); + let mut parts = dep.splitn(2, '/'); let dep = parts.next().unwrap(); let is_reexport = parts.next().is_some(); if !is_reexport && features.get(dep).is_some() { continue } diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 8cf9d8ab470..3738e97fe3c 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -1,18 +1,19 @@ #![deny(unused)] -#![feature(os, std_misc, core, path_relative_from, collections)] -#![feature(io, str_words, exit_status, fs_time, convert)] +#![feature(fs_time)] #![cfg_attr(test, deny(warnings))] #[cfg(test)] extern crate hamcrest; #[macro_use] extern crate log; -extern crate rustc_serialize; extern crate curl; extern crate docopt; extern crate flate2; extern crate git2; extern crate glob; extern crate libc; +extern crate num_cpus; extern crate regex; +extern crate registry; +extern crate rustc_serialize; extern crate semver; extern crate tar; extern crate term; @@ -21,8 +22,6 @@ extern crate time; extern crate toml; extern crate url; -extern crate registry; - use std::env; use std::error::Error; use std::io::prelude::*; @@ -180,7 +179,7 @@ pub fn handle_error(err: CliError, shell: &mut MultiShell) { with --verbose.".to_string(), BLACK); } - std::env::set_exit_status(exit_code); + std::process::exit(exit_code); } fn handle_cause(mut cargo_err: &CargoError, shell: &mut MultiShell) -> bool { diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 06fac5cc0b1..ea25fc509d7 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -75,7 +75,7 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> { fn rm_rf(path: &Path) -> CargoResult<()> { let m = fs::metadata(path); - if m.as_ref().map(|s| s.is_dir()) == Ok(true) { + if m.as_ref().map(|s| s.is_dir()).unwrap_or(false) { try!(fs::remove_dir_all(path).chain_error(|| { human("could not remove build directory") })); diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index abe31a53a93..12b1e0d8d3c 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -24,7 +24,6 @@ use std::collections::HashMap; use std::default::Default; -use std::num::ToPrimitive; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -332,23 +331,19 @@ fn scrape_build_config(config: &Config, -> CargoResult { let cfg_jobs = match try!(config.get_i64("build.jobs")) { Some((n, p)) => { - match n.to_u32() { - Some(n) => Some(n), - None if n <= 0 => { - return Err(human(format!("build.jobs must be positive, \ - but found {} in {:?}", n, p))); - } - None => { - return Err(human(format!("build.jobs is too large: \ - found {} in {:?}", n, p))); - } + if n <= 0 { + return Err(human(format!("build.jobs must be positive, \ + but found {} in {:?}", n, p))); + } else if n >= u32::max_value() as i64 { + return Err(human(format!("build.jobs is too large: \ + found {} in {:?}", n, p))); + } else { + Some(n as u32) } } None => None, }; - #[allow(deprecated)] - fn num_cpus() -> u32 { ::std::os::num_cpus() as u32 } - let jobs = jobs.or(cfg_jobs).unwrap_or(num_cpus()); + let jobs = jobs.or(cfg_jobs).unwrap_or(::num_cpus::get() as u32); let mut base = ops::BuildConfig { jobs: jobs, requested_target: target.clone(), diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 6b7ef6132cb..0392580a8ca 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -39,7 +39,7 @@ pub fn package(manifest_path: &Path, if list { let root = pkg.root(); let mut list: Vec<_> = try!(src.list_files(&pkg)).iter().map(|file| { - file.relative_from(&root).unwrap().to_path_buf() + util::without_prefix(&file, &root).unwrap().to_path_buf() }).collect(); list.sort(); for file in list.iter() { @@ -123,7 +123,7 @@ fn tar(pkg: &Package, src: &PathSource, config: &Config, let root = pkg.root(); for file in try!(src.list_files(pkg)).iter() { if &**file == dst { continue } - let relative = file.relative_from(&root).unwrap(); + let relative = util::without_prefix(&file, &root).unwrap(); let relative = try!(relative.to_str().chain_error(|| { human(format!("non-utf8 path in source directory: {}", relative.display())) diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 39c7f9edd4a..2ac4e00211d 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -1,5 +1,4 @@ use std::collections::HashSet; -use std::error::FromError; use std::fs::{self, File}; use std::io::prelude::*; use std::io; @@ -77,7 +76,7 @@ pub fn read_packages(path: &Path, source_id: &SourceId, config: &Config) fn walk(path: &Path, callback: &mut F) -> CargoResult<()> where F: FnMut(&Path) -> CargoResult { - if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) { + if !fs::metadata(&path).map(|m| m.is_dir()).unwrap_or(false) { return Ok(()) } @@ -93,7 +92,7 @@ fn walk(path: &Path, callback: &mut F) -> CargoResult<()> Err(ref e) if e.kind() == io::ErrorKind::PermissionDenied => { return Ok(()) } - Err(e) => return Err(FromError::from_error(e)), + Err(e) => return Err(From::from(e)), }; for dir in dirs { let dir = try!(dir).path(); diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index 5f5a3611322..79bd505c5a1 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -1,7 +1,7 @@ use std::path::Path; use ops::{self, ExecEngine, CompileFilter}; -use util::{CargoResult, human, process, ProcessError}; +use util::{self, CargoResult, human, process, ProcessError}; use core::source::Source; use sources::PathSource; @@ -47,7 +47,7 @@ pub fn run(manifest_path: &Path, let compile = try!(ops::compile(manifest_path, options)); let exe = &compile.binaries[0]; - let exe = match exe.relative_from(config.cwd()) { + let exe = match util::without_prefix(&exe, config.cwd()) { Some(path) => path, None => &**exe, }; diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index f5d384ebf07..553fbd13db5 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -1,5 +1,5 @@ use std::collections::{HashMap, HashSet}; -use std::ffi::AsOsStr; +use std::ffi::OsStr; use std::path::PathBuf; use semver::Version; @@ -72,15 +72,15 @@ impl Compilation { } /// See `process`. - pub fn target_process(&self, cmd: &T, pkg: &Package) + pub fn target_process>(&self, cmd: T, pkg: &Package) -> CargoResult { - self.process(CommandType::Target(cmd.as_os_str().to_os_string()), pkg) + self.process(CommandType::Target(cmd.as_ref().to_os_string()), pkg) } /// See `process`. - pub fn host_process(&self, cmd: &T, pkg: &Package) + pub fn host_process>(&self, cmd: T, pkg: &Package) -> CargoResult { - self.process(CommandType::Host(cmd.as_os_str().to_os_string()), pkg) + self.process(CommandType::Host(cmd.as_ref().to_os_string()), pkg) } /// Prepares a new process with an appropriate environment to run against diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index 73e042ba0fa..c64d3e49ec2 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -155,7 +155,7 @@ pub fn prepare(pkg: &Package, target: &Target, req: Platform, // This is also the location where we provide feedback into the build // state informing what variables were discovered via our script as // well. - let output = try!(str::from_utf8(&output.stdout).chain_error(|| { + let output = try!(str::from_utf8(&output.stdout).map_err(|_| { human("build script output was not valid utf-8") })); let parsed_output = try!(BuildOutput::parse(output, &pkg_name)); @@ -256,7 +256,7 @@ impl BuildOutput { let whence = format!("build script of `{}`", pkg_name); for line in input.lines() { - let mut iter = line.splitn(1, |c| c == ':'); + let mut iter = line.splitn(2, ':'); if iter.next() != Some("cargo") { // skip this line since it doesn't start with "cargo:" continue; @@ -267,7 +267,7 @@ impl BuildOutput { }; // getting the `key=value` part of the line - let mut iter = data.splitn(1, |c| c == '='); + let mut iter = data.splitn(2, '='); let key = iter.next(); let value = iter.next(); let (key, value) = match (key, value) { @@ -301,9 +301,9 @@ impl BuildOutput { pub fn parse_rustc_flags(value: &str, whence: &str) -> CargoResult<(Vec, Vec)> { - // TODO: some arguments (like paths) may contain spaces let value = value.trim(); - let mut flags_iter = value.words(); + let mut flags_iter = value.split(|c: char| c.is_whitespace()) + .filter(|w| w.chars().any(|c| !c.is_whitespace())); let (mut library_links, mut library_paths) = (Vec::new(), Vec::new()); loop { let flag = match flags_iter.next() { diff --git a/src/cargo/ops/cargo_rustc/engine.rs b/src/cargo/ops/cargo_rustc/engine.rs index 124a56dce36..b9c1ca1f1e0 100644 --- a/src/cargo/ops/cargo_rustc/engine.rs +++ b/src/cargo/ops/cargo_rustc/engine.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::ffi::{AsOsStr, OsString}; +use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::Path; use std::process::Output; @@ -49,23 +49,23 @@ impl CommandPrototype { pub fn get_type(&self) -> &CommandType { &self.ty } - pub fn arg(&mut self, arg: &T) -> &mut CommandPrototype { + pub fn arg>(&mut self, arg: T) -> &mut CommandPrototype { self.builder.arg(arg); self } - pub fn args(&mut self, arguments: &[T]) -> &mut CommandPrototype { + pub fn args>(&mut self, arguments: &[T]) -> &mut CommandPrototype { self.builder.args(arguments); self } - pub fn cwd(&mut self, path: &T) -> &mut CommandPrototype { + pub fn cwd>(&mut self, path: T) -> &mut CommandPrototype { self.builder.cwd(path); self } - pub fn env(&mut self, key: &str, val: &T) - -> &mut CommandPrototype { + pub fn env>(&mut self, key: &str, val: T) + -> &mut CommandPrototype { self.builder.env(key, val); self } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 0415a9c7c3e..46cef33b97a 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -600,7 +600,9 @@ fn root_path(cx: &Context, pkg: &Package, target: &Target) -> PathBuf { let absolute = pkg.root().join(target.src_path()); let cwd = cx.config.cwd(); if absolute.starts_with(cwd) { - absolute.relative_from(cwd).map(|s| s.to_path_buf()).unwrap_or(absolute) + util::without_prefix(&absolute, cwd).map(|s| { + s.to_path_buf() + }).unwrap_or(absolute) } else { absolute } diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index e32807e8d03..a5993284e0d 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -4,7 +4,7 @@ use std::path::Path; use core::Source; use sources::PathSource; use ops::{self, ExecEngine, ProcessEngine, Compilation}; -use util::{CargoResult, ProcessError}; +use util::{self, CargoResult, ProcessError}; pub struct TestOptions<'a, 'b: 'a> { pub compile_opts: ops::CompileOptions<'a, 'b>, @@ -91,7 +91,7 @@ fn build_and_run(manifest_path: &Path, let cwd = config.cwd(); for &(_, ref exe) in &compile.tests { - let to_display = match exe.relative_from(&cwd) { + let to_display = match util::without_prefix(exe, &cwd) { Some(path) => path, None => &**exe, }; diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 49c7504162d..3e2ea0f0892 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -9,7 +9,7 @@ use git2; use core::{Package, PackageId, Summary, SourceId, Source, Dependency, Registry}; use ops; -use util::{CargoResult, internal, internal_error, human, ChainError, Config}; +use util::{self, CargoResult, internal, internal_error, human, ChainError, Config}; pub struct PathSource<'a, 'b: 'a> { id: SourceId, @@ -99,7 +99,7 @@ impl<'a, 'b> PathSource<'a, 'b> { .map(|p| parse(p)).collect::, _>>()); let mut filter = |p: &Path| { - let relative_path = p.relative_from(&root).unwrap(); + let relative_path = util::without_prefix(p, &root).unwrap(); include.iter().any(|p| p.matches_path(&relative_path)) || { include.len() == 0 && !exclude.iter().any(|p| p.matches_path(&relative_path)) @@ -163,9 +163,9 @@ impl<'a, 'b> PathSource<'a, 'b> { // TODO: the `entry` has a mode we should be able to look at instead // of just calling stat() again - if fs::metadata(&file_path).map(|m| m.is_dir()) == Ok(true) { + if fs::metadata(&file_path).map(|m| m.is_dir()).unwrap_or(false) { warn!(" found submodule {}", file_path.display()); - let rel = file_path.relative_from(&root).unwrap(); + let rel = util::without_prefix(&file_path, &root).unwrap(); let rel = try!(rel.to_str().chain_error(|| { human(format!("invalid utf-8 filename: {}", rel.display())) })); @@ -219,7 +219,7 @@ impl<'a, 'b> PathSource<'a, 'b> { is_root: bool, filter: &mut F) -> CargoResult<()> where F: FnMut(&Path) -> bool { - if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) { + if !fs::metadata(&path).map(|m| m.is_dir()).unwrap_or(false) { if (*filter)(path) { ret.push(path.to_path_buf()); } diff --git a/src/cargo/util/errors.rs b/src/cargo/util/errors.rs index 75bbcf10edf..4c24b34c59b 100644 --- a/src/cargo/util/errors.rs +++ b/src/cargo/util/errors.rs @@ -1,4 +1,4 @@ -use std::error::{FromError, Error}; +use std::error::Error; use std::ffi; use std::fmt; use std::io; @@ -233,8 +233,8 @@ impl CliError { } } -impl FromError> for CliError { - fn from_error(err: Box) -> CliError { +impl From> for CliError { + fn from(err: Box) -> CliError { CliError::from_boxed(err, 101) } } @@ -244,8 +244,8 @@ impl FromError> for CliError { macro_rules! from_error { ($($p:ty,)*) => ( - $(impl FromError<$p> for Box { - fn from_error(t: $p) -> Box { Box::new(t) } + $(impl From<$p> for Box { + fn from(t: $p) -> Box { Box::new(t) } })* ) } @@ -264,8 +264,8 @@ from_error! { ffi::NulError, } -impl FromError> for Box { - fn from_error(t: Human) -> Box { Box::new(t) } +impl From> for Box { + fn from(t: Human) -> Box { Box::new(t) } } impl CargoError for semver::ReqParseError {} @@ -278,7 +278,6 @@ impl CargoError for CliError {} impl CargoError for toml::Error {} impl CargoError for toml::DecodeError {} impl CargoError for url::ParseError {} -impl CargoError for str::Utf8Error {} impl CargoError for ffi::NulError {} // ============================================================================= diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index 8ce77ea6843..095884d776d 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -5,7 +5,7 @@ pub use self::errors::{CliError, ProcessError}; pub use self::errors::{process_error, internal_error, internal, human}; pub use self::errors::{Human, caused_human}; pub use self::paths::{join_paths, path2bytes, bytes2path, dylib_path}; -pub use self::paths::{normalize_path, dylib_path_envvar}; +pub use self::paths::{normalize_path, dylib_path_envvar, without_prefix}; pub use self::lev_distance::{lev_distance}; pub use self::hex::{to_hex, short_hash}; pub use self::dependency_queue::{DependencyQueue, Fresh, Dirty, Freshness}; diff --git a/src/cargo/util/paths.rs b/src/cargo/util/paths.rs index c7c749deec1..a758b58c9c6 100644 --- a/src/cargo/util/paths.rs +++ b/src/cargo/util/paths.rs @@ -1,14 +1,12 @@ use std::env; -use std::ffi::{AsOsStr, OsString}; +use std::ffi::{OsStr, OsString}; use std::path::{Path, PathBuf, Component}; use util::{human, internal, CargoResult, ChainError}; -pub fn join_paths(paths: &[T], env: &str) -> CargoResult { +pub fn join_paths>(paths: &[T], env: &str) -> CargoResult { env::join_paths(paths.iter()).or_else(|e| { - let paths = paths.iter().map(|p| { - Path::new(p.as_os_str()) - }).collect::>(); + let paths = paths.iter().map(Path::new).collect::>(); internal(format!("failed to join path array: {:?}", paths)).chain_error(|| { human(format!("failed to join search paths together: {}\n\ Does ${} have an unterminated quote character?", @@ -52,6 +50,21 @@ pub fn normalize_path(path: &Path) -> PathBuf { return ret; } +pub fn without_prefix<'a>(a: &'a Path, b: &'a Path) -> Option<&'a Path> { + let mut a = a.components(); + let mut b = b.components(); + loop { + let mut a2 = a.clone(); + match (a2.next(), b.next()) { + (Some(x), Some(y)) if x == y => a = a2, + (Some(_), Some(_)) | + (None, Some(_)) => return None, + (Some(_), None) | + (None, None) => return Some(a.as_path()), + } + } +} + #[cfg(unix)] pub fn path2bytes(path: &Path) -> CargoResult<&[u8]> { use std::os::unix::prelude::*; diff --git a/src/cargo/util/process_builder.rs b/src/cargo/util/process_builder.rs index 025ebcb303a..81d3b92c3eb 100644 --- a/src/cargo/util/process_builder.rs +++ b/src/cargo/util/process_builder.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use std::env; -use std::ffi::{OsString, AsOsStr}; +use std::ffi::{OsString, OsStr}; use std::fmt; use std::path::Path; use std::process::{Command, Output}; @@ -28,26 +28,26 @@ impl fmt::Display for ProcessBuilder { } impl ProcessBuilder { - pub fn arg(&mut self, arg: &T) -> &mut ProcessBuilder { - self.args.push(arg.as_os_str().to_os_string()); + pub fn arg>(&mut self, arg: T) -> &mut ProcessBuilder { + self.args.push(arg.as_ref().to_os_string()); self } - pub fn args(&mut self, arguments: &[T]) -> &mut ProcessBuilder { + pub fn args>(&mut self, arguments: &[T]) -> &mut ProcessBuilder { self.args.extend(arguments.iter().map(|t| { - t.as_os_str().to_os_string() + t.as_ref().to_os_string() })); self } - pub fn cwd(&mut self, path: &T) -> &mut ProcessBuilder { - self.cwd = path.as_os_str().to_os_string(); + pub fn cwd>(&mut self, path: T) -> &mut ProcessBuilder { + self.cwd = path.as_ref().to_os_string(); self } - pub fn env(&mut self, key: &str, - val: &T) -> &mut ProcessBuilder { - self.env.insert(key.to_string(), Some(val.as_os_str().to_os_string())); + pub fn env>(&mut self, key: &str, + val: T) -> &mut ProcessBuilder { + self.env.insert(key.to_string(), Some(val.as_ref().to_os_string())); self } @@ -128,9 +128,9 @@ impl ProcessBuilder { } } -pub fn process(cmd: &T) -> CargoResult { +pub fn process>(cmd: T) -> CargoResult { Ok(ProcessBuilder { - program: cmd.as_os_str().to_os_string(), + program: cmd.as_ref().to_os_string(), args: Vec::new(), cwd: try!(env::current_dir()).as_os_str().to_os_string(), env: HashMap::new(), diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index d41d87a15d7..e653ab0fcb0 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -3,7 +3,6 @@ use std::default::Default; use std::fmt; use std::fs; use std::path::{Path, PathBuf}; -use std::slice; use std::str; use toml; @@ -15,7 +14,7 @@ use core::{Summary, Manifest, Target, Dependency, PackageId, GitReference}; use core::dependency::Kind; use core::manifest::{LibKind, Profile, ManifestMetadata}; use core::package_id::Metadata; -use util::{CargoResult, human, ToUrl, ToSemver, ChainError, Config}; +use util::{self, CargoResult, human, ToUrl, ToSemver, ChainError, Config}; /// Representation of the projects file layout. /// @@ -99,11 +98,11 @@ pub fn to_manifest(contents: &[u8], config: &Config) -> CargoResult<(Manifest, Vec)> { let manifest = layout.root.join("Cargo.toml"); - let manifest = match manifest.relative_from(config.cwd()) { + let manifest = match util::without_prefix(&manifest, config.cwd()) { Some(path) => path.to_path_buf(), None => manifest.clone(), }; - let contents = try!(str::from_utf8(contents).chain_error(|| { + let contents = try!(str::from_utf8(contents).map_err(|_| { human(format!("{} is not valid UTF-8", manifest.display())) })); let root = try!(parse(contents, &manifest)); @@ -204,7 +203,7 @@ pub struct TomlManifest { package: Option>, project: Option>, profile: Option, - lib: Option>, + lib: Option, bin: Option>, example: Option>, test: Option>, @@ -235,21 +234,6 @@ pub struct TomlProfile { rpath: Option, } -#[derive(RustcDecodable)] -pub enum ManyOrOne { - Many(Vec), - One(T), -} - -impl ManyOrOne { - fn as_slice(&self) -> &[T] { - match *self { - ManyOrOne::Many(ref v) => v, - ManyOrOne::One(ref t) => slice::ref_slice(t), - } - } -} - #[derive(RustcDecodable)] pub struct TomlProject { name: String, @@ -305,14 +289,14 @@ struct Context<'a, 'b, 'c: 'b> { // otherwise acceptable executable names are not used when inside of // `src/bin/*`, but it seems ok to not build executables with non-UTF8 // paths. -fn inferred_lib_target(name: &str, layout: &Layout) -> Vec { +fn inferred_lib_target(name: &str, layout: &Layout) -> Option { layout.lib.as_ref().map(|lib| { - vec![TomlTarget { + TomlTarget { name: name.to_string(), path: Some(PathValue::Path(lib.clone())), .. TomlTarget::new() - }] - }).unwrap_or(Vec::new()) + } + }) } fn inferred_bin_targets(name: &str, layout: &Layout) -> Vec { @@ -388,24 +372,17 @@ impl TomlManifest { // If we have a lib with a path, we're done // If we have a lib with no path, use the inferred lib or_else package name - let mut used_deprecated_lib = false; let lib = match self.lib { - Some(ref libs) => { - match *libs { - ManyOrOne::Many(..) => used_deprecated_lib = true, - _ => {} - } - try!(libs.as_slice().iter().map(|t| { - try!(validate_library_name(t)); - Ok(if layout.lib.is_some() && t.path.is_none() { - TomlTarget { - path: layout.lib.as_ref().map(|p| PathValue::Path(p.clone())), - .. t.clone() - } - } else { - t.clone() - }) - }).collect::>>()) + Some(ref lib) => { + try!(validate_library_name(lib)); + Some(if layout.lib.is_some() && lib.path.is_none() { + TomlTarget { + path: layout.lib.as_ref().map(|p| PathValue::Path(p.clone())), + .. lib.clone() + } + } else { + lib.clone() + }) } None => inferred_lib_target(&project.name, layout), }; @@ -519,10 +496,6 @@ impl TomlManifest { project.links.clone(), metadata, profiles); - if used_deprecated_lib { - manifest.add_warning(format!("the [[lib]] section has been \ - deprecated in favor of [lib]")); - } if project.license_file.is_some() && project.license.is_some() { manifest.add_warning(format!("warning: only one of `license` or \ `license-file` is necessary")); @@ -652,7 +625,7 @@ impl fmt::Debug for PathValue { } } -fn normalize(libs: &[TomlLibTarget], +fn normalize(lib: &Option, bins: &[TomlBinTarget], custom_build: Option, examples: &[TomlExampleTarget], @@ -669,9 +642,8 @@ fn normalize(libs: &[TomlLibTarget], .set_for_host(toml.plugin.unwrap_or(t2.for_host())); } - fn lib_targets(dst: &mut Vec, libs: &[TomlLibTarget], - metadata: &Metadata) { - let l = &libs[0]; + fn lib_target(dst: &mut Vec, l: &TomlLibTarget, + metadata: &Metadata) { let path = l.path.clone().unwrap_or_else(|| { PathValue::Path(Path::new("src").join(&format!("{}.rs", l.name))) }); @@ -764,14 +736,12 @@ fn normalize(libs: &[TomlLibTarget], let mut ret = Vec::new(); - if libs.len() > 0 && bins.len() > 0 { - lib_targets(&mut ret, libs, metadata); + if let Some(ref lib) = *lib { + lib_target(&mut ret, lib, metadata); bin_targets(&mut ret, bins, &mut |bin| Path::new("src").join("bin") .join(&format!("{}.rs", bin.name))); - } else if libs.len() > 0 && bins.len() == 0 { - lib_targets(&mut ret, libs, metadata); - } else if libs.len() == 0 && bins.len() > 0 { + } else if bins.len() > 0 { bin_targets(&mut ret, bins, &mut |bin| Path::new("src") .join(&format!("{}.rs", bin.name))); diff --git a/src/rustversion.txt b/src/rustversion.txt index 09053248bb5..22e8ceff87b 100644 --- a/src/rustversion.txt +++ b/src/rustversion.txt @@ -1 +1 @@ -2015-03-30 +2015-04-02 diff --git a/tests/support/mod.rs b/tests/support/mod.rs index a8f535c6cdf..cda18976c7e 100644 --- a/tests/support/mod.rs +++ b/tests/support/mod.rs @@ -1,6 +1,6 @@ use std::env; use std::error::Error; -use std::ffi::AsOsStr; +use std::ffi::OsStr; use std::fmt; use std::fs; use std::io::prelude::*; @@ -121,7 +121,7 @@ impl ProjectBuilder { self.root.join("target") } - pub fn process(&self, program: &T) -> ProcessBuilder { + pub fn process>(&self, program: T) -> ProcessBuilder { let mut p = process(program).unwrap(); p.cwd(&self.root()).env("HOME", &paths::home()); return p; diff --git a/tests/test_cargo_bench.rs b/tests/test_cargo_bench.rs index de82969ab1c..2d643fbf203 100644 --- a/tests/test_cargo_bench.rs +++ b/tests/test_cargo_bench.rs @@ -179,7 +179,7 @@ test bench_hello ... ", COMPILING, p.url(), RUNNING)) .with_stderr("\ thread '
' panicked at 'assertion failed: \ - `(left == right) && (right == left)` (left: \ + `(left == right)` (left: \ `\"hello\"`, right: `\"nope\"`)', src[..]foo.rs:14 ") diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 1efe9160531..3faea78b519 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -1,6 +1,7 @@ use std::env; use std::fs::{self, File}; use std::io::prelude::*; +use std::thread; use tempdir::TempDir; use support::{project, execs, main_file, basic_bin_manifest}; @@ -1186,21 +1187,6 @@ test!(staticlib_rlib_and_bin { assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0)); }); -test!(opt_out_of_lib { - let p = project("foo") - .file("Cargo.toml", r#" - lib = [] - - [package] - name = "foo" - authors = [] - version = "0.0.1" - "#) - .file("src/lib.rs", "bad syntax") - .file("src/main.rs", "fn main() {}"); - assert_that(p.cargo_process("build"), execs().with_status(0)); -}); - test!(opt_out_of_bin { let p = project("foo") .file("Cargo.toml", r#" @@ -1232,24 +1218,6 @@ test!(single_lib { assert_that(p.cargo_process("build"), execs().with_status(0)); }); -test!(deprecated_lib { - let p = project("foo") - .file("Cargo.toml", r#" - [package] - name = "foo" - authors = [] - version = "0.0.1" - - [[lib]] - name = "foo" - "#) - .file("src/foo.rs", ""); - assert_that(p.cargo_process("build"), - execs().with_status(0) - .with_stderr("\ -the [[lib]] section has been deprecated in favor of [lib]\n")); -}); - test!(freshness_ignores_excluded { let foo = project("foo") .file("Cargo.toml", r#" @@ -1572,8 +1540,7 @@ test!(compile_then_delete { assert_that(&p.bin("foo"), existing_file()); if cfg!(windows) { // On windows unlinking immediately after running often fails, so sleep - use std::time::duration::Duration; - ::sleep(Duration::milliseconds(100)); + thread::sleep_ms(100); } fs::remove_file(&p.bin("foo")).unwrap(); assert_that(p.cargo("run"), diff --git a/tests/test_cargo_compile_custom_build.rs b/tests/test_cargo_compile_custom_build.rs index dd7b6cee68f..ee438e03cd3 100644 --- a/tests/test_cargo_compile_custom_build.rs +++ b/tests/test_cargo_compile_custom_build.rs @@ -99,7 +99,7 @@ test!(custom_build_env_vars { let out = env::var("OUT_DIR").unwrap(); assert!(out.starts_with(r"{0}")); - assert_eq!(fs::metadata(&out).map(|m| m.is_dir()), Ok(true)); + assert!(fs::metadata(&out).map(|m| m.is_dir()).unwrap_or(false)); let _host = env::var("HOST").unwrap(); diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 4ea280cf3a8..2382e473273 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -1,7 +1,7 @@ use std::fs::{self, File}; use std::io::prelude::*; use std::path::Path; -use std::time::Duration; +use std::thread; use git2; use support::{ProjectBuilder, project, execs, main_file, path2url}; @@ -698,7 +698,7 @@ test!(update_with_shared_deps { add(&repo); commit(&repo); - ::sleep(Duration::milliseconds(1000)); + thread::sleep_ms(1000); // By default, not transitive updates println!("dep1 update"); @@ -890,7 +890,7 @@ test!(stale_cached_version { add(&repo); commit(&repo); - ::sleep(Duration::milliseconds(1000)); + thread::sleep_ms(1000); let rev = repo.revparse_single("HEAD").unwrap().id(); @@ -996,7 +996,7 @@ test!(dep_with_changed_submodule { add(&repo); commit(&repo); - ::sleep(Duration::milliseconds(1000)); + thread::sleep_ms(1000); // Update the dependency and carry on! println!("update"); assert_that(project.cargo("update").arg("-v"), @@ -1094,7 +1094,7 @@ test!(git_build_cmd_freshness { }).unwrap(); foo.root().move_into_the_past().unwrap(); - ::sleep(Duration::milliseconds(1000)); + thread::sleep_ms(1000); assert_that(foo.cargo("build"), execs().with_status(0) diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index c5288943067..608a1b3a34c 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -1,6 +1,6 @@ use std::fs::{self, File}; use std::io::prelude::*; -use std::time::Duration; +use std::thread; use support::{project, execs, main_file}; use support::{COMPILING, RUNNING}; @@ -352,7 +352,7 @@ test!(deep_dependencies_trigger_rebuild { // // We base recompilation off mtime, so sleep for at least a second to ensure // that this write will change the mtime. - ::sleep(Duration::seconds(1)); + thread::sleep_ms(1000); File::create(&p.root().join("baz/src/baz.rs")).unwrap().write_all(br#" pub fn baz() { println!("hello!"); } "#).unwrap(); @@ -365,7 +365,7 @@ test!(deep_dependencies_trigger_rebuild { COMPILING, p.url()))); // Make sure an update to bar doesn't trigger baz - ::sleep(Duration::seconds(1)); + thread::sleep_ms(1000); File::create(&p.root().join("bar/src/bar.rs")).unwrap().write_all(br#" extern crate baz; pub fn bar() { println!("hello!"); baz::baz(); } diff --git a/tests/test_cargo_publish.rs b/tests/test_cargo_publish.rs index c83b1406676..ada46bbc5f6 100644 --- a/tests/test_cargo_publish.rs +++ b/tests/test_cargo_publish.rs @@ -64,7 +64,7 @@ test!(simple { let mut f = File::open(&upload_path().join("api/v1/crates/new")).unwrap(); // Skip the metadata payload and the size of the tarball let mut sz = [0; 4]; - assert_eq!(f.read(&mut sz), Ok(4)); + assert_eq!(f.read(&mut sz).unwrap(), 4); let sz = ((sz[0] as u32) << 0) | ((sz[1] as u32) << 8) | ((sz[2] as u32) << 16) | diff --git a/tests/test_cargo_test.rs b/tests/test_cargo_test.rs index 6cf457aee0a..6c08c73aea7 100644 --- a/tests/test_cargo_test.rs +++ b/tests/test_cargo_test.rs @@ -133,7 +133,7 @@ failures: ---- test_hello stdout ---- thread 'test_hello' panicked at 'assertion failed: \ - `(left == right) && (right == left)` (left: \ + `(left == right)` (left: \ `\"hello\"`, right: `\"nope\"`)', src[..]foo.rs:12 @@ -1166,11 +1166,8 @@ test!(example_dev_dep { macro_rules! f6( () => ({(f5!()) + (f5!())}) ); macro_rules! f7( () => ({(f6!()) + (f6!())}) ); macro_rules! f8( () => ({(f7!()) + (f7!())}) ); - macro_rules! f9( () => ({(f8!()) + (f8!())}) ); - macro_rules! f10( () => ({(f9!()) + (f9!())}) ); - macro_rules! f11( () => ({(f10!()) + (f10!())}) ); pub fn bar() { - f11!(); + f8!(); } "#); assert_that(p.cargo_process("test"), diff --git a/tests/tests.rs b/tests/tests.rs index 00d6054e81e..8be26db87c6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,5 +1,4 @@ -#![feature(io, convert, thread_sleep)] -#![feature(std_misc, io, fs, fs_ext, path_ext, fs_time, fs_walk)] +#![feature(fs, fs_ext, path_ext, fs_time, fs_walk)] extern crate rustc_serialize; extern crate cargo; @@ -53,7 +52,3 @@ mod test_cargo_search; mod test_cargo_test; mod test_cargo_version; mod test_shell; - -fn sleep(dur: std::time::Duration) { - std::thread::sleep(dur) -}