From e7f2374757592ab88142af69fef721f222b634f0 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sun, 11 Jun 2017 06:27:22 +0300 Subject: [PATCH 1/2] Rename Everything to Default to avoid confusion --- src/bin/run.rs | 2 +- src/cargo/ops/cargo_compile.rs | 12 ++++++------ src/cargo/ops/cargo_install.rs | 2 +- src/cargo/ops/cargo_package.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bin/run.rs b/src/bin/run.rs index 96c51bea240..7c65728fc1b 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -92,7 +92,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult { release: options.flag_release, mode: ops::CompileMode::Build, filter: if examples.is_empty() && bins.is_empty() { - ops::CompileFilter::Everything { required_features_filterable: false, } + ops::CompileFilter::Default { required_features_filterable: false, } } else { ops::CompileFilter::new(false, &bins, false, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 888939a2203..71f51572c9a 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -78,7 +78,7 @@ impl<'a> CompileOptions<'a> { spec: ops::Packages::Packages(&[]), mode: mode, release: false, - filter: CompileFilter::Everything { required_features_filterable: false }, + filter: CompileFilter::Default { required_features_filterable: false }, message_format: MessageFormat::Human, target_rustdoc_args: None, target_rustc_args: None, @@ -154,7 +154,7 @@ pub enum FilterRule<'a> { } pub enum CompileFilter<'a> { - Everything { + Default { /// Flag whether targets can be safely skipped when required-features are not satisfied. required_features_filterable: bool, }, @@ -381,7 +381,7 @@ impl<'a> CompileFilter<'a> { tests: rule_tsts, } } else { - CompileFilter::Everything { + CompileFilter::Default { required_features_filterable: true, } } @@ -389,7 +389,7 @@ impl<'a> CompileFilter<'a> { pub fn matches(&self, target: &Target) -> bool { match *self { - CompileFilter::Everything { .. } => true, + CompileFilter::Default { .. } => true, CompileFilter::Only { lib, bins, examples, tests, benches } => { let rule = match *target.kind() { TargetKind::Bin => bins, @@ -407,7 +407,7 @@ impl<'a> CompileFilter<'a> { pub fn is_specific(&self) -> bool { match *self { - CompileFilter::Everything { .. } => false, + CompileFilter::Default { .. } => false, CompileFilter::Only { .. } => true, } } @@ -589,7 +589,7 @@ fn generate_targets<'a>(pkg: &'a Package, }; let targets = match *filter { - CompileFilter::Everything { required_features_filterable } => { + CompileFilter::Default { required_features_filterable } => { let deps = if release { &profiles.bench_deps } else { diff --git a/src/cargo/ops/cargo_install.rs b/src/cargo/ops/cargo_install.rs index ceb67c323c7..9c907ab50fc 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -401,7 +401,7 @@ fn find_duplicates(dst: &Path, } }; match *filter { - CompileFilter::Everything { .. } => { + CompileFilter::Default { .. } => { pkg.targets().iter() .filter(|t| t.is_bin()) .filter_map(|t| check(t.name().to_string())) diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index c46c7b2eeeb..3bccb7c1fa2 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -299,7 +299,7 @@ fn run_verify(ws: &Workspace, tar: &File, opts: &PackageOpts) -> CargoResult<()> no_default_features: false, all_features: false, spec: ops::Packages::Packages(&[]), - filter: ops::CompileFilter::Everything { required_features_filterable: true }, + filter: ops::CompileFilter::Default { required_features_filterable: true }, release: false, message_format: ops::MessageFormat::Human, mode: ops::CompileMode::Build, From 42346b9c47e75bdd2767d918cb7dade5a40f495f Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sun, 11 Jun 2017 06:48:14 +0300 Subject: [PATCH 2/2] cargo check,build,rustc --all-targets `cargo check` does not check all targets by default, and to check all, you need to call it `cargo check --tests --examples --bins --benches`. `cargo check --all-targets` is a shortcut. `--all-targets` is also added to `build` and to `rustc` command. For consitency `--all-targets` added to other commands like `test` although "all targets" is default behavior. --- src/bin/bench.rs | 5 ++++- src/bin/build.rs | 5 ++++- src/bin/check.rs | 5 ++++- src/bin/doc.rs | 3 ++- src/bin/install.rs | 3 ++- src/bin/run.rs | 3 ++- src/bin/rustc.rs | 5 ++++- src/bin/rustdoc.rs | 5 ++++- src/bin/test.rs | 8 ++++++-- src/cargo/ops/cargo_compile.rs | 11 +++++++++-- tests/check.rs | 26 ++++++++++++++++++++++++++ 11 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/bin/bench.rs b/src/bin/bench.rs index c58ff5c087d..73dcccc3dbb 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -26,6 +26,7 @@ pub struct Options { flag_tests: bool, flag_bench: Vec, flag_benches: bool, + flag_all_targets: bool, flag_frozen: bool, flag_locked: bool, arg_args: Vec, @@ -50,6 +51,7 @@ Options: --tests Benchmark all tests --bench NAME Benchmark only the specified bench target --benches Benchmark all benches + --all-targets Benchmark all targets (default) --no-run Compile, but don't run benchmarks -p SPEC, --package SPEC ... Package to run benchmarks for --all Benchmark all packages in the workspace @@ -115,7 +117,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bin, options.flag_bins, &options.flag_test, options.flag_tests, &options.flag_example, options.flag_examples, - &options.flag_bench, options.flag_benches,), + &options.flag_bench, options.flag_benches, + options.flag_all_targets), message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: None, diff --git a/src/bin/build.rs b/src/bin/build.rs index 759c2746646..bf08dde7bb4 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -28,6 +28,7 @@ pub struct Options { flag_tests: bool, flag_bench: Vec, flag_benches: bool, + flag_all_targets: bool, flag_locked: bool, flag_frozen: bool, flag_all: bool, @@ -55,6 +56,7 @@ Options: --tests Build all tests --bench NAME Build only the specified bench target --benches Build all benches + --all-targets Build all targets (lib and bin targets by default) --release Build artifacts in release mode, with optimizations --features FEATURES Space-separated list of features to also build --all-features Build all available features @@ -111,7 +113,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bin, options.flag_bins, &options.flag_test, options.flag_tests, &options.flag_example, options.flag_examples, - &options.flag_bench, options.flag_benches,), + &options.flag_bench, options.flag_benches, + options.flag_all_targets), message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: None, diff --git a/src/bin/check.rs b/src/bin/check.rs index 147ff43b9a9..2cb1063e886 100644 --- a/src/bin/check.rs +++ b/src/bin/check.rs @@ -26,6 +26,7 @@ Options: --tests Check all tests --bench NAME Check only the specified bench target --benches Check all benches + --all-targets Check all targets (lib and bin targets by default) --release Check artifacts in release mode, with optimizations --features FEATURES Space-separated list of features to also check --all-features Check all available features @@ -72,6 +73,7 @@ pub struct Options { flag_tests: bool, flag_bench: Vec, flag_benches: bool, + flag_all_targets: bool, flag_locked: bool, flag_frozen: bool, flag_all: bool, @@ -109,7 +111,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bin, options.flag_bins, &options.flag_test, options.flag_tests, &options.flag_example, options.flag_examples, - &options.flag_bench, options.flag_benches,), + &options.flag_bench, options.flag_benches, + options.flag_all_targets), message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: None, diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 11e44670faf..46ceab48891 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -98,7 +98,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bin, options.flag_bins, &empty, false, &empty, false, - &empty, false), + &empty, false, + false), message_format: options.flag_message_format, release: options.flag_release, mode: ops::CompileMode::Doc { diff --git a/src/bin/install.rs b/src/bin/install.rs index 197dcdd1be0..5e26aac0aa1 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -119,7 +119,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bin, options.flag_bins, &[], false, &options.flag_example, options.flag_examples, - &[], false), + &[], false, + false), message_format: ops::MessageFormat::Human, target_rustc_args: None, target_rustdoc_args: None, diff --git a/src/bin/run.rs b/src/bin/run.rs index 7c65728fc1b..68d2b7fa18d 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -98,7 +98,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &bins, false, &[], false, &examples, false, - &[], false) + &[], false, + false) }, message_format: options.flag_message_format, target_rustdoc_args: None, diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index 3ee18a86234..f08173112bb 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -29,6 +29,7 @@ pub struct Options { flag_tests: bool, flag_bench: Vec, flag_benches: bool, + flag_all_targets: bool, flag_profile: Option, flag_frozen: bool, flag_locked: bool, @@ -53,6 +54,7 @@ Options: --tests Build all tests --bench NAME Build only the specified bench target --benches Build all benches + --all-targets Build all targets (lib and bin targets by default) --release Build artifacts in release mode, with optimizations --profile PROFILE Profile to build the selected target for --features FEATURES Features to compile for the package @@ -120,7 +122,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bin, options.flag_bins, &options.flag_test, options.flag_tests, &options.flag_example, options.flag_examples, - &options.flag_bench, options.flag_benches,), + &options.flag_bench, options.flag_benches, + options.flag_all_targets), message_format: options.flag_message_format, target_rustdoc_args: None, target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]), diff --git a/src/bin/rustdoc.rs b/src/bin/rustdoc.rs index b6a8e640e2b..1248da017c6 100644 --- a/src/bin/rustdoc.rs +++ b/src/bin/rustdoc.rs @@ -28,6 +28,7 @@ pub struct Options { flag_tests: bool, flag_bench: Vec, flag_benches: bool, + flag_all_targets: bool, flag_frozen: bool, flag_locked: bool, } @@ -52,6 +53,7 @@ Options: --tests Build all tests --bench NAME Build only the specified bench target --benches Build all benches + --all-targets Build all targets (default) --release Build artifacts in release mode, with optimizations --features FEATURES Space-separated list of features to also build --all-features Build all available features @@ -105,7 +107,8 @@ pub fn execute(options: Options, config: &Config) -> CliResult { &options.flag_bin, options.flag_bins, &options.flag_test, options.flag_tests, &options.flag_example, options.flag_examples, - &options.flag_bench, options.flag_benches,), + &options.flag_bench, options.flag_benches, + options.flag_all_targets), message_format: options.flag_message_format, mode: ops::CompileMode::Doc { deps: false }, target_rustdoc_args: Some(&options.arg_opts), diff --git a/src/bin/test.rs b/src/bin/test.rs index 5fbae53f373..6c05e298c30 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -24,6 +24,7 @@ pub struct Options { flag_tests: bool, flag_bench: Vec, flag_benches: bool, + flag_all_targets: bool, flag_verbose: u32, flag_quiet: Option, flag_color: Option, @@ -54,6 +55,7 @@ Options: --tests Test all tests --bench NAME ... Test only the specified bench target --benches Test all benches + --all-targets Test all targets (default) --no-run Compile, but don't run tests -p SPEC, --package SPEC ... Package to run tests for --all Test all packages in the workspace @@ -122,14 +124,16 @@ pub fn execute(options: Options, config: &Config) -> CliResult { if options.flag_doc { mode = ops::CompileMode::Doctest; filter = ops::CompileFilter::new(true, &empty, false, &empty, false, - &empty, false, &empty, false); + &empty, false, &empty, false, + false); } else { mode = ops::CompileMode::Test; filter = ops::CompileFilter::new(options.flag_lib, &options.flag_bin, options.flag_bins, &options.flag_test, options.flag_tests, &options.flag_example, options.flag_examples, - &options.flag_bench, options.flag_benches); + &options.flag_bench, options.flag_benches, + options.flag_all_targets); } let spec = Packages::from_flags(options.flag_all, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 71f51572c9a..e75d94b38ae 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -367,13 +367,20 @@ impl<'a> CompileFilter<'a> { bins: &'a [String], all_bins: bool, tsts: &'a [String], all_tsts: bool, exms: &'a [String], all_exms: bool, - bens: &'a [String], all_bens: bool) -> CompileFilter<'a> { + bens: &'a [String], all_bens: bool, + all_targets: bool) -> CompileFilter<'a> { let rule_bins = FilterRule::new(bins, all_bins); let rule_tsts = FilterRule::new(tsts, all_tsts); let rule_exms = FilterRule::new(exms, all_exms); let rule_bens = FilterRule::new(bens, all_bens); - if lib_only || rule_bins.is_specific() || rule_tsts.is_specific() + if all_targets { + CompileFilter::Only { + lib: true, bins: FilterRule::All, + examples: FilterRule::All, benches: FilterRule::All, + tests: FilterRule::All, + } + } else if lib_only || rule_bins.is_specific() || rule_tsts.is_specific() || rule_exms.is_specific() || rule_bens.is_specific() { CompileFilter::Only { lib: lib_only, bins: rule_bins, diff --git a/tests/check.rs b/tests/check.rs index 09ebfb0ac44..b7f23c27663 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -393,3 +393,29 @@ fn check_all() { .with_stderr_contains("[..] --crate-name b b[/]src[/]main.rs [..]") ); } + +#[test] +fn check_all_targets() { + let foo = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", "fn main() {}") + .file("src/lib.rs", "pub fn smth() {}") + .file("examples/example1.rs", "fn main() {}") + .file("tests/test2.rs", "#[test] fn t() {}") + .file("benches/bench3.rs", "") + ; + + assert_that(foo.cargo_process("check").arg("--all-targets").arg("-v"), + execs().with_status(0) + .with_stderr_contains("[..] --crate-name foo src[/]lib.rs [..]") + .with_stderr_contains("[..] --crate-name foo src[/]main.rs [..]") + .with_stderr_contains("[..] --crate-name example1 examples[/]example1.rs [..]") + .with_stderr_contains("[..] --crate-name test2 tests[/]test2.rs [..]") + .with_stderr_contains("[..] --crate-name bench3 benches[/]bench3.rs [..]") + ); +}