Skip to content

Commit

Permalink
Auto merge of #6292 - ehuss:no-rmeta-hardlink, r=alexcrichton
Browse files Browse the repository at this point in the history
Don't hardlink rmeta files.

`.rmeta` files shouldn't be needed in the main directory, and since rustc started outputing rmeta files for binaries, there are name collisions between bins and libs of the same name.

Partial fix for #5524.
  • Loading branch information
bors committed Nov 9, 2018
2 parents 6582378 + 61f9588 commit f0950da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
10 changes: 3 additions & 7 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,12 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
let mut unsupported = Vec::new();
{
if unit.mode.is_check() {
// This is not quite correct for non-lib targets. rustc
// currently does not emit rmeta files, so there is nothing to
// check for! See #3624.
// This may be confusing. rustc outputs a file named `lib*.rmeta`
// for both libraries and binaries.
let path = out_dir.join(format!("lib{}.rmeta", file_stem));
let hardlink = link_stem
.clone()
.map(|(ld, ls)| ld.join(format!("lib{}.rmeta", ls)));
ret.push(OutputFile {
path,
hardlink,
hardlink: None,
flavor: FileFlavor::Linkable,
});
} else {
Expand Down
45 changes: 24 additions & 21 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fmt::{self, Write};

use glob::glob;
use support::install::exe;
use support::is_nightly;
use support::paths::CargoPathExt;
use support::registry::Package;
use support::{basic_manifest, project};
Expand Down Expand Up @@ -573,39 +572,44 @@ fn check_artifacts() {
.file("examples/ex1.rs", "fn main() {}")
.file("benches/b1.rs", "")
.build();

let assert_glob = |path: &str, count: usize| {
assert_eq!(
glob(&p.root().join(path).to_str().unwrap())
.unwrap()
.count(),
count
);
};

p.cargo("check").run();
assert!(p.root().join("target/debug/libfoo.rmeta").is_file());
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
assert_glob("target/debug/deps/libfoo-*.rmeta", 2);

p.root().join("target").rm_rf();
p.cargo("check --lib").run();
assert!(p.root().join("target/debug/libfoo.rmeta").is_file());
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
assert_glob("target/debug/deps/libfoo-*.rmeta", 1);

p.root().join("target").rm_rf();
p.cargo("check --bin foo").run();
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!(p.root().join("target/debug/libfoo.rmeta").is_file());
}
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
assert_glob("target/debug/deps/libfoo-*.rmeta", 2);

p.root().join("target").rm_rf();
p.cargo("check --test t1").run();
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
assert_eq!(
glob(&p.root().join("target/debug/t1-*").to_str().unwrap())
.unwrap()
.count(),
0
);
assert_glob("target/debug/t1-*", 0);
assert_glob("target/debug/deps/libfoo-*.rmeta", 1);
assert_glob("target/debug/deps/libt1-*.rmeta", 1);

p.root().join("target").rm_rf();
p.cargo("check --example ex1").run();
Expand All @@ -617,18 +621,17 @@ fn check_artifacts() {
.join(exe("ex1"))
.is_file()
);
assert_glob("target/debug/deps/libfoo-*.rmeta", 1);
assert_glob("target/debug/examples/libex1-*.rmeta", 1);

p.root().join("target").rm_rf();
p.cargo("check --bench b1").run();
assert!(!p.root().join("target/debug/libfoo.rmeta").is_file());
assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
assert!(!p.root().join("target/debug").join(exe("foo")).is_file());
assert_eq!(
glob(&p.root().join("target/debug/b1-*").to_str().unwrap())
.unwrap()
.count(),
0
);
assert_glob("target/debug/b1-*", 0);
assert_glob("target/debug/deps/libfoo-*.rmeta", 1);
assert_glob("target/debug/deps/libb1-*.rmeta", 1);
}

#[test]
Expand Down

0 comments on commit f0950da

Please sign in to comment.