From 27edc433c95d23017a9e72e48752f1f33dc59f23 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 2 May 2018 11:18:37 -0700 Subject: [PATCH] Be more conservative about which files are linked to the output dir. 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. --- .../compiler/context/compilation_files.rs | 20 +++++++++++-------- tests/testsuite/check.rs | 15 +++++++++++--- tests/testsuite/path.rs | 9 ++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index e94a0aa4ffb..29afdcbf7bc 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -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, - export_dir: Option<(PathBuf, Vec>)>, + /// Additional directory to include a copy of the outputs. + export_dir: Option, + /// The root targets requested by the user on the command line (does not + /// include dependencies). + roots: Vec>, ws: &'a Workspace<'cfg>, metas: HashMap, Option>, /// 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 { - 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 diff --git a/tests/testsuite/check.rs b/tests/testsuite/check.rs index f4e49e711d4..b4c523bfd21 100644 --- a/tests/testsuite/check.rs +++ b/tests/testsuite/check.rs @@ -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()), diff --git a/tests/testsuite/path.rs b/tests/testsuite/path.rs index 594e0b9a1b0..98fb7c5e9dd 100644 --- a/tests/testsuite/path.rs +++ b/tests/testsuite/path.rs @@ -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]