diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 52e6cccaf28..5f756948243 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -645,8 +645,12 @@ fn hardlink_or_copy(src: &Path, dst: &Path) -> CargoResult<()> { use std::os::windows::fs::symlink_dir as symlink; let dst_dir = dst.parent().unwrap(); - assert!(src.starts_with(dst_dir)); - symlink(src.strip_prefix(dst_dir).unwrap(), dst) + let src = if src.starts_with(dst_dir) { + src.strip_prefix(dst_dir).unwrap() + } else { + src + }; + symlink(src, dst) } else { fs::hard_link(src, dst) }; diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index 9a241ae264c..ecb80fe67e8 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -1,11 +1,10 @@ use std::path::Path; use std::fs::{self, File}; use std::env; -use std::io::Write; use hamcrest::assert_that; -use cargotest::{process, ChannelChanger}; +use cargotest::{process, sleep_ms, ChannelChanger}; use cargotest::support::{execs, project}; #[test] @@ -31,7 +30,7 @@ fn binary_with_debug() { check_dir_contents( &p.root().join("out"), &["foo"], - &["foo"], + &["foo", "foo.dSYM"], &["foo.exe", "foo.pdb"], ); } @@ -105,7 +104,7 @@ fn dynamic_library_with_debug() { check_dir_contents( &p.root().join("out"), &["libfoo.so"], - &["libfoo.so"], + &["libfoo.dylib"], &["foo.dll", "foo.dll.lib"], ); } @@ -194,7 +193,7 @@ fn include_only_the_binary_from_the_current_package() { check_dir_contents( &p.root().join("out"), &["foo"], - &["foo"], + &["foo", "foo.dSYM"], &["foo.exe", "foo.pdb"], ); } @@ -250,10 +249,8 @@ fn replaces_artifacts() { execs().with_stdout("foo"), ); - fs::File::create(p.root().join("src/main.rs")) - .unwrap() - .write_all(br#"fn main() { println!("bar") }"#) - .unwrap(); + sleep_ms(1000); + p.change_file("src/main.rs", r#"fn main() { println!("bar") }"#); assert_that( p.cargo("build -Z out-dir --out-dir out")