diff --git a/.gitignore b/.gitignore index e0d63ba2e18..df490beb2f3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ src/registry/Cargo.lock rustc __pycache__ .idea/ -*.iml \ No newline at end of file +*.iml +*.swp diff --git a/src/bin/bench.rs b/src/bin/bench.rs index ff1e0b4e7ba..d164c7a81b6 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -1,3 +1,5 @@ +use std::env; + use cargo::core::Workspace; use cargo::ops::{self, MessageFormat, Packages}; use cargo::util::{CliResult, CliError, Config, CargoErrorKind}; @@ -88,17 +90,23 @@ Compilation can be customized with the `bench` profile in the manifest. "; pub fn execute(options: Options, config: &Config) -> CliResult { - let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; - - let spec = Packages::from_flags(options.flag_all, - &options.flag_exclude, - &options.flag_package)?; + debug!("executing; cmd=cargo-bench; args={:?}", + env::args().collect::>()); config.configure(options.flag_verbose, options.flag_quiet, &options.flag_color, options.flag_frozen, options.flag_locked)?; + + let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; + + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, + &options.flag_exclude, + &options.flag_package)?; + let ops = ops::TestOptions { no_run: options.flag_no_run, no_fail_fast: options.flag_no_fail_fast, @@ -124,7 +132,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { }, }; - let ws = Workspace::new(&root, config)?; let err = ops::run_benches(&ws, &ops, &options.arg_args)?; match err { None => Ok(()), diff --git a/src/bin/build.rs b/src/bin/build.rs index c679fc50f06..04a108a4030 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -92,8 +92,10 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_locked)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; - let spec = Packages::from_flags(options.flag_all, + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, &options.flag_exclude, &options.flag_package)?; @@ -117,7 +119,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { target_rustc_args: None, }; - let ws = Workspace::new(&root, config)?; ops::compile(&ws, &opts)?; Ok(()) } diff --git a/src/bin/check.rs b/src/bin/check.rs index fd36f542000..ed4942de61c 100644 --- a/src/bin/check.rs +++ b/src/bin/check.rs @@ -91,7 +91,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; let ws = Workspace::new(&root, config)?; - let spec = Packages::from_flags(options.flag_all, + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, &options.flag_exclude, &options.flag_package)?; diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 6b4190985df..25aa0ec8a49 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -1,3 +1,5 @@ +use std::env; + use cargo::core::Workspace; use cargo::ops::{self, MessageFormat, Packages}; use cargo::util::{CliResult, Config}; @@ -69,6 +71,9 @@ the `cargo help pkgid` command. "; pub fn execute(options: Options, config: &Config) -> CliResult { + debug!("executing; cmd=cargo-check; args={:?}", + env::args().collect::>()); + config.configure(options.flag_verbose, options.flag_quiet, &options.flag_color, @@ -76,8 +81,9 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_locked)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; - let spec = if options.flag_all { + let spec = if options.flag_all || (ws.is_virtual() && options.flag_package.is_empty()) { Packages::All } else { Packages::Packages(&options.flag_package) @@ -109,7 +115,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { }, }; - let ws = Workspace::new(&root, config)?; ops::doc(&ws, &doc_opts)?; Ok(()) } diff --git a/src/bin/test.rs b/src/bin/test.rs index fe8d5757f8c..7010fbad441 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -1,3 +1,5 @@ +use std::env; + use cargo::core::Workspace; use cargo::ops::{self, MessageFormat, Packages}; use cargo::util::{CliResult, CliError, Config, CargoErrorKind}; @@ -109,6 +111,9 @@ To get the list of all options available for the test binaries use this: "; pub fn execute(options: Options, config: &Config) -> CliResult { + debug!("executing; cmd=cargo-test; args={:?}", + env::args().collect::>()); + config.configure(options.flag_verbose, options.flag_quiet, &options.flag_color, @@ -116,6 +121,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult { options.flag_locked)?; let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; + let ws = Workspace::new(&root, config)?; let empty = Vec::new(); let (mode, filter); @@ -132,7 +138,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bench, options.flag_benches); } - let spec = Packages::from_flags(options.flag_all, + let spec = Packages::from_flags(ws.is_virtual(), + options.flag_all, &options.flag_exclude, &options.flag_package)?; @@ -157,7 +164,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult { }, }; - let ws = Workspace::new(&root, config)?; let err = ops::run_tests(&ws, &ops, &options.arg_args)?; match err { None => Ok(()), diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 5f93baa856b..ad53fc5b5c9 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -179,6 +179,13 @@ impl<'cfg> Workspace<'cfg> { } } + pub fn is_virtual(&self) -> bool { + match *self.packages.get(&self.current_manifest) { + MaybePackage::Package(..) => false, + MaybePackage::Virtual(..) => true + } + } + /// Returns the `Config` this workspace is associated with. pub fn config(&self) -> &'cfg Config { self.config diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index de2cc1e2b56..c1b0243e786 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -110,9 +110,11 @@ pub enum Packages<'a> { } impl<'a> Packages<'a> { - pub fn from_flags(all: bool, exclude: &'a Vec, package: &'a Vec) + pub fn from_flags(virtual_ws: bool, all: bool, exclude: &'a Vec, package: &'a Vec) -> CargoResult { + let all = all || (virtual_ws && package.is_empty()); + let packages = match (all, &exclude) { (true, exclude) if exclude.is_empty() => Packages::All, (true, exclude) => Packages::OptOut(exclude), diff --git a/tests/bench.rs b/tests/bench.rs index cf68a629eee..56cc52f6e3d 100644 --- a/tests/bench.rs +++ b/tests/bench.rs @@ -1189,3 +1189,55 @@ fn legacy_bench_name() { [WARNING] path `[..]src[/]bench.rs` was erroneously implicitly accepted for benchmark `bench`, please set bench.path in Cargo.toml")); } + +#[test] +fn bench_virtual_manifest_all_implied() { + if !is_nightly() { return } + + let p = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["foo", "bar"] + "#) + .file("foo/Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + "#) + .file("foo/src/lib.rs", r#" + pub fn foo() {} + "#) + .file("foo/benches/foo.rs", r#" + #![feature(test)] + extern crate test; + use test::Bencher; + #[bench] + fn bench_foo(_: &mut Bencher) -> () { () } + "#) + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#) + .file("bar/benches/bar.rs", r#" + #![feature(test)] + extern crate test; + use test::Bencher; + #[bench] + fn bench_bar(_: &mut Bencher) -> () { () } + "#); + + // The order in which foo and bar are built is not guaranteed + + assert_that(p.cargo_process("bench"), + execs().with_status(0) + .with_stderr_contains("\ +[RUNNING] target[/]release[/]deps[/]bar-[..][EXE]") + .with_stdout_contains("test bench_bar ... bench: [..]") + .with_stderr_contains("\ +[RUNNING] target[/]release[/]deps[/]foo-[..][EXE]") + .with_stdout_contains("test bench_foo ... bench: [..]")); +} diff --git a/tests/build.rs b/tests/build.rs index f3e9445f8e3..2f82def40ee 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -3038,6 +3038,73 @@ fn build_all_virtual_manifest() { [..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n")); } +#[test] +fn build_virtual_manifest_all_implied() { + let p = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["foo", "bar"] + "#) + .file("foo/Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + "#) + .file("foo/src/lib.rs", r#" + pub fn foo() {} + "#) + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); + + // The order in which foo and bar are built is not guaranteed + assert_that(p.cargo_process("build"), + execs().with_status(0) + .with_stderr_contains("[..] Compiling bar v0.1.0 ([..])") + .with_stderr_contains("[..] Compiling foo v0.1.0 ([..])") + .with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\ + [..] Compiling [..] v0.1.0 ([..])\n\ + [..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n")); +} + +#[test] +fn build_virtual_manifest_one_project() { + let p = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["foo", "bar"] + "#) + .file("foo/Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + "#) + .file("foo/src/lib.rs", r#" + pub fn foo() {} + "#) + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); + + assert_that(p.cargo_process("build") + .arg("-p").arg("foo"), + execs().with_status(0) + .with_stderr_does_not_contain("bar") + .with_stderr_contains("[..] Compiling foo v0.1.0 ([..])") + .with_stderr("[..] Compiling [..] v0.1.0 ([..])\n\ + [..] Finished dev [unoptimized + debuginfo] target(s) in [..]\n")); +} + #[test] fn build_all_virtual_manifest_implicit_examples() { let p = project("foo") diff --git a/tests/check.rs b/tests/check.rs index 09ebfb0ac44..d0a0e48fff3 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -393,3 +393,34 @@ fn check_all() { .with_stderr_contains("[..] --crate-name b b[/]src[/]main.rs [..]") ); } + +#[test] +fn check_virtual_all_implied() { + let p = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["foo", "bar"] + "#) + .file("foo/Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + "#) + .file("foo/src/lib.rs", r#" + pub fn foo() {} + "#) + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); + + assert_that(p.cargo_process("check").arg("-v"), + execs().with_status(0) + .with_stderr_contains("[..] --crate-name foo foo[/]src[/]lib.rs [..]") + .with_stderr_contains("[..] --crate-name bar bar[/]src[/]lib.rs [..]") + ); +} diff --git a/tests/doc.rs b/tests/doc.rs index 119b5d32a44..2c322a91709 100644 --- a/tests/doc.rs +++ b/tests/doc.rs @@ -692,6 +692,37 @@ fn doc_all_virtual_manifest() { .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")); } +#[test] +fn doc_virtual_manifest_all_implied() { + let p = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["foo", "bar"] + "#) + .file("foo/Cargo.toml", r#" + [project] + name = "foo" + version = "0.1.0" + "#) + .file("foo/src/lib.rs", r#" + pub fn foo() {} + "#) + .file("bar/Cargo.toml", r#" + [project] + name = "bar" + version = "0.1.0" + "#) + .file("bar/src/lib.rs", r#" + pub fn bar() {} + "#); + + // The order in which foo and bar are documented is not guaranteed + assert_that(p.cargo_process("doc"), + execs().with_status(0) + .with_stderr_contains("[..] Documenting bar v0.1.0 ([..])") + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")); +} + #[test] fn doc_all_member_dependency_same_name() { let p = project("workspace") diff --git a/tests/test.rs b/tests/test.rs index 686157a3247..d0d577d0991 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2455,6 +2455,38 @@ fn test_all_virtual_manifest() { .with_stdout_contains("test b ... ok")); } +#[test] +fn test_virtual_manifest_all_implied() { + let p = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["a", "b"] + "#) + .file("a/Cargo.toml", r#" + [project] + name = "a" + version = "0.1.0" + "#) + .file("a/src/lib.rs", r#" + #[test] + fn a() {} + "#) + .file("b/Cargo.toml", r#" + [project] + name = "b" + version = "0.1.0" + "#) + .file("b/src/lib.rs", r#" + #[test] + fn b() {} + "#); + + assert_that(p.cargo_process("test"), + execs().with_status(0) + .with_stdout_contains("test a ... ok") + .with_stdout_contains("test b ... ok")); +} + #[test] fn test_all_member_dependency_same_name() { let p = project("workspace") diff --git a/tests/workspaces.rs b/tests/workspaces.rs index 4670d28f77a..1228ae28218 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -673,7 +673,7 @@ manifest located at: [..] } #[test] -fn virtual_build() { +fn virtual_build_all_implied() { let p = project("foo") .file("Cargo.toml", r#" [workspace] @@ -688,11 +688,7 @@ fn virtual_build() { .file("bar/src/main.rs", "fn main() {}"); p.build(); assert_that(p.cargo("build"), - execs().with_status(101) - .with_stderr("\ -error: manifest path `[..]` is a virtual manifest, but this command \ -requires running against an actual package in this workspace -")); + execs().with_status(0)); } #[test]