Skip to content

Commit c2932aa

Browse files
committed
Auto merge of rust-lang#126279 - Oneirical:you-can-run-make-but-cannot-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
2 parents 59e2c01 + 03f19d6 commit c2932aa

File tree

8 files changed

+112
-53
lines changed

8 files changed

+112
-53
lines changed

Diff for: src/tools/run-make-support/src/lib.rs

+32
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,38 @@ pub fn cwd() -> PathBuf {
214214
env::current_dir().unwrap()
215215
}
216216

217+
// FIXME(Oneirical): This will no longer be required after compiletest receives the ability
218+
// to manipulate read-only files. See https://github.com/rust-lang/rust/issues/126334
219+
/// Ensure that the path P is read-only while the test runs, and restore original permissions
220+
/// at the end so compiletest can clean up.
221+
/// This will panic on Windows if the path is a directory (as it would otherwise do nothing)
222+
#[track_caller]
223+
pub fn test_while_readonly<P: AsRef<Path>, F: FnOnce() + std::panic::UnwindSafe>(
224+
path: P,
225+
closure: F,
226+
) {
227+
let path = path.as_ref();
228+
if is_windows() && path.is_dir() {
229+
eprintln!("This helper function cannot be used on Windows to make directories readonly.");
230+
eprintln!(
231+
"See the official documentation:
232+
https://doc.rust-lang.org/std/fs/struct.Permissions.html#method.set_readonly"
233+
);
234+
panic!("`test_while_readonly` on directory detected while on Windows.");
235+
}
236+
let metadata = fs_wrapper::metadata(&path);
237+
let original_perms = metadata.permissions();
238+
239+
let mut new_perms = original_perms.clone();
240+
new_perms.set_readonly(true);
241+
fs_wrapper::set_permissions(&path, new_perms);
242+
243+
let success = std::panic::catch_unwind(closure);
244+
245+
fs_wrapper::set_permissions(&path, original_perms);
246+
success.unwrap();
247+
}
248+
217249
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
218250
/// available on the platform!
219251
#[track_caller]

Diff for: src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ run-make/foreign-double-unwind/Makefile
6161
run-make/foreign-exceptions/Makefile
6262
run-make/foreign-rust-exceptions/Makefile
6363
run-make/glibc-staticlib-args/Makefile
64-
run-make/inaccessible-temp-dir/Makefile
6564
run-make/include_bytes_deps/Makefile
6665
run-make/incr-add-rust-src-component/Makefile
6766
run-make/incr-foreign-head-span/Makefile
@@ -74,7 +73,6 @@ run-make/invalid-library/Makefile
7473
run-make/invalid-so/Makefile
7574
run-make/invalid-staticlib/Makefile
7675
run-make/issue-107094/Makefile
77-
run-make/issue-10971-temps-dir/Makefile
7876
run-make/issue-109934-lto-debuginfo/Makefile
7977
run-make/issue-14698/Makefile
8078
run-make/issue-15460/Makefile
@@ -150,7 +148,6 @@ run-make/optimization-remarks-dir/Makefile
150148
run-make/output-filename-conflicts-with-directory/Makefile
151149
run-make/output-filename-overwrites-input/Makefile
152150
run-make/output-type-permutations/Makefile
153-
run-make/output-with-hyphens/Makefile
154151
run-make/override-aliased-flags/Makefile
155152
run-make/overwrite-input/Makefile
156153
run-make/panic-abort-eh_frame/Makefile

Diff for: tests/run-make/inaccessible-temp-dir/Makefile

-32
This file was deleted.

Diff for: tests/run-make/inaccessible-temp-dir/rmake.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Issue #66530: We would ICE if someone compiled with `-o /dev/null`,
2+
// because we would try to generate auxiliary files in `/dev/` (which
3+
// at least the OS X file system rejects).
4+
//
5+
// An attempt to `-Ztemps-dir` into a directory we cannot write into should
6+
// indeed be an error; but not an ICE.
7+
//
8+
// However, some folks run tests as root, which can write `/dev/` and end
9+
// up clobbering `/dev/null`. Instead we'll use an inaccessible path, which
10+
// also used to ICE, but even root can't magically write there.
11+
//
12+
// Note that `-Ztemps-dir` uses `create_dir_all` so it is not sufficient to
13+
// use a directory with non-existing parent like `/does-not-exist/output`.
14+
// See https://github.com/rust-lang/rust/issues/66530
15+
16+
//@ ignore-arm
17+
// Reason: linker error on `armhf-gnu`
18+
//@ ignore-windows
19+
// Reason: `set_readonly` has no effect on directories
20+
// and does not prevent modification.
21+
22+
use run_make_support::{fs_wrapper, rustc, test_while_readonly};
23+
24+
fn main() {
25+
// Create an inaccessible directory.
26+
fs_wrapper::create_dir("inaccessible");
27+
test_while_readonly("inaccessible", || {
28+
// Run rustc with `-Z temps-dir` set to a directory *inside* the inaccessible one,
29+
// so that it can't create `tmp`.
30+
rustc()
31+
.input("program.rs")
32+
.arg("-Ztemps-dir=inaccessible/tmp")
33+
.run_fail()
34+
.assert_stderr_contains(
35+
"failed to find or create the directory specified by `--temps-dir`",
36+
);
37+
});
38+
}

Diff for: tests/run-make/issue-10971-temps-dir/Makefile

-10
This file was deleted.

Diff for: tests/run-make/output-with-hyphens/Makefile

-8
This file was deleted.

Diff for: tests/run-make/output-with-hyphens/rmake.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Rust files with hyphens in their filename should
2+
// not result in compiled libraries keeping that hyphen -
3+
// it should become an underscore. Only bin executables
4+
// should keep the hyphen. This test ensures that this rule
5+
// remains enforced.
6+
// See https://github.com/rust-lang/rust/pull/23786
7+
8+
//@ ignore-cross-compile
9+
10+
use run_make_support::{bin_name, path, rust_lib_name, rustc};
11+
12+
fn main() {
13+
rustc().input("foo-bar.rs").crate_type("bin").run();
14+
assert!(path(bin_name("foo-bar")).exists());
15+
rustc().input("foo-bar.rs").crate_type("lib").run();
16+
assert!(path(rust_lib_name("foo_bar")).exists());
17+
}

Diff for: tests/run-make/parallel-rustc-no-overwrite/rmake.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// When two instances of rustc are invoked in parallel, they
2+
// can conflict on their temporary files and overwrite each others',
3+
// leading to unsuccessful compilation. The -Z temps-dir flag adds
4+
// separate designated directories for each rustc invocation, preventing
5+
// conflicts. This test uses this flag and checks for successful compilation.
6+
// See https://github.com/rust-lang/rust/pull/83846
7+
8+
use run_make_support::{fs_wrapper, rustc};
9+
use std::sync::{Arc, Barrier};
10+
use std::thread;
11+
12+
fn main() {
13+
fs_wrapper::create_file("lib.rs");
14+
let barrier = Arc::new(Barrier::new(2));
15+
let handle = {
16+
let barrier = Arc::clone(&barrier);
17+
thread::spawn(move || {
18+
barrier.wait();
19+
rustc().crate_type("lib").arg("-Ztemps-dir=temp1").input("lib.rs").run();
20+
})
21+
};
22+
barrier.wait();
23+
rustc().crate_type("staticlib").arg("-Ztemps-dir=temp2").input("lib.rs").run();
24+
handle.join().expect("lib thread panicked");
25+
}

0 commit comments

Comments
 (0)