Skip to content

Be more conservative about which files are linked to the output dir. #5460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 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 @@ -108,13 +113,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())
} else {
None
}
pub fn export_dir(&self) -> Option<PathBuf> {
self.export_dir.clone()
}

pub fn pkg_dir(&self, unit: &Unit<'a>) -> String {
Expand Down Expand Up @@ -206,9 +206,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 unit.target.is_bin() || self.roots.contains(unit) {
Some((
out_dir.parent().unwrap().to_owned(),
if unit.mode.is_any_test() {
Expand All @@ -217,6 +215,8 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
bin_stem
},
))
} else {
None
}
} else if bin_stem == file_stem {
None
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ fn link_targets<'a, 'cfg>(
) -> CargoResult<Work> {
let bcx = cx.bcx;
let outputs = cx.outputs(unit)?;
let export_dir = cx.files().export_dir(unit);
let export_dir = cx.files().export_dir();
let package_id = unit.pkg.package_id().clone();
let target = unit.target.clone();
let profile = unit.profile;
Expand Down
23 changes: 19 additions & 4 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use cargotest::install::exe;
use cargotest::is_nightly;
use cargotest::support::paths::CargoPathExt;
use cargotest::support::registry::Package;
use cargotest::support::{execs, project};
Expand Down Expand Up @@ -830,7 +831,12 @@ fn check_artifacts() {
p.cargo("check").arg("--bin").arg("foo"),
execs().with_status(0),
);
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
if is_nightly() {
// The nightly check can be removed once 1.27 is stable.
// Bins now generate `rmeta` files.
// See: https://github.com/rust-lang/rust/pull/49289
assert_that(&p.root().join("target/debug/libfoo.rmeta"), existing_file());
}
assert_that(
&p.root().join("target/debug/libfoo.rlib"),
is_not(existing_file()),
Expand All @@ -845,7 +851,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 +875,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 +893,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