authorbors <bors@rust-lang.org> 2024-06-11 15:50:25 UTC
committerbors <bors@rust-lang.org> 2024-06-11 15:50:25 UTC
log3ea5e236ecb4c5f22437059f82d3915d311e4ec0
treed53e401384bc689dfab71897283ef6c03638e8a1
parent0c960618b56f662d933e8b864cd9632a99174e87
parentc84afee89851f0d0d5089d64d35225a6adb28453

Auto merge of #125736 - Oneirical:run-make-file-management, r=jieyouxu

run-make-support: add wrapper for `fs` operations Suggested by #125728. The point of this wrapper is to stop silent fails caused by forgetting to `unwrap` `fs` functions. However, functions like `fs::read` which return something and get stored in a variable should cause a failure on their own if they are not unwrapped (as the `Result` will be stored in the variable, and something will be done on that `Result` that should have been done to its contents). Is it still pertinent to wrap `fs::read_to_string`, `fs::metadata` and so on? Closes: https://github.com/rust-lang/rust/issues/125728 try-job: x86_64-msvc try-job: i686-mingw

36 files changed, 211 insertions(+), 108 deletions(-)

src/tools/run-make-support/src/fs_wrapper.rs created+113
......@@ -0,0 +1,113 @@
1use std::fs;
2use std::path::Path;
3
4/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message..
5#[track_caller]
6pub fn remove_file<P: AsRef<Path>>(path: P) {
7 fs::remove_file(path.as_ref())
8 .expect(&format!("the file in path \"{}\" could not be removed", path.as_ref().display()));
9}
10
11/// A wrapper around [`std::fs::copy`] which includes the file path in the panic message.
12#[track_caller]
13pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
14 fs::copy(from.as_ref(), to.as_ref()).expect(&format!(
15 "the file \"{}\" could not be copied over to \"{}\"",
16 from.as_ref().display(),
17 to.as_ref().display(),
18 ));
19}
20
21/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
22#[track_caller]
23pub fn create_file<P: AsRef<Path>>(path: P) {
24 fs::File::create(path.as_ref())
25 .expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display()));
26}
27
28/// A wrapper around [`std::fs::read`] which includes the file path in the panic message..
29#[track_caller]
30pub fn read<P: AsRef<Path>>(path: P) -> Vec<u8> {
31 fs::read(path.as_ref())
32 .expect(&format!("the file in path \"{}\" could not be read", path.as_ref().display()))
33}
34
35/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message..
36#[track_caller]
37pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
38 fs::read_to_string(path.as_ref()).expect(&format!(
39 "the file in path \"{}\" could not be read into a String",
40 path.as_ref().display()
41 ))
42}
43
44/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message..
45#[track_caller]
46pub fn read_dir<P: AsRef<Path>>(path: P) -> fs::ReadDir {
47 fs::read_dir(path.as_ref())
48 .expect(&format!("the directory in path \"{}\" could not be read", path.as_ref().display()))
49}
50
51/// A wrapper around [`std::fs::write`] which includes the file path in the panic message..
52#[track_caller]
53pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
54 fs::write(path.as_ref(), contents.as_ref()).expect(&format!(
55 "the file in path \"{}\" could not be written to",
56 path.as_ref().display()
57 ));
58}
59
60/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message..
61#[track_caller]
62pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
63 fs::remove_dir_all(path.as_ref()).expect(&format!(
64 "the directory in path \"{}\" could not be removed alongside all its contents",
65 path.as_ref().display(),
66 ));
67}
68
69/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message..
70#[track_caller]
71pub fn create_dir<P: AsRef<Path>>(path: P) {
72 fs::create_dir(path.as_ref()).expect(&format!(
73 "the directory in path \"{}\" could not be created",
74 path.as_ref().display()
75 ));
76}
77
78/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message..
79#[track_caller]
80pub fn create_dir_all<P: AsRef<Path>>(path: P) {
81 fs::create_dir_all(path.as_ref()).expect(&format!(
82 "the directory (and all its parents) in path \"{}\" could not be created",
83 path.as_ref().display()
84 ));
85}
86
87/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message..
88#[track_caller]
89pub fn metadata<P: AsRef<Path>>(path: P) -> fs::Metadata {
90 fs::metadata(path.as_ref()).expect(&format!(
91 "the file's metadata in path \"{}\" could not be read",
92 path.as_ref().display()
93 ))
94}
95
96/// A wrapper around [`std::fs::rename`] which includes the file path in the panic message.
97#[track_caller]
98pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
99 fs::rename(from.as_ref(), to.as_ref()).expect(&format!(
100 "the file \"{}\" could not be moved over to \"{}\"",
101 from.as_ref().display(),
102 to.as_ref().display(),
103 ));
104}
105
106/// A wrapper around [`std::fs::set_permissions`] which includes the file path in the panic message.
107#[track_caller]
108pub fn set_permissions<P: AsRef<Path>>(path: P, perm: fs::Permissions) {
109 fs::set_permissions(path.as_ref(), perm).expect(&format!(
110 "the file's permissions in path \"{}\" could not be changed",
111 path.as_ref().display()
112 ));
113}
src/tools/run-make-support/src/lib.rs+8-14
......@@ -8,6 +8,7 @@ pub mod clang;
88mod command;
99pub mod diff;
1010mod drop_bomb;
11pub mod fs_wrapper;
1112pub mod llvm_readobj;
1213pub mod run;
1314pub mod rustc;
......@@ -153,7 +154,7 @@ pub fn dynamic_lib_extension() -> &'static str {
153154 }
154155}
155156
156/// Construct a rust library (rlib) name.
157/// Generate the name a rust library (rlib) would have.
157158pub fn rust_lib_name(name: &str) -> String {
158159 format!("lib{name}.rlib")
159160}
......@@ -228,15 +229,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
228229 fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
229230 let dst = dst.as_ref();
230231 if !dst.is_dir() {
231 fs::create_dir_all(&dst)?;
232 std::fs::create_dir_all(&dst)?;
232233 }
233 for entry in fs::read_dir(src)? {
234 for entry in std::fs::read_dir(src)? {
234235 let entry = entry?;
235236 let ty = entry.file_type()?;
236237 if ty.is_dir() {
237238 copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?;
238239 } else {
239 fs::copy(entry.path(), dst.join(entry.file_name()))?;
240 std::fs::copy(entry.path(), dst.join(entry.file_name()))?;
240241 }
241242 }
242243 Ok(())
......@@ -255,13 +256,6 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
255256
256257/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
257258pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
258 fn read_file(path: &Path) -> Vec<u8> {
259 match fs::read(path) {
260 Ok(c) => c,
261 Err(e) => panic!("Failed to read `{}`: {:?}", path.display(), e),
262 }
263 }
264
265259 let dir2 = dir2.as_ref();
266260 read_dir(dir1, |entry_path| {
267261 let entry_name = entry_path.file_name().unwrap();
......@@ -269,8 +263,8 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
269263 recursive_diff(&entry_path, &dir2.join(entry_name));
270264 } else {
271265 let path2 = dir2.join(entry_name);
272 let file1 = read_file(&entry_path);
273 let file2 = read_file(&path2);
266 let file1 = fs_wrapper::read(&entry_path);
267 let file2 = fs_wrapper::read(&path2);
274268
275269 // We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
276270 // Why not using String? Because there might be minified files or even potentially
......@@ -286,7 +280,7 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
286280}
287281
288282pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
289 for entry in fs::read_dir(dir).unwrap() {
283 for entry in fs_wrapper::read_dir(dir) {
290284 callback(&entry.unwrap().path());
291285 }
292286}
tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs+2-2
......@@ -5,7 +5,7 @@
55
66use std::path::PathBuf;
77
8use run_make_support::{aux_build, rustc, source_root};
8use run_make_support::{aux_build, fs_wrapper, rustc, source_root};
99
1010fn main() {
1111 aux_build().input("stable.rs").emit("metadata").run();
......@@ -13,7 +13,7 @@ fn main() {
1313 let output =
1414 rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run();
1515
16 let version = std::fs::read_to_string(source_root().join("src/version")).unwrap();
16 let version = fs_wrapper::read_to_string(source_root().join("src/version"));
1717 let expected_string = format!("stable since {}", version.trim());
1818 output.assert_stderr_contains(expected_string);
1919}
tests/run-make/c-link-to-rust-dylib/rmake.rs+4-4
......@@ -3,9 +3,9 @@
33
44//@ ignore-cross-compile
55
6use std::fs::remove_file;
7
8use run_make_support::{cc, cwd, dynamic_lib_extension, is_msvc, read_dir, run, run_fail, rustc};
6use run_make_support::{
7 cc, cwd, dynamic_lib_extension, fs_wrapper, is_msvc, read_dir, run, run_fail, rustc,
8};
99
1010fn main() {
1111 rustc().input("foo.rs").run();
......@@ -28,7 +28,7 @@ fn main() {
2828 name.ends_with(".so") || name.ends_with(".dll") || name.ends_with(".dylib")
2929 })
3030 {
31 remove_file(path).unwrap();
31 fs_wrapper::remove_file(path);
3232 }
3333 });
3434 run_fail("bar");
tests/run-make/c-link-to-rust-staticlib/rmake.rs+2-1
......@@ -3,6 +3,7 @@
33
44//@ ignore-cross-compile
55
6use run_make_support::fs_wrapper::remove_file;
67use run_make_support::{cc, extra_c_flags, run, rustc, static_lib_name};
78use std::fs;
89
......@@ -10,6 +11,6 @@ fn main() {
1011 rustc().input("foo.rs").run();
1112 cc().input("bar.c").input(static_lib_name("foo")).out_exe("bar").args(&extra_c_flags()).run();
1213 run("bar");
13 fs::remove_file(static_lib_name("foo"));
14 remove_file(static_lib_name("foo"));
1415 run("bar");
1516}
tests/run-make/cdylib/rmake.rs+2-4
......@@ -10,9 +10,7 @@
1010
1111//@ ignore-cross-compile
1212
13use std::fs::remove_file;
14
15use run_make_support::{cc, cwd, dynamic_lib_name, is_msvc, run, rustc};
13use run_make_support::{cc, cwd, dynamic_lib_name, fs_wrapper, is_msvc, run, rustc};
1614
1715fn main() {
1816 rustc().input("bar.rs").run();
......@@ -25,7 +23,7 @@ fn main() {
2523 }
2624
2725 run("foo");
28 remove_file(dynamic_lib_name("foo")).unwrap();
26 fs_wrapper::remove_file(dynamic_lib_name("foo"));
2927
3028 rustc().input("foo.rs").arg("-Clto").run();
3129 run("foo");
tests/run-make/compiler-builtins/rmake.rs+3-3
......@@ -14,6 +14,7 @@
1414
1515#![deny(warnings)]
1616
17use run_make_support::fs_wrapper::{read, read_dir};
1718use run_make_support::object::read::archive::ArchiveFile;
1819use run_make_support::object::read::Object;
1920use run_make_support::object::ObjectSection;
......@@ -55,8 +56,7 @@ fn main() {
5556 cmd.run();
5657
5758 let rlibs_path = target_dir.join(target).join("debug").join("deps");
58 let compiler_builtins_rlib = std::fs::read_dir(rlibs_path)
59 .unwrap()
59 let compiler_builtins_rlib = read_dir(rlibs_path)
6060 .find_map(|e| {
6161 let path = e.unwrap().path();
6262 let file_name = path.file_name().unwrap().to_str().unwrap();
......@@ -70,7 +70,7 @@ fn main() {
7070
7171 // rlib files are archives, where the archive members each a CGU, and we also have one called
7272 // lib.rmeta which is the encoded metadata. Each of the CGUs is an object file.
73 let data = std::fs::read(compiler_builtins_rlib).unwrap();
73 let data = read(compiler_builtins_rlib);
7474
7575 let mut defined_symbols = HashSet::new();
7676 let mut undefined_relocations = HashSet::new();
tests/run-make/const-prop-lint/rmake.rs+2-4
......@@ -1,13 +1,11 @@
11// Tests that const prop lints interrupting codegen don't leave `.o` files around.
22
3use std::fs;
4
5use run_make_support::{cwd, rustc};
3use run_make_support::{cwd, fs_wrapper, rustc};
64
75fn main() {
86 rustc().input("input.rs").run_fail().assert_exit_code(1);
97
10 for entry in fs::read_dir(cwd()).unwrap() {
8 for entry in fs_wrapper::read_dir(cwd()) {
119 let entry = entry.unwrap();
1210 let path = entry.path();
1311
tests/run-make/doctests-keep-binaries/rmake.rs+4-4
......@@ -1,13 +1,13 @@
11// Check that valid binaries are persisted by running them, regardless of whether the
22// --run or --no-run option is used.
33
4use run_make_support::fs_wrapper::{create_dir, remove_dir_all};
45use run_make_support::{run, rustc, rustdoc};
5use std::fs::{create_dir, remove_dir_all};
66use std::path::Path;
77
88fn setup_test_env<F: FnOnce(&Path, &Path)>(callback: F) {
99 let out_dir = Path::new("doctests");
10 create_dir(&out_dir).expect("failed to create doctests folder");
10 create_dir(&out_dir);
1111 rustc().input("t.rs").crate_type("rlib").run();
1212 callback(&out_dir, Path::new("libt.rlib"));
1313 remove_dir_all(out_dir);
......@@ -43,9 +43,9 @@ fn main() {
4343 check_generated_binaries();
4444 });
4545 // Behavior with --test-run-directory with relative paths.
46 setup_test_env(|_out_dir, extern_path| {
46 setup_test_env(|_out_dir, _extern_path| {
4747 let run_dir_path = Path::new("rundir");
48 create_dir(&run_dir_path).expect("failed to create rundir folder");
48 create_dir(&run_dir_path);
4949
5050 rustdoc()
5151 .input("t.rs")
tests/run-make/doctests-runtool/rmake.rs+2-2
......@@ -1,12 +1,12 @@
11// Tests behavior of rustdoc `--runtool`.
22
3use run_make_support::fs_wrapper::{create_dir, remove_dir_all};
34use run_make_support::{rustc, rustdoc};
4use std::fs::{create_dir, remove_dir_all};
55use std::path::PathBuf;
66
77fn mkdir(name: &str) -> PathBuf {
88 let dir = PathBuf::from(name);
9 create_dir(&dir).expect("failed to create doctests folder");
9 create_dir(&dir);
1010 dir
1111}
1212
tests/run-make/emit-named-files/rmake.rs+2-3
......@@ -1,7 +1,6 @@
1use std::fs::create_dir;
21use std::path::Path;
32
4use run_make_support::rustc;
3use run_make_support::{fs_wrapper, rustc};
54
65fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
76 let out_file = out_dir.join(out_file);
......@@ -12,7 +11,7 @@ fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
1211fn main() {
1312 let out_dir = Path::new("emit");
1413
15 create_dir(&out_dir).unwrap();
14 fs_wrapper::create_dir(&out_dir);
1615
1716 emit_and_check(&out_dir, "libfoo.s", "asm");
1817 emit_and_check(&out_dir, "libfoo.bc", "llvm-bc");
tests/run-make/incr-prev-body-beyond-eof/rmake.rs+5-6
......@@ -13,15 +13,14 @@
1313//@ ignore-nvptx64-nvidia-cuda
1414// FIXME: can't find crate for `std`
1515
16use run_make_support::fs_wrapper as fs;
1617use run_make_support::rustc;
17use std::fs;
1818
1919fn main() {
20 // FIXME(Oneirical): Use run_make_support::fs_wrapper here.
21 fs::create_dir("src").unwrap();
22 fs::create_dir("incr").unwrap();
23 fs::copy("a.rs", "src/main.rs").unwrap();
20 fs::create_dir("src");
21 fs::create_dir("incr");
22 fs::copy("a.rs", "src/main.rs");
2423 rustc().incremental("incr").input("src/main.rs").run();
25 fs::copy("b.rs", "src/main.rs").unwrap();
24 fs::copy("b.rs", "src/main.rs");
2625 rustc().incremental("incr").input("src/main.rs").run();
2726}
tests/run-make/issue-107495-archive-permissions/rmake.rs+3-3
......@@ -3,8 +3,8 @@
33#[cfg(unix)]
44extern crate libc;
55
6use run_make_support::aux_build;
7use std::fs;
6use run_make_support::{aux_build, fs_wrapper};
7
88#[cfg(unix)]
99use std::os::unix::fs::PermissionsExt;
1010use std::path::Path;
......@@ -20,7 +20,7 @@ fn main() {
2020}
2121
2222fn verify(path: &Path) {
23 let perm = fs::metadata(path).unwrap().permissions();
23 let perm = fs_wrapper::metadata(path).permissions();
2424
2525 assert!(!perm.readonly());
2626
tests/run-make/mixing-formats/rmake.rs-1
......@@ -13,7 +13,6 @@
1313//@ ignore-cross-compile
1414
1515use run_make_support::{run_in_tmpdir, rustc};
16use std::fs;
1716
1817fn main() {
1918 run_in_tmpdir(|| {
tests/run-make/non-unicode-env/rmake.rs+2-1
......@@ -1,3 +1,4 @@
1use run_make_support::fs_wrapper;
12use run_make_support::rustc;
23
34fn main() {
......@@ -6,6 +7,6 @@ fn main() {
67 #[cfg(windows)]
78 let non_unicode: std::ffi::OsString = std::os::windows::ffi::OsStringExt::from_wide(&[0xD800]);
89 let output = rustc().input("non_unicode_env.rs").env("NON_UNICODE_VAR", non_unicode).run_fail();
9 let expected = std::fs::read_to_string("non_unicode_env.stderr").unwrap();
10 let expected = fs_wrapper::read_to_string("non_unicode_env.stderr");
1011 output.assert_stderr_equals(expected);
1112}
tests/run-make/non-unicode-in-incremental-dir/rmake.rs+3-3
......@@ -1,4 +1,4 @@
1use run_make_support::rustc;
1use run_make_support::{fs_wrapper, rustc};
22
33fn main() {
44 #[cfg(unix)]
......@@ -17,8 +17,8 @@ fn main() {
1717 }
1818 let incr_dir = "incr-dir";
1919 rustc().input("foo.rs").incremental(&incr_dir).run();
20 for crate_dir in std::fs::read_dir(&incr_dir).unwrap() {
21 std::fs::create_dir(crate_dir.unwrap().path().join(&non_unicode)).unwrap();
20 for crate_dir in fs_wrapper::read_dir(&incr_dir) {
21 fs_wrapper::create_dir(crate_dir.unwrap().path().join(&non_unicode));
2222 }
2323 rustc().input("foo.rs").incremental(&incr_dir).run();
2424}
tests/run-make/print-cfg/rmake.rs+2-2
......@@ -10,7 +10,7 @@ use std::ffi::OsString;
1010use std::iter::FromIterator;
1111use std::path::PathBuf;
1212
13use run_make_support::rustc;
13use run_make_support::{fs_wrapper, rustc};
1414
1515struct PrintCfg {
1616 target: &'static str,
......@@ -96,7 +96,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
9696
9797 rustc().target(target).arg(print_arg).run();
9898
99 let output = std::fs::read_to_string(&tmp_path).unwrap();
99 let output = fs_wrapper::read_to_string(&tmp_path);
100100
101101 check_(&output, includes, disallow);
102102 }
tests/run-make/print-to-output/rmake.rs+2-2
......@@ -4,7 +4,7 @@
44use std::ffi::OsString;
55use std::path::PathBuf;
66
7use run_make_support::{rustc, target};
7use run_make_support::{fs_wrapper, rustc, target};
88
99struct Option<'a> {
1010 target: &'a str,
......@@ -49,7 +49,7 @@ fn check(args: Option) {
4949
5050 rustc().target(args.target).arg(print_arg).run();
5151
52 std::fs::read_to_string(&tmp_path).unwrap()
52 fs_wrapper::read_to_string(&tmp_path)
5353 };
5454
5555 check_(&stdout, args.includes);
tests/run-make/repr128-dwarf/rmake.rs+2-3
......@@ -3,7 +3,7 @@
33
44use gimli::{AttributeValue, EndianRcSlice, Reader, RunTimeEndian};
55use object::{Object, ObjectSection};
6use run_make_support::{gimli, object, rustc};
6use run_make_support::{fs_wrapper, gimli, object, rustc};
77use std::collections::HashMap;
88use std::path::PathBuf;
99use std::rc::Rc;
......@@ -19,8 +19,7 @@ fn main() {
1919 .join("DWARF")
2020 .join("repr128");
2121 let output =
22 std::fs::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output })
23 .unwrap();
22 fs_wrapper::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output });
2423 let obj = object::File::parse(output.as_slice()).unwrap();
2524 let endian = if obj.is_little_endian() { RunTimeEndian::Little } else { RunTimeEndian::Big };
2625 let dwarf = gimli::Dwarf::load(|section| -> Result<_, ()> {
tests/run-make/reset-codegen-1/rmake.rs+9-5
......@@ -7,8 +7,8 @@
77
88//@ ignore-cross-compile
99
10use run_make_support::rustc;
11use std::fs;
10use run_make_support::{bin_name, fs_wrapper, rustc};
11use std::path::Path;
1212
1313fn compile(output_file: &str, emit: Option<&str>) {
1414 let mut rustc = rustc();
......@@ -28,11 +28,15 @@ fn main() {
2828 ("link-output", Some("link")),
2929 ("obj-output", Some("obj")),
3030 ("dep-output", Some("dep-info")),
31 ("multi-output", Some("asm,obj")),
3231 ];
3332 for (output_file, emit) in flags {
34 fs::remove_file(output_file).unwrap_or_default();
33 // In the None case, bin_name is required for successful Windows compilation.
34 let output_file = &bin_name(output_file);
3535 compile(output_file, emit);
36 fs::remove_file(output_file);
36 assert!(Path::new(output_file).is_file());
3737 }
38
39 compile("multi-output", Some("asm,obj"));
40 assert!(Path::new("multi-output.s").is_file());
41 assert!(Path::new("multi-output.o").is_file());
3842}
tests/run-make/resolve-rename/rmake.rs+3-2
......@@ -5,11 +5,12 @@
55// the renamed library.
66// See https://github.com/rust-lang/rust/pull/49253
77
8use run_make_support::fs_wrapper;
89use run_make_support::rustc;
9use std::fs;
10
1011fn main() {
1112 rustc().extra_filename("-hash").input("foo.rs").run();
1213 rustc().input("bar.rs").run();
13 fs::rename("libfoo-hash.rlib", "libfoo-another-hash.rlib").unwrap();
14 fs_wrapper::rename("libfoo-hash.rlib", "libfoo-another-hash.rlib");
1415 rustc().input("baz.rs").run();
1516}
tests/run-make/rustdoc-scrape-examples-remap/scrape.rs+2-4
......@@ -1,12 +1,10 @@
1use run_make_support::{htmldocck, rustc, rustdoc, source_root};
2use std::fs::read_dir;
1use run_make_support::{fs_wrapper, htmldocck, rustc, rustdoc, source_root};
32use std::path::Path;
43
54pub fn scrape(extra_args: &[&str]) {
65 let out_dir = Path::new("rustdoc");
76 let crate_name = "foobar";
8 let deps = read_dir("examples")
9 .unwrap()
7 let deps = fs_wrapper::read_dir("examples")
108 .filter_map(|entry| entry.ok().map(|e| e.path()))
119 .filter(|path| path.is_file() && path.extension().is_some_and(|ext| ext == "rs"))
1210 .collect::<Vec<_>>();
tests/run-make/rustdoc-test-args/rmake.rs+3-3
......@@ -1,10 +1,10 @@
1use run_make_support::rustdoc;
1use run_make_support::{fs_wrapper, rustdoc};
2use std::iter;
23use std::path::Path;
3use std::{fs, iter};
44
55fn generate_a_lot_of_cfgs(path: &Path) {
66 let content = iter::repeat("--cfg=a\n").take(100_000).collect::<String>();
7 fs::write(path, content.as_bytes()).expect("failed to create args file");
7 fs_wrapper::write(path, content.as_bytes());
88}
99
1010fn main() {
tests/run-make/rustdoc-themes/rmake.rs+6-6
......@@ -1,15 +1,15 @@
11// Test that rustdoc will properly load in a theme file and display it in the theme selector.
22
3use run_make_support::{htmldocck, rustdoc, source_root};
3use run_make_support::{fs_wrapper, htmldocck, rustdoc, source_root};
44use std::path::Path;
55
66fn main() {
77 let out_dir = Path::new("rustdoc-themes");
88 let test_css = "test.css";
99
10 let no_script =
11 std::fs::read_to_string(source_root().join("src/librustdoc/html/static/css/noscript.css"))
12 .unwrap();
10 let no_script = fs_wrapper::read_to_string(
11 source_root().join("src/librustdoc/html/static/css/noscript.css"),
12 );
1313
1414 let mut test_content = String::new();
1515 let mut found_begin_light = false;
......@@ -24,8 +24,8 @@ fn main() {
2424 }
2525 }
2626 assert!(!test_content.is_empty());
27 std::fs::create_dir_all(&out_dir).unwrap();
28 std::fs::write(&test_css, test_content).unwrap();
27 fs_wrapper::create_dir_all(&out_dir);
28 fs_wrapper::write(&test_css, test_content);
2929
3030 rustdoc().output(&out_dir).input("foo.rs").arg("--theme").arg(&test_css).run();
3131 htmldocck().arg(out_dir).arg("foo.rs").run();
tests/run-make/rustdoc-verify-output-files/rmake.rs+2-2
......@@ -1,4 +1,4 @@
1use std::fs::copy;
1use run_make_support::fs_wrapper::copy;
22use std::path::{Path, PathBuf};
33
44use run_make_support::{copy_dir_all, recursive_diff, rustdoc};
......@@ -38,7 +38,7 @@ fn main() {
3838 assert!(out_dir.join("foobar.json").is_file());
3939
4040 // Copy first json output to check if it's exactly same after second compilation.
41 copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")).unwrap();
41 copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json"));
4242
4343 // Generate json doc on the same output.
4444 generate_docs(&out_dir, JsonOutput::Yes);
tests/run-make/wasm-custom-section/rmake.rs+2-2
......@@ -1,13 +1,13 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::collections::HashMap;
55
66fn main() {
77 rustc().input("foo.rs").target("wasm32-wasip1").run();
88 rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
99
10 let file = std::fs::read("bar.wasm").unwrap();
10 let file = fs_wrapper::read("bar.wasm");
1111
1212 let mut custom = HashMap::new();
1313 for payload in wasmparser::Parser::new(0).parse_all(&file) {
tests/run-make/wasm-custom-sections-opt/rmake.rs+3-3
......@@ -1,18 +1,18 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::collections::HashMap;
55use std::path::Path;
66
77fn main() {
88 rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
99
10 verify(&Path::new("foo.wasm"));
10 verify(Path::new("foo.wasm"));
1111}
1212
1313fn verify(path: &Path) {
1414 eprintln!("verify {path:?}");
15 let file = std::fs::read(&path).unwrap();
15 let file = fs_wrapper::read(&path);
1616
1717 let mut custom = HashMap::new();
1818 for payload in wasmparser::Parser::new(0).parse_all(&file) {
tests/run-make/wasm-export-all-symbols/rmake.rs+2-2
......@@ -1,6 +1,6 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::collections::HashMap;
55use std::path::Path;
66use wasmparser::ExternalKind::*;
......@@ -33,7 +33,7 @@ fn test(args: &[&str]) {
3333
3434fn verify_exports(path: &Path, exports: &[(&str, wasmparser::ExternalKind)]) {
3535 println!("verify {path:?}");
36 let file = std::fs::read(path).unwrap();
36 let file = fs_wrapper::read(path);
3737 let mut wasm_exports = HashMap::new();
3838 for payload in wasmparser::Parser::new(0).parse_all(&file) {
3939 let payload = payload.unwrap();
tests/run-make/wasm-import-module/rmake.rs+2-2
......@@ -1,6 +1,6 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::collections::HashMap;
55use wasmparser::TypeRef::Func;
66
......@@ -8,7 +8,7 @@ fn main() {
88 rustc().input("foo.rs").target("wasm32-wasip1").run();
99 rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
1010
11 let file = std::fs::read("bar.wasm").unwrap();
11 let file = fs_wrapper::read("bar.wasm");
1212
1313 let mut imports = HashMap::new();
1414 for payload in wasmparser::Parser::new(0).parse_all(&file) {
tests/run-make/wasm-panic-small/rmake.rs+2-2
......@@ -1,7 +1,7 @@
11//@ only-wasm32-wasip1
22#![deny(warnings)]
33
4use run_make_support::rustc;
4use run_make_support::{fs_wrapper, rustc};
55
66fn main() {
77 test("a");
......@@ -15,7 +15,7 @@ fn test(cfg: &str) {
1515
1616 rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().cfg(cfg).run();
1717
18 let bytes = std::fs::read("foo.wasm").unwrap();
18 let bytes = fs_wrapper::read("foo.wasm");
1919 println!("{}", bytes.len());
2020 assert!(bytes.len() < 40_000);
2121}
tests/run-make/wasm-spurious-import/rmake.rs+2-2
......@@ -1,6 +1,6 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::collections::HashMap;
55
66fn main() {
......@@ -13,7 +13,7 @@ fn main() {
1313 .arg("-Copt-level=z")
1414 .run();
1515
16 let file = std::fs::read("main.wasm").unwrap();
16 let file = fs_wrapper::read("main.wasm");
1717
1818 let mut imports = HashMap::new();
1919 for payload in wasmparser::Parser::new(0).parse_all(&file) {
tests/run-make/wasm-stringify-ints-small/rmake.rs+2-2
......@@ -1,12 +1,12 @@
11//@ only-wasm32-wasip1
22#![deny(warnings)]
33
4use run_make_support::rustc;
4use run_make_support::{fs_wrapper, rustc};
55
66fn main() {
77 rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
88
9 let bytes = std::fs::read("foo.wasm").unwrap();
9 let bytes = fs_wrapper::read("foo.wasm");
1010 println!("{}", bytes.len());
1111 assert!(bytes.len() < 50_000);
1212}
tests/run-make/wasm-symbols-different-module/rmake.rs+2-2
......@@ -1,6 +1,6 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::collections::{HashMap, HashSet};
55use std::path::Path;
66
......@@ -23,7 +23,7 @@ fn test(file: &str, args: &[&str], expected_imports: &[(&str, &[&str])]) {
2323
2424 rustc().input(file).target("wasm32-wasip1").args(args).run();
2525
26 let file = std::fs::read(Path::new(file).with_extension("wasm")).unwrap();
26 let file = fs_wrapper::read(Path::new(file).with_extension("wasm"));
2727
2828 let mut imports = HashMap::new();
2929 for payload in wasmparser::Parser::new(0).parse_all(&file) {
tests/run-make/wasm-symbols-not-exported/rmake.rs+2-2
......@@ -1,6 +1,6 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::path::Path;
55
66fn main() {
......@@ -17,7 +17,7 @@ fn main() {
1717
1818fn verify_symbols(path: &Path) {
1919 eprintln!("verify {path:?}");
20 let file = std::fs::read(&path).unwrap();
20 let file = fs_wrapper::read(&path);
2121
2222 for payload in wasmparser::Parser::new(0).parse_all(&file) {
2323 let payload = payload.unwrap();
tests/run-make/wasm-symbols-not-imported/rmake.rs+2-2
......@@ -1,6 +1,6 @@
11//@ only-wasm32-wasip1
22
3use run_make_support::{rustc, wasmparser};
3use run_make_support::{fs_wrapper, rustc, wasmparser};
44use std::path::Path;
55
66fn main() {
......@@ -16,7 +16,7 @@ fn main() {
1616
1717fn verify_symbols(path: &Path) {
1818 eprintln!("verify {path:?}");
19 let file = std::fs::read(&path).unwrap();
19 let file = fs_wrapper::read(&path);
2020
2121 for payload in wasmparser::Parser::new(0).parse_all(&file) {
2222 let payload = payload.unwrap();
tests/run-make/windows-ws2_32/rmake.rs+2-3
......@@ -3,8 +3,7 @@
33// Tests that WS2_32.dll is not unnecessarily linked, see issue #85441
44
55use run_make_support::object::{self, read::Object};
6use run_make_support::rustc;
7use std::fs;
6use run_make_support::{fs_wrapper, rustc};
87
98fn main() {
109 rustc().input("empty.rs").run();
......@@ -15,7 +14,7 @@ fn main() {
1514}
1615
1716fn links_ws2_32(exe: &str) -> bool {
18 let binary_data = fs::read(exe).unwrap();
17 let binary_data = fs_wrapper::read(exe);
1918 let file = object::File::parse(&*binary_data).unwrap();
2019 for import in file.imports().unwrap() {
2120 if import.library().eq_ignore_ascii_case(b"WS2_32.dll") {