Skip to content

Commit

Permalink
tests/run-make: update for symlink helper changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jieyouxu committed Sep 16, 2024
1 parent 0891959 commit 1fd1378
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 26 deletions.
26 changes: 21 additions & 5 deletions tests/run-make/invalid-symlink-search-path/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// In this test, the symlink created is invalid (valid relative to the root, but not
// relatively to where it is located), and used to cause an internal
// compiler error (ICE) when passed as a library search path. This was fixed in #26044,
// and this test checks that the invalid symlink is instead simply ignored.
// In this test, the symlink created is invalid (valid relative to the root, but not relatively to
// where it is located), and used to cause an internal compiler error (ICE) when passed as a library
// search path. This was fixed in #26044, and this test checks that the invalid symlink is instead
// simply ignored.
//
// See https://github.com/rust-lang/rust/issues/26006

//@ needs-symlink
Expand All @@ -22,7 +23,22 @@ fn main() {
.run();
rfs::create_dir("out/bar");
rfs::create_dir("out/bar/deps");
rfs::create_symlink("out/foo/libfoo.rlib", "out/bar/deps/libfoo.rlib");
#[cfg(unix)]
{
rfs::unix::symlink("out/foo/libfoo.rlib", "out/bar/deps/libfoo.rlib");
}
#[cfg(windows)]
{
rfs::windows::symlink_file("out/foo/libfoo.rlib", "out/bar/deps/libfoo.rlib");
}
#[cfg(not(any(unix, windows)))]
{
// FIXME(jieyouxu): this is not supported, but we really should implement a only-* directive
// that accepts multiple targets, like e.g. `//@ only-target-families: unix, windows`. That
// way, it properly shows up as an ignored test instead of silently passing.
return;
}

// Check that the invalid symlink does not cause an ICE
rustc()
.input("in/bar/lib.rs")
Expand Down
40 changes: 29 additions & 11 deletions tests/run-make/symlinked-extern/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Crates that are resolved normally have their path canonicalized and all
// symlinks resolved. This did not happen for paths specified
// using the --extern option to rustc, which could lead to rustc thinking
// that it encountered two different versions of a crate, when it's
// actually the same version found through different paths.
// See https://github.com/rust-lang/rust/pull/16505

// This test checks that --extern and symlinks together
// can result in successful compilation.
// Crates that are resolved normally have their path canonicalized and all symlinks resolved. This
// did not happen for paths specified using the `--extern` option to rustc, which could lead to
// rustc thinking that it encountered two different versions of a crate, when it's actually the same
// version found through different paths.
//
// This test checks that `--extern` and symlinks together can result in successful compilation.
//
// See <https://github.com/rust-lang/rust/pull/16505>.

//@ ignore-cross-compile
//@ needs-symlink
Expand All @@ -16,7 +15,26 @@ use run_make_support::{cwd, rfs, rustc};
fn main() {
rustc().input("foo.rs").run();
rfs::create_dir_all("other");
rfs::create_symlink("libfoo.rlib", "other");
#[cfg(unix)]
{
rfs::unix::symlink(cwd().join("libfoo.rlib"), cwd().join("other").join("libfoo.rlib"));
}
#[cfg(windows)]
{
rfs::windows::symlink_file(
cwd().join("libfoo.rlib"),
cwd().join("other").join("libfoo.rlib"),
);
}
#[cfg(not(any(unix, windows)))]
{
// FIXME(jieyouxu): this is not supported, but we really should implement a only-* directive
// that accepts multiple targets, like e.g. `//@ only-target-families: unix, windows`. That
// way, it properly shows up as an ignored test instead of silently passing.
return;
}

rustc().input("bar.rs").library_search_path(cwd()).run();
rustc().input("baz.rs").extern_("foo", "other").library_search_path(cwd()).run();

rustc().input("baz.rs").extern_("foo", "other/libfoo.rlib").library_search_path(cwd()).run();
}
37 changes: 28 additions & 9 deletions tests/run-make/symlinked-libraries/rmake.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
// When a directory and a symlink simultaneously exist with the same name,
// setting that name as the library search path should not cause rustc
// to avoid looking in the symlink and cause an error. This test creates
// a directory and a symlink named "other", and places the library in the symlink.
// If it succeeds, the library was successfully found.
// See https://github.com/rust-lang/rust/issues/12459
// Avoid erroring on symlinks pointing to the same file that are present in the library search path.
//
// See <https://github.com/rust-lang/rust/issues/12459>.

//@ ignore-cross-compile
//@ needs-symlink

use run_make_support::{dynamic_lib_name, rfs, rustc};
use run_make_support::{cwd, dynamic_lib_name, rfs, rustc};

fn main() {
rustc().input("foo.rs").arg("-Cprefer-dynamic").run();
rfs::create_dir_all("other");
rfs::create_symlink(dynamic_lib_name("foo"), "other");
rustc().input("bar.rs").library_search_path("other").run();

#[cfg(unix)]
{
rfs::unix::symlink(
cwd().join(dynamic_lib_name("foo")),
cwd().join("other").join(dynamic_lib_name("foo")),
);
}
#[cfg(windows)]
{
rfs::windows::symlink_file(
cwd().join(dynamic_lib_name("foo")),
cwd().join("other").join(dynamic_lib_name("foo")),
);
}
#[cfg(not(any(unix, windows)))]
{
// FIXME(jieyouxu): this is not supported, but we really should implement a only-* directive
// that accepts multiple targets, like e.g. `//@ only-target-families: unix, windows`. That
// way, it properly shows up as an ignored test instead of silently passing.
return;
}

rustc().input("bar.rs").library_search_path(cwd()).library_search_path("other").run();
}
16 changes: 15 additions & 1 deletion tests/run-make/symlinked-rlib/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ use run_make_support::{cwd, rfs, rustc};

fn main() {
rustc().input("foo.rs").crate_type("rlib").output("foo.xxx").run();
rfs::create_symlink("foo.xxx", "libfoo.rlib");
#[cfg(unix)]
{
rfs::unix::symlink("foo.xxx", "libfoo.rlib");
}
#[cfg(windows)]
{
rfs::windows::symlink_file("foo.xxx", "libfoo.rlib");
}
#[cfg(not(any(unix, windows)))]
{
// FIXME(jieyouxu): this is not supported, but we really should implement a only-* directive
// that accepts multiple targets, like e.g. `//@ only-target-families: unix, windows`. That
// way, it properly shows up as an ignored test instead of silently passing.
return;
}
rustc().input("bar.rs").library_search_path(cwd()).run();
}

0 comments on commit 1fd1378

Please sign in to comment.