Make the default behaviour of `cargo build` match the documentation
authorXimin Luo <infinity0@pwned.gg>
Mon, 5 Feb 2018 16:04:11 +0000 (17:04 +0100)
committerXimin Luo <infinity0@pwned.gg>
Tue, 6 Feb 2018 00:35:20 +0000 (01:35 +0100)
cargo build --help says:

    --all-targets                Build all targets (lib and bin targets by default)

but the old default behaviour was actually doing --all-targets. This meant that
--avoid-dev-deps was only effectively if one gave --lib --bins explicitly. With
this commit, `cargo build --avoid-dev-deps` with no other flags, will build lib
and bins and avoid installing dev-dependencies.

src/cargo/ops/cargo_compile.rs

index bf905c3afd1a35be38a99eb44a16725a54b7f7b9..d7c08c9c4561189d788b9d3ed965edd22aff278c 100644 (file)
@@ -421,7 +421,7 @@ impl<'a> CompileFilter<'a> {
 
     pub fn need_dev_deps(&self) -> bool {
         match *self {
-            CompileFilter::Default { .. } => true,
+            CompileFilter::Default { .. } => false,
             CompileFilter::Only { examples, tests, benches, .. } =>
                 examples.is_specific() || tests.is_specific() || benches.is_specific()
         }
@@ -429,7 +429,11 @@ impl<'a> CompileFilter<'a> {
 
     pub fn matches(&self, target: &Target) -> bool {
         match *self {
-            CompileFilter::Default { .. } => true,
+            CompileFilter::Default { .. } => match *target.kind() {
+                TargetKind::Bin => true,
+                TargetKind::Lib(..) => true,
+                _ => false,
+            },
             CompileFilter::Only { lib, bins, examples, tests, benches, .. } => {
                 let rule = match *target.kind() {
                     TargetKind::Bin => bins,