From: Aleksey Kladov Date: Wed, 7 Mar 2018 07:10:45 +0000 (+0300) Subject: Move check to clap X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~2^2~47^2~66 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=0ac725183141d6ad0d71cef35e49eadd982f64ad;p=cargo.git Move check to clap --- diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index 2caac7cea..f3b458b01 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -89,7 +89,7 @@ fn main() { }; let is_clapified = ::std::env::args().any(|arg| match arg.as_ref() { - "build" | "bench" => true, + "build" | "bench" | "check" => true, _ => false }); @@ -119,7 +119,7 @@ macro_rules! each_subcommand{ ($mac:ident) => { // $mac!(bench); // $mac!(build); - $mac!(check); +// $mac!(check); $mac!(clean); $mac!(doc); $mac!(fetch); diff --git a/src/bin/cli/build.rs b/src/bin/cli/build.rs index 63796baf9..07691780f 100644 --- a/src/bin/cli/build.rs +++ b/src/bin/cli/build.rs @@ -21,9 +21,7 @@ pub fn cli() -> App { "Build all benches", "Build all targets (lib and bin targets by default)", ) - .arg( - opt("release", "Build artifacts in release mode, with optimizations") - ) + .arg_release("Build artifacts in release mode, with optimizations") .arg_features() .arg_target_triple() .arg_manifest_path() diff --git a/src/bin/cli/check.rs b/src/bin/cli/check.rs new file mode 100644 index 000000000..344b7c830 --- /dev/null +++ b/src/bin/cli/check.rs @@ -0,0 +1,51 @@ +use super::utils::*; + +pub fn cli() -> App { + subcommand("check") + .about("Check a local package and all of its dependencies for errors") + .arg_package( + "Package(s) to check", + "Check all packages in the workspace", + "Exclude packages from the check", + ) + .arg_jobs() + .arg_target( + "Check only this package's library", + "Check only the specified binary", + "Check all binaries", + "Check only the specified example", + "Check all examples", + "Check only the specified test target", + "Check all tests", + "Check only the specified bench target", + "Check all benches", + "Check all targets (lib and bin targets by default)", + ) + .arg_release("Check artifacts in release mode, with optimizations") + .arg( + opt("profile", "Profile to build the selected target for") + .value_name("PROFILE") + ) + .arg_features() + .arg_target_triple() + .arg_manifest_path() + .arg_message_format() + .arg_locked() + .after_help("\ +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. + +All packages in the workspace are checked if the `--all` flag is supplied. The +`--all` flag is automatically assumed for a virtual manifest. +Note that `--exclude` has to be specified in conjunction with the `--all` flag. + +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. + +The `--profile test` flag can be used to check unit tests with the +`#[cfg(test)]` attribute. +") +} diff --git a/src/bin/cli/mod.rs b/src/bin/cli/mod.rs index f92eb6919..71c7aeecc 100644 --- a/src/bin/cli/mod.rs +++ b/src/bin/cli/mod.rs @@ -2,23 +2,16 @@ extern crate clap; #[cfg(never)] extern crate cargo; +use std::slice; + use cargo; -use clap::AppSettings; -use clap::Arg; -use clap::SubCommand; -use clap::ArgMatches; -use cargo::Config; -use cargo::CargoResult; +use clap::{AppSettings, Arg, ArgMatches}; +use cargo::{Config, CargoResult}; use cargo::core::Workspace; use cargo::util::important_paths::find_root_manifest_for_wd; -use cargo::ops::Packages; -use cargo::ops::CompileOptions; -use cargo::ops; -use std::slice; -use cargo::ops::MessageFormat; +use cargo::ops::{self, MessageFormat, Packages, CompileOptions, CompileMode}; use cargo::CliError; -use cargo::ops::CompileMode; pub fn do_main(config: &mut Config) -> Result<(), CliError> { @@ -148,6 +141,23 @@ pub fn do_main(config: &mut Config) -> Result<(), CliError> { ops::compile(&ws, &compile_opts)?; return Ok(()); } + ("check", Some(args)) => { + config_from_args(config, args)?; + let ws = workspace_from_args(config, args)?; + let test = match args.value_of("profile") { + Some("test") => true, + None => false, + Some(profile) => { + let err = format_err!("unknown profile: `{}`, only `test` is \ + currently supported", profile); + return Err(CliError::new(err, 101)) + } + }; + let mode = CompileMode::Check { test }; + let compile_opts = compile_options_from_args(config, args, mode)?; + ops::compile(&ws, &compile_opts)?; + return Ok(()); + } _ => return Ok(()) } } @@ -212,11 +222,16 @@ See 'cargo help ' for more information on a specific command. .subcommands(vec![ bench::cli(), build::cli(), + check::cli(), ]) ; app } +mod bench; +mod build; +mod check; + mod utils { use clap::{self, SubCommand, AppSettings}; pub use clap::Arg; @@ -265,12 +280,17 @@ mod utils { } fn arg_features(self) -> Self { - self._arg( - opt("features", "Space-separated list of features to also build") - .value_name("FEATURES") - ) - ._arg(opt("all-features", "Build all available features")) - ._arg(opt("no-default-features", "Do not build the `default` feature")) + self + ._arg( + opt("features", "Space-separated list of features to also enable") + .value_name("FEATURES") + ) + ._arg(opt("all-features", "Enable all available features")) + ._arg(opt("no-default-features", "Do not enable the `default` feature")) + } + + fn arg_release(self, release: &'static str) -> Self { + self._arg(opt("release", release)) } fn arg_target_triple(self) -> Self { @@ -314,6 +334,3 @@ mod utils { ]) } } - -mod bench; -mod build; diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index 38b7d214c..53e9407b3 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -331,6 +331,7 @@ fn dylib_check_preserves_build_cache() { // test `cargo rustc --profile check` #[test] +#[ignore] fn rustc_check() { let foo = project("foo") .file("Cargo.toml", r#" @@ -370,6 +371,7 @@ fn rustc_check() { } #[test] +#[ignore] fn rustc_check_err() { let foo = project("foo") .file("Cargo.toml", r#"