Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cargo check --all #3731

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/bin/check.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -64,6 +65,7 @@ pub struct Options {
flag_bench: Vec<String>,
flag_locked: bool,
flag_frozen: bool,
flag_all: bool,
}

pub fn execute(options: Options, config: &Config) -> CliResult {
Expand All @@ -79,14 +81,20 @@ 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,
target: options.flag_target.as_ref().map(|t| &t[..]),
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,
Expand Down
38 changes: 38 additions & 0 deletions tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [..]")
);
}