Skip to content

Commit

Permalink
Be more conservative about which files are linked to the output dir.
Browse files Browse the repository at this point in the history
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 rust-lang#5444.
  • Loading branch information
ehuss committed May 10, 2018
1 parent 7067bc8 commit 27edc43
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
20 changes: 12 additions & 8 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand All @@ -217,6 +219,8 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
bin_stem
},
))
} else {
None
}
} else if bin_stem == file_stem {
None
Expand Down
15 changes: 12 additions & 3 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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()),
Expand All @@ -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()),
Expand Down
9 changes: 6 additions & 3 deletions tests/testsuite/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 27edc43

Please sign in to comment.