|
| 1 | +use std::env; |
| 2 | + |
| 3 | +use cargo::core::Workspace; |
| 4 | +use cargo::ops::{self, CompileOptions, MessageFormat}; |
| 5 | +use cargo::util::important_paths::{find_root_manifest_for_wd}; |
| 6 | +use cargo::util::{CliResult, Config}; |
| 7 | + |
| 8 | +#[derive(RustcDecodable)] |
| 9 | +pub struct Options { |
| 10 | + flag_package: Vec<String>, |
| 11 | + flag_jobs: Option<u32>, |
| 12 | + flag_features: Vec<String>, |
| 13 | + flag_all_features: bool, |
| 14 | + flag_no_default_features: bool, |
| 15 | + flag_target: Option<String>, |
| 16 | + flag_manifest_path: Option<String>, |
| 17 | + flag_verbose: u32, |
| 18 | + flag_quiet: Option<bool>, |
| 19 | + flag_color: Option<String>, |
| 20 | + flag_message_format: MessageFormat, |
| 21 | + flag_release: bool, |
| 22 | + flag_lib: bool, |
| 23 | + flag_bin: Vec<String>, |
| 24 | + flag_example: Vec<String>, |
| 25 | + flag_test: Vec<String>, |
| 26 | + flag_bench: Vec<String>, |
| 27 | + flag_locked: bool, |
| 28 | + flag_frozen: bool, |
| 29 | +} |
| 30 | + |
| 31 | +pub const USAGE: &'static str = " |
| 32 | +Check a local package and all of its dependencies for errors |
| 33 | +
|
| 34 | +Usage: |
| 35 | + cargo check [options] |
| 36 | +
|
| 37 | +Options: |
| 38 | + -h, --help Print this message |
| 39 | + -p SPEC, --package SPEC ... Package to check |
| 40 | + -j N, --jobs N Number of parallel jobs, defaults to # of CPUs |
| 41 | + --lib Check only this package's library |
| 42 | + --bin NAME Check only the specified binary |
| 43 | + --example NAME Check only the specified example |
| 44 | + --test NAME Check only the specified test target |
| 45 | + --bench NAME Check only the specified benchmark target |
| 46 | + --release Check artifacts in release mode, with optimizations |
| 47 | + --features FEATURES Space-separated list of features to also check |
| 48 | + --all-features Check all available features |
| 49 | + --no-default-features Do not check the `default` feature |
| 50 | + --target TRIPLE Check for the target triple |
| 51 | + --manifest-path PATH Path to the manifest to compile |
| 52 | + -v, --verbose ... Use verbose output |
| 53 | + -q, --quiet No output printed to stdout |
| 54 | + --color WHEN Coloring: auto, always, never |
| 55 | + --message-format FMT Error format: human, json [default: human] |
| 56 | + --frozen Require Cargo.lock and cache are up to date |
| 57 | + --locked Require Cargo.lock is up to date |
| 58 | +
|
| 59 | +If the --package argument is given, then SPEC is a package id specification |
| 60 | +which indicates which package should be built. If it is not given, then the |
| 61 | +current package is built. For more information on SPEC and its format, see the |
| 62 | +`cargo help pkgid` command. |
| 63 | +
|
| 64 | +Compilation can be configured via the use of profiles which are configured in |
| 65 | +the manifest. The default profile for this command is `dev`, but passing |
| 66 | +the --release flag will use the `release` profile instead. |
| 67 | +"; |
| 68 | + |
| 69 | +pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> { |
| 70 | + debug!("executing; cmd=cargo-check; args={:?}", |
| 71 | + env::args().collect::<Vec<_>>()); |
| 72 | + config.configure(options.flag_verbose, |
| 73 | + options.flag_quiet, |
| 74 | + &options.flag_color, |
| 75 | + options.flag_frozen, |
| 76 | + options.flag_locked)?; |
| 77 | + |
| 78 | + let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?; |
| 79 | + |
| 80 | + let opts = CompileOptions { |
| 81 | + config: config, |
| 82 | + jobs: options.flag_jobs, |
| 83 | + target: options.flag_target.as_ref().map(|t| &t[..]), |
| 84 | + features: &options.flag_features, |
| 85 | + all_features: options.flag_all_features, |
| 86 | + no_default_features: options.flag_no_default_features, |
| 87 | + spec: ops::Packages::Packages(&options.flag_package), |
| 88 | + mode: ops::CompileMode::Check, |
| 89 | + release: options.flag_release, |
| 90 | + filter: ops::CompileFilter::new(options.flag_lib, |
| 91 | + &options.flag_bin, |
| 92 | + &options.flag_test, |
| 93 | + &options.flag_example, |
| 94 | + &options.flag_bench), |
| 95 | + message_format: options.flag_message_format, |
| 96 | + target_rustdoc_args: None, |
| 97 | + target_rustc_args: None, |
| 98 | + }; |
| 99 | + |
| 100 | + let ws = Workspace::new(&root, config)?; |
| 101 | + ops::compile(&ws, &opts)?; |
| 102 | + Ok(None) |
| 103 | +} |
0 commit comments