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

cargo check #3296

Merged
merged 4 commits into from
Dec 14, 2016
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
2 changes: 2 additions & 0 deletions src/bin/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Options:

Some common cargo commands are (see all commands with --list):
build Compile the current project
check Analyze the current project and report errors, but don't build object files
clean Remove the target directory
doc Build this project's and its dependencies' documentation
new Create a new cargo project
Expand All @@ -75,6 +76,7 @@ macro_rules! each_subcommand{
($mac:ident) => {
$mac!(bench);
$mac!(build);
$mac!(check);
$mac!(clean);
$mac!(doc);
$mac!(fetch);
Expand Down
103 changes: 103 additions & 0 deletions src/bin/check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
use std::env;

use cargo::core::Workspace;
use cargo::ops::{self, CompileOptions, MessageFormat};
use cargo::util::important_paths::{find_root_manifest_for_wd};
use cargo::util::{CliResult, Config};

#[derive(RustcDecodable)]
pub struct Options {
flag_package: Vec<String>,
flag_jobs: Option<u32>,
flag_features: Vec<String>,
flag_all_features: bool,
flag_no_default_features: bool,
flag_target: Option<String>,
flag_manifest_path: Option<String>,
flag_verbose: u32,
flag_quiet: Option<bool>,
flag_color: Option<String>,
flag_message_format: MessageFormat,
flag_release: bool,
flag_lib: bool,
flag_bin: Vec<String>,
flag_example: Vec<String>,
flag_test: Vec<String>,
flag_bench: Vec<String>,
flag_locked: bool,
flag_frozen: bool,
}

pub const USAGE: &'static str = "
Check a local package and all of its dependencies for errors

Usage:
cargo check [options]

Options:
-h, --help Print this message
-p SPEC, --package SPEC ... Package to check
-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
--example NAME Check only the specified example
--test NAME Check only the specified test target
--bench NAME Check only the specified benchmark target
--release Check artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also check
--all-features Check all available features
--no-default-features Do not check the `default` feature
--target TRIPLE Check for the target triple
--manifest-path PATH Path to the manifest to compile
-v, --verbose ... Use verbose output
-q, --quiet No output printed to stdout
--color WHEN Coloring: auto, always, never
--message-format FMT Error format: human, json [default: human]
--frozen Require Cargo.lock and cache are up to date
--locked Require Cargo.lock is up to date

If the --package argument is given, then SPEC is a package id specification
which indicates which package should be built. If it is not given, then the
current package is built. For more information on SPEC and its format, see the
`cargo help pkgid` command.

Compilation can be configured via the use of profiles which are configured in
the manifest. The default profile for this command is `dev`, but passing
the --release flag will use the `release` profile instead.
";

pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
debug!("executing; cmd=cargo-check; args={:?}",
env::args().collect::<Vec<_>>());
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 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),
mode: ops::CompileMode::Check,
release: options.flag_release,
filter: ops::CompileFilter::new(options.flag_lib,
&options.flag_bin,
&options.flag_test,
&options.flag_example,
&options.flag_bench),
message_format: options.flag_message_format,
target_rustdoc_args: None,
target_rustc_args: None,
};

let ws = Workspace::new(&root, config)?;
ops::compile(&ws, &opts)?;
Ok(None)
}
14 changes: 13 additions & 1 deletion src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl LibKind {
"lib" => LibKind::Lib,
"rlib" => LibKind::Rlib,
"dylib" => LibKind::Dylib,
"procc-macro" => LibKind::ProcMacro,
"proc-macro" => LibKind::ProcMacro,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this related to this new feature or some kind of other random bugfix?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random bugfix

s => LibKind::Other(s.to_string()),
}
}
Expand Down Expand Up @@ -136,6 +136,7 @@ pub struct Profile {
pub test: bool,
pub doc: bool,
pub run_custom_build: bool,
pub check: bool,
pub panic: Option<String>,
}

Expand Down Expand Up @@ -168,6 +169,7 @@ pub struct Profiles {
pub bench_deps: Profile,
pub doc: Profile,
pub custom_build: Profile,
pub check: Profile,
}

/// Information about a binary, a library, an example, etc. that is part of the
Expand Down Expand Up @@ -531,6 +533,13 @@ impl Profile {
..Profile::default_dev()
}
}

pub fn default_check() -> Profile {
Profile {
check: true,
..Profile::default_dev()
}
}
}

impl Default for Profile {
Expand All @@ -547,6 +556,7 @@ impl Default for Profile {
test: false,
doc: false,
run_custom_build: false,
check: false,
panic: None,
}
}
Expand All @@ -560,6 +570,8 @@ impl fmt::Display for Profile {
write!(f, "Profile(doc)")
} else if self.run_custom_build {
write!(f, "Profile(run)")
} else if self.check {
write!(f, "Profile(check)")
} else {
write!(f, "Profile(build)")
}
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ impl<'cfg> Workspace<'cfg> {
bench_deps: Profile::default_release(),
doc: Profile::default_doc(),
custom_build: Profile::default_custom_build(),
check: Profile::default_check(),
};

for pkg in self.members().filter(|p| p.manifest_path() != root_manifest) {
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
for kind in [Kind::Host, Kind::Target].iter() {
let Profiles {
ref release, ref dev, ref test, ref bench, ref doc,
ref custom_build, ref test_deps, ref bench_deps,
ref custom_build, ref test_deps, ref bench_deps, ref check
} = *profiles;
let profiles = [release, dev, test, bench, doc, custom_build,
test_deps, bench_deps];
test_deps, bench_deps, check];
for profile in profiles.iter() {
units.push(Unit {
pkg: &pkg,
Expand Down
6 changes: 4 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ pub struct CompileOptions<'a> {
pub target_rustc_args: Option<&'a [String]>,
}

#[derive(Clone, Copy, PartialEq)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum CompileMode {
Test,
Build,
Check,
Bench,
Doc { deps: bool },
}
Expand Down Expand Up @@ -335,6 +336,7 @@ fn generate_targets<'a>(pkg: &'a Package,
CompileMode::Test => test,
CompileMode::Bench => &profiles.bench,
CompileMode::Build => build,
CompileMode::Check => &profiles.check,
CompileMode::Doc { .. } => &profiles.doc,
};
match *filter {
Expand Down Expand Up @@ -366,7 +368,7 @@ fn generate_targets<'a>(pkg: &'a Package,
}
Ok(base)
}
CompileMode::Build => {
CompileMode::Build | CompileMode::Check => {
Ok(pkg.targets().iter().filter(|t| {
t.is_bin() || t.is_lib()
}).map(|t| (t, profile)).collect())
Expand Down
Loading