Move check to clap
authorAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 7 Mar 2018 07:10:45 +0000 (10:10 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Thu, 8 Mar 2018 20:30:46 +0000 (23:30 +0300)
src/bin/cargo.rs
src/bin/cli/build.rs
src/bin/cli/check.rs [new file with mode: 0644]
src/bin/cli/mod.rs
tests/testsuite/check.rs

index 2caac7cea12fdcfb3e72a34bcaf8220f5f935591..f3b458b01aa056e72d15a3f5587b9d1820995ba6 100644 (file)
@@ -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);
index 63796baf9cf7235a735f20a4a1576ef7b3c72326..07691780fdf44d28d4085061b16ab83a1275408e 100644 (file)
@@ -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 (file)
index 0000000..344b7c8
--- /dev/null
@@ -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.
+")
+}
index f92eb69196b296d13afd356f3f1dd18f45b447f0..71c7aeeccf62597c582445c4a3a3338e47ad24a8 100644 (file)
@@ -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 <command>' 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;
index 38b7d214ca157b005bcce5a81574d3e3a64c5105..53e9407b341b3be7f211b9a3066285e22de526cd 100644 (file)
@@ -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#"