From 427cf94106abb650accd6ef9e2f7252176af9a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 09:32:41 +0000 Subject: [PATCH 01/27] run_make_support: move `impl_common_helpers` into own `macros` module --- src/tools/run-make-support/src/cc.rs | 2 +- src/tools/run-make-support/src/clang.rs | 2 +- src/tools/run-make-support/src/lib.rs | 116 +--------------------- src/tools/run-make-support/src/llvm.rs | 10 +- src/tools/run-make-support/src/macros.rs | 113 +++++++++++++++++++++ src/tools/run-make-support/src/rustc.rs | 2 +- src/tools/run-make-support/src/rustdoc.rs | 2 +- 7 files changed, 125 insertions(+), 122 deletions(-) create mode 100644 src/tools/run-make-support/src/macros.rs diff --git a/src/tools/run-make-support/src/cc.rs b/src/tools/run-make-support/src/cc.rs index 75a20a21a3107..677790b0aa95c 100644 --- a/src/tools/run-make-support/src/cc.rs +++ b/src/tools/run-make-support/src/cc.rs @@ -20,7 +20,7 @@ pub struct Cc { cmd: Command, } -crate::impl_common_helpers!(Cc); +crate::macros::impl_common_helpers!(Cc); impl Cc { /// Construct a new platform-specific C compiler invocation. diff --git a/src/tools/run-make-support/src/clang.rs b/src/tools/run-make-support/src/clang.rs index c23e41ebe2191..2b0712541cd5f 100644 --- a/src/tools/run-make-support/src/clang.rs +++ b/src/tools/run-make-support/src/clang.rs @@ -16,7 +16,7 @@ pub struct Clang { cmd: Command, } -crate::impl_common_helpers!(Clang); +crate::macros::impl_common_helpers!(Clang); impl Clang { /// Construct a new `clang` invocation. `clang` is not always available for all targets. diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index cec2cedd15c9f..cf7d235e4b56d 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -9,6 +9,7 @@ mod command; pub mod diff; pub mod fs_wrapper; pub mod llvm; +mod macros; pub mod run; pub mod rustc; pub mod rustdoc; @@ -37,6 +38,8 @@ pub use run::{cmd, run, run_fail, run_with_args}; pub use rustc::{aux_build, bare_rustc, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; +use command::{Command, CompletedProcess}; + #[track_caller] #[must_use] pub fn env_var(name: &str) -> String { @@ -538,116 +541,3 @@ pub fn run_in_tmpdir(callback: F) { env::set_current_dir(original_dir).unwrap(); fs::remove_dir_all(tmpdir).unwrap(); } - -/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct -/// containing a `cmd: Command` field. The provided helpers are: -/// -/// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended -/// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add -/// new specific helper methods over relying on these generic argument providers. -/// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to -/// methods of the same name on [`Command`]. -/// 3. Output and execution: `run` and `run_fail` are provided. These are -/// higher-level convenience methods which wait for the command to finish running and assert -/// that the command successfully ran or failed as expected. They return -/// [`CompletedProcess`], which can be used to assert the stdout/stderr/exit code of the executed -/// process. -/// -/// Example usage: -/// -/// ```ignore (illustrative) -/// struct CommandWrapper { cmd: Command } // <- required `cmd` field -/// -/// crate::impl_common_helpers!(CommandWrapper); -/// -/// impl CommandWrapper { -/// // ... additional specific helper methods -/// } -/// ``` -macro_rules! impl_common_helpers { - ($wrapper: ident) => { - impl $wrapper { - /// Specify an environment variable. - pub fn env(&mut self, key: K, value: V) -> &mut Self - where - K: AsRef<::std::ffi::OsStr>, - V: AsRef<::std::ffi::OsStr>, - { - self.cmd.env(key, value); - self - } - - /// Remove an environmental variable. - pub fn env_remove(&mut self, key: K) -> &mut Self - where - K: AsRef<::std::ffi::OsStr>, - { - self.cmd.env_remove(key); - self - } - - /// Generic command argument provider. Prefer specific helper methods if possible. - /// Note that for some executables, arguments might be platform specific. For C/C++ - /// compilers, arguments might be platform *and* compiler specific. - pub fn arg(&mut self, arg: S) -> &mut Self - where - S: AsRef<::std::ffi::OsStr>, - { - self.cmd.arg(arg); - self - } - - /// Generic command arguments provider. Prefer specific helper methods if possible. - /// Note that for some executables, arguments might be platform specific. For C/C++ - /// compilers, arguments might be platform *and* compiler specific. - pub fn args(&mut self, args: V) -> &mut Self - where - V: AsRef<[S]>, - S: AsRef<::std::ffi::OsStr>, - { - self.cmd.args(args.as_ref()); - self - } - - /// Inspect what the underlying [`Command`] is up to the - /// current construction. - pub fn inspect(&mut self, inspector: I) -> &mut Self - where - I: FnOnce(&::std::process::Command), - { - self.cmd.inspect(inspector); - self - } - - /// Run the constructed command and assert that it is successfully run. - #[track_caller] - pub fn run(&mut self) -> crate::command::CompletedProcess { - self.cmd.run() - } - - /// Run the constructed command and assert that it does not successfully run. - #[track_caller] - pub fn run_fail(&mut self) -> crate::command::CompletedProcess { - self.cmd.run_fail() - } - - /// Run the command but do not check its exit status. - /// Only use if you explicitly don't care about the exit status. - /// Prefer to use [`Self::run`] and [`Self::run_fail`] - /// whenever possible. - #[track_caller] - pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess { - self.cmd.run_unchecked() - } - - /// Set the path where the command will be run. - pub fn current_dir>(&mut self, path: P) -> &mut Self { - self.cmd.current_dir(path); - self - } - } - }; -} - -use crate::command::{Command, CompletedProcess}; -pub(crate) use impl_common_helpers; diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/llvm.rs index 064dc62a4afa2..e7715a905fb72 100644 --- a/src/tools/run-make-support/src/llvm.rs +++ b/src/tools/run-make-support/src/llvm.rs @@ -70,11 +70,11 @@ pub struct LlvmAr { cmd: Command, } -crate::impl_common_helpers!(LlvmReadobj); -crate::impl_common_helpers!(LlvmProfdata); -crate::impl_common_helpers!(LlvmFilecheck); -crate::impl_common_helpers!(LlvmObjdump); -crate::impl_common_helpers!(LlvmAr); +crate::macros::impl_common_helpers!(LlvmReadobj); +crate::macros::impl_common_helpers!(LlvmProfdata); +crate::macros::impl_common_helpers!(LlvmFilecheck); +crate::macros::impl_common_helpers!(LlvmObjdump); +crate::macros::impl_common_helpers!(LlvmAr); /// Generate the path to the bin directory of LLVM. #[must_use] diff --git a/src/tools/run-make-support/src/macros.rs b/src/tools/run-make-support/src/macros.rs new file mode 100644 index 0000000000000..f7fe4f5422399 --- /dev/null +++ b/src/tools/run-make-support/src/macros.rs @@ -0,0 +1,113 @@ +/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct +/// containing a `cmd: Command` field. The provided helpers are: +/// +/// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended +/// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add +/// new specific helper methods over relying on these generic argument providers. +/// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to +/// methods of the same name on [`Command`]. +/// 3. Output and execution: `run` and `run_fail` are provided. These are higher-level convenience +/// methods which wait for the command to finish running and assert that the command successfully +/// ran or failed as expected. They return [`CompletedProcess`], which can be used to assert the +/// stdout/stderr/exit code of the executed process. +/// +/// Example usage: +/// +/// ```ignore (illustrative) +/// struct CommandWrapper { cmd: Command } // <- required `cmd` field +/// +/// crate::macros::impl_common_helpers!(CommandWrapper); +/// +/// impl CommandWrapper { +/// // ... additional specific helper methods +/// } +/// ``` +/// +/// [`Command`]: crate::command::Command +/// [`CompletedProcess`]: crate::command::CompletedProcess +macro_rules! impl_common_helpers { + ($wrapper: ident) => { + impl $wrapper { + /// Specify an environment variable. + pub fn env(&mut self, key: K, value: V) -> &mut Self + where + K: AsRef<::std::ffi::OsStr>, + V: AsRef<::std::ffi::OsStr>, + { + self.cmd.env(key, value); + self + } + + /// Remove an environmental variable. + pub fn env_remove(&mut self, key: K) -> &mut Self + where + K: AsRef<::std::ffi::OsStr>, + { + self.cmd.env_remove(key); + self + } + + /// Generic command argument provider. Prefer specific helper methods if possible. + /// Note that for some executables, arguments might be platform specific. For C/C++ + /// compilers, arguments might be platform *and* compiler specific. + pub fn arg(&mut self, arg: S) -> &mut Self + where + S: AsRef<::std::ffi::OsStr>, + { + self.cmd.arg(arg); + self + } + + /// Generic command arguments provider. Prefer specific helper methods if possible. + /// Note that for some executables, arguments might be platform specific. For C/C++ + /// compilers, arguments might be platform *and* compiler specific. + pub fn args(&mut self, args: V) -> &mut Self + where + V: AsRef<[S]>, + S: AsRef<::std::ffi::OsStr>, + { + self.cmd.args(args.as_ref()); + self + } + + /// Inspect what the underlying [`Command`] is up to the + /// current construction. + pub fn inspect(&mut self, inspector: I) -> &mut Self + where + I: FnOnce(&::std::process::Command), + { + self.cmd.inspect(inspector); + self + } + + /// Run the constructed command and assert that it is successfully run. + #[track_caller] + pub fn run(&mut self) -> crate::command::CompletedProcess { + self.cmd.run() + } + + /// Run the constructed command and assert that it does not successfully run. + #[track_caller] + pub fn run_fail(&mut self) -> crate::command::CompletedProcess { + self.cmd.run_fail() + } + + /// Run the command but do not check its exit status. + /// Only use if you explicitly don't care about the exit status. + /// Prefer to use [`Self::run`] and [`Self::run_fail`] + /// whenever possible. + #[track_caller] + pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess { + self.cmd.run_unchecked() + } + + /// Set the path where the command will be run. + pub fn current_dir>(&mut self, path: P) -> &mut Self { + self.cmd.current_dir(path); + self + } + } + }; +} + +pub(crate) use impl_common_helpers; diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/rustc.rs index 6b08608cc62f5..8dc6d1238b342 100644 --- a/src/tools/run-make-support/src/rustc.rs +++ b/src/tools/run-make-support/src/rustc.rs @@ -31,7 +31,7 @@ pub struct Rustc { cmd: Command, } -crate::impl_common_helpers!(Rustc); +crate::macros::impl_common_helpers!(Rustc); #[track_caller] fn setup_common() -> Command { diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/rustdoc.rs index 2be962ad88828..547ab0c49c671 100644 --- a/src/tools/run-make-support/src/rustdoc.rs +++ b/src/tools/run-make-support/src/rustdoc.rs @@ -22,7 +22,7 @@ pub struct Rustdoc { cmd: Command, } -crate::impl_common_helpers!(Rustdoc); +crate::macros::impl_common_helpers!(Rustdoc); #[track_caller] fn setup_common() -> Command { From 544dda382892ce6fe228c6dcea756a8e91dd8112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 09:38:01 +0000 Subject: [PATCH 02/27] run_make_support: move target checks into `targets` module --- src/tools/run-make-support/src/lib.rs | 54 ++++++++--------------- src/tools/run-make-support/src/targets.rs | 41 +++++++++++++++++ 2 files changed, 59 insertions(+), 36 deletions(-) create mode 100644 src/tools/run-make-support/src/targets.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index cf7d235e4b56d..1dbbad9132b73 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -13,6 +13,7 @@ mod macros; pub mod run; pub mod rustc; pub mod rustdoc; +pub mod targets; use std::env; use std::ffi::OsString; @@ -37,6 +38,7 @@ pub use llvm::{ pub use run::{cmd, run, run_fail, run_with_args}; pub use rustc::{aux_build, bare_rustc, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; +pub use targets::{is_darwin, is_msvc, is_windows, target, uname}; use command::{Command, CompletedProcess}; @@ -58,28 +60,17 @@ pub fn env_var_os(name: &str) -> OsString { } } -/// `TARGET` -#[must_use] -pub fn target() -> String { - env_var("TARGET") -} - -/// Check if target is windows-like. -#[must_use] -pub fn is_windows() -> bool { - target().contains("windows") -} - -/// Check if target uses msvc. -#[must_use] -pub fn is_msvc() -> bool { - target().contains("msvc") -} - -/// Check if target uses macOS. -#[must_use] -pub fn is_darwin() -> bool { - target().contains("darwin") +/// `AR` +#[track_caller] +pub fn ar(inputs: &[impl AsRef], output_path: impl AsRef) { + let output = fs::File::create(&output_path).expect(&format!( + "the file in path \"{}\" could not be created", + output_path.as_ref().display() + )); + let mut builder = ar::Builder::new(output); + for input in inputs { + builder.append_path(input).unwrap(); + } } #[track_caller] @@ -348,20 +339,11 @@ pub fn cygpath_windows>(path: P) -> String { output.stdout_utf8().trim().to_string() } -/// Run `uname`. This assumes that `uname` is available on the platform! -#[track_caller] -#[must_use] -pub fn uname() -> String { - let caller = panic::Location::caller(); - let mut uname = Command::new("uname"); - let output = uname.run(); - if !output.status().success() { - handle_failed_output(&uname, output, caller.line()); - } - output.stdout_utf8() -} - -fn handle_failed_output(cmd: &Command, output: CompletedProcess, caller_line_number: u32) -> ! { +pub(crate) fn handle_failed_output( + cmd: &Command, + output: CompletedProcess, + caller_line_number: u32, +) -> ! { if output.status().success() { eprintln!("command unexpectedly succeeded at line {caller_line_number}"); } else { diff --git a/src/tools/run-make-support/src/targets.rs b/src/tools/run-make-support/src/targets.rs new file mode 100644 index 0000000000000..68b66e68448c8 --- /dev/null +++ b/src/tools/run-make-support/src/targets.rs @@ -0,0 +1,41 @@ +use std::panic; + +use crate::command::Command; +use crate::{env_var, handle_failed_output}; + +/// `TARGET` +#[must_use] +pub fn target() -> String { + env_var("TARGET") +} + +/// Check if target is windows-like. +#[must_use] +pub fn is_windows() -> bool { + target().contains("windows") +} + +/// Check if target uses msvc. +#[must_use] +pub fn is_msvc() -> bool { + target().contains("msvc") +} + +/// Check if target uses macOS. +#[must_use] +pub fn is_darwin() -> bool { + target().contains("darwin") +} + +/// Run `uname`. This assumes that `uname` is available on the platform! +#[track_caller] +#[must_use] +pub fn uname() -> String { + let caller = panic::Location::caller(); + let mut uname = Command::new("uname"); + let output = uname.run(); + if !output.status().success() { + handle_failed_output(&uname, output, caller.line()); + } + output.stdout_utf8() +} From a02008edac2b13e27822c916453fdb8356bebd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 09:45:59 +0000 Subject: [PATCH 03/27] run_make_support: move `env_var{,_os}` into `env_checked` module --- src/tools/run-make-support/src/env_checked.rs | 20 ++++++++++++ src/tools/run-make-support/src/lib.rs | 32 ++++--------------- 2 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 src/tools/run-make-support/src/env_checked.rs diff --git a/src/tools/run-make-support/src/env_checked.rs b/src/tools/run-make-support/src/env_checked.rs new file mode 100644 index 0000000000000..adde8b02ac23d --- /dev/null +++ b/src/tools/run-make-support/src/env_checked.rs @@ -0,0 +1,20 @@ +use std::ffi::OsString; +use std::env; + +#[track_caller] +#[must_use] +pub fn env_var(name: &str) -> String { + match env::var(name) { + Ok(v) => v, + Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"), + } +} + +#[track_caller] +#[must_use] +pub fn env_var_os(name: &str) -> OsString { + match env::var_os(name) { + Some(v) => v, + None => panic!("failed to retrieve environment variable {name:?}"), + } +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 1dbbad9132b73..6ef1b6b92ad85 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -7,6 +7,7 @@ pub mod cc; pub mod clang; mod command; pub mod diff; +pub mod env_checked; pub mod fs_wrapper; pub mod llvm; mod macros; @@ -15,8 +16,6 @@ pub mod rustc; pub mod rustdoc; pub mod targets; -use std::env; -use std::ffi::OsString; use std::fs; use std::io; use std::panic; @@ -31,6 +30,7 @@ pub use wasmparser; pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use diff::{diff, Diff}; +pub use env_checked::{env_var, env_var_os}; pub use llvm::{ llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck, LlvmObjdump, LlvmProfdata, LlvmReadobj, @@ -42,24 +42,6 @@ pub use targets::{is_darwin, is_msvc, is_windows, target, uname}; use command::{Command, CompletedProcess}; -#[track_caller] -#[must_use] -pub fn env_var(name: &str) -> String { - match env::var(name) { - Ok(v) => v, - Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"), - } -} - -#[track_caller] -#[must_use] -pub fn env_var_os(name: &str) -> OsString { - match env::var_os(name) { - Some(v) => v, - None => panic!("failed to retrieve environment variable {name:?}"), - } -} - /// `AR` #[track_caller] pub fn ar(inputs: &[impl AsRef], output_path: impl AsRef) { @@ -206,7 +188,7 @@ pub fn bin_name(name: &str) -> String { /// Return the current working directory. #[must_use] pub fn cwd() -> PathBuf { - env::current_dir().unwrap() + std::env::current_dir().unwrap() } // FIXME(Oneirical): This will no longer be required after compiletest receives the ability @@ -363,10 +345,10 @@ pub fn set_host_rpath(cmd: &mut Command) { let mut paths = vec![]; paths.push(cwd()); paths.push(PathBuf::from(env_var("HOST_RPATH_DIR"))); - for p in env::split_paths(&env_var(&ld_lib_path_envvar)) { + for p in std::env::split_paths(&env_var(&ld_lib_path_envvar)) { paths.push(p.to_path_buf()); } - env::join_paths(paths.iter()).unwrap() + std::env::join_paths(paths.iter()).unwrap() }); } @@ -518,8 +500,8 @@ pub fn run_in_tmpdir(callback: F) { let tmpdir = original_dir.join("../temporary-directory"); copy_dir_all(".", &tmpdir); - env::set_current_dir(&tmpdir).unwrap(); + std::env::set_current_dir(&tmpdir).unwrap(); callback(); - env::set_current_dir(original_dir).unwrap(); + std::env::set_current_dir(original_dir).unwrap(); fs::remove_dir_all(tmpdir).unwrap(); } From 288c572745c5cf0ff14e2645b571adb41540afe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 10:00:18 +0000 Subject: [PATCH 04/27] run_make_support: move external deps to `external_deps` module --- src/tools/run-make-support/src/env_checked.rs | 2 +- .../src/{ => external_deps}/cc.rs | 0 .../src/{ => external_deps}/clang.rs | 0 .../src/external_deps/htmldocck.rs | 14 ++++++++ .../src/{ => external_deps}/llvm.rs | 0 .../run-make-support/src/external_deps/mod.rs | 10 ++++++ .../src/external_deps/python.rs | 11 ++++++ .../src/{ => external_deps}/rustc.rs | 0 .../src/{ => external_deps}/rustdoc.rs | 0 src/tools/run-make-support/src/lib.rs | 36 +++++++------------ 10 files changed, 49 insertions(+), 24 deletions(-) rename src/tools/run-make-support/src/{ => external_deps}/cc.rs (100%) rename src/tools/run-make-support/src/{ => external_deps}/clang.rs (100%) create mode 100644 src/tools/run-make-support/src/external_deps/htmldocck.rs rename src/tools/run-make-support/src/{ => external_deps}/llvm.rs (100%) create mode 100644 src/tools/run-make-support/src/external_deps/mod.rs create mode 100644 src/tools/run-make-support/src/external_deps/python.rs rename src/tools/run-make-support/src/{ => external_deps}/rustc.rs (100%) rename src/tools/run-make-support/src/{ => external_deps}/rustdoc.rs (100%) diff --git a/src/tools/run-make-support/src/env_checked.rs b/src/tools/run-make-support/src/env_checked.rs index adde8b02ac23d..9f9d2445ef66d 100644 --- a/src/tools/run-make-support/src/env_checked.rs +++ b/src/tools/run-make-support/src/env_checked.rs @@ -1,5 +1,5 @@ -use std::ffi::OsString; use std::env; +use std::ffi::OsString; #[track_caller] #[must_use] diff --git a/src/tools/run-make-support/src/cc.rs b/src/tools/run-make-support/src/external_deps/cc.rs similarity index 100% rename from src/tools/run-make-support/src/cc.rs rename to src/tools/run-make-support/src/external_deps/cc.rs diff --git a/src/tools/run-make-support/src/clang.rs b/src/tools/run-make-support/src/external_deps/clang.rs similarity index 100% rename from src/tools/run-make-support/src/clang.rs rename to src/tools/run-make-support/src/external_deps/clang.rs diff --git a/src/tools/run-make-support/src/external_deps/htmldocck.rs b/src/tools/run-make-support/src/external_deps/htmldocck.rs new file mode 100644 index 0000000000000..afd0711ee0470 --- /dev/null +++ b/src/tools/run-make-support/src/external_deps/htmldocck.rs @@ -0,0 +1,14 @@ +use crate::command::Command; +use crate::source_root; + +use super::python::python_command; + +/// `htmldocck` is a python script which is used for rustdoc test suites, it is assumed to be +/// available at `$SOURCE_ROOT/src/etc/htmldocck.py`. +#[track_caller] +#[must_use] +pub fn htmldocck() -> Command { + let mut python = python_command(); + python.arg(source_root().join("src/etc/htmldocck.py")); + python +} diff --git a/src/tools/run-make-support/src/llvm.rs b/src/tools/run-make-support/src/external_deps/llvm.rs similarity index 100% rename from src/tools/run-make-support/src/llvm.rs rename to src/tools/run-make-support/src/external_deps/llvm.rs diff --git a/src/tools/run-make-support/src/external_deps/mod.rs b/src/tools/run-make-support/src/external_deps/mod.rs new file mode 100644 index 0000000000000..f4f03aa7efbde --- /dev/null +++ b/src/tools/run-make-support/src/external_deps/mod.rs @@ -0,0 +1,10 @@ +//! This module contains external tool dependencies that we assume are available in the environment, +//! such as `cc` or `python`. + +pub mod cc; +pub mod clang; +pub mod htmldocck; +pub mod llvm; +pub mod python; +pub mod rustc; +pub mod rustdoc; diff --git a/src/tools/run-make-support/src/external_deps/python.rs b/src/tools/run-make-support/src/external_deps/python.rs new file mode 100644 index 0000000000000..59e725fd73e91 --- /dev/null +++ b/src/tools/run-make-support/src/external_deps/python.rs @@ -0,0 +1,11 @@ +use crate::command::Command; +use crate::env_checked::env_var; + +/// Obtain path of python as provided by the `PYTHON` environment variable. It is up to the caller +/// to document and check if the python version is compatible with its intended usage. +#[track_caller] +#[must_use] +pub fn python_command() -> Command { + let python_path = env_var("PYTHON"); + Command::new(python_path) +} diff --git a/src/tools/run-make-support/src/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs similarity index 100% rename from src/tools/run-make-support/src/rustc.rs rename to src/tools/run-make-support/src/external_deps/rustc.rs diff --git a/src/tools/run-make-support/src/rustdoc.rs b/src/tools/run-make-support/src/external_deps/rustdoc.rs similarity index 100% rename from src/tools/run-make-support/src/rustdoc.rs rename to src/tools/run-make-support/src/external_deps/rustdoc.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 6ef1b6b92ad85..57c53a309e215 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -3,17 +3,13 @@ //! notably is built via cargo: this means that if your test wants some non-trivial utility, such //! as `object` or `wasmparser`, they can be re-exported and be made available through this library. -pub mod cc; -pub mod clang; mod command; pub mod diff; pub mod env_checked; +pub mod external_deps; pub mod fs_wrapper; -pub mod llvm; mod macros; pub mod run; -pub mod rustc; -pub mod rustdoc; pub mod targets; use std::fs; @@ -27,17 +23,26 @@ pub use object; pub use regex; pub use wasmparser; +// Re-exports of external dependencies. +pub use external_deps::{cc, clang, htmldocck, llvm, python, rustc, rustdoc}; + pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; -pub use diff::{diff, Diff}; -pub use env_checked::{env_var, env_var_os}; +pub use htmldocck::htmldocck; pub use llvm::{ llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck, LlvmObjdump, LlvmProfdata, LlvmReadobj, }; -pub use run::{cmd, run, run_fail, run_with_args}; +pub use python::python_command; pub use rustc::{aux_build, bare_rustc, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; + +pub use diff::{diff, Diff}; + +pub use env_checked::{env_var, env_var_os}; + +pub use run::{cmd, run, run_fail, run_with_args}; + pub use targets::{is_darwin, is_msvc, is_windows, target, uname}; use command::{Command, CompletedProcess}; @@ -55,21 +60,6 @@ pub fn ar(inputs: &[impl AsRef], output_path: impl AsRef) { } } -#[track_caller] -#[must_use] -pub fn python_command() -> Command { - let python_path = env_var("PYTHON"); - Command::new(python_path) -} - -#[track_caller] -#[must_use] -pub fn htmldocck() -> Command { - let mut python = python_command(); - python.arg(source_root().join("src/etc/htmldocck.py")); - python -} - /// Returns the path for a local test file. pub fn path>(p: P) -> PathBuf { cwd().join(p.as_ref()) From f042e72d1e8eb5e098a139b0ea80a6399cb7174e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 10:19:02 +0000 Subject: [PATCH 05/27] run_make_support: cleanup and document some lib.rs reexports --- src/tools/run-make-support/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 57c53a309e215..e7ac23f63104c 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -4,11 +4,12 @@ //! as `object` or `wasmparser`, they can be re-exported and be made available through this library. mod command; +mod macros; + pub mod diff; pub mod env_checked; pub mod external_deps; pub mod fs_wrapper; -mod macros; pub mod run; pub mod targets; @@ -17,6 +18,7 @@ use std::io; use std::panic; use std::path::{Path, PathBuf}; +// Re-exports of third-party library crates. pub use bstr; pub use gimli; pub use object; @@ -26,6 +28,7 @@ pub use wasmparser; // Re-exports of external dependencies. pub use external_deps::{cc, clang, htmldocck, llvm, python, rustc, rustdoc}; +// These rely on external dependencies. pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use htmldocck::htmldocck; @@ -37,12 +40,18 @@ pub use python::python_command; pub use rustc::{aux_build, bare_rustc, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; +/// [`diff`] is implemented in terms of the [similar] library. +/// +/// [similar]: https://github.com/mitsuhiko/similar pub use diff::{diff, Diff}; +/// Panic-on-fail [`std::env::var`] and [`std::env::var_os`] wrappers. pub use env_checked::{env_var, env_var_os}; +/// Convenience helpers for running binaries and other commands. pub use run::{cmd, run, run_fail, run_with_args}; +/// Helpers for checking target information. pub use targets::{is_darwin, is_msvc, is_windows, target, uname}; use command::{Command, CompletedProcess}; From 439c6f60c76e64f50b176a0153f81d83be56b5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 10:30:21 +0000 Subject: [PATCH 06/27] run_make_support: move `ar` into own module --- src/tools/run-make-support/src/ar.rs | 22 ++++++++++++++++++++++ src/tools/run-make-support/src/lib.rs | 22 ++++++++-------------- 2 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 src/tools/run-make-support/src/ar.rs diff --git a/src/tools/run-make-support/src/ar.rs b/src/tools/run-make-support/src/ar.rs new file mode 100644 index 0000000000000..6f46a1dad34c3 --- /dev/null +++ b/src/tools/run-make-support/src/ar.rs @@ -0,0 +1,22 @@ +use std::fs; +use std::path::Path; + +/// Archive utility. +/// +/// # Notes +/// +/// This *currently* uses the [ar][rust-ar] crate, but this is subject to changes. We may need to +/// use `llvm-ar`, and if that is the case, this should be moved under `external_deps`. +/// +/// [rust-ar]: https://github.com/mdsteele/rust-ar +#[track_caller] +pub fn ar(inputs: &[impl AsRef], output_path: impl AsRef) { + let output = fs::File::create(&output_path).expect(&format!( + "the file in path `{}` could not be created", + output_path.as_ref().display() + )); + let mut builder = ar::Builder::new(output); + for input in inputs { + builder.append_path(input).unwrap(); + } +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index e7ac23f63104c..cb9d5ff90a78a 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -6,6 +6,7 @@ mod command; mod macros; +pub mod ar; pub mod diff; pub mod env_checked; pub mod external_deps; @@ -40,7 +41,13 @@ pub use python::python_command; pub use rustc::{aux_build, bare_rustc, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; -/// [`diff`] is implemented in terms of the [similar] library. +/// [`ar`][mod@ar] currently uses the [ar][rust-ar] rust library, but that is subject to changes, we +/// may switch to `llvm-ar` subject to experimentation. +/// +/// [rust-ar]: https://github.com/mdsteele/rust-ar +pub use ar::ar; + +/// [`diff`][mod@diff] is implemented in terms of the [similar] library. /// /// [similar]: https://github.com/mitsuhiko/similar pub use diff::{diff, Diff}; @@ -56,19 +63,6 @@ pub use targets::{is_darwin, is_msvc, is_windows, target, uname}; use command::{Command, CompletedProcess}; -/// `AR` -#[track_caller] -pub fn ar(inputs: &[impl AsRef], output_path: impl AsRef) { - let output = fs::File::create(&output_path).expect(&format!( - "the file in path \"{}\" could not be created", - output_path.as_ref().display() - )); - let mut builder = ar::Builder::new(output); - for input in inputs { - builder.append_path(input).unwrap(); - } -} - /// Returns the path for a local test file. pub fn path>(p: P) -> PathBuf { cwd().join(p.as_ref()) From 483328d40163784f1114d78f0c326403f246e03f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 10:39:00 +0000 Subject: [PATCH 07/27] run_make_support: move artifact name helpers into `artifact_names` module --- .../run-make-support/src/artifact_names.rs | 81 ++++++++++++++++++ src/tools/run-make-support/src/lib.rs | 82 ++----------------- 2 files changed, 87 insertions(+), 76 deletions(-) create mode 100644 src/tools/run-make-support/src/artifact_names.rs diff --git a/src/tools/run-make-support/src/artifact_names.rs b/src/tools/run-make-support/src/artifact_names.rs new file mode 100644 index 0000000000000..a2c58f4e4b677 --- /dev/null +++ b/src/tools/run-make-support/src/artifact_names.rs @@ -0,0 +1,81 @@ +//! A collection of helpers to construct artifact names, such as names of dynamic or static +//! librarys which are target-dependent. + +use crate::targets::{is_darwin, is_msvc, is_windows}; + +/// Construct the static library name based on the target. +#[must_use] +pub fn static_lib_name(name: &str) -> String { + // See tools.mk (irrelevant lines omitted): + // + // ```makefile + // ifeq ($(UNAME),Darwin) + // STATICLIB = $(TMPDIR)/lib$(1).a + // else + // ifdef IS_WINDOWS + // ifdef IS_MSVC + // STATICLIB = $(TMPDIR)/$(1).lib + // else + // STATICLIB = $(TMPDIR)/lib$(1).a + // endif + // else + // STATICLIB = $(TMPDIR)/lib$(1).a + // endif + // endif + // ``` + assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace"); + + if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") } +} + +/// Construct the dynamic library name based on the target. +#[must_use] +pub fn dynamic_lib_name(name: &str) -> String { + // See tools.mk (irrelevant lines omitted): + // + // ```makefile + // ifeq ($(UNAME),Darwin) + // DYLIB = $(TMPDIR)/lib$(1).dylib + // else + // ifdef IS_WINDOWS + // DYLIB = $(TMPDIR)/$(1).dll + // else + // DYLIB = $(TMPDIR)/lib$(1).so + // endif + // endif + // ``` + assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace"); + + let extension = dynamic_lib_extension(); + if is_darwin() { + format!("lib{name}.{extension}") + } else if is_windows() { + format!("{name}.{extension}") + } else { + format!("lib{name}.{extension}") + } +} + +/// Construct the dynamic library extension based on the target. +#[must_use] +pub fn dynamic_lib_extension() -> &'static str { + if is_darwin() { + "dylib" + } else if is_windows() { + "dll" + } else { + "so" + } +} + +/// Construct the name of a rust library (rlib). +#[must_use] +pub fn rust_lib_name(name: &str) -> String { + format!("lib{name}.rlib") +} + +/// Construct the binary (executable) name based on the target. +#[must_use] +pub fn bin_name(name: &str) -> String { + if is_windows() { format!("{name}.exe") } else { name.to_string() } +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index cb9d5ff90a78a..5ca15b8853072 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -7,6 +7,7 @@ mod command; mod macros; pub mod ar; +pub mod artifact_names; pub mod diff; pub mod env_checked; pub mod external_deps; @@ -61,6 +62,11 @@ pub use run::{cmd, run, run_fail, run_with_args}; /// Helpers for checking target information. pub use targets::{is_darwin, is_msvc, is_windows, target, uname}; +/// Helpers for building names of output artifacts that are potentially target-specific. +pub use artifact_names::{ + bin_name, dynamic_lib_extension, dynamic_lib_name, rust_lib_name, static_lib_name, +}; + use command::{Command, CompletedProcess}; /// Returns the path for a local test file. @@ -102,82 +108,6 @@ pub fn create_symlink, Q: AsRef>(original: P, link: Q) { )); } -/// Construct the static library name based on the platform. -#[must_use] -pub fn static_lib_name(name: &str) -> String { - // See tools.mk (irrelevant lines omitted): - // - // ```makefile - // ifeq ($(UNAME),Darwin) - // STATICLIB = $(TMPDIR)/lib$(1).a - // else - // ifdef IS_WINDOWS - // ifdef IS_MSVC - // STATICLIB = $(TMPDIR)/$(1).lib - // else - // STATICLIB = $(TMPDIR)/lib$(1).a - // endif - // else - // STATICLIB = $(TMPDIR)/lib$(1).a - // endif - // endif - // ``` - assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace"); - - if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") } -} - -/// Construct the dynamic library name based on the platform. -#[must_use] -pub fn dynamic_lib_name(name: &str) -> String { - // See tools.mk (irrelevant lines omitted): - // - // ```makefile - // ifeq ($(UNAME),Darwin) - // DYLIB = $(TMPDIR)/lib$(1).dylib - // else - // ifdef IS_WINDOWS - // DYLIB = $(TMPDIR)/$(1).dll - // else - // DYLIB = $(TMPDIR)/lib$(1).so - // endif - // endif - // ``` - assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace"); - - let extension = dynamic_lib_extension(); - if is_darwin() { - format!("lib{name}.{extension}") - } else if is_windows() { - format!("{name}.{extension}") - } else { - format!("lib{name}.{extension}") - } -} - -#[must_use] -pub fn dynamic_lib_extension() -> &'static str { - if is_darwin() { - "dylib" - } else if is_windows() { - "dll" - } else { - "so" - } -} - -/// Generate the name a rust library (rlib) would have. -#[must_use] -pub fn rust_lib_name(name: &str) -> String { - format!("lib{name}.rlib") -} - -/// Construct the binary name based on platform. -#[must_use] -pub fn bin_name(name: &str) -> String { - if is_windows() { format!("{name}.exe") } else { name.to_string() } -} - /// Return the current working directory. #[must_use] pub fn cwd() -> PathBuf { From dc9531533c50ade680b98b3ed7e4e1a2f408b474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 10:50:28 +0000 Subject: [PATCH 08/27] run_make_support: move path-related helpers into own module --- .../run-make-support/src/external_deps/mod.rs | 5 ++ src/tools/run-make-support/src/lib.rs | 38 ++--------- .../run-make-support/src/path_helpers.rs | 66 +++++++++++++++++++ 3 files changed, 75 insertions(+), 34 deletions(-) create mode 100644 src/tools/run-make-support/src/path_helpers.rs diff --git a/src/tools/run-make-support/src/external_deps/mod.rs b/src/tools/run-make-support/src/external_deps/mod.rs index f4f03aa7efbde..bcd7dce0f965c 100644 --- a/src/tools/run-make-support/src/external_deps/mod.rs +++ b/src/tools/run-make-support/src/external_deps/mod.rs @@ -1,5 +1,10 @@ //! This module contains external tool dependencies that we assume are available in the environment, //! such as `cc` or `python`. +//! +//! # Notes +//! +//! - This is not the *only* place where external dependencies are assumed or referenced. For +//! example, see [`cygpath_windows`][crate::path_helpers::cygpath_windows]. pub mod cc; pub mod clang; diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 5ca15b8853072..5ec466af6cefd 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -12,6 +12,7 @@ pub mod diff; pub mod env_checked; pub mod external_deps; pub mod fs_wrapper; +pub mod path_helpers; pub mod run; pub mod targets; @@ -67,18 +68,10 @@ pub use artifact_names::{ bin_name, dynamic_lib_extension, dynamic_lib_name, rust_lib_name, static_lib_name, }; -use command::{Command, CompletedProcess}; - -/// Returns the path for a local test file. -pub fn path>(p: P) -> PathBuf { - cwd().join(p.as_ref()) -} +/// Path-related helpers. +pub use path_helpers::{cwd, cygpath_windows, path, source_root}; -/// Path to the root rust-lang/rust source checkout. -#[must_use] -pub fn source_root() -> PathBuf { - env_var("SOURCE_ROOT").into() -} +use command::{Command, CompletedProcess}; /// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix. #[cfg(target_family = "windows")] @@ -108,12 +101,6 @@ pub fn create_symlink, Q: AsRef>(original: P, link: Q) { )); } -/// Return the current working directory. -#[must_use] -pub fn cwd() -> PathBuf { - std::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 @@ -227,23 +214,6 @@ pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) count } -/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is -/// available on the platform! -#[track_caller] -#[must_use] -pub fn cygpath_windows>(path: P) -> String { - let caller = panic::Location::caller(); - let mut cygpath = Command::new("cygpath"); - cygpath.arg("-w"); - cygpath.arg(path.as_ref()); - let output = cygpath.run(); - if !output.status().success() { - handle_failed_output(&cygpath, output, caller.line()); - } - // cygpath -w can attach a newline - output.stdout_utf8().trim().to_string() -} - pub(crate) fn handle_failed_output( cmd: &Command, output: CompletedProcess, diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs new file mode 100644 index 0000000000000..59e0cec0be483 --- /dev/null +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -0,0 +1,66 @@ +//! Collection of path-related helpers. + +use std::panic; +use std::path::{Path, PathBuf}; + +use crate::command::Command; +use crate::env_checked::env_var; +use crate::handle_failed_output; + +/// Return the current working directory. +/// +/// This forwards to [`std::env::current_dir`], please see its docs regarding platform-specific +/// behavior. +#[must_use] +pub fn cwd() -> PathBuf { + std::env::current_dir().unwrap() +} + +/// Construct a `PathBuf` relative to the current working directory by joining `cwd()` with the +/// relative path. This is mostly a convenience helper so the test writer does not need to write +/// `PathBuf::from(path_like_string)`. +/// +/// # Example +/// +/// ```rust +/// let p = path("support_file.txt"); +/// ``` +pub fn path>(p: P) -> PathBuf { + cwd().join(p.as_ref()) +} + +/// Path to the root `rust-lang/rust` source checkout. +#[must_use] +pub fn source_root() -> PathBuf { + env_var("SOURCE_ROOT").into() +} + +/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is +/// available on the platform! +/// +/// # FIXME +/// +/// FIXME(jieyouxu): we should consider not depending on `cygpath`. +/// +/// > The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style +/// > pathnames and vice versa. +/// > +/// > [irrelevant entries omitted...] +/// > +/// > `-w, --windows print Windows form of NAMEs (C:\WINNT)` +/// > +/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*. +#[track_caller] +#[must_use] +pub fn cygpath_windows>(path: P) -> String { + let caller = panic::Location::caller(); + let mut cygpath = Command::new("cygpath"); + cygpath.arg("-w"); + cygpath.arg(path.as_ref()); + let output = cygpath.run(); + if !output.status().success() { + handle_failed_output(&cygpath, output, caller.line()); + } + // cygpath -w can attach a newline + output.stdout_utf8().trim().to_string() +} From 17212abd1a75a83a5e7ccc4aebaf573bf5766c48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 11:30:59 +0000 Subject: [PATCH 09/27] run_make_support: move fs helpers to own module --- src/tools/run-make-support/src/fs_helpers.rs | 71 ++++++++++++++++++++ src/tools/run-make-support/src/lib.rs | 69 ++----------------- 2 files changed, 75 insertions(+), 65 deletions(-) create mode 100644 src/tools/run-make-support/src/fs_helpers.rs diff --git a/src/tools/run-make-support/src/fs_helpers.rs b/src/tools/run-make-support/src/fs_helpers.rs new file mode 100644 index 0000000000000..07e0900842aba --- /dev/null +++ b/src/tools/run-make-support/src/fs_helpers.rs @@ -0,0 +1,71 @@ +use std::io; +use std::path::Path; + +use crate::fs_wrapper; + +// FIXME(jieyouxu): modify create_symlink to panic on windows. + +/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix. +#[cfg(target_family = "windows")] +pub fn create_symlink, Q: AsRef>(original: P, link: Q) { + if link.as_ref().exists() { + std::fs::remove_dir(link.as_ref()).unwrap(); + } + 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, Q: AsRef>(original: P, link: Q) { + if link.as_ref().exists() { + std::fs::remove_dir(link.as_ref()).unwrap(); + } + 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(), + )); +} + +/// Copy a directory into another. +pub fn copy_dir_all(src: impl AsRef, dst: impl AsRef) { + fn copy_dir_all_inner(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { + let dst = dst.as_ref(); + if !dst.is_dir() { + std::fs::create_dir_all(&dst)?; + } + for entry in std::fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?; + } else { + std::fs::copy(entry.path(), dst.join(entry.file_name()))?; + } + } + Ok(()) + } + + if let Err(e) = copy_dir_all_inner(&src, &dst) { + // Trying to give more context about what exactly caused the failure + panic!( + "failed to copy `{}` to `{}`: {:?}", + src.as_ref().display(), + dst.as_ref().display(), + e + ); + } +} + +/// Helper for reading entries in a given directory. +pub fn read_dir, F: FnMut(&Path)>(dir: P, mut callback: F) { + for entry in fs_wrapper::read_dir(dir) { + callback(&entry.unwrap().path()); + } +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 5ec466af6cefd..33248527f0a42 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -11,13 +11,13 @@ pub mod artifact_names; pub mod diff; pub mod env_checked; pub mod external_deps; +pub mod fs_helpers; pub mod fs_wrapper; pub mod path_helpers; pub mod run; pub mod targets; use std::fs; -use std::io; use std::panic; use std::path::{Path, PathBuf}; @@ -71,35 +71,10 @@ pub use artifact_names::{ /// Path-related helpers. pub use path_helpers::{cwd, cygpath_windows, path, source_root}; -use command::{Command, CompletedProcess}; +/// Helpers for common fs operations. +pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; -/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix. -#[cfg(target_family = "windows")] -pub fn create_symlink, Q: AsRef>(original: P, link: Q) { - if link.as_ref().exists() { - std::fs::remove_dir(link.as_ref()).unwrap(); - } - 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, Q: AsRef>(original: P, link: Q) { - if link.as_ref().exists() { - std::fs::remove_dir(link.as_ref()).unwrap(); - } - 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(), - )); -} +use command::{Command, CompletedProcess}; // 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 @@ -275,36 +250,6 @@ pub fn invalid_utf8_not_contains, S: AsRef>(path: P, expecte } } -/// Copy a directory into another. -pub fn copy_dir_all(src: impl AsRef, dst: impl AsRef) { - fn copy_dir_all_inner(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { - let dst = dst.as_ref(); - if !dst.is_dir() { - std::fs::create_dir_all(&dst)?; - } - for entry in std::fs::read_dir(src)? { - let entry = entry?; - let ty = entry.file_type()?; - if ty.is_dir() { - copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?; - } else { - std::fs::copy(entry.path(), dst.join(entry.file_name()))?; - } - } - Ok(()) - } - - if let Err(e) = copy_dir_all_inner(&src, &dst) { - // Trying to give more context about what exactly caused the failure - panic!( - "failed to copy `{}` to `{}`: {:?}", - src.as_ref().display(), - dst.as_ref().display(), - e - ); - } -} - /// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise. pub fn recursive_diff(dir1: impl AsRef, dir2: impl AsRef) { let dir2 = dir2.as_ref(); @@ -330,12 +275,6 @@ pub fn recursive_diff(dir1: impl AsRef, dir2: impl AsRef) { }); } -pub fn read_dir(dir: impl AsRef, mut callback: F) { - for entry in fs_wrapper::read_dir(dir) { - callback(&entry.unwrap().path()); - } -} - /// Check that `actual` is equal to `expected`. Panic otherwise. #[track_caller] pub fn assert_equals, S2: AsRef>(actual: S1, expected: S2) { From 66cef19d11553dcc48848200afbdf113021af76c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 11:38:47 +0000 Subject: [PATCH 10/27] run_make_support: move `run_in_tmpdir` and `test_while_readonly` to `scoped_run` module --- src/tools/run-make-support/src/lib.rs | 58 ++-------------- src/tools/run-make-support/src/scoped_run.rs | 71 ++++++++++++++++++++ 2 files changed, 75 insertions(+), 54 deletions(-) create mode 100644 src/tools/run-make-support/src/scoped_run.rs diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 33248527f0a42..0f8fc6af0b3c6 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -15,9 +15,9 @@ pub mod fs_helpers; pub mod fs_wrapper; pub mod path_helpers; pub mod run; +pub mod scoped_run; pub mod targets; -use std::fs; use std::panic; use std::path::{Path, PathBuf}; @@ -74,39 +74,10 @@ pub use path_helpers::{cwd, cygpath_windows, path, source_root}; /// Helpers for common fs operations. pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; -use command::{Command, CompletedProcess}; - -// 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, 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); +/// Helpers for scoped test execution where certain properties are attempted to be maintained. +pub use scoped_run::{run_in_tmpdir, test_while_readonly}; - let success = std::panic::catch_unwind(closure); - - fs_wrapper::set_permissions(&path, original_perms); - success.unwrap(); -} +use command::{Command, CompletedProcess}; /// Browse the directory `path` non-recursively and return all files which respect the parameters /// outlined by `closure`. @@ -316,24 +287,3 @@ pub fn assert_not_contains, S2: AsRef>(haystack: S1, needle: panic!("needle was unexpectedly found in haystack"); } } - -/// This function is designed for running commands in a temporary directory -/// that is cleared after the function ends. -/// -/// What this function does: -/// 1) Creates a temporary directory (`tmpdir`) -/// 2) Copies all files from the current directory to `tmpdir` -/// 3) Changes the current working directory to `tmpdir` -/// 4) Calls `callback` -/// 5) Switches working directory back to the original one -/// 6) Removes `tmpdir` -pub fn run_in_tmpdir(callback: F) { - let original_dir = cwd(); - let tmpdir = original_dir.join("../temporary-directory"); - copy_dir_all(".", &tmpdir); - - std::env::set_current_dir(&tmpdir).unwrap(); - callback(); - std::env::set_current_dir(original_dir).unwrap(); - fs::remove_dir_all(tmpdir).unwrap(); -} diff --git a/src/tools/run-make-support/src/scoped_run.rs b/src/tools/run-make-support/src/scoped_run.rs new file mode 100644 index 0000000000000..ab8d2429b6ae6 --- /dev/null +++ b/src/tools/run-make-support/src/scoped_run.rs @@ -0,0 +1,71 @@ +//! Collection of helpers that try to maintain certain properties while running a test closure. + +use std::fs; +use std::path::Path; + +use crate::fs_helpers::copy_dir_all; +use crate::fs_wrapper; +use crate::path_helpers::cwd; +use crate::targets::is_windows; + +/// 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) +/// +/// # Pitfalls +/// +/// - Some CI runners are ran as root which may bypass read-only permission restrictions. Unclear +/// exactly when such scenarios occur. +/// +/// # FIXME +/// +/// FIXME(Oneirical): This will no longer be required after compiletest receives the ability to +/// manipulate read-only files. See . +#[track_caller] +pub fn test_while_readonly(path: P, closure: F) +where + P: AsRef, + F: FnOnce() + std::panic::UnwindSafe, +{ + 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(); +} + +/// This function is designed for running commands in a temporary directory that is cleared after +/// the function ends. +/// +/// What this function does: +/// 1. Creates a temporary directory (`tmpdir`) +/// 2. Copies all files from the current directory to `tmpdir` +/// 3. Changes the current working directory to `tmpdir` +/// 4. Calls `callback` +/// 5. Switches working directory back to the original one +/// 6. Removes `tmpdir` +pub fn run_in_tmpdir(callback: F) { + let original_dir = cwd(); + let tmpdir = original_dir.join("../temporary-directory"); + copy_dir_all(".", &tmpdir); + + std::env::set_current_dir(&tmpdir).unwrap(); + callback(); + std::env::set_current_dir(original_dir).unwrap(); + fs::remove_dir_all(tmpdir).unwrap(); +} From f66d3d33e4a6481123ed03d9100d1330c1828521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 11:47:53 +0000 Subject: [PATCH 11/27] run_make_support: move assertions and helpers into own module --- .../run-make-support/src/assertion_helpers.rs | 142 ++++++++++++++++++ src/tools/run-make-support/src/lib.rs | 142 +----------------- 2 files changed, 150 insertions(+), 134 deletions(-) create mode 100644 src/tools/run-make-support/src/assertion_helpers.rs diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs new file mode 100644 index 0000000000000..96f6296b304ca --- /dev/null +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -0,0 +1,142 @@ +//! Collection of assertions and assertion-related helpers. + +use std::path::{Path, PathBuf}; +use std::panic; + +use crate::fs_wrapper; +use crate::path_helpers::cwd; + +/// Browse the directory `path` non-recursively and return all files which respect the parameters +/// outlined by `closure`. +#[track_caller] +pub fn shallow_find_files, F: Fn(&PathBuf) -> bool>( + path: P, + filter: F, +) -> Vec { + let mut matching_files = Vec::new(); + for entry in fs_wrapper::read_dir(path) { + let entry = entry.expect("failed to read directory entry."); + let path = entry.path(); + + if path.is_file() && filter(&path) { + matching_files.push(path); + } + } + matching_files +} + +/// Returns true if the filename at `path` starts with `prefix`. +pub fn has_prefix>(path: P, prefix: &str) -> bool { + path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix)) +} + +/// Returns true if the filename at `path` has the extension `extension`. +pub fn has_extension>(path: P, extension: &str) -> bool { + path.as_ref().extension().is_some_and(|ext| ext == extension) +} + +/// Returns true if the filename at `path` does not contain `expected`. +pub fn not_contains>(path: P, expected: &str) -> bool { + !path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected)) +} + +/// Returns true if the filename at `path` is not in `expected`. +pub fn filename_not_in_denylist, V: AsRef<[String]>>(path: P, expected: V) -> bool { + let expected = expected.as_ref(); + path.as_ref() + .file_name() + .is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned())) +} + +/// Returns true if the filename at `path` ends with `suffix`. +pub fn has_suffix>(path: P, suffix: &str) -> bool { + path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix)) +} + +/// Gathers all files in the current working directory that have the extension `ext`, and counts +/// the number of lines within that contain a match with the regex pattern `re`. +pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) -> usize { + let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext)); + + let mut count = 0; + for file in fetched_files { + let content = fs_wrapper::read_to_string(file); + count += content.lines().filter(|line| re.is_match(&line)).count(); + } + + count +} + +/// Read the contents of a file that cannot simply be read by +/// [`read_to_string`][crate::fs_wrapper::read_to_string], due to invalid UTF-8 data, then assert +/// that it contains `expected`. +#[track_caller] +pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S) { + let buffer = fs_wrapper::read(path.as_ref()); + let expected = expected.as_ref(); + if !String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } +} + +/// Read the contents of a file that cannot simply be read by +/// [`read_to_string`][crate::fs_wrapper::read_to_string], due to invalid UTF-8 data, then assert +/// that it does not contain `expected`. +#[track_caller] +pub fn invalid_utf8_not_contains, S: AsRef>(path: P, expected: S) { + let buffer = fs_wrapper::read(path.as_ref()); + let expected = expected.as_ref(); + if String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was unexpectedly found in file"); + } +} + +/// Assert that `actual` is equal to `expected`. +#[track_caller] +pub fn assert_equals, E: AsRef>(actual: A, expected: E) { + let actual = actual.as_ref(); + let expected = expected.as_ref(); + if actual != expected { + eprintln!("=== ACTUAL TEXT ==="); + eprintln!("{}", actual); + eprintln!("=== EXPECTED ==="); + eprintln!("{}", expected); + panic!("expected text was not found in actual text"); + } +} + +/// Assert that `haystack` contains `needle`. +#[track_caller] +pub fn assert_contains, N: AsRef>(haystack: H, needle: N) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); + if !haystack.contains(needle) { + eprintln!("=== HAYSTACK ==="); + eprintln!("{}", haystack); + eprintln!("=== NEEDLE ==="); + eprintln!("{}", needle); + panic!("needle was not found in haystack"); + } +} + +/// Assert that `haystack` does not contain `needle`. +#[track_caller] +pub fn assert_not_contains, N: AsRef>(haystack: H, needle: N) { + let haystack = haystack.as_ref(); + let needle = needle.as_ref(); + if haystack.contains(needle) { + eprintln!("=== HAYSTACK ==="); + eprintln!("{}", haystack); + eprintln!("=== NEEDLE ==="); + eprintln!("{}", needle); + panic!("needle was unexpectedly found in haystack"); + } +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 0f8fc6af0b3c6..60b775082891f 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -8,6 +8,7 @@ mod macros; pub mod ar; pub mod artifact_names; +pub mod assertion_helpers; pub mod diff; pub mod env_checked; pub mod external_deps; @@ -18,7 +19,6 @@ pub mod run; pub mod scoped_run; pub mod targets; -use std::panic; use std::path::{Path, PathBuf}; // Re-exports of third-party library crates. @@ -77,41 +77,14 @@ pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; /// Helpers for scoped test execution where certain properties are attempted to be maintained. pub use scoped_run::{run_in_tmpdir, test_while_readonly}; -use command::{Command, CompletedProcess}; - -/// Browse the directory `path` non-recursively and return all files which respect the parameters -/// outlined by `closure`. -#[track_caller] -pub fn shallow_find_files, F: Fn(&PathBuf) -> bool>( - path: P, - filter: F, -) -> Vec { - let mut matching_files = Vec::new(); - for entry in fs_wrapper::read_dir(path) { - let entry = entry.expect("failed to read directory entry."); - let path = entry.path(); - - if path.is_file() && filter(&path) { - matching_files.push(path); - } - } - matching_files -} - -/// Returns true if the filename at `path` starts with `prefix`. -pub fn has_prefix>(path: P, prefix: &str) -> bool { - path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix)) -} - -/// Returns true if the filename at `path` has the extension `extension`. -pub fn has_extension>(path: P, extension: &str) -> bool { - path.as_ref().extension().is_some_and(|ext| ext == extension) -} +pub use assertion_helpers::{ + assert_contains, assert_equals, assert_not_contains, + count_regex_matches_in_files_with_extension, filename_not_in_denylist, has_extension, + has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains, + shallow_find_files, +}; -/// Returns true if the filename at `path` does not contain `expected`. -pub fn not_contains>(path: P, expected: &str) -> bool { - !path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected)) -} +use command::{Command, CompletedProcess}; /// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name. #[track_caller] @@ -133,33 +106,6 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf { path(lib_path) } -/// Returns true if the filename at `path` is not in `expected`. -pub fn filename_not_in_denylist, V: AsRef<[String]>>(path: P, expected: V) -> bool { - let expected = expected.as_ref(); - path.as_ref() - .file_name() - .is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned())) -} - -/// Returns true if the filename at `path` ends with `suffix`. -pub fn has_suffix>(path: P, suffix: &str) -> bool { - path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix)) -} - -/// Gathers all files in the current working directory that have the extension `ext`, and counts -/// the number of lines within that contain a match with the regex pattern `re`. -pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) -> usize { - let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext)); - - let mut count = 0; - for file in fetched_files { - let content = fs_wrapper::read_to_string(file); - count += content.lines().filter(|line| re.is_match(&line)).count(); - } - - count -} - pub(crate) fn handle_failed_output( cmd: &Command, output: CompletedProcess, @@ -191,36 +137,6 @@ pub fn set_host_rpath(cmd: &mut Command) { }); } -/// Read the contents of a file that cannot simply be read by -/// read_to_string, due to invalid utf8 data, then assert that it contains `expected`. -#[track_caller] -pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S) { - let buffer = fs_wrapper::read(path.as_ref()); - let expected = expected.as_ref(); - if !String::from_utf8_lossy(&buffer).contains(expected) { - eprintln!("=== FILE CONTENTS (LOSSY) ==="); - eprintln!("{}", String::from_utf8_lossy(&buffer)); - eprintln!("=== SPECIFIED TEXT ==="); - eprintln!("{}", expected); - panic!("specified text was not found in file"); - } -} - -/// Read the contents of a file that cannot simply be read by -/// read_to_string, due to invalid utf8 data, then assert that it does not contain `expected`. -#[track_caller] -pub fn invalid_utf8_not_contains, S: AsRef>(path: P, expected: S) { - let buffer = fs_wrapper::read(path.as_ref()); - let expected = expected.as_ref(); - if String::from_utf8_lossy(&buffer).contains(expected) { - eprintln!("=== FILE CONTENTS (LOSSY) ==="); - eprintln!("{}", String::from_utf8_lossy(&buffer)); - eprintln!("=== SPECIFIED TEXT ==="); - eprintln!("{}", expected); - panic!("specified text was unexpectedly found in file"); - } -} - /// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise. pub fn recursive_diff(dir1: impl AsRef, dir2: impl AsRef) { let dir2 = dir2.as_ref(); @@ -245,45 +161,3 @@ pub fn recursive_diff(dir1: impl AsRef, dir2: impl AsRef) { } }); } - -/// Check that `actual` is equal to `expected`. Panic otherwise. -#[track_caller] -pub fn assert_equals, S2: AsRef>(actual: S1, expected: S2) { - let actual = actual.as_ref(); - let expected = expected.as_ref(); - if actual != expected { - eprintln!("=== ACTUAL TEXT ==="); - eprintln!("{}", actual); - eprintln!("=== EXPECTED ==="); - eprintln!("{}", expected); - panic!("expected text was not found in actual text"); - } -} - -/// Check that `haystack` contains `needle`. Panic otherwise. -#[track_caller] -pub fn assert_contains, S2: AsRef>(haystack: S1, needle: S2) { - let haystack = haystack.as_ref(); - let needle = needle.as_ref(); - if !haystack.contains(needle) { - eprintln!("=== HAYSTACK ==="); - eprintln!("{}", haystack); - eprintln!("=== NEEDLE ==="); - eprintln!("{}", needle); - panic!("needle was not found in haystack"); - } -} - -/// Check that `haystack` does not contain `needle`. Panic otherwise. -#[track_caller] -pub fn assert_not_contains, S2: AsRef>(haystack: S1, needle: S2) { - let haystack = haystack.as_ref(); - let needle = needle.as_ref(); - if haystack.contains(needle) { - eprintln!("=== HAYSTACK ==="); - eprintln!("{}", haystack); - eprintln!("=== NEEDLE ==="); - eprintln!("{}", needle); - panic!("needle was unexpectedly found in haystack"); - } -} From 230804dc3a92c640935f34f16325b0c0e93b9ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 11:55:57 +0000 Subject: [PATCH 12/27] run_make_support: rename `recursive_diff` to `assert_recursive_eq` --- src/tools/run-make-support/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 60b775082891f..1a2a648c47ada 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -137,13 +137,13 @@ pub fn set_host_rpath(cmd: &mut Command) { }); } -/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise. -pub fn recursive_diff(dir1: impl AsRef, dir2: impl AsRef) { +/// Assert that all files in `dir1` exist and have the same content in `dir2` +pub fn assert_recursive_eq(dir1: impl AsRef, dir2: impl AsRef) { let dir2 = dir2.as_ref(); read_dir(dir1, |entry_path| { let entry_name = entry_path.file_name().unwrap(); if entry_path.is_dir() { - recursive_diff(&entry_path, &dir2.join(entry_name)); + assert_recursive_eq(&entry_path, &dir2.join(entry_name)); } else { let path2 = dir2.join(entry_name); let file1 = fs_wrapper::read(&entry_path); From 56cbfa8749d18fedc0133b2f501b8d5678e89ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 12:15:36 +0000 Subject: [PATCH 13/27] tests: update rustdoc test for renamed `assert_recursive_eq` --- tests/run-make/rustdoc-verify-output-files/rmake.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-make/rustdoc-verify-output-files/rmake.rs b/tests/run-make/rustdoc-verify-output-files/rmake.rs index 1bf41c68114cb..61dd97e09a916 100644 --- a/tests/run-make/rustdoc-verify-output-files/rmake.rs +++ b/tests/run-make/rustdoc-verify-output-files/rmake.rs @@ -1,7 +1,7 @@ use run_make_support::fs_wrapper::copy; use std::path::{Path, PathBuf}; -use run_make_support::{copy_dir_all, recursive_diff, rustdoc}; +use run_make_support::{assert_recursive_eq, copy_dir_all, rustdoc}; #[derive(PartialEq)] enum JsonOutput { @@ -45,5 +45,5 @@ fn main() { // Check if all docs(including both json and html formats) are still the same after multiple // compilations. - recursive_diff(&out_dir, &tmp_out_dir); + assert_recursive_eq(&out_dir, &tmp_out_dir); } From 88fd1df017d7652ffd82ad11cb9f63d8a660f95f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 11:59:06 +0000 Subject: [PATCH 14/27] run_make_support: move `assert_recursive_eq` into `assertion_helpers` --- .../run-make-support/src/assertion_helpers.rs | 28 ++++++++++++++++++- src/tools/run-make-support/src/lib.rs | 27 +----------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs index 96f6296b304ca..3fdcc94a034f1 100644 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -1,8 +1,9 @@ //! Collection of assertions and assertion-related helpers. -use std::path::{Path, PathBuf}; use std::panic; +use std::path::{Path, PathBuf}; +use crate::fs_helpers; use crate::fs_wrapper; use crate::path_helpers::cwd; @@ -140,3 +141,28 @@ pub fn assert_not_contains, N: AsRef>(haystack: H, needle: N) panic!("needle was unexpectedly found in haystack"); } } + +/// Assert that all files in `dir1` exist and have the same content in `dir2` +pub fn assert_recursive_eq(dir1: impl AsRef, dir2: impl AsRef) { + let dir2 = dir2.as_ref(); + fs_helpers::read_dir(dir1, |entry_path| { + let entry_name = entry_path.file_name().unwrap(); + if entry_path.is_dir() { + assert_recursive_eq(&entry_path, &dir2.join(entry_name)); + } else { + let path2 = dir2.join(entry_name); + let file1 = fs_wrapper::read(&entry_path); + let file2 = fs_wrapper::read(&path2); + + // We don't use `assert_eq!` because they are `Vec`, so not great for display. + // Why not using String? Because there might be minified files or even potentially + // binary ones, so that would display useless output. + assert!( + file1 == file2, + "`{}` and `{}` have different content", + entry_path.display(), + path2.display(), + ); + } + }); +} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 1a2a648c47ada..658b6cc3559b1 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -78,7 +78,7 @@ pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; pub use scoped_run::{run_in_tmpdir, test_while_readonly}; pub use assertion_helpers::{ - assert_contains, assert_equals, assert_not_contains, + assert_contains, assert_equals, assert_not_contains, assert_recursive_eq, count_regex_matches_in_files_with_extension, filename_not_in_denylist, has_extension, has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains, shallow_find_files, @@ -136,28 +136,3 @@ pub fn set_host_rpath(cmd: &mut Command) { std::env::join_paths(paths.iter()).unwrap() }); } - -/// Assert that all files in `dir1` exist and have the same content in `dir2` -pub fn assert_recursive_eq(dir1: impl AsRef, dir2: impl AsRef) { - let dir2 = dir2.as_ref(); - read_dir(dir1, |entry_path| { - let entry_name = entry_path.file_name().unwrap(); - if entry_path.is_dir() { - assert_recursive_eq(&entry_path, &dir2.join(entry_name)); - } else { - let path2 = dir2.join(entry_name); - let file1 = fs_wrapper::read(&entry_path); - let file2 = fs_wrapper::read(&path2); - - // We don't use `assert_eq!` because they are `Vec`, so not great for display. - // Why not using String? Because there might be minified files or even potentially - // binary ones, so that would display useless output. - assert!( - file1 == file2, - "`{}` and `{}` have different content", - entry_path.display(), - path2.display(), - ); - } - }); -} From e956808c6c5117b85ebc0eb6b3d92f6e512a593c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 12:07:36 +0000 Subject: [PATCH 15/27] run_make_support: move `handle_failed_output` into `util` module --- src/tools/run-make-support/src/command.rs | 4 +++- src/tools/run-make-support/src/lib.rs | 22 +++---------------- .../run-make-support/src/path_helpers.rs | 2 +- src/tools/run-make-support/src/run.rs | 3 +-- src/tools/run-make-support/src/targets.rs | 3 ++- src/tools/run-make-support/src/util.rs | 21 ++++++++++++++++++ 6 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 src/tools/run-make-support/src/util.rs diff --git a/src/tools/run-make-support/src/command.rs b/src/tools/run-make-support/src/command.rs index 5017a4b88dad3..47376c401bb67 100644 --- a/src/tools/run-make-support/src/command.rs +++ b/src/tools/run-make-support/src/command.rs @@ -5,7 +5,9 @@ use std::panic; use std::path::Path; use std::process::{Command as StdCommand, ExitStatus, Output, Stdio}; -use crate::{assert_contains, assert_equals, assert_not_contains, handle_failed_output}; +use crate::util::handle_failed_output; +use crate::{assert_contains, assert_equals, assert_not_contains}; + use build_helper::drop_bomb::DropBomb; /// This is a custom command wrapper that simplifies working with commands and makes it easier to diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 658b6cc3559b1..7c7b890f6ed5b 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -5,6 +5,7 @@ mod command; mod macros; +mod util; pub mod ar; pub mod artifact_names; @@ -19,7 +20,7 @@ pub mod run; pub mod scoped_run; pub mod targets; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; // Re-exports of third-party library crates. pub use bstr; @@ -84,7 +85,7 @@ pub use assertion_helpers::{ shallow_find_files, }; -use command::{Command, CompletedProcess}; +use command::Command; /// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name. #[track_caller] @@ -106,23 +107,6 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf { path(lib_path) } -pub(crate) fn handle_failed_output( - cmd: &Command, - output: CompletedProcess, - caller_line_number: u32, -) -> ! { - if output.status().success() { - eprintln!("command unexpectedly succeeded at line {caller_line_number}"); - } else { - eprintln!("command failed at line {caller_line_number}"); - } - eprintln!("{cmd:?}"); - eprintln!("output status: `{}`", output.status()); - eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8()); - eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8()); - std::process::exit(1) -} - /// Set the runtime library path as needed for running the host rustc/rustdoc/etc. pub fn set_host_rpath(cmd: &mut Command) { let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR"); diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs index 59e0cec0be483..a35c32cbe48b1 100644 --- a/src/tools/run-make-support/src/path_helpers.rs +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use crate::command::Command; use crate::env_checked::env_var; -use crate::handle_failed_output; +use crate::util::handle_failed_output; /// Return the current working directory. /// diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs index 54730bb7de736..d47e009fe9f95 100644 --- a/src/tools/run-make-support/src/run.rs +++ b/src/tools/run-make-support/src/run.rs @@ -4,10 +4,9 @@ use std::panic; use std::path::{Path, PathBuf}; use crate::command::{Command, CompletedProcess}; +use crate::util::handle_failed_output; use crate::{cwd, env_var, is_windows, set_host_rpath}; -use super::handle_failed_output; - #[track_caller] fn run_common(name: &str, args: Option<&[&str]>) -> Command { let mut bin_path = PathBuf::new(); diff --git a/src/tools/run-make-support/src/targets.rs b/src/tools/run-make-support/src/targets.rs index 68b66e68448c8..42d4a45680d16 100644 --- a/src/tools/run-make-support/src/targets.rs +++ b/src/tools/run-make-support/src/targets.rs @@ -1,7 +1,8 @@ use std::panic; use crate::command::Command; -use crate::{env_var, handle_failed_output}; +use crate::env_var; +use crate::util::handle_failed_output; /// `TARGET` #[must_use] diff --git a/src/tools/run-make-support/src/util.rs b/src/tools/run-make-support/src/util.rs new file mode 100644 index 0000000000000..41fdaf55aad5e --- /dev/null +++ b/src/tools/run-make-support/src/util.rs @@ -0,0 +1,21 @@ +use crate::command::{Command, CompletedProcess}; + +/// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the +/// executed command, failure location, output status and stdout/stderr, and abort the process with +/// exit code `1`. +pub(crate) fn handle_failed_output( + cmd: &Command, + output: CompletedProcess, + caller_line_number: u32, +) -> ! { + if output.status().success() { + eprintln!("command unexpectedly succeeded at line {caller_line_number}"); + } else { + eprintln!("command failed at line {caller_line_number}"); + } + eprintln!("{cmd:?}"); + eprintln!("output status: `{}`", output.status()); + eprintln!("=== STDOUT ===\n{}\n\n", output.stdout_utf8()); + eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8()); + std::process::exit(1) +} From aadd08576d6b407f76e7ac5a08fa6e3fa633e35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Mon, 15 Jul 2024 12:14:19 +0000 Subject: [PATCH 16/27] run_make_support: make `set_host_rpath` private and move into `util` --- .../run-make-support/src/external_deps/llvm.rs | 3 ++- .../src/external_deps/rustc.rs | 6 ++++-- .../src/external_deps/rustdoc.rs | 3 ++- src/tools/run-make-support/src/lib.rs | 18 ------------------ src/tools/run-make-support/src/run.rs | 4 ++-- src/tools/run-make-support/src/util.rs | 18 ++++++++++++++++++ 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/tools/run-make-support/src/external_deps/llvm.rs b/src/tools/run-make-support/src/external_deps/llvm.rs index e7715a905fb72..9c821dfc03d25 100644 --- a/src/tools/run-make-support/src/external_deps/llvm.rs +++ b/src/tools/run-make-support/src/external_deps/llvm.rs @@ -1,6 +1,7 @@ use std::path::{Path, PathBuf}; -use crate::{env_var, Command}; +use crate::command::Command; +use crate::env_checked::env_var; /// Construct a new `llvm-readobj` invocation with the `GNU` output style. /// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`. diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index 8dc6d1238b342..ce04caf6d3414 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -1,8 +1,10 @@ -use command::Command; use std::ffi::{OsStr, OsString}; use std::path::Path; -use crate::{command, cwd, env_var, set_host_rpath}; +use crate::command::Command; +use crate::env_checked::env_var; +use crate::path_helpers::cwd; +use crate::util::set_host_rpath; /// Construct a new `rustc` invocation. This will automatically set the library /// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this. diff --git a/src/tools/run-make-support/src/external_deps/rustdoc.rs b/src/tools/run-make-support/src/external_deps/rustdoc.rs index 547ab0c49c671..db324f07c7e91 100644 --- a/src/tools/run-make-support/src/external_deps/rustdoc.rs +++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs @@ -2,7 +2,8 @@ use std::ffi::OsStr; use std::path::Path; use crate::command::Command; -use crate::{env_var, env_var_os, set_host_rpath}; +use crate::env_checked::{env_var, env_var_os}; +use crate::util::set_host_rpath; /// Construct a plain `rustdoc` invocation with no flags set. #[track_caller] diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 7c7b890f6ed5b..593655d7fd208 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -20,8 +20,6 @@ pub mod run; pub mod scoped_run; pub mod targets; -use std::path::PathBuf; - // Re-exports of third-party library crates. pub use bstr; pub use gimli; @@ -85,8 +83,6 @@ pub use assertion_helpers::{ shallow_find_files, }; -use command::Command; - /// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name. #[track_caller] pub fn build_native_static_lib(lib_name: &str) -> PathBuf { @@ -106,17 +102,3 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf { llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run(); path(lib_path) } - -/// Set the runtime library path as needed for running the host rustc/rustdoc/etc. -pub fn set_host_rpath(cmd: &mut Command) { - let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR"); - cmd.env(&ld_lib_path_envvar, { - let mut paths = vec![]; - paths.push(cwd()); - paths.push(PathBuf::from(env_var("HOST_RPATH_DIR"))); - for p in std::env::split_paths(&env_var(&ld_lib_path_envvar)) { - paths.push(p.to_path_buf()); - } - std::env::join_paths(paths.iter()).unwrap() - }); -} diff --git a/src/tools/run-make-support/src/run.rs b/src/tools/run-make-support/src/run.rs index d47e009fe9f95..17f8ce34f19c1 100644 --- a/src/tools/run-make-support/src/run.rs +++ b/src/tools/run-make-support/src/run.rs @@ -4,8 +4,8 @@ use std::panic; use std::path::{Path, PathBuf}; use crate::command::{Command, CompletedProcess}; -use crate::util::handle_failed_output; -use crate::{cwd, env_var, is_windows, set_host_rpath}; +use crate::util::{handle_failed_output, set_host_rpath}; +use crate::{cwd, env_var, is_windows}; #[track_caller] fn run_common(name: &str, args: Option<&[&str]>) -> Command { diff --git a/src/tools/run-make-support/src/util.rs b/src/tools/run-make-support/src/util.rs index 41fdaf55aad5e..9ed92ac415671 100644 --- a/src/tools/run-make-support/src/util.rs +++ b/src/tools/run-make-support/src/util.rs @@ -1,4 +1,8 @@ +use std::path::PathBuf; + use crate::command::{Command, CompletedProcess}; +use crate::env_checked::env_var; +use crate::path_helpers::cwd; /// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the /// executed command, failure location, output status and stdout/stderr, and abort the process with @@ -19,3 +23,17 @@ pub(crate) fn handle_failed_output( eprintln!("=== STDERR ===\n{}\n\n", output.stderr_utf8()); std::process::exit(1) } + +/// Set the runtime library path as needed for running the host rustc/rustdoc/etc. +pub(crate) fn set_host_rpath(cmd: &mut Command) { + let ld_lib_path_envvar = env_var("LD_LIB_PATH_ENVVAR"); + cmd.env(&ld_lib_path_envvar, { + let mut paths = vec![]; + paths.push(cwd()); + paths.push(PathBuf::from(env_var("HOST_RPATH_DIR"))); + for p in std::env::split_paths(&env_var(&ld_lib_path_envvar)) { + paths.push(p.to_path_buf()); + } + std::env::join_paths(paths.iter()).unwrap() + }); +} From b7f7205212bed592c14c5292b6ed1c02e0361acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 11:12:05 +0000 Subject: [PATCH 17/27] run_make_support: move `build_native_static_lib` under `external_deps` And fix some `ar`-related rebase mishaps. --- src/tools/run-make-support/src/ar.rs | 22 -------------- .../src/external_deps/c_build.rs | 27 +++++++++++++++++ .../run-make-support/src/external_deps/mod.rs | 1 + src/tools/run-make-support/src/lib.rs | 30 ++----------------- 4 files changed, 30 insertions(+), 50 deletions(-) delete mode 100644 src/tools/run-make-support/src/ar.rs create mode 100644 src/tools/run-make-support/src/external_deps/c_build.rs diff --git a/src/tools/run-make-support/src/ar.rs b/src/tools/run-make-support/src/ar.rs deleted file mode 100644 index 6f46a1dad34c3..0000000000000 --- a/src/tools/run-make-support/src/ar.rs +++ /dev/null @@ -1,22 +0,0 @@ -use std::fs; -use std::path::Path; - -/// Archive utility. -/// -/// # Notes -/// -/// This *currently* uses the [ar][rust-ar] crate, but this is subject to changes. We may need to -/// use `llvm-ar`, and if that is the case, this should be moved under `external_deps`. -/// -/// [rust-ar]: https://github.com/mdsteele/rust-ar -#[track_caller] -pub fn ar(inputs: &[impl AsRef], output_path: impl AsRef) { - let output = fs::File::create(&output_path).expect(&format!( - "the file in path `{}` could not be created", - output_path.as_ref().display() - )); - let mut builder = ar::Builder::new(output); - for input in inputs { - builder.append_path(input).unwrap(); - } -} diff --git a/src/tools/run-make-support/src/external_deps/c_build.rs b/src/tools/run-make-support/src/external_deps/c_build.rs new file mode 100644 index 0000000000000..35b2bf75c95f5 --- /dev/null +++ b/src/tools/run-make-support/src/external_deps/c_build.rs @@ -0,0 +1,27 @@ +use std::path::PathBuf; + +use crate::artifact_names::static_lib_name; +use crate::external_deps::cc::cc; +use crate::external_deps::llvm::llvm_ar; +use crate::path_helpers::path; +use crate::targets::is_msvc; + +/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name. +#[track_caller] +pub fn build_native_static_lib(lib_name: &str) -> PathBuf { + let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") }; + let src = format!("{lib_name}.c"); + let lib_path = static_lib_name(lib_name); + if is_msvc() { + cc().arg("-c").out_exe(&obj_file).input(src).run(); + } else { + cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run(); + }; + let obj_file = if is_msvc() { + PathBuf::from(format!("{lib_name}.obj")) + } else { + PathBuf::from(format!("{lib_name}.o")) + }; + llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run(); + path(lib_path) +} diff --git a/src/tools/run-make-support/src/external_deps/mod.rs b/src/tools/run-make-support/src/external_deps/mod.rs index bcd7dce0f965c..13020b51563b3 100644 --- a/src/tools/run-make-support/src/external_deps/mod.rs +++ b/src/tools/run-make-support/src/external_deps/mod.rs @@ -6,6 +6,7 @@ //! - This is not the *only* place where external dependencies are assumed or referenced. For //! example, see [`cygpath_windows`][crate::path_helpers::cygpath_windows]. +pub mod c_build; pub mod cc; pub mod clang; pub mod htmldocck; diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 593655d7fd208..5befea5335154 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -7,7 +7,6 @@ mod command; mod macros; mod util; -pub mod ar; pub mod artifact_names; pub mod assertion_helpers; pub mod diff; @@ -28,9 +27,10 @@ pub use regex; pub use wasmparser; // Re-exports of external dependencies. -pub use external_deps::{cc, clang, htmldocck, llvm, python, rustc, rustdoc}; +pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rustdoc}; // These rely on external dependencies. +pub use c_build::build_native_static_lib; pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc}; pub use clang::{clang, Clang}; pub use htmldocck::htmldocck; @@ -42,12 +42,6 @@ pub use python::python_command; pub use rustc::{aux_build, bare_rustc, rustc, Rustc}; pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; -/// [`ar`][mod@ar] currently uses the [ar][rust-ar] rust library, but that is subject to changes, we -/// may switch to `llvm-ar` subject to experimentation. -/// -/// [rust-ar]: https://github.com/mdsteele/rust-ar -pub use ar::ar; - /// [`diff`][mod@diff] is implemented in terms of the [similar] library. /// /// [similar]: https://github.com/mitsuhiko/similar @@ -82,23 +76,3 @@ pub use assertion_helpers::{ has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains, shallow_find_files, }; - -/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name. -#[track_caller] -pub fn build_native_static_lib(lib_name: &str) -> PathBuf { - let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") }; - let src = format!("{lib_name}.c"); - let lib_path = static_lib_name(lib_name); - if is_msvc() { - cc().arg("-c").out_exe(&obj_file).input(src).run(); - } else { - cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run(); - }; - let obj_file = if is_msvc() { - PathBuf::from(format!("{lib_name}.obj")) - } else { - PathBuf::from(format!("{lib_name}.o")) - }; - llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run(); - path(lib_path) -} From a443dc4ecdc2e85fbfabdd972028d51616ee20c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 11:17:28 +0000 Subject: [PATCH 18/27] run_make_support: rename `env_checked` -> `env` --- src/tools/run-make-support/src/{env_checked.rs => env.rs} | 5 ++--- src/tools/run-make-support/src/external_deps/llvm.rs | 2 +- src/tools/run-make-support/src/external_deps/python.rs | 2 +- src/tools/run-make-support/src/external_deps/rustc.rs | 2 +- src/tools/run-make-support/src/external_deps/rustdoc.rs | 2 +- src/tools/run-make-support/src/lib.rs | 4 ++-- src/tools/run-make-support/src/path_helpers.rs | 2 +- src/tools/run-make-support/src/util.rs | 2 +- 8 files changed, 10 insertions(+), 11 deletions(-) rename src/tools/run-make-support/src/{env_checked.rs => env.rs} (84%) diff --git a/src/tools/run-make-support/src/env_checked.rs b/src/tools/run-make-support/src/env.rs similarity index 84% rename from src/tools/run-make-support/src/env_checked.rs rename to src/tools/run-make-support/src/env.rs index 9f9d2445ef66d..f52524e7d54cd 100644 --- a/src/tools/run-make-support/src/env_checked.rs +++ b/src/tools/run-make-support/src/env.rs @@ -1,10 +1,9 @@ -use std::env; use std::ffi::OsString; #[track_caller] #[must_use] pub fn env_var(name: &str) -> String { - match env::var(name) { + match std::env::var(name) { Ok(v) => v, Err(err) => panic!("failed to retrieve environment variable {name:?}: {err:?}"), } @@ -13,7 +12,7 @@ pub fn env_var(name: &str) -> String { #[track_caller] #[must_use] pub fn env_var_os(name: &str) -> OsString { - match env::var_os(name) { + match std::env::var_os(name) { Some(v) => v, None => panic!("failed to retrieve environment variable {name:?}"), } diff --git a/src/tools/run-make-support/src/external_deps/llvm.rs b/src/tools/run-make-support/src/external_deps/llvm.rs index 9c821dfc03d25..5e8ad7ed31257 100644 --- a/src/tools/run-make-support/src/external_deps/llvm.rs +++ b/src/tools/run-make-support/src/external_deps/llvm.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; /// Construct a new `llvm-readobj` invocation with the `GNU` output style. /// This assumes that `llvm-readobj` is available at `$LLVM_BIN_DIR/llvm-readobj`. diff --git a/src/tools/run-make-support/src/external_deps/python.rs b/src/tools/run-make-support/src/external_deps/python.rs index 59e725fd73e91..fb885069371bd 100644 --- a/src/tools/run-make-support/src/external_deps/python.rs +++ b/src/tools/run-make-support/src/external_deps/python.rs @@ -1,5 +1,5 @@ use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; /// Obtain path of python as provided by the `PYTHON` environment variable. It is up to the caller /// to document and check if the python version is compatible with its intended usage. diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index ce04caf6d3414..71d28dd9675fb 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -2,7 +2,7 @@ use std::ffi::{OsStr, OsString}; use std::path::Path; use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; use crate::path_helpers::cwd; use crate::util::set_host_rpath; diff --git a/src/tools/run-make-support/src/external_deps/rustdoc.rs b/src/tools/run-make-support/src/external_deps/rustdoc.rs index db324f07c7e91..96c2218a563e6 100644 --- a/src/tools/run-make-support/src/external_deps/rustdoc.rs +++ b/src/tools/run-make-support/src/external_deps/rustdoc.rs @@ -2,7 +2,7 @@ use std::ffi::OsStr; use std::path::Path; use crate::command::Command; -use crate::env_checked::{env_var, env_var_os}; +use crate::env::{env_var, env_var_os}; use crate::util::set_host_rpath; /// Construct a plain `rustdoc` invocation with no flags set. diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 5befea5335154..38070f79edc58 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -10,7 +10,7 @@ mod util; pub mod artifact_names; pub mod assertion_helpers; pub mod diff; -pub mod env_checked; +pub mod env; pub mod external_deps; pub mod fs_helpers; pub mod fs_wrapper; @@ -48,7 +48,7 @@ pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc}; pub use diff::{diff, Diff}; /// Panic-on-fail [`std::env::var`] and [`std::env::var_os`] wrappers. -pub use env_checked::{env_var, env_var_os}; +pub use env::{env_var, env_var_os}; /// Convenience helpers for running binaries and other commands. pub use run::{cmd, run, run_fail, run_with_args}; diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs index a35c32cbe48b1..f46368b53f8bc 100644 --- a/src/tools/run-make-support/src/path_helpers.rs +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -4,7 +4,7 @@ use std::panic; use std::path::{Path, PathBuf}; use crate::command::Command; -use crate::env_checked::env_var; +use crate::env::env_var; use crate::util::handle_failed_output; /// Return the current working directory. diff --git a/src/tools/run-make-support/src/util.rs b/src/tools/run-make-support/src/util.rs index 9ed92ac415671..703e3ad1c6cd2 100644 --- a/src/tools/run-make-support/src/util.rs +++ b/src/tools/run-make-support/src/util.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use crate::command::{Command, CompletedProcess}; -use crate::env_checked::env_var; +use crate::env::env_var; use crate::path_helpers::cwd; /// If a given [`Command`] failed (as indicated by its [`CompletedProcess`]), verbose print the From 13a175106141cdac24e241cb558e529c72be943b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 11:23:29 +0000 Subject: [PATCH 19/27] run_make_support: rename `cygpath_windows` to `get_windows_path` and move under `external_deps` as private --- .../run-make-support/src/external_deps/cc.rs | 9 +++-- .../src/external_deps/cygpath.rs | 35 +++++++++++++++++++ .../run-make-support/src/external_deps/mod.rs | 8 ++--- src/tools/run-make-support/src/lib.rs | 2 +- .../run-make-support/src/path_helpers.rs | 33 ----------------- 5 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 src/tools/run-make-support/src/external_deps/cygpath.rs diff --git a/src/tools/run-make-support/src/external_deps/cc.rs b/src/tools/run-make-support/src/external_deps/cc.rs index 677790b0aa95c..840bfa0d2b46e 100644 --- a/src/tools/run-make-support/src/external_deps/cc.rs +++ b/src/tools/run-make-support/src/external_deps/cc.rs @@ -1,7 +1,10 @@ use std::path::Path; use crate::command::Command; -use crate::{cygpath_windows, env_var, is_msvc, is_windows, uname}; +use crate::{env_var, is_msvc, is_windows, uname}; + +// FIXME(jieyouxu): can we get rid of the `cygpath` external dependency? +use super::cygpath::get_windows_path; /// Construct a new platform-specific C compiler invocation. /// @@ -72,10 +75,10 @@ impl Cc { if is_msvc() { path.set_extension("exe"); - let fe_path = cygpath_windows(&path); + let fe_path = get_windows_path(&path); path.set_extension(""); path.set_extension("obj"); - let fo_path = cygpath_windows(path); + let fo_path = get_windows_path(path); self.cmd.arg(format!("-Fe:{fe_path}")); self.cmd.arg(format!("-Fo:{fo_path}")); } else { diff --git a/src/tools/run-make-support/src/external_deps/cygpath.rs b/src/tools/run-make-support/src/external_deps/cygpath.rs new file mode 100644 index 0000000000000..07d8e840a63a8 --- /dev/null +++ b/src/tools/run-make-support/src/external_deps/cygpath.rs @@ -0,0 +1,35 @@ +use std::panic; +use std::path::Path; + +use crate::command::Command; +use crate::util::handle_failed_output; + +/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is +/// available on the platform! +/// +/// # FIXME +/// +/// FIXME(jieyouxu): we should consider not depending on `cygpath`. +/// +/// > The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style +/// > pathnames and vice versa. +/// > +/// > [irrelevant entries omitted...] +/// > +/// > `-w, --windows print Windows form of NAMEs (C:\WINNT)` +/// > +/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*. +#[track_caller] +#[must_use] +pub fn get_windows_path>(path: P) -> String { + let caller = panic::Location::caller(); + let mut cygpath = Command::new("cygpath"); + cygpath.arg("-w"); + cygpath.arg(path.as_ref()); + let output = cygpath.run(); + if !output.status().success() { + handle_failed_output(&cygpath, output, caller.line()); + } + // cygpath -w can attach a newline + output.stdout_utf8().trim().to_string() +} diff --git a/src/tools/run-make-support/src/external_deps/mod.rs b/src/tools/run-make-support/src/external_deps/mod.rs index 13020b51563b3..a2dc426f3f229 100644 --- a/src/tools/run-make-support/src/external_deps/mod.rs +++ b/src/tools/run-make-support/src/external_deps/mod.rs @@ -1,10 +1,5 @@ //! This module contains external tool dependencies that we assume are available in the environment, //! such as `cc` or `python`. -//! -//! # Notes -//! -//! - This is not the *only* place where external dependencies are assumed or referenced. For -//! example, see [`cygpath_windows`][crate::path_helpers::cygpath_windows]. pub mod c_build; pub mod cc; @@ -14,3 +9,6 @@ pub mod llvm; pub mod python; pub mod rustc; pub mod rustdoc; + +// Library-internal external dependency. +mod cygpath; diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 38070f79edc58..5416a6920a576 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -62,7 +62,7 @@ pub use artifact_names::{ }; /// Path-related helpers. -pub use path_helpers::{cwd, cygpath_windows, path, source_root}; +pub use path_helpers::{cwd, path, source_root}; /// Helpers for common fs operations. pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs index f46368b53f8bc..b29d8727d2b37 100644 --- a/src/tools/run-make-support/src/path_helpers.rs +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -1,11 +1,8 @@ //! Collection of path-related helpers. -use std::panic; use std::path::{Path, PathBuf}; -use crate::command::Command; use crate::env::env_var; -use crate::util::handle_failed_output; /// Return the current working directory. /// @@ -34,33 +31,3 @@ pub fn path>(p: P) -> PathBuf { pub fn source_root() -> PathBuf { env_var("SOURCE_ROOT").into() } - -/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is -/// available on the platform! -/// -/// # FIXME -/// -/// FIXME(jieyouxu): we should consider not depending on `cygpath`. -/// -/// > The cygpath program is a utility that converts Windows native filenames to Cygwin POSIX-style -/// > pathnames and vice versa. -/// > -/// > [irrelevant entries omitted...] -/// > -/// > `-w, --windows print Windows form of NAMEs (C:\WINNT)` -/// > -/// > -- *from [cygpath documentation](https://cygwin.com/cygwin-ug-net/cygpath.html)*. -#[track_caller] -#[must_use] -pub fn cygpath_windows>(path: P) -> String { - let caller = panic::Location::caller(); - let mut cygpath = Command::new("cygpath"); - cygpath.arg("-w"); - cygpath.arg(path.as_ref()); - let output = cygpath.run(); - if !output.status().success() { - handle_failed_output(&cygpath, output, caller.line()); - } - // cygpath -w can attach a newline - output.stdout_utf8().trim().to_string() -} From e1569fde3efee2955e0a32beefc108c6874c9fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 12:39:17 +0000 Subject: [PATCH 20/27] run_make_support: coalesce fs helpers into single `fs` module There were *two* `read_dir` helpers, one being a simple `std::fs::read_dir` wrapper, the other has a different callback-based signature. We also rename the callback-based `read_dir` as `read_dir_entries`. Also don't top-level re-export most `fs::*` helpers. --- .../run-make-support/src/assertion_helpers.rs | 21 ++-- src/tools/run-make-support/src/diff/mod.rs | 10 +- .../src/{fs_wrapper.rs => fs.rs} | 99 +++++++++++++++---- src/tools/run-make-support/src/fs_helpers.rs | 71 ------------- src/tools/run-make-support/src/lib.rs | 6 +- src/tools/run-make-support/src/scoped_run.rs | 14 ++- 6 files changed, 104 insertions(+), 117 deletions(-) rename src/tools/run-make-support/src/{fs_wrapper.rs => fs.rs} (52%) delete mode 100644 src/tools/run-make-support/src/fs_helpers.rs diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs index 3fdcc94a034f1..b57ac475e0876 100644 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -3,8 +3,7 @@ use std::panic; use std::path::{Path, PathBuf}; -use crate::fs_helpers; -use crate::fs_wrapper; +use crate::fs as rfs; use crate::path_helpers::cwd; /// Browse the directory `path` non-recursively and return all files which respect the parameters @@ -15,7 +14,7 @@ pub fn shallow_find_files, F: Fn(&PathBuf) -> bool>( filter: F, ) -> Vec { let mut matching_files = Vec::new(); - for entry in fs_wrapper::read_dir(path) { + for entry in rfs::read_dir(path) { let entry = entry.expect("failed to read directory entry."); let path = entry.path(); @@ -61,7 +60,7 @@ pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) let mut count = 0; for file in fetched_files { - let content = fs_wrapper::read_to_string(file); + let content = rfs::read_to_string(file); count += content.lines().filter(|line| re.is_match(&line)).count(); } @@ -69,11 +68,11 @@ pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) } /// Read the contents of a file that cannot simply be read by -/// [`read_to_string`][crate::fs_wrapper::read_to_string], due to invalid UTF-8 data, then assert +/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert /// that it contains `expected`. #[track_caller] pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S) { - let buffer = fs_wrapper::read(path.as_ref()); + let buffer = rfs::read(path.as_ref()); let expected = expected.as_ref(); if !String::from_utf8_lossy(&buffer).contains(expected) { eprintln!("=== FILE CONTENTS (LOSSY) ==="); @@ -85,11 +84,11 @@ pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S } /// Read the contents of a file that cannot simply be read by -/// [`read_to_string`][crate::fs_wrapper::read_to_string], due to invalid UTF-8 data, then assert +/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert /// that it does not contain `expected`. #[track_caller] pub fn invalid_utf8_not_contains, S: AsRef>(path: P, expected: S) { - let buffer = fs_wrapper::read(path.as_ref()); + let buffer = rfs::read(path.as_ref()); let expected = expected.as_ref(); if String::from_utf8_lossy(&buffer).contains(expected) { eprintln!("=== FILE CONTENTS (LOSSY) ==="); @@ -145,14 +144,14 @@ pub fn assert_not_contains, N: AsRef>(haystack: H, needle: N) /// Assert that all files in `dir1` exist and have the same content in `dir2` pub fn assert_recursive_eq(dir1: impl AsRef, dir2: impl AsRef) { let dir2 = dir2.as_ref(); - fs_helpers::read_dir(dir1, |entry_path| { + rfs::read_dir_entries(dir1, |entry_path| { let entry_name = entry_path.file_name().unwrap(); if entry_path.is_dir() { assert_recursive_eq(&entry_path, &dir2.join(entry_name)); } else { let path2 = dir2.join(entry_name); - let file1 = fs_wrapper::read(&entry_path); - let file2 = fs_wrapper::read(&path2); + let file1 = rfs::read(&entry_path); + let file2 = rfs::read(&path2); // We don't use `assert_eq!` because they are `Vec`, so not great for display. // Why not using String? Because there might be minified files or even potentially diff --git a/src/tools/run-make-support/src/diff/mod.rs b/src/tools/run-make-support/src/diff/mod.rs index ad989b74e4d9e..9f35488911928 100644 --- a/src/tools/run-make-support/src/diff/mod.rs +++ b/src/tools/run-make-support/src/diff/mod.rs @@ -2,7 +2,7 @@ use regex::Regex; use similar::TextDiff; use std::path::{Path, PathBuf}; -use crate::fs_wrapper; +use crate::fs as rfs; use build_helper::drop_bomb::DropBomb; #[cfg(test)] @@ -43,7 +43,7 @@ impl Diff { /// Specify the expected output for the diff from a file. pub fn expected_file>(&mut self, path: P) -> &mut Self { let path = path.as_ref(); - let content = fs_wrapper::read_to_string(path); + let content = rfs::read_to_string(path); let name = path.to_string_lossy().to_string(); self.expected_file = Some(path.into()); @@ -62,7 +62,7 @@ impl Diff { /// Specify the actual output for the diff from a file. pub fn actual_file>(&mut self, path: P) -> &mut Self { let path = path.as_ref(); - let content = fs_wrapper::read_to_string(path); + let content = rfs::read_to_string(path); let name = path.to_string_lossy().to_string(); self.actual = Some(content); @@ -116,7 +116,7 @@ impl Diff { if let Some(ref expected_file) = self.expected_file { if std::env::var("RUSTC_BLESS_TEST").is_ok() { println!("Blessing `{}`", expected_file.display()); - fs_wrapper::write(expected_file, actual); + rfs::write(expected_file, actual); return; } } @@ -138,7 +138,7 @@ impl Diff { if let Some(ref expected_file) = self.expected_file { if std::env::var("RUSTC_BLESS_TEST").is_ok() { println!("Blessing `{}`", expected_file.display()); - fs_wrapper::write(expected_file, actual); + rfs::write(expected_file, actual); return; } } diff --git a/src/tools/run-make-support/src/fs_wrapper.rs b/src/tools/run-make-support/src/fs.rs similarity index 52% rename from src/tools/run-make-support/src/fs_wrapper.rs rename to src/tools/run-make-support/src/fs.rs index 0f0d6f6618ced..f346e983aea8b 100644 --- a/src/tools/run-make-support/src/fs_wrapper.rs +++ b/src/tools/run-make-support/src/fs.rs @@ -1,17 +1,82 @@ -use std::fs; +use std::io; use std::path::Path; +// FIXME(jieyouxu): modify create_symlink to panic on windows. + +/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix. +#[cfg(target_family = "windows")] +pub fn create_symlink, Q: AsRef>(original: P, link: Q) { + if link.as_ref().exists() { + std::fs::remove_dir(link.as_ref()).unwrap(); + } + std::os::windows::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, Q: AsRef>(original: P, link: Q) { + if link.as_ref().exists() { + std::fs::remove_dir(link.as_ref()).unwrap(); + } + std::os::unix::fs::symlink(original.as_ref(), link.as_ref()).expect(&format!( + "failed to create symlink {:?} for {:?}", + link.as_ref().display(), + original.as_ref().display(), + )); +} + +/// Copy a directory into another. +pub fn copy_dir_all(src: impl AsRef, dst: impl AsRef) { + fn copy_dir_all_inner(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { + let dst = dst.as_ref(); + if !dst.is_dir() { + std::fs::create_dir_all(&dst)?; + } + for entry in std::fs::read_dir(src)? { + let entry = entry?; + let ty = entry.file_type()?; + if ty.is_dir() { + copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?; + } else { + std::fs::copy(entry.path(), dst.join(entry.file_name()))?; + } + } + Ok(()) + } + + if let Err(e) = copy_dir_all_inner(&src, &dst) { + // Trying to give more context about what exactly caused the failure + panic!( + "failed to copy `{}` to `{}`: {:?}", + src.as_ref().display(), + dst.as_ref().display(), + e + ); + } +} + +/// Helper for reading entries in a given directory. +pub fn read_dir_entries, F: FnMut(&Path)>(dir: P, mut callback: F) { + for entry in read_dir(dir) { + callback(&entry.unwrap().path()); + } +} + /// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message. #[track_caller] pub fn remove_file>(path: P) { - fs::remove_file(path.as_ref()) + std::fs::remove_file(path.as_ref()) .expect(&format!("the file in path \"{}\" could not be removed", path.as_ref().display())); } /// A wrapper around [`std::fs::copy`] which includes the file path in the panic message. #[track_caller] pub fn copy, Q: AsRef>(from: P, to: Q) { - fs::copy(from.as_ref(), to.as_ref()).expect(&format!( + std::fs::copy(from.as_ref(), to.as_ref()).expect(&format!( "the file \"{}\" could not be copied over to \"{}\"", from.as_ref().display(), to.as_ref().display(), @@ -21,21 +86,21 @@ pub fn copy, Q: AsRef>(from: P, to: Q) { /// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message. #[track_caller] pub fn create_file>(path: P) { - fs::File::create(path.as_ref()) + std::fs::File::create(path.as_ref()) .expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display())); } /// A wrapper around [`std::fs::read`] which includes the file path in the panic message. #[track_caller] pub fn read>(path: P) -> Vec { - fs::read(path.as_ref()) + std::fs::read(path.as_ref()) .expect(&format!("the file in path \"{}\" could not be read", path.as_ref().display())) } /// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message. #[track_caller] pub fn read_to_string>(path: P) -> String { - fs::read_to_string(path.as_ref()).expect(&format!( + std::fs::read_to_string(path.as_ref()).expect(&format!( "the file in path \"{}\" could not be read into a String", path.as_ref().display() )) @@ -43,15 +108,15 @@ pub fn read_to_string>(path: P) -> String { /// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message. #[track_caller] -pub fn read_dir>(path: P) -> fs::ReadDir { - fs::read_dir(path.as_ref()) +pub fn read_dir>(path: P) -> std::fs::ReadDir { + std::fs::read_dir(path.as_ref()) .expect(&format!("the directory in path \"{}\" could not be read", path.as_ref().display())) } /// A wrapper around [`std::fs::write`] which includes the file path in the panic message. #[track_caller] pub fn write, C: AsRef<[u8]>>(path: P, contents: C) { - fs::write(path.as_ref(), contents.as_ref()).expect(&format!( + std::fs::write(path.as_ref(), contents.as_ref()).expect(&format!( "the file in path \"{}\" could not be written to", path.as_ref().display() )); @@ -60,7 +125,7 @@ pub fn write, C: AsRef<[u8]>>(path: P, contents: C) { /// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message. #[track_caller] pub fn remove_dir_all>(path: P) { - fs::remove_dir_all(path.as_ref()).expect(&format!( + std::fs::remove_dir_all(path.as_ref()).expect(&format!( "the directory in path \"{}\" could not be removed alongside all its contents", path.as_ref().display(), )); @@ -69,7 +134,7 @@ pub fn remove_dir_all>(path: P) { /// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message. #[track_caller] pub fn create_dir>(path: P) { - fs::create_dir(path.as_ref()).expect(&format!( + std::fs::create_dir(path.as_ref()).expect(&format!( "the directory in path \"{}\" could not be created", path.as_ref().display() )); @@ -78,7 +143,7 @@ pub fn create_dir>(path: P) { /// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message. #[track_caller] pub fn create_dir_all>(path: P) { - fs::create_dir_all(path.as_ref()).expect(&format!( + std::fs::create_dir_all(path.as_ref()).expect(&format!( "the directory (and all its parents) in path \"{}\" could not be created", path.as_ref().display() )); @@ -86,8 +151,8 @@ pub fn create_dir_all>(path: P) { /// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message. #[track_caller] -pub fn metadata>(path: P) -> fs::Metadata { - fs::metadata(path.as_ref()).expect(&format!( +pub fn metadata>(path: P) -> std::fs::Metadata { + std::fs::metadata(path.as_ref()).expect(&format!( "the file's metadata in path \"{}\" could not be read", path.as_ref().display() )) @@ -96,7 +161,7 @@ pub fn metadata>(path: P) -> fs::Metadata { /// A wrapper around [`std::fs::rename`] which includes the file path in the panic message. #[track_caller] pub fn rename, Q: AsRef>(from: P, to: Q) { - fs::rename(from.as_ref(), to.as_ref()).expect(&format!( + std::fs::rename(from.as_ref(), to.as_ref()).expect(&format!( "the file \"{}\" could not be moved over to \"{}\"", from.as_ref().display(), to.as_ref().display(), @@ -105,8 +170,8 @@ pub fn rename, Q: AsRef>(from: P, to: Q) { /// A wrapper around [`std::fs::set_permissions`] which includes the file path in the panic message. #[track_caller] -pub fn set_permissions>(path: P, perm: fs::Permissions) { - fs::set_permissions(path.as_ref(), perm).expect(&format!( +pub fn set_permissions>(path: P, perm: std::fs::Permissions) { + std::fs::set_permissions(path.as_ref(), perm).expect(&format!( "the file's permissions in path \"{}\" could not be changed", path.as_ref().display() )); diff --git a/src/tools/run-make-support/src/fs_helpers.rs b/src/tools/run-make-support/src/fs_helpers.rs deleted file mode 100644 index 07e0900842aba..0000000000000 --- a/src/tools/run-make-support/src/fs_helpers.rs +++ /dev/null @@ -1,71 +0,0 @@ -use std::io; -use std::path::Path; - -use crate::fs_wrapper; - -// FIXME(jieyouxu): modify create_symlink to panic on windows. - -/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix. -#[cfg(target_family = "windows")] -pub fn create_symlink, Q: AsRef>(original: P, link: Q) { - if link.as_ref().exists() { - std::fs::remove_dir(link.as_ref()).unwrap(); - } - 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, Q: AsRef>(original: P, link: Q) { - if link.as_ref().exists() { - std::fs::remove_dir(link.as_ref()).unwrap(); - } - 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(), - )); -} - -/// Copy a directory into another. -pub fn copy_dir_all(src: impl AsRef, dst: impl AsRef) { - fn copy_dir_all_inner(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { - let dst = dst.as_ref(); - if !dst.is_dir() { - std::fs::create_dir_all(&dst)?; - } - for entry in std::fs::read_dir(src)? { - let entry = entry?; - let ty = entry.file_type()?; - if ty.is_dir() { - copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?; - } else { - std::fs::copy(entry.path(), dst.join(entry.file_name()))?; - } - } - Ok(()) - } - - if let Err(e) = copy_dir_all_inner(&src, &dst) { - // Trying to give more context about what exactly caused the failure - panic!( - "failed to copy `{}` to `{}`: {:?}", - src.as_ref().display(), - dst.as_ref().display(), - e - ); - } -} - -/// Helper for reading entries in a given directory. -pub fn read_dir, F: FnMut(&Path)>(dir: P, mut callback: F) { - for entry in fs_wrapper::read_dir(dir) { - callback(&entry.unwrap().path()); - } -} diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 5416a6920a576..ae34ecd8d9726 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -12,8 +12,7 @@ pub mod assertion_helpers; pub mod diff; pub mod env; pub mod external_deps; -pub mod fs_helpers; -pub mod fs_wrapper; +pub mod fs; pub mod path_helpers; pub mod run; pub mod scoped_run; @@ -64,9 +63,6 @@ pub use artifact_names::{ /// Path-related helpers. pub use path_helpers::{cwd, path, source_root}; -/// Helpers for common fs operations. -pub use fs_helpers::{copy_dir_all, create_symlink, read_dir}; - /// Helpers for scoped test execution where certain properties are attempted to be maintained. pub use scoped_run::{run_in_tmpdir, test_while_readonly}; diff --git a/src/tools/run-make-support/src/scoped_run.rs b/src/tools/run-make-support/src/scoped_run.rs index ab8d2429b6ae6..63837e98904a4 100644 --- a/src/tools/run-make-support/src/scoped_run.rs +++ b/src/tools/run-make-support/src/scoped_run.rs @@ -1,10 +1,8 @@ //! Collection of helpers that try to maintain certain properties while running a test closure. -use std::fs; use std::path::Path; -use crate::fs_helpers::copy_dir_all; -use crate::fs_wrapper; +use crate::fs as rfs; use crate::path_helpers::cwd; use crate::targets::is_windows; @@ -36,16 +34,16 @@ where ); panic!("`test_while_readonly` on directory detected while on Windows."); } - let metadata = fs_wrapper::metadata(&path); + let metadata = rfs::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); + rfs::set_permissions(&path, new_perms); let success = std::panic::catch_unwind(closure); - fs_wrapper::set_permissions(&path, original_perms); + rfs::set_permissions(&path, original_perms); success.unwrap(); } @@ -62,10 +60,10 @@ where pub fn run_in_tmpdir(callback: F) { let original_dir = cwd(); let tmpdir = original_dir.join("../temporary-directory"); - copy_dir_all(".", &tmpdir); + rfs::copy_dir_all(".", &tmpdir); std::env::set_current_dir(&tmpdir).unwrap(); callback(); std::env::set_current_dir(original_dir).unwrap(); - fs::remove_dir_all(tmpdir).unwrap(); + rfs::remove_dir_all(tmpdir); } From 636be91cc0d8e406171ec4aa1b5dea4b77d1a714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 12:42:06 +0000 Subject: [PATCH 21/27] tests: update for renamed `fs` module in run_make_support --- tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs | 4 ++-- tests/run-make/c-link-to-rust-dylib/rmake.rs | 8 +++---- .../c-link-to-rust-staticlib/rmake.rs | 2 +- tests/run-make/cdylib/rmake.rs | 4 ++-- tests/run-make/comment-section/rmake.rs | 5 +++-- tests/run-make/compiler-builtins/rmake.rs | 2 +- tests/run-make/compiler-lookup-paths/rmake.rs | 14 ++++++------ tests/run-make/const-prop-lint/rmake.rs | 4 ++-- tests/run-make/crate-name-priority/rmake.rs | 10 ++++----- .../run-make/doctests-keep-binaries/rmake.rs | 2 +- tests/run-make/doctests-runtool/rmake.rs | 2 +- tests/run-make/dump-mono-stats/rmake.rs | 4 ++-- tests/run-make/dylib-chain/rmake.rs | 8 +++---- tests/run-make/emit-named-files/rmake.rs | 4 ++-- tests/run-make/emit-path-unhashed/rmake.rs | 10 ++++----- tests/run-make/extern-flag-pathless/rmake.rs | 18 +++++++-------- .../extra-filename-with-temp-outputs/rmake.rs | 6 ++--- .../run-make/ice-dep-cannot-find-dep/rmake.rs | 2 +- tests/run-make/inaccessible-temp-dir/rmake.rs | 4 ++-- .../incr-prev-body-beyond-eof/rmake.rs | 10 ++++----- tests/run-make/incr-test-moved-file/rmake.rs | 12 +++++----- .../incremental-debugger-visualizer/rmake.rs | 22 +++++++++---------- .../incremental-session-fail/rmake.rs | 4 ++-- .../run-make/inline-always-many-cgu/rmake.rs | 8 +++---- tests/run-make/intrinsic-unreachable/rmake.rs | 6 ++--- tests/run-make/invalid-library/rmake.rs | 4 ++-- tests/run-make/invalid-so/rmake.rs | 4 ++-- tests/run-make/invalid-staticlib/rmake.rs | 4 ++-- .../issue-107495-archive-permissions/rmake.rs | 4 ++-- tests/run-make/ls-metadata/rmake.rs | 4 ++-- tests/run-make/lto-readonly-lib/rmake.rs | 2 +- .../many-crates-but-no-match/rmake.rs | 8 +++---- tests/run-make/mixing-libs/rmake.rs | 4 ++-- .../moved-src-dir-fingerprint-ice/rmake.rs | 14 ++++++------ tests/run-make/non-unicode-env/rmake.rs | 4 ++-- .../non-unicode-in-incremental-dir/rmake.rs | 6 ++--- tests/run-make/obey-crate-type-flag/rmake.rs | 4 ++-- .../rmake.rs | 4 ++-- .../output-filename-overwrites-input/rmake.rs | 6 ++--- .../output-type-permutations/rmake.rs | 13 +++++------ .../parallel-rustc-no-overwrite/rmake.rs | 4 ++-- tests/run-make/pgo-branch-weights/rmake.rs | 9 +++----- tests/run-make/pgo-use/rmake.rs | 6 ++--- tests/run-make/prefer-dylib/rmake.rs | 4 ++-- tests/run-make/prefer-rlib/rmake.rs | 6 ++--- .../pretty-print-with-dep-file/rmake.rs | 4 ++-- tests/run-make/print-cfg/rmake.rs | 4 ++-- tests/run-make/print-to-output/rmake.rs | 4 ++-- tests/run-make/remap-path-prefix/rmake.rs | 16 +++++--------- tests/run-make/repr128-dwarf/rmake.rs | 4 ++-- tests/run-make/reset-codegen-1/rmake.rs | 2 +- tests/run-make/resolve-rename/rmake.rs | 4 ++-- tests/run-make/rlib-chain/rmake.rs | 8 +++---- .../rustdoc-scrape-examples-remap/scrape.rs | 4 ++-- tests/run-make/rustdoc-test-args/rmake.rs | 4 ++-- tests/run-make/rustdoc-themes/rmake.rs | 11 +++++----- .../rustdoc-verify-output-files/rmake.rs | 8 +++---- tests/run-make/sepcomp-cci-copies/rmake.rs | 2 +- tests/run-make/sepcomp-inlining/rmake.rs | 2 +- tests/run-make/sepcomp-separate/rmake.rs | 2 +- tests/run-make/silly-file-names/rmake.rs | 10 ++++----- tests/run-make/symlinked-extern/rmake.rs | 6 ++--- tests/run-make/symlinked-libraries/rmake.rs | 6 ++--- tests/run-make/symlinked-rlib/rmake.rs | 4 ++-- tests/run-make/target-specs/rmake.rs | 8 +++---- tests/run-make/track-path-dep-info/rmake.rs | 4 ++-- tests/run-make/track-pgo-dep-info/rmake.rs | 4 ++-- tests/run-make/volatile-intrinsics/rmake.rs | 4 ++-- tests/run-make/wasm-custom-section/rmake.rs | 4 ++-- .../wasm-custom-sections-opt/rmake.rs | 4 ++-- .../run-make/wasm-export-all-symbols/rmake.rs | 4 ++-- tests/run-make/wasm-import-module/rmake.rs | 4 ++-- tests/run-make/wasm-panic-small/rmake.rs | 4 ++-- tests/run-make/wasm-spurious-import/rmake.rs | 4 ++-- .../wasm-stringify-ints-small/rmake.rs | 4 ++-- .../wasm-symbols-different-module/rmake.rs | 4 ++-- .../wasm-symbols-not-exported/rmake.rs | 4 ++-- .../wasm-symbols-not-imported/rmake.rs | 4 ++-- .../run-make/weird-output-filenames/rmake.rs | 6 ++--- tests/run-make/windows-ws2_32/rmake.rs | 4 ++-- 80 files changed, 225 insertions(+), 239 deletions(-) diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs index d937514c2ca21..5dd05f151df41 100644 --- a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs +++ b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs @@ -5,14 +5,14 @@ use std::path::PathBuf; -use run_make_support::{aux_build, fs_wrapper, rustc, source_root}; +use run_make_support::{aux_build, fs as rfs, rustc, source_root}; fn main() { aux_build().input("stable.rs").emit("metadata").run(); let output = rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run(); - let version = fs_wrapper::read_to_string(source_root().join("src/version")); + let version = rfs::read_to_string(source_root().join("src/version")); let expected_string = format!("stable since {}", version.trim()); output.assert_stderr_contains(expected_string); } diff --git a/tests/run-make/c-link-to-rust-dylib/rmake.rs b/tests/run-make/c-link-to-rust-dylib/rmake.rs index b8ea0b6b345b4..e4441ac0c3be1 100644 --- a/tests/run-make/c-link-to-rust-dylib/rmake.rs +++ b/tests/run-make/c-link-to-rust-dylib/rmake.rs @@ -3,9 +3,7 @@ //@ ignore-cross-compile -use run_make_support::{ - cc, cwd, dynamic_lib_extension, fs_wrapper, is_msvc, read_dir, run, run_fail, rustc, -}; +use run_make_support::{cc, cwd, dynamic_lib_extension, fs as rfs, is_msvc, run, run_fail, rustc}; fn main() { rustc().input("foo.rs").run(); @@ -21,14 +19,14 @@ fn main() { run("bar"); let expected_extension = dynamic_lib_extension(); - read_dir(cwd(), |path| { + rfs::read_dir_entries(cwd(), |path| { if path.is_file() && path.extension().is_some_and(|ext| ext == expected_extension) && path.file_name().and_then(|name| name.to_str()).is_some_and(|name| { name.ends_with(".so") || name.ends_with(".dll") || name.ends_with(".dylib") }) { - fs_wrapper::remove_file(path); + rfs::remove_file(path); } }); run_fail("bar"); diff --git a/tests/run-make/c-link-to-rust-staticlib/rmake.rs b/tests/run-make/c-link-to-rust-staticlib/rmake.rs index d60b37524f43c..8c845f8b6f2d2 100644 --- a/tests/run-make/c-link-to-rust-staticlib/rmake.rs +++ b/tests/run-make/c-link-to-rust-staticlib/rmake.rs @@ -3,7 +3,7 @@ //@ ignore-cross-compile -use run_make_support::fs_wrapper::remove_file; +use run_make_support::fs::remove_file; use run_make_support::{cc, extra_c_flags, run, rustc, static_lib_name}; use std::fs; diff --git a/tests/run-make/cdylib/rmake.rs b/tests/run-make/cdylib/rmake.rs index 55ea227ab5198..b6f2a9be0b224 100644 --- a/tests/run-make/cdylib/rmake.rs +++ b/tests/run-make/cdylib/rmake.rs @@ -10,7 +10,7 @@ //@ ignore-cross-compile -use run_make_support::{cc, cwd, dynamic_lib_name, fs_wrapper, is_msvc, run, rustc}; +use run_make_support::{cc, cwd, dynamic_lib_name, fs as rfs, is_msvc, run, rustc}; fn main() { rustc().input("bar.rs").run(); @@ -23,7 +23,7 @@ fn main() { } run("foo"); - fs_wrapper::remove_file(dynamic_lib_name("foo")); + rfs::remove_file(dynamic_lib_name("foo")); rustc().input("foo.rs").arg("-Clto").run(); run("foo"); diff --git a/tests/run-make/comment-section/rmake.rs b/tests/run-make/comment-section/rmake.rs index 188c6dcb25d2e..f6978ab259ddb 100644 --- a/tests/run-make/comment-section/rmake.rs +++ b/tests/run-make/comment-section/rmake.rs @@ -9,9 +9,10 @@ use std::path::PathBuf; +use run_make_support::fs as rfs; use run_make_support::llvm_readobj; use run_make_support::rustc; -use run_make_support::{cwd, env_var, read_dir, run_in_tmpdir}; +use run_make_support::{cwd, env_var, run_in_tmpdir}; fn main() { let target = env_var("TARGET"); @@ -33,7 +34,7 @@ fn main() { // Check all object files (including temporary outputs) have a `.comment` // section with the expected content. - read_dir(cwd(), |f| { + rfs::read_dir_entries(cwd(), |f| { if !f.extension().is_some_and(|ext| ext == "o") { return; } diff --git a/tests/run-make/compiler-builtins/rmake.rs b/tests/run-make/compiler-builtins/rmake.rs index 10ff9cd282d8b..b9dacdd0b9058 100644 --- a/tests/run-make/compiler-builtins/rmake.rs +++ b/tests/run-make/compiler-builtins/rmake.rs @@ -14,7 +14,7 @@ #![deny(warnings)] -use run_make_support::fs_wrapper::{read, read_dir}; +use run_make_support::fs::{read, read_dir}; use run_make_support::object::read::archive::ArchiveFile; use run_make_support::object::read::Object; use run_make_support::object::ObjectSection; diff --git a/tests/run-make/compiler-lookup-paths/rmake.rs b/tests/run-make/compiler-lookup-paths/rmake.rs index 0f79185282134..cfb7ef90ce43b 100644 --- a/tests/run-make/compiler-lookup-paths/rmake.rs +++ b/tests/run-make/compiler-lookup-paths/rmake.rs @@ -9,16 +9,16 @@ //@ ignore-wasm64 // Reason: a C compiler is required for build_native_static_lib -use run_make_support::{build_native_static_lib, fs_wrapper, rustc, static_lib_name}; +use run_make_support::{build_native_static_lib, fs as rfs, rustc, static_lib_name}; fn main() { build_native_static_lib("native"); let lib_native = static_lib_name("native"); - fs_wrapper::create_dir_all("crate"); - fs_wrapper::create_dir_all("native"); - fs_wrapper::rename(&lib_native, format!("native/{}", &lib_native)); + rfs::create_dir_all("crate"); + rfs::create_dir_all("native"); + rfs::rename(&lib_native, format!("native/{}", &lib_native)); rustc().input("a.rs").run(); - fs_wrapper::rename("liba.rlib", "crate/liba.rlib"); + rfs::rename("liba.rlib", "crate/liba.rlib"); rustc().input("b.rs").specific_library_search_path("native", "crate").run_fail(); rustc().input("b.rs").specific_library_search_path("dependency", "crate").run_fail(); rustc().input("b.rs").specific_library_search_path("crate", "crate").run(); @@ -35,8 +35,8 @@ fn main() { rustc().input("d.rs").specific_library_search_path("all", "native").run(); // Deduplication tests. - fs_wrapper::create_dir_all("e1"); - fs_wrapper::create_dir_all("e2"); + rfs::create_dir_all("e1"); + rfs::create_dir_all("e2"); rustc().input("e.rs").output("e1/libe.rlib").run(); rustc().input("e.rs").output("e2/libe.rlib").run(); diff --git a/tests/run-make/const-prop-lint/rmake.rs b/tests/run-make/const-prop-lint/rmake.rs index d194f70d91696..25d9ccad41774 100644 --- a/tests/run-make/const-prop-lint/rmake.rs +++ b/tests/run-make/const-prop-lint/rmake.rs @@ -1,11 +1,11 @@ // Tests that const prop lints interrupting codegen don't leave `.o` files around. -use run_make_support::{cwd, fs_wrapper, rustc}; +use run_make_support::{cwd, fs as rfs, rustc}; fn main() { rustc().input("input.rs").run_fail().assert_exit_code(1); - for entry in fs_wrapper::read_dir(cwd()) { + for entry in rfs::read_dir(cwd()) { let entry = entry.unwrap(); let path = entry.path(); diff --git a/tests/run-make/crate-name-priority/rmake.rs b/tests/run-make/crate-name-priority/rmake.rs index b7cb2c9971141..c0cc8bdfdbfa8 100644 --- a/tests/run-make/crate-name-priority/rmake.rs +++ b/tests/run-make/crate-name-priority/rmake.rs @@ -4,15 +4,15 @@ // and the compiler flags, and checks that the flag is favoured each time. // See https://github.com/rust-lang/rust/pull/15518 -use run_make_support::{bin_name, fs_wrapper, rustc}; +use run_make_support::{bin_name, fs as rfs, rustc}; fn main() { rustc().input("foo.rs").run(); - fs_wrapper::remove_file(bin_name("foo")); + rfs::remove_file(bin_name("foo")); rustc().input("foo.rs").crate_name("bar").run(); - fs_wrapper::remove_file(bin_name("bar")); + rfs::remove_file(bin_name("bar")); rustc().input("foo1.rs").run(); - fs_wrapper::remove_file(bin_name("foo")); + rfs::remove_file(bin_name("foo")); rustc().input("foo1.rs").output(bin_name("bar1")).run(); - fs_wrapper::remove_file(bin_name("bar1")); + rfs::remove_file(bin_name("bar1")); } diff --git a/tests/run-make/doctests-keep-binaries/rmake.rs b/tests/run-make/doctests-keep-binaries/rmake.rs index e48c8a0cef351..35b29f21a5ab9 100644 --- a/tests/run-make/doctests-keep-binaries/rmake.rs +++ b/tests/run-make/doctests-keep-binaries/rmake.rs @@ -1,7 +1,7 @@ // Check that valid binaries are persisted by running them, regardless of whether the // --run or --no-run option is used. -use run_make_support::fs_wrapper::{create_dir, remove_dir_all}; +use run_make_support::fs::{create_dir, remove_dir_all}; use run_make_support::{run, rustc, rustdoc}; use std::path::Path; diff --git a/tests/run-make/doctests-runtool/rmake.rs b/tests/run-make/doctests-runtool/rmake.rs index 5208730d336dc..979c3ea7d2c15 100644 --- a/tests/run-make/doctests-runtool/rmake.rs +++ b/tests/run-make/doctests-runtool/rmake.rs @@ -1,6 +1,6 @@ // Tests behavior of rustdoc `--runtool`. -use run_make_support::fs_wrapper::{create_dir, remove_dir_all}; +use run_make_support::fs::{create_dir, remove_dir_all}; use run_make_support::{rustc, rustdoc}; use std::path::PathBuf; diff --git a/tests/run-make/dump-mono-stats/rmake.rs b/tests/run-make/dump-mono-stats/rmake.rs index 05ba2e6b8ff2b..05a5b559e6ddf 100644 --- a/tests/run-make/dump-mono-stats/rmake.rs +++ b/tests/run-make/dump-mono-stats/rmake.rs @@ -4,7 +4,7 @@ // a specific expected string. // See https://github.com/rust-lang/rust/pull/105481 -use run_make_support::{cwd, fs_wrapper, rustc}; +use run_make_support::{cwd, fs as rfs, rustc}; fn main() { rustc() @@ -13,5 +13,5 @@ fn main() { .arg(format!("-Zdump-mono-stats={}", cwd().display())) .arg("-Zdump-mono-stats-format=json") .run(); - assert!(fs_wrapper::read_to_string("foo.mono_items.json").contains(r#""name":"bar""#)); + assert!(rfs::read_to_string("foo.mono_items.json").contains(r#""name":"bar""#)); } diff --git a/tests/run-make/dylib-chain/rmake.rs b/tests/run-make/dylib-chain/rmake.rs index a96cc3508750b..63ae2f01ce408 100644 --- a/tests/run-make/dylib-chain/rmake.rs +++ b/tests/run-make/dylib-chain/rmake.rs @@ -8,7 +8,7 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rustc}; +use run_make_support::{dynamic_lib_name, fs as rfs, run, run_fail, rustc}; fn main() { rustc().input("m1.rs").arg("-Cprefer-dynamic").run(); @@ -16,8 +16,8 @@ fn main() { rustc().input("m3.rs").arg("-Cprefer-dynamic").run(); rustc().input("m4.rs").run(); run("m4"); - fs_wrapper::remove_file(dynamic_lib_name("m1")); - fs_wrapper::remove_file(dynamic_lib_name("m2")); - fs_wrapper::remove_file(dynamic_lib_name("m3")); + rfs::remove_file(dynamic_lib_name("m1")); + rfs::remove_file(dynamic_lib_name("m2")); + rfs::remove_file(dynamic_lib_name("m3")); run_fail("m4"); } diff --git a/tests/run-make/emit-named-files/rmake.rs b/tests/run-make/emit-named-files/rmake.rs index a02c97fec4cba..0cf743fc7d438 100644 --- a/tests/run-make/emit-named-files/rmake.rs +++ b/tests/run-make/emit-named-files/rmake.rs @@ -1,6 +1,6 @@ use std::path::Path; -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) { let out_file = out_dir.join(out_file); @@ -11,7 +11,7 @@ fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) { fn main() { let out_dir = Path::new("emit"); - fs_wrapper::create_dir(&out_dir); + rfs::create_dir(&out_dir); emit_and_check(&out_dir, "libfoo.s", "asm"); emit_and_check(&out_dir, "libfoo.bc", "llvm-bc"); diff --git a/tests/run-make/emit-path-unhashed/rmake.rs b/tests/run-make/emit-path-unhashed/rmake.rs index ce56c19758868..0d0ad1b91670f 100644 --- a/tests/run-make/emit-path-unhashed/rmake.rs +++ b/tests/run-make/emit-path-unhashed/rmake.rs @@ -6,13 +6,13 @@ // adding a new output type (in this test, metadata). // See https://github.com/rust-lang/rust/issues/86044 -use run_make_support::{diff, fs_wrapper, rustc}; +use run_make_support::{diff, fs as rfs, rustc}; fn main() { - fs_wrapper::create_dir("emit"); - fs_wrapper::create_dir("emit/a"); - fs_wrapper::create_dir("emit/b"); - fs_wrapper::create_dir("emit/c"); + rfs::create_dir("emit"); + rfs::create_dir("emit/a"); + rfs::create_dir("emit/b"); + rfs::create_dir("emit/c"); // The default output name. rustc().emit("link").input("foo.rs").run(); // The output is named with the output flag. diff --git a/tests/run-make/extern-flag-pathless/rmake.rs b/tests/run-make/extern-flag-pathless/rmake.rs index 9cf828abcb8b4..bdc8b3e2c9991 100644 --- a/tests/run-make/extern-flag-pathless/rmake.rs +++ b/tests/run-make/extern-flag-pathless/rmake.rs @@ -8,21 +8,21 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -use run_make_support::{dynamic_lib_name, fs_wrapper, run, run_fail, rust_lib_name, rustc}; +use run_make_support::{dynamic_lib_name, fs as rfs, run, run_fail, rust_lib_name, rustc}; fn main() { rustc().input("bar.rs").crate_type("rlib").crate_type("dylib").arg("-Cprefer-dynamic").run(); // By default, the rlib has priority over the dylib. rustc().input("foo.rs").arg("--extern").arg("bar").run(); - fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + rfs::rename(dynamic_lib_name("bar"), "bar.tmp"); run("foo"); - fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + rfs::rename("bar.tmp", dynamic_lib_name("bar")); rustc().input("foo.rs").extern_("bar", rust_lib_name("bar")).arg("--extern").arg("bar").run(); - fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + rfs::rename(dynamic_lib_name("bar"), "bar.tmp"); run("foo"); - fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + rfs::rename("bar.tmp", dynamic_lib_name("bar")); // The first explicit usage of extern overrides the second pathless --extern bar. rustc() @@ -31,13 +31,13 @@ fn main() { .arg("--extern") .arg("bar") .run(); - fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + rfs::rename(dynamic_lib_name("bar"), "bar.tmp"); run_fail("foo"); - fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + rfs::rename("bar.tmp", dynamic_lib_name("bar")); // With prefer-dynamic, execution fails as it refuses to use the rlib. rustc().input("foo.rs").arg("--extern").arg("bar").arg("-Cprefer-dynamic").run(); - fs_wrapper::rename(dynamic_lib_name("bar"), "bar.tmp"); + rfs::rename(dynamic_lib_name("bar"), "bar.tmp"); run_fail("foo"); - fs_wrapper::rename("bar.tmp", dynamic_lib_name("bar")); + rfs::rename("bar.tmp", dynamic_lib_name("bar")); } diff --git a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs index c39e397a7cb35..d7b865f816992 100644 --- a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs +++ b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs @@ -7,7 +7,7 @@ // See https://github.com/rust-lang/rust/pull/15686 use run_make_support::{ - bin_name, cwd, fs_wrapper, has_prefix, has_suffix, rustc, shallow_find_files, + bin_name, cwd, fs as rfs, has_prefix, has_suffix, rustc, shallow_find_files, }; fn main() { @@ -16,6 +16,6 @@ fn main() { has_prefix(path, "foobar.foo") && has_suffix(path, "0.rcgu.o") }); let object_file = object_files.get(0).unwrap(); - fs_wrapper::remove_file(object_file); - fs_wrapper::remove_file(bin_name("foobar")); + rfs::remove_file(object_file); + rfs::remove_file(bin_name("foobar")); } diff --git a/tests/run-make/ice-dep-cannot-find-dep/rmake.rs b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs index 33c755bddd7bf..b4210eb5f3bc0 100644 --- a/tests/run-make/ice-dep-cannot-find-dep/rmake.rs +++ b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs @@ -16,7 +16,7 @@ // If we used `rustc` the additional '-L rmake_out' option would allow rustc to // actually find the crate. -use run_make_support::{bare_rustc, fs_wrapper, rust_lib_name, rustc}; +use run_make_support::{bare_rustc, fs as rfs, rust_lib_name, rustc}; fn main() { rustc().crate_name("a").crate_type("rlib").input("a.rs").arg("--verbose").run(); diff --git a/tests/run-make/inaccessible-temp-dir/rmake.rs b/tests/run-make/inaccessible-temp-dir/rmake.rs index 62b8479c32881..4fbd207975c5c 100644 --- a/tests/run-make/inaccessible-temp-dir/rmake.rs +++ b/tests/run-make/inaccessible-temp-dir/rmake.rs @@ -24,11 +24,11 @@ // Reason: `set_readonly` has no effect on directories // and does not prevent modification. -use run_make_support::{fs_wrapper, rustc, test_while_readonly}; +use run_make_support::{fs as rfs, rustc, test_while_readonly}; fn main() { // Create an inaccessible directory. - fs_wrapper::create_dir("inaccessible"); + rfs::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`. diff --git a/tests/run-make/incr-prev-body-beyond-eof/rmake.rs b/tests/run-make/incr-prev-body-beyond-eof/rmake.rs index e6d6ae95aaaf6..ae74f120ce39b 100644 --- a/tests/run-make/incr-prev-body-beyond-eof/rmake.rs +++ b/tests/run-make/incr-prev-body-beyond-eof/rmake.rs @@ -13,14 +13,14 @@ //@ ignore-nvptx64-nvidia-cuda // FIXME: can't find crate for `std` -use run_make_support::fs_wrapper as fs; +use run_make_support::fs as rfs; use run_make_support::rustc; fn main() { - fs::create_dir("src"); - fs::create_dir("incr"); - fs::copy("a.rs", "src/main.rs"); + rfs::create_dir("src"); + rfs::create_dir("incr"); + rfs::copy("a.rs", "src/main.rs"); rustc().incremental("incr").input("src/main.rs").run(); - fs::copy("b.rs", "src/main.rs"); + rfs::copy("b.rs", "src/main.rs"); rustc().incremental("incr").input("src/main.rs").run(); } diff --git a/tests/run-make/incr-test-moved-file/rmake.rs b/tests/run-make/incr-test-moved-file/rmake.rs index ae142a0d22e86..c4fc3d37526e0 100644 --- a/tests/run-make/incr-test-moved-file/rmake.rs +++ b/tests/run-make/incr-test-moved-file/rmake.rs @@ -14,14 +14,14 @@ //@ ignore-nvptx64-nvidia-cuda // FIXME: can't find crate for 'std' -use run_make_support::{fs_wrapper, rust_lib_name, rustc}; +use run_make_support::{fs as rfs, rust_lib_name, rustc}; fn main() { - fs_wrapper::create_dir("incr"); - fs_wrapper::create_dir("src"); - fs_wrapper::create_dir("src/mydir"); - fs_wrapper::copy("main.rs", "src/main.rs"); + rfs::create_dir("incr"); + rfs::create_dir("src"); + rfs::create_dir("src/mydir"); + rfs::copy("main.rs", "src/main.rs"); rustc().input("src/main.rs").incremental("incr").arg("--test").run(); - fs_wrapper::rename("src/main.rs", "src/mydir/main.rs"); + rfs::rename("src/main.rs", "src/mydir/main.rs"); rustc().input("src/mydir/main.rs").incremental("incr").arg("--test").run(); } diff --git a/tests/run-make/incremental-debugger-visualizer/rmake.rs b/tests/run-make/incremental-debugger-visualizer/rmake.rs index 1ef3af873530e..da9f9d41ee81e 100644 --- a/tests/run-make/incremental-debugger-visualizer/rmake.rs +++ b/tests/run-make/incremental-debugger-visualizer/rmake.rs @@ -2,14 +2,14 @@ // (in this case, foo.py and foo.natvis) are picked up when compiling incrementally. // See https://github.com/rust-lang/rust/pull/111641 -use run_make_support::{fs_wrapper, invalid_utf8_contains, invalid_utf8_not_contains, rustc}; +use run_make_support::{fs as rfs, invalid_utf8_contains, invalid_utf8_not_contains, rustc}; use std::io::Read; fn main() { - fs_wrapper::create_file("foo.py"); - fs_wrapper::write("foo.py", "GDB script v1"); - fs_wrapper::create_file("foo.natvis"); - fs_wrapper::write("foo.natvis", "Natvis v1"); + rfs::create_file("foo.py"); + rfs::write("foo.py", "GDB script v1"); + rfs::create_file("foo.natvis"); + rfs::write("foo.natvis", "Natvis v1"); rustc() .input("foo.rs") .crate_type("rlib") @@ -22,9 +22,9 @@ fn main() { invalid_utf8_contains("libfoo.rmeta", "Natvis v1"); // Change only the GDB script and check that the change has been picked up - fs_wrapper::remove_file("foo.py"); - fs_wrapper::create_file("foo.py"); - fs_wrapper::write("foo.py", "GDB script v2"); + rfs::remove_file("foo.py"); + rfs::create_file("foo.py"); + rfs::write("foo.py", "GDB script v2"); rustc() .input("foo.rs") .crate_type("rlib") @@ -38,9 +38,9 @@ fn main() { invalid_utf8_contains("libfoo.rmeta", "Natvis v1"); // Now change the Natvis version and check that the change has been picked up - fs_wrapper::remove_file("foo.natvis"); - fs_wrapper::create_file("foo.natvis"); - fs_wrapper::write("foo.natvis", "Natvis v2"); + rfs::remove_file("foo.natvis"); + rfs::create_file("foo.natvis"); + rfs::write("foo.natvis", "Natvis v2"); rustc() .input("foo.rs") .crate_type("rlib") diff --git a/tests/run-make/incremental-session-fail/rmake.rs b/tests/run-make/incremental-session-fail/rmake.rs index 0283709f2cf8c..22ff1e2a8a4d7 100644 --- a/tests/run-make/incremental-session-fail/rmake.rs +++ b/tests/run-make/incremental-session-fail/rmake.rs @@ -4,10 +4,10 @@ // the ensuing compilation failure is not an ICE. // See https://github.com/rust-lang/rust/pull/85698 -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { - fs_wrapper::create_file("session"); + rfs::create_file("session"); // rustc should fail to create the session directory here. let out = rustc().input("foo.rs").crate_type("rlib").incremental("session").run_fail(); out.assert_stderr_contains("could not create incremental compilation crate directory"); diff --git a/tests/run-make/inline-always-many-cgu/rmake.rs b/tests/run-make/inline-always-many-cgu/rmake.rs index c55ea69f3b908..3b51bb1cd81a6 100644 --- a/tests/run-make/inline-always-many-cgu/rmake.rs +++ b/tests/run-make/inline-always-many-cgu/rmake.rs @@ -1,6 +1,6 @@ -use run_make_support::fs_wrapper::read_to_string; +use run_make_support::fs as rfs; use run_make_support::regex::Regex; -use run_make_support::{read_dir, rustc}; +use run_make_support::rustc; use std::ffi::OsStr; @@ -8,9 +8,9 @@ fn main() { rustc().input("foo.rs").emit("llvm-ir").codegen_units(2).run(); let re = Regex::new(r"\bcall\b").unwrap(); let mut nb_ll = 0; - read_dir(".", |path| { + rfs::read_dir_entries(".", |path| { if path.is_file() && path.extension().is_some_and(|ext| ext == OsStr::new("ll")) { - assert!(!re.is_match(&read_to_string(path))); + assert!(!re.is_match(&rfs::read_to_string(path))); nb_ll += 1; } }); diff --git a/tests/run-make/intrinsic-unreachable/rmake.rs b/tests/run-make/intrinsic-unreachable/rmake.rs index 7e78c8288b821..34f7ab3fbc8a9 100644 --- a/tests/run-make/intrinsic-unreachable/rmake.rs +++ b/tests/run-make/intrinsic-unreachable/rmake.rs @@ -8,13 +8,13 @@ //@ ignore-windows // Reason: Because of Windows exception handling, the code is not necessarily any shorter. -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { rustc().opt().emit("asm").input("exit-ret.rs").run(); rustc().opt().emit("asm").input("exit-unreachable.rs").run(); assert!( - fs_wrapper::read_to_string("exit-unreachable.s").lines().count() - < fs_wrapper::read_to_string("exit-ret.s").lines().count() + rfs::read_to_string("exit-unreachable.s").lines().count() + < rfs::read_to_string("exit-ret.s").lines().count() ); } diff --git a/tests/run-make/invalid-library/rmake.rs b/tests/run-make/invalid-library/rmake.rs index 9ebab1c8b0f09..3961e2b846bd4 100644 --- a/tests/run-make/invalid-library/rmake.rs +++ b/tests/run-make/invalid-library/rmake.rs @@ -4,11 +4,11 @@ // one appearing in stderr in this scenario. // See https://github.com/rust-lang/rust/pull/12645 -use run_make_support::fs_wrapper::create_file; +use run_make_support::fs as rfs; use run_make_support::{llvm_ar, rustc}; fn main() { - create_file("lib.rmeta"); + rfs::create_file("lib.rmeta"); llvm_ar().obj_to_ar().output_input("libfoo-ffffffff-1.0.rlib", "lib.rmeta").run(); rustc().input("foo.rs").run_fail().assert_stderr_contains("found invalid metadata"); } diff --git a/tests/run-make/invalid-so/rmake.rs b/tests/run-make/invalid-so/rmake.rs index 5cfda05334eb1..c79e0563bada4 100644 --- a/tests/run-make/invalid-so/rmake.rs +++ b/tests/run-make/invalid-so/rmake.rs @@ -4,10 +4,10 @@ // explains that the file exists, but that its metadata is incorrect. // See https://github.com/rust-lang/rust/pull/88368 -use run_make_support::{dynamic_lib_name, fs_wrapper, rustc}; +use run_make_support::{dynamic_lib_name, fs as rfs, rustc}; fn main() { - fs_wrapper::create_file(dynamic_lib_name("foo")); + rfs::create_file(dynamic_lib_name("foo")); rustc() .crate_type("lib") .extern_("foo", dynamic_lib_name("foo")) diff --git a/tests/run-make/invalid-staticlib/rmake.rs b/tests/run-make/invalid-staticlib/rmake.rs index 451292932477c..e31dcdec95bd6 100644 --- a/tests/run-make/invalid-staticlib/rmake.rs +++ b/tests/run-make/invalid-staticlib/rmake.rs @@ -4,10 +4,10 @@ // an internal compiler error (ICE). // See https://github.com/rust-lang/rust/pull/28673 -use run_make_support::{fs_wrapper, rustc, static_lib_name}; +use run_make_support::{fs as rfs, rustc, static_lib_name}; fn main() { - fs_wrapper::create_file(static_lib_name("foo")); + rfs::create_file(static_lib_name("foo")); rustc() .arg("-") .crate_type("rlib") diff --git a/tests/run-make/issue-107495-archive-permissions/rmake.rs b/tests/run-make/issue-107495-archive-permissions/rmake.rs index ee281fe0a5f0b..78d57d57afbed 100644 --- a/tests/run-make/issue-107495-archive-permissions/rmake.rs +++ b/tests/run-make/issue-107495-archive-permissions/rmake.rs @@ -3,7 +3,7 @@ #[cfg(unix)] extern crate libc; -use run_make_support::{aux_build, fs_wrapper}; +use run_make_support::{aux_build, fs as rfs}; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; @@ -20,7 +20,7 @@ fn main() { } fn verify(path: &Path) { - let perm = fs_wrapper::metadata(path).permissions(); + let perm = rfs::metadata(path).permissions(); assert!(!perm.readonly()); diff --git a/tests/run-make/ls-metadata/rmake.rs b/tests/run-make/ls-metadata/rmake.rs index 0e60f2c46787a..8a2d79ed3af31 100644 --- a/tests/run-make/ls-metadata/rmake.rs +++ b/tests/run-make/ls-metadata/rmake.rs @@ -6,12 +6,12 @@ //@ ignore-cross-compile -use run_make_support::fs_wrapper; +use run_make_support::fs as rfs; use run_make_support::rustc; fn main() { rustc().input("foo.rs").run(); rustc().arg("-Zls=root").input("foo").run(); - fs_wrapper::create_file("bar"); + rfs::create_file("bar"); rustc().arg("-Zls=root").input("bar").run(); } diff --git a/tests/run-make/lto-readonly-lib/rmake.rs b/tests/run-make/lto-readonly-lib/rmake.rs index 9eb135addd9ec..5e06aeb73b601 100644 --- a/tests/run-make/lto-readonly-lib/rmake.rs +++ b/tests/run-make/lto-readonly-lib/rmake.rs @@ -7,7 +7,7 @@ //@ ignore-cross-compile -use run_make_support::fs_wrapper; +use run_make_support::fs as rfs; use run_make_support::{run, rust_lib_name, rustc, test_while_readonly}; fn main() { diff --git a/tests/run-make/many-crates-but-no-match/rmake.rs b/tests/run-make/many-crates-but-no-match/rmake.rs index ea4f166b2bd99..7f8f93346d793 100644 --- a/tests/run-make/many-crates-but-no-match/rmake.rs +++ b/tests/run-make/many-crates-but-no-match/rmake.rs @@ -4,12 +4,12 @@ // what should be done to fix the issue. // See https://github.com/rust-lang/rust/issues/13266 -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { - fs_wrapper::create_dir("a1"); - fs_wrapper::create_dir("a2"); - fs_wrapper::create_dir("a3"); + rfs::create_dir("a1"); + rfs::create_dir("a2"); + rfs::create_dir("a3"); rustc().crate_type("rlib").out_dir("a1").input("crateA1.rs").run(); rustc().crate_type("rlib").library_search_path("a1").input("crateB.rs").run(); rustc().crate_type("rlib").out_dir("a2").input("crateA2.rs").run(); diff --git a/tests/run-make/mixing-libs/rmake.rs b/tests/run-make/mixing-libs/rmake.rs index 06ef6ab00f5f8..6799a93fbc125 100644 --- a/tests/run-make/mixing-libs/rmake.rs +++ b/tests/run-make/mixing-libs/rmake.rs @@ -6,7 +6,7 @@ //@ ignore-cross-compile -use run_make_support::{dynamic_lib_name, fs_wrapper, rustc}; +use run_make_support::{dynamic_lib_name, fs as rfs, rustc}; fn main() { rustc().input("rlib.rs").crate_type("rlib").crate_type("dylib").run(); @@ -16,6 +16,6 @@ fn main() { // librlib's dynamic version needs to be removed here to prevent prog.rs from fetching // the wrong one. - fs_wrapper::remove_file(dynamic_lib_name("rlib")); + rfs::remove_file(dynamic_lib_name("rlib")); rustc().input("prog.rs").run_fail(); } diff --git a/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs index c642602998922..2fd6022706461 100644 --- a/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs +++ b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs @@ -17,20 +17,20 @@ //@ ignore-nvptx64-nvidia-cuda // FIXME: can't find crate for 'std' -use run_make_support::{fs_wrapper, rust_lib_name, rustc}; +use run_make_support::{fs as rfs, rust_lib_name, rustc}; fn main() { - fs_wrapper::create_dir("incr"); - fs_wrapper::create_dir("first_src"); - fs_wrapper::create_dir("output"); - fs_wrapper::rename("my_lib.rs", "first_src/my_lib.rs"); - fs_wrapper::rename("main.rs", "first_src/main.rs"); + rfs::create_dir("incr"); + rfs::create_dir("first_src"); + rfs::create_dir("output"); + rfs::rename("my_lib.rs", "first_src/my_lib.rs"); + rfs::rename("main.rs", "first_src/main.rs"); // Build from "first_src" std::env::set_current_dir("first_src").unwrap(); rustc().input("my_lib.rs").incremental("incr").crate_type("lib").run(); rustc().input("main.rs").incremental("incr").extern_("my_lib", rust_lib_name("my_lib")).run(); std::env::set_current_dir("..").unwrap(); - fs_wrapper::rename("first_src", "second_src"); + rfs::rename("first_src", "second_src"); std::env::set_current_dir("second_src").unwrap(); // Build from "second_src" - the output and incremental directory remain identical rustc().input("my_lib.rs").incremental("incr").crate_type("lib").run(); diff --git a/tests/run-make/non-unicode-env/rmake.rs b/tests/run-make/non-unicode-env/rmake.rs index bffd9477f8fe2..f23fef88dabc5 100644 --- a/tests/run-make/non-unicode-env/rmake.rs +++ b/tests/run-make/non-unicode-env/rmake.rs @@ -1,4 +1,4 @@ -use run_make_support::fs_wrapper; +use run_make_support::fs as rfs; use run_make_support::rustc; fn main() { @@ -7,6 +7,6 @@ fn main() { #[cfg(windows)] let non_unicode: std::ffi::OsString = std::os::windows::ffi::OsStringExt::from_wide(&[0xD800]); let output = rustc().input("non_unicode_env.rs").env("NON_UNICODE_VAR", non_unicode).run_fail(); - let expected = fs_wrapper::read_to_string("non_unicode_env.stderr"); + let expected = rfs::read_to_string("non_unicode_env.stderr"); output.assert_stderr_equals(expected); } diff --git a/tests/run-make/non-unicode-in-incremental-dir/rmake.rs b/tests/run-make/non-unicode-in-incremental-dir/rmake.rs index 895d9e00a2d45..d0d730d17ebb5 100644 --- a/tests/run-make/non-unicode-in-incremental-dir/rmake.rs +++ b/tests/run-make/non-unicode-in-incremental-dir/rmake.rs @@ -1,4 +1,4 @@ -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { #[cfg(unix)] @@ -17,8 +17,8 @@ fn main() { } let incr_dir = "incr-dir"; rustc().input("foo.rs").incremental(&incr_dir).run(); - for crate_dir in fs_wrapper::read_dir(&incr_dir) { - fs_wrapper::create_dir(crate_dir.unwrap().path().join(&non_unicode)); + for crate_dir in rfs::read_dir(&incr_dir) { + rfs::create_dir(crate_dir.unwrap().path().join(&non_unicode)); } rustc().input("foo.rs").incremental(&incr_dir).run(); } diff --git a/tests/run-make/obey-crate-type-flag/rmake.rs b/tests/run-make/obey-crate-type-flag/rmake.rs index 8aa78cccbb23b..198eb6931589e 100644 --- a/tests/run-make/obey-crate-type-flag/rmake.rs +++ b/tests/run-make/obey-crate-type-flag/rmake.rs @@ -6,7 +6,7 @@ //@ ignore-cross-compile use run_make_support::{ - cwd, dynamic_lib_name, fs_wrapper, has_extension, rust_lib_name, rustc, shallow_find_files, + cwd, dynamic_lib_name, fs as rfs, has_extension, rust_lib_name, rustc, shallow_find_files, }; use std::path::Path; @@ -15,7 +15,7 @@ fn main() { assert!(Path::new(&dynamic_lib_name("test")).exists()); assert!(Path::new(&rust_lib_name("test")).exists()); - fs_wrapper::remove_file(rust_lib_name("test")); + rfs::remove_file(rust_lib_name("test")); rustc().crate_type("dylib").input("test.rs").run(); assert!(shallow_find_files(cwd(), |path| { has_extension(path, "rlib") }).is_empty()); } diff --git a/tests/run-make/output-filename-conflicts-with-directory/rmake.rs b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs index 4b5c9e8d1187d..6df9628a9fb73 100644 --- a/tests/run-make/output-filename-conflicts-with-directory/rmake.rs +++ b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs @@ -4,10 +4,10 @@ // potentially-confusing linker error. // See https://github.com/rust-lang/rust/pull/47203 -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { - fs_wrapper::create_dir("foo"); + rfs::create_dir("foo"); rustc().input("foo.rs").output("foo").run_fail().assert_stderr_contains( r#"the generated executable for the input file "foo.rs" conflicts with the existing directory "foo""#, ); diff --git a/tests/run-make/output-filename-overwrites-input/rmake.rs b/tests/run-make/output-filename-overwrites-input/rmake.rs index c6055e818a175..0e9c20b0468fb 100644 --- a/tests/run-make/output-filename-overwrites-input/rmake.rs +++ b/tests/run-make/output-filename-overwrites-input/rmake.rs @@ -4,14 +4,14 @@ //@ ignore-cross-compile -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { - fs_wrapper::copy("foo.rs", "foo"); + rfs::copy("foo.rs", "foo"); rustc().input("foo").output("foo").run_fail().assert_stderr_contains( r#"the input file "foo" would be overwritten by the generated executable"#, ); - fs_wrapper::copy("bar.rs", "bar.rlib"); + rfs::copy("bar.rs", "bar.rlib"); rustc().input("bar.rlib").output("bar.rlib").run_fail().assert_stderr_contains( r#"the input file "bar.rlib" would be overwritten by the generated executable"#, ); diff --git a/tests/run-make/output-type-permutations/rmake.rs b/tests/run-make/output-type-permutations/rmake.rs index 1d1637a744ec0..a4d2601260b49 100644 --- a/tests/run-make/output-type-permutations/rmake.rs +++ b/tests/run-make/output-type-permutations/rmake.rs @@ -5,7 +5,7 @@ // See https://github.com/rust-lang/rust/pull/12020 use run_make_support::{ - bin_name, dynamic_lib_name, filename_not_in_denylist, fs_wrapper, rust_lib_name, rustc, + bin_name, dynamic_lib_name, filename_not_in_denylist, fs as rfs, rust_lib_name, rustc, shallow_find_files, static_lib_name, }; use std::path::PathBuf; @@ -20,10 +20,10 @@ fn assert_expected_output_files(expectations: Expectations, rustc_invocation: im let Expectations { expected_files: must_exist, allowed_files: can_exist, test_dir: dir } = expectations; - fs_wrapper::create_dir(&dir); + rfs::create_dir(&dir); rustc_invocation(); for file in must_exist { - fs_wrapper::remove_file(PathBuf::from(&dir).join(&file)); + rfs::remove_file(PathBuf::from(&dir).join(&file)); } let actual_output_files = shallow_find_files(dir, |path| filename_not_in_denylist(path, &can_exist)); @@ -526,17 +526,14 @@ fn main() { test_dir: "rlib-emits".to_string(), }, || { - fs_wrapper::rename("staticlib-all3/bar.bc", "rlib-emits/foo.bc"); + rfs::rename("staticlib-all3/bar.bc", "rlib-emits/foo.bc"); rustc() .input("foo.rs") .emit("llvm-bc,link") .crate_type("rlib") .out_dir("rlib-emits") .run(); - assert_eq!( - fs_wrapper::read("rlib-emits/foo.bc"), - fs_wrapper::read("rlib-emits/bar.bc") - ); + assert_eq!(rfs::read("rlib-emits/foo.bc"), rfs::read("rlib-emits/bar.bc")); }, ); } diff --git a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs index 3f032cf3762a9..9c224ad05b21b 100644 --- a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs +++ b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs @@ -5,12 +5,12 @@ // 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 run_make_support::{fs as rfs, rustc}; use std::sync::{Arc, Barrier}; use std::thread; fn main() { - fs_wrapper::create_file("lib.rs"); + rfs::create_file("lib.rs"); let barrier = Arc::new(Barrier::new(2)); let handle = { let barrier = Arc::clone(&barrier); diff --git a/tests/run-make/pgo-branch-weights/rmake.rs b/tests/run-make/pgo-branch-weights/rmake.rs index d3cb79c39afa9..0915fe0e2a299 100644 --- a/tests/run-make/pgo-branch-weights/rmake.rs +++ b/tests/run-make/pgo-branch-weights/rmake.rs @@ -10,14 +10,14 @@ //@ needs-profiler-support //@ ignore-cross-compile -use run_make_support::{fs_wrapper, llvm_filecheck, llvm_profdata, run_with_args, rustc}; +use run_make_support::{fs as rfs, llvm_filecheck, llvm_profdata, run_with_args, rustc}; use std::path::Path; fn main() { let path_prof_data_dir = Path::new("prof_data_dir"); let path_merged_profdata = path_prof_data_dir.join("merged.profdata"); rustc().input("opaque.rs").run(); - fs_wrapper::create_dir_all(&path_prof_data_dir); + rfs::create_dir_all(&path_prof_data_dir); rustc() .input("interesting.rs") .profile_generate(&path_prof_data_dir) @@ -34,8 +34,5 @@ fn main() { .codegen_units(1) .emit("llvm-ir") .run(); - llvm_filecheck() - .patterns("filecheck-patterns.txt") - .stdin(fs_wrapper::read("interesting.ll")) - .run(); + llvm_filecheck().patterns("filecheck-patterns.txt").stdin(rfs::read("interesting.ll")).run(); } diff --git a/tests/run-make/pgo-use/rmake.rs b/tests/run-make/pgo-use/rmake.rs index 0f76aff80d0ca..f53ea79102cbb 100644 --- a/tests/run-make/pgo-use/rmake.rs +++ b/tests/run-make/pgo-use/rmake.rs @@ -9,8 +9,8 @@ //@ ignore-cross-compile use run_make_support::{ - cwd, fs_wrapper, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args, - rustc, shallow_find_files, + cwd, fs as rfs, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args, rustc, + shallow_find_files, }; fn main() { @@ -47,7 +47,7 @@ fn main() { // line with the function name before the line with the function attributes. // FileCheck only supports checking that something matches on the next line, // but not if something matches on the previous line. - let ir = fs_wrapper::read_to_string("main.ll"); + let ir = rfs::read_to_string("main.ll"); let lines: Vec<_> = ir.lines().rev().collect(); let mut reversed_ir = lines.join("\n"); reversed_ir.push('\n'); diff --git a/tests/run-make/prefer-dylib/rmake.rs b/tests/run-make/prefer-dylib/rmake.rs index 6b3b3ad6d3b8a..0fed3e8725956 100644 --- a/tests/run-make/prefer-dylib/rmake.rs +++ b/tests/run-make/prefer-dylib/rmake.rs @@ -1,6 +1,6 @@ //@ ignore-cross-compile -use run_make_support::{cwd, dynamic_lib_name, fs_wrapper, read_dir, run, run_fail, rustc}; +use run_make_support::{dynamic_lib_name, fs as rfs, run, run_fail, rustc}; fn main() { rustc().input("bar.rs").crate_type("dylib").crate_type("rlib").arg("-Cprefer-dynamic").run(); @@ -8,7 +8,7 @@ fn main() { run("foo"); - fs_wrapper::remove_file(dynamic_lib_name("bar")); + rfs::remove_file(dynamic_lib_name("bar")); // This time the command should fail. run_fail("foo"); } diff --git a/tests/run-make/prefer-rlib/rmake.rs b/tests/run-make/prefer-rlib/rmake.rs index 96861a264e621..188db7c06028f 100644 --- a/tests/run-make/prefer-rlib/rmake.rs +++ b/tests/run-make/prefer-rlib/rmake.rs @@ -3,13 +3,13 @@ //@ ignore-cross-compile -use run_make_support::{dynamic_lib_name, fs_wrapper, path, run, rust_lib_name, rustc}; +use run_make_support::{dynamic_lib_name, fs as rfs, path, run, rust_lib_name, rustc}; fn main() { rustc().input("bar.rs").crate_type("dylib").crate_type("rlib").run(); assert!(path(rust_lib_name("bar")).exists()); rustc().input("foo.rs").run(); - fs_wrapper::remove_file(rust_lib_name("bar")); - fs_wrapper::remove_file(dynamic_lib_name("bar")); + rfs::remove_file(rust_lib_name("bar")); + rfs::remove_file(dynamic_lib_name("bar")); run("foo"); } diff --git a/tests/run-make/pretty-print-with-dep-file/rmake.rs b/tests/run-make/pretty-print-with-dep-file/rmake.rs index 859a9781bb6e6..4b3d1c34faea1 100644 --- a/tests/run-make/pretty-print-with-dep-file/rmake.rs +++ b/tests/run-make/pretty-print-with-dep-file/rmake.rs @@ -5,13 +5,13 @@ // does not get an unexpected dep-info file. // See https://github.com/rust-lang/rust/issues/112898 -use run_make_support::{fs_wrapper, invalid_utf8_contains, rustc}; +use run_make_support::{fs as rfs, invalid_utf8_contains, rustc}; use std::path::Path; fn main() { rustc().emit("dep-info").arg("-Zunpretty=expanded").input("with-dep.rs").run(); invalid_utf8_contains("with-dep.d", "with-dep.rs"); - fs_wrapper::remove_file("with-dep.d"); + rfs::remove_file("with-dep.d"); rustc().emit("dep-info").arg("-Zunpretty=normal").input("with-dep.rs").run(); assert!(!Path::new("with-dep.d").exists()); } diff --git a/tests/run-make/print-cfg/rmake.rs b/tests/run-make/print-cfg/rmake.rs index d11eda1db2aed..73a03189cb241 100644 --- a/tests/run-make/print-cfg/rmake.rs +++ b/tests/run-make/print-cfg/rmake.rs @@ -10,7 +10,7 @@ use std::ffi::OsString; use std::iter::FromIterator; use std::path::PathBuf; -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; struct PrintCfg { target: &'static str, @@ -96,7 +96,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) { rustc().target(target).arg(print_arg).run(); - let output = fs_wrapper::read_to_string(&tmp_path); + let output = rfs::read_to_string(&tmp_path); check_(&output, includes, disallow); } diff --git a/tests/run-make/print-to-output/rmake.rs b/tests/run-make/print-to-output/rmake.rs index 66f62a7015aba..ecfd84f81bb3f 100644 --- a/tests/run-make/print-to-output/rmake.rs +++ b/tests/run-make/print-to-output/rmake.rs @@ -4,7 +4,7 @@ use std::ffi::OsString; use std::path::PathBuf; -use run_make_support::{fs_wrapper, rustc, target}; +use run_make_support::{fs as rfs, rustc, target}; struct Option<'a> { target: &'a str, @@ -49,7 +49,7 @@ fn check(args: Option) { rustc().target(args.target).arg(print_arg).run(); - fs_wrapper::read_to_string(&tmp_path) + rfs::read_to_string(&tmp_path) }; check_(&stdout, args.includes); diff --git a/tests/run-make/remap-path-prefix/rmake.rs b/tests/run-make/remap-path-prefix/rmake.rs index 62c0368e4b3a4..390db93e62d17 100644 --- a/tests/run-make/remap-path-prefix/rmake.rs +++ b/tests/run-make/remap-path-prefix/rmake.rs @@ -4,7 +4,7 @@ // See https://github.com/rust-lang/rust/pull/85344 use run_make_support::bstr::ByteSlice; -use run_make_support::{bstr, fs_wrapper, is_darwin, rustc}; +use run_make_support::{bstr, fs as rfs, is_darwin, rustc}; fn main() { let mut out_simple = rustc(); @@ -60,12 +60,9 @@ fn main() { // helper functions. fn rmeta_contains(expected: &str) { // Normalize to account for path differences in Windows. - if !bstr::BString::from(fs_wrapper::read("liblib.rmeta")) - .replace(b"\\", b"/") - .contains_str(expected) - { + if !bstr::BString::from(rfs::read("liblib.rmeta")).replace(b"\\", b"/").contains_str(expected) { eprintln!("=== FILE CONTENTS (LOSSY) ==="); - eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); + eprintln!("{}", String::from_utf8_lossy(&rfs::read("liblib.rmeta"))); eprintln!("=== SPECIFIED TEXT ==="); eprintln!("{}", expected); panic!("specified text was not found in file"); @@ -74,12 +71,9 @@ fn rmeta_contains(expected: &str) { fn rmeta_not_contains(expected: &str) { // Normalize to account for path differences in Windows. - if bstr::BString::from(fs_wrapper::read("liblib.rmeta")) - .replace(b"\\", b"/") - .contains_str(expected) - { + if bstr::BString::from(rfs::read("liblib.rmeta")).replace(b"\\", b"/").contains_str(expected) { eprintln!("=== FILE CONTENTS (LOSSY) ==="); - eprintln!("{}", String::from_utf8_lossy(&fs_wrapper::read("liblib.rmeta"))); + eprintln!("{}", String::from_utf8_lossy(&rfs::read("liblib.rmeta"))); eprintln!("=== SPECIFIED TEXT ==="); eprintln!("{}", expected); panic!("specified text was not found in file"); diff --git a/tests/run-make/repr128-dwarf/rmake.rs b/tests/run-make/repr128-dwarf/rmake.rs index a65cf234edffe..1c61698ffcd4e 100644 --- a/tests/run-make/repr128-dwarf/rmake.rs +++ b/tests/run-make/repr128-dwarf/rmake.rs @@ -3,7 +3,7 @@ use gimli::{AttributeValue, EndianRcSlice, Reader, RunTimeEndian}; use object::{Object, ObjectSection}; -use run_make_support::{fs_wrapper, gimli, object, rustc}; +use run_make_support::{fs as rfs, gimli, object, rustc}; use std::collections::HashMap; use std::path::PathBuf; use std::rc::Rc; @@ -19,7 +19,7 @@ fn main() { .join("DWARF") .join("repr128"); let output = - fs_wrapper::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output }); + rfs::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output }); let obj = object::File::parse(output.as_slice()).unwrap(); let endian = if obj.is_little_endian() { RunTimeEndian::Little } else { RunTimeEndian::Big }; let dwarf = gimli::Dwarf::load(|section| -> Result<_, ()> { diff --git a/tests/run-make/reset-codegen-1/rmake.rs b/tests/run-make/reset-codegen-1/rmake.rs index 19d42b3d6d5ec..18cf5513d5c02 100644 --- a/tests/run-make/reset-codegen-1/rmake.rs +++ b/tests/run-make/reset-codegen-1/rmake.rs @@ -7,7 +7,7 @@ //@ ignore-cross-compile -use run_make_support::{bin_name, fs_wrapper, rustc}; +use run_make_support::{bin_name, fs as rfs, rustc}; use std::path::Path; fn compile(output_file: &str, emit: Option<&str>) { diff --git a/tests/run-make/resolve-rename/rmake.rs b/tests/run-make/resolve-rename/rmake.rs index 09bd4165b2a5d..cefd608177d7f 100644 --- a/tests/run-make/resolve-rename/rmake.rs +++ b/tests/run-make/resolve-rename/rmake.rs @@ -5,12 +5,12 @@ // the renamed library. // See https://github.com/rust-lang/rust/pull/49253 -use run_make_support::fs_wrapper; +use run_make_support::fs as rfs; use run_make_support::rustc; fn main() { rustc().extra_filename("-hash").input("foo.rs").run(); rustc().input("bar.rs").run(); - fs_wrapper::rename("libfoo-hash.rlib", "libfoo-another-hash.rlib"); + rfs::rename("libfoo-hash.rlib", "libfoo-another-hash.rlib"); rustc().input("baz.rs").run(); } diff --git a/tests/run-make/rlib-chain/rmake.rs b/tests/run-make/rlib-chain/rmake.rs index 0947262bf6200..875de607a7b1d 100644 --- a/tests/run-make/rlib-chain/rmake.rs +++ b/tests/run-make/rlib-chain/rmake.rs @@ -8,7 +8,7 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -use run_make_support::{fs_wrapper, run, rust_lib_name, rustc}; +use run_make_support::{fs as rfs, run, rust_lib_name, rustc}; fn main() { rustc().input("m1.rs").run(); @@ -16,8 +16,8 @@ fn main() { rustc().input("m3.rs").run(); rustc().input("m4.rs").run(); run("m4"); - fs_wrapper::remove_file(rust_lib_name("m1")); - fs_wrapper::remove_file(rust_lib_name("m2")); - fs_wrapper::remove_file(rust_lib_name("m3")); + rfs::remove_file(rust_lib_name("m1")); + rfs::remove_file(rust_lib_name("m2")); + rfs::remove_file(rust_lib_name("m3")); run("m4"); } diff --git a/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs b/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs index 5d67ee2580fbc..e769274670649 100644 --- a/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs +++ b/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs @@ -1,10 +1,10 @@ -use run_make_support::{fs_wrapper, htmldocck, rustc, rustdoc, source_root}; +use run_make_support::{fs as rfs, htmldocck, rustc, rustdoc, source_root}; use std::path::Path; pub fn scrape(extra_args: &[&str]) { let out_dir = Path::new("rustdoc"); let crate_name = "foobar"; - let deps = fs_wrapper::read_dir("examples") + let deps = rfs::read_dir("examples") .filter_map(|entry| entry.ok().map(|e| e.path())) .filter(|path| path.is_file() && path.extension().is_some_and(|ext| ext == "rs")) .collect::>(); diff --git a/tests/run-make/rustdoc-test-args/rmake.rs b/tests/run-make/rustdoc-test-args/rmake.rs index 80eb768c14c60..57ff529d063d3 100644 --- a/tests/run-make/rustdoc-test-args/rmake.rs +++ b/tests/run-make/rustdoc-test-args/rmake.rs @@ -1,10 +1,10 @@ -use run_make_support::{fs_wrapper, rustdoc}; +use run_make_support::{fs as rfs, rustdoc}; use std::iter; use std::path::Path; fn generate_a_lot_of_cfgs(path: &Path) { let content = iter::repeat("--cfg=a\n").take(100_000).collect::(); - fs_wrapper::write(path, content.as_bytes()); + rfs::write(path, content.as_bytes()); } fn main() { diff --git a/tests/run-make/rustdoc-themes/rmake.rs b/tests/run-make/rustdoc-themes/rmake.rs index 4174c0552bea2..3a63ebbc20b53 100644 --- a/tests/run-make/rustdoc-themes/rmake.rs +++ b/tests/run-make/rustdoc-themes/rmake.rs @@ -1,15 +1,14 @@ // Test that rustdoc will properly load in a theme file and display it in the theme selector. -use run_make_support::{fs_wrapper, htmldocck, rustdoc, source_root}; +use run_make_support::{fs as rfs, htmldocck, rustdoc, source_root}; use std::path::Path; fn main() { let out_dir = Path::new("rustdoc-themes"); let test_css = "test.css"; - let no_script = fs_wrapper::read_to_string( - source_root().join("src/librustdoc/html/static/css/noscript.css"), - ); + let no_script = + rfs::read_to_string(source_root().join("src/librustdoc/html/static/css/noscript.css")); let mut test_content = String::new(); let mut found_begin_light = false; @@ -24,8 +23,8 @@ fn main() { } } assert!(!test_content.is_empty()); - fs_wrapper::create_dir_all(&out_dir); - fs_wrapper::write(&test_css, test_content); + rfs::create_dir_all(&out_dir); + rfs::write(&test_css, test_content); rustdoc().output(&out_dir).input("foo.rs").arg("--theme").arg(&test_css).run(); htmldocck().arg(out_dir).arg("foo.rs").run(); diff --git a/tests/run-make/rustdoc-verify-output-files/rmake.rs b/tests/run-make/rustdoc-verify-output-files/rmake.rs index 61dd97e09a916..efcc47079bd18 100644 --- a/tests/run-make/rustdoc-verify-output-files/rmake.rs +++ b/tests/run-make/rustdoc-verify-output-files/rmake.rs @@ -1,7 +1,7 @@ -use run_make_support::fs_wrapper::copy; +use run_make_support::fs as rfs; use std::path::{Path, PathBuf}; -use run_make_support::{assert_recursive_eq, copy_dir_all, rustdoc}; +use run_make_support::{assert_recursive_eq, rustdoc}; #[derive(PartialEq)] enum JsonOutput { @@ -26,7 +26,7 @@ fn main() { generate_docs(&out_dir, JsonOutput::No); // Copy first output for to check if it's exactly same after second compilation. - copy_dir_all(&out_dir, &tmp_out_dir); + rfs::copy_dir_all(&out_dir, &tmp_out_dir); // Generate html docs once again on same output. generate_docs(&out_dir, JsonOutput::No); @@ -38,7 +38,7 @@ fn main() { assert!(out_dir.join("foobar.json").is_file()); // Copy first json output to check if it's exactly same after second compilation. - copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")); + rfs::copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")); // Generate json doc on the same output. generate_docs(&out_dir, JsonOutput::Yes); diff --git a/tests/run-make/sepcomp-cci-copies/rmake.rs b/tests/run-make/sepcomp-cci-copies/rmake.rs index 612a73977feea..e05db252632cc 100644 --- a/tests/run-make/sepcomp-cci-copies/rmake.rs +++ b/tests/run-make/sepcomp-cci-copies/rmake.rs @@ -5,7 +5,7 @@ // See https://github.com/rust-lang/rust/pull/16367 use run_make_support::{ - count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc, + count_regex_matches_in_files_with_extension, cwd, fs as rfs, has_extension, regex, rustc, shallow_find_files, }; diff --git a/tests/run-make/sepcomp-inlining/rmake.rs b/tests/run-make/sepcomp-inlining/rmake.rs index de7551b9a512d..c3e28c4198e78 100644 --- a/tests/run-make/sepcomp-inlining/rmake.rs +++ b/tests/run-make/sepcomp-inlining/rmake.rs @@ -6,7 +6,7 @@ // See https://github.com/rust-lang/rust/pull/16367 use run_make_support::{ - count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc, + count_regex_matches_in_files_with_extension, cwd, fs as rfs, has_extension, regex, rustc, shallow_find_files, }; diff --git a/tests/run-make/sepcomp-separate/rmake.rs b/tests/run-make/sepcomp-separate/rmake.rs index 6f1d22424b5b9..83fcd9490ecce 100644 --- a/tests/run-make/sepcomp-separate/rmake.rs +++ b/tests/run-make/sepcomp-separate/rmake.rs @@ -4,7 +4,7 @@ // See https://github.com/rust-lang/rust/pull/16367 use run_make_support::{ - count_regex_matches_in_files_with_extension, cwd, fs_wrapper, has_extension, regex, rustc, + count_regex_matches_in_files_with_extension, cwd, fs as rfs, has_extension, regex, rustc, shallow_find_files, }; diff --git a/tests/run-make/silly-file-names/rmake.rs b/tests/run-make/silly-file-names/rmake.rs index 9df116146fec3..a883597e81c33 100644 --- a/tests/run-make/silly-file-names/rmake.rs +++ b/tests/run-make/silly-file-names/rmake.rs @@ -11,13 +11,13 @@ //@ ignore-windows // Reason: Windows refuses files with < and > in their names -use run_make_support::{diff, fs_wrapper, run, rustc}; +use run_make_support::{diff, fs as rfs, run, rustc}; fn main() { - fs_wrapper::create_file(""); - fs_wrapper::write("trailing-gt>", r#""comes from a file with a name that ends with >""#); + rfs::create_file(""); + rfs::write("trailing-gt>", r#""comes from a file with a name that ends with >""#); rustc().input("silly-file-names.rs").output("silly-file-names").run(); let out = run("silly-file-names").stdout_utf8(); diff().expected_file("silly-file-names.run.stdout").actual_text("actual-stdout", out).run(); diff --git a/tests/run-make/symlinked-extern/rmake.rs b/tests/run-make/symlinked-extern/rmake.rs index 9ed5b76edcbd6..cf69216d43174 100644 --- a/tests/run-make/symlinked-extern/rmake.rs +++ b/tests/run-make/symlinked-extern/rmake.rs @@ -11,12 +11,12 @@ //@ ignore-cross-compile //@ needs-symlink -use run_make_support::{create_symlink, cwd, fs_wrapper, rustc}; +use run_make_support::{cwd, fs as rfs, rustc}; fn main() { rustc().input("foo.rs").run(); - fs_wrapper::create_dir_all("other"); - create_symlink("libfoo.rlib", "other"); + rfs::create_dir_all("other"); + rfs::create_symlink("libfoo.rlib", "other"); rustc().input("bar.rs").library_search_path(cwd()).run(); rustc().input("baz.rs").extern_("foo", "other").library_search_path(cwd()).run(); } diff --git a/tests/run-make/symlinked-libraries/rmake.rs b/tests/run-make/symlinked-libraries/rmake.rs index 1d1dce5b5cfe8..eb4fc081f2bcf 100644 --- a/tests/run-make/symlinked-libraries/rmake.rs +++ b/tests/run-make/symlinked-libraries/rmake.rs @@ -8,11 +8,11 @@ //@ ignore-cross-compile //@ needs-symlink -use run_make_support::{create_symlink, dynamic_lib_name, fs_wrapper, rustc}; +use run_make_support::{dynamic_lib_name, fs as rfs, rustc}; fn main() { rustc().input("foo.rs").arg("-Cprefer-dynamic").run(); - fs_wrapper::create_dir_all("other"); - create_symlink(dynamic_lib_name("foo"), "other"); + rfs::create_dir_all("other"); + rfs::create_symlink(dynamic_lib_name("foo"), "other"); rustc().input("bar.rs").library_search_path("other").run(); } diff --git a/tests/run-make/symlinked-rlib/rmake.rs b/tests/run-make/symlinked-rlib/rmake.rs index 65ebb19142823..52dc9a153b87f 100644 --- a/tests/run-make/symlinked-rlib/rmake.rs +++ b/tests/run-make/symlinked-rlib/rmake.rs @@ -8,10 +8,10 @@ //@ ignore-cross-compile //@ needs-symlink -use run_make_support::{create_symlink, cwd, rustc}; +use run_make_support::{cwd, fs as rfs, rustc}; fn main() { rustc().input("foo.rs").crate_type("rlib").output("foo.xxx").run(); - create_symlink("foo.xxx", "libfoo.rlib"); + rfs::create_symlink("foo.xxx", "libfoo.rlib"); rustc().input("bar.rs").library_search_path(cwd()).run(); } diff --git a/tests/run-make/target-specs/rmake.rs b/tests/run-make/target-specs/rmake.rs index d2b5f65083808..dc8bac8ff9d71 100644 --- a/tests/run-make/target-specs/rmake.rs +++ b/tests/run-make/target-specs/rmake.rs @@ -5,11 +5,11 @@ // using them correctly, or fails with the right error message when using them improperly. // See https://github.com/rust-lang/rust/pull/16156 -use run_make_support::{diff, fs_wrapper, rustc}; +use run_make_support::{diff, fs as rfs, rustc}; fn main() { rustc().input("foo.rs").target("my-awesome-platform.json").crate_type("lib").emit("asm").run(); - assert!(!fs_wrapper::read_to_string("foo.s").contains("morestack")); + assert!(!rfs::read_to_string("foo.s").contains("morestack")); rustc() .input("foo.rs") .target("my-invalid-platform.json") @@ -40,8 +40,8 @@ fn main() { .print("target-spec-json") .run() .stdout_utf8(); - fs_wrapper::create_file("test-platform.json"); - fs_wrapper::write("test-platform.json", test_platform.as_bytes()); + rfs::create_file("test-platform.json"); + rfs::write("test-platform.json", test_platform.as_bytes()); let test_platform_2 = rustc() .arg("-Zunstable-options") .target("test-platform.json") diff --git a/tests/run-make/track-path-dep-info/rmake.rs b/tests/run-make/track-path-dep-info/rmake.rs index f108dc6605129..84041672984e6 100644 --- a/tests/run-make/track-path-dep-info/rmake.rs +++ b/tests/run-make/track-path-dep-info/rmake.rs @@ -4,10 +4,10 @@ // output successfully added the file as a dependency. // See https://github.com/rust-lang/rust/pull/84029 -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { rustc().input("macro_def.rs").run(); rustc().env("EXISTING_PROC_MACRO_ENV", "1").emit("dep-info").input("macro_use.rs").run(); - assert!(fs_wrapper::read_to_string("macro_use.d").contains("emojis.txt:")); + assert!(rfs::read_to_string("macro_use.d").contains("emojis.txt:")); } diff --git a/tests/run-make/track-pgo-dep-info/rmake.rs b/tests/run-make/track-pgo-dep-info/rmake.rs index acfe05cf8ea3d..f93085ad64603 100644 --- a/tests/run-make/track-pgo-dep-info/rmake.rs +++ b/tests/run-make/track-pgo-dep-info/rmake.rs @@ -8,7 +8,7 @@ // Reason: the binary is executed //@ needs-profiler-support -use run_make_support::{fs_wrapper, llvm_profdata, run, rustc}; +use run_make_support::{fs as rfs, llvm_profdata, run, rustc}; fn main() { // Generate the profile-guided-optimization (PGO) profiles @@ -19,5 +19,5 @@ fn main() { // Use the profiles in compilation rustc().profile_use("merged.profdata").emit("dep-info").input("main.rs").run(); // Check that the profile file is in the dep-info emit file - assert!(fs_wrapper::read_to_string("main.d").contains("merged.profdata")); + assert!(rfs::read_to_string("main.d").contains("merged.profdata")); } diff --git a/tests/run-make/volatile-intrinsics/rmake.rs b/tests/run-make/volatile-intrinsics/rmake.rs index fb9be4bb9ba23..fcadeafff3989 100644 --- a/tests/run-make/volatile-intrinsics/rmake.rs +++ b/tests/run-make/volatile-intrinsics/rmake.rs @@ -1,6 +1,6 @@ //@ ignore-cross-compile -use run_make_support::fs_wrapper::read; +use run_make_support::fs as rfs; use run_make_support::{assert_contains, run, rustc}; fn main() { @@ -11,7 +11,7 @@ fn main() { // ... and the loads/stores must not be optimized out. rustc().input("main.rs").emit("llvm-ir").run(); - let raw_llvm_ir = read("main.ll"); + let raw_llvm_ir = rfs::read("main.ll"); let llvm_ir = String::from_utf8_lossy(&raw_llvm_ir); assert_contains(&llvm_ir, "load volatile"); assert_contains(&llvm_ir, "store volatile"); diff --git a/tests/run-make/wasm-custom-section/rmake.rs b/tests/run-make/wasm-custom-section/rmake.rs index e958f5086ac66..d22e4109945e2 100644 --- a/tests/run-make/wasm-custom-section/rmake.rs +++ b/tests/run-make/wasm-custom-section/rmake.rs @@ -1,13 +1,13 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::collections::HashMap; fn main() { rustc().input("foo.rs").target("wasm32-wasip1").run(); rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run(); - let file = fs_wrapper::read("bar.wasm"); + let file = rfs::read("bar.wasm"); let mut custom = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-custom-sections-opt/rmake.rs b/tests/run-make/wasm-custom-sections-opt/rmake.rs index 346cffecc774a..db5a5a4849d50 100644 --- a/tests/run-make/wasm-custom-sections-opt/rmake.rs +++ b/tests/run-make/wasm-custom-sections-opt/rmake.rs @@ -1,6 +1,6 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::collections::HashMap; use std::path::Path; @@ -12,7 +12,7 @@ fn main() { fn verify(path: &Path) { eprintln!("verify {path:?}"); - let file = fs_wrapper::read(&path); + let file = rfs::read(&path); let mut custom = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-export-all-symbols/rmake.rs b/tests/run-make/wasm-export-all-symbols/rmake.rs index 41a2eaaafc313..ba006f55f5b4a 100644 --- a/tests/run-make/wasm-export-all-symbols/rmake.rs +++ b/tests/run-make/wasm-export-all-symbols/rmake.rs @@ -1,6 +1,6 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::collections::HashMap; use std::path::Path; use wasmparser::ExternalKind::*; @@ -33,7 +33,7 @@ fn test(args: &[&str]) { fn verify_exports(path: &Path, exports: &[(&str, wasmparser::ExternalKind)]) { println!("verify {path:?}"); - let file = fs_wrapper::read(path); + let file = rfs::read(path); let mut wasm_exports = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { let payload = payload.unwrap(); diff --git a/tests/run-make/wasm-import-module/rmake.rs b/tests/run-make/wasm-import-module/rmake.rs index 881242c59a27b..5eb49c8434898 100644 --- a/tests/run-make/wasm-import-module/rmake.rs +++ b/tests/run-make/wasm-import-module/rmake.rs @@ -1,6 +1,6 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::collections::HashMap; use wasmparser::TypeRef::Func; @@ -8,7 +8,7 @@ fn main() { rustc().input("foo.rs").target("wasm32-wasip1").run(); rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run(); - let file = fs_wrapper::read("bar.wasm"); + let file = rfs::read("bar.wasm"); let mut imports = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-panic-small/rmake.rs b/tests/run-make/wasm-panic-small/rmake.rs index 891cac4bc9fb3..5cc9c3411800d 100644 --- a/tests/run-make/wasm-panic-small/rmake.rs +++ b/tests/run-make/wasm-panic-small/rmake.rs @@ -1,7 +1,7 @@ //@ only-wasm32-wasip1 #![deny(warnings)] -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { test("a"); @@ -15,7 +15,7 @@ fn test(cfg: &str) { rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().cfg(cfg).run(); - let bytes = fs_wrapper::read("foo.wasm"); + let bytes = rfs::read("foo.wasm"); println!("{}", bytes.len()); assert!(bytes.len() < 40_000); } diff --git a/tests/run-make/wasm-spurious-import/rmake.rs b/tests/run-make/wasm-spurious-import/rmake.rs index 88e4c83c94ca5..520b1075dbac7 100644 --- a/tests/run-make/wasm-spurious-import/rmake.rs +++ b/tests/run-make/wasm-spurious-import/rmake.rs @@ -1,6 +1,6 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::collections::HashMap; fn main() { @@ -13,7 +13,7 @@ fn main() { .arg("-Copt-level=z") .run(); - let file = fs_wrapper::read("main.wasm"); + let file = rfs::read("main.wasm"); let mut imports = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-stringify-ints-small/rmake.rs b/tests/run-make/wasm-stringify-ints-small/rmake.rs index 42e415b3a8626..26d968755e458 100644 --- a/tests/run-make/wasm-stringify-ints-small/rmake.rs +++ b/tests/run-make/wasm-stringify-ints-small/rmake.rs @@ -1,12 +1,12 @@ //@ only-wasm32-wasip1 #![deny(warnings)] -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run(); - let bytes = fs_wrapper::read("foo.wasm"); + let bytes = rfs::read("foo.wasm"); println!("{}", bytes.len()); assert!(bytes.len() < 50_000); } diff --git a/tests/run-make/wasm-symbols-different-module/rmake.rs b/tests/run-make/wasm-symbols-different-module/rmake.rs index 734f79d834a95..f21dd5886196f 100644 --- a/tests/run-make/wasm-symbols-different-module/rmake.rs +++ b/tests/run-make/wasm-symbols-different-module/rmake.rs @@ -1,6 +1,6 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::collections::{HashMap, HashSet}; use std::path::Path; @@ -23,7 +23,7 @@ fn test(file: &str, args: &[&str], expected_imports: &[(&str, &[&str])]) { rustc().input(file).target("wasm32-wasip1").args(args).run(); - let file = fs_wrapper::read(Path::new(file).with_extension("wasm")); + let file = rfs::read(Path::new(file).with_extension("wasm")); let mut imports = HashMap::new(); for payload in wasmparser::Parser::new(0).parse_all(&file) { diff --git a/tests/run-make/wasm-symbols-not-exported/rmake.rs b/tests/run-make/wasm-symbols-not-exported/rmake.rs index 4c817a6fd8206..e744ac47c503f 100644 --- a/tests/run-make/wasm-symbols-not-exported/rmake.rs +++ b/tests/run-make/wasm-symbols-not-exported/rmake.rs @@ -1,6 +1,6 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::path::Path; fn main() { @@ -17,7 +17,7 @@ fn main() { fn verify_symbols(path: &Path) { eprintln!("verify {path:?}"); - let file = fs_wrapper::read(&path); + let file = rfs::read(&path); for payload in wasmparser::Parser::new(0).parse_all(&file) { let payload = payload.unwrap(); diff --git a/tests/run-make/wasm-symbols-not-imported/rmake.rs b/tests/run-make/wasm-symbols-not-imported/rmake.rs index 58c9f9c6f45c1..b0955e4f458a2 100644 --- a/tests/run-make/wasm-symbols-not-imported/rmake.rs +++ b/tests/run-make/wasm-symbols-not-imported/rmake.rs @@ -1,6 +1,6 @@ //@ only-wasm32-wasip1 -use run_make_support::{fs_wrapper, rustc, wasmparser}; +use run_make_support::{fs as rfs, rustc, wasmparser}; use std::path::Path; fn main() { @@ -16,7 +16,7 @@ fn main() { fn verify_symbols(path: &Path) { eprintln!("verify {path:?}"); - let file = fs_wrapper::read(&path); + let file = rfs::read(&path); for payload in wasmparser::Parser::new(0).parse_all(&file) { let payload = payload.unwrap(); diff --git a/tests/run-make/weird-output-filenames/rmake.rs b/tests/run-make/weird-output-filenames/rmake.rs index ed331a0b8d4ea..9f59f2961a219 100644 --- a/tests/run-make/weird-output-filenames/rmake.rs +++ b/tests/run-make/weird-output-filenames/rmake.rs @@ -1,4 +1,4 @@ -use run_make_support::fs_wrapper::copy; +use run_make_support::fs as rfs; use run_make_support::regex::Regex; use run_make_support::{cwd, rustc}; @@ -6,12 +6,12 @@ fn main() { let invalid_characters = [".foo.rs", ".foo.bar", "+foo+bar.rs"]; let re = Regex::new(r"invalid character.*in crate name:").unwrap(); for f in invalid_characters { - copy("foo.rs", f); + rfs::copy("foo.rs", f); let stderr = rustc().input(f).run_fail().stderr_utf8(); assert!(re.is_match(&stderr)); } - copy("foo.rs", "-foo.rs"); + rfs::copy("foo.rs", "-foo.rs"); rustc() .input(cwd().join("-foo.rs")) .run_fail() diff --git a/tests/run-make/windows-ws2_32/rmake.rs b/tests/run-make/windows-ws2_32/rmake.rs index fde59452bc550..41e92b702753b 100644 --- a/tests/run-make/windows-ws2_32/rmake.rs +++ b/tests/run-make/windows-ws2_32/rmake.rs @@ -3,7 +3,7 @@ // Tests that WS2_32.dll is not unnecessarily linked, see issue #85441 use run_make_support::object::{self, read::Object}; -use run_make_support::{fs_wrapper, rustc}; +use run_make_support::{fs as rfs, rustc}; fn main() { rustc().input("empty.rs").run(); @@ -14,7 +14,7 @@ fn main() { } fn links_ws2_32(exe: &str) -> bool { - let binary_data = fs_wrapper::read(exe); + let binary_data = rfs::read(exe); let file = object::File::parse(&*binary_data).unwrap(); for import in file.imports().unwrap() { if import.library().eq_ignore_ascii_case(b"WS2_32.dll") { From 0dfecb3855aabafd14d6156f013b128c12ed7795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 12:44:25 +0000 Subject: [PATCH 22/27] run_make_support: move some helpers from assertion to path --- .../run-make-support/src/assertion_helpers.rs | 50 +------------------ src/tools/run-make-support/src/lib.rs | 9 ++-- .../run-make-support/src/path_helpers.rs | 47 +++++++++++++++++ 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs index b57ac475e0876..5fb9d0da494c3 100644 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -1,57 +1,9 @@ //! Collection of assertions and assertion-related helpers. use std::panic; -use std::path::{Path, PathBuf}; +use std::path::Path; use crate::fs as rfs; -use crate::path_helpers::cwd; - -/// Browse the directory `path` non-recursively and return all files which respect the parameters -/// outlined by `closure`. -#[track_caller] -pub fn shallow_find_files, F: Fn(&PathBuf) -> bool>( - path: P, - filter: F, -) -> Vec { - let mut matching_files = Vec::new(); - for entry in rfs::read_dir(path) { - let entry = entry.expect("failed to read directory entry."); - let path = entry.path(); - - if path.is_file() && filter(&path) { - matching_files.push(path); - } - } - matching_files -} - -/// Returns true if the filename at `path` starts with `prefix`. -pub fn has_prefix>(path: P, prefix: &str) -> bool { - path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix)) -} - -/// Returns true if the filename at `path` has the extension `extension`. -pub fn has_extension>(path: P, extension: &str) -> bool { - path.as_ref().extension().is_some_and(|ext| ext == extension) -} - -/// Returns true if the filename at `path` does not contain `expected`. -pub fn not_contains>(path: P, expected: &str) -> bool { - !path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected)) -} - -/// Returns true if the filename at `path` is not in `expected`. -pub fn filename_not_in_denylist, V: AsRef<[String]>>(path: P, expected: V) -> bool { - let expected = expected.as_ref(); - path.as_ref() - .file_name() - .is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned())) -} - -/// Returns true if the filename at `path` ends with `suffix`. -pub fn has_suffix>(path: P, suffix: &str) -> bool { - path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix)) -} /// Gathers all files in the current working directory that have the extension `ext`, and counts /// the number of lines within that contain a match with the regex pattern `re`. diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index ae34ecd8d9726..f97e3dd5d8b21 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -61,14 +61,15 @@ pub use artifact_names::{ }; /// Path-related helpers. -pub use path_helpers::{cwd, path, source_root}; +pub use path_helpers::{ + cwd, filename_not_in_denylist, has_extension, has_prefix, has_suffix, not_contains, path, + shallow_find_files, source_root, +}; /// Helpers for scoped test execution where certain properties are attempted to be maintained. pub use scoped_run::{run_in_tmpdir, test_while_readonly}; pub use assertion_helpers::{ assert_contains, assert_equals, assert_not_contains, assert_recursive_eq, - count_regex_matches_in_files_with_extension, filename_not_in_denylist, has_extension, - has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains, - shallow_find_files, + count_regex_matches_in_files_with_extension, invalid_utf8_contains, invalid_utf8_not_contains, }; diff --git a/src/tools/run-make-support/src/path_helpers.rs b/src/tools/run-make-support/src/path_helpers.rs index b29d8727d2b37..f37ea8dfef8c6 100644 --- a/src/tools/run-make-support/src/path_helpers.rs +++ b/src/tools/run-make-support/src/path_helpers.rs @@ -31,3 +31,50 @@ pub fn path>(p: P) -> PathBuf { pub fn source_root() -> PathBuf { env_var("SOURCE_ROOT").into() } + +/// Browse the directory `path` non-recursively and return all files which respect the parameters +/// outlined by `closure`. +#[track_caller] +pub fn shallow_find_files, F: Fn(&PathBuf) -> bool>( + path: P, + filter: F, +) -> Vec { + let mut matching_files = Vec::new(); + for entry in std::fs::read_dir(path).unwrap() { + let entry = entry.expect("failed to read directory entry."); + let path = entry.path(); + + if path.is_file() && filter(&path) { + matching_files.push(path); + } + } + matching_files +} + +/// Returns true if the filename at `path` does not contain `expected`. +pub fn not_contains>(path: P, expected: &str) -> bool { + !path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().contains(expected)) +} + +/// Returns true if the filename at `path` is not in `expected`. +pub fn filename_not_in_denylist, V: AsRef<[String]>>(path: P, expected: V) -> bool { + let expected = expected.as_ref(); + path.as_ref() + .file_name() + .is_some_and(|name| !expected.contains(&name.to_str().unwrap().to_owned())) +} + +/// Returns true if the filename at `path` starts with `prefix`. +pub fn has_prefix>(path: P, prefix: &str) -> bool { + path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().starts_with(prefix)) +} + +/// Returns true if the filename at `path` has the extension `extension`. +pub fn has_extension>(path: P, extension: &str) -> bool { + path.as_ref().extension().is_some_and(|ext| ext == extension) +} + +/// Returns true if the filename at `path` ends with `suffix`. +pub fn has_suffix>(path: P, suffix: &str) -> bool { + path.as_ref().file_name().is_some_and(|name| name.to_str().unwrap().ends_with(suffix)) +} From 57a2f76557c3b4ea4ad0c40f1c9dc9c11ca9d289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 12:52:57 +0000 Subject: [PATCH 23/27] run_make_support: moved some helpers into `string` module --- .../run-make-support/src/assertion_helpers.rs | 46 ----------------- src/tools/run-make-support/src/lib.rs | 4 ++ src/tools/run-make-support/src/string.rs | 50 +++++++++++++++++++ 3 files changed, 54 insertions(+), 46 deletions(-) create mode 100644 src/tools/run-make-support/src/string.rs diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs index 5fb9d0da494c3..844c2d477aa80 100644 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -5,52 +5,6 @@ use std::path::Path; use crate::fs as rfs; -/// Gathers all files in the current working directory that have the extension `ext`, and counts -/// the number of lines within that contain a match with the regex pattern `re`. -pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) -> usize { - let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext)); - - let mut count = 0; - for file in fetched_files { - let content = rfs::read_to_string(file); - count += content.lines().filter(|line| re.is_match(&line)).count(); - } - - count -} - -/// Read the contents of a file that cannot simply be read by -/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert -/// that it contains `expected`. -#[track_caller] -pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S) { - let buffer = rfs::read(path.as_ref()); - let expected = expected.as_ref(); - if !String::from_utf8_lossy(&buffer).contains(expected) { - eprintln!("=== FILE CONTENTS (LOSSY) ==="); - eprintln!("{}", String::from_utf8_lossy(&buffer)); - eprintln!("=== SPECIFIED TEXT ==="); - eprintln!("{}", expected); - panic!("specified text was not found in file"); - } -} - -/// Read the contents of a file that cannot simply be read by -/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert -/// that it does not contain `expected`. -#[track_caller] -pub fn invalid_utf8_not_contains, S: AsRef>(path: P, expected: S) { - let buffer = rfs::read(path.as_ref()); - let expected = expected.as_ref(); - if String::from_utf8_lossy(&buffer).contains(expected) { - eprintln!("=== FILE CONTENTS (LOSSY) ==="); - eprintln!("{}", String::from_utf8_lossy(&buffer)); - eprintln!("=== SPECIFIED TEXT ==="); - eprintln!("{}", expected); - panic!("specified text was unexpectedly found in file"); - } -} - /// Assert that `actual` is equal to `expected`. #[track_caller] pub fn assert_equals, E: AsRef>(actual: A, expected: E) { diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index f97e3dd5d8b21..3dbc2d201ffac 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -16,6 +16,7 @@ pub mod fs; pub mod path_helpers; pub mod run; pub mod scoped_run; +pub mod string; pub mod targets; // Re-exports of third-party library crates. @@ -71,5 +72,8 @@ pub use scoped_run::{run_in_tmpdir, test_while_readonly}; pub use assertion_helpers::{ assert_contains, assert_equals, assert_not_contains, assert_recursive_eq, +}; + +pub use string::{ count_regex_matches_in_files_with_extension, invalid_utf8_contains, invalid_utf8_not_contains, }; diff --git a/src/tools/run-make-support/src/string.rs b/src/tools/run-make-support/src/string.rs new file mode 100644 index 0000000000000..f0b1e2334d8b3 --- /dev/null +++ b/src/tools/run-make-support/src/string.rs @@ -0,0 +1,50 @@ +use std::path::Path; + +use crate::fs as rfs; +use crate::path_helpers::{cwd, has_extension, shallow_find_files}; + +/// Gathers all files in the current working directory that have the extension `ext`, and counts +/// the number of lines within that contain a match with the regex pattern `re`. +pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) -> usize { + let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext)); + + let mut count = 0; + for file in fetched_files { + let content = rfs::read_to_string(file); + count += content.lines().filter(|line| re.is_match(&line)).count(); + } + + count +} + +/// Read the contents of a file that cannot simply be read by +/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert +/// that it contains `expected`. +#[track_caller] +pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S) { + let buffer = rfs::read(path.as_ref()); + let expected = expected.as_ref(); + if !String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was not found in file"); + } +} + +/// Read the contents of a file that cannot simply be read by +/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert +/// that it does not contain `expected`. +#[track_caller] +pub fn invalid_utf8_not_contains, S: AsRef>(path: P, expected: S) { + let buffer = rfs::read(path.as_ref()); + let expected = expected.as_ref(); + if String::from_utf8_lossy(&buffer).contains(expected) { + eprintln!("=== FILE CONTENTS (LOSSY) ==="); + eprintln!("{}", String::from_utf8_lossy(&buffer)); + eprintln!("=== SPECIFIED TEXT ==="); + eprintln!("{}", expected); + panic!("specified text was unexpectedly found in file"); + } +} From 30bdc4a30994beb338f9ab6589fd992082b3f0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 13:01:54 +0000 Subject: [PATCH 24/27] run_make_support: rename `assert_recursive_eq` to `assert_dirs_are_equal` --- src/tools/run-make-support/src/assertion_helpers.rs | 4 ++-- src/tools/run-make-support/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs index 844c2d477aa80..07992afc4b966 100644 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -48,12 +48,12 @@ pub fn assert_not_contains, N: AsRef>(haystack: H, needle: N) } /// Assert that all files in `dir1` exist and have the same content in `dir2` -pub fn assert_recursive_eq(dir1: impl AsRef, dir2: impl AsRef) { +pub fn assert_dirs_are_equal(dir1: impl AsRef, dir2: impl AsRef) { let dir2 = dir2.as_ref(); rfs::read_dir_entries(dir1, |entry_path| { let entry_name = entry_path.file_name().unwrap(); if entry_path.is_dir() { - assert_recursive_eq(&entry_path, &dir2.join(entry_name)); + assert_dirs_are_equal(&entry_path, &dir2.join(entry_name)); } else { let path2 = dir2.join(entry_name); let file1 = rfs::read(&entry_path); diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 3dbc2d201ffac..1a5e6d092ec42 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -71,7 +71,7 @@ pub use path_helpers::{ pub use scoped_run::{run_in_tmpdir, test_while_readonly}; pub use assertion_helpers::{ - assert_contains, assert_equals, assert_not_contains, assert_recursive_eq, + assert_contains, assert_dirs_are_equal, assert_equals, assert_not_contains, }; pub use string::{ From a00b860bfcf552d0c09e56edd0bcb377b6b532b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 13:02:34 +0000 Subject: [PATCH 25/27] tests: update rustdoc test for renamed `assert_dirs_are_equal` --- tests/run-make/rustdoc-verify-output-files/rmake.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-make/rustdoc-verify-output-files/rmake.rs b/tests/run-make/rustdoc-verify-output-files/rmake.rs index efcc47079bd18..940503bf85fb9 100644 --- a/tests/run-make/rustdoc-verify-output-files/rmake.rs +++ b/tests/run-make/rustdoc-verify-output-files/rmake.rs @@ -1,7 +1,7 @@ use run_make_support::fs as rfs; use std::path::{Path, PathBuf}; -use run_make_support::{assert_recursive_eq, rustdoc}; +use run_make_support::{assert_dirs_are_equal, rustdoc}; #[derive(PartialEq)] enum JsonOutput { @@ -45,5 +45,5 @@ fn main() { // Check if all docs(including both json and html formats) are still the same after multiple // compilations. - assert_recursive_eq(&out_dir, &tmp_out_dir); + assert_dirs_are_equal(&out_dir, &tmp_out_dir); } From 1f1bf4c71b73351193fbcb0deff298b17884c9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 13:31:27 +0000 Subject: [PATCH 26/27] run_make_support: use `fs` internally, but `rfs` to tests --- .../run-make-support/src/assertion_helpers.rs | 8 ++++---- src/tools/run-make-support/src/diff/mod.rs | 14 ++++++++------ src/tools/run-make-support/src/lib.rs | 9 ++++++++- src/tools/run-make-support/src/scoped_run.rs | 12 ++++++------ src/tools/run-make-support/src/string.rs | 8 ++++---- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/tools/run-make-support/src/assertion_helpers.rs b/src/tools/run-make-support/src/assertion_helpers.rs index 07992afc4b966..4b5b349431db9 100644 --- a/src/tools/run-make-support/src/assertion_helpers.rs +++ b/src/tools/run-make-support/src/assertion_helpers.rs @@ -3,7 +3,7 @@ use std::panic; use std::path::Path; -use crate::fs as rfs; +use crate::fs; /// Assert that `actual` is equal to `expected`. #[track_caller] @@ -50,14 +50,14 @@ pub fn assert_not_contains, N: AsRef>(haystack: H, needle: N) /// Assert that all files in `dir1` exist and have the same content in `dir2` pub fn assert_dirs_are_equal(dir1: impl AsRef, dir2: impl AsRef) { let dir2 = dir2.as_ref(); - rfs::read_dir_entries(dir1, |entry_path| { + fs::read_dir_entries(dir1, |entry_path| { let entry_name = entry_path.file_name().unwrap(); if entry_path.is_dir() { assert_dirs_are_equal(&entry_path, &dir2.join(entry_name)); } else { let path2 = dir2.join(entry_name); - let file1 = rfs::read(&entry_path); - let file2 = rfs::read(&path2); + let file1 = fs::read(&entry_path); + let file2 = fs::read(&path2); // We don't use `assert_eq!` because they are `Vec`, so not great for display. // Why not using String? Because there might be minified files or even potentially diff --git a/src/tools/run-make-support/src/diff/mod.rs b/src/tools/run-make-support/src/diff/mod.rs index 9f35488911928..ac66233160658 100644 --- a/src/tools/run-make-support/src/diff/mod.rs +++ b/src/tools/run-make-support/src/diff/mod.rs @@ -1,10 +1,12 @@ +use std::path::{Path, PathBuf}; + use regex::Regex; use similar::TextDiff; -use std::path::{Path, PathBuf}; -use crate::fs as rfs; use build_helper::drop_bomb::DropBomb; +use crate::fs; + #[cfg(test)] mod tests; @@ -43,7 +45,7 @@ impl Diff { /// Specify the expected output for the diff from a file. pub fn expected_file>(&mut self, path: P) -> &mut Self { let path = path.as_ref(); - let content = rfs::read_to_string(path); + let content = fs::read_to_string(path); let name = path.to_string_lossy().to_string(); self.expected_file = Some(path.into()); @@ -62,7 +64,7 @@ impl Diff { /// Specify the actual output for the diff from a file. pub fn actual_file>(&mut self, path: P) -> &mut Self { let path = path.as_ref(); - let content = rfs::read_to_string(path); + let content = fs::read_to_string(path); let name = path.to_string_lossy().to_string(); self.actual = Some(content); @@ -116,7 +118,7 @@ impl Diff { if let Some(ref expected_file) = self.expected_file { if std::env::var("RUSTC_BLESS_TEST").is_ok() { println!("Blessing `{}`", expected_file.display()); - rfs::write(expected_file, actual); + fs::write(expected_file, actual); return; } } @@ -138,7 +140,7 @@ impl Diff { if let Some(ref expected_file) = self.expected_file { if std::env::var("RUSTC_BLESS_TEST").is_ok() { println!("Blessing `{}`", expected_file.display()); - rfs::write(expected_file, actual); + fs::write(expected_file, actual); return; } } diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 1a5e6d092ec42..b15705e896582 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -12,13 +12,20 @@ pub mod assertion_helpers; pub mod diff; pub mod env; pub mod external_deps; -pub mod fs; pub mod path_helpers; pub mod run; pub mod scoped_run; pub mod string; pub mod targets; +mod fs; + +/// [`std::fs`] wrappers and assorted filesystem-related helpers. Public to tests as `rfs` to not be +/// confused with [`std::fs`]. +pub mod rfs { + pub use crate::fs::*; +} + // Re-exports of third-party library crates. pub use bstr; pub use gimli; diff --git a/src/tools/run-make-support/src/scoped_run.rs b/src/tools/run-make-support/src/scoped_run.rs index 63837e98904a4..074a83922c5b9 100644 --- a/src/tools/run-make-support/src/scoped_run.rs +++ b/src/tools/run-make-support/src/scoped_run.rs @@ -2,7 +2,7 @@ use std::path::Path; -use crate::fs as rfs; +use crate::fs; use crate::path_helpers::cwd; use crate::targets::is_windows; @@ -34,16 +34,16 @@ where ); panic!("`test_while_readonly` on directory detected while on Windows."); } - let metadata = rfs::metadata(&path); + let metadata = fs::metadata(&path); let original_perms = metadata.permissions(); let mut new_perms = original_perms.clone(); new_perms.set_readonly(true); - rfs::set_permissions(&path, new_perms); + fs::set_permissions(&path, new_perms); let success = std::panic::catch_unwind(closure); - rfs::set_permissions(&path, original_perms); + fs::set_permissions(&path, original_perms); success.unwrap(); } @@ -60,10 +60,10 @@ where pub fn run_in_tmpdir(callback: F) { let original_dir = cwd(); let tmpdir = original_dir.join("../temporary-directory"); - rfs::copy_dir_all(".", &tmpdir); + fs::copy_dir_all(".", &tmpdir); std::env::set_current_dir(&tmpdir).unwrap(); callback(); std::env::set_current_dir(original_dir).unwrap(); - rfs::remove_dir_all(tmpdir); + fs::remove_dir_all(tmpdir); } diff --git a/src/tools/run-make-support/src/string.rs b/src/tools/run-make-support/src/string.rs index f0b1e2334d8b3..a79004b8ec6b0 100644 --- a/src/tools/run-make-support/src/string.rs +++ b/src/tools/run-make-support/src/string.rs @@ -1,6 +1,6 @@ use std::path::Path; -use crate::fs as rfs; +use crate::fs; use crate::path_helpers::{cwd, has_extension, shallow_find_files}; /// Gathers all files in the current working directory that have the extension `ext`, and counts @@ -10,7 +10,7 @@ pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) let mut count = 0; for file in fetched_files { - let content = rfs::read_to_string(file); + let content = fs::read_to_string(file); count += content.lines().filter(|line| re.is_match(&line)).count(); } @@ -22,7 +22,7 @@ pub fn count_regex_matches_in_files_with_extension(re: ®ex::Regex, ext: &str) /// that it contains `expected`. #[track_caller] pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S) { - let buffer = rfs::read(path.as_ref()); + let buffer = fs::read(path.as_ref()); let expected = expected.as_ref(); if !String::from_utf8_lossy(&buffer).contains(expected) { eprintln!("=== FILE CONTENTS (LOSSY) ==="); @@ -38,7 +38,7 @@ pub fn invalid_utf8_contains, S: AsRef>(path: P, expected: S /// that it does not contain `expected`. #[track_caller] pub fn invalid_utf8_not_contains, S: AsRef>(path: P, expected: S) { - let buffer = rfs::read(path.as_ref()); + let buffer = fs::read(path.as_ref()); let expected = expected.as_ref(); if String::from_utf8_lossy(&buffer).contains(expected) { eprintln!("=== FILE CONTENTS (LOSSY) ==="); From d69cc1ccbf9d25225add138a4b0f6ee424d0d59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= Date: Wed, 17 Jul 2024 13:31:38 +0000 Subject: [PATCH 27/27] tests: update for `rfs` rename --- tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs | 2 +- tests/run-make/c-link-to-rust-dylib/rmake.rs | 2 +- tests/run-make/c-link-to-rust-staticlib/rmake.rs | 2 +- tests/run-make/cdylib/rmake.rs | 2 +- tests/run-make/comment-section/rmake.rs | 2 +- tests/run-make/compiler-builtins/rmake.rs | 2 +- tests/run-make/compiler-lookup-paths/rmake.rs | 2 +- tests/run-make/const-prop-lint/rmake.rs | 2 +- tests/run-make/crate-name-priority/rmake.rs | 2 +- tests/run-make/doctests-keep-binaries/rmake.rs | 2 +- tests/run-make/doctests-runtool/rmake.rs | 2 +- tests/run-make/dump-mono-stats/rmake.rs | 2 +- tests/run-make/dylib-chain/rmake.rs | 2 +- tests/run-make/emit-named-files/rmake.rs | 2 +- tests/run-make/emit-path-unhashed/rmake.rs | 2 +- tests/run-make/extern-flag-pathless/rmake.rs | 2 +- tests/run-make/extra-filename-with-temp-outputs/rmake.rs | 4 +--- tests/run-make/ice-dep-cannot-find-dep/rmake.rs | 2 +- tests/run-make/inaccessible-temp-dir/rmake.rs | 2 +- tests/run-make/incr-prev-body-beyond-eof/rmake.rs | 2 +- tests/run-make/incr-test-moved-file/rmake.rs | 2 +- tests/run-make/incremental-debugger-visualizer/rmake.rs | 2 +- tests/run-make/incremental-session-fail/rmake.rs | 2 +- tests/run-make/inline-always-many-cgu/rmake.rs | 2 +- tests/run-make/intrinsic-unreachable/rmake.rs | 2 +- tests/run-make/invalid-library/rmake.rs | 2 +- tests/run-make/invalid-so/rmake.rs | 2 +- tests/run-make/invalid-staticlib/rmake.rs | 2 +- tests/run-make/issue-107495-archive-permissions/rmake.rs | 2 +- tests/run-make/ls-metadata/rmake.rs | 2 +- tests/run-make/lto-readonly-lib/rmake.rs | 2 +- tests/run-make/many-crates-but-no-match/rmake.rs | 2 +- tests/run-make/mixing-libs/rmake.rs | 2 +- tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs | 2 +- tests/run-make/non-unicode-env/rmake.rs | 2 +- tests/run-make/non-unicode-in-incremental-dir/rmake.rs | 2 +- tests/run-make/obey-crate-type-flag/rmake.rs | 2 +- .../output-filename-conflicts-with-directory/rmake.rs | 2 +- tests/run-make/output-filename-overwrites-input/rmake.rs | 2 +- tests/run-make/output-type-permutations/rmake.rs | 2 +- tests/run-make/parallel-rustc-no-overwrite/rmake.rs | 2 +- tests/run-make/pgo-branch-weights/rmake.rs | 2 +- tests/run-make/pgo-use/rmake.rs | 2 +- tests/run-make/prefer-dylib/rmake.rs | 2 +- tests/run-make/prefer-rlib/rmake.rs | 2 +- tests/run-make/pretty-print-with-dep-file/rmake.rs | 2 +- tests/run-make/print-cfg/rmake.rs | 2 +- tests/run-make/print-to-output/rmake.rs | 2 +- tests/run-make/remap-path-prefix/rmake.rs | 2 +- tests/run-make/repr128-dwarf/rmake.rs | 2 +- tests/run-make/reset-codegen-1/rmake.rs | 2 +- tests/run-make/resolve-rename/rmake.rs | 2 +- tests/run-make/rlib-chain/rmake.rs | 2 +- tests/run-make/rustdoc-scrape-examples-remap/scrape.rs | 2 +- tests/run-make/rustdoc-test-args/rmake.rs | 2 +- tests/run-make/rustdoc-themes/rmake.rs | 2 +- tests/run-make/rustdoc-verify-output-files/rmake.rs | 2 +- tests/run-make/sepcomp-cci-copies/rmake.rs | 2 +- tests/run-make/sepcomp-inlining/rmake.rs | 2 +- tests/run-make/sepcomp-separate/rmake.rs | 2 +- tests/run-make/silly-file-names/rmake.rs | 2 +- tests/run-make/symlinked-extern/rmake.rs | 2 +- tests/run-make/symlinked-libraries/rmake.rs | 2 +- tests/run-make/symlinked-rlib/rmake.rs | 2 +- tests/run-make/target-specs/rmake.rs | 2 +- tests/run-make/track-path-dep-info/rmake.rs | 2 +- tests/run-make/track-pgo-dep-info/rmake.rs | 2 +- tests/run-make/volatile-intrinsics/rmake.rs | 2 +- tests/run-make/wasm-custom-section/rmake.rs | 2 +- tests/run-make/wasm-custom-sections-opt/rmake.rs | 2 +- tests/run-make/wasm-export-all-symbols/rmake.rs | 2 +- tests/run-make/wasm-import-module/rmake.rs | 2 +- tests/run-make/wasm-panic-small/rmake.rs | 2 +- tests/run-make/wasm-spurious-import/rmake.rs | 2 +- tests/run-make/wasm-stringify-ints-small/rmake.rs | 2 +- tests/run-make/wasm-symbols-different-module/rmake.rs | 2 +- tests/run-make/wasm-symbols-not-exported/rmake.rs | 2 +- tests/run-make/wasm-symbols-not-imported/rmake.rs | 2 +- tests/run-make/weird-output-filenames/rmake.rs | 2 +- tests/run-make/windows-ws2_32/rmake.rs | 2 +- 80 files changed, 80 insertions(+), 82 deletions(-) diff --git a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs index 5dd05f151df41..fec4a4bb90b36 100644 --- a/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs +++ b/tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; -use run_make_support::{aux_build, fs as rfs, rustc, source_root}; +use run_make_support::{aux_build, rfs, rustc, source_root}; fn main() { aux_build().input("stable.rs").emit("metadata").run(); diff --git a/tests/run-make/c-link-to-rust-dylib/rmake.rs b/tests/run-make/c-link-to-rust-dylib/rmake.rs index e4441ac0c3be1..ab9aa445402b0 100644 --- a/tests/run-make/c-link-to-rust-dylib/rmake.rs +++ b/tests/run-make/c-link-to-rust-dylib/rmake.rs @@ -3,7 +3,7 @@ //@ ignore-cross-compile -use run_make_support::{cc, cwd, dynamic_lib_extension, fs as rfs, is_msvc, run, run_fail, rustc}; +use run_make_support::{cc, cwd, dynamic_lib_extension, is_msvc, rfs, run, run_fail, rustc}; fn main() { rustc().input("foo.rs").run(); diff --git a/tests/run-make/c-link-to-rust-staticlib/rmake.rs b/tests/run-make/c-link-to-rust-staticlib/rmake.rs index 8c845f8b6f2d2..ee35350da66a6 100644 --- a/tests/run-make/c-link-to-rust-staticlib/rmake.rs +++ b/tests/run-make/c-link-to-rust-staticlib/rmake.rs @@ -3,7 +3,7 @@ //@ ignore-cross-compile -use run_make_support::fs::remove_file; +use run_make_support::rfs::remove_file; use run_make_support::{cc, extra_c_flags, run, rustc, static_lib_name}; use std::fs; diff --git a/tests/run-make/cdylib/rmake.rs b/tests/run-make/cdylib/rmake.rs index b6f2a9be0b224..21b83d1b1a91f 100644 --- a/tests/run-make/cdylib/rmake.rs +++ b/tests/run-make/cdylib/rmake.rs @@ -10,7 +10,7 @@ //@ ignore-cross-compile -use run_make_support::{cc, cwd, dynamic_lib_name, fs as rfs, is_msvc, run, rustc}; +use run_make_support::{cc, cwd, dynamic_lib_name, is_msvc, rfs, run, rustc}; fn main() { rustc().input("bar.rs").run(); diff --git a/tests/run-make/comment-section/rmake.rs b/tests/run-make/comment-section/rmake.rs index f6978ab259ddb..a16adea716260 100644 --- a/tests/run-make/comment-section/rmake.rs +++ b/tests/run-make/comment-section/rmake.rs @@ -9,8 +9,8 @@ use std::path::PathBuf; -use run_make_support::fs as rfs; use run_make_support::llvm_readobj; +use run_make_support::rfs; use run_make_support::rustc; use run_make_support::{cwd, env_var, run_in_tmpdir}; diff --git a/tests/run-make/compiler-builtins/rmake.rs b/tests/run-make/compiler-builtins/rmake.rs index b9dacdd0b9058..43d1d69b245f9 100644 --- a/tests/run-make/compiler-builtins/rmake.rs +++ b/tests/run-make/compiler-builtins/rmake.rs @@ -14,12 +14,12 @@ #![deny(warnings)] -use run_make_support::fs::{read, read_dir}; use run_make_support::object::read::archive::ArchiveFile; use run_make_support::object::read::Object; use run_make_support::object::ObjectSection; use run_make_support::object::ObjectSymbol; use run_make_support::object::RelocationTarget; +use run_make_support::rfs::{read, read_dir}; use run_make_support::{cmd, env_var, object}; use std::collections::HashSet; use std::path::PathBuf; diff --git a/tests/run-make/compiler-lookup-paths/rmake.rs b/tests/run-make/compiler-lookup-paths/rmake.rs index cfb7ef90ce43b..3ffa6e0592f0c 100644 --- a/tests/run-make/compiler-lookup-paths/rmake.rs +++ b/tests/run-make/compiler-lookup-paths/rmake.rs @@ -9,7 +9,7 @@ //@ ignore-wasm64 // Reason: a C compiler is required for build_native_static_lib -use run_make_support::{build_native_static_lib, fs as rfs, rustc, static_lib_name}; +use run_make_support::{build_native_static_lib, rfs, rustc, static_lib_name}; fn main() { build_native_static_lib("native"); diff --git a/tests/run-make/const-prop-lint/rmake.rs b/tests/run-make/const-prop-lint/rmake.rs index 25d9ccad41774..17e4b0c77f35b 100644 --- a/tests/run-make/const-prop-lint/rmake.rs +++ b/tests/run-make/const-prop-lint/rmake.rs @@ -1,6 +1,6 @@ // Tests that const prop lints interrupting codegen don't leave `.o` files around. -use run_make_support::{cwd, fs as rfs, rustc}; +use run_make_support::{cwd, rfs, rustc}; fn main() { rustc().input("input.rs").run_fail().assert_exit_code(1); diff --git a/tests/run-make/crate-name-priority/rmake.rs b/tests/run-make/crate-name-priority/rmake.rs index c0cc8bdfdbfa8..5bdb49b33ceac 100644 --- a/tests/run-make/crate-name-priority/rmake.rs +++ b/tests/run-make/crate-name-priority/rmake.rs @@ -4,7 +4,7 @@ // and the compiler flags, and checks that the flag is favoured each time. // See https://github.com/rust-lang/rust/pull/15518 -use run_make_support::{bin_name, fs as rfs, rustc}; +use run_make_support::{bin_name, rfs, rustc}; fn main() { rustc().input("foo.rs").run(); diff --git a/tests/run-make/doctests-keep-binaries/rmake.rs b/tests/run-make/doctests-keep-binaries/rmake.rs index 35b29f21a5ab9..6bff5c0c8d048 100644 --- a/tests/run-make/doctests-keep-binaries/rmake.rs +++ b/tests/run-make/doctests-keep-binaries/rmake.rs @@ -1,7 +1,7 @@ // Check that valid binaries are persisted by running them, regardless of whether the // --run or --no-run option is used. -use run_make_support::fs::{create_dir, remove_dir_all}; +use run_make_support::rfs::{create_dir, remove_dir_all}; use run_make_support::{run, rustc, rustdoc}; use std::path::Path; diff --git a/tests/run-make/doctests-runtool/rmake.rs b/tests/run-make/doctests-runtool/rmake.rs index 979c3ea7d2c15..5d829b9e88bc0 100644 --- a/tests/run-make/doctests-runtool/rmake.rs +++ b/tests/run-make/doctests-runtool/rmake.rs @@ -1,6 +1,6 @@ // Tests behavior of rustdoc `--runtool`. -use run_make_support::fs::{create_dir, remove_dir_all}; +use run_make_support::rfs::{create_dir, remove_dir_all}; use run_make_support::{rustc, rustdoc}; use std::path::PathBuf; diff --git a/tests/run-make/dump-mono-stats/rmake.rs b/tests/run-make/dump-mono-stats/rmake.rs index 05a5b559e6ddf..f4142e0a31c3e 100644 --- a/tests/run-make/dump-mono-stats/rmake.rs +++ b/tests/run-make/dump-mono-stats/rmake.rs @@ -4,7 +4,7 @@ // a specific expected string. // See https://github.com/rust-lang/rust/pull/105481 -use run_make_support::{cwd, fs as rfs, rustc}; +use run_make_support::{cwd, rfs, rustc}; fn main() { rustc() diff --git a/tests/run-make/dylib-chain/rmake.rs b/tests/run-make/dylib-chain/rmake.rs index 63ae2f01ce408..54d53d4709201 100644 --- a/tests/run-make/dylib-chain/rmake.rs +++ b/tests/run-make/dylib-chain/rmake.rs @@ -8,7 +8,7 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -use run_make_support::{dynamic_lib_name, fs as rfs, run, run_fail, rustc}; +use run_make_support::{dynamic_lib_name, rfs, run, run_fail, rustc}; fn main() { rustc().input("m1.rs").arg("-Cprefer-dynamic").run(); diff --git a/tests/run-make/emit-named-files/rmake.rs b/tests/run-make/emit-named-files/rmake.rs index 0cf743fc7d438..1570e1adc2561 100644 --- a/tests/run-make/emit-named-files/rmake.rs +++ b/tests/run-make/emit-named-files/rmake.rs @@ -1,6 +1,6 @@ use std::path::Path; -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) { let out_file = out_dir.join(out_file); diff --git a/tests/run-make/emit-path-unhashed/rmake.rs b/tests/run-make/emit-path-unhashed/rmake.rs index 0d0ad1b91670f..a97153e37dd9c 100644 --- a/tests/run-make/emit-path-unhashed/rmake.rs +++ b/tests/run-make/emit-path-unhashed/rmake.rs @@ -6,7 +6,7 @@ // adding a new output type (in this test, metadata). // See https://github.com/rust-lang/rust/issues/86044 -use run_make_support::{diff, fs as rfs, rustc}; +use run_make_support::{diff, rfs, rustc}; fn main() { rfs::create_dir("emit"); diff --git a/tests/run-make/extern-flag-pathless/rmake.rs b/tests/run-make/extern-flag-pathless/rmake.rs index bdc8b3e2c9991..ec380feae4624 100644 --- a/tests/run-make/extern-flag-pathless/rmake.rs +++ b/tests/run-make/extern-flag-pathless/rmake.rs @@ -8,7 +8,7 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -use run_make_support::{dynamic_lib_name, fs as rfs, run, run_fail, rust_lib_name, rustc}; +use run_make_support::{dynamic_lib_name, rfs, run, run_fail, rust_lib_name, rustc}; fn main() { rustc().input("bar.rs").crate_type("rlib").crate_type("dylib").arg("-Cprefer-dynamic").run(); diff --git a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs index d7b865f816992..0910045bb8577 100644 --- a/tests/run-make/extra-filename-with-temp-outputs/rmake.rs +++ b/tests/run-make/extra-filename-with-temp-outputs/rmake.rs @@ -6,9 +6,7 @@ // are named as expected. // See https://github.com/rust-lang/rust/pull/15686 -use run_make_support::{ - bin_name, cwd, fs as rfs, has_prefix, has_suffix, rustc, shallow_find_files, -}; +use run_make_support::{bin_name, cwd, has_prefix, has_suffix, rfs, rustc, shallow_find_files}; fn main() { rustc().extra_filename("bar").input("foo.rs").arg("-Csave-temps").run(); diff --git a/tests/run-make/ice-dep-cannot-find-dep/rmake.rs b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs index b4210eb5f3bc0..8ba3a0366b002 100644 --- a/tests/run-make/ice-dep-cannot-find-dep/rmake.rs +++ b/tests/run-make/ice-dep-cannot-find-dep/rmake.rs @@ -16,7 +16,7 @@ // If we used `rustc` the additional '-L rmake_out' option would allow rustc to // actually find the crate. -use run_make_support::{bare_rustc, fs as rfs, rust_lib_name, rustc}; +use run_make_support::{bare_rustc, rfs, rust_lib_name, rustc}; fn main() { rustc().crate_name("a").crate_type("rlib").input("a.rs").arg("--verbose").run(); diff --git a/tests/run-make/inaccessible-temp-dir/rmake.rs b/tests/run-make/inaccessible-temp-dir/rmake.rs index 4fbd207975c5c..b6624f37f962c 100644 --- a/tests/run-make/inaccessible-temp-dir/rmake.rs +++ b/tests/run-make/inaccessible-temp-dir/rmake.rs @@ -24,7 +24,7 @@ // Reason: `set_readonly` has no effect on directories // and does not prevent modification. -use run_make_support::{fs as rfs, rustc, test_while_readonly}; +use run_make_support::{rfs, rustc, test_while_readonly}; fn main() { // Create an inaccessible directory. diff --git a/tests/run-make/incr-prev-body-beyond-eof/rmake.rs b/tests/run-make/incr-prev-body-beyond-eof/rmake.rs index ae74f120ce39b..14e75671df8a1 100644 --- a/tests/run-make/incr-prev-body-beyond-eof/rmake.rs +++ b/tests/run-make/incr-prev-body-beyond-eof/rmake.rs @@ -13,7 +13,7 @@ //@ ignore-nvptx64-nvidia-cuda // FIXME: can't find crate for `std` -use run_make_support::fs as rfs; +use run_make_support::rfs; use run_make_support::rustc; fn main() { diff --git a/tests/run-make/incr-test-moved-file/rmake.rs b/tests/run-make/incr-test-moved-file/rmake.rs index c4fc3d37526e0..f314e110a8c33 100644 --- a/tests/run-make/incr-test-moved-file/rmake.rs +++ b/tests/run-make/incr-test-moved-file/rmake.rs @@ -14,7 +14,7 @@ //@ ignore-nvptx64-nvidia-cuda // FIXME: can't find crate for 'std' -use run_make_support::{fs as rfs, rust_lib_name, rustc}; +use run_make_support::{rfs, rust_lib_name, rustc}; fn main() { rfs::create_dir("incr"); diff --git a/tests/run-make/incremental-debugger-visualizer/rmake.rs b/tests/run-make/incremental-debugger-visualizer/rmake.rs index da9f9d41ee81e..985816ff5d70f 100644 --- a/tests/run-make/incremental-debugger-visualizer/rmake.rs +++ b/tests/run-make/incremental-debugger-visualizer/rmake.rs @@ -2,7 +2,7 @@ // (in this case, foo.py and foo.natvis) are picked up when compiling incrementally. // See https://github.com/rust-lang/rust/pull/111641 -use run_make_support::{fs as rfs, invalid_utf8_contains, invalid_utf8_not_contains, rustc}; +use run_make_support::{invalid_utf8_contains, invalid_utf8_not_contains, rfs, rustc}; use std::io::Read; fn main() { diff --git a/tests/run-make/incremental-session-fail/rmake.rs b/tests/run-make/incremental-session-fail/rmake.rs index 22ff1e2a8a4d7..c6927c8a9f16d 100644 --- a/tests/run-make/incremental-session-fail/rmake.rs +++ b/tests/run-make/incremental-session-fail/rmake.rs @@ -4,7 +4,7 @@ // the ensuing compilation failure is not an ICE. // See https://github.com/rust-lang/rust/pull/85698 -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; fn main() { rfs::create_file("session"); diff --git a/tests/run-make/inline-always-many-cgu/rmake.rs b/tests/run-make/inline-always-many-cgu/rmake.rs index 3b51bb1cd81a6..5a6929c855b2a 100644 --- a/tests/run-make/inline-always-many-cgu/rmake.rs +++ b/tests/run-make/inline-always-many-cgu/rmake.rs @@ -1,5 +1,5 @@ -use run_make_support::fs as rfs; use run_make_support::regex::Regex; +use run_make_support::rfs; use run_make_support::rustc; use std::ffi::OsStr; diff --git a/tests/run-make/intrinsic-unreachable/rmake.rs b/tests/run-make/intrinsic-unreachable/rmake.rs index 34f7ab3fbc8a9..bb189fbdcb5d4 100644 --- a/tests/run-make/intrinsic-unreachable/rmake.rs +++ b/tests/run-make/intrinsic-unreachable/rmake.rs @@ -8,7 +8,7 @@ //@ ignore-windows // Reason: Because of Windows exception handling, the code is not necessarily any shorter. -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; fn main() { rustc().opt().emit("asm").input("exit-ret.rs").run(); diff --git a/tests/run-make/invalid-library/rmake.rs b/tests/run-make/invalid-library/rmake.rs index 3961e2b846bd4..42afb74a59efc 100644 --- a/tests/run-make/invalid-library/rmake.rs +++ b/tests/run-make/invalid-library/rmake.rs @@ -4,7 +4,7 @@ // one appearing in stderr in this scenario. // See https://github.com/rust-lang/rust/pull/12645 -use run_make_support::fs as rfs; +use run_make_support::rfs; use run_make_support::{llvm_ar, rustc}; fn main() { diff --git a/tests/run-make/invalid-so/rmake.rs b/tests/run-make/invalid-so/rmake.rs index c79e0563bada4..754c53a49b924 100644 --- a/tests/run-make/invalid-so/rmake.rs +++ b/tests/run-make/invalid-so/rmake.rs @@ -4,7 +4,7 @@ // explains that the file exists, but that its metadata is incorrect. // See https://github.com/rust-lang/rust/pull/88368 -use run_make_support::{dynamic_lib_name, fs as rfs, rustc}; +use run_make_support::{dynamic_lib_name, rfs, rustc}; fn main() { rfs::create_file(dynamic_lib_name("foo")); diff --git a/tests/run-make/invalid-staticlib/rmake.rs b/tests/run-make/invalid-staticlib/rmake.rs index e31dcdec95bd6..ba9e07dd07b8f 100644 --- a/tests/run-make/invalid-staticlib/rmake.rs +++ b/tests/run-make/invalid-staticlib/rmake.rs @@ -4,7 +4,7 @@ // an internal compiler error (ICE). // See https://github.com/rust-lang/rust/pull/28673 -use run_make_support::{fs as rfs, rustc, static_lib_name}; +use run_make_support::{rfs, rustc, static_lib_name}; fn main() { rfs::create_file(static_lib_name("foo")); diff --git a/tests/run-make/issue-107495-archive-permissions/rmake.rs b/tests/run-make/issue-107495-archive-permissions/rmake.rs index 78d57d57afbed..f47b8d7190f28 100644 --- a/tests/run-make/issue-107495-archive-permissions/rmake.rs +++ b/tests/run-make/issue-107495-archive-permissions/rmake.rs @@ -3,7 +3,7 @@ #[cfg(unix)] extern crate libc; -use run_make_support::{aux_build, fs as rfs}; +use run_make_support::{aux_build, rfs}; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; diff --git a/tests/run-make/ls-metadata/rmake.rs b/tests/run-make/ls-metadata/rmake.rs index 8a2d79ed3af31..45299a48c110d 100644 --- a/tests/run-make/ls-metadata/rmake.rs +++ b/tests/run-make/ls-metadata/rmake.rs @@ -6,7 +6,7 @@ //@ ignore-cross-compile -use run_make_support::fs as rfs; +use run_make_support::rfs; use run_make_support::rustc; fn main() { diff --git a/tests/run-make/lto-readonly-lib/rmake.rs b/tests/run-make/lto-readonly-lib/rmake.rs index 5e06aeb73b601..d0ba3fb37a202 100644 --- a/tests/run-make/lto-readonly-lib/rmake.rs +++ b/tests/run-make/lto-readonly-lib/rmake.rs @@ -7,7 +7,7 @@ //@ ignore-cross-compile -use run_make_support::fs as rfs; +use run_make_support::rfs; use run_make_support::{run, rust_lib_name, rustc, test_while_readonly}; fn main() { diff --git a/tests/run-make/many-crates-but-no-match/rmake.rs b/tests/run-make/many-crates-but-no-match/rmake.rs index 7f8f93346d793..938ffce6a036c 100644 --- a/tests/run-make/many-crates-but-no-match/rmake.rs +++ b/tests/run-make/many-crates-but-no-match/rmake.rs @@ -4,7 +4,7 @@ // what should be done to fix the issue. // See https://github.com/rust-lang/rust/issues/13266 -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; fn main() { rfs::create_dir("a1"); diff --git a/tests/run-make/mixing-libs/rmake.rs b/tests/run-make/mixing-libs/rmake.rs index 6799a93fbc125..89fbf5589e3b3 100644 --- a/tests/run-make/mixing-libs/rmake.rs +++ b/tests/run-make/mixing-libs/rmake.rs @@ -6,7 +6,7 @@ //@ ignore-cross-compile -use run_make_support::{dynamic_lib_name, fs as rfs, rustc}; +use run_make_support::{dynamic_lib_name, rfs, rustc}; fn main() { rustc().input("rlib.rs").crate_type("rlib").crate_type("dylib").run(); diff --git a/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs index 2fd6022706461..f63146e692ac4 100644 --- a/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs +++ b/tests/run-make/moved-src-dir-fingerprint-ice/rmake.rs @@ -17,7 +17,7 @@ //@ ignore-nvptx64-nvidia-cuda // FIXME: can't find crate for 'std' -use run_make_support::{fs as rfs, rust_lib_name, rustc}; +use run_make_support::{rfs, rust_lib_name, rustc}; fn main() { rfs::create_dir("incr"); diff --git a/tests/run-make/non-unicode-env/rmake.rs b/tests/run-make/non-unicode-env/rmake.rs index f23fef88dabc5..0042e4d1e173a 100644 --- a/tests/run-make/non-unicode-env/rmake.rs +++ b/tests/run-make/non-unicode-env/rmake.rs @@ -1,4 +1,4 @@ -use run_make_support::fs as rfs; +use run_make_support::rfs; use run_make_support::rustc; fn main() { diff --git a/tests/run-make/non-unicode-in-incremental-dir/rmake.rs b/tests/run-make/non-unicode-in-incremental-dir/rmake.rs index d0d730d17ebb5..ef316f1103638 100644 --- a/tests/run-make/non-unicode-in-incremental-dir/rmake.rs +++ b/tests/run-make/non-unicode-in-incremental-dir/rmake.rs @@ -1,4 +1,4 @@ -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; fn main() { #[cfg(unix)] diff --git a/tests/run-make/obey-crate-type-flag/rmake.rs b/tests/run-make/obey-crate-type-flag/rmake.rs index 198eb6931589e..8d6eb237982e8 100644 --- a/tests/run-make/obey-crate-type-flag/rmake.rs +++ b/tests/run-make/obey-crate-type-flag/rmake.rs @@ -6,7 +6,7 @@ //@ ignore-cross-compile use run_make_support::{ - cwd, dynamic_lib_name, fs as rfs, has_extension, rust_lib_name, rustc, shallow_find_files, + cwd, dynamic_lib_name, has_extension, rfs, rust_lib_name, rustc, shallow_find_files, }; use std::path::Path; diff --git a/tests/run-make/output-filename-conflicts-with-directory/rmake.rs b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs index 6df9628a9fb73..e49b5005fa066 100644 --- a/tests/run-make/output-filename-conflicts-with-directory/rmake.rs +++ b/tests/run-make/output-filename-conflicts-with-directory/rmake.rs @@ -4,7 +4,7 @@ // potentially-confusing linker error. // See https://github.com/rust-lang/rust/pull/47203 -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; fn main() { rfs::create_dir("foo"); diff --git a/tests/run-make/output-filename-overwrites-input/rmake.rs b/tests/run-make/output-filename-overwrites-input/rmake.rs index 0e9c20b0468fb..1fa12259fafa3 100644 --- a/tests/run-make/output-filename-overwrites-input/rmake.rs +++ b/tests/run-make/output-filename-overwrites-input/rmake.rs @@ -4,7 +4,7 @@ //@ ignore-cross-compile -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; fn main() { rfs::copy("foo.rs", "foo"); diff --git a/tests/run-make/output-type-permutations/rmake.rs b/tests/run-make/output-type-permutations/rmake.rs index a4d2601260b49..c51b2153945f0 100644 --- a/tests/run-make/output-type-permutations/rmake.rs +++ b/tests/run-make/output-type-permutations/rmake.rs @@ -5,7 +5,7 @@ // See https://github.com/rust-lang/rust/pull/12020 use run_make_support::{ - bin_name, dynamic_lib_name, filename_not_in_denylist, fs as rfs, rust_lib_name, rustc, + bin_name, dynamic_lib_name, filename_not_in_denylist, rfs, rust_lib_name, rustc, shallow_find_files, static_lib_name, }; use std::path::PathBuf; diff --git a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs index 9c224ad05b21b..3f412bfefc8d3 100644 --- a/tests/run-make/parallel-rustc-no-overwrite/rmake.rs +++ b/tests/run-make/parallel-rustc-no-overwrite/rmake.rs @@ -5,7 +5,7 @@ // 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 as rfs, rustc}; +use run_make_support::{rfs, rustc}; use std::sync::{Arc, Barrier}; use std::thread; diff --git a/tests/run-make/pgo-branch-weights/rmake.rs b/tests/run-make/pgo-branch-weights/rmake.rs index 0915fe0e2a299..588c5c6dc31c7 100644 --- a/tests/run-make/pgo-branch-weights/rmake.rs +++ b/tests/run-make/pgo-branch-weights/rmake.rs @@ -10,7 +10,7 @@ //@ needs-profiler-support //@ ignore-cross-compile -use run_make_support::{fs as rfs, llvm_filecheck, llvm_profdata, run_with_args, rustc}; +use run_make_support::{llvm_filecheck, llvm_profdata, rfs, run_with_args, rustc}; use std::path::Path; fn main() { diff --git a/tests/run-make/pgo-use/rmake.rs b/tests/run-make/pgo-use/rmake.rs index f53ea79102cbb..cad49372266e8 100644 --- a/tests/run-make/pgo-use/rmake.rs +++ b/tests/run-make/pgo-use/rmake.rs @@ -9,7 +9,7 @@ //@ ignore-cross-compile use run_make_support::{ - cwd, fs as rfs, has_extension, has_prefix, llvm_filecheck, llvm_profdata, run_with_args, rustc, + cwd, has_extension, has_prefix, llvm_filecheck, llvm_profdata, rfs, run_with_args, rustc, shallow_find_files, }; diff --git a/tests/run-make/prefer-dylib/rmake.rs b/tests/run-make/prefer-dylib/rmake.rs index 0fed3e8725956..264d184a6c708 100644 --- a/tests/run-make/prefer-dylib/rmake.rs +++ b/tests/run-make/prefer-dylib/rmake.rs @@ -1,6 +1,6 @@ //@ ignore-cross-compile -use run_make_support::{dynamic_lib_name, fs as rfs, run, run_fail, rustc}; +use run_make_support::{dynamic_lib_name, rfs, run, run_fail, rustc}; fn main() { rustc().input("bar.rs").crate_type("dylib").crate_type("rlib").arg("-Cprefer-dynamic").run(); diff --git a/tests/run-make/prefer-rlib/rmake.rs b/tests/run-make/prefer-rlib/rmake.rs index 188db7c06028f..6d38282c2e395 100644 --- a/tests/run-make/prefer-rlib/rmake.rs +++ b/tests/run-make/prefer-rlib/rmake.rs @@ -3,7 +3,7 @@ //@ ignore-cross-compile -use run_make_support::{dynamic_lib_name, fs as rfs, path, run, rust_lib_name, rustc}; +use run_make_support::{dynamic_lib_name, path, rfs, run, rust_lib_name, rustc}; fn main() { rustc().input("bar.rs").crate_type("dylib").crate_type("rlib").run(); diff --git a/tests/run-make/pretty-print-with-dep-file/rmake.rs b/tests/run-make/pretty-print-with-dep-file/rmake.rs index 4b3d1c34faea1..d7a29ff7d19ba 100644 --- a/tests/run-make/pretty-print-with-dep-file/rmake.rs +++ b/tests/run-make/pretty-print-with-dep-file/rmake.rs @@ -5,7 +5,7 @@ // does not get an unexpected dep-info file. // See https://github.com/rust-lang/rust/issues/112898 -use run_make_support::{fs as rfs, invalid_utf8_contains, rustc}; +use run_make_support::{invalid_utf8_contains, rfs, rustc}; use std::path::Path; fn main() { diff --git a/tests/run-make/print-cfg/rmake.rs b/tests/run-make/print-cfg/rmake.rs index 73a03189cb241..d83e8a36f2c08 100644 --- a/tests/run-make/print-cfg/rmake.rs +++ b/tests/run-make/print-cfg/rmake.rs @@ -10,7 +10,7 @@ use std::ffi::OsString; use std::iter::FromIterator; use std::path::PathBuf; -use run_make_support::{fs as rfs, rustc}; +use run_make_support::{rfs, rustc}; struct PrintCfg { target: &'static str, diff --git a/tests/run-make/print-to-output/rmake.rs b/tests/run-make/print-to-output/rmake.rs index ecfd84f81bb3f..d0cba725b3679 100644 --- a/tests/run-make/print-to-output/rmake.rs +++ b/tests/run-make/print-to-output/rmake.rs @@ -4,7 +4,7 @@ use std::ffi::OsString; use std::path::PathBuf; -use run_make_support::{fs as rfs, rustc, target}; +use run_make_support::{rfs, rustc, target}; struct Option<'a> { target: &'a str, diff --git a/tests/run-make/remap-path-prefix/rmake.rs b/tests/run-make/remap-path-prefix/rmake.rs index 390db93e62d17..aeb30e72d5bf4 100644 --- a/tests/run-make/remap-path-prefix/rmake.rs +++ b/tests/run-make/remap-path-prefix/rmake.rs @@ -4,7 +4,7 @@ // See https://github.com/rust-lang/rust/pull/85344 use run_make_support::bstr::ByteSlice; -use run_make_support::{bstr, fs as rfs, is_darwin, rustc}; +use run_make_support::{bstr, is_darwin, rfs, rustc}; fn main() { let mut out_simple = rustc(); diff --git a/tests/run-make/repr128-dwarf/rmake.rs b/tests/run-make/repr128-dwarf/rmake.rs index 1c61698ffcd4e..824ca6e187608 100644 --- a/tests/run-make/repr128-dwarf/rmake.rs +++ b/tests/run-make/repr128-dwarf/rmake.rs @@ -3,7 +3,7 @@ use gimli::{AttributeValue, EndianRcSlice, Reader, RunTimeEndian}; use object::{Object, ObjectSection}; -use run_make_support::{fs as rfs, gimli, object, rustc}; +use run_make_support::{gimli, object, rfs, rustc}; use std::collections::HashMap; use std::path::PathBuf; use std::rc::Rc; diff --git a/tests/run-make/reset-codegen-1/rmake.rs b/tests/run-make/reset-codegen-1/rmake.rs index 18cf5513d5c02..cc6bb7d5e39c3 100644 --- a/tests/run-make/reset-codegen-1/rmake.rs +++ b/tests/run-make/reset-codegen-1/rmake.rs @@ -7,7 +7,7 @@ //@ ignore-cross-compile -use run_make_support::{bin_name, fs as rfs, rustc}; +use run_make_support::{bin_name, rfs, rustc}; use std::path::Path; fn compile(output_file: &str, emit: Option<&str>) { diff --git a/tests/run-make/resolve-rename/rmake.rs b/tests/run-make/resolve-rename/rmake.rs index cefd608177d7f..16ee7b0288569 100644 --- a/tests/run-make/resolve-rename/rmake.rs +++ b/tests/run-make/resolve-rename/rmake.rs @@ -5,7 +5,7 @@ // the renamed library. // See https://github.com/rust-lang/rust/pull/49253 -use run_make_support::fs as rfs; +use run_make_support::rfs; use run_make_support::rustc; fn main() { diff --git a/tests/run-make/rlib-chain/rmake.rs b/tests/run-make/rlib-chain/rmake.rs index 875de607a7b1d..306a472f47370 100644 --- a/tests/run-make/rlib-chain/rmake.rs +++ b/tests/run-make/rlib-chain/rmake.rs @@ -8,7 +8,7 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -use run_make_support::{fs as rfs, run, rust_lib_name, rustc}; +use run_make_support::{rfs, run, rust_lib_name, rustc}; fn main() { rustc().input("m1.rs").run(); diff --git a/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs b/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs index e769274670649..3feee78f2e154 100644 --- a/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs +++ b/tests/run-make/rustdoc-scrape-examples-remap/scrape.rs @@ -1,4 +1,4 @@ -use run_make_support::{fs as rfs, htmldocck, rustc, rustdoc, source_root}; +use run_make_support::{htmldocck, rfs, rustc, rustdoc, source_root}; use std::path::Path; pub fn scrape(extra_args: &[&str]) { diff --git a/tests/run-make/rustdoc-test-args/rmake.rs b/tests/run-make/rustdoc-test-args/rmake.rs index 57ff529d063d3..69dea83de4fee 100644 --- a/tests/run-make/rustdoc-test-args/rmake.rs +++ b/tests/run-make/rustdoc-test-args/rmake.rs @@ -1,4 +1,4 @@ -use run_make_support::{fs as rfs, rustdoc}; +use run_make_support::{rfs, rustdoc}; use std::iter; use std::path::Path; diff --git a/tests/run-make/rustdoc-themes/rmake.rs b/tests/run-make/rustdoc-themes/rmake.rs index 3a63ebbc20b53..981db358f29de 100644 --- a/tests/run-make/rustdoc-themes/rmake.rs +++ b/tests/run-make/rustdoc-themes/rmake.rs @@ -1,6 +1,6 @@ // Test that rustdoc will properly load in a theme file and display it in the theme selector. -use run_make_support::{fs as rfs, htmldocck, rustdoc, source_root}; +use run_make_support::{htmldocck, rfs, rustdoc, source_root}; use std::path::Path; fn main() { diff --git a/tests/run-make/rustdoc-verify-output-files/rmake.rs b/tests/run-make/rustdoc-verify-output-files/rmake.rs index 940503bf85fb9..d1ff2e330f539 100644 --- a/tests/run-make/rustdoc-verify-output-files/rmake.rs +++ b/tests/run-make/rustdoc-verify-output-files/rmake.rs @@ -1,4 +1,4 @@ -use run_make_support::fs as rfs; +use run_make_support::rfs; use std::path::{Path, PathBuf}; use run_make_support::{assert_dirs_are_equal, rustdoc}; diff --git a/tests/run-make/sepcomp-cci-copies/rmake.rs b/tests/run-make/sepcomp-cci-copies/rmake.rs index e05db252632cc..e244f54658073 100644 --- a/tests/run-make/sepcomp-cci-copies/rmake.rs +++ b/tests/run-make/sepcomp-cci-copies/rmake.rs @@ -5,7 +5,7 @@ // See https://github.com/rust-lang/rust/pull/16367 use run_make_support::{ - count_regex_matches_in_files_with_extension, cwd, fs as rfs, has_extension, regex, rustc, + count_regex_matches_in_files_with_extension, cwd, has_extension, regex, rfs, rustc, shallow_find_files, }; diff --git a/tests/run-make/sepcomp-inlining/rmake.rs b/tests/run-make/sepcomp-inlining/rmake.rs index c3e28c4198e78..b7a6bed05b846 100644 --- a/tests/run-make/sepcomp-inlining/rmake.rs +++ b/tests/run-make/sepcomp-inlining/rmake.rs @@ -6,7 +6,7 @@ // See https://github.com/rust-lang/rust/pull/16367 use run_make_support::{ - count_regex_matches_in_files_with_extension, cwd, fs as rfs, has_extension, regex, rustc, + count_regex_matches_in_files_with_extension, cwd, has_extension, regex, rfs, rustc, shallow_find_files, }; diff --git a/tests/run-make/sepcomp-separate/rmake.rs b/tests/run-make/sepcomp-separate/rmake.rs index 83fcd9490ecce..90017572c4c18 100644 --- a/tests/run-make/sepcomp-separate/rmake.rs +++ b/tests/run-make/sepcomp-separate/rmake.rs @@ -4,7 +4,7 @@ // See https://github.com/rust-lang/rust/pull/16367 use run_make_support::{ - count_regex_matches_in_files_with_extension, cwd, fs as rfs, has_extension, regex, rustc, + count_regex_matches_in_files_with_extension, cwd, has_extension, regex, rfs, rustc, shallow_find_files, }; diff --git a/tests/run-make/silly-file-names/rmake.rs b/tests/run-make/silly-file-names/rmake.rs index a883597e81c33..2acf2be864803 100644 --- a/tests/run-make/silly-file-names/rmake.rs +++ b/tests/run-make/silly-file-names/rmake.rs @@ -11,7 +11,7 @@ //@ ignore-windows // Reason: Windows refuses files with < and > in their names -use run_make_support::{diff, fs as rfs, run, rustc}; +use run_make_support::{diff, rfs, run, rustc}; fn main() { rfs::create_file("