Skip to content
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

Symlink dSYM on macOS example binaries. #6891

Merged
merged 1 commit into from
Apr 30, 2019
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
16 changes: 10 additions & 6 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,16 @@ impl TargetInfo {
}

// See rust-lang/cargo#4490, rust-lang/cargo#4960.
// - Only uplift debuginfo for binaries.
// Tests are run directly from `target/debug/deps/`
// and examples are inside target/debug/examples/ which already have symbols next to them,
// so no need to do anything.
if *kind == TargetKind::Bin {
if target_triple.contains("-apple-") {
// Only uplift debuginfo for binaries.
// - Tests are run directly from `target/debug/deps/` with the
// metadata hash still in the filename.
// - Examples are only uplifted for apple because the symbol file
// needs to match the executable file name to be found (i.e., it
// needs to remove the hash in the filename). On Windows, the path
// to the .pdb with the hash is embedded in the executable.
let is_apple = target_triple.contains("-apple-");
if *kind == TargetKind::Bin || (*kind == TargetKind::ExampleBin && is_apple) {
if is_apple {
ret.push(FileType {
suffix: ".dSYM".to_string(),
prefix: prefix.clone(),
Expand Down
30 changes: 12 additions & 18 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4132,10 +4132,8 @@ fn building_a_dependent_crate_witout_bin_should_fail() {
}

#[test]
#[cfg(any(target_os = "macos", target_os = "ios"))]
fn uplift_dsym_of_bin_on_mac() {
if !cfg!(any(target_os = "macos", target_os = "ios")) {
return;
}
let p = project()
.file("src/main.rs", "fn main() { panic!(); }")
.file("src/bin/b.rs", "fn main() { panic!(); }")
Expand All @@ -4144,23 +4142,17 @@ fn uplift_dsym_of_bin_on_mac() {
.build();

p.cargo("build --bins --examples --tests").run();
assert!(p.bin("foo.dSYM").is_dir());
assert!(p.bin("b.dSYM").is_dir());
assert!(p
.bin("b.dSYM")
.symlink_metadata()
.expect("read metadata from b.dSYM")
.file_type()
.is_symlink());
assert!(!p.bin("c.dSYM").is_dir());
assert!(!p.bin("d.dSYM").is_dir());
assert!(p.target_debug_dir().join("foo.dSYM").is_dir());
assert!(p.target_debug_dir().join("b.dSYM").is_dir());
assert!(p.target_debug_dir().join("b.dSYM").is_symlink());
assert!(p.target_debug_dir().join("examples/c.dSYM").is_symlink());
assert!(!p.target_debug_dir().join("c.dSYM").exists());
assert!(!p.target_debug_dir().join("d.dSYM").exists());
}

#[test]
#[cfg(all(target_os = "windows", target_env = "msvc"))]
fn uplift_pdb_of_bin_on_windows() {
if !cfg!(all(target_os = "windows", target_env = "msvc")) {
return;
}
let p = project()
.file("src/main.rs", "fn main() { panic!(); }")
.file("src/bin/b.rs", "fn main() { panic!(); }")
Expand All @@ -4171,8 +4163,10 @@ fn uplift_pdb_of_bin_on_windows() {
p.cargo("build --bins --examples --tests").run();
assert!(p.target_debug_dir().join("foo.pdb").is_file());
assert!(p.target_debug_dir().join("b.pdb").is_file());
assert!(!p.target_debug_dir().join("c.pdb").is_file());
assert!(!p.target_debug_dir().join("d.pdb").is_file());
assert!(!p.target_debug_dir().join("examples/c.pdb").exists());
assert_eq!(p.glob("target/debug/examples/c-*.pdb").count(), 1);
assert!(!p.target_debug_dir().join("c.pdb").exists());
assert!(!p.target_debug_dir().join("d.pdb").exists());
}

// Ensure that `cargo build` chooses the correct profile for building
Expand Down
6 changes: 6 additions & 0 deletions tests/testsuite/support/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub trait CargoPathExt {
fn move_in_time<F>(&self, travel_amount: F)
where
F: Fn(i64, u32) -> (i64, u32);

fn is_symlink(&self) -> bool;
}

impl CargoPathExt for Path {
Expand Down Expand Up @@ -142,6 +144,10 @@ impl CargoPathExt for Path {
});
}
}

fn is_symlink(&self) -> bool {
fs::symlink_metadata(self).map(|m| m.file_type().is_symlink()).unwrap_or(false)
}
}

fn do_op<F>(path: &Path, desc: &str, mut f: F)
Expand Down