Be more conservative about which files are linked to the output dir.
authorEric Huss <eric@huss.org>
Wed, 2 May 2018 18:18:37 +0000 (11:18 -0700)
committerEric Huss <eric@huss.org>
Thu, 10 May 2018 15:46:02 +0000 (08:46 -0700)
This changes it so that only top-level targets requested on the command-line will be included in the output directory.  Dependencies are no longer included.

Fixes #5444.

src/cargo/core/compiler/context/compilation_files.rs
tests/testsuite/check.rs
tests/testsuite/path.rs

index e94a0aa4ffbddaee582704bb35a6b9408dc385d3..29afdcbf7bcfc44c99fb290af9f8a9bbb9a4fff1 100644 (file)
@@ -25,7 +25,11 @@ pub struct CompilationFiles<'a, 'cfg: 'a> {
     pub(super) host: Layout,
     /// The target directory layout for the target (if different from then host)
     pub(super) target: Option<Layout>,
-    export_dir: Option<(PathBuf, Vec<Unit<'a>>)>,
+    /// Additional directory to include a copy of the outputs.
+    export_dir: Option<PathBuf>,
+    /// The root targets requested by the user on the command line (does not
+    /// include dependencies).
+    roots: Vec<Unit<'a>>,
     ws: &'a Workspace<'cfg>,
     metas: HashMap<Unit<'a>, Option<Metadata>>,
     /// For each Unit, a list all files produced.
@@ -65,7 +69,8 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
             ws,
             host,
             target,
-            export_dir: export_dir.map(|dir| (dir, roots.to_vec())),
+            export_dir,
+            roots: roots.to_vec(),
             metas,
             outputs,
         }
@@ -109,9 +114,8 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
     }
 
     pub fn export_dir(&self, unit: &Unit<'a>) -> Option<PathBuf> {
-        let &(ref dir, ref roots) = self.export_dir.as_ref()?;
-        if roots.contains(unit) {
-            Some(dir.clone())
+        if self.roots.contains(unit) {
+            self.export_dir.clone()
         } else {
             None
         }
@@ -206,9 +210,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
         // we don't want to link it up.
         if out_dir.ends_with("deps") {
             // Don't lift up library dependencies
-            if self.ws.members().find(|&p| p == unit.pkg).is_none() && !unit.target.is_bin() {
-                None
-            } else {
+            if self.roots.contains(unit) {
                 Some((
                     out_dir.parent().unwrap().to_owned(),
                     if unit.mode.is_any_test() {
@@ -217,6 +219,8 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
                         bin_stem
                     },
                 ))
+            } else {
+                None
             }
         } else if bin_stem == file_stem {
             None
index f4e49e711d4c81777e47e4e5c8ed5390212ebd95..b4c523bfd21a3978ecfa8639b5b18600e19234cb 100644 (file)
@@ -845,7 +845,10 @@ fn check_artifacts() {
         p.cargo("check").arg("--test").arg("t1"),
         execs().with_status(0),
     );
-    assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
+    assert_that(
+        &p.root().join("target/debug/libfoo.rmeta"),
+        is_not(existing_file()),
+    );
     assert_that(
         &p.root().join("target/debug/libfoo.rlib"),
         is_not(existing_file()),
@@ -866,7 +869,10 @@ fn check_artifacts() {
         p.cargo("check").arg("--example").arg("ex1"),
         execs().with_status(0),
     );
-    assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
+    assert_that(
+        &p.root().join("target/debug/libfoo.rmeta"),
+        is_not(existing_file()),
+    );
     assert_that(
         &p.root().join("target/debug/libfoo.rlib"),
         is_not(existing_file()),
@@ -881,7 +887,10 @@ fn check_artifacts() {
         p.cargo("check").arg("--bench").arg("b1"),
         execs().with_status(0),
     );
-    assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
+    assert_that(
+        &p.root().join("target/debug/libfoo.rmeta"),
+        is_not(existing_file()),
+    );
     assert_that(
         &p.root().join("target/debug/libfoo.rlib"),
         is_not(existing_file()),
index 594e0b9a1b05ebdcc59cf6c33ea7b402653b4ecd..98fb7c5e9dd5cc4e3a82c119226958e6d9b7d5a5 100644 (file)
@@ -4,9 +4,9 @@ use std::io::prelude::*;
 use cargo::util::process;
 use cargotest::sleep_ms;
 use cargotest::support::paths::{self, CargoPathExt};
-use cargotest::support::{execs, main_file, project};
 use cargotest::support::registry::Package;
-use hamcrest::{assert_that, existing_file};
+use cargotest::support::{execs, main_file, project};
+use hamcrest::{assert_that, existing_file, is_not};
 
 #[test]
 #[cfg(not(windows))] // I have no idea why this is failing spuriously on
@@ -1278,7 +1278,10 @@ fn workspace_produces_rlib() {
     assert_that(p.cargo("build"), execs().with_status(0));
 
     assert_that(&p.root().join("target/debug/libtop.rlib"), existing_file());
-    assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
+    assert_that(
+        &p.root().join("target/debug/libfoo.rlib"),
+        is_not(existing_file()),
+    );
 }
 
 #[test]