Skip to content

Commit

Permalink
Rollup merge of rust-lang#126279 - Oneirical:you-can-run-make-but-can…
Browse files Browse the repository at this point in the history
…not-hide, r=jieyouxu

Migrate `inaccessible-temp-dir`, `output-with-hyphens` and `issue-10971-temps-dir` `run-make` tests to `rmake`

Part of rust-lang#121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html).

try-job: x86_64-msvc
  • Loading branch information
jieyouxu authored Jun 17, 2024
2 parents 04ab7b2 + 03f19d6 commit d54f8ee
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 53 deletions.
32 changes: 32 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,38 @@ pub fn cwd() -> PathBuf {
env::current_dir().unwrap()
}

// FIXME(Oneirical): This will no longer be required after compiletest receives the ability
// to manipulate read-only files. See https://github.com/rust-lang/rust/issues/126334
/// Ensure that the path P is read-only while the test runs, and restore original permissions
/// at the end so compiletest can clean up.
/// This will panic on Windows if the path is a directory (as it would otherwise do nothing)
#[track_caller]
pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>(
path: P,
closure: F,
) {
let path = path.as_ref();
if is_windows() && path.is_dir() {
eprintln!("This helper function cannot be used on Windows to make directories readonly.");
eprintln!(
"See the official documentation:
https://doc.rust-lang.org/std/fs/struct.Permissions.html#method.set_readonly"
);
panic!("`test_while_readonly` on directory detected while on Windows.");
}
let metadata = fs_wrapper::metadata(&path);
let original_perms = metadata.permissions();

let mut new_perms = original_perms.clone();
new_perms.set_readonly(true);
fs_wrapper::set_permissions(&path, new_perms);

let success = std::panic::catch_unwind(closure);

fs_wrapper::set_permissions(&path, original_perms);
success.unwrap();
}

/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
/// available on the platform!
#[track_caller]
Expand Down
3 changes: 0 additions & 3 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ run-make/foreign-double-unwind/Makefile
run-make/foreign-exceptions/Makefile
run-make/foreign-rust-exceptions/Makefile
run-make/glibc-staticlib-args/Makefile
run-make/inaccessible-temp-dir/Makefile
run-make/include_bytes_deps/Makefile
run-make/incr-add-rust-src-component/Makefile
run-make/incr-foreign-head-span/Makefile
Expand All @@ -74,7 +73,6 @@ run-make/invalid-library/Makefile
run-make/invalid-so/Makefile
run-make/invalid-staticlib/Makefile
run-make/issue-107094/Makefile
run-make/issue-10971-temps-dir/Makefile
run-make/issue-109934-lto-debuginfo/Makefile
run-make/issue-14698/Makefile
run-make/issue-15460/Makefile
Expand Down Expand Up @@ -153,7 +151,6 @@ run-make/optimization-remarks-dir/Makefile
run-make/output-filename-conflicts-with-directory/Makefile
run-make/output-filename-overwrites-input/Makefile
run-make/output-type-permutations/Makefile
run-make/output-with-hyphens/Makefile
run-make/override-aliased-flags/Makefile
run-make/overwrite-input/Makefile
run-make/panic-abort-eh_frame/Makefile
Expand Down
32 changes: 0 additions & 32 deletions tests/run-make/inaccessible-temp-dir/Makefile

This file was deleted.

38 changes: 38 additions & 0 deletions tests/run-make/inaccessible-temp-dir/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Issue #66530: We would ICE if someone compiled with `-o /dev/null`,
// because we would try to generate auxiliary files in `/dev/` (which
// at least the OS X file system rejects).
//
// An attempt to `-Ztemps-dir` into a directory we cannot write into should
// indeed be an error; but not an ICE.
//
// However, some folks run tests as root, which can write `/dev/` and end
// up clobbering `/dev/null`. Instead we'll use an inaccessible path, which
// also used to ICE, but even root can't magically write there.
//
// Note that `-Ztemps-dir` uses `create_dir_all` so it is not sufficient to
// use a directory with non-existing parent like `/does-not-exist/output`.
// See https://github.com/rust-lang/rust/issues/66530

//@ ignore-arm
// Reason: linker error on `armhf-gnu`
//@ ignore-windows
// Reason: `set_readonly` has no effect on directories
// and does not prevent modification.

use run_make_support::{fs_wrapper, rustc, test_while_readonly};

fn main() {
// Create an inaccessible directory.
fs_wrapper::create_dir("inaccessible");
test_while_readonly("inaccessible", || {
// Run rustc with `-Z temps-dir` set to a directory *inside* the inaccessible one,
// so that it can't create `tmp`.
rustc()
.input("program.rs")
.arg("-Ztemps-dir=inaccessible/tmp")
.run_fail()
.assert_stderr_contains(
"failed to find or create the directory specified by `--temps-dir`",
);
});
}
10 changes: 0 additions & 10 deletions tests/run-make/issue-10971-temps-dir/Makefile

This file was deleted.

8 changes: 0 additions & 8 deletions tests/run-make/output-with-hyphens/Makefile

This file was deleted.

17 changes: 17 additions & 0 deletions tests/run-make/output-with-hyphens/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Rust files with hyphens in their filename should
// not result in compiled libraries keeping that hyphen -
// it should become an underscore. Only bin executables
// should keep the hyphen. This test ensures that this rule
// remains enforced.
// See https://github.com/rust-lang/rust/pull/23786

//@ ignore-cross-compile

use run_make_support::{bin_name, path, rust_lib_name, rustc};

fn main() {
rustc().input("foo-bar.rs").crate_type("bin").run();
assert!(path(bin_name("foo-bar")).exists());
rustc().input("foo-bar.rs").crate_type("lib").run();
assert!(path(rust_lib_name("foo_bar")).exists());
}
25 changes: 25 additions & 0 deletions tests/run-make/parallel-rustc-no-overwrite/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// When two instances of rustc are invoked in parallel, they
// can conflict on their temporary files and overwrite each others',
// leading to unsuccessful compilation. The -Z temps-dir flag adds
// separate designated directories for each rustc invocation, preventing
// conflicts. This test uses this flag and checks for successful compilation.
// See https://github.com/rust-lang/rust/pull/83846

use run_make_support::{fs_wrapper, rustc};
use std::sync::{Arc, Barrier};
use std::thread;

fn main() {
fs_wrapper::create_file("lib.rs");
let barrier = Arc::new(Barrier::new(2));
let handle = {
let barrier = Arc::clone(&barrier);
thread::spawn(move || {
barrier.wait();
rustc().crate_type("lib").arg("-Ztemps-dir=temp1").input("lib.rs").run();
})
};
barrier.wait();
rustc().crate_type("staticlib").arg("-Ztemps-dir=temp2").input("lib.rs").run();
handle.join().expect("lib thread panicked");
}

0 comments on commit d54f8ee

Please sign in to comment.