From cbd613e7015c2d425379c3081336f841d31d484e Mon Sep 17 00:00:00 2001 From: joboet Date: Thu, 8 Feb 2024 12:41:46 +0100 Subject: [PATCH] std: move path into `sys` --- library/std/src/sys/mod.rs | 1 + library/std/src/sys/pal/hermit/mod.rs | 2 -- library/std/src/sys/pal/sgx/mod.rs | 1 - library/std/src/sys/pal/solid/mod.rs | 1 - library/std/src/sys/pal/teeos/mod.rs | 2 -- library/std/src/sys/pal/uefi/mod.rs | 1 - library/std/src/sys/pal/uefi/path.rs | 25 ------------------- library/std/src/sys/pal/unix/mod.rs | 1 - library/std/src/sys/pal/unsupported/mod.rs | 2 -- library/std/src/sys/pal/wasi/mod.rs | 2 -- library/std/src/sys/pal/wasm/mod.rs | 2 -- library/std/src/sys/pal/windows/fs.rs | 2 +- library/std/src/sys/pal/windows/mod.rs | 5 ++-- library/std/src/sys/pal/xous/mod.rs | 2 -- library/std/src/sys/pal/zkvm/mod.rs | 4 --- library/std/src/sys/path/mod.rs | 18 +++++++++++++ .../src/sys/{pal/sgx/path.rs => path/sgx.rs} | 0 .../sys/{pal/unix/path.rs => path/unix.rs} | 0 .../path.rs => path/unsupported_backslash.rs} | 0 .../{pal/windows/path.rs => path/windows.rs} | 4 +-- 20 files changed, 24 insertions(+), 51 deletions(-) delete mode 100644 library/std/src/sys/pal/uefi/path.rs create mode 100644 library/std/src/sys/path/mod.rs rename library/std/src/sys/{pal/sgx/path.rs => path/sgx.rs} (100%) rename library/std/src/sys/{pal/unix/path.rs => path/unix.rs} (100%) rename library/std/src/sys/{pal/solid/path.rs => path/unsupported_backslash.rs} (100%) rename library/std/src/sys/{pal/windows/path.rs => path/windows.rs} (99%) diff --git a/library/std/src/sys/mod.rs b/library/std/src/sys/mod.rs index e03e98b18d29f..fae21636897b8 100644 --- a/library/std/src/sys/mod.rs +++ b/library/std/src/sys/mod.rs @@ -7,6 +7,7 @@ mod personality; pub mod cmath; pub mod os_str; +pub mod path; // FIXME(117276): remove this, move feature implementations into individual // submodules. diff --git a/library/std/src/sys/pal/hermit/mod.rs b/library/std/src/sys/pal/hermit/mod.rs index 3c83afa280be5..57cc656e266a1 100644 --- a/library/std/src/sys/pal/hermit/mod.rs +++ b/library/std/src/sys/pal/hermit/mod.rs @@ -28,8 +28,6 @@ pub mod io; pub mod memchr; pub mod net; pub mod os; -#[path = "../unix/path.rs"] -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/sgx/mod.rs b/library/std/src/sys/pal/sgx/mod.rs index a769fc1ef5932..46f3e5b401da5 100644 --- a/library/std/src/sys/pal/sgx/mod.rs +++ b/library/std/src/sys/pal/sgx/mod.rs @@ -22,7 +22,6 @@ pub mod io; pub mod memchr; pub mod net; pub mod os; -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/solid/mod.rs b/library/std/src/sys/pal/solid/mod.rs index 46699e64169f5..be8e00339021f 100644 --- a/library/std/src/sys/pal/solid/mod.rs +++ b/library/std/src/sys/pal/solid/mod.rs @@ -29,7 +29,6 @@ pub mod fs; pub mod io; pub mod net; pub mod os; -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/teeos/mod.rs b/library/std/src/sys/pal/teeos/mod.rs index 95a5b97ea4237..7953104486c56 100644 --- a/library/std/src/sys/pal/teeos/mod.rs +++ b/library/std/src/sys/pal/teeos/mod.rs @@ -25,8 +25,6 @@ pub mod net; #[path = "../unsupported/once.rs"] pub mod once; pub mod os; -#[path = "../unix/path.rs"] -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/uefi/mod.rs b/library/std/src/sys/pal/uefi/mod.rs index 9ee753aa1a0c1..bc0d21129e293 100644 --- a/library/std/src/sys/pal/uefi/mod.rs +++ b/library/std/src/sys/pal/uefi/mod.rs @@ -26,7 +26,6 @@ pub mod net; #[path = "../unsupported/once.rs"] pub mod once; pub mod os; -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/uefi/path.rs b/library/std/src/sys/pal/uefi/path.rs deleted file mode 100644 index 106682eee56b6..0000000000000 --- a/library/std/src/sys/pal/uefi/path.rs +++ /dev/null @@ -1,25 +0,0 @@ -use super::unsupported; -use crate::ffi::OsStr; -use crate::io; -use crate::path::{Path, PathBuf, Prefix}; - -pub const MAIN_SEP_STR: &str = "\\"; -pub const MAIN_SEP: char = '\\'; - -#[inline] -pub fn is_sep_byte(b: u8) -> bool { - b == b'\\' -} - -#[inline] -pub fn is_verbatim_sep(b: u8) -> bool { - b == b'\\' -} - -pub fn parse_prefix(_p: &OsStr) -> Option> { - None -} - -pub(crate) fn absolute(_path: &Path) -> io::Result { - unsupported() -} diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index 43cb9d89be9dd..976a437c17ff9 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -27,7 +27,6 @@ pub mod net; #[cfg(target_os = "l4re")] pub use self::l4re::net; pub mod os; -pub mod path; pub mod pipe; pub mod process; pub mod rand; diff --git a/library/std/src/sys/pal/unsupported/mod.rs b/library/std/src/sys/pal/unsupported/mod.rs index b56ded8579c4d..88f939cbab924 100644 --- a/library/std/src/sys/pal/unsupported/mod.rs +++ b/library/std/src/sys/pal/unsupported/mod.rs @@ -9,8 +9,6 @@ pub mod locks; pub mod net; pub mod once; pub mod os; -#[path = "../unix/path.rs"] -pub mod path; pub mod pipe; pub mod process; pub mod stdio; diff --git a/library/std/src/sys/pal/wasi/mod.rs b/library/std/src/sys/pal/wasi/mod.rs index 4ffc8ecdd67ee..116878ee99681 100644 --- a/library/std/src/sys/pal/wasi/mod.rs +++ b/library/std/src/sys/pal/wasi/mod.rs @@ -30,8 +30,6 @@ pub mod io; pub mod net; pub mod os; -#[path = "../unix/path.rs"] -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/wasm/mod.rs b/library/std/src/sys/pal/wasm/mod.rs index 76306b618d82b..567555118d707 100644 --- a/library/std/src/sys/pal/wasm/mod.rs +++ b/library/std/src/sys/pal/wasm/mod.rs @@ -28,8 +28,6 @@ pub mod io; pub mod net; #[path = "../unsupported/os.rs"] pub mod os; -#[path = "../unix/path.rs"] -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/windows/fs.rs b/library/std/src/sys/pal/windows/fs.rs index 2bdd3d96fa48c..b82a83ae7a3e8 100644 --- a/library/std/src/sys/pal/windows/fs.rs +++ b/library/std/src/sys/pal/windows/fs.rs @@ -16,8 +16,8 @@ use crate::sys::{c, cvt, Align8}; use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::thread; -use super::path::maybe_verbatim; use super::{api, to_u16s, IoResult}; +use crate::sys::path::maybe_verbatim; pub struct File { handle: Handle, diff --git a/library/std/src/sys/pal/windows/mod.rs b/library/std/src/sys/pal/windows/mod.rs index 364521dba40ac..726a4509f280f 100644 --- a/library/std/src/sys/pal/windows/mod.rs +++ b/library/std/src/sys/pal/windows/mod.rs @@ -23,7 +23,6 @@ pub mod locks; pub mod memchr; pub mod net; pub mod os; -pub mod path; pub mod pipe; pub mod process; pub mod rand; @@ -210,7 +209,7 @@ pub fn to_u16s>(s: S) -> crate::io::Result> { // Once the syscall has completed (errors bail out early) the second closure is // yielded the data which has been read from the syscall. The return value // from this closure is then the return value of the function. -fn fill_utf16_buf(mut f1: F1, f2: F2) -> crate::io::Result +pub fn fill_utf16_buf(mut f1: F1, f2: F2) -> crate::io::Result where F1: FnMut(*mut u16, c::DWORD) -> c::DWORD, F2: FnOnce(&[u16]) -> T, @@ -274,7 +273,7 @@ where } } -fn os2path(s: &[u16]) -> PathBuf { +pub fn os2path(s: &[u16]) -> PathBuf { PathBuf::from(OsString::from_wide(s)) } diff --git a/library/std/src/sys/pal/xous/mod.rs b/library/std/src/sys/pal/xous/mod.rs index b4948d7e583b4..c9bad4ef019b5 100644 --- a/library/std/src/sys/pal/xous/mod.rs +++ b/library/std/src/sys/pal/xous/mod.rs @@ -12,8 +12,6 @@ pub mod io; pub mod locks; pub mod net; pub mod os; -#[path = "../unix/path.rs"] -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/pal/zkvm/mod.rs b/library/std/src/sys/pal/zkvm/mod.rs index 7f221dc4fd98a..e859269831aa9 100644 --- a/library/std/src/sys/pal/zkvm/mod.rs +++ b/library/std/src/sys/pal/zkvm/mod.rs @@ -24,10 +24,6 @@ pub mod net; #[path = "../unsupported/once.rs"] pub mod once; pub mod os; -#[path = "../unix/os_str.rs"] -pub mod os_str; -#[path = "../unix/path.rs"] -pub mod path; #[path = "../unsupported/pipe.rs"] pub mod pipe; #[path = "../unsupported/process.rs"] diff --git a/library/std/src/sys/path/mod.rs b/library/std/src/sys/path/mod.rs new file mode 100644 index 0000000000000..24a94ec782824 --- /dev/null +++ b/library/std/src/sys/path/mod.rs @@ -0,0 +1,18 @@ +cfg_if::cfg_if! { + if #[cfg(target_os = "windows")] { + mod windows; + pub use windows::*; + } else if #[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] { + mod sgx; + pub use sgx::*; + } else if #[cfg(any( + target_os = "uefi", + target_os = "solid_asp3", + ))] { + mod unsupported_backslash; + pub use unsupported_backslash::*; + } else { + mod unix; + pub use unix::*; + } +} diff --git a/library/std/src/sys/pal/sgx/path.rs b/library/std/src/sys/path/sgx.rs similarity index 100% rename from library/std/src/sys/pal/sgx/path.rs rename to library/std/src/sys/path/sgx.rs diff --git a/library/std/src/sys/pal/unix/path.rs b/library/std/src/sys/path/unix.rs similarity index 100% rename from library/std/src/sys/pal/unix/path.rs rename to library/std/src/sys/path/unix.rs diff --git a/library/std/src/sys/pal/solid/path.rs b/library/std/src/sys/path/unsupported_backslash.rs similarity index 100% rename from library/std/src/sys/pal/solid/path.rs rename to library/std/src/sys/path/unsupported_backslash.rs diff --git a/library/std/src/sys/pal/windows/path.rs b/library/std/src/sys/path/windows.rs similarity index 99% rename from library/std/src/sys/pal/windows/path.rs rename to library/std/src/sys/path/windows.rs index d9684f2175313..cebc791023115 100644 --- a/library/std/src/sys/pal/windows/path.rs +++ b/library/std/src/sys/path/windows.rs @@ -1,8 +1,8 @@ -use super::{c, fill_utf16_buf, to_u16s}; use crate::ffi::{OsStr, OsString}; use crate::io; use crate::path::{Path, PathBuf, Prefix}; use crate::ptr; +use crate::sys::pal::{c, fill_utf16_buf, os2path, to_u16s}; #[cfg(test)] mod tests; @@ -339,6 +339,6 @@ pub(crate) fn absolute(path: &Path) -> io::Result { // `lpfilename` is a pointer to a null terminated string that is not // invalidated until after `GetFullPathNameW` returns successfully. |buffer, size| unsafe { c::GetFullPathNameW(lpfilename, size, buffer, ptr::null_mut()) }, - super::os2path, + os2path, ) }