From d48cbf6df3a19486bcc7f051d908f871db797cdc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 12 Feb 2018 19:31:48 +0300 Subject: [PATCH 01/17] Cleanup --- src/bin/init.rs | 13 ++++++------- src/bin/new.rs | 6 ++---- src/cargo/ops/cargo_new.rs | 23 +++++++++-------------- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/bin/init.rs b/src/bin/init.rs index 9252ddd39..4c3832e68 100644 --- a/src/bin/init.rs +++ b/src/bin/init.rs @@ -56,17 +56,16 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { let path = &arg_path.unwrap_or_else(|| String::from(".")); let opts = ops::NewOptions::new(flag_vcs, - flag_bin, - flag_lib, - path, - flag_name.as_ref().map(|s| s.as_ref())); + flag_bin, + flag_lib, + path, + flag_name.as_ref().map(|s| s.as_ref())); let opts_lib = opts.lib; ops::init(&opts, config)?; - config.shell().status("Created", format!("{} project", - if opts_lib { "library" } - else {"binary (application)"}))?; + let project_kind = if opts_lib { "library" } else { "binary (application)" }; + config.shell().status("Created", format!("{} project", project_kind))?; Ok(()) } diff --git a/src/bin/new.rs b/src/bin/new.rs index c006fd1e4..1e6342e2f 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -63,10 +63,8 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { let opts_lib = opts.lib; ops::new(&opts, config)?; - config.shell().status("Created", format!("{} `{}` project", - if opts_lib { "library" } - else {"binary (application)"}, - arg_path))?; + let project_kind = if opts_lib { "library" } else { "binary (application)" }; + config.shell().status("Created", format!("{} `{}` project", project_kind, arg_path))?; Ok(()) } diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 83dc8d045..9fbb8f853 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -62,25 +62,20 @@ impl<'de> Deserialize<'de> for VersionControl { impl<'a> NewOptions<'a> { pub fn new(version_control: Option, - bin: bool, - lib: bool, - path: &'a str, - name: Option<&'a str>) -> NewOptions<'a> { + bin: bool, + lib: bool, + path: &'a str, + name: Option<&'a str>) -> NewOptions<'a> { // default to lib - let is_lib = if !bin { - true - } - else { - lib - }; + let is_lib = !bin || lib; NewOptions { - version_control: version_control, - bin: bin, + version_control, + bin, lib: is_lib, - path: path, - name: name, + path, + name, } } } From 9e5721c2b7571fb7188805992226b788ed8043bc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 12 Feb 2018 19:57:31 +0300 Subject: [PATCH 02/17] Refactor `NewOptions` to make it slightly more clear --- src/bin/init.rs | 6 ++-- src/bin/new.rs | 6 ++-- src/cargo/ops/cargo_new.rs | 65 +++++++++++++++++++++++--------------- 3 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/bin/init.rs b/src/bin/init.rs index 4c3832e68..74ae608ac 100644 --- a/src/bin/init.rs +++ b/src/bin/init.rs @@ -59,13 +59,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { flag_bin, flag_lib, path, - flag_name.as_ref().map(|s| s.as_ref())); + flag_name.as_ref().map(|s| s.as_ref()))?; - let opts_lib = opts.lib; ops::init(&opts, config)?; - let project_kind = if opts_lib { "library" } else { "binary (application)" }; - config.shell().status("Created", format!("{} project", project_kind))?; + config.shell().status("Created", format!("{} project", opts.kind))?; Ok(()) } diff --git a/src/bin/new.rs b/src/bin/new.rs index 1e6342e2f..6b51a6180 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -58,13 +58,11 @@ pub fn execute(options: Options, config: &mut Config) -> CliResult { flag_bin, flag_lib, &arg_path, - flag_name.as_ref().map(|s| s.as_ref())); + flag_name.as_ref().map(|s| s.as_ref()))?; - let opts_lib = opts.lib; ops::new(&opts, config)?; - let project_kind = if opts_lib { "library" } else { "binary (application)" }; - config.shell().status("Created", format!("{} `{}` project", project_kind, arg_path))?; + config.shell().status("Created", format!("{} `{}` project", opts.kind, arg_path))?; Ok(()) } diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 9fbb8f853..3cba288be 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -1,6 +1,7 @@ use std::collections::BTreeMap; use std::env; use std::fs; +use std::fmt; use std::path::Path; use serde::{Deserialize, Deserializer}; @@ -23,12 +24,32 @@ pub enum VersionControl { Git, Hg, Pijul, Fossil, NoVcs } #[derive(Debug)] pub struct NewOptions<'a> { pub version_control: Option, - pub bin: bool, - pub lib: bool, + pub kind: NewProjectKind, pub path: &'a str, pub name: Option<&'a str>, } +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum NewProjectKind { + Bin, + Lib, +} + +impl NewProjectKind { + fn is_bin(&self) -> bool { + *self == NewProjectKind::Bin + } +} + +impl fmt::Display for NewProjectKind { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + NewProjectKind::Bin => "binary (application)", + NewProjectKind::Lib => "library", + }.fmt(f) + } +} + struct SourceFileInformation { relative_path: String, target_name: String, @@ -65,18 +86,18 @@ impl<'a> NewOptions<'a> { bin: bool, lib: bool, path: &'a str, - name: Option<&'a str>) -> NewOptions<'a> { + name: Option<&'a str>) -> CargoResult> { - // default to lib - let is_lib = !bin || lib; + let kind = match (bin, lib) { + (true, true) => bail!("can't specify both lib and binary outputs"), + (true, false) => NewProjectKind::Bin, + (false, true) => NewProjectKind::Lib, + // default to lib + (false, false) => NewProjectKind::Lib, + }; - NewOptions { - version_control, - bin, - lib: is_lib, - path, - name, - } + let opts = NewOptions { version_control, kind, path, name }; + Ok(opts) } } @@ -122,7 +143,7 @@ fn check_name(name: &str, opts: &NewOptions) -> CargoResult<()> { "super", "test", "trait", "true", "type", "typeof", "unsafe", "unsized", "use", "virtual", "where", "while", "yield"]; - if blacklist.contains(&name) || (opts.bin && is_bad_artifact_name(name)) { + if blacklist.contains(&name) || (opts.kind.is_bin() && is_bad_artifact_name(name)) { bail!("The name `{}` cannot be used as a crate name{}", name, name_help) @@ -264,10 +285,6 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> { ) } - if opts.lib && opts.bin { - bail!("can't specify both lib and binary outputs") - } - let name = get_name(&path, opts)?; check_name(name, opts)?; @@ -275,8 +292,8 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> { version_control: opts.version_control, path: &path, name: name, - source_files: vec![plan_new_source_file(opts.bin, name.to_string())], - bin: opts.bin, + source_files: vec![plan_new_source_file(opts.kind.is_bin(), name.to_string())], + bin: opts.kind.is_bin(), }; mk(config, &mkopts).chain_err(|| { @@ -294,10 +311,6 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { bail!("`cargo init` cannot be run on existing Cargo projects") } - if opts.lib && opts.bin { - bail!("can't specify both lib and binary outputs"); - } - let name = get_name(&path, opts)?; check_name(name, opts)?; @@ -306,7 +319,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { detect_source_paths_and_types(&path, name, &mut src_paths_types)?; if src_paths_types.is_empty() { - src_paths_types.push(plan_new_source_file(opts.bin, name.to_string())); + src_paths_types.push(plan_new_source_file(opts.kind.is_bin(), name.to_string())); } else { // --bin option may be ignored if lib.rs or src/lib.rs present // Maybe when doing `cargo init --bin` inside a library project stub, @@ -348,9 +361,9 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> { } let mkopts = MkOptions { - version_control: version_control, + version_control, path: &path, - name: name, + name, bin: src_paths_types.iter().any(|x|x.bin), source_files: src_paths_types, }; From ec991ebcb90149281f8601f7a1dd7f621268fd9a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 12 Feb 2018 09:27:11 -0800 Subject: [PATCH 03/17] Don't spin on empty fds in `read2` on Unix This commit fixes what I think is some pathological behavior in Cargo where if one stdio stream is closed before another then Cargo can accidentally spin in a tight loop and not block appropriately. Previously, for example, if stderr closed before stdout then Cargo would spin in a `poll` loop continuously getting notified that stderr is closed. The behavior is now changed so after a file descriptor is done we stop passing it to `poll` and instead only pass the one remaining readable file descriptor. --- src/cargo/util/read2.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cargo/util/read2.rs b/src/cargo/util/read2.rs index 74d6d67f2..7b2681082 100644 --- a/src/cargo/util/read2.rs +++ b/src/cargo/util/read2.rs @@ -27,9 +27,12 @@ mod imp { fds[0].events = libc::POLLIN; fds[1].fd = err_pipe.as_raw_fd(); fds[1].events = libc::POLLIN; - loop { + let mut nfds = 2; + let mut errfd = 1; + + while nfds > 0 { // wait for either pipe to become readable using `select` - let r = unsafe { libc::poll(fds.as_mut_ptr(), 2, -1) }; + let r = unsafe { libc::poll(fds.as_mut_ptr(), nfds, -1) }; if r == -1 { let err = io::Error::last_os_error(); if err.kind() == io::ErrorKind::Interrupted { @@ -55,19 +58,20 @@ mod imp { } } }; - if !out_done && fds[0].revents != 0 && handle(out_pipe.read_to_end(&mut out))? { - out_done = true; - } - data(true, &mut out, out_done); - if !err_done && fds[1].revents != 0 && handle(err_pipe.read_to_end(&mut err))? { + if !err_done && fds[errfd].revents != 0 && handle(err_pipe.read_to_end(&mut err))? { err_done = true; + nfds -= 1; } data(false, &mut err, err_done); - - if out_done && err_done { - return Ok(()) + if !out_done && fds[0].revents != 0 && handle(out_pipe.read_to_end(&mut out))? { + out_done = true; + fds[0].fd = err_pipe.as_raw_fd(); + errfd = 0; + nfds -= 1; } + data(true, &mut out, out_done); } + Ok(()) } } From 7f3e86e069191ab552122fdcf6eaba84843a51e8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 12 Feb 2018 21:33:31 +0300 Subject: [PATCH 04/17] Switch to lazycell from crate.io --- Cargo.toml | 1 + src/cargo/core/package.rs | 3 +- src/cargo/lib.rs | 1 + src/cargo/ops/cargo_rustc/compilation.rs | 6 +- src/cargo/sources/registry/remote.rs | 5 +- src/cargo/util/config.rs | 13 +++-- src/cargo/util/lazy_cell.rs | 74 ------------------------ src/cargo/util/mod.rs | 2 - 8 files changed, 18 insertions(+), 87 deletions(-) delete mode 100644 src/cargo/util/lazy_cell.rs diff --git a/Cargo.toml b/Cargo.toml index 265a0ad15..2cf17e31c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ hex = "0.3" home = "0.3" ignore = "0.3" jobserver = "0.1.9" +lazycell = "0.6" libc = "0.2" libgit2-sys = "0.6" log = "0.4" diff --git a/src/cargo/core/package.rs b/src/cargo/core/package.rs index 72ac61625..e0c54c03a 100644 --- a/src/cargo/core/package.rs +++ b/src/cargo/core/package.rs @@ -7,11 +7,12 @@ use std::path::{Path, PathBuf}; use semver::Version; use serde::ser; use toml; +use lazycell::LazyCell; use core::{Dependency, Manifest, PackageId, SourceId, Target}; use core::{Summary, SourceMap}; use ops; -use util::{Config, LazyCell, internal, lev_distance}; +use util::{Config, internal, lev_distance}; use util::errors::{CargoResult, CargoResultExt}; /// Information about a package that is available somewhere in the file system. diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 6e8d77154..d60792c7a 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -21,6 +21,7 @@ extern crate hex; extern crate home; extern crate ignore; extern crate jobserver; +extern crate lazycell; extern crate libc; extern crate libgit2_sys; extern crate num_cpus; diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index 3fe62f365..88f82516b 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -1,10 +1,12 @@ use std::collections::{HashMap, HashSet, BTreeSet}; use std::ffi::OsStr; use std::path::PathBuf; + use semver::Version; +use lazycell::LazyCell; use core::{PackageId, Package, Target, TargetKind}; -use util::{self, CargoResult, Config, LazyCell, ProcessBuilder, process, join_paths}; +use util::{self, CargoResult, Config, ProcessBuilder, process, join_paths}; /// A structure returning the result of a compilation. pub struct Compilation<'cfg> { @@ -101,7 +103,7 @@ impl<'cfg> Compilation<'cfg> { } fn target_runner(&self) -> CargoResult<&Option<(PathBuf, Vec)>> { - self.target_runner.get_or_try_init(|| { + self.target_runner.try_borrow_with(|| { let key = format!("target.{}.runner", self.target); Ok(self.config.get_path_and_args(&key)?.map(|v| v.val)) }) diff --git a/src/cargo/sources/registry/remote.rs b/src/cargo/sources/registry/remote.rs index 5ffabb9d5..331183e6d 100644 --- a/src/cargo/sources/registry/remote.rs +++ b/src/cargo/sources/registry/remote.rs @@ -9,12 +9,13 @@ use std::str; use git2; use hex; use serde_json; +use lazycell::LazyCell; use core::{PackageId, SourceId}; use sources::git; use sources::registry::{RegistryData, RegistryConfig, INDEX_LOCK, CRATE_TEMPLATE, VERSION_TEMPLATE}; use util::network; -use util::{FileLock, Filesystem, LazyCell}; +use util::{FileLock, Filesystem}; use util::{Config, Sha256, ToUrl, Progress}; use util::errors::{CargoResult, CargoResultExt, HttpNot200}; @@ -43,7 +44,7 @@ impl<'cfg> RemoteRegistry<'cfg> { } fn repo(&self) -> CargoResult<&git2::Repository> { - self.repo.get_or_try_init(|| { + self.repo.try_borrow_with(|| { let path = self.index_path.clone().into_path_unlocked(); // Fast path without a lock diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index bd6bea77c..8d1d75e86 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -16,6 +16,7 @@ use curl::easy::Easy; use jobserver; use serde::{Serialize, Serializer}; use toml; +use lazycell::LazyCell; use core::shell::Verbosity; use core::{Shell, CliUnstable}; @@ -26,7 +27,7 @@ use util::Rustc; use util::errors::{CargoResult, CargoResultExt, CargoError, internal}; use util::paths; use util::toml as cargo_toml; -use util::{Filesystem, LazyCell}; +use util::Filesystem; use self::ConfigValue as CV; @@ -144,18 +145,18 @@ impl Config { /// Get the path to the `rustdoc` executable pub fn rustdoc(&self) -> CargoResult<&Path> { - self.rustdoc.get_or_try_init(|| self.get_tool("rustdoc")).map(AsRef::as_ref) + self.rustdoc.try_borrow_with(|| self.get_tool("rustdoc")).map(AsRef::as_ref) } /// Get the path to the `rustc` executable pub fn rustc(&self) -> CargoResult<&Rustc> { - self.rustc.get_or_try_init(|| Rustc::new(self.get_tool("rustc")?, + self.rustc.try_borrow_with(|| Rustc::new(self.get_tool("rustc")?, self.maybe_get_tool("rustc_wrapper")?)) } /// Get the path to the `cargo` executable pub fn cargo_exe(&self) -> CargoResult<&Path> { - self.cargo_exe.get_or_try_init(|| { + self.cargo_exe.try_borrow_with(|| { fn from_current_exe() -> CargoResult { // Try fetching the path to `cargo` using env::current_exe(). // The method varies per operating system and might fail; in particular, @@ -207,7 +208,7 @@ impl Config { } pub fn values(&self) -> CargoResult<&HashMap> { - self.values.get_or_try_init(|| self.load_values()) + self.values.try_borrow_with(|| self.load_values()) } pub fn set_values(&self, values: HashMap) -> CargoResult<()> { @@ -648,7 +649,7 @@ impl Config { } pub fn http(&self) -> CargoResult<&RefCell> { - let http = self.easy.get_or_try_init(|| { + let http = self.easy.try_borrow_with(|| { ops::http_handle(self).map(RefCell::new) })?; { diff --git a/src/cargo/util/lazy_cell.rs b/src/cargo/util/lazy_cell.rs deleted file mode 100644 index a55254175..000000000 --- a/src/cargo/util/lazy_cell.rs +++ /dev/null @@ -1,74 +0,0 @@ -//! A lazily fill Cell, but with frozen contents. -//! -//! With a `RefCell`, the inner contents cannot be borrowed for the lifetime of -//! the entire object, but only of the borrows returned. A `LazyCell` is a -//! variation on `RefCell` which allows borrows tied to the lifetime of the -//! outer object. -//! -//! The limitation of a `LazyCell` is that after initialized, it can never be -//! modified unless you've otherwise got a `&mut` reference - -use std::cell::UnsafeCell; - -#[derive(Debug)] -pub struct LazyCell { - inner: UnsafeCell>, -} - -impl LazyCell { - /// Creates a new empty lazy cell. - pub fn new() -> LazyCell { - LazyCell { inner: UnsafeCell::new(None) } - } - - /// Put a value into this cell. - /// - /// This function will fail if the cell has already been filled. - pub fn fill(&self, t: T) -> Result<(), T> { - unsafe { - let slot = self.inner.get(); - if (*slot).is_none() { - *slot = Some(t); - Ok(()) - } else { - Err(t) - } - } - } - - /// Borrows the contents of this lazy cell for the duration of the cell - /// itself. - /// - /// This function will return `Some` if the cell has been previously - /// initialized, and `None` if it has not yet been initialized. - pub fn borrow(&self) -> Option<&T> { - unsafe { - (*self.inner.get()).as_ref() - } - } - - /// Same as `borrow`, but the mutable version - pub fn borrow_mut(&mut self) -> Option<&mut T> { - unsafe { - (*self.inner.get()).as_mut() - } - } - - /// Consumes this `LazyCell`, returning the underlying value. - #[allow(unused_unsafe)] - pub fn into_inner(self) -> Option { - unsafe { - self.inner.into_inner() - } - } - - /// Borrows the contents of this lazy cell, initializing it if necessary. - pub fn get_or_try_init(&self, init: F) -> Result<&T, Error> - where F: FnOnce() -> Result - { - if self.borrow().is_none() && self.fill(init()?).is_err() { - unreachable!(); - } - Ok(self.borrow().unwrap()) - } -} diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index 1e1b55e36..4b500cfb2 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -7,7 +7,6 @@ pub use self::errors::{process_error, internal}; pub use self::flock::{FileLock, Filesystem}; pub use self::graph::Graph; pub use self::hex::{to_hex, short_hash, hash_u64}; -pub use self::lazy_cell::LazyCell; pub use self::lev_distance::{lev_distance}; pub use self::paths::{join_paths, path2bytes, bytes2path, dylib_path}; pub use self::paths::{normalize_path, dylib_path_envvar, without_prefix}; @@ -40,7 +39,6 @@ mod dependency_queue; mod rustc; mod sha256; mod vcs; -mod lazy_cell; mod flock; mod read2; mod progress; From 9cb10e68a2f225b5e993043f13da98568a41c50a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 12 Feb 2018 20:00:59 +0300 Subject: [PATCH 05/17] Switch `cargo new` default to `--bin` --- src/bin/init.rs | 4 ++-- src/bin/new.rs | 4 ++-- src/cargo/ops/cargo_new.rs | 4 ++-- src/doc/src/getting-started/first-steps.md | 2 +- src/doc/src/guide/creating-a-new-project.md | 6 ++---- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/bin/init.rs b/src/bin/init.rs index 74ae608ac..7d2a8593c 100644 --- a/src/bin/init.rs +++ b/src/bin/init.rs @@ -32,8 +32,8 @@ Options: control system (git, hg, pijul, or fossil) or do not initialize any version control at all (none), overriding a global configuration. - --bin Use a binary (application) template - --lib Use a library template [default] + --bin Use a binary (application) template [default] + --lib Use a library template --name NAME Set the resulting package name -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout diff --git a/src/bin/new.rs b/src/bin/new.rs index 6b51a6180..e18dcf8c2 100644 --- a/src/bin/new.rs +++ b/src/bin/new.rs @@ -32,8 +32,8 @@ Options: control system (git, hg, pijul, or fossil) or do not initialize any version control at all (none), overriding a global configuration. - --bin Use a binary (application) template - --lib Use a library template [default] + --bin Use a binary (application) template [default] + --lib Use a library template --name NAME Set the resulting package name, defaults to the value of -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 3cba288be..aaaa69e21 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -92,8 +92,8 @@ impl<'a> NewOptions<'a> { (true, true) => bail!("can't specify both lib and binary outputs"), (true, false) => NewProjectKind::Bin, (false, true) => NewProjectKind::Lib, - // default to lib - (false, false) => NewProjectKind::Lib, + // default to bin + (false, false) => NewProjectKind::Bin, }; let opts = NewOptions { version_control, kind, path, name }; diff --git a/src/doc/src/getting-started/first-steps.md b/src/doc/src/getting-started/first-steps.md index 6b31d8d0c..3a0bad356 100644 --- a/src/doc/src/getting-started/first-steps.md +++ b/src/doc/src/getting-started/first-steps.md @@ -7,7 +7,7 @@ $ cargo new hello_world --bin ``` We’re passing `--bin` because we’re making a binary program: if we -were making a library, we’d leave it off. +were making a library, we’d pass `--lib`. Let’s check out what Cargo has generated for us: diff --git a/src/doc/src/guide/creating-a-new-project.md b/src/doc/src/guide/creating-a-new-project.md index 3566e02a3..98f2a65d7 100644 --- a/src/doc/src/guide/creating-a-new-project.md +++ b/src/doc/src/guide/creating-a-new-project.md @@ -7,7 +7,7 @@ $ cargo new hello_world --bin ``` We’re passing `--bin` because we’re making a binary program: if we -were making a library, we’d leave it off. This also initializes a new `git` +were making a library, we’d pass `--lib`. This also initializes a new `git` repository by default. If you don't want it to do that, pass `--vcs none`. Let’s check out what Cargo has generated for us: @@ -23,9 +23,7 @@ $ tree . 1 directory, 2 files ``` -If we had just used `cargo new hello_world` without the `--bin` flag, then -we would have a `lib.rs` instead of a `main.rs`. For now, however, this is all -we need to get started. First, let’s check out `Cargo.toml`: +Let’s take a closer look at `Cargo.toml`: ```toml [package] From ddffe6063c6ea89710f21d2ac46afa468a563511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 12 Feb 2018 19:27:45 +0100 Subject: [PATCH 06/17] readme: add link to the cargo documentation on docs.rs --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 187da3a6d..e029365e4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Learn more at https://doc.rust-lang.org/cargo/ [![Build Status](https://travis-ci.org/rust-lang/cargo.svg?branch=master)](https://travis-ci.org/rust-lang/cargo) [![Build Status](https://ci.appveyor.com/api/projects/status/github/rust-lang/cargo?branch=master&svg=true)](https://ci.appveyor.com/project/rust-lang-libs/cargo) +Code documentation: https://docs.rs/cargo/ + ## Installing Cargo Cargo is distributed by default with Rust, so if you've got `rustc` installed From b90bb7d6a8e410a2ba631bc2a1f3f40b1f5aaf9c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 12 Feb 2018 12:42:31 -0800 Subject: [PATCH 07/17] Update dependencies Just a few major updates here and there --- Cargo.toml | 6 +++--- tests/cargotest/Cargo.toml | 2 +- tests/cargotest/support/registry.rs | 4 ++-- tests/package.rs | 6 +----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 265a0ad15..237890cfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ git2-curl = "0.7" glob = "0.2" hex = "0.3" home = "0.3" -ignore = "0.3" +ignore = "0.4" jobserver = "0.1.9" libc = "0.2" libgit2-sys = "0.6" @@ -54,10 +54,10 @@ toml = "0.4" url = "1.1" [target.'cfg(target_os = "macos")'.dependencies] -core-foundation = { version = "0.4.4", features = ["mac_os_10_7_support"] } +core-foundation = { version = "0.5.1", features = ["mac_os_10_7_support"] } [target.'cfg(windows)'.dependencies] -miow = "0.2" +miow = "0.3" [target.'cfg(windows)'.dependencies.winapi] version = "0.3" diff --git a/tests/cargotest/Cargo.toml b/tests/cargotest/Cargo.toml index 5f1b6a498..ee9770a38 100644 --- a/tests/cargotest/Cargo.toml +++ b/tests/cargotest/Cargo.toml @@ -12,7 +12,7 @@ filetime = "0.1" flate2 = "1.0" git2 = { version = "0.6", default-features = false } hamcrest = "=0.1.1" -hex = "0.2" +hex = "0.3" log = "0.4" serde_json = "1.0" tar = { version = "0.4", default-features = false } diff --git a/tests/cargotest/support/registry.rs b/tests/cargotest/support/registry.rs index 25f8feb14..7283ad78a 100644 --- a/tests/cargotest/support/registry.rs +++ b/tests/cargotest/support/registry.rs @@ -6,7 +6,7 @@ use std::path::{PathBuf, Path}; use flate2::Compression; use flate2::write::GzEncoder; use git2; -use hex::ToHex; +use hex; use tar::{Builder, Header}; use url::Url; @@ -320,5 +320,5 @@ impl Package { pub fn cksum(s: &[u8]) -> String { let mut sha = Sha256::new(); sha.update(s); - sha.finish().to_hex() + hex::encode(&sha.finish()) } diff --git a/tests/package.rs b/tests/package.rs index f49a56193..ca35e624b 100644 --- a/tests/package.rs +++ b/tests/package.rs @@ -330,10 +330,6 @@ See [..] See [..] [WARNING] [..] file `some_dir[/]dir_deep_3[/]some_dir[/]file` WILL be excluded [..] See [..] -[WARNING] [..] file `some_dir[/]dir_deep_4[/]some_dir[/]file` WILL be excluded [..] -See [..] -[WARNING] [..] file `some_dir[/]dir_deep_5[/]some_dir[/]file` WILL be excluded [..] -See [..] [WARNING] [..] file `some_dir[/]file_deep_1` WILL be excluded [..] See [..] [ARCHIVING] [..] @@ -1003,4 +999,4 @@ Caused by: consider adding `cargo-features = [\"epoch\"]` to the manifest "))); -} \ No newline at end of file +} From 79942fea1bb7a480f6eebd6cd1f8a04ac9f45a0b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 17 Jan 2018 11:33:25 -0800 Subject: [PATCH 08/17] Implement renaming dependencies in the manifest This commit implements a new unstable feature for manifests which allows renaming a crate when depending on it. For example you can do: ```toml cargo-features = ["dependencies-as"] ... [dependencies] foo = "0.1" bar = { version = "0.1", registry = "custom", package = "foo" } baz = { git = "https://github.com/foo/bar", package = "foo" } ``` Here three crates will be imported but they'll be made available to the Rust source code via the names `foo` (crates.io), `bar` (the custom registry), and `baz` (the git dependency). The *package* name, however, will be `foo` for all of them. In other words the git repository here would be searched for a crate called `foo`. For example: ```rust extern crate foo; // crates.io extern crate bar; // registry `custom` extern crate baz; // git repository ``` The intention here is to enable a few use cases: * Enable depending on the same named crate from different registries * Allow depending on multiple versions of a crate from one registry * Removing the need for `extern crate foo as bar` syntactically in Rust source Currently I don't think we're ready to stabilize this so it's just a nightly feature, but I'm hoping we can continue to iterate on it! --- src/cargo/core/dependency.rs | 13 ++++ src/cargo/core/features.rs | 3 + src/cargo/ops/cargo_rustc/mod.rs | 34 ++++++--- src/cargo/util/toml/mod.rs | 80 +++++++++++++-------- tests/metadata.rs | 6 +- tests/rename-deps.rs | 120 +++++++++++++++++++++++++++++++ 6 files changed, 216 insertions(+), 40 deletions(-) create mode 100644 tests/rename-deps.rs diff --git a/src/cargo/core/dependency.rs b/src/cargo/core/dependency.rs index ca944dc19..aa24554e7 100644 --- a/src/cargo/core/dependency.rs +++ b/src/cargo/core/dependency.rs @@ -27,6 +27,7 @@ struct Inner { specified_req: bool, kind: Kind, only_match_name: bool, + rename: Option, optional: bool, default_features: bool, @@ -49,6 +50,7 @@ struct SerializedDependency<'a> { source: &'a SourceId, req: String, kind: Kind, + rename: Option<&'a str>, optional: bool, uses_default_features: bool, @@ -69,6 +71,7 @@ impl ser::Serialize for Dependency { uses_default_features: self.uses_default_features(), features: self.features(), target: self.platform(), + rename: self.rename(), }.serialize(s) } } @@ -182,6 +185,7 @@ impl Dependency { default_features: true, specified_req: false, platform: None, + rename: None, }), } } @@ -221,6 +225,10 @@ impl Dependency { self.inner.platform.as_ref() } + pub fn rename(&self) -> Option<&str> { + self.inner.rename.as_ref().map(|s| &**s) + } + pub fn set_kind(&mut self, kind: Kind) -> &mut Dependency { Rc::make_mut(&mut self.inner).kind = kind; self @@ -261,6 +269,11 @@ impl Dependency { self } + pub fn set_rename(&mut self, rename: &str) -> &mut Dependency { + Rc::make_mut(&mut self.inner).rename = Some(rename.to_string()); + self + } + /// Lock this dependency to depending on the specified package id pub fn lock_to(&mut self, id: &PackageId) -> &mut Dependency { assert_eq!(self.inner.source_id, *id.source_id()); diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 323366b9b..74437f7c9 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -159,6 +159,9 @@ features! { // Using epochs [unstable] epoch: bool, + + // Renaming a package in the manifest via the `package` key + [unstable] rename_dependency: bool, } } diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index b32948576..ec97e81b2 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -947,12 +947,12 @@ Cargo.toml. This warning might turn into a hard error in the future.", } } - for unit in dep_targets { - if unit.profile.run_custom_build { - cmd.env("OUT_DIR", &cx.build_script_out_dir(&unit)); + for dep in dep_targets { + if dep.profile.run_custom_build { + cmd.env("OUT_DIR", &cx.build_script_out_dir(&dep)); } - if unit.target.linkable() && !unit.profile.doc { - link_to(cmd, cx, &unit)?; + if dep.target.linkable() && !dep.profile.doc { + link_to(cmd, cx, &unit, &dep)?; } } @@ -960,15 +960,31 @@ Cargo.toml. This warning might turn into a hard error in the future.", fn link_to<'a, 'cfg>(cmd: &mut ProcessBuilder, cx: &mut Context<'a, 'cfg>, - unit: &Unit<'a>) -> CargoResult<()> { - for &(ref dst, _, file_type) in cx.target_filenames(unit)?.iter() { + current: &Unit<'a>, + dep: &Unit<'a>) -> CargoResult<()> { + for &(ref dst, _, file_type) in cx.target_filenames(dep)?.iter() { if file_type != TargetFileType::Linkable { continue } let mut v = OsString::new(); - v.push(&unit.target.crate_name()); + + // Unfortunately right now Cargo doesn't have a great way to get a + // 1:1 mapping of entries in `dependencies()` to the actual crate + // we're depending on. Instead we're left to do some guesswork here + // to figure out what `Dependency` the `dep` unit corresponds to in + // `current` to see if we're renaming it. + // + // This I believe mostly works out for now, but we'll likely want + // to tighten up this in the future. + let name = current.pkg.dependencies() + .iter() + .filter(|d| d.matches_ignoring_source(dep.pkg.summary())) + .filter_map(|d| d.rename()) + .next(); + + v.push(name.unwrap_or(&dep.target.crate_name())); v.push("="); - v.push(cx.out_dir(unit)); + v.push(cx.out_dir(dep)); v.push(&path::MAIN_SEPARATOR.to_string()); v.push(&dst.file_name().unwrap()); cmd.arg("--extern").arg(&v); diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c33aaef93..633f2bf1f 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -142,7 +142,7 @@ type TomlBenchTarget = TomlTarget; #[serde(untagged)] pub enum TomlDependency { Simple(String), - Detailed(DetailedTomlDependency) + Detailed(DetailedTomlDependency), } impl<'de> de::Deserialize<'de> for TomlDependency { @@ -193,6 +193,7 @@ pub struct DetailedTomlDependency { default_features: Option, #[serde(rename = "default_features")] default_features2: Option, + package: Option, } #[derive(Debug, Deserialize, Serialize)] @@ -917,16 +918,28 @@ impl TomlDependency { cx: &mut Context, kind: Option) -> CargoResult { - let details = match *self { - TomlDependency::Simple(ref version) => DetailedTomlDependency { - version: Some(version.clone()), - .. Default::default() - }, - TomlDependency::Detailed(ref details) => details.clone(), - }; + match *self { + TomlDependency::Simple(ref version) => { + DetailedTomlDependency { + version: Some(version.clone()), + ..Default::default() + }.to_dependency(name, cx, kind) + } + TomlDependency::Detailed(ref details) => { + details.to_dependency(name, cx, kind) + } + } + } +} - if details.version.is_none() && details.path.is_none() && - details.git.is_none() { +impl DetailedTomlDependency { + fn to_dependency(&self, + name: &str, + cx: &mut Context, + kind: Option) + -> CargoResult { + if self.version.is_none() && self.path.is_none() && + self.git.is_none() { let msg = format!("dependency ({}) specified without \ providing a local path, Git repository, or \ version to use. This will be considered an \ @@ -934,11 +947,11 @@ impl TomlDependency { cx.warnings.push(msg); } - if details.git.is_none() { + if self.git.is_none() { let git_only_keys = [ - (&details.branch, "branch"), - (&details.tag, "tag"), - (&details.rev, "rev") + (&self.branch, "branch"), + (&self.tag, "tag"), + (&self.rev, "rev") ]; for &(key, key_name) in &git_only_keys { @@ -951,7 +964,7 @@ impl TomlDependency { } } - let registry_id = match details.registry { + let registry_id = match self.registry { Some(ref registry) => { cx.features.require(Feature::alternative_registries())?; SourceId::alt_registry(cx.config, registry)? @@ -960,10 +973,10 @@ impl TomlDependency { }; let new_source_id = match ( - details.git.as_ref(), - details.path.as_ref(), - details.registry.as_ref(), - details.registry_index.as_ref(), + self.git.as_ref(), + self.path.as_ref(), + self.registry.as_ref(), + self.registry_index.as_ref(), ) { (Some(_), _, Some(_), _) | (Some(_), _, _, Some(_))=> bail!("dependency ({}) specification is ambiguous. \ @@ -978,7 +991,7 @@ impl TomlDependency { cx.warnings.push(msg) } - let n_details = [&details.branch, &details.tag, &details.rev] + let n_details = [&self.branch, &self.tag, &self.rev] .iter() .filter(|d| d.is_some()) .count(); @@ -990,9 +1003,9 @@ impl TomlDependency { cx.warnings.push(msg) } - let reference = details.branch.clone().map(GitReference::Branch) - .or_else(|| details.tag.clone().map(GitReference::Tag)) - .or_else(|| details.rev.clone().map(GitReference::Rev)) + let reference = self.branch.clone().map(GitReference::Branch) + .or_else(|| self.tag.clone().map(GitReference::Tag)) + .or_else(|| self.rev.clone().map(GitReference::Rev)) .unwrap_or_else(|| GitReference::Branch("master".to_string())); let loc = git.to_url()?; SourceId::for_git(&loc, reference)? @@ -1023,24 +1036,33 @@ impl TomlDependency { (None, None, None, None) => SourceId::crates_io(cx.config)?, }; - let version = details.version.as_ref().map(|v| &v[..]); + let (pkg_name, rename) = match self.package { + Some(ref s) => (&s[..], Some(name)), + None => (name, None), + }; + + let version = self.version.as_ref().map(|v| &v[..]); let mut dep = match cx.pkgid { Some(id) => { - Dependency::parse(name, version, &new_source_id, + Dependency::parse(pkg_name, version, &new_source_id, id, cx.config)? } None => Dependency::parse_no_deprecated(name, version, &new_source_id)?, }; - dep.set_features(details.features.unwrap_or_default()) - .set_default_features(details.default_features - .or(details.default_features2) + dep.set_features(self.features.clone().unwrap_or_default()) + .set_default_features(self.default_features + .or(self.default_features2) .unwrap_or(true)) - .set_optional(details.optional.unwrap_or(false)) + .set_optional(self.optional.unwrap_or(false)) .set_platform(cx.platform.clone()) .set_registry_id(®istry_id); if let Some(kind) = kind { dep.set_kind(kind); } + if let Some(rename) = rename { + cx.features.require(Feature::rename_dependency())?; + dep.set_rename(rename); + } Ok(dep) } } diff --git a/tests/metadata.rs b/tests/metadata.rs index 71c3545ea..b3c99fd17 100644 --- a/tests/metadata.rs +++ b/tests/metadata.rs @@ -193,7 +193,8 @@ fn cargo_metadata_with_deps_and_version() { "req": "^0.0.1", "source": "registry+[..]", "target": null, - "uses_default_features": true + "uses_default_features": true, + "rename": null } ], "features": {}, @@ -228,7 +229,8 @@ fn cargo_metadata_with_deps_and_version() { "req": "*", "source": "registry+[..]", "target": null, - "uses_default_features": true + "uses_default_features": true, + "rename": null } ], "features": {}, diff --git a/tests/rename-deps.rs b/tests/rename-deps.rs new file mode 100644 index 000000000..f144acca2 --- /dev/null +++ b/tests/rename-deps.rs @@ -0,0 +1,120 @@ +extern crate cargo; +extern crate cargotest; +extern crate hamcrest; + +use cargotest::support::{project, execs}; +use cargotest::support::registry::Package; +use cargotest::ChannelChanger; +use hamcrest::assert_that; + +#[test] +fn gated() { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = { package = "foo", version = "0.1" } + "#) + .file("src/lib.rs", "") + .build(); + + assert_that(p.cargo("build").masquerade_as_nightly_cargo(), + execs().with_status(101) + .with_stderr("\ +error: failed to parse manifest at `[..]` + +Caused by: + feature `rename-dependency` is required + +consider adding `cargo-features = [\"rename-dependency\"]` to the manifest +")); + + let p = project("bar") + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = { version = "0.1", package = "baz" } + "#) + .file("src/lib.rs", "") + .build(); + + assert_that(p.cargo("build").masquerade_as_nightly_cargo(), + execs().with_status(101) + .with_stderr("\ +error: failed to parse manifest at `[..]` + +Caused by: + feature `rename-dependency` is required + +consider adding `cargo-features = [\"rename-dependency\"]` to the manifest +")); +} + +#[test] +fn rename_dependency() { + Package::new("bar", "0.1.0").publish(); + Package::new("bar", "0.2.0").publish(); + + let p = project("foo") + .file("Cargo.toml", r#" + cargo-features = ["rename-dependency"] + + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + bar = { version = "0.1.0" } + baz = { version = "0.2.0", package = "bar" } + "#) + .file("src/lib.rs", " + extern crate bar; + extern crate baz; + ") + .build(); + + assert_that(p.cargo("build").masquerade_as_nightly_cargo(), + execs().with_status(0)); +} + +#[test] +fn rename_with_different_names() { + let p = project("foo") + .file("Cargo.toml", r#" + cargo-features = ["rename-dependency"] + + [project] + name = "foo" + version = "0.0.1" + authors = [] + + [dependencies] + baz = { path = "bar", package = "bar" } + "#) + .file("src/lib.rs", " + extern crate baz; + ") + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.0.1" + authors = [] + + [lib] + name = "random_name" + "#) + .file("bar/src/lib.rs", "") + .build(); + + assert_that(p.cargo("build").masquerade_as_nightly_cargo(), + execs().with_status(0)); +} From 7e92513debcf0c62999206e3675493470c4b4ead Mon Sep 17 00:00:00 2001 From: Yong Wen Chua Date: Wed, 14 Feb 2018 09:58:20 +0800 Subject: [PATCH 09/17] Fix DocOpt deserialization type bounds This is wrt https://github.com/docopt/docopt.rs/pull/222 DocOpt does not support deserializing borrowed types. This change was reverted in https://github.com/docopt/docopt.rs/commit/7292a374e69afb192bb7aaa00f9d9f4afebc200d because it broke crates like Cargo etc. --- src/cargo/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index d60792c7a..41615e3d8 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -40,7 +40,7 @@ extern crate core_foundation; use std::fmt; -use serde::Deserialize; +use serde::de::DeserializeOwned; use serde::ser; use docopt::Docopt; use failure::Error; @@ -103,7 +103,7 @@ impl fmt::Display for VersionInfo { } } -pub fn call_main_without_stdin<'de, Flags: Deserialize<'de>>( +pub fn call_main_without_stdin( exec: fn(Flags, &mut Config) -> CliResult, config: &mut Config, usage: &str, From 3e4d1558ab63605d15d6d143b0b5f89ea579a8b8 Mon Sep 17 00:00:00 2001 From: David Ross Date: Tue, 13 Feb 2018 22:17:15 -0800 Subject: [PATCH 10/17] Remove cargo-only downloads from installation docs This also copies extra instructions for installing rust from https://doc.rust-lang.org/book/first-edition/getting-started.html#installing-rust-1. Fixes https://github.com/rust-lang/cargo/issues/5027. --- src/doc/src/getting-started/installation.md | 39 ++++++++++----------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/doc/src/getting-started/installation.md b/src/doc/src/getting-started/installation.md index 98b84780b..186c9daa5 100644 --- a/src/doc/src/getting-started/installation.md +++ b/src/doc/src/getting-started/installation.md @@ -1,38 +1,37 @@ ## Installation -### Install Stable Rust and Cargo +### Install Rust and Cargo -The easiest way to get Cargo is to get the current stable release of [Rust] by -using the `rustup` script: +The easiest way to get Cargo is to install the current stable release of [Rust] +by using `rustup`. + +On Linux and macOS systems, this is done as follows: ```console $ curl -sSf https://static.rust-lang.org/rustup.sh | sh ``` +It will download a script, and start the installation. If everything goes well, +you’ll see this appear: + +```console +Rust is installed now. Great! +``` + +On Windows, download and run [rustup-init.exe]. It will start the installation +in a console and present the above message on success. + After this, you can use the `rustup` command to also install `beta` or `nightly` channels for Rust and Cargo. -### Install Nightly Cargo - -To install just Cargo, the current recommended installation method is through -the official nightly builds. Note that Cargo will also require that [Rust] is -already installed on the system. - -| Platform | 64-bit | 32-bit | -|------------------|-------------------|-------------------| -| Linux binaries | [tar.gz][linux64] | [tar.gz][linux32] | -| MacOS binaries | [tar.gz][mac64] | [tar.gz][mac32] | -| Windows binaries | [tar.gz][win64] | [tar.gz][win32] | +For other installation options and information, visit the +[install][install-rust] page of the Rust website. ### Build and Install Cargo from Source Alternatively, you can [build Cargo from source][compiling-from-source]. [rust]: https://www.rust-lang.org/ -[linux64]: https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-unknown-linux-gnu.tar.gz -[linux32]: https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-unknown-linux-gnu.tar.gz -[mac64]: https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-apple-darwin.tar.gz -[mac32]: https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-apple-darwin.tar.gz -[win64]: https://static.rust-lang.org/cargo-dist/cargo-nightly-x86_64-pc-windows-gnu.tar.gz -[win32]: https://static.rust-lang.org/cargo-dist/cargo-nightly-i686-pc-windows-gnu.tar.gz +[rustup-init.exe]: https://win.rustup.rs/ +[install-rust]: https://www.rust-lang.org/install.html [compiling-from-source]: https://github.com/rust-lang/cargo#compiling-from-source From f76db9c790b3cec9079e1472fa95106ac8d025ae Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Wed, 14 Feb 2018 12:27:19 -0500 Subject: [PATCH 11/17] When -v is passed with --list, display path to custom commands --- src/bin/cargo.rs | 21 ++++++++++++++++----- tests/cargo.rs | 4 ++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index fa2ba69ea..1f282f82d 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -180,7 +180,15 @@ fn execute(flags: Flags, config: &mut Config) -> CliResult { if flags.flag_list { println!("Installed Commands:"); for command in list_commands(config) { - println!(" {}", command); + let (command, path) = command; + if flags.flag_verbose > 0 { + match path { + Some(p) => println!(" {:<20} {}", command, p), + None => println!(" {:<20}", command), + } + } else { + println!(" {}", command); + } } return Ok(()); } @@ -301,7 +309,7 @@ fn find_closest(config: &Config, cmd: &str) -> Option { // 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)) + .map(|&(ref c, _)| (lev_distance(c, cmd), c)) .filter(|&(d, _)| d < 4) .collect::>(); filtered.sort_by(|a, b| a.0.cmp(&b.0)); @@ -347,7 +355,7 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[String]) -> C } /// List all runnable commands -fn list_commands(config: &Config) -> BTreeSet { +fn list_commands(config: &Config) -> BTreeSet<(String, Option)> { let prefix = "cargo-"; let suffix = env::consts::EXE_SUFFIX; let mut commands = BTreeSet::new(); @@ -367,13 +375,16 @@ fn list_commands(config: &Config) -> BTreeSet { } if is_executable(entry.path()) { let end = filename.len() - suffix.len(); - commands.insert(filename[prefix.len()..end].to_string()); + commands.insert( + (filename[prefix.len()..end].to_string(), + Some(path.display().to_string())) + ); } } } macro_rules! add_cmd { - ($cmd:ident) => ({ commands.insert(stringify!($cmd).replace("_", "-")); }) + ($cmd:ident) => ({ commands.insert((stringify!($cmd).replace("_", "-"), None)); }) } each_subcommand!(add_cmd); commands diff --git a/tests/cargo.rs b/tests/cargo.rs index 55de7b9c7..35e22c641 100644 --- a/tests/cargo.rs +++ b/tests/cargo.rs @@ -74,7 +74,7 @@ fn list_command_looks_at_path() { .env("PATH", &path); let output = output.exec_with_output().unwrap(); let output = str::from_utf8(&output.stdout).unwrap(); - assert!(output.contains("\n 1\n"), "missing 1: {}", output); + assert!(output.contains("\n 1 "), "missing 1: {}", output); } // windows and symlinks don't currently agree that well @@ -95,7 +95,7 @@ fn list_command_resolves_symlinks() { .env("PATH", &path); let output = output.exec_with_output().unwrap(); let output = str::from_utf8(&output.stdout).unwrap(); - assert!(output.contains("\n 2\n"), "missing 2: {}", output); + assert!(output.contains("\n 2 "), "missing 2: {}", output); } #[test] From 996197094cc070e4783a568442b8e7af2c0a9649 Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Sat, 17 Feb 2018 22:23:27 -0600 Subject: [PATCH 12/17] doc: add explicit example with ^ and leading 0 Since the leading 0 is treated a bit special, its worth it to have an explicit example to match the above example of the major version being > 0. --- src/doc/src/reference/specifying-dependencies.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/src/reference/specifying-dependencies.md b/src/doc/src/reference/specifying-dependencies.md index b5044bd73..c63b5835d 100644 --- a/src/doc/src/reference/specifying-dependencies.md +++ b/src/doc/src/reference/specifying-dependencies.md @@ -42,6 +42,7 @@ be allowed with them: ^1.2 := >=1.2.0 <2.0.0 ^1 := >=1.0.0 <2.0.0 ^0.2.3 := >=0.2.3 <0.3.0 +^0.2 := >= 0.2.0 < 0.3.0 ^0.0.3 := >=0.0.3 <0.0.4 ^0.0 := >=0.0.0 <0.1.0 ^0 := >=0.0.0 <1.0.0 From e59171aab00e6fb939a9fcbdcabacae27492d32c Mon Sep 17 00:00:00 2001 From: Doug Goldstein Date: Sat, 17 Feb 2018 22:41:32 -0600 Subject: [PATCH 13/17] update contributing to show how to build the docs The contributing guide referenced a script that was deleted in 1271bb4de0c0 so it wasn't possible to follow the contributing guide successfully prior to contributing doc improvements. --- CONTRIBUTING.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index eb7374ee6..ed260e51a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -109,13 +109,16 @@ and [merges][mergequeue] it into Cargo's `master` branch. To contribute to the documentation, all you need to do is change the markdown files in the `src/doc` directory. To view the rendered version of changes you -have made locally, run: +have made locally, make sure you have `mdbook` installed and run: ```sh -sh src/ci/dox.sh -open target/doc/index.html +cd src/doc +mdbook build +open book/index.html ``` +To install `mdbook` run `cargo install mdbook`. + ## Issue Triage From 0c46ede78c0b0a2f2c234a5eb42fd2bfed728610 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 19 Feb 2018 14:29:48 -0800 Subject: [PATCH 14/17] Update default codegen-units It's been 16 since rustc 1.24. --- src/doc/src/reference/manifest.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/doc/src/reference/manifest.md b/src/doc/src/reference/manifest.md index 1c15ac457..117cd373c 100644 --- a/src/doc/src/reference/manifest.md +++ b/src/doc/src/reference/manifest.md @@ -299,7 +299,7 @@ lto = false # Link Time Optimization usually reduces size of binaries # be passed debug-assertions = true # controls whether debug assertions are enabled # (e.g. debug_assert!() and arithmetic overflow checks) -codegen-units = 1 # if > 1 enables parallel code generation which improves +codegen-units = 16 # if > 1 enables parallel code generation which improves # compile times, but prevents some optimizations. # Passes `-C codegen-units`. panic = 'unwind' # panic strategy (`-C panic=...`), can also be 'abort' @@ -314,7 +314,7 @@ debug = false rpath = false lto = false debug-assertions = false -codegen-units = 1 +codegen-units = 16 panic = 'unwind' incremental = false overflow-checks = false @@ -326,7 +326,7 @@ debug = 2 rpath = false lto = false debug-assertions = true -codegen-units = 1 +codegen-units = 16 panic = 'unwind' incremental = true overflow-checks = true @@ -338,7 +338,7 @@ debug = false rpath = false lto = false debug-assertions = false -codegen-units = 1 +codegen-units = 16 panic = 'unwind' incremental = false overflow-checks = false @@ -350,7 +350,7 @@ debug = 2 rpath = false lto = false debug-assertions = true -codegen-units = 1 +codegen-units = 16 panic = 'unwind' incremental = true overflow-checks = true From c2ff988c9f09ab6d865088f57c99c967590111bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Thu, 8 Feb 2018 01:13:17 +0100 Subject: [PATCH 15/17] Reorganize integration tests as one crate with many modules. Issue #4867. --- Cargo.toml | 6 +- .../alt_registry.rs} | 3 - .../bad_config.rs} | 3 - .../bad_manifest_path.rs} | 3 - tests/{ => testsuite}/bench.rs | 4 - tests/{ => testsuite}/build.rs | 6 -- .../build_auth.rs} | 7 +- .../{build-lib.rs => testsuite/build_lib.rs} | 0 .../build_script.rs} | 3 - .../build_script_env.rs} | 3 - tests/{ => testsuite}/cargo.rs | 4 - tests/{ => testsuite}/cargo_alias_config.rs | 2 - .../cargo_features.rs} | 3 - tests/{ => testsuite}/cargotest/Cargo.toml | 2 +- tests/{ => testsuite}/cargotest/install.rs | 0 tests/{ => testsuite}/cargotest/lib.rs | 0 .../cargotest/support/cross_compile.rs | 0 .../{ => testsuite}/cargotest/support/git.rs | 0 .../{ => testsuite}/cargotest/support/mod.rs | 0 .../cargotest/support/paths.rs | 0 .../cargotest/support/publish.rs | 0 .../cargotest/support/registry.rs | 0 tests/{ => testsuite}/cfg.rs | 4 - tests/{ => testsuite}/check-style.sh | 0 tests/{ => testsuite}/check.rs | 4 - tests/{ => testsuite}/clean.rs | 3 - tests/{ => testsuite}/concurrent.rs | 6 +- tests/{ => testsuite}/config.rs | 3 - .../cross_compile.rs} | 4 - .../cross_publish.rs} | 6 -- tests/{ => testsuite}/death.rs | 5 -- tests/{dep-info.rs => testsuite/dep_info.rs} | 3 - tests/{ => testsuite}/directory.rs | 8 +- tests/{ => testsuite}/doc.rs | 5 +- tests/{ => testsuite}/features.rs | 4 - tests/{ => testsuite}/fetch.rs | 3 - tests/{ => testsuite}/freshness.rs | 3 - .../generate_lockfile.rs} | 3 - tests/{ => testsuite}/git.rs | 6 +- tests/{ => testsuite}/init.rs | 6 +- tests/{ => testsuite}/install.rs | 5 +- tests/{ => testsuite}/jobserver.rs | 3 - tests/testsuite/lib.rs | 82 +++++++++++++++++++ .../local_registry.rs} | 4 - .../lockfile_compat.rs} | 3 - tests/{ => testsuite}/login.rs | 7 +- tests/{ => testsuite}/metadata.rs | 3 - .../net_config.rs} | 3 - tests/{ => testsuite}/new.rs | 6 +- tests/{ => testsuite}/overrides.rs | 3 - tests/{ => testsuite}/package.rs | 9 +- tests/{ => testsuite}/patch.rs | 6 +- tests/{ => testsuite}/path.rs | 6 +- tests/{ => testsuite}/plugins.rs | 3 - .../proc_macro.rs} | 3 - tests/{ => testsuite}/profiles.rs | 3 - tests/{ => testsuite}/publish.rs | 5 -- .../read_manifest.rs} | 3 - tests/{ => testsuite}/registry.rs | 5 -- .../required_features.rs} | 3 - tests/{ => testsuite}/resolve.rs | 3 - tests/{ => testsuite}/run.rs | 4 - tests/{ => testsuite}/rustc.rs | 3 - tests/{ => testsuite}/rustdoc.rs | 3 - tests/{ => testsuite}/rustdocflags.rs | 3 - tests/{ => testsuite}/rustflags.rs | 3 - tests/{ => testsuite}/search.rs | 6 +- .../small_fd_limits.rs} | 6 +- tests/{ => testsuite}/test.rs | 5 +- .../tool_paths.rs} | 3 - .../verify_project.rs} | 3 - tests/{ => testsuite}/version.rs | 5 +- .../warn_on_failure.rs} | 3 - tests/{ => testsuite}/workspaces.rs | 4 - 74 files changed, 107 insertions(+), 237 deletions(-) rename tests/{alt-registry.rs => testsuite/alt_registry.rs} (99%) rename tests/{bad-config.rs => testsuite/bad_config.rs} (99%) rename tests/{bad-manifest-path.rs => testsuite/bad_manifest_path.rs} (99%) rename tests/{ => testsuite}/bench.rs (99%) rename tests/{ => testsuite}/build.rs (99%) rename tests/{build-auth.rs => testsuite/build_auth.rs} (98%) rename tests/{build-lib.rs => testsuite/build_lib.rs} (100%) rename tests/{build-script.rs => testsuite/build_script.rs} (99%) rename tests/{build-script-env.rs => testsuite/build_script_env.rs} (98%) rename tests/{ => testsuite}/cargo.rs (98%) rename tests/{ => testsuite}/cargo_alias_config.rs (98%) rename tests/{cargo-features.rs => testsuite/cargo_features.rs} (99%) rename tests/{ => testsuite}/cargotest/Cargo.toml (92%) rename tests/{ => testsuite}/cargotest/install.rs (100%) rename tests/{ => testsuite}/cargotest/lib.rs (100%) rename tests/{ => testsuite}/cargotest/support/cross_compile.rs (100%) rename tests/{ => testsuite}/cargotest/support/git.rs (100%) rename tests/{ => testsuite}/cargotest/support/mod.rs (100%) rename tests/{ => testsuite}/cargotest/support/paths.rs (100%) rename tests/{ => testsuite}/cargotest/support/publish.rs (100%) rename tests/{ => testsuite}/cargotest/support/registry.rs (100%) rename tests/{ => testsuite}/cfg.rs (99%) rename tests/{ => testsuite}/check-style.sh (100%) rename tests/{ => testsuite}/check.rs (99%) rename tests/{ => testsuite}/clean.rs (99%) rename tests/{ => testsuite}/concurrent.rs (99%) rename tests/{ => testsuite}/config.rs (93%) rename tests/{cross-compile.rs => testsuite/cross_compile.rs} (99%) rename tests/{cross-publish.rs => testsuite/cross_publish.rs} (96%) rename tests/{ => testsuite}/death.rs (98%) rename tests/{dep-info.rs => testsuite/dep_info.rs} (97%) rename tests/{ => testsuite}/directory.rs (99%) rename tests/{ => testsuite}/doc.rs (99%) rename tests/{ => testsuite}/features.rs (99%) rename tests/{ => testsuite}/fetch.rs (90%) rename tests/{ => testsuite}/freshness.rs (99%) rename tests/{generate-lockfile.rs => testsuite/generate_lockfile.rs} (99%) rename tests/{ => testsuite}/git.rs (99%) rename tests/{ => testsuite}/init.rs (99%) rename tests/{ => testsuite}/install.rs (99%) rename tests/{ => testsuite}/jobserver.rs (99%) create mode 100644 tests/testsuite/lib.rs rename tests/{local-registry.rs => testsuite/local_registry.rs} (99%) rename tests/{lockfile-compat.rs => testsuite/lockfile_compat.rs} (99%) rename tests/{ => testsuite}/login.rs (98%) rename tests/{ => testsuite}/metadata.rs (99%) rename tests/{net-config.rs => testsuite/net_config.rs} (96%) rename tests/{ => testsuite}/new.rs (99%) rename tests/{ => testsuite}/overrides.rs (99%) rename tests/{ => testsuite}/package.rs (99%) rename tests/{ => testsuite}/patch.rs (99%) rename tests/{ => testsuite}/path.rs (99%) rename tests/{ => testsuite}/plugins.rs (99%) rename tests/{proc-macro.rs => testsuite/proc_macro.rs} (99%) rename tests/{ => testsuite}/profiles.rs (99%) rename tests/{ => testsuite}/publish.rs (99%) rename tests/{read-manifest.rs => testsuite/read_manifest.rs} (98%) rename tests/{ => testsuite}/registry.rs (99%) rename tests/{required-features.rs => testsuite/required_features.rs} (99%) rename tests/{ => testsuite}/resolve.rs (99%) rename tests/{ => testsuite}/run.rs (99%) rename tests/{ => testsuite}/rustc.rs (99%) rename tests/{ => testsuite}/rustdoc.rs (99%) rename tests/{ => testsuite}/rustdocflags.rs (98%) rename tests/{ => testsuite}/rustflags.rs (99%) rename tests/{ => testsuite}/search.rs (99%) rename tests/{small-fd-limits.rs => testsuite/small_fd_limits.rs} (97%) rename tests/{ => testsuite}/test.rs (99%) rename tests/{tool-paths.rs => testsuite/tool_paths.rs} (99%) rename tests/{verify-project.rs => testsuite/verify_project.rs} (97%) rename tests/{ => testsuite}/version.rs (94%) rename tests/{warn-on-failure.rs => testsuite/warn_on_failure.rs} (98%) rename tests/{ => testsuite}/workspaces.rs (99%) diff --git a/Cargo.toml b/Cargo.toml index 877980ead..f366fbb14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ features = [ [dev-dependencies] bufstream = "0.1" -cargotest = { path = "tests/cargotest", version = "0.1" } +cargotest = { path = "tests/testsuite/cargotest", version = "0.1" } filetime = "0.1" hamcrest = "=0.1.1" @@ -88,3 +88,7 @@ hamcrest = "=0.1.1" name = "cargo" test = false doc = false + +[[test]] +name = "testsuite" +path = "tests/testsuite/lib.rs" \ No newline at end of file diff --git a/tests/alt-registry.rs b/tests/testsuite/alt_registry.rs similarity index 99% rename from tests/alt-registry.rs rename to tests/testsuite/alt_registry.rs index 7d3f91155..467995a10 100644 --- a/tests/alt-registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::ChannelChanger; use cargotest::support::registry::{self, Package, alt_api_path}; use cargotest::support::{paths, project, execs}; diff --git a/tests/bad-config.rs b/tests/testsuite/bad_config.rs similarity index 99% rename from tests/bad-config.rs rename to tests/testsuite/bad_config.rs index 87717578c..dc6f8a75a 100644 --- a/tests/bad-config.rs +++ b/tests/testsuite/bad_config.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{project, execs}; use cargotest::support::registry::Package; use hamcrest::assert_that; diff --git a/tests/bad-manifest-path.rs b/tests/testsuite/bad_manifest_path.rs similarity index 99% rename from tests/bad-manifest-path.rs rename to tests/testsuite/bad_manifest_path.rs index 2dc0d5b26..5673f0076 100644 --- a/tests/bad-manifest-path.rs +++ b/tests/testsuite/bad_manifest_path.rs @@ -1,6 +1,3 @@ -extern crate hamcrest; -extern crate cargotest; - use cargotest::support::{project, execs, main_file, basic_bin_manifest}; use hamcrest::{assert_that}; diff --git a/tests/bench.rs b/tests/testsuite/bench.rs similarity index 99% rename from tests/bench.rs rename to tests/testsuite/bench.rs index 947f920e3..8ab6a126f 100644 --- a/tests/bench.rs +++ b/tests/testsuite/bench.rs @@ -1,7 +1,3 @@ -extern crate cargotest; -extern crate cargo; -extern crate hamcrest; - use std::str; use cargo::util::process; diff --git a/tests/build.rs b/tests/testsuite/build.rs similarity index 99% rename from tests/build.rs rename to tests/testsuite/build.rs index 7f3e887be..d148f5f5c 100644 --- a/tests/build.rs +++ b/tests/testsuite/build.rs @@ -1,9 +1,3 @@ -extern crate cargo; -#[macro_use] -extern crate cargotest; -extern crate hamcrest; -extern crate tempdir; - use std::env; use std::fs::{self, File}; use std::io::prelude::*; diff --git a/tests/build-auth.rs b/tests/testsuite/build_auth.rs similarity index 98% rename from tests/build-auth.rs rename to tests/testsuite/build_auth.rs index 5420de7bc..53ec0d4f1 100644 --- a/tests/build-auth.rs +++ b/tests/testsuite/build_auth.rs @@ -1,13 +1,10 @@ -extern crate bufstream; -extern crate git2; -extern crate cargotest; -extern crate hamcrest; - +use std; use std::collections::HashSet; use std::io::prelude::*; use std::net::TcpListener; use std::thread; +use git2; use bufstream::BufStream; use cargotest::support::paths; use cargotest::support::{project, execs}; diff --git a/tests/build-lib.rs b/tests/testsuite/build_lib.rs similarity index 100% rename from tests/build-lib.rs rename to tests/testsuite/build_lib.rs diff --git a/tests/build-script.rs b/tests/testsuite/build_script.rs similarity index 99% rename from tests/build-script.rs rename to tests/testsuite/build_script.rs index 32ff94e9f..d88a0b5db 100644 --- a/tests/build-script.rs +++ b/tests/testsuite/build_script.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::env; use std::fs::{self, File}; use std::io::prelude::*; diff --git a/tests/build-script-env.rs b/tests/testsuite/build_script_env.rs similarity index 98% rename from tests/build-script-env.rs rename to tests/testsuite/build_script_env.rs index 610301cfb..6afe2a7a9 100644 --- a/tests/build-script-env.rs +++ b/tests/testsuite/build_script_env.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::fs::File; use cargotest::sleep_ms; diff --git a/tests/cargo.rs b/tests/testsuite/cargo.rs similarity index 98% rename from tests/cargo.rs rename to tests/testsuite/cargo.rs index 35e22c641..fdcb237af 100644 --- a/tests/cargo.rs +++ b/tests/testsuite/cargo.rs @@ -1,7 +1,3 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; - use std::env; use std::fs::{self, File}; use std::io::prelude::*; diff --git a/tests/cargo_alias_config.rs b/tests/testsuite/cargo_alias_config.rs similarity index 98% rename from tests/cargo_alias_config.rs rename to tests/testsuite/cargo_alias_config.rs index 0f1a95834..6bd1633a9 100644 --- a/tests/cargo_alias_config.rs +++ b/tests/testsuite/cargo_alias_config.rs @@ -1,5 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; use cargotest::support::{project, execs, basic_bin_manifest}; use hamcrest::{assert_that}; diff --git a/tests/cargo-features.rs b/tests/testsuite/cargo_features.rs similarity index 99% rename from tests/cargo-features.rs rename to tests/testsuite/cargo_features.rs index 9d3246c4d..8ac5fb351 100644 --- a/tests/cargo-features.rs +++ b/tests/testsuite/cargo_features.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::ChannelChanger; use cargotest::support::{project, execs}; use hamcrest::assert_that; diff --git a/tests/cargotest/Cargo.toml b/tests/testsuite/cargotest/Cargo.toml similarity index 92% rename from tests/cargotest/Cargo.toml rename to tests/testsuite/cargotest/Cargo.toml index ee9770a38..a4a7c7e7f 100644 --- a/tests/cargotest/Cargo.toml +++ b/tests/testsuite/cargotest/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Alex Crichton "] path = "lib.rs" [dependencies] -cargo = { path = "../.." } +cargo = { path = "../../.." } filetime = "0.1" flate2 = "1.0" git2 = { version = "0.6", default-features = false } diff --git a/tests/cargotest/install.rs b/tests/testsuite/cargotest/install.rs similarity index 100% rename from tests/cargotest/install.rs rename to tests/testsuite/cargotest/install.rs diff --git a/tests/cargotest/lib.rs b/tests/testsuite/cargotest/lib.rs similarity index 100% rename from tests/cargotest/lib.rs rename to tests/testsuite/cargotest/lib.rs diff --git a/tests/cargotest/support/cross_compile.rs b/tests/testsuite/cargotest/support/cross_compile.rs similarity index 100% rename from tests/cargotest/support/cross_compile.rs rename to tests/testsuite/cargotest/support/cross_compile.rs diff --git a/tests/cargotest/support/git.rs b/tests/testsuite/cargotest/support/git.rs similarity index 100% rename from tests/cargotest/support/git.rs rename to tests/testsuite/cargotest/support/git.rs diff --git a/tests/cargotest/support/mod.rs b/tests/testsuite/cargotest/support/mod.rs similarity index 100% rename from tests/cargotest/support/mod.rs rename to tests/testsuite/cargotest/support/mod.rs diff --git a/tests/cargotest/support/paths.rs b/tests/testsuite/cargotest/support/paths.rs similarity index 100% rename from tests/cargotest/support/paths.rs rename to tests/testsuite/cargotest/support/paths.rs diff --git a/tests/cargotest/support/publish.rs b/tests/testsuite/cargotest/support/publish.rs similarity index 100% rename from tests/cargotest/support/publish.rs rename to tests/testsuite/cargotest/support/publish.rs diff --git a/tests/cargotest/support/registry.rs b/tests/testsuite/cargotest/support/registry.rs similarity index 100% rename from tests/cargotest/support/registry.rs rename to tests/testsuite/cargotest/support/registry.rs diff --git a/tests/cfg.rs b/tests/testsuite/cfg.rs similarity index 99% rename from tests/cfg.rs rename to tests/testsuite/cfg.rs index 370ae36f7..dbdbddcac 100644 --- a/tests/cfg.rs +++ b/tests/testsuite/cfg.rs @@ -1,7 +1,3 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; - use std::str::FromStr; use std::fmt; diff --git a/tests/check-style.sh b/tests/testsuite/check-style.sh similarity index 100% rename from tests/check-style.sh rename to tests/testsuite/check-style.sh diff --git a/tests/check.rs b/tests/testsuite/check.rs similarity index 99% rename from tests/check.rs rename to tests/testsuite/check.rs index 2f0ea0f4e..864dc2cf7 100644 --- a/tests/check.rs +++ b/tests/testsuite/check.rs @@ -1,7 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; -extern crate glob; - use cargotest::is_nightly; use cargotest::support::{execs, project}; use cargotest::support::registry::Package; diff --git a/tests/clean.rs b/tests/testsuite/clean.rs similarity index 99% rename from tests/clean.rs rename to tests/testsuite/clean.rs index 0cf552371..bc701a8e2 100644 --- a/tests/clean.rs +++ b/tests/testsuite/clean.rs @@ -1,6 +1,3 @@ -extern crate hamcrest; -extern crate cargotest; - use std::env; use cargotest::support::{git, project, execs, main_file, basic_bin_manifest}; diff --git a/tests/concurrent.rs b/tests/testsuite/concurrent.rs similarity index 99% rename from tests/concurrent.rs rename to tests/testsuite/concurrent.rs index 27ad4b27e..1829cfa15 100644 --- a/tests/concurrent.rs +++ b/tests/testsuite/concurrent.rs @@ -1,7 +1,3 @@ -extern crate cargotest; -extern crate git2; -extern crate hamcrest; - use std::{env, str}; use std::fs::{self, File}; use std::io::Write; @@ -11,6 +7,8 @@ use std::thread; use std::sync::mpsc::channel; use std::time::Duration; +use git2; +use cargotest; use cargotest::install::{has_installed_exe, cargo_home}; use cargotest::support::git; use cargotest::support::registry::Package; diff --git a/tests/config.rs b/tests/testsuite/config.rs similarity index 93% rename from tests/config.rs rename to tests/testsuite/config.rs index 89226ce12..92b76d527 100644 --- a/tests/config.rs +++ b/tests/testsuite/config.rs @@ -1,6 +1,3 @@ -extern crate hamcrest; -extern crate cargotest; - use cargotest::support::{project, execs}; use hamcrest::assert_that; diff --git a/tests/cross-compile.rs b/tests/testsuite/cross_compile.rs similarity index 99% rename from tests/cross-compile.rs rename to tests/testsuite/cross_compile.rs index cdb55f307..080112e89 100644 --- a/tests/cross-compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -1,7 +1,3 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; - use cargo::util::process; use cargotest::{is_nightly, rustc_host}; use cargotest::support::{project, execs, basic_bin_manifest, cross_compile}; diff --git a/tests/cross-publish.rs b/tests/testsuite/cross_publish.rs similarity index 96% rename from tests/cross-publish.rs rename to tests/testsuite/cross_publish.rs index b971d45a8..5c9545fce 100644 --- a/tests/cross-publish.rs +++ b/tests/testsuite/cross_publish.rs @@ -1,9 +1,3 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; -extern crate flate2; -extern crate tar; - use std::fs::File; use std::path::PathBuf; use std::io::prelude::*; diff --git a/tests/death.rs b/tests/testsuite/death.rs similarity index 98% rename from tests/death.rs rename to tests/testsuite/death.rs index 3f80e406c..e520c4dcd 100644 --- a/tests/death.rs +++ b/tests/testsuite/death.rs @@ -1,8 +1,3 @@ -extern crate cargotest; -extern crate libc; -#[cfg(windows)] -extern crate winapi; - use std::fs; use std::io::{self, Read}; use std::net::TcpListener; diff --git a/tests/dep-info.rs b/tests/testsuite/dep_info.rs similarity index 97% rename from tests/dep-info.rs rename to tests/testsuite/dep_info.rs index f2f1f82e0..5bf0bf6ad 100644 --- a/tests/dep-info.rs +++ b/tests/testsuite/dep_info.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{basic_bin_manifest, main_file, execs, project}; use hamcrest::{assert_that, existing_file}; diff --git a/tests/directory.rs b/tests/testsuite/directory.rs similarity index 99% rename from tests/directory.rs rename to tests/testsuite/directory.rs index 17c17c143..47a6173e4 100644 --- a/tests/directory.rs +++ b/tests/testsuite/directory.rs @@ -1,10 +1,4 @@ -#[macro_use] -extern crate cargotest; -extern crate hamcrest; -#[macro_use] -extern crate serde_derive; -extern crate serde_json; - +use serde_json; use std::collections::HashMap; use std::fs::{self, File}; use std::io::prelude::*; diff --git a/tests/doc.rs b/tests/testsuite/doc.rs similarity index 99% rename from tests/doc.rs rename to tests/testsuite/doc.rs index 1464bdc62..401064c3b 100644 --- a/tests/doc.rs +++ b/tests/testsuite/doc.rs @@ -1,7 +1,4 @@ -extern crate cargotest; -extern crate hamcrest; -extern crate cargo; - +use cargotest; use std::str; use std::fs::{self, File}; use std::io::Read; diff --git a/tests/features.rs b/tests/testsuite/features.rs similarity index 99% rename from tests/features.rs rename to tests/testsuite/features.rs index 0eae4380b..465455723 100644 --- a/tests/features.rs +++ b/tests/testsuite/features.rs @@ -1,7 +1,3 @@ -#[macro_use] -extern crate cargotest; -extern crate hamcrest; - use std::fs::File; use std::io::prelude::*; diff --git a/tests/fetch.rs b/tests/testsuite/fetch.rs similarity index 90% rename from tests/fetch.rs rename to tests/testsuite/fetch.rs index 8c5e9a59d..880c57ebd 100644 --- a/tests/fetch.rs +++ b/tests/testsuite/fetch.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{project, execs}; use hamcrest::assert_that; diff --git a/tests/freshness.rs b/tests/testsuite/freshness.rs similarity index 99% rename from tests/freshness.rs rename to tests/testsuite/freshness.rs index ff127a4f5..6a160eb62 100644 --- a/tests/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::fs::{self, File}; use std::io::prelude::*; diff --git a/tests/generate-lockfile.rs b/tests/testsuite/generate_lockfile.rs similarity index 99% rename from tests/generate-lockfile.rs rename to tests/testsuite/generate_lockfile.rs index 2a6459602..30b2651bc 100644 --- a/tests/generate-lockfile.rs +++ b/tests/testsuite/generate_lockfile.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::fs::{self, File}; use std::io::prelude::*; diff --git a/tests/git.rs b/tests/testsuite/git.rs similarity index 99% rename from tests/git.rs rename to tests/testsuite/git.rs index 3fa90093f..13bffe055 100644 --- a/tests/git.rs +++ b/tests/testsuite/git.rs @@ -1,8 +1,4 @@ -extern crate cargo; -extern crate cargotest; -extern crate git2; -extern crate hamcrest; - +use git2; use std::fs::{self, File}; use std::io::prelude::*; use std::net::{TcpListener, TcpStream}; diff --git a/tests/init.rs b/tests/testsuite/init.rs similarity index 99% rename from tests/init.rs rename to tests/testsuite/init.rs index c0b3fcd75..5aebd1e69 100644 --- a/tests/init.rs +++ b/tests/testsuite/init.rs @@ -1,8 +1,4 @@ -extern crate cargotest; -extern crate cargo; -extern crate tempdir; -extern crate hamcrest; - +use cargotest; use std::fs::{self, File}; use std::io::prelude::*; use std::env; diff --git a/tests/install.rs b/tests/testsuite/install.rs similarity index 99% rename from tests/install.rs rename to tests/testsuite/install.rs index 1ae6806c4..c3da7daa0 100644 --- a/tests/install.rs +++ b/tests/testsuite/install.rs @@ -1,7 +1,4 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; - +use cargotest; use std::fs::{self, File, OpenOptions}; use std::io::prelude::*; diff --git a/tests/jobserver.rs b/tests/testsuite/jobserver.rs similarity index 99% rename from tests/jobserver.rs rename to tests/testsuite/jobserver.rs index 6803f3fbe..290f9d7ee 100644 --- a/tests/jobserver.rs +++ b/tests/testsuite/jobserver.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::net::TcpListener; use std::thread; use std::process::Command; diff --git a/tests/testsuite/lib.rs b/tests/testsuite/lib.rs new file mode 100644 index 000000000..6c26e3a2c --- /dev/null +++ b/tests/testsuite/lib.rs @@ -0,0 +1,82 @@ +extern crate cargo; +#[macro_use] +extern crate cargotest; +extern crate hamcrest; +extern crate tempdir; +extern crate bufstream; +extern crate git2; +extern crate glob; +extern crate flate2; +extern crate tar; +extern crate libc; +#[cfg(windows)] +extern crate winapi; +#[macro_use] +extern crate serde_derive; +extern crate serde_json; +extern crate toml; +extern crate url; + + +mod alt_registry; +mod bad_config; +mod bad_manifest_path; +mod bench; +mod build_auth; +mod build_lib; +mod build; +mod build_script_env; +mod build_script; +mod cargo_alias_config; +mod cargo_features; +//mod cargo; +mod cfg; +mod check; +mod clean; +mod concurrent; +mod config; +mod cross_compile; +mod cross_publish; +mod death; +mod dep_info; +mod directory; +mod doc; +mod features; +mod fetch; +mod freshness; +mod generate_lockfile; +mod git; +mod init; +mod install; +mod jobserver; +mod local_registry; +mod lockfile_compat; +mod login; +mod metadata; +mod net_config; +mod new; +mod overrides; +mod package; +mod patch; +mod path; +mod plugins; +mod proc_macro; +mod profiles; +mod publish; +mod read_manifest; +mod registry; +mod required_features; +mod resolve; +mod run; +mod rustc; +mod rustdocflags; +mod rustdoc; +mod rustflags; +mod search; +mod small_fd_limits; +mod test; +mod tool_paths; +mod verify_project; +mod version; +mod warn_on_failure; +mod workspaces; diff --git a/tests/local-registry.rs b/tests/testsuite/local_registry.rs similarity index 99% rename from tests/local-registry.rs rename to tests/testsuite/local_registry.rs index 99e529b83..6bafed933 100644 --- a/tests/local-registry.rs +++ b/tests/testsuite/local_registry.rs @@ -1,7 +1,3 @@ -#[macro_use] -extern crate cargotest; -extern crate hamcrest; - use std::fs::{self, File}; use std::io::prelude::*; diff --git a/tests/lockfile-compat.rs b/tests/testsuite/lockfile_compat.rs similarity index 99% rename from tests/lockfile-compat.rs rename to tests/testsuite/lockfile_compat.rs index c8a16aa2e..8cf4f789c 100644 --- a/tests/lockfile-compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::git; use cargotest::support::registry::Package; use cargotest::support::{execs, project, lines_match}; diff --git a/tests/login.rs b/tests/testsuite/login.rs similarity index 98% rename from tests/login.rs rename to tests/testsuite/login.rs index a91bf553f..ffe8e5c36 100644 --- a/tests/login.rs +++ b/tests/testsuite/login.rs @@ -1,12 +1,7 @@ -#[macro_use] -extern crate cargotest; -extern crate cargo; -extern crate hamcrest; -extern crate toml; - use std::io::prelude::*; use std::fs::{self, File}; +use toml; use cargotest::{ChannelChanger, cargo_process}; use cargotest::support::execs; use cargotest::support::registry::registry; diff --git a/tests/metadata.rs b/tests/testsuite/metadata.rs similarity index 99% rename from tests/metadata.rs rename to tests/testsuite/metadata.rs index b3c99fd17..5cf011355 100644 --- a/tests/metadata.rs +++ b/tests/testsuite/metadata.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use hamcrest::assert_that; use cargotest::support::registry::Package; use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest, main_file}; diff --git a/tests/net-config.rs b/tests/testsuite/net_config.rs similarity index 96% rename from tests/net-config.rs rename to tests/testsuite/net_config.rs index aeaacafc7..37d9f4aaa 100644 --- a/tests/net-config.rs +++ b/tests/testsuite/net_config.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{project, execs}; use hamcrest::assert_that; diff --git a/tests/new.rs b/tests/testsuite/new.rs similarity index 99% rename from tests/new.rs rename to tests/testsuite/new.rs index 46def76c0..134cc7244 100644 --- a/tests/new.rs +++ b/tests/testsuite/new.rs @@ -1,12 +1,8 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; -extern crate tempdir; - use std::fs::{self, File}; use std::io::prelude::*; use std::env; +use cargotest; use cargo::util::ProcessBuilder; use cargotest::process; use cargotest::support::{execs, paths}; diff --git a/tests/overrides.rs b/tests/testsuite/overrides.rs similarity index 99% rename from tests/overrides.rs rename to tests/testsuite/overrides.rs index afcd94190..3a16004a4 100644 --- a/tests/overrides.rs +++ b/tests/testsuite/overrides.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::git; use cargotest::support::paths; use cargotest::support::registry::Package; diff --git a/tests/package.rs b/tests/testsuite/package.rs similarity index 99% rename from tests/package.rs rename to tests/testsuite/package.rs index ca35e624b..425e73019 100644 --- a/tests/package.rs +++ b/tests/testsuite/package.rs @@ -1,14 +1,9 @@ -#[macro_use] -extern crate cargotest; -extern crate flate2; -extern crate git2; -extern crate hamcrest; -extern crate tar; - +use std; use std::fs::File; use std::io::prelude::*; use std::path::{Path, PathBuf}; +use git2; use cargotest::{cargo_process, process, ChannelChanger}; use cargotest::support::{project, execs, paths, git, path2url, cargo_exe, registry}; use cargotest::support::registry::Package; diff --git a/tests/patch.rs b/tests/testsuite/patch.rs similarity index 99% rename from tests/patch.rs rename to tests/testsuite/patch.rs index c7f6bc1ab..47ca00320 100644 --- a/tests/patch.rs +++ b/tests/testsuite/patch.rs @@ -1,11 +1,7 @@ -#[macro_use] -extern crate cargotest; -extern crate hamcrest; -extern crate toml; - use std::fs::{self, File}; use std::io::{Read, Write}; +use toml; use cargotest::support::git; use cargotest::support::paths; use cargotest::support::registry::Package; diff --git a/tests/path.rs b/tests/testsuite/path.rs similarity index 99% rename from tests/path.rs rename to tests/testsuite/path.rs index 5a2ebab19..03fc05d53 100644 --- a/tests/path.rs +++ b/tests/testsuite/path.rs @@ -1,12 +1,8 @@ -extern crate cargo; -#[macro_use] -extern crate cargotest; -extern crate hamcrest; - use std::fs::{self, File}; use std::io::prelude::*; use cargo::util::process; +use cargotest; use cargotest::sleep_ms; use cargotest::support::paths::{self, CargoPathExt}; use cargotest::support::{project, execs, main_file}; diff --git a/tests/plugins.rs b/tests/testsuite/plugins.rs similarity index 99% rename from tests/plugins.rs rename to tests/testsuite/plugins.rs index b464b945f..ac010ddc9 100644 --- a/tests/plugins.rs +++ b/tests/testsuite/plugins.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::fs; use std::env; diff --git a/tests/proc-macro.rs b/tests/testsuite/proc_macro.rs similarity index 99% rename from tests/proc-macro.rs rename to tests/testsuite/proc_macro.rs index 953523ac6..eb5c62e14 100644 --- a/tests/proc-macro.rs +++ b/tests/testsuite/proc_macro.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::is_nightly; use cargotest::support::{project, execs}; use hamcrest::assert_that; diff --git a/tests/profiles.rs b/tests/testsuite/profiles.rs similarity index 99% rename from tests/profiles.rs rename to tests/testsuite/profiles.rs index b051f1147..5f8298752 100644 --- a/tests/profiles.rs +++ b/tests/testsuite/profiles.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::env; use cargotest::is_nightly; diff --git a/tests/publish.rs b/tests/testsuite/publish.rs similarity index 99% rename from tests/publish.rs rename to tests/testsuite/publish.rs index 334ade227..38e3b06ec 100644 --- a/tests/publish.rs +++ b/tests/testsuite/publish.rs @@ -1,8 +1,3 @@ -extern crate cargotest; -extern crate flate2; -extern crate hamcrest; -extern crate tar; - use std::io::prelude::*; use std::fs::{self, File}; use std::io::SeekFrom; diff --git a/tests/read-manifest.rs b/tests/testsuite/read_manifest.rs similarity index 98% rename from tests/read-manifest.rs rename to tests/testsuite/read_manifest.rs index 41ed14204..010b5bfbc 100644 --- a/tests/read-manifest.rs +++ b/tests/testsuite/read_manifest.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{project, execs, main_file, basic_bin_manifest}; use hamcrest::{assert_that}; diff --git a/tests/registry.rs b/tests/testsuite/registry.rs similarity index 99% rename from tests/registry.rs rename to tests/testsuite/registry.rs index 89c879a00..a7e8df69f 100644 --- a/tests/registry.rs +++ b/tests/testsuite/registry.rs @@ -1,8 +1,3 @@ -#[macro_use] -extern crate cargotest; -extern crate hamcrest; -extern crate url; - use std::fs::{self, File}; use std::io::prelude::*; use std::path::PathBuf; diff --git a/tests/required-features.rs b/tests/testsuite/required_features.rs similarity index 99% rename from tests/required-features.rs rename to tests/testsuite/required_features.rs index 233f7f6f5..c99ff6a5c 100644 --- a/tests/required-features.rs +++ b/tests/testsuite/required_features.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::is_nightly; use cargotest::install::{cargo_home, has_installed_exe}; use cargotest::support::{project, execs}; diff --git a/tests/resolve.rs b/tests/testsuite/resolve.rs similarity index 99% rename from tests/resolve.rs rename to tests/testsuite/resolve.rs index f2a6b6dfb..a38decc68 100644 --- a/tests/resolve.rs +++ b/tests/testsuite/resolve.rs @@ -1,8 +1,5 @@ #![deny(warnings)] -extern crate hamcrest; -extern crate cargo; - use std::collections::BTreeMap; use hamcrest::{assert_that, equal_to, contains, not}; diff --git a/tests/run.rs b/tests/testsuite/run.rs similarity index 99% rename from tests/run.rs rename to tests/testsuite/run.rs index 96a7bb02d..793ade044 100644 --- a/tests/run.rs +++ b/tests/testsuite/run.rs @@ -1,7 +1,3 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; - use cargo::util::paths::dylib_path_envvar; use cargotest::support::{project, execs, path2url}; use hamcrest::{assert_that, existing_file}; diff --git a/tests/rustc.rs b/tests/testsuite/rustc.rs similarity index 99% rename from tests/rustc.rs rename to tests/testsuite/rustc.rs index da6aced75..7cc037c25 100644 --- a/tests/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{execs, project}; use hamcrest::assert_that; diff --git a/tests/rustdoc.rs b/tests/testsuite/rustdoc.rs similarity index 99% rename from tests/rustdoc.rs rename to tests/testsuite/rustdoc.rs index 570ce6ad8..2e5224f3b 100644 --- a/tests/rustdoc.rs +++ b/tests/testsuite/rustdoc.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{execs, project}; use hamcrest::{assert_that}; diff --git a/tests/rustdocflags.rs b/tests/testsuite/rustdocflags.rs similarity index 98% rename from tests/rustdocflags.rs rename to tests/testsuite/rustdocflags.rs index 19c496426..dc379ad42 100644 --- a/tests/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{project, execs}; use hamcrest::assert_that; diff --git a/tests/rustflags.rs b/tests/testsuite/rustflags.rs similarity index 99% rename from tests/rustflags.rs rename to tests/testsuite/rustflags.rs index ff8fe0aac..05e6c0b64 100644 --- a/tests/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use std::io::Write; use std::fs::{self, File}; diff --git a/tests/search.rs b/tests/testsuite/search.rs similarity index 99% rename from tests/search.rs rename to tests/testsuite/search.rs index 4b407739c..70e00f9cb 100644 --- a/tests/search.rs +++ b/tests/testsuite/search.rs @@ -1,13 +1,9 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; -extern crate url; - use std::fs::{self, File}; use std::io::prelude::*; use std::path::PathBuf; use cargo::util::ProcessBuilder; +use cargotest; use cargotest::support::execs; use cargotest::support::git::repo; use cargotest::support::paths; diff --git a/tests/small-fd-limits.rs b/tests/testsuite/small_fd_limits.rs similarity index 97% rename from tests/small-fd-limits.rs rename to tests/testsuite/small_fd_limits.rs index e997f76fd..53a2dae8c 100644 --- a/tests/small-fd-limits.rs +++ b/tests/testsuite/small_fd_limits.rs @@ -1,13 +1,9 @@ -extern crate cargotest; -extern crate git2; -extern crate hamcrest; -extern crate url; - use std::env; use std::ffi::OsStr; use std::path::PathBuf; use std::process::Command; +use git2; use cargotest::support::{execs, project}; use cargotest::support::registry::Package; use cargotest::support::paths; diff --git a/tests/test.rs b/tests/testsuite/test.rs similarity index 99% rename from tests/test.rs rename to tests/testsuite/test.rs index 2a454f043..914a06d31 100644 --- a/tests/test.rs +++ b/tests/testsuite/test.rs @@ -1,11 +1,8 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; - use std::fs::File; use std::io::prelude::*; use std::str; +use cargo; use cargotest::{sleep_ms, is_nightly, rustc_host}; use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest, cargo_exe}; use cargotest::support::paths::CargoPathExt; diff --git a/tests/tool-paths.rs b/tests/testsuite/tool_paths.rs similarity index 99% rename from tests/tool-paths.rs rename to tests/testsuite/tool_paths.rs index 0d3b5d299..f76790ae1 100644 --- a/tests/tool-paths.rs +++ b/tests/testsuite/tool_paths.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::rustc_host; use cargotest::support::{path2url, project, execs}; use hamcrest::assert_that; diff --git a/tests/verify-project.rs b/tests/testsuite/verify_project.rs similarity index 97% rename from tests/verify-project.rs rename to tests/testsuite/verify_project.rs index 509367ad8..ef99f5fc1 100644 --- a/tests/verify-project.rs +++ b/tests/testsuite/verify_project.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{project, execs, main_file, basic_bin_manifest}; use hamcrest::{assert_that}; diff --git a/tests/version.rs b/tests/testsuite/version.rs similarity index 94% rename from tests/version.rs rename to tests/testsuite/version.rs index a63d8700b..d9868f222 100644 --- a/tests/version.rs +++ b/tests/testsuite/version.rs @@ -1,7 +1,4 @@ -extern crate cargo; -extern crate cargotest; -extern crate hamcrest; - +use cargo; use cargotest::support::{project, execs}; use hamcrest::assert_that; diff --git a/tests/warn-on-failure.rs b/tests/testsuite/warn_on_failure.rs similarity index 98% rename from tests/warn-on-failure.rs rename to tests/testsuite/warn_on_failure.rs index bbd418df6..e6d2a61db 100644 --- a/tests/warn-on-failure.rs +++ b/tests/testsuite/warn_on_failure.rs @@ -1,6 +1,3 @@ -extern crate cargotest; -extern crate hamcrest; - use cargotest::support::{project, execs, Project}; use cargotest::support::registry::Package; use hamcrest::assert_that; diff --git a/tests/workspaces.rs b/tests/testsuite/workspaces.rs similarity index 99% rename from tests/workspaces.rs rename to tests/testsuite/workspaces.rs index 77df97448..1d2bf33fc 100644 --- a/tests/workspaces.rs +++ b/tests/testsuite/workspaces.rs @@ -1,7 +1,3 @@ -#[macro_use] -extern crate cargotest; -extern crate hamcrest; - use std::env; use std::fs::{self, File}; use std::io::{Read, Write}; From 98f17bcc5608129e94855cf1e3637509dee549b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Rocha?= Date: Thu, 8 Feb 2018 17:30:58 +0100 Subject: [PATCH 16/17] Adding cargo.rs file tests as cargo_command.rs. --- tests/testsuite/{cargo.rs => cargo_command.rs} | 1 + tests/testsuite/lib.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename tests/testsuite/{cargo.rs => cargo_command.rs} (99%) diff --git a/tests/testsuite/cargo.rs b/tests/testsuite/cargo_command.rs similarity index 99% rename from tests/testsuite/cargo.rs rename to tests/testsuite/cargo_command.rs index fdcb237af..8ca737c7d 100644 --- a/tests/testsuite/cargo.rs +++ b/tests/testsuite/cargo_command.rs @@ -4,6 +4,7 @@ use std::io::prelude::*; use std::path::{Path, PathBuf}; use std::str; +use cargo; use cargotest::cargo_process; use cargotest::support::paths::{self, CargoPathExt}; use cargotest::support::{execs, project, Project, basic_bin_manifest}; diff --git a/tests/testsuite/lib.rs b/tests/testsuite/lib.rs index 6c26e3a2c..3a2e33b11 100644 --- a/tests/testsuite/lib.rs +++ b/tests/testsuite/lib.rs @@ -29,7 +29,7 @@ mod build_script_env; mod build_script; mod cargo_alias_config; mod cargo_features; -//mod cargo; +mod cargo_command; mod cfg; mod check; mod clean; From 7a564576f193064fb8d900f190802c80d2812bb4 Mon Sep 17 00:00:00 2001 From: Eh2406 Date: Wed, 21 Feb 2018 14:26:29 -0500 Subject: [PATCH 17/17] fix winapi import --- tests/testsuite/death.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testsuite/death.rs b/tests/testsuite/death.rs index e520c4dcd..9a7d69bf1 100644 --- a/tests/testsuite/death.rs +++ b/tests/testsuite/death.rs @@ -28,8 +28,8 @@ fn enabled() -> bool { let me = processthreadsapi::GetCurrentProcess(); let mut ret = 0; let r = jobapi::IsProcessInJob(me, 0 as *mut _, &mut ret); - assert!(r != 0); - if ret == winapi::shared::minwindef::FALSE { + assert_ne!(r, 0); + if ret == ::winapi::shared::minwindef::FALSE { return true }