Skip to content

Ignore run-make tests that use symlink on Windows and adjust symlink wrapper #126846

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

Closed
wants to merge 2 commits into from
Closed
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
49 changes: 27 additions & 22 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,37 @@ pub fn source_root() -> PathBuf {
env_var("SOURCE_ROOT").into()
}

/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
#[cfg(target_family = "windows")]
/// Creates a new symlink to a path on the filesystem (only available for Unix because symlink
/// creation is a priviledged operation on Windows; see
/// <https://doc.rust-lang.org/stable/std/os/windows/fs/fn.symlink_file.html#limitations>).
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
if link.as_ref().exists() {
std::fs::remove_dir(link.as_ref()).unwrap();
#[cfg(target_family = "windows")]
{
panic!(
"symlink is an priviledged operation on Windows that is not normally enabled on user machines"
);
}
use std::os::windows::fs;
fs::symlink_file(original.as_ref(), link.as_ref()).expect(&format!(
"failed to create symlink {:?} for {:?}",
link.as_ref().display(),
original.as_ref().display(),
));
}

/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
#[cfg(target_family = "unix")]
pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
if link.as_ref().exists() {
std::fs::remove_dir(link.as_ref()).unwrap();
#[cfg(target_family = "unix")]
{
let link = link.as_ref();
if link.exists() {
std::fs::remove_dir(link)
.expect(&format!("failed to remove existing symlink: {}", link.display()));
}

use std::os::unix::fs;
fs::symlink(original.as_ref(), link).expect(&format!(
"failed to create symlink {} for {}",
link.display(),
original.as_ref().display(),
));
}

#[cfg(not(any(target_family = "unix", target_family = "windows")))]
{
unimplemented!();
}
use std::os::unix::fs;
fs::symlink(original.as_ref(), link.as_ref()).expect(&format!(
"failed to create symlink {:?} for {:?}",
link.as_ref().display(),
original.as_ref().display(),
));
}

/// Construct the static library name based on the platform.
Expand Down
1 change: 1 addition & 0 deletions tests/run-make/symlinked-extern/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// can result in successful compilation.

//@ ignore-cross-compile
//@ ignore-windows (symlink creation is priviledged on Windows)

use run_make_support::{create_symlink, cwd, fs_wrapper, rustc};

Expand Down
1 change: 1 addition & 0 deletions tests/run-make/symlinked-libraries/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// See https://github.com/rust-lang/rust/issues/12459

//@ ignore-cross-compile
//@ ignore-windows (symlink creation is priviledged on Windows)

use run_make_support::{create_symlink, dynamic_lib_name, fs_wrapper, rustc};

Expand Down
1 change: 1 addition & 0 deletions tests/run-make/symlinked-rlib/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// See https://github.com/rust-lang/rust/pull/32828

//@ ignore-cross-compile
//@ ignore-windows (symlink creation is priviledged on Windows)

use run_make_support::{create_symlink, cwd, rustc};

Expand Down
Loading