diff --git a/src/bin/bench.rs b/src/bin/bench.rs index d164c7a81b6..dcee0049e23 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -28,6 +28,7 @@ pub struct Options { flag_tests: bool, flag_bench: Vec, flag_benches: bool, + flag_all_targets: bool, flag_no_fail_fast: bool, flag_frozen: bool, flag_locked: bool, @@ -53,6 +54,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 @@ -125,7 +127,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 04a108a4030..b0ee43b4ba4 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 @@ -113,7 +115,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 ed4942de61c..262e4aaf859 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, @@ -110,7 +112,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 25aa0ec8a49..517d2b6da15 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -104,7 +104,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 12518926ca9..10ea2d1259c 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 3ff26fc6212..58012cb3469 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -92,13 +92,14 @@ 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, &[], 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 0616e6f5e08..95f6d173b86 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 55ce9c89d61..82de14c00f5 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 7010fbad441..39322feb5f9 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -26,6 +26,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, @@ -56,6 +57,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 @@ -128,14 +130,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(ws.is_virtual(), diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index e4162b81f34..c1931fc0a40 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -80,7 +80,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, @@ -159,7 +159,7 @@ pub enum FilterRule<'a> { #[derive(Debug)] pub enum CompileFilter<'a> { - Everything { + Default { /// Flag whether targets can be safely skipped when required-features are not satisfied. required_features_filterable: bool, }, @@ -379,13 +379,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, @@ -393,7 +400,7 @@ impl<'a> CompileFilter<'a> { tests: rule_tsts, } } else { - CompileFilter::Everything { + CompileFilter::Default { required_features_filterable: true, } } @@ -401,7 +408,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, @@ -419,7 +426,7 @@ impl<'a> CompileFilter<'a> { pub fn is_specific(&self) -> bool { match *self { - CompileFilter::Everything { .. } => false, + CompileFilter::Default { .. } => false, CompileFilter::Only { .. } => true, } } @@ -601,7 +608,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 3ce46881b61..b6b87a82bb1 100644 --- a/src/cargo/ops/cargo_install.rs +++ b/src/cargo/ops/cargo_install.rs @@ -490,7 +490,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, diff --git a/tests/check.rs b/tests/check.rs index d0a0e48fff3..84ff66b5f33 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -424,3 +424,29 @@ fn check_virtual_all_implied() { .with_stderr_contains("[..] --crate-name bar bar[/]src[/]lib.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 [..]") + ); +}