From 97c1bba1650a55943ecf8b91c4782c35e531fa95 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 17 Feb 2017 09:09:23 -0800 Subject: [PATCH] Add `cargo check --all` This'll check all `build` targets for all packages in a workspace --- src/bin/check.rs | 14 +++++++++++--- tests/check.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/bin/check.rs b/src/bin/check.rs index de8a9c6040c..e13c68b2556 100644 --- a/src/bin/check.rs +++ b/src/bin/check.rs @@ -1,7 +1,7 @@ use std::env; use cargo::core::Workspace; -use cargo::ops::{self, CompileOptions, MessageFormat}; +use cargo::ops::{self, CompileOptions, MessageFormat, Packages}; use cargo::util::{CliResult, Config}; use cargo::util::important_paths::find_root_manifest_for_wd; @@ -13,7 +13,8 @@ Usage: Options: -h, --help Print this message - -p SPEC, --package SPEC ... Package to check + -p SPEC, --package SPEC ... Package(s) to check + --all Check all packages in the workspace -j N, --jobs N Number of parallel jobs, defaults to # of CPUs --lib Check only this package's library --bin NAME Check only the specified binary @@ -64,6 +65,7 @@ pub struct Options { flag_bench: Vec, flag_locked: bool, flag_frozen: bool, + flag_all: bool, } pub fn execute(options: Options, config: &Config) -> CliResult { @@ -79,6 +81,12 @@ 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 = if options.flag_all { + Packages::All + } else { + Packages::Packages(&options.flag_package) + }; + let opts = CompileOptions { config: config, jobs: options.flag_jobs, @@ -86,7 +94,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult { features: &options.flag_features, all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, - spec: ops::Packages::Packages(&options.flag_package), + spec: spec, mode: ops::CompileMode::Check, release: options.flag_release, filter: ops::CompileFilter::new(options.flag_lib, diff --git a/tests/check.rs b/tests/check.rs index b01d88e952d..a47242ce8b5 100644 --- a/tests/check.rs +++ b/tests/check.rs @@ -383,3 +383,41 @@ fn rustc_check_err() { .arg("--emit=metadata"), execs().with_status(101)); } + +#[test] +fn check_all() { + if !is_nightly() { + return + } + let foo = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [workspace] + [dependencies] + b = { path = "b" } + "#) + .file("src/main.rs", "fn main() {}") + .file("examples/a.rs", "fn main() {}") + .file("tests/a.rs", "") + .file("src/lib.rs", "") + .file("b/Cargo.toml", r#" + [package] + name = "b" + version = "0.0.1" + authors = [] + "#) + .file("b/src/main.rs", "fn main() {}") + .file("b/src/lib.rs", ""); + + assert_that(foo.cargo_process("check").arg("--all").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 b b[/]src[/]lib.rs [..]") + .with_stderr_contains("[..] --crate-name b b[/]src[/]main.rs [..]") + ); +}