From 25592d9a5c005fd5bf8c7976ca47a221ad7ea603 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 18 Jul 2017 16:32:35 -0700 Subject: [PATCH 01/84] Initial --- Cargo.toml | 16 +++ README.md | 20 ++++ src/lib.rs | 278 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+) create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 src/lib.rs diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000000..aa5a4b7a22d --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "home" +version = "0.1.0" +authors = [ "Brian Anderson " ] +description = "Shared definitions of home directories" +documentation = "https://docs.rs/home" +repository = "https://github.com/brson/home" +license = "MIT/Apache-2.0" + +[target."cfg(windows)".dependencies] +scopeguard = "0.1.2" +winapi = "0.2.8" +kernel32-sys = "0.2.1" +advapi32-sys = "0.2.0" +userenv-sys = "0.2.0" + diff --git a/README.md b/README.md new file mode 100644 index 00000000000..c8058974ea4 --- /dev/null +++ b/README.md @@ -0,0 +1,20 @@ +Canonical definitions of `home_dir`, `cargo_home`, and `rustup_home`. + +This provides the definition of `home_dir` used by Cargo and rustup, +as well functions to find the correct value of `CARGO_HOME` and +`RUSTUP_HOME`. + +The definition of `home_dir` provided by the standard library is +incorrect because it considers the `HOME` environment variable on +Windows. This causes surprising situations where a Rust program will +behave differently depending on whether it is run under a Unix +emulation environment like Cygwin or MinGW. Neither Cargo nor rustup +use the standard libraries definition - they use the definition here. + +This crate further provides two functions, `cargo_home` and +`rustup_home`, which are the canonical way to determine the location +that Cargo and rustup store their data. + +## License + +MIT/Apache-2.0 diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 00000000000..47c557cc227 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,278 @@ +/// Canonical definitions of `home_dir`, `cargo_home`, and `rustup_home`. +/// +/// This provides the definition of `home_dir` used by Cargo and +/// rustup, as well functions to find the correct value of +/// `CARGO_HOME` and `RUSTUP_HOME`. +/// +/// The definition of `home_dir` provided by the standard library is +/// incorrect because it considers the `HOME` environment variable on +/// Windows. This causes surprising situations where a Rust program +/// will behave differently depending on whether it is run under a +/// Unix emulation environment like Cygwin or MinGW. Neither Cargo nor +/// rustup use the standard libraries definition - they use the +/// definition here. +/// +/// This crate further provides two functions, `cargo_home` and +/// `rustup_home`, which are the canonical way to determine the +/// location that Cargo and rustup store their data. + +#[cfg(windows)] +extern crate scopeguard; +#[cfg(windows)] +extern crate winapi; +#[cfg(windows)] +extern crate kernel32; +#[cfg(windows)] +extern crate advapi32; +#[cfg(windows)] +extern crate userenv; + +#[cfg(windows)] +use winapi::DWORD; +use std::path::PathBuf; +use std::io; +use std::env; + +/// Returns the path of the current user's home directory if known. +/// +/// # Unix +/// +/// Returns the value of the 'HOME' environment variable if it is set +/// and not equal to the empty string. Otherwise, it tries to determine the +/// home directory by invoking the `getpwuid_r` function on the UID of the +/// current user. +/// +/// # Windows +/// +/// Returns the value of the 'USERPROFILE' environment variable if it +/// is set and not equal to the empty string. If both do not exist, +/// [`GetUserProfileDirectory`][msdn] is used to return the +/// appropriate path. +/// +/// [msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762280(v=vs.85).aspx +/// +/// # Examples +/// +/// ``` +/// use std::env; +/// +/// match env::home_dir() { +/// Some(path) => println!("{}", path.display()), +/// None => println!("Impossible to get your home dir!"), +/// } +/// ``` +pub fn home_dir() -> Option { + home_dir_() +} + +#[cfg(windows)] +fn home_dir_() -> Option { + use std::ptr; + use kernel32::{GetCurrentProcess, GetLastError, CloseHandle}; + use advapi32::OpenProcessToken; + use userenv::GetUserProfileDirectoryW; + use winapi::ERROR_INSUFFICIENT_BUFFER; + use winapi::winnt::TOKEN_READ; + use scopeguard; + + ::std::env::var_os("USERPROFILE").map(PathBuf::from).or_else(|| unsafe { + let me = GetCurrentProcess(); + let mut token = ptr::null_mut(); + if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { + return None; + } + let _g = scopeguard::guard(token, |h| { let _ = CloseHandle(*h); }); + fill_utf16_buf(|buf, mut sz| { + match GetUserProfileDirectoryW(token, buf, &mut sz) { + 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, + 0 => sz, + _ => sz - 1, // sz includes the null terminator + } + }, os2path).ok() + }) +} + +#[cfg(windows)] +fn os2path(s: &[u16]) -> PathBuf { + use std::ffi::OsString; + use std::os::windows::ffi::OsStringExt; + PathBuf::from(OsString::from_wide(s)) +} + +#[cfg(windows)] +fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result + where F1: FnMut(*mut u16, DWORD) -> DWORD, + F2: FnOnce(&[u16]) -> T +{ + use kernel32::{GetLastError, SetLastError}; + use winapi::{ERROR_INSUFFICIENT_BUFFER}; + + // Start off with a stack buf but then spill over to the heap if we end up + // needing more space. + let mut stack_buf = [0u16; 512]; + let mut heap_buf = Vec::new(); + unsafe { + let mut n = stack_buf.len(); + loop { + let buf = if n <= stack_buf.len() { + &mut stack_buf[..] + } else { + let extra = n - heap_buf.len(); + heap_buf.reserve(extra); + heap_buf.set_len(n); + &mut heap_buf[..] + }; + + // This function is typically called on windows API functions which + // will return the correct length of the string, but these functions + // also return the `0` on error. In some cases, however, the + // returned "correct length" may actually be 0! + // + // To handle this case we call `SetLastError` to reset it to 0 and + // then check it again if we get the "0 error value". If the "last + // error" is still 0 then we interpret it as a 0 length buffer and + // not an actual error. + SetLastError(0); + let k = match f1(buf.as_mut_ptr(), n as DWORD) { + 0 if GetLastError() == 0 => 0, + 0 => return Err(io::Error::last_os_error()), + n => n, + } as usize; + if k == n && GetLastError() == ERROR_INSUFFICIENT_BUFFER { + n *= 2; + } else if k >= n { + n = k; + } else { + return Ok(f2(&buf[..k])) + } + } + } +} + +#[cfg(unix)] +fn home_dir_() -> Option { + ::std::env::home_dir() +} + +/// Returns the storage directory used by Cargo, often knowns as +/// `.cargo` or `CARGO_HOME`. +/// +/// It returns one of the following values, in this order of +/// preference: +/// +/// - The value of the `CARGO_HOME` environment variable, if it is +/// an absolute path. +/// - The value of the current working directory joined with the value +/// of the `CARGO_HOME` environment variable, if `CARGO_HOME` is a +/// relative directory. +/// - The `.cargo` directory in the user's home directory, as reported +/// by the `home_dir` function. +/// +/// # Errors +/// +/// This function fails if it fails to retrieve the current directory, +/// or if the home directory cannot be determined. +pub fn cargo_home() -> io::Result { + let env_var = env::var_os("CARGO_HOME"); + + // NB: During the multirust-rs -> rustup transition the install + // dir changed from ~/.multirust/bin to ~/.cargo/bin. Because + // multirust used to explicitly set CARGO_HOME it's possible to + // get here when e.g. installing under `cargo run` and decide to + // install to the wrong place. This check is to make the + // multirust-rs to rustup upgrade seamless. + let env_var = if let Some(v) = env_var { + let vv = v.to_string_lossy().to_string(); + if vv.contains(".multirust/cargo") || + vv.contains(r".multirust\cargo") || + vv.trim().is_empty() { + None + } else { + Some(v) + } + } else { + None + }; + + let cwd = env::current_dir()?; + let env_cargo_home = env_var.map(|home| cwd.join(home)); + let home_dir = home_dir() + .ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); + let user_home = home_dir.map(|p| p.join(".cargo")); + + if let Some(p) = env_cargo_home { + Ok(p) + } else { + user_home + } +} + +/// Returns the storage directory used by rustup, often knowns as +/// `.rustup` or `RUSTUP_HOME`. +/// +/// It returns one of the following values, in this order of +/// preference: +/// +/// - The value of the `RUSTUP_HOME` environment variable, if it is +/// an absolute path. +/// - The value of the current working directory joined with the value +/// of the `RUSTUP_HOME` environment variable, if `RUSTUP_HOME` is a +/// relative directory. +/// - The `.rustup` directory in the user's home directory, as reported +/// by the `home_dir` function. +/// +/// As a matter of backwards compatibility, this function _may_ return +/// the `.multirust` directory in the user's home directory, only if +/// it determines that the user is running an old version of rustup +/// where that is necessary. +/// +/// # Errors +/// +/// This function fails if it fails to retrieve the current directory, +/// or if the home directory cannot be determined. +pub fn rustup_home() -> io::Result { + let env_var = env::var_os("RUSTUP_HOME"); + let cwd = env::current_dir()?; + let env_rustup_home = env_var.map(|home| cwd.join(home)); + let home_dir = home_dir() + .ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); + + let user_home = if use_rustup_dir() { + home_dir.map(|d| d.join(".rustup")) + } else { + home_dir.map(|d| d.join(".multirust")) + }; + + if let Some(p) = env_rustup_home { + Ok(p) + } else { + user_home + } +} + +fn use_rustup_dir() -> bool { + fn rustup_dir() -> Option { + home_dir().map(|p| p.join(".rustup")) + } + + fn multirust_dir() -> Option { + home_dir().map(|p| p.join(".multirust")) + } + + fn rustup_dir_exists() -> bool { + rustup_dir().map(|p| p.exists()).unwrap_or(false) + } + + fn multirust_dir_exists() -> bool { + multirust_dir().map(|p| p.exists()).unwrap_or(false) + } + + fn rustup_old_version_exists() -> bool { + rustup_dir() + .map(|p| p.join("rustup-version").exists()) + .unwrap_or(false) + } + + !rustup_old_version_exists() + && (rustup_dir_exists() || !multirust_dir_exists()) +} From b1a9fe1f88f20071ede29d536b0e7b3f946484bb Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 18 Jul 2017 16:35:51 -0700 Subject: [PATCH 02/84] Link to upstream issue --- README.md | 4 ++++ src/lib.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index c8058974ea4..2ff22423e38 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ This crate further provides two functions, `cargo_home` and `rustup_home`, which are the canonical way to determine the location that Cargo and rustup store their data. +See [rust-lang/rust#43321]. + +[rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 + ## License MIT/Apache-2.0 diff --git a/src/lib.rs b/src/lib.rs index 47c557cc227..509577b56e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,10 @@ /// This crate further provides two functions, `cargo_home` and /// `rustup_home`, which are the canonical way to determine the /// location that Cargo and rustup store their data. +/// +/// See [rust-lang/rust#43321]. +/// +/// [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 #[cfg(windows)] extern crate scopeguard; From cf5dd418fc02a6d6168def44756d756d2198589f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 18 Jul 2017 17:09:52 -0700 Subject: [PATCH 03/84] Add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000000..9f970225adb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file From 759a15b8aeb3a23ec31c7a87db919bdd33b13739 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 18 Jul 2017 17:10:07 -0700 Subject: [PATCH 04/84] Add cwd-accepting versions of cargo_home and rustup_home --- Cargo.toml | 2 +- src/lib.rs | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa5a4b7a22d..d2eed3e1de4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.1.0" +version = "0.2.0" authors = [ "Brian Anderson " ] description = "Shared definitions of home directories" documentation = "https://docs.rs/home" diff --git a/src/lib.rs b/src/lib.rs index 509577b56e0..49906084a5c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,7 +33,7 @@ extern crate userenv; #[cfg(windows)] use winapi::DWORD; -use std::path::PathBuf; +use std::path::{PathBuf, Path}; use std::io; use std::env; @@ -177,6 +177,11 @@ fn home_dir_() -> Option { /// This function fails if it fails to retrieve the current directory, /// or if the home directory cannot be determined. pub fn cargo_home() -> io::Result { + let cwd = env::current_dir()?; + cargo_home_with_cwd(&cwd) +} + +pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { let env_var = env::var_os("CARGO_HOME"); // NB: During the multirust-rs -> rustup transition the install @@ -198,7 +203,6 @@ pub fn cargo_home() -> io::Result { None }; - let cwd = env::current_dir()?; let env_cargo_home = env_var.map(|home| cwd.join(home)); let home_dir = home_dir() .ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); @@ -235,8 +239,12 @@ pub fn cargo_home() -> io::Result { /// This function fails if it fails to retrieve the current directory, /// or if the home directory cannot be determined. pub fn rustup_home() -> io::Result { - let env_var = env::var_os("RUSTUP_HOME"); let cwd = env::current_dir()?; + rustup_home_with_cwd(&cwd) +} + +pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { + let env_var = env::var_os("RUSTUP_HOME"); let env_rustup_home = env_var.map(|home| cwd.join(home)); let home_dir = home_dir() .ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); From c6432703f9a0f0a10d71d0962866186c8af7eedf Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 18 Jul 2017 17:23:33 -0700 Subject: [PATCH 05/84] Add cargo compat code --- Cargo.toml | 2 +- src/lib.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d2eed3e1de4..000046826a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.2.0" +version = "0.3.0" authors = [ "Brian Anderson " ] description = "Shared definitions of home directories" documentation = "https://docs.rs/home" diff --git a/src/lib.rs b/src/lib.rs index 49906084a5c..0917964b050 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,10 +208,22 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { .ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); let user_home = home_dir.map(|p| p.join(".cargo")); + // Compatibility with old cargo that used the std definition of home_dir + let compat_home_dir = ::std::env::home_dir(); + let compat_user_home = compat_home_dir.map(|p| p.join(".cargo")); + if let Some(p) = env_cargo_home { Ok(p) } else { - user_home + if let Some(d) = compat_user_home { + if d.exists() { + Ok(d) + } else { + user_home + } + } else { + user_home + } } } From abf65ad79ee8f927859e4cde88acc1475dde7332 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Sun, 30 Jul 2017 16:02:16 -0700 Subject: [PATCH 06/84] Redox OS --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0917964b050..779df86cc53 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,7 +153,7 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result } } -#[cfg(unix)] +#[cfg(any(unix, target_os = "redox"))] fn home_dir_() -> Option { ::std::env::home_dir() } From c10b8d2ab3f8d8dd80627cf19e9ff6917f086f0a Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 2 Mar 2018 17:12:38 +0100 Subject: [PATCH 07/84] Bump scopeguard to 0.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 000046826a0..8336b6a6e0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/brson/home" license = "MIT/Apache-2.0" [target."cfg(windows)".dependencies] -scopeguard = "0.1.2" +scopeguard = "0.3" winapi = "0.2.8" kernel32-sys = "0.2.1" advapi32-sys = "0.2.0" From 1825f0a437a62593da418c1593283561eaea43e1 Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 2 Mar 2018 17:19:26 +0100 Subject: [PATCH 08/84] Bump winapi to 0.3 --- Cargo.toml | 4 +--- src/lib.rs | 19 ++++++++----------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8336b6a6e0e..c6d36e0671e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,6 @@ license = "MIT/Apache-2.0" [target."cfg(windows)".dependencies] scopeguard = "0.3" -winapi = "0.2.8" -kernel32-sys = "0.2.1" -advapi32-sys = "0.2.0" +winapi = { version = "0.3", features = ["errhandlingapi", "handleapi", "processthreadsapi", "std", "winerror", "winnt"] } userenv-sys = "0.2.0" diff --git a/src/lib.rs b/src/lib.rs index 0917964b050..bdc124b22e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,14 +25,10 @@ extern crate scopeguard; #[cfg(windows)] extern crate winapi; #[cfg(windows)] -extern crate kernel32; -#[cfg(windows)] -extern crate advapi32; -#[cfg(windows)] extern crate userenv; #[cfg(windows)] -use winapi::DWORD; +use winapi::shared::minwindef::DWORD; use std::path::{PathBuf, Path}; use std::io; use std::env; @@ -72,11 +68,12 @@ pub fn home_dir() -> Option { #[cfg(windows)] fn home_dir_() -> Option { use std::ptr; - use kernel32::{GetCurrentProcess, GetLastError, CloseHandle}; - use advapi32::OpenProcessToken; use userenv::GetUserProfileDirectoryW; - use winapi::ERROR_INSUFFICIENT_BUFFER; - use winapi::winnt::TOKEN_READ; + use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; + use winapi::um::errhandlingapi::GetLastError; + use winapi::um::handleapi::CloseHandle; + use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken}; + use winapi::um::winnt::TOKEN_READ; use scopeguard; ::std::env::var_os("USERPROFILE").map(PathBuf::from).or_else(|| unsafe { @@ -108,8 +105,8 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result where F1: FnMut(*mut u16, DWORD) -> DWORD, F2: FnOnce(&[u16]) -> T { - use kernel32::{GetLastError, SetLastError}; - use winapi::{ERROR_INSUFFICIENT_BUFFER}; + use winapi::um::errhandlingapi::{GetLastError, SetLastError}; + use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; // Start off with a stack buf but then spill over to the heap if we end up // needing more space. From bfaf1f14b2e9348b9af432e84947bcb72fe3b10a Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Fri, 2 Mar 2018 17:19:36 +0100 Subject: [PATCH 09/84] Bump version number --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c6d36e0671e..411ae3b419a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.3.0" +version = "0.3.1" authors = [ "Brian Anderson " ] description = "Shared definitions of home directories" documentation = "https://docs.rs/home" From 5673c9aa67536225f9ef6eb6d8f00113f7aa2ae1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 19 Mar 2018 13:06:23 -0700 Subject: [PATCH 10/84] Bump to 0.3.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 411ae3b419a..863a4dada26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.3.1" +version = "0.3.2" authors = [ "Brian Anderson " ] description = "Shared definitions of home directories" documentation = "https://docs.rs/home" From 152407f2dbac5a10ea0b0409ce73b52b4c827a3f Mon Sep 17 00:00:00 2001 From: Andreas Jonson Date: Thu, 10 May 2018 11:09:56 +0200 Subject: [PATCH 11/84] Depend on only one version of winapi --- Cargo.toml | 3 +-- src/lib.rs | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 863a4dada26..ede5385be6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,5 @@ license = "MIT/Apache-2.0" [target."cfg(windows)".dependencies] scopeguard = "0.3" -winapi = { version = "0.3", features = ["errhandlingapi", "handleapi", "processthreadsapi", "std", "winerror", "winnt"] } -userenv-sys = "0.2.0" +winapi = { version = "0.3", features = ["errhandlingapi", "handleapi", "processthreadsapi", "std", "winerror", "winnt", "userenv"] } diff --git a/src/lib.rs b/src/lib.rs index bdc124b22e1..3880f783772 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,8 +24,6 @@ extern crate scopeguard; #[cfg(windows)] extern crate winapi; -#[cfg(windows)] -extern crate userenv; #[cfg(windows)] use winapi::shared::minwindef::DWORD; @@ -68,7 +66,7 @@ pub fn home_dir() -> Option { #[cfg(windows)] fn home_dir_() -> Option { use std::ptr; - use userenv::GetUserProfileDirectoryW; + use winapi::um::userenv::GetUserProfileDirectoryW; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; use winapi::um::errhandlingapi::GetLastError; use winapi::um::handleapi::CloseHandle; From 5744640b4d911c1e08a1be8223f8ab76ec112f79 Mon Sep 17 00:00:00 2001 From: Andreas Jonson Date: Fri, 11 May 2018 11:29:48 +0200 Subject: [PATCH 12/84] Bump to 0.3.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ede5385be6e..0fd91fec806 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.3.2" +version = "0.3.3" authors = [ "Brian Anderson " ] description = "Shared definitions of home directories" documentation = "https://docs.rs/home" From f5dd969b79b14519a1b2364e8bcc4b106ceb4b82 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2019 17:33:59 +0700 Subject: [PATCH 13/84] cargo: Split winapi to separate table --- Cargo.toml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0fd91fec806..b318f7d1e29 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,5 +9,15 @@ license = "MIT/Apache-2.0" [target."cfg(windows)".dependencies] scopeguard = "0.3" -winapi = { version = "0.3", features = ["errhandlingapi", "handleapi", "processthreadsapi", "std", "winerror", "winnt", "userenv"] } +[target."cfg(windows)".dependencies.winapi] +version = "0.3" +features = [ + "errhandlingapi", + "handleapi", + "processthreadsapi", + "std", + "winerror", + "winnt", + "userenv", +] From 71afeb233911a8414ae0a3039b238348aba8810b Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2019 17:35:10 +0700 Subject: [PATCH 14/84] cargo: Bump scopeguard to 1.0.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b318f7d1e29..19864dead4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/brson/home" license = "MIT/Apache-2.0" [target."cfg(windows)".dependencies] -scopeguard = "0.3" +scopeguard = "1" [target."cfg(windows)".dependencies.winapi] version = "0.3" From 41fb21b9169312f42c489c481a1d7c47ae2b3475 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2019 17:41:34 +0700 Subject: [PATCH 15/84] Update to 2018 edition --- Cargo.toml | 5 +++-- src/lib.rs | 57 ++++++++++++++++++++++++++---------------------------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 19864dead4e..368f034fba2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,10 +2,11 @@ name = "home" version = "0.3.3" authors = [ "Brian Anderson " ] -description = "Shared definitions of home directories" documentation = "https://docs.rs/home" -repository = "https://github.com/brson/home" +edition = "2018" license = "MIT/Apache-2.0" +repository = "https://github.com/brson/home" +description = "Shared definitions of home directories" [target."cfg(windows)".dependencies] scopeguard = "1" diff --git a/src/lib.rs b/src/lib.rs index 9e31a3e971f..297b0ac823b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,29 +1,26 @@ -/// Canonical definitions of `home_dir`, `cargo_home`, and `rustup_home`. -/// -/// This provides the definition of `home_dir` used by Cargo and -/// rustup, as well functions to find the correct value of -/// `CARGO_HOME` and `RUSTUP_HOME`. -/// -/// The definition of `home_dir` provided by the standard library is -/// incorrect because it considers the `HOME` environment variable on -/// Windows. This causes surprising situations where a Rust program -/// will behave differently depending on whether it is run under a -/// Unix emulation environment like Cygwin or MinGW. Neither Cargo nor -/// rustup use the standard libraries definition - they use the -/// definition here. -/// -/// This crate further provides two functions, `cargo_home` and -/// `rustup_home`, which are the canonical way to determine the -/// location that Cargo and rustup store their data. -/// -/// See [rust-lang/rust#43321]. -/// -/// [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 +//! Canonical definitions of `home_dir`, `cargo_home`, and `rustup_home`. +//! +//! This provides the definition of `home_dir` used by Cargo and +//! rustup, as well functions to find the correct value of +//! `CARGO_HOME` and `RUSTUP_HOME`. +//! +//! The definition of `home_dir` provided by the standard library is +//! incorrect because it considers the `HOME` environment variable on +//! Windows. This causes surprising situations where a Rust program +//! will behave differently depending on whether it is run under a +//! Unix emulation environment like Cygwin or MinGW. Neither Cargo nor +//! rustup use the standard libraries definition - they use the +//! definition here. +//! +//! This crate further provides two functions, `cargo_home` and +//! `rustup_home`, which are the canonical way to determine the +//! location that Cargo and rustup store their data. +//! +//! See [rust-lang/rust#43321]. +//! +//! [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 -#[cfg(windows)] -extern crate scopeguard; -#[cfg(windows)] -extern crate winapi; +#![deny(rust_2018_idioms)] #[cfg(windows)] use winapi::shared::minwindef::DWORD; @@ -74,7 +71,7 @@ fn home_dir_() -> Option { use winapi::um::winnt::TOKEN_READ; use scopeguard; - ::std::env::var_os("USERPROFILE").map(PathBuf::from).or_else(|| unsafe { + std::env::var_os("USERPROFILE").map(PathBuf::from).or_else(|| unsafe { let me = GetCurrentProcess(); let mut token = ptr::null_mut(); if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { @@ -150,7 +147,7 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result #[cfg(any(unix, target_os = "redox"))] fn home_dir_() -> Option { - ::std::env::home_dir() + std::env::home_dir() } /// Returns the storage directory used by Cargo, often knowns as @@ -204,9 +201,9 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { let user_home = home_dir.map(|p| p.join(".cargo")); // Compatibility with old cargo that used the std definition of home_dir - let compat_home_dir = ::std::env::home_dir(); + let compat_home_dir = std::env::home_dir(); let compat_user_home = compat_home_dir.map(|p| p.join(".cargo")); - + if let Some(p) = env_cargo_home { Ok(p) } else { @@ -215,7 +212,7 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { Ok(d) } else { user_home - } + } } else { user_home } From 2a4ac15b273f76fb06aaa47d69001be8d266b964 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2019 18:51:46 +0700 Subject: [PATCH 16/84] Lazy ok_or_else --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 297b0ac823b..cfbbf5572f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -197,7 +197,7 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { let env_cargo_home = env_var.map(|home| cwd.join(home)); let home_dir = home_dir() - .ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); let user_home = home_dir.map(|p| p.join(".cargo")); // Compatibility with old cargo that used the std definition of home_dir @@ -251,7 +251,7 @@ pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { let env_var = env::var_os("RUSTUP_HOME"); let env_rustup_home = env_var.map(|home| cwd.join(home)); let home_dir = home_dir() - .ok_or(io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); let user_home = if use_rustup_dir() { home_dir.map(|d| d.join(".rustup")) From 72d8872255d1d2a29521573b31bd7a30dccc53e4 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2019 19:01:31 +0700 Subject: [PATCH 17/84] Lazy calculate user_home --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cfbbf5572f3..edb33a98724 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -250,19 +250,19 @@ pub fn rustup_home() -> io::Result { pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { let env_var = env::var_os("RUSTUP_HOME"); let env_rustup_home = env_var.map(|home| cwd.join(home)); - let home_dir = home_dir() + let home_dir = || home_dir() .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); - let user_home = if use_rustup_dir() { - home_dir.map(|d| d.join(".rustup")) + let user_home = || if use_rustup_dir() { + home_dir().map(|d| d.join(".rustup")) } else { - home_dir.map(|d| d.join(".multirust")) + home_dir().map(|d| d.join(".multirust")) }; if let Some(p) = env_rustup_home { Ok(p) } else { - user_home + user_home() } } From f39302f432f62e29910c876f766eb8a324cee843 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 1 Jun 2019 19:01:52 +0700 Subject: [PATCH 18/84] cargo fmt --- src/lib.rs | 93 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index edb33a98724..0d41d8c5c8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,11 +22,11 @@ #![deny(rust_2018_idioms)] +use std::env; +use std::io; +use std::path::{Path, PathBuf}; #[cfg(windows)] use winapi::shared::minwindef::DWORD; -use std::path::{PathBuf, Path}; -use std::io; -use std::env; /// Returns the path of the current user's home directory if known. /// @@ -62,30 +62,38 @@ pub fn home_dir() -> Option { #[cfg(windows)] fn home_dir_() -> Option { + use scopeguard; use std::ptr; - use winapi::um::userenv::GetUserProfileDirectoryW; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; use winapi::um::errhandlingapi::GetLastError; use winapi::um::handleapi::CloseHandle; use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken}; + use winapi::um::userenv::GetUserProfileDirectoryW; use winapi::um::winnt::TOKEN_READ; - use scopeguard; - std::env::var_os("USERPROFILE").map(PathBuf::from).or_else(|| unsafe { - let me = GetCurrentProcess(); - let mut token = ptr::null_mut(); - if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { - return None; - } - let _g = scopeguard::guard(token, |h| { let _ = CloseHandle(*h); }); - fill_utf16_buf(|buf, mut sz| { - match GetUserProfileDirectoryW(token, buf, &mut sz) { - 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, - 0 => sz, - _ => sz - 1, // sz includes the null terminator + std::env::var_os("USERPROFILE") + .map(PathBuf::from) + .or_else(|| unsafe { + let me = GetCurrentProcess(); + let mut token = ptr::null_mut(); + if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { + return None; } - }, os2path).ok() - }) + let _g = scopeguard::guard(token, |h| { + let _ = CloseHandle(*h); + }); + fill_utf16_buf( + |buf, mut sz| { + match GetUserProfileDirectoryW(token, buf, &mut sz) { + 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, + 0 => sz, + _ => sz - 1, // sz includes the null terminator + } + }, + os2path, + ) + .ok() + }) } #[cfg(windows)] @@ -97,11 +105,12 @@ fn os2path(s: &[u16]) -> PathBuf { #[cfg(windows)] fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result - where F1: FnMut(*mut u16, DWORD) -> DWORD, - F2: FnOnce(&[u16]) -> T +where + F1: FnMut(*mut u16, DWORD) -> DWORD, + F2: FnOnce(&[u16]) -> T, { - use winapi::um::errhandlingapi::{GetLastError, SetLastError}; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; + use winapi::um::errhandlingapi::{GetLastError, SetLastError}; // Start off with a stack buf but then spill over to the heap if we end up // needing more space. @@ -139,7 +148,7 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result } else if k >= n { n = k; } else { - return Ok(f2(&buf[..k])) + return Ok(f2(&buf[..k])); } } } @@ -183,21 +192,22 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { // install to the wrong place. This check is to make the // multirust-rs to rustup upgrade seamless. let env_var = if let Some(v) = env_var { - let vv = v.to_string_lossy().to_string(); - if vv.contains(".multirust/cargo") || - vv.contains(r".multirust\cargo") || - vv.trim().is_empty() { - None - } else { - Some(v) - } + let vv = v.to_string_lossy().to_string(); + if vv.contains(".multirust/cargo") + || vv.contains(r".multirust\cargo") + || vv.trim().is_empty() + { + None + } else { + Some(v) + } } else { None }; let env_cargo_home = env_var.map(|home| cwd.join(home)); - let home_dir = home_dir() - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); + let home_dir = + home_dir().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); let user_home = home_dir.map(|p| p.join(".cargo")); // Compatibility with old cargo that used the std definition of home_dir @@ -250,13 +260,15 @@ pub fn rustup_home() -> io::Result { pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { let env_var = env::var_os("RUSTUP_HOME"); let env_rustup_home = env_var.map(|home| cwd.join(home)); - let home_dir = || home_dir() - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); + let home_dir = + || home_dir().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); - let user_home = || if use_rustup_dir() { - home_dir().map(|d| d.join(".rustup")) - } else { - home_dir().map(|d| d.join(".multirust")) + let user_home = || { + if use_rustup_dir() { + home_dir().map(|d| d.join(".rustup")) + } else { + home_dir().map(|d| d.join(".multirust")) + } }; if let Some(p) = env_rustup_home { @@ -289,6 +301,5 @@ fn use_rustup_dir() -> bool { .unwrap_or(false) } - !rustup_old_version_exists() - && (rustup_dir_exists() || !multirust_dir_exists()) + !rustup_old_version_exists() && (rustup_dir_exists() || !multirust_dir_exists()) } From 97baa417b2cb91839b3ca616344cc65f9e4d3040 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 6 Aug 2019 14:46:10 -0700 Subject: [PATCH 19/84] Bump to 0.4 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 368f034fba2..df19ba9d0a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.3.3" +version = "0.4.0" authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" From 645457e91962cb22965646173f8275dc3236bfdd Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 6 Aug 2019 14:49:27 -0700 Subject: [PATCH 20/84] Allow deprecated std::env::home_dir --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 0d41d8c5c8e..fc3975bdbdb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ //! [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 #![deny(rust_2018_idioms)] +#![allow(deprecated)] // uses std::env::home_dir when necessary use std::env; use std::io; From b4a6db25d73a138e530519dcb911b9ea1ccd1863 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 6 Aug 2019 14:54:43 -0700 Subject: [PATCH 21/84] Mention dirs crate --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index fc3975bdbdb..7a3a9f76a07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,11 @@ //! rustup, as well functions to find the correct value of //! `CARGO_HOME` and `RUSTUP_HOME`. //! +//! See also the [`dirs`](https://docs.rs/dirs) crate. +//! +//! _Note that as of 2019/08/06 it appears that cargo uses this crate, but +//! rustup does not._ +//! //! The definition of `home_dir` provided by the standard library is //! incorrect because it considers the `HOME` environment variable on //! Windows. This causes surprising situations where a Rust program From 2f749939248c4f9e9e8ea6f29a8b2ec139b5c65d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 6 Aug 2019 14:54:57 -0700 Subject: [PATCH 22/84] Bump to 0.4.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index df19ba9d0a0..7825aa9bb6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.4.0" +version = "0.4.1" authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" From 64de940e4db172503e65c78193abfcae08fb3c97 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 7 Aug 2019 02:17:53 +0000 Subject: [PATCH 23/84] Fix windows build failure --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 7a3a9f76a07..2a60dba99a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,7 +86,7 @@ fn home_dir_() -> Option { return None; } let _g = scopeguard::guard(token, |h| { - let _ = CloseHandle(*h); + let _ = CloseHandle(h); }); fill_utf16_buf( |buf, mut sz| { From c2a4f958babdc291fd5b08cc44abe31c68603b21 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 8 Aug 2019 12:04:31 -0700 Subject: [PATCH 24/84] Bump to 0.4.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7825aa9bb6c..9c4411e2f93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.4.1" +version = "0.4.2" authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" From 38ba4ef4d5a3c7e63cd2c266d0d73e6bbaa7df9c Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 15 Aug 2019 14:17:29 -0700 Subject: [PATCH 25/84] Add travis config --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..193e015fb46 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: rust +rust: + - stable \ No newline at end of file From 2c718c97bb5746ee9c57a239e77c2264cf239061 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 15 Aug 2019 14:17:51 -0700 Subject: [PATCH 26/84] Add Cargo.lock to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9f970225adb..4470988469a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -target/ \ No newline at end of file +target/ +Cargo.lock \ No newline at end of file From 2002aee0cbbc49494cfa7509459591050ff1f449 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 16 Aug 2019 09:54:03 +0700 Subject: [PATCH 27/84] Add LICENSE text file Because Apache-2.0 requires text license to be present along with source. --- Cargo.toml | 2 +- LICENSE-APACHE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE-MIT | 21 ++++++ 3 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT diff --git a/Cargo.toml b/Cargo.toml index 9c4411e2f93..74278f8b111 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.4.2" authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" repository = "https://github.com/brson/home" description = "Shared definitions of home directories" diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 00000000000..c3164555677 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2019 Brian Anderson + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 00000000000..f613bcb1f3c --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Brian Anderson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From e658ff7822116eeb1a5b1adc5f8d08b7fa10a96d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 16 Aug 2019 12:31:15 +0700 Subject: [PATCH 28/84] ci: Add Mac and Windows builds --- .travis.yml | 31 ++++++++++++++++++++++++++++++- src/lib.rs | 9 ++++----- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 193e015fb46..a34d64d774e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,32 @@ +dist: xenial language: rust rust: - - stable \ No newline at end of file + - stable + +git: + depth: 1 + quiet: true + +matrix: + fast_finish: true + include: + - os: linux + env: TARGET=x86_64-unknown-linux-gnu + + - os: osx + osx_image: xcode9.2 + env: MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=x86_64-apple-darwin + + - os: windows + env: TARGET=x86_64-pc-windows-msvc EXE_EXT=.exe + services: nil + + - name: rustfmt + install: + - rustup component add rustfmt + script: + - cargo fmt --all -- --check + +script: + - cargo build --verbose + - cargo test --verbose diff --git a/src/lib.rs b/src/lib.rs index 2a60dba99a0..7876ca56db2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ //! [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 #![deny(rust_2018_idioms)] -#![allow(deprecated)] // uses std::env::home_dir when necessary +#![allow(deprecated)] // uses env::home_dir when necessary use std::env; use std::io; @@ -68,7 +68,6 @@ pub fn home_dir() -> Option { #[cfg(windows)] fn home_dir_() -> Option { - use scopeguard; use std::ptr; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; use winapi::um::errhandlingapi::GetLastError; @@ -77,7 +76,7 @@ fn home_dir_() -> Option { use winapi::um::userenv::GetUserProfileDirectoryW; use winapi::um::winnt::TOKEN_READ; - std::env::var_os("USERPROFILE") + env::var_os("USERPROFILE") .map(PathBuf::from) .or_else(|| unsafe { let me = GetCurrentProcess(); @@ -162,7 +161,7 @@ where #[cfg(any(unix, target_os = "redox"))] fn home_dir_() -> Option { - std::env::home_dir() + env::home_dir() } /// Returns the storage directory used by Cargo, often knowns as @@ -217,7 +216,7 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { let user_home = home_dir.map(|p| p.join(".cargo")); // Compatibility with old cargo that used the std definition of home_dir - let compat_home_dir = std::env::home_dir(); + let compat_home_dir = env::home_dir(); let compat_user_home = compat_home_dir.map(|p| p.join(".cargo")); if let Some(p) = env_cargo_home { From ae79f9fdfa74ff5584d8cf1f206071b0780449a4 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 16 Aug 2019 22:05:49 +0700 Subject: [PATCH 29/84] chore: Split Windows impl to a separate module --- src/lib.rs | 108 ++++-------------------------------------------- src/windows.rs | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 100 deletions(-) create mode 100644 src/windows.rs diff --git a/src/lib.rs b/src/lib.rs index 7876ca56db2..b404dc0bf6e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,24 +28,24 @@ #![deny(rust_2018_idioms)] #![allow(deprecated)] // uses env::home_dir when necessary +mod windows; + use std::env; use std::io; use std::path::{Path, PathBuf}; -#[cfg(windows)] -use winapi::shared::minwindef::DWORD; /// Returns the path of the current user's home directory if known. /// /// # Unix /// -/// Returns the value of the 'HOME' environment variable if it is set +/// Returns the value of the `HOME` environment variable if it is set /// and not equal to the empty string. Otherwise, it tries to determine the /// home directory by invoking the `getpwuid_r` function on the UID of the /// current user. /// /// # Windows /// -/// Returns the value of the 'USERPROFILE' environment variable if it +/// Returns the value of the `USERPROFILE` environment variable if it /// is set and not equal to the empty string. If both do not exist, /// [`GetUserProfileDirectory`][msdn] is used to return the /// appropriate path. @@ -55,112 +55,20 @@ use winapi::shared::minwindef::DWORD; /// # Examples /// /// ``` -/// use std::env; -/// -/// match env::home_dir() { +/// match home::home_dir() { /// Some(path) => println!("{}", path.display()), /// None => println!("Impossible to get your home dir!"), /// } /// ``` pub fn home_dir() -> Option { - home_dir_() -} - -#[cfg(windows)] -fn home_dir_() -> Option { - use std::ptr; - use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; - use winapi::um::errhandlingapi::GetLastError; - use winapi::um::handleapi::CloseHandle; - use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken}; - use winapi::um::userenv::GetUserProfileDirectoryW; - use winapi::um::winnt::TOKEN_READ; - - env::var_os("USERPROFILE") - .map(PathBuf::from) - .or_else(|| unsafe { - let me = GetCurrentProcess(); - let mut token = ptr::null_mut(); - if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { - return None; - } - let _g = scopeguard::guard(token, |h| { - let _ = CloseHandle(h); - }); - fill_utf16_buf( - |buf, mut sz| { - match GetUserProfileDirectoryW(token, buf, &mut sz) { - 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, - 0 => sz, - _ => sz - 1, // sz includes the null terminator - } - }, - os2path, - ) - .ok() - }) + home_dir_inner() } #[cfg(windows)] -fn os2path(s: &[u16]) -> PathBuf { - use std::ffi::OsString; - use std::os::windows::ffi::OsStringExt; - PathBuf::from(OsString::from_wide(s)) -} - -#[cfg(windows)] -fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result -where - F1: FnMut(*mut u16, DWORD) -> DWORD, - F2: FnOnce(&[u16]) -> T, -{ - use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; - use winapi::um::errhandlingapi::{GetLastError, SetLastError}; - - // Start off with a stack buf but then spill over to the heap if we end up - // needing more space. - let mut stack_buf = [0u16; 512]; - let mut heap_buf = Vec::new(); - unsafe { - let mut n = stack_buf.len(); - loop { - let buf = if n <= stack_buf.len() { - &mut stack_buf[..] - } else { - let extra = n - heap_buf.len(); - heap_buf.reserve(extra); - heap_buf.set_len(n); - &mut heap_buf[..] - }; - - // This function is typically called on windows API functions which - // will return the correct length of the string, but these functions - // also return the `0` on error. In some cases, however, the - // returned "correct length" may actually be 0! - // - // To handle this case we call `SetLastError` to reset it to 0 and - // then check it again if we get the "0 error value". If the "last - // error" is still 0 then we interpret it as a 0 length buffer and - // not an actual error. - SetLastError(0); - let k = match f1(buf.as_mut_ptr(), n as DWORD) { - 0 if GetLastError() == 0 => 0, - 0 => return Err(io::Error::last_os_error()), - n => n, - } as usize; - if k == n && GetLastError() == ERROR_INSUFFICIENT_BUFFER { - n *= 2; - } else if k >= n { - n = k; - } else { - return Ok(f2(&buf[..k])); - } - } - } -} +use windows::home_dir_inner; #[cfg(any(unix, target_os = "redox"))] -fn home_dir_() -> Option { +fn home_dir_inner() -> Option { env::home_dir() } diff --git a/src/windows.rs b/src/windows.rs new file mode 100644 index 00000000000..15eff883bb8 --- /dev/null +++ b/src/windows.rs @@ -0,0 +1,109 @@ +#![cfg(windows)] + +use std::env; +use std::ffi::OsString; +use std::io; +use std::os::windows::ffi::OsStringExt; +use std::path::PathBuf; +use std::ptr; + +use winapi::shared::minwindef::DWORD; +use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; +use winapi::um::errhandlingapi::{GetLastError, SetLastError}; +use winapi::um::handleapi::CloseHandle; +use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken}; +use winapi::um::userenv::GetUserProfileDirectoryW; +use winapi::um::winnt::TOKEN_READ; + +pub fn home_dir_inner() -> Option { + env::var_os("USERPROFILE") + .map(PathBuf::from) + .or_else(|| unsafe { + let me = GetCurrentProcess(); + let mut token = ptr::null_mut(); + if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { + return None; + } + let _g = scopeguard::guard(token, |h| { + let _ = CloseHandle(h); + }); + fill_utf16_buf( + |buf, mut sz| { + match GetUserProfileDirectoryW(token, buf, &mut sz) { + 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, + 0 => sz, + _ => sz - 1, // sz includes the null terminator + } + }, + os2path, + ) + .ok() + }) +} + +fn os2path(s: &[u16]) -> PathBuf { + PathBuf::from(OsString::from_wide(s)) +} + +// Many Windows APIs follow a pattern of where we hand a buffer and then they +// will report back to us how large the buffer should be or how many bytes +// currently reside in the buffer. This function is an abstraction over these +// functions by making them easier to call. +// +// The first callback, `f1`, is yielded a (pointer, len) pair which can be +// passed to a syscall. The `ptr` is valid for `len` items (u16 in this case). +// The closure is expected to return what the syscall returns which will be +// interpreted by this function to determine if the syscall needs to be invoked +// again (with more buffer space). +// +// 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. +// +// Taken from rust-lang/rust/src/libstd/sys/windows/mod.rs#L106 +fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result +where + F1: FnMut(*mut u16, DWORD) -> DWORD, + F2: FnOnce(&[u16]) -> T, +{ + // Start off with a stack buf but then spill over to the heap if we end up + // needing more space. + let mut stack_buf = [0u16; 512]; + let mut heap_buf = Vec::new(); + unsafe { + let mut n = stack_buf.len(); + loop { + let buf = if n <= stack_buf.len() { + &mut stack_buf[..] + } else { + let extra = n - heap_buf.len(); + heap_buf.reserve(extra); + heap_buf.set_len(n); + &mut heap_buf[..] + }; + + // This function is typically called on windows API functions which + // will return the correct length of the string, but these functions + // also return the `0` on error. In some cases, however, the + // returned "correct length" may actually be 0! + // + // To handle this case we call `SetLastError` to reset it to 0 and + // then check it again if we get the "0 error value". If the "last + // error" is still 0 then we interpret it as a 0 length buffer and + // not an actual error. + SetLastError(0); + let k = match f1(buf.as_mut_ptr(), n as DWORD) { + 0 if GetLastError() == 0 => 0, + 0 => return Err(io::Error::last_os_error()), + n => n, + } as usize; + if k == n && GetLastError() == ERROR_INSUFFICIENT_BUFFER { + n *= 2; + } else if k >= n { + n = k; + } else { + return Ok(f2(&buf[..k])); + } + } + } +} From e9d14ba8796076e92780cc41695e23cceb123e58 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 16 Aug 2019 22:05:49 +0700 Subject: [PATCH 30/84] Add home_dir impl for Windows UWP platforms --- src/windows.rs | 52 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index 15eff883bb8..2021c678525 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -18,27 +18,37 @@ use winapi::um::winnt::TOKEN_READ; pub fn home_dir_inner() -> Option { env::var_os("USERPROFILE") .map(PathBuf::from) - .or_else(|| unsafe { - let me = GetCurrentProcess(); - let mut token = ptr::null_mut(); - if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { - return None; - } - let _g = scopeguard::guard(token, |h| { - let _ = CloseHandle(h); - }); - fill_utf16_buf( - |buf, mut sz| { - match GetUserProfileDirectoryW(token, buf, &mut sz) { - 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, - 0 => sz, - _ => sz - 1, // sz includes the null terminator - } - }, - os2path, - ) - .ok() - }) + .or_else(|| home_dir_crt()) +} + +#[cfg(not(target_vendor = "uwp"))] +fn home_dir_crt() -> Option { + unsafe { + let me = GetCurrentProcess(); + let mut token = ptr::null_mut(); + if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { + return None; + } + let _g = scopeguard::guard(token, |h| { + let _ = CloseHandle(h); + }); + fill_utf16_buf( + |buf, mut sz| { + match GetUserProfileDirectoryW(token, buf, &mut sz) { + 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, + 0 => sz, + _ => sz - 1, // sz includes the null terminator + } + }, + os2path, + ) + .ok() + } +} + +#[cfg(target_vendor = "uwp")] +fn home_dir_crt() -> Option { + None } fn os2path(s: &[u16]) -> PathBuf { From 7bb09dda70d2d63d71dd8da0e1fff03c061c3335 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 16 Aug 2019 22:05:49 +0700 Subject: [PATCH 31/84] Remove multirust support * Correct impl of rustup_home when RUSTUP_HOME is absolute directory. * Correct impl of cargo_home when CARGO_HOME is absolute directory. --- src/lib.rs | 108 ++++++++++++++--------------------------------------- 1 file changed, 27 insertions(+), 81 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b404dc0bf6e..076813dbf47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,6 @@ //! [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 #![deny(rust_2018_idioms)] -#![allow(deprecated)] // uses env::home_dir when necessary mod windows; @@ -69,6 +68,7 @@ use windows::home_dir_inner; #[cfg(any(unix, target_os = "redox"))] fn home_dir_inner() -> Option { + #[allow(deprecated)] env::home_dir() } @@ -96,49 +96,26 @@ pub fn cargo_home() -> io::Result { } pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { - let env_var = env::var_os("CARGO_HOME"); - - // NB: During the multirust-rs -> rustup transition the install - // dir changed from ~/.multirust/bin to ~/.cargo/bin. Because - // multirust used to explicitly set CARGO_HOME it's possible to - // get here when e.g. installing under `cargo run` and decide to - // install to the wrong place. This check is to make the - // multirust-rs to rustup upgrade seamless. - let env_var = if let Some(v) = env_var { - let vv = v.to_string_lossy().to_string(); - if vv.contains(".multirust/cargo") - || vv.contains(r".multirust\cargo") - || vv.trim().is_empty() - { - None - } else { - Some(v) - } - } else { - None + let cargo_home_env = match env::var_os("CARGO_HOME") { + Some(p) => match p.as_os_str().to_str() { + Some(q) if !q.trim().is_empty() => Some(p), + _ => None, + }, + _ => None, }; - let env_cargo_home = env_var.map(|home| cwd.join(home)); - let home_dir = - home_dir().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); - let user_home = home_dir.map(|p| p.join(".cargo")); - - // Compatibility with old cargo that used the std definition of home_dir - let compat_home_dir = env::home_dir(); - let compat_user_home = compat_home_dir.map(|p| p.join(".cargo")); - - if let Some(p) = env_cargo_home { - Ok(p) - } else { - if let Some(d) = compat_user_home { - if d.exists() { - Ok(d) + match cargo_home_env { + Some(home) => { + let home = PathBuf::from(home); + if home.is_absolute() { + Ok(home) } else { - user_home + Ok(cwd.join(&home)) } - } else { - user_home } + None => home_dir() + .map(|p| p.join(".cargo")) + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")), } } @@ -171,48 +148,17 @@ pub fn rustup_home() -> io::Result { } pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { - let env_var = env::var_os("RUSTUP_HOME"); - let env_rustup_home = env_var.map(|home| cwd.join(home)); - let home_dir = - || home_dir().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "couldn't find home dir")); - - let user_home = || { - if use_rustup_dir() { - home_dir().map(|d| d.join(".rustup")) - } else { - home_dir().map(|d| d.join(".multirust")) + match env::var_os("RUSTUP_HOME") { + Some(home) => { + let home = PathBuf::from(home); + if home.is_absolute() { + Ok(home) + } else { + Ok(cwd.join(&home)) + } } - }; - - if let Some(p) = env_rustup_home { - Ok(p) - } else { - user_home() + None => home_dir() + .map(|d| d.join(".rustup")) + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find rustup home dir")), } } - -fn use_rustup_dir() -> bool { - fn rustup_dir() -> Option { - home_dir().map(|p| p.join(".rustup")) - } - - fn multirust_dir() -> Option { - home_dir().map(|p| p.join(".multirust")) - } - - fn rustup_dir_exists() -> bool { - rustup_dir().map(|p| p.exists()).unwrap_or(false) - } - - fn multirust_dir_exists() -> bool { - multirust_dir().map(|p| p.exists()).unwrap_or(false) - } - - fn rustup_old_version_exists() -> bool { - rustup_dir() - .map(|p| p.join("rustup-version").exists()) - .unwrap_or(false) - } - - !rustup_old_version_exists() && (rustup_dir_exists() || !multirust_dir_exists()) -} From 180b3348a5cb2971b7b8d993d93ad5eadfc902a0 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 16 Aug 2019 22:05:49 +0700 Subject: [PATCH 32/84] Add more examples to show how API works --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 076813dbf47..3fa5f13feeb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -90,6 +90,15 @@ fn home_dir_inner() -> Option { /// /// This function fails if it fails to retrieve the current directory, /// or if the home directory cannot be determined. +/// +/// # Examples +/// +/// ``` +/// match home::cargo_home() { +/// Ok(path) => println!("{}", path.display()), +/// Err(err) => eprintln!("Cannot get your cargo home dir: {:?}", err), +/// } +/// ``` pub fn cargo_home() -> io::Result { let cwd = env::current_dir()?; cargo_home_with_cwd(&cwd) @@ -142,6 +151,15 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { /// /// This function fails if it fails to retrieve the current directory, /// or if the home directory cannot be determined. +/// +/// # Examples +/// +/// ``` +/// match home::rustup_home() { +/// Ok(path) => println!("{}", path.display()), +/// Err(err) => eprintln!("Cannot get your rustup home dir: {:?}", err), +/// } +/// ``` pub fn rustup_home() -> io::Result { let cwd = env::current_dir()?; rustup_home_with_cwd(&cwd) From 46003d5ed7586e9952467eaf1b4ddf95a113f1cd Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 21 Aug 2019 15:41:28 +0700 Subject: [PATCH 33/84] Bump home to 0.5.0 --- .gitignore | 2 +- CHANGELOG.md | 21 +++++++++++++++++++++ Cargo.toml | 2 +- src/lib.rs | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.gitignore b/.gitignore index 4470988469a..2c96eb1b651 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ target/ -Cargo.lock \ No newline at end of file +Cargo.lock diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000000..287644e14ac --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,21 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + + + +## [0.5.0] - 2019-08-21 +### Added +- Add `home_dir` implementation for Windows UWP platforms. + +### Fixed +- Fix `rustup_home` implementation when `RUSTUP_HOME` is absolute directory. +- Fix `cargo_home` implementation when `CARGO_HOME` is absolute directory. + +### Removed +- Remove support `multirust` folder used in old version of `rustup`. + +[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.5.0...HEAD +[0.5.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.4.2...v0.5.0 diff --git a/Cargo.toml b/Cargo.toml index 9c4411e2f93..e4e589b160d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.4.2" +version = "0.5.0" # also update `html_root_url` in `src/lib.rs` authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index 3fa5f13feeb..4476541fb60 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,7 @@ //! //! [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 +#![doc(html_root_url = "https://docs.rs/home/0.5.0")] #![deny(rust_2018_idioms)] mod windows; From 08eec123f89bcbf522d950405fca475488ae167a Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 29 Aug 2019 13:54:15 +0700 Subject: [PATCH 34/84] State that rustup uses this crate --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4476541fb60..cd4c9024749 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,8 +6,8 @@ //! //! See also the [`dirs`](https://docs.rs/dirs) crate. //! -//! _Note that as of 2019/08/06 it appears that cargo uses this crate, but -//! rustup does not._ +//! _Note that as of 2019/08/06 it appears that cargo uses this crate. And +//! rustup has used this crate since 2019/08/21._ //! //! The definition of `home_dir` provided by the standard library is //! incorrect because it considers the `HOME` environment variable on From 3e824d244825356604d4f842cfb2ba37febfe1d2 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 17 Sep 2019 13:09:33 +0700 Subject: [PATCH 35/84] Update changelog version changed link --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 287644e14ac..78aa7d302ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,11 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `home_dir` implementation for Windows UWP platforms. ### Fixed -- Fix `rustup_home` implementation when `RUSTUP_HOME` is absolute directory. -- Fix `cargo_home` implementation when `CARGO_HOME` is absolute directory. +- Fix `rustup_home` implementation when `RUSTUP_HOME` is an absolute directory. +- Fix `cargo_home` implementation when `CARGO_HOME` is an absolute directory. ### Removed -- Remove support `multirust` folder used in old version of `rustup`. +- Remove support for `multirust` folder used in old version of `rustup`. -[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.5.0...HEAD -[0.5.0]: https://github.com/olivierlacan/keep-a-changelog/compare/v0.4.2...v0.5.0 +[Unreleased]: https://github.com/brson/home/compare/v0.5.0...HEAD +[0.5.0]: https://github.com/brson/home/compare/0.4.2...v0.5.0 From f44f3f287b2623f3e6ddff4d83ee44f8a41be6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Fri, 11 Oct 2019 20:17:43 +0200 Subject: [PATCH 36/84] Disable unnecessary features for scopeguard --- Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5f999e1720f..fa4f4d91b36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,8 +8,9 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/brson/home" description = "Shared definitions of home directories" -[target."cfg(windows)".dependencies] -scopeguard = "1" +[target."cfg(windows)".dependencies.scopeguard] +version = "1" +default-features = false [target."cfg(windows)".dependencies.winapi] version = "0.3" From 3f94c5ad004c1c44f25338e6df46c3a5a4d79992 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 4 Oct 2019 18:10:05 +0700 Subject: [PATCH 37/84] Remove redundant closure --- src/windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/windows.rs b/src/windows.rs index 2021c678525..7bc7addc18e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -18,7 +18,7 @@ use winapi::um::winnt::TOKEN_READ; pub fn home_dir_inner() -> Option { env::var_os("USERPROFILE") .map(PathBuf::from) - .or_else(|| home_dir_crt()) + .or_else(home_dir_crt) } #[cfg(not(target_vendor = "uwp"))] From ef18523ab49d167e6a085741fb99caf5506190e9 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 12 Oct 2019 01:38:48 +0700 Subject: [PATCH 38/84] Bump new version: v0.5.1 --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- src/lib.rs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78aa7d302ee..052155d591b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## [0.5.1] - 2019-10-12 +### Changed +- Disable unnecessary features for `scopeguard`. Thanks @mati865. + ## [0.5.0] - 2019-08-21 ### Added - Add `home_dir` implementation for Windows UWP platforms. @@ -18,4 +22,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Remove support for `multirust` folder used in old version of `rustup`. [Unreleased]: https://github.com/brson/home/compare/v0.5.0...HEAD +[0.5.1]: https://github.com/brson/home/compare/v0.5.0...v0.5.1 [0.5.0]: https://github.com/brson/home/compare/0.4.2...v0.5.0 diff --git a/Cargo.toml b/Cargo.toml index fa4f4d91b36..c25610579d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.5.0" # also update `html_root_url` in `src/lib.rs` +version = "0.5.1" # also update `html_root_url` in `src/lib.rs` authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index cd4c9024749..78f88f13b7d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ //! //! [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 -#![doc(html_root_url = "https://docs.rs/home/0.5.0")] +#![doc(html_root_url = "https://docs.rs/home/0.5.1")] #![deny(rust_2018_idioms)] mod windows; From cfc445e38c70b48b6c1c5290caf85e3186d91916 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 15 Oct 2019 15:48:58 +0700 Subject: [PATCH 39/84] Use rustup minimal profile to speed up Rust installation time --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a34d64d774e..b46fec8acf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ dist: xenial -language: rust -rust: - - stable +language: minimal git: depth: 1 @@ -18,7 +16,7 @@ matrix: env: MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=x86_64-apple-darwin - os: windows - env: TARGET=x86_64-pc-windows-msvc EXE_EXT=.exe + env: TARGET=x86_64-pc-windows-msvc services: nil - name: rustfmt @@ -27,6 +25,10 @@ matrix: script: - cargo fmt --all -- --check +before_install: + - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal + - export PATH="$HOME/.cargo/bin:$PATH" + script: - cargo build --verbose - cargo test --verbose From 29d9c3c34d526028d497f195c2c70101a4855a7c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 21 Oct 2019 23:24:17 +0700 Subject: [PATCH 40/84] build(travis): fix build stuck issue on Windows build jobs Because `minimal` is not a supported language on Windows OS. --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b46fec8acf7..292d5d6ed35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ dist: xenial -language: minimal +language: shell git: depth: 1 @@ -30,5 +30,5 @@ before_install: - export PATH="$HOME/.cargo/bin:$PATH" script: - - cargo build --verbose - - cargo test --verbose + - cargo build + - cargo test From 1886c070e1a90386bd4865b12854296bf1ab6895 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 15 Oct 2019 23:58:47 +0700 Subject: [PATCH 41/84] ci: Try github actions Use minimal profile --- .github/workflows/rust.yml | 57 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 2 +- ci/install-rust.bash | 19 +++++++++++++ ci/install-rustup.bash | 23 +++++++++++++++ 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/rust.yml create mode 100644 ci/install-rust.bash create mode 100644 ci/install-rustup.bash diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 00000000000..3d2d32e219f --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,57 @@ +name: Rust +on: [push, pull_request] + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + build: [linux, macos, win32, win64] + include: + - build: linux + os: ubuntu-latest + rust: stable + - build: macos + os: macos-latest + rust: stable + - build: win32 + os: windows-latest + rust: stable-i686-msvc + - build: win64 + os: windows-latest + rust: stable-x86_64-msvc + steps: + - uses: actions/checkout@v1 + - run: bash ci/install-rustup.bash ${{ matrix.rust }} + - run: bash ci/install-rust.bash ${{ matrix.rust }} + - if: runner.os == 'Linux' + shell: bash + run: | + rustup component add rustfmt + cargo fmt -- --check + - run: cargo build --verbose + - run: cargo test --verbose + + clippy: + name: Clippy + runs-on: ${{ matrix.os }} + strategy: + matrix: + build: [linux, macos, windows] + include: + - build: linux + os: ubuntu-latest + rust: stable + - build: macos + os: macos-latest + rust: stable + - build: windows + os: windows-latest + rust: stable + steps: + - uses: actions/checkout@v1 + - run: bash ci/install-rustup.bash ${{ matrix.rust }} + - run: bash ci/install-rust.bash ${{ matrix.rust }} + - run: rustup component add clippy + - run: cargo clippy --all --all-targets diff --git a/.travis.yml b/.travis.yml index 292d5d6ed35..9829494a5c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,7 +23,7 @@ matrix: install: - rustup component add rustfmt script: - - cargo fmt --all -- --check + - cargo fmt -- --check before_install: - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal diff --git a/ci/install-rust.bash b/ci/install-rust.bash new file mode 100644 index 00000000000..3c3bd378b77 --- /dev/null +++ b/ci/install-rust.bash @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Install/update rust. + +set -e +if [[ -z "$1" ]]; then + echo "First parameter must be toolchain to install." + exit 1 +fi +TOOLCHAIN="$1" + +rustup component remove --toolchain="$TOOLCHAIN" rust-docs || echo "already removed" +rustup update --no-self-update "$TOOLCHAIN" +rustup default "$TOOLCHAIN" +if [[ -n $2 ]]; then + rustup target add "$2" +fi +rustup -V +rustc -Vv +cargo -V diff --git a/ci/install-rustup.bash b/ci/install-rustup.bash new file mode 100644 index 00000000000..88684e1f6e7 --- /dev/null +++ b/ci/install-rustup.bash @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +# Install/update rustup. +# +# It is helpful to have this as a separate script due to some issues on +# Windows where immediately after `rustup self update`, rustup can fail with +# "Device or resource busy". + +set -e +if [[ -z "$1" ]]; then + echo "First parameter must be toolchain to install." + exit 1 +fi +TOOLCHAIN="$1" + +# Install/update rustup. +RUSTUP_MINOR_VER=$(rustup -V 2> /dev/null | grep -o -E '1\.[0-9]{2}' | cut -d . -f2) +if [[ -n $RUSTUP_MINOR_VER && $RUSTUP_MINOR_VER -ge 20 ]]; then + echo "$(rustup -V)" already installed + rustup set profile minimal +else + curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain="$TOOLCHAIN" --profile=minimal + echo "##[add-path]$HOME/.cargo/bin" +fi From 38c2d2b4d7e922826460be3178922bba96912601 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 2 Jan 2020 15:11:17 +0700 Subject: [PATCH 42/84] actions: Install rustup only (and not install toolchain) --- .github/workflows/rust.yml | 9 +++------ ci/install-rustup.bash | 7 +------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3d2d32e219f..0e0a7c24b80 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -23,7 +23,7 @@ jobs: rust: stable-x86_64-msvc steps: - uses: actions/checkout@v1 - - run: bash ci/install-rustup.bash ${{ matrix.rust }} + - run: bash ci/install-rustup.bash - run: bash ci/install-rust.bash ${{ matrix.rust }} - if: runner.os == 'Linux' shell: bash @@ -42,16 +42,13 @@ jobs: include: - build: linux os: ubuntu-latest - rust: stable - build: macos os: macos-latest - rust: stable - build: windows os: windows-latest - rust: stable steps: - uses: actions/checkout@v1 - - run: bash ci/install-rustup.bash ${{ matrix.rust }} - - run: bash ci/install-rust.bash ${{ matrix.rust }} + - run: bash ci/install-rustup.bash + - run: bash ci/install-rust.bash stable - run: rustup component add clippy - run: cargo clippy --all --all-targets diff --git a/ci/install-rustup.bash b/ci/install-rustup.bash index 88684e1f6e7..4c87a93891c 100644 --- a/ci/install-rustup.bash +++ b/ci/install-rustup.bash @@ -6,11 +6,6 @@ # "Device or resource busy". set -e -if [[ -z "$1" ]]; then - echo "First parameter must be toolchain to install." - exit 1 -fi -TOOLCHAIN="$1" # Install/update rustup. RUSTUP_MINOR_VER=$(rustup -V 2> /dev/null | grep -o -E '1\.[0-9]{2}' | cut -d . -f2) @@ -18,6 +13,6 @@ if [[ -n $RUSTUP_MINOR_VER && $RUSTUP_MINOR_VER -ge 20 ]]; then echo "$(rustup -V)" already installed rustup set profile minimal else - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain="$TOOLCHAIN" --profile=minimal + curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=none --profile=minimal echo "##[add-path]$HOME/.cargo/bin" fi From 23bc439c969a3e6e9540e288b2fe89a66ec0bd95 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 2 Jan 2020 16:27:24 +0700 Subject: [PATCH 43/84] Add why we cannot use Miri --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0e0a7c24b80..a65165bcd8f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,3 +1,5 @@ +# XXX: Miri cannot emulate the Windows syscalls. So it's pointless to run it. + name: Rust on: [push, pull_request] From 854cbf90f371b63d46c34d205d8a84a415efa109 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 2 Jan 2020 16:27:34 +0700 Subject: [PATCH 44/84] Run clippy on Windows only --- .github/workflows/rust.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a65165bcd8f..4525e19b9bf 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -37,17 +37,7 @@ jobs: clippy: name: Clippy - runs-on: ${{ matrix.os }} - strategy: - matrix: - build: [linux, macos, windows] - include: - - build: linux - os: ubuntu-latest - - build: macos - os: macos-latest - - build: windows - os: windows-latest + runs-on: windows-latest steps: - uses: actions/checkout@v1 - run: bash ci/install-rustup.bash From d1ffd6e4f9f12fbeedda723fcc360d3821150dc7 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 30 Dec 2019 17:06:58 +0700 Subject: [PATCH 45/84] Add default .rustfmt.toml --- .rustfmt.toml | 4 ++++ src/windows.rs | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .rustfmt.toml diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000000..17120d6f6c4 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,4 @@ +max_width = 120 +edition = "2018" +merge_derives = false +use_field_init_shorthand = true diff --git a/src/windows.rs b/src/windows.rs index 7bc7addc18e..6e6fd7488e2 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -16,9 +16,7 @@ use winapi::um::userenv::GetUserProfileDirectoryW; use winapi::um::winnt::TOKEN_READ; pub fn home_dir_inner() -> Option { - env::var_os("USERPROFILE") - .map(PathBuf::from) - .or_else(home_dir_crt) + env::var_os("USERPROFILE").map(PathBuf::from).or_else(home_dir_crt) } #[cfg(not(target_vendor = "uwp"))] From 77ea3e869cb817c95f6641cc68990d420c296b71 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 30 Dec 2019 15:23:15 +0700 Subject: [PATCH 46/84] Correct links --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 78f88f13b7d..90c28afe1ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,9 +21,9 @@ //! `rustup_home`, which are the canonical way to determine the //! location that Cargo and rustup store their data. //! -//! See [rust-lang/rust#43321]. +//! See also this [discussion]. //! -//! [rust-lang/rust#43321]: https://github.com/rust-lang/rust/issues/43321 +//! [discussion]: https://github.com/rust-lang/rust/pull/46799#issuecomment-361156935 #![doc(html_root_url = "https://docs.rs/home/0.5.1")] #![deny(rust_2018_idioms)] @@ -50,7 +50,7 @@ use std::path::{Path, PathBuf}; /// [`GetUserProfileDirectory`][msdn] is used to return the /// appropriate path. /// -/// [msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762280(v=vs.85).aspx +/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectoryw /// /// # Examples /// From a596a750441ce48eb8da4c79024508478e825823 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 30 Dec 2019 15:23:32 +0700 Subject: [PATCH 47/84] Remove incorrect documents about multirust --- src/lib.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 90c28afe1ef..458e77039c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,11 +143,6 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { /// - The `.rustup` directory in the user's home directory, as reported /// by the `home_dir` function. /// -/// As a matter of backwards compatibility, this function _may_ return -/// the `.multirust` directory in the user's home directory, only if -/// it determines that the user is running an old version of rustup -/// where that is necessary. -/// /// # Errors /// /// This function fails if it fails to retrieve the current directory, From 0d0111277725b12dc9309620d55d4b07e90629ca Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Thu, 2 Jan 2020 16:50:01 +0700 Subject: [PATCH 48/84] Check for emptiness of env vars --- src/lib.rs | 18 +++++------------- src/windows.rs | 5 ++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 458e77039c3..835e277299f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,16 +106,8 @@ pub fn cargo_home() -> io::Result { } pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { - let cargo_home_env = match env::var_os("CARGO_HOME") { - Some(p) => match p.as_os_str().to_str() { - Some(q) if !q.trim().is_empty() => Some(p), - _ => None, - }, - _ => None, - }; - - match cargo_home_env { - Some(home) => { + match env::var_os("CARGO_HOME") { + Some(home) if !home.is_empty() => { let home = PathBuf::from(home); if home.is_absolute() { Ok(home) @@ -123,7 +115,7 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { Ok(cwd.join(&home)) } } - None => home_dir() + _ => home_dir() .map(|p| p.join(".cargo")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")), } @@ -163,7 +155,7 @@ pub fn rustup_home() -> io::Result { pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { match env::var_os("RUSTUP_HOME") { - Some(home) => { + Some(home) if !home.is_empty() => { let home = PathBuf::from(home); if home.is_absolute() { Ok(home) @@ -171,7 +163,7 @@ pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { Ok(cwd.join(&home)) } } - None => home_dir() + _ => home_dir() .map(|d| d.join(".rustup")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find rustup home dir")), } diff --git a/src/windows.rs b/src/windows.rs index 6e6fd7488e2..18634ac1a95 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -16,7 +16,10 @@ use winapi::um::userenv::GetUserProfileDirectoryW; use winapi::um::winnt::TOKEN_READ; pub fn home_dir_inner() -> Option { - env::var_os("USERPROFILE").map(PathBuf::from).or_else(home_dir_crt) + env::var_os("USERPROFILE") + .filter(|s| !s.is_empty()) + .map(PathBuf::from) + .or_else(home_dir_crt) } #[cfg(not(target_vendor = "uwp"))] From fdca5966432f4840571c5ff9742145f684902121 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 30 Dec 2019 20:54:19 +0700 Subject: [PATCH 49/84] Add some behavior tests for home_dir on Windows --- src/windows.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/windows.rs b/src/windows.rs index 18634ac1a95..8e155e2bc13 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -118,3 +118,29 @@ where } } } + +#[cfg(not(target_vendor = "uwp"))] +#[cfg(test)] +mod tests { + use super::home_dir_inner; + use std::env; + use std::path::{Path, PathBuf}; + + #[test] + fn test_with_without() { + let olduserprofile = env::var_os("USERPROFILE").unwrap(); + + env::remove_var("HOME"); + env::remove_var("USERPROFILE"); + + assert_eq!(home_dir_inner(), Some(PathBuf::from(olduserprofile))); + + let home = Path::new(r"C:\Users\foo tar baz"); + + env::set_var("HOME", home.as_os_str()); + assert_ne!(home_dir_inner().as_deref(), Some(home)); + + env::set_var("USERPROFILE", home.as_os_str()); + assert_eq!(home_dir_inner().as_deref(), Some(home)); + } +} From 1c5772b1cb0fc8f8d0d6a807c246a712bbcb09f1 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 5 Jan 2020 21:50:51 +0700 Subject: [PATCH 50/84] actions: Cache CARGO_HOME --- .github/workflows/rust.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4525e19b9bf..39c1ab2a603 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -25,6 +25,12 @@ jobs: rust: stable-x86_64-msvc steps: - uses: actions/checkout@v1 + - name: Cache CARGO_HOME + uses: actions/cache@v1 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-home-${{ hashFiles('**/Cargo.toml') }} + restore-keys: ${{ runner.os }}-cargo-home - run: bash ci/install-rustup.bash - run: bash ci/install-rust.bash ${{ matrix.rust }} - if: runner.os == 'Linux' @@ -40,6 +46,12 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v1 + - name: Cache CARGO_HOME + uses: actions/cache@v1 + with: + path: ~/.cargo + key: ${{ runner.os }}-cargo-home-${{ hashFiles('**/Cargo.toml') }} + restore-keys: ${{ runner.os }}-cargo-home - run: bash ci/install-rustup.bash - run: bash ci/install-rust.bash stable - run: rustup component add clippy From 12645bc8a2b9348aedfc3db50b72087b5f429d61 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 30 Dec 2019 13:55:15 +0700 Subject: [PATCH 51/84] Specialized handling for our cases --- Cargo.toml | 4 --- src/windows.rs | 97 +++++++++++++------------------------------------- 2 files changed, 24 insertions(+), 77 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c25610579d0..aa1ca583de7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,6 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/brson/home" description = "Shared definitions of home directories" -[target."cfg(windows)".dependencies.scopeguard] -version = "1" -default-features = false - [target."cfg(windows)".dependencies.winapi] version = "0.3" features = [ diff --git a/src/windows.rs b/src/windows.rs index 8e155e2bc13..34662ddff45 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -2,18 +2,17 @@ use std::env; use std::ffi::OsString; -use std::io; use std::os::windows::ffi::OsStringExt; use std::path::PathBuf; use std::ptr; -use winapi::shared::minwindef::DWORD; +use winapi::shared::minwindef::{DWORD, MAX_PATH}; use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; use winapi::um::errhandlingapi::{GetLastError, SetLastError}; use winapi::um::handleapi::CloseHandle; use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken}; use winapi::um::userenv::GetUserProfileDirectoryW; -use winapi::um::winnt::TOKEN_READ; +use winapi::um::winnt::{HANDLE, TOKEN_READ}; pub fn home_dir_inner() -> Option { env::var_os("USERPROFILE") @@ -30,20 +29,9 @@ fn home_dir_crt() -> Option { if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { return None; } - let _g = scopeguard::guard(token, |h| { - let _ = CloseHandle(h); - }); - fill_utf16_buf( - |buf, mut sz| { - match GetUserProfileDirectoryW(token, buf, &mut sz) { - 0 if GetLastError() != ERROR_INSUFFICIENT_BUFFER => 0, - 0 => sz, - _ => sz - 1, // sz includes the null terminator - } - }, - os2path, - ) - .ok() + let rs = get_user_profile_directory(token); + let _ = CloseHandle(token); + rs } } @@ -52,68 +40,31 @@ fn home_dir_crt() -> Option { None } -fn os2path(s: &[u16]) -> PathBuf { - PathBuf::from(OsString::from_wide(s)) -} - -// Many Windows APIs follow a pattern of where we hand a buffer and then they -// will report back to us how large the buffer should be or how many bytes -// currently reside in the buffer. This function is an abstraction over these -// functions by making them easier to call. -// -// The first callback, `f1`, is yielded a (pointer, len) pair which can be -// passed to a syscall. The `ptr` is valid for `len` items (u16 in this case). -// The closure is expected to return what the syscall returns which will be -// interpreted by this function to determine if the syscall needs to be invoked -// again (with more buffer space). -// -// 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. -// -// Taken from rust-lang/rust/src/libstd/sys/windows/mod.rs#L106 -fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result -where - F1: FnMut(*mut u16, DWORD) -> DWORD, - F2: FnOnce(&[u16]) -> T, -{ +// Inspired from rust/src/libstd/sys/windows/mod.rs#L106 +fn get_user_profile_directory(token: HANDLE) -> Option { // Start off with a stack buf but then spill over to the heap if we end up // needing more space. - let mut stack_buf = [0u16; 512]; + let mut stack_buf = [0u16; MAX_PATH]; let mut heap_buf = Vec::new(); + let mut n = stack_buf.len() as DWORD; + let mut buf = &mut stack_buf[..]; unsafe { - let mut n = stack_buf.len(); loop { - let buf = if n <= stack_buf.len() { - &mut stack_buf[..] - } else { - let extra = n - heap_buf.len(); - heap_buf.reserve(extra); - heap_buf.set_len(n); - &mut heap_buf[..] - }; - - // This function is typically called on windows API functions which - // will return the correct length of the string, but these functions - // also return the `0` on error. In some cases, however, the - // returned "correct length" may actually be 0! - // - // To handle this case we call `SetLastError` to reset it to 0 and - // then check it again if we get the "0 error value". If the "last - // error" is still 0 then we interpret it as a 0 length buffer and - // not an actual error. SetLastError(0); - let k = match f1(buf.as_mut_ptr(), n as DWORD) { - 0 if GetLastError() == 0 => 0, - 0 => return Err(io::Error::last_os_error()), - n => n, - } as usize; - if k == n && GetLastError() == ERROR_INSUFFICIENT_BUFFER { - n *= 2; - } else if k >= n { - n = k; - } else { - return Ok(f2(&buf[..k])); + match GetUserProfileDirectoryW(token, buf.as_mut_ptr(), &mut n) { + 0 => match GetLastError() { + ERROR_INSUFFICIENT_BUFFER => { + let extra = n as usize - heap_buf.len(); + heap_buf.reserve(extra); + heap_buf.set_len(n as usize); + buf = &mut heap_buf[..]; + } + _code => return None, + }, + _ => { + let n = n as usize - 1; // sz includes the null terminator + return Some(PathBuf::from(OsString::from_wide(buf.get_unchecked(..n)))); + } } } } From 2fbb2909765a78665e61c19406b008342ec37e29 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 30 Dec 2019 17:10:20 +0700 Subject: [PATCH 52/84] Use SHGetFolderPath to replace GetUserProfileDirectory --- Cargo.toml | 6 +---- src/windows.rs | 60 +++++++++++++++----------------------------------- 2 files changed, 19 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa1ca583de7..002c34fe36c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,11 +11,7 @@ description = "Shared definitions of home directories" [target."cfg(windows)".dependencies.winapi] version = "0.3" features = [ - "errhandlingapi", - "handleapi", - "processthreadsapi", + "shlobj", "std", "winerror", - "winnt", - "userenv", ] diff --git a/src/windows.rs b/src/windows.rs index 34662ddff45..83e473dc051 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -2,17 +2,15 @@ use std::env; use std::ffi::OsString; +use std::mem::MaybeUninit; use std::os::windows::ffi::OsStringExt; use std::path::PathBuf; use std::ptr; +use std::slice; -use winapi::shared::minwindef::{DWORD, MAX_PATH}; -use winapi::shared::winerror::ERROR_INSUFFICIENT_BUFFER; -use winapi::um::errhandlingapi::{GetLastError, SetLastError}; -use winapi::um::handleapi::CloseHandle; -use winapi::um::processthreadsapi::{GetCurrentProcess, OpenProcessToken}; -use winapi::um::userenv::GetUserProfileDirectoryW; -use winapi::um::winnt::{HANDLE, TOKEN_READ}; +use winapi::shared::minwindef::MAX_PATH; +use winapi::shared::winerror::S_OK; +use winapi::um::shlobj::{SHGetFolderPathW, CSIDL_PROFILE}; pub fn home_dir_inner() -> Option { env::var_os("USERPROFILE") @@ -24,14 +22,18 @@ pub fn home_dir_inner() -> Option { #[cfg(not(target_vendor = "uwp"))] fn home_dir_crt() -> Option { unsafe { - let me = GetCurrentProcess(); - let mut token = ptr::null_mut(); - if OpenProcessToken(me, TOKEN_READ, &mut token) == 0 { - return None; + let mut path: [MaybeUninit; MAX_PATH] = MaybeUninit::uninit().assume_init(); + let ptr = path.as_mut_ptr() as *mut u16; + match SHGetFolderPathW(ptr::null_mut(), CSIDL_PROFILE, ptr::null_mut(), 0, ptr) { + S_OK => { + let ptr = path.as_ptr() as *const u16; + let len = wcslen(ptr); + let path = slice::from_raw_parts(ptr, len); + let s = OsString::from_wide(path); + Some(PathBuf::from(s)) + } + _ => None, } - let rs = get_user_profile_directory(token); - let _ = CloseHandle(token); - rs } } @@ -40,34 +42,8 @@ fn home_dir_crt() -> Option { None } -// Inspired from rust/src/libstd/sys/windows/mod.rs#L106 -fn get_user_profile_directory(token: HANDLE) -> Option { - // Start off with a stack buf but then spill over to the heap if we end up - // needing more space. - let mut stack_buf = [0u16; MAX_PATH]; - let mut heap_buf = Vec::new(); - let mut n = stack_buf.len() as DWORD; - let mut buf = &mut stack_buf[..]; - unsafe { - loop { - SetLastError(0); - match GetUserProfileDirectoryW(token, buf.as_mut_ptr(), &mut n) { - 0 => match GetLastError() { - ERROR_INSUFFICIENT_BUFFER => { - let extra = n as usize - heap_buf.len(); - heap_buf.reserve(extra); - heap_buf.set_len(n as usize); - buf = &mut heap_buf[..]; - } - _code => return None, - }, - _ => { - let n = n as usize - 1; // sz includes the null terminator - return Some(PathBuf::from(OsString::from_wide(buf.get_unchecked(..n)))); - } - } - } - } +extern "C" { + fn wcslen(buf: *const u16) -> usize; } #[cfg(not(target_vendor = "uwp"))] From d23fd465d55c3ac4313bbb26da3bcc77b97a7396 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 5 Jan 2020 21:48:12 +0700 Subject: [PATCH 53/84] Use Vec instead of MaybeUninit which is complex --- src/windows.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index 83e473dc051..baccc856b1f 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -2,11 +2,9 @@ use std::env; use std::ffi::OsString; -use std::mem::MaybeUninit; use std::os::windows::ffi::OsStringExt; use std::path::PathBuf; use std::ptr; -use std::slice; use winapi::shared::minwindef::MAX_PATH; use winapi::shared::winerror::S_OK; @@ -22,14 +20,12 @@ pub fn home_dir_inner() -> Option { #[cfg(not(target_vendor = "uwp"))] fn home_dir_crt() -> Option { unsafe { - let mut path: [MaybeUninit; MAX_PATH] = MaybeUninit::uninit().assume_init(); - let ptr = path.as_mut_ptr() as *mut u16; - match SHGetFolderPathW(ptr::null_mut(), CSIDL_PROFILE, ptr::null_mut(), 0, ptr) { + let mut path: Vec = Vec::with_capacity(MAX_PATH); + match SHGetFolderPathW(ptr::null_mut(), CSIDL_PROFILE, ptr::null_mut(), 0, path.as_mut_ptr()) { S_OK => { - let ptr = path.as_ptr() as *const u16; - let len = wcslen(ptr); - let path = slice::from_raw_parts(ptr, len); - let s = OsString::from_wide(path); + let len = wcslen(path.as_ptr()); + path.set_len(len); + let s = OsString::from_wide(&path); Some(PathBuf::from(s)) } _ => None, From c03a7bc7d4914033bbc372632aeb77c1aa5b3c99 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Fri, 4 Oct 2019 17:31:12 +0700 Subject: [PATCH 54/84] Add doc to *_with_cwd functions --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 835e277299f..a7bcaaba440 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -105,6 +105,8 @@ pub fn cargo_home() -> io::Result { cargo_home_with_cwd(&cwd) } +/// Returns the storage directory used by Cargo within `cwd`. +/// For more details, see [`cargo_home`](fn.cargo_home.html). pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { match env::var_os("CARGO_HOME") { Some(home) if !home.is_empty() => { @@ -153,6 +155,8 @@ pub fn rustup_home() -> io::Result { rustup_home_with_cwd(&cwd) } +/// Returns the storage directory used by rustup within `cwd`. +/// For more details, see [`rustup_home`](fn.rustup_home.html). pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { match env::var_os("RUSTUP_HOME") { Some(home) if !home.is_empty() => { From 69258b07fc30ea855aad801eaa60d05650e43910 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 5 Jan 2020 22:42:53 +0700 Subject: [PATCH 55/84] Remove needless cfg gate --- src/lib.rs | 1 + src/windows.rs | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a7bcaaba440..79a09b4f144 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,7 @@ #![doc(html_root_url = "https://docs.rs/home/0.5.1")] #![deny(rust_2018_idioms)] +#[cfg(windows)] mod windows; use std::env; diff --git a/src/windows.rs b/src/windows.rs index baccc856b1f..c3ff99fafee 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,5 +1,3 @@ -#![cfg(windows)] - use std::env; use std::ffi::OsString; use std::os::windows::ffi::OsStringExt; From f6cccd574be2c0f0fb209e20483247de90f4e579 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 5 Jan 2020 22:53:03 +0700 Subject: [PATCH 56/84] Bump to 0.5.2 --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- src/lib.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 052155d591b..213298d663a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## [0.5.2] - 2020-01-05 +### Changed +- Check for emptiness of `CARGO_HOME` and `RUSTUP_HOME` environment variables. +- Windows: Use `SHGetFolderPath` to replace `GetUserProfileDirectory` syscall. + * Remove `scopeguard` dependency. + ## [0.5.1] - 2019-10-12 ### Changed - Disable unnecessary features for `scopeguard`. Thanks @mati865. diff --git a/Cargo.toml b/Cargo.toml index 002c34fe36c..cef57815313 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.5.1" # also update `html_root_url` in `src/lib.rs` +version = "0.5.2" # also update `html_root_url` in `src/lib.rs` authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index 79a09b4f144..b46f9b26d38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ //! //! [discussion]: https://github.com/rust-lang/rust/pull/46799#issuecomment-361156935 -#![doc(html_root_url = "https://docs.rs/home/0.5.1")] +#![doc(html_root_url = "https://docs.rs/home/0.5.2")] #![deny(rust_2018_idioms)] #[cfg(windows)] From 61576aba2a86db2e702341f7925a959b07e2722f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 6 Jan 2020 00:41:14 +0700 Subject: [PATCH 57/84] Remove Travis template as GitHub Actions is enough --- .travis.yml | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9829494a5c8..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -dist: xenial -language: shell - -git: - depth: 1 - quiet: true - -matrix: - fast_finish: true - include: - - os: linux - env: TARGET=x86_64-unknown-linux-gnu - - - os: osx - osx_image: xcode9.2 - env: MACOSX_DEPLOYMENT_TARGET=10.7 TARGET=x86_64-apple-darwin - - - os: windows - env: TARGET=x86_64-pc-windows-msvc - services: nil - - - name: rustfmt - install: - - rustup component add rustfmt - script: - - cargo fmt -- --check - -before_install: - - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=stable --profile=minimal - - export PATH="$HOME/.cargo/bin:$PATH" - -script: - - cargo build - - cargo test From 0a52e7134e8541c8015891d50bd50802cc76dd45 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 6 Jan 2020 00:43:17 +0700 Subject: [PATCH 58/84] actions: Trigger builds on PR or commit for master branch --- .github/workflows/rust.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 39c1ab2a603..0cb6686f44a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,7 +1,20 @@ # XXX: Miri cannot emulate the Windows syscalls. So it's pointless to run it. name: Rust -on: [push, pull_request] +on: + # Trigger the workflow on push or pull request, + # but only for the master branch + push: + branches: + - master + pull_request: + branches: + - master + # Also trigger on page_build, as well as release created events + page_build: + release: + types: # This configuration does not affect the page_build event above + - created jobs: test: From 410d426278a5a930ac15c5bc966d492736506f62 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 00:04:29 +0700 Subject: [PATCH 59/84] Include only necessary components in package --- Cargo.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index cef57815313..e216dee6f9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,13 @@ version = "0.5.2" # also update `html_root_url` in `src/lib.rs` authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" +include = [ + "/src", + "/Cargo.toml", + "/CHANGELOG", + "/LICENSE-*", + "/README.md", +] license = "MIT OR Apache-2.0" repository = "https://github.com/brson/home" description = "Shared definitions of home directories" From c97f8f01634ee25a8ec52735c586484823ccb58d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 00:09:26 +0700 Subject: [PATCH 60/84] readme: Add badge for docs.rs and crates.io --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ff22423e38..db2ba9259a4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Documentation](https://docs.rs/home/badge.svg)](https://docs.rs/home) +[![Crates.io](https://img.shields.io/crates/v/home.svg)](https://crates.io/crates/home) + Canonical definitions of `home_dir`, `cargo_home`, and `rustup_home`. This provides the definition of `home_dir` used by Cargo and rustup, @@ -21,4 +24,4 @@ See [rust-lang/rust#43321]. ## License -MIT/Apache-2.0 +MIT OR Apache-2.0 From 1d9393ea3d571419b3aa544d4d3df845efaefa09 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 00:10:25 +0700 Subject: [PATCH 61/84] Use README in crates.io --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index e216dee6f9d..37eb253dd50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ include = [ "/README.md", ] license = "MIT OR Apache-2.0" +readme = "README.md" repository = "https://github.com/brson/home" description = "Shared definitions of home directories" From fd7d4257823ae58e72803ac34443e6ee145ad7f1 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 00:44:18 +0700 Subject: [PATCH 62/84] actions: Add before cache step to clean it up --- .github/workflows/rust.yml | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 0cb6686f44a..4828bbc9668 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,7 +42,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('**/Cargo.toml') }} + key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} restore-keys: ${{ runner.os }}-cargo-home - run: bash ci/install-rustup.bash - run: bash ci/install-rust.bash ${{ matrix.rust }} @@ -53,6 +53,17 @@ jobs: cargo fmt -- --check - run: cargo build --verbose - run: cargo test --verbose + # FIXME: Use `cargo install` directly when Rust 1.41.0 is out + - name: Before cache + shell: bash + run: | + case ${{ runner.os }} in + Linux ) OS=linux;; + Windows ) OS=windows;; + macOS ) OS=osx;; + esac + curl -sSL "https://github.com/lzutao/cargo-cache/releases/download/0.3.3/cargo-cache-0.3.3-${OS}.tar.gz" | tar -xzf - -C ~/.cargo/bin + cargo cache --autoclean clippy: name: Clippy @@ -63,9 +74,20 @@ jobs: uses: actions/cache@v1 with: path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('**/Cargo.toml') }} + key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} restore-keys: ${{ runner.os }}-cargo-home - run: bash ci/install-rustup.bash - run: bash ci/install-rust.bash stable - run: rustup component add clippy - run: cargo clippy --all --all-targets + # FIXME: Use `cargo install` directly when Rust 1.41.0 is out + - name: Before cache + shell: bash + run: | + case ${{ runner.os }} in + Linux ) OS=linux;; + Windows ) OS=windows;; + macOS ) OS=osx;; + esac + curl -sSL "https://github.com/lzutao/cargo-cache/releases/download/0.3.3/cargo-cache-0.3.3-${OS}.tar.gz" | tar -xzf - -C ~/.cargo/bin + cargo cache --autoclean From cd272968ef5b6c4ed46ad7853eabd6bfc85d8686 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 18:45:21 +0700 Subject: [PATCH 63/84] Use Rust 1.36.0 as minimum Rust version --- .github/workflows/rust.yml | 8 ++++---- src/lib.rs | 8 ++++---- src/windows.rs | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4828bbc9668..2503bc37e2e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,16 +26,16 @@ jobs: include: - build: linux os: ubuntu-latest - rust: stable + rust: 1.36.0 - build: macos os: macos-latest - rust: stable + rust: 1.36.0 - build: win32 os: windows-latest - rust: stable-i686-msvc + rust: 1.36.0-i686-msvc - build: win64 os: windows-latest - rust: stable-x86_64-msvc + rust: 1.36.0-x86_64-msvc steps: - uses: actions/checkout@v1 - name: Cache CARGO_HOME diff --git a/src/lib.rs b/src/lib.rs index b46f9b26d38..99d889638b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -109,8 +109,8 @@ pub fn cargo_home() -> io::Result { /// Returns the storage directory used by Cargo within `cwd`. /// For more details, see [`cargo_home`](fn.cargo_home.html). pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { - match env::var_os("CARGO_HOME") { - Some(home) if !home.is_empty() => { + match env::var_os("CARGO_HOME").filter(|h| !h.is_empty()) { + Some(home) => { let home = PathBuf::from(home); if home.is_absolute() { Ok(home) @@ -159,8 +159,8 @@ pub fn rustup_home() -> io::Result { /// Returns the storage directory used by rustup within `cwd`. /// For more details, see [`rustup_home`](fn.rustup_home.html). pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { - match env::var_os("RUSTUP_HOME") { - Some(home) if !home.is_empty() => { + match env::var_os("RUSTUP_HOME").filter(|h| !h.is_empty()) { + Some(home) => { let home = PathBuf::from(home); if home.is_absolute() { Ok(home) diff --git a/src/windows.rs b/src/windows.rs index c3ff99fafee..30a535df5ce 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -45,6 +45,7 @@ extern "C" { mod tests { use super::home_dir_inner; use std::env; + use std::ops::Deref; use std::path::{Path, PathBuf}; #[test] @@ -59,9 +60,9 @@ mod tests { let home = Path::new(r"C:\Users\foo tar baz"); env::set_var("HOME", home.as_os_str()); - assert_ne!(home_dir_inner().as_deref(), Some(home)); + assert_ne!(home_dir_inner().as_ref().map(Deref::deref), Some(home)); env::set_var("USERPROFILE", home.as_os_str()); - assert_eq!(home_dir_inner().as_deref(), Some(home)); + assert_eq!(home_dir_inner().as_ref().map(Deref::deref), Some(home)); } } From 5a577f72bdbf641eab7b96802bfaeaf2f3d23333 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 18:46:47 +0700 Subject: [PATCH 64/84] actions: Use beta toolchain for Clippy --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2503bc37e2e..2e457e5d348 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -77,7 +77,7 @@ jobs: key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} restore-keys: ${{ runner.os }}-cargo-home - run: bash ci/install-rustup.bash - - run: bash ci/install-rust.bash stable + - run: bash ci/install-rust.bash beta - run: rustup component add clippy - run: cargo clippy --all --all-targets # FIXME: Use `cargo install` directly when Rust 1.41.0 is out From 4607d98f2cd1d356b6a252f2b573072caebefefd Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 19:02:47 +0700 Subject: [PATCH 65/84] Bump to 0.5.3 --- CHANGELOG.md | 6 ++++++ Cargo.toml | 2 +- src/lib.rs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 213298d663a..3dc1f8063dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.5.3] - 2020-01-07 + +Use Rust 1.36.0 as minimum Rust version. ## [0.5.2] - 2020-01-05 + +*YANKED since it cannot be built on Rust 1.36.0* + ### Changed - Check for emptiness of `CARGO_HOME` and `RUSTUP_HOME` environment variables. - Windows: Use `SHGetFolderPath` to replace `GetUserProfileDirectory` syscall. diff --git a/Cargo.toml b/Cargo.toml index 37eb253dd50..f7c8296901c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.5.2" # also update `html_root_url` in `src/lib.rs` +version = "0.5.3" # also update `html_root_url` in `src/lib.rs` authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index 99d889638b9..ad31d3d2eb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ //! //! [discussion]: https://github.com/rust-lang/rust/pull/46799#issuecomment-361156935 -#![doc(html_root_url = "https://docs.rs/home/0.5.2")] +#![doc(html_root_url = "https://docs.rs/home/0.5.3")] #![deny(rust_2018_idioms)] #[cfg(windows)] From 3a6eccd53357624442eeb03f28abde1941dc433c Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 Jan 2020 19:10:13 +0700 Subject: [PATCH 66/84] doc: Now we use SHGetFolderPathW --- src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ad31d3d2eb1..7a82bdcd556 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,10 +48,9 @@ use std::path::{Path, PathBuf}; /// /// Returns the value of the `USERPROFILE` environment variable if it /// is set and not equal to the empty string. If both do not exist, -/// [`GetUserProfileDirectory`][msdn] is used to return the -/// appropriate path. +/// [`SHGetFolderPathW`][msdn] is used to return the appropriate path. /// -/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectoryw +/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpathw /// /// # Examples /// From af762b04feacfc64344adfe0efe3f23188ff4200 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 13 Jun 2020 23:15:40 +0700 Subject: [PATCH 67/84] Remove redundant CI scripts --- .github/workflows/rust.yml | 18 ++++++++++++++---- ci/install-rust.bash | 19 ------------------- ci/install-rustup.bash | 18 ------------------ 3 files changed, 14 insertions(+), 41 deletions(-) delete mode 100644 ci/install-rust.bash delete mode 100644 ci/install-rustup.bash diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2e457e5d348..950e814a22e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -44,8 +44,13 @@ jobs: path: ~/.cargo key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} restore-keys: ${{ runner.os }}-cargo-home - - run: bash ci/install-rustup.bash - - run: bash ci/install-rust.bash ${{ matrix.rust }} + - run: | + rustup update --no-self-update ${{ matrix.rust }} + rustup default ${{ matrix.rust }} + - run: | + rustup -V + rustc -Vv + cargo -V - if: runner.os == 'Linux' shell: bash run: | @@ -76,8 +81,13 @@ jobs: path: ~/.cargo key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} restore-keys: ${{ runner.os }}-cargo-home - - run: bash ci/install-rustup.bash - - run: bash ci/install-rust.bash beta + - run: | + rustup update --no-self-update nightly + rustup default nightly + - run: | + rustup -V + rustc -Vv + cargo -V - run: rustup component add clippy - run: cargo clippy --all --all-targets # FIXME: Use `cargo install` directly when Rust 1.41.0 is out diff --git a/ci/install-rust.bash b/ci/install-rust.bash deleted file mode 100644 index 3c3bd378b77..00000000000 --- a/ci/install-rust.bash +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -# Install/update rust. - -set -e -if [[ -z "$1" ]]; then - echo "First parameter must be toolchain to install." - exit 1 -fi -TOOLCHAIN="$1" - -rustup component remove --toolchain="$TOOLCHAIN" rust-docs || echo "already removed" -rustup update --no-self-update "$TOOLCHAIN" -rustup default "$TOOLCHAIN" -if [[ -n $2 ]]; then - rustup target add "$2" -fi -rustup -V -rustc -Vv -cargo -V diff --git a/ci/install-rustup.bash b/ci/install-rustup.bash deleted file mode 100644 index 4c87a93891c..00000000000 --- a/ci/install-rustup.bash +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash -# Install/update rustup. -# -# It is helpful to have this as a separate script due to some issues on -# Windows where immediately after `rustup self update`, rustup can fail with -# "Device or resource busy". - -set -e - -# Install/update rustup. -RUSTUP_MINOR_VER=$(rustup -V 2> /dev/null | grep -o -E '1\.[0-9]{2}' | cut -d . -f2) -if [[ -n $RUSTUP_MINOR_VER && $RUSTUP_MINOR_VER -ge 20 ]]; then - echo "$(rustup -V)" already installed - rustup set profile minimal -else - curl -sSL https://sh.rustup.rs | sh -s -- -y --default-toolchain=none --profile=minimal - echo "##[add-path]$HOME/.cargo/bin" -fi From 32044e53dfbdcd32bafad3109d1fbab805fc0f40 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 13 Jun 2020 23:39:50 +0700 Subject: [PATCH 68/84] Improve CI caching by add Cargo.lock But do not add Cargo.lock to cargo package --- .github/workflows/rust.yml | 15 ++++----------- .gitignore | 1 - Cargo.lock | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 Cargo.lock diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 950e814a22e..65d6d834367 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,7 +42,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} + key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.lock') }} restore-keys: ${{ runner.os }}-cargo-home - run: | rustup update --no-self-update ${{ matrix.rust }} @@ -58,7 +58,7 @@ jobs: cargo fmt -- --check - run: cargo build --verbose - run: cargo test --verbose - # FIXME: Use `cargo install` directly when Rust 1.41.0 is out + # FIXME: Use `cargo install` when we switch to Rust 1.41.0 - name: Before cache shell: bash run: | @@ -79,7 +79,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} + key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.lock') }} restore-keys: ${{ runner.os }}-cargo-home - run: | rustup update --no-self-update nightly @@ -90,14 +90,7 @@ jobs: cargo -V - run: rustup component add clippy - run: cargo clippy --all --all-targets - # FIXME: Use `cargo install` directly when Rust 1.41.0 is out - name: Before cache - shell: bash run: | - case ${{ runner.os }} in - Linux ) OS=linux;; - Windows ) OS=windows;; - macOS ) OS=osx;; - esac - curl -sSL "https://github.com/lzutao/cargo-cache/releases/download/0.3.3/cargo-cache-0.3.3-${OS}.tar.gz" | tar -xzf - -C ~/.cargo/bin + cargo install --debug --bin cargo-cache -- cargo-cache cargo cache --autoclean diff --git a/.gitignore b/.gitignore index 2c96eb1b651..2f7896d1d13 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ target/ -Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000000..bbf3ddfb6c5 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,32 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "home" +version = "0.5.3" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From 0719a86ab2682ec4809a61b63ec562bfae129a1a Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 19 Sep 2022 14:00:47 -0400 Subject: [PATCH 69/84] Revert "Improve CI caching by add Cargo.lock" This reverts commit 32044e53dfbdcd32bafad3109d1fbab805fc0f40. --- .github/workflows/rust.yml | 15 +++++++++++---- .gitignore | 1 + Cargo.lock | 32 -------------------------------- 3 files changed, 12 insertions(+), 36 deletions(-) delete mode 100644 Cargo.lock diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 65d6d834367..950e814a22e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,7 +42,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.lock') }} + key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} restore-keys: ${{ runner.os }}-cargo-home - run: | rustup update --no-self-update ${{ matrix.rust }} @@ -58,7 +58,7 @@ jobs: cargo fmt -- --check - run: cargo build --verbose - run: cargo test --verbose - # FIXME: Use `cargo install` when we switch to Rust 1.41.0 + # FIXME: Use `cargo install` directly when Rust 1.41.0 is out - name: Before cache shell: bash run: | @@ -79,7 +79,7 @@ jobs: uses: actions/cache@v1 with: path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.lock') }} + key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} restore-keys: ${{ runner.os }}-cargo-home - run: | rustup update --no-self-update nightly @@ -90,7 +90,14 @@ jobs: cargo -V - run: rustup component add clippy - run: cargo clippy --all --all-targets + # FIXME: Use `cargo install` directly when Rust 1.41.0 is out - name: Before cache + shell: bash run: | - cargo install --debug --bin cargo-cache -- cargo-cache + case ${{ runner.os }} in + Linux ) OS=linux;; + Windows ) OS=windows;; + macOS ) OS=osx;; + esac + curl -sSL "https://github.com/lzutao/cargo-cache/releases/download/0.3.3/cargo-cache-0.3.3-${OS}.tar.gz" | tar -xzf - -C ~/.cargo/bin cargo cache --autoclean diff --git a/.gitignore b/.gitignore index 2f7896d1d13..2c96eb1b651 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target/ +Cargo.lock diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index bbf3ddfb6c5..00000000000 --- a/Cargo.lock +++ /dev/null @@ -1,32 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -[[package]] -name = "home" -version = "0.5.3" -dependencies = [ - "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" From deefa5afb0b40527f87d029f2567603f887fe2eb Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 19 Sep 2022 14:02:07 -0400 Subject: [PATCH 70/84] chore: Update CI and remove lockfile --- .github/workflows/rust.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 950e814a22e..d578054cb1d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -90,14 +90,8 @@ jobs: cargo -V - run: rustup component add clippy - run: cargo clippy --all --all-targets - # FIXME: Use `cargo install` directly when Rust 1.41.0 is out - name: Before cache shell: bash run: | - case ${{ runner.os }} in - Linux ) OS=linux;; - Windows ) OS=windows;; - macOS ) OS=osx;; - esac - curl -sSL "https://github.com/lzutao/cargo-cache/releases/download/0.3.3/cargo-cache-0.3.3-${OS}.tar.gz" | tar -xzf - -C ~/.cargo/bin + cargo install --debug --bin cargo-cache -- cargo-cache cargo cache --autoclean From 0467bc297a963970e30b91b9100cc0501aa996ca Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 8 Jun 2020 10:44:13 +1200 Subject: [PATCH 71/84] Add `_from` variants to support threaded tests These permit abstracting over some common global process state and allow the use of home in project where in-process threaded tests are desirable, and where rustup / cargo state is changed during the tests. --- CHANGELOG.md | 3 ++ src/lib.rs | 91 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 85 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc1f8063dd..639ceb930eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +- Add `_from` variants of functions to support in-process threaded tests for + rustup. + ## [0.5.3] - 2020-01-07 Use Rust 1.36.0 as minimum Rust version. diff --git a/src/lib.rs b/src/lib.rs index 7a82bdcd556..f722774ea0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,9 +32,42 @@ mod windows; use std::env; +use std::ffi::OsString; use std::io; use std::path::{Path, PathBuf}; +/// Permits parameterising the home functions via the _from variants - used for +/// in-process unit testing by rustup. +pub trait Env { + fn home_dir(&self) -> Option; + fn current_dir(&self) -> io::Result; + fn var_os(&self, key: &str) -> Option; +} + +/// Implements Env for the OS context, both Unix style and Windows. +/// +/// This is trait permits in-process testing by providing a control point to +/// allow in-process divergence on what is normally process wide state. +/// +/// Implementations should be provided by whatever testing framework the caller +/// is using. Code that is not performing in-process threaded testing requiring +/// isolated rustup/cargo directories does not need this trait or the _from +/// functions. +struct OsEnv {} +impl Env for OsEnv { + fn home_dir(&self) -> Option { + home_dir_inner() + } + fn current_dir(&self) -> io::Result { + env::current_dir() + } + fn var_os(&self, key: &str) -> Option { + env::var_os(key) + } +} + +static OS_ENV: OsEnv = OsEnv {}; + /// Returns the path of the current user's home directory if known. /// /// # Unix @@ -61,7 +94,15 @@ use std::path::{Path, PathBuf}; /// } /// ``` pub fn home_dir() -> Option { - home_dir_inner() + home_dir_from(&OS_ENV) +} + +/// Variant of home_dir where the environment source is parameterised. This is +/// specifically to support in-process testing scenarios as environment +/// variables and user home metadata are normally process global state. See the +/// OsEnv trait. +pub fn home_dir_from(env: &dyn Env) -> Option { + env.home_dir() } #[cfg(windows)] @@ -101,14 +142,30 @@ fn home_dir_inner() -> Option { /// } /// ``` pub fn cargo_home() -> io::Result { - let cwd = env::current_dir()?; - cargo_home_with_cwd(&cwd) + cargo_home_from(&OS_ENV) +} + +/// Variant of cargo_home where the environment source is parameterised. This is +/// specifically to support in-process testing scenarios as environment +/// variables and user home metadata are normally process global state. See the +/// OsEnv trait. +pub fn cargo_home_from(env: &dyn Env) -> io::Result { + let cwd = env.current_dir()?; + cargo_home_with_cwd_from(env, &cwd) } /// Returns the storage directory used by Cargo within `cwd`. /// For more details, see [`cargo_home`](fn.cargo_home.html). pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { - match env::var_os("CARGO_HOME").filter(|h| !h.is_empty()) { + cargo_home_with_cwd_from(&OS_ENV, cwd) +} + +/// Variant of cargo_home_with_cwd where the environment source is +/// parameterised. This is specifically to support in-process testing scenarios +/// as environment variables and user home metadata are normally process global +/// state. See the OsEnv trait. +pub fn cargo_home_with_cwd_from(env: &dyn Env, cwd: &Path) -> io::Result { + match env.var_os("CARGO_HOME").filter(|h| !h.is_empty()) { Some(home) => { let home = PathBuf::from(home); if home.is_absolute() { @@ -117,7 +174,7 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { Ok(cwd.join(&home)) } } - _ => home_dir() + _ => home_dir_from(env) .map(|p| p.join(".cargo")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")), } @@ -151,14 +208,30 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { /// } /// ``` pub fn rustup_home() -> io::Result { - let cwd = env::current_dir()?; - rustup_home_with_cwd(&cwd) + rustup_home_from(&OS_ENV) +} + +/// Variant of cargo_home_with_cwd where the environment source is +/// parameterised. This is specifically to support in-process testing scenarios +/// as environment variables and user home metadata are normally process global +/// state. See the OsEnv trait. +pub fn rustup_home_from(env: &dyn Env) -> io::Result { + let cwd = env.current_dir()?; + rustup_home_with_cwd_from(env, &cwd) } /// Returns the storage directory used by rustup within `cwd`. /// For more details, see [`rustup_home`](fn.rustup_home.html). pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { - match env::var_os("RUSTUP_HOME").filter(|h| !h.is_empty()) { + rustup_home_with_cwd_from(&OS_ENV, cwd) +} + +/// Variant of cargo_home_with_cwd where the environment source is +/// parameterised. This is specifically to support in-process testing scenarios +/// as environment variables and user home metadata are normally process global +/// state. See the OsEnv trait. +pub fn rustup_home_with_cwd_from(env: &dyn Env, cwd: &Path) -> io::Result { + match env.var_os("RUSTUP_HOME").filter(|h| !h.is_empty()) { Some(home) => { let home = PathBuf::from(home); if home.is_absolute() { @@ -167,7 +240,7 @@ pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { Ok(cwd.join(&home)) } } - _ => home_dir() + _ => home_dir_from(env) .map(|d| d.join(".rustup")) .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find rustup home dir")), } From 660ccbc53f89501385cb9ebfbdae94dea93ce95c Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Wed, 1 Jul 2020 12:23:03 +1200 Subject: [PATCH 72/84] Publically export OS_ENV This needs to be public to allow rustup to cleanly call the from family of functions but still benefit from the Windows specific codepath. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f722774ea0b..2bc3e5a9dd6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ pub trait Env { /// is using. Code that is not performing in-process threaded testing requiring /// isolated rustup/cargo directories does not need this trait or the _from /// functions. -struct OsEnv {} +pub struct OsEnv {} impl Env for OsEnv { fn home_dir(&self) -> Option { home_dir_inner() @@ -66,7 +66,7 @@ impl Env for OsEnv { } } -static OS_ENV: OsEnv = OsEnv {}; +pub static OS_ENV: OsEnv = OsEnv {}; /// Returns the path of the current user's home directory if known. /// From c77b640949f795b8b0e158cbec07caaf6579ba9a Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 3 Jul 2020 16:02:20 +1200 Subject: [PATCH 73/84] Review feedback --- src/lib.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2bc3e5a9dd6..625d11783d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,11 +36,15 @@ use std::ffi::OsString; use std::io; use std::path::{Path, PathBuf}; -/// Permits parameterising the home functions via the _from variants - used for +/// Permits parameterizing the home functions via the _from variants - used for /// in-process unit testing by rustup. pub trait Env { + /// Return the path to the the users home dir, or None if any error occurs: + /// see home_inner. fn home_dir(&self) -> Option; + /// Return the current working directory. fn current_dir(&self) -> io::Result; + /// Get an environment variable, as per std::env::var_os. fn var_os(&self, key: &str) -> Option; } @@ -53,7 +57,7 @@ pub trait Env { /// is using. Code that is not performing in-process threaded testing requiring /// isolated rustup/cargo directories does not need this trait or the _from /// functions. -pub struct OsEnv {} +pub struct OsEnv; impl Env for OsEnv { fn home_dir(&self) -> Option { home_dir_inner() @@ -66,7 +70,7 @@ impl Env for OsEnv { } } -pub static OS_ENV: OsEnv = OsEnv {}; +pub const OS_ENV: OsEnv = OsEnv {}; /// Returns the path of the current user's home directory if known. /// @@ -97,10 +101,7 @@ pub fn home_dir() -> Option { home_dir_from(&OS_ENV) } -/// Variant of home_dir where the environment source is parameterised. This is -/// specifically to support in-process testing scenarios as environment -/// variables and user home metadata are normally process global state. See the -/// OsEnv trait. +/// Returns the path of the current user's home directory from [`Env::home_dir`]. pub fn home_dir_from(env: &dyn Env) -> Option { env.home_dir() } @@ -145,10 +146,10 @@ pub fn cargo_home() -> io::Result { cargo_home_from(&OS_ENV) } -/// Variant of cargo_home where the environment source is parameterised. This is +/// Variant of cargo_home where the environment source is parameterized. This is /// specifically to support in-process testing scenarios as environment /// variables and user home metadata are normally process global state. See the -/// OsEnv trait. +/// [`Env`] trait. pub fn cargo_home_from(env: &dyn Env) -> io::Result { let cwd = env.current_dir()?; cargo_home_with_cwd_from(env, &cwd) @@ -161,7 +162,7 @@ pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { } /// Variant of cargo_home_with_cwd where the environment source is -/// parameterised. This is specifically to support in-process testing scenarios +/// parameterized. This is specifically to support in-process testing scenarios /// as environment variables and user home metadata are normally process global /// state. See the OsEnv trait. pub fn cargo_home_with_cwd_from(env: &dyn Env, cwd: &Path) -> io::Result { @@ -212,7 +213,7 @@ pub fn rustup_home() -> io::Result { } /// Variant of cargo_home_with_cwd where the environment source is -/// parameterised. This is specifically to support in-process testing scenarios +/// parameterized. This is specifically to support in-process testing scenarios /// as environment variables and user home metadata are normally process global /// state. See the OsEnv trait. pub fn rustup_home_from(env: &dyn Env) -> io::Result { @@ -227,7 +228,7 @@ pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { } /// Variant of cargo_home_with_cwd where the environment source is -/// parameterised. This is specifically to support in-process testing scenarios +/// parameterized. This is specifically to support in-process testing scenarios /// as environment variables and user home metadata are normally process global /// state. See the OsEnv trait. pub fn rustup_home_with_cwd_from(env: &dyn Env, cwd: &Path) -> io::Result { From e3e570dc4b9049eeb084af6b402e198100b16ce3 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 19 Sep 2022 15:07:49 -0400 Subject: [PATCH 74/84] Add mockable home fn and `Env` trait This PR follows up and replaces on #23 which intended to add mockable functions to the `home` crate. This PR follows in similar vain except for a few changes. - All mockable fn and the `Env` trait moved into a new `env` module to keep the docs clean from all the extra methods that are usually not required for most users of the crate. - Rename the functions to be `with_env` instead of just having `_from`. The goal of this PR is to enable `rustup` and hopefully `cargo` in the future to be able to write tests which mockout the environment while still going through the core logic of this crate. --- src/env.rs | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 115 ++++------------------------------------------------- 2 files changed, 114 insertions(+), 107 deletions(-) create mode 100644 src/env.rs diff --git a/src/env.rs b/src/env.rs new file mode 100644 index 00000000000..e47273bc859 --- /dev/null +++ b/src/env.rs @@ -0,0 +1,106 @@ +//! Lower-level utilities for mocking the process environment. + +use std::{ + ffi::OsString, + io, + path::{Path, PathBuf}, +}; + +/// Permits parameterizing the home functions via the _from variants - used for +/// in-process unit testing by rustup. +pub trait Env { + /// Return the path to the the users home dir, or None if any error occurs: + /// see home_inner. + fn home_dir(&self) -> Option; + /// Return the current working directory. + fn current_dir(&self) -> io::Result; + /// Get an environment variable, as per std::env::var_os. + fn var_os(&self, key: &str) -> Option; +} + +/// Implements Env for the OS context, both Unix style and Windows. +/// +/// This is trait permits in-process testing by providing a control point to +/// allow in-process divergence on what is normally process wide state. +/// +/// Implementations should be provided by whatever testing framework the caller +/// is using. Code that is not performing in-process threaded testing requiring +/// isolated rustup/cargo directories does not need this trait or the _from +/// functions. +pub struct OsEnv; +impl Env for OsEnv { + fn home_dir(&self) -> Option { + crate::home_dir_inner() + } + fn current_dir(&self) -> io::Result { + std::env::current_dir() + } + fn var_os(&self, key: &str) -> Option { + std::env::var_os(key) + } +} + +pub const OS_ENV: OsEnv = OsEnv {}; + +/// Returns the path of the current user's home directory from [`Env::home_dir`]. +pub fn home_dir_with_env(env: &dyn Env) -> Option { + env.home_dir() +} + +/// Variant of cargo_home where the environment source is parameterized. This is +/// specifically to support in-process testing scenarios as environment +/// variables and user home metadata are normally process global state. See the +/// [`Env`] trait. +pub fn cargo_home_with_env(env: &dyn Env) -> io::Result { + let cwd = env.current_dir()?; + cargo_home_with_cwd_env(env, &cwd) +} + +/// Variant of cargo_home_with_cwd where the environment source is +/// parameterized. This is specifically to support in-process testing scenarios +/// as environment variables and user home metadata are normally process global +/// state. See the OsEnv trait. +pub fn cargo_home_with_cwd_env(env: &dyn Env, cwd: &Path) -> io::Result { + match env.var_os("CARGO_HOME").filter(|h| !h.is_empty()) { + Some(home) => { + let home = PathBuf::from(home); + if home.is_absolute() { + Ok(home) + } else { + Ok(cwd.join(&home)) + } + } + _ => home_dir_with_env(env) + .map(|p| p.join(".cargo")) + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")), + } +} + +/// Variant of cargo_home_with_cwd where the environment source is +/// parameterized. This is specifically to support in-process testing scenarios +/// as environment variables and user home metadata are normally process global +/// state. See the OsEnv trait. +pub fn rustup_home_with_env(env: &dyn Env) -> io::Result { + let cwd = env.current_dir()?; + rustup_home_with_cwd_env(env, &cwd) +} + +/// Variant of cargo_home_with_cwd where the environment source is +/// parameterized. This is specifically to support in-process testing scenarios +/// as environment variables and user home metadata are normally process global +/// state. See the OsEnv trait. +pub fn rustup_home_with_cwd_env(env: &dyn Env, cwd: &Path) -> io::Result { + match env.var_os("RUSTUP_HOME").filter(|h| !h.is_empty()) { + Some(home) => { + let home = PathBuf::from(home); + if home.is_absolute() { + Ok(home) + } else { + Ok(cwd.join(&home)) + } + } + _ => home_dir_with_env(env) + .map(|d| d.join(".rustup")) + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find rustup home dir")), + } +} diff --git a/src/lib.rs b/src/lib.rs index 625d11783d6..ee3931aba1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,50 +28,14 @@ #![doc(html_root_url = "https://docs.rs/home/0.5.3")] #![deny(rust_2018_idioms)] +pub mod env; + #[cfg(windows)] mod windows; -use std::env; -use std::ffi::OsString; use std::io; use std::path::{Path, PathBuf}; -/// Permits parameterizing the home functions via the _from variants - used for -/// in-process unit testing by rustup. -pub trait Env { - /// Return the path to the the users home dir, or None if any error occurs: - /// see home_inner. - fn home_dir(&self) -> Option; - /// Return the current working directory. - fn current_dir(&self) -> io::Result; - /// Get an environment variable, as per std::env::var_os. - fn var_os(&self, key: &str) -> Option; -} - -/// Implements Env for the OS context, both Unix style and Windows. -/// -/// This is trait permits in-process testing by providing a control point to -/// allow in-process divergence on what is normally process wide state. -/// -/// Implementations should be provided by whatever testing framework the caller -/// is using. Code that is not performing in-process threaded testing requiring -/// isolated rustup/cargo directories does not need this trait or the _from -/// functions. -pub struct OsEnv; -impl Env for OsEnv { - fn home_dir(&self) -> Option { - home_dir_inner() - } - fn current_dir(&self) -> io::Result { - env::current_dir() - } - fn var_os(&self, key: &str) -> Option { - env::var_os(key) - } -} - -pub const OS_ENV: OsEnv = OsEnv {}; - /// Returns the path of the current user's home directory if known. /// /// # Unix @@ -98,12 +62,7 @@ pub const OS_ENV: OsEnv = OsEnv {}; /// } /// ``` pub fn home_dir() -> Option { - home_dir_from(&OS_ENV) -} - -/// Returns the path of the current user's home directory from [`Env::home_dir`]. -pub fn home_dir_from(env: &dyn Env) -> Option { - env.home_dir() + env::home_dir_with_env(&env::OS_ENV) } #[cfg(windows)] @@ -112,7 +71,7 @@ use windows::home_dir_inner; #[cfg(any(unix, target_os = "redox"))] fn home_dir_inner() -> Option { #[allow(deprecated)] - env::home_dir() + std::env::home_dir() } /// Returns the storage directory used by Cargo, often knowns as @@ -143,42 +102,13 @@ fn home_dir_inner() -> Option { /// } /// ``` pub fn cargo_home() -> io::Result { - cargo_home_from(&OS_ENV) -} - -/// Variant of cargo_home where the environment source is parameterized. This is -/// specifically to support in-process testing scenarios as environment -/// variables and user home metadata are normally process global state. See the -/// [`Env`] trait. -pub fn cargo_home_from(env: &dyn Env) -> io::Result { - let cwd = env.current_dir()?; - cargo_home_with_cwd_from(env, &cwd) + env::cargo_home_with_env(&env::OS_ENV) } /// Returns the storage directory used by Cargo within `cwd`. /// For more details, see [`cargo_home`](fn.cargo_home.html). pub fn cargo_home_with_cwd(cwd: &Path) -> io::Result { - cargo_home_with_cwd_from(&OS_ENV, cwd) -} - -/// Variant of cargo_home_with_cwd where the environment source is -/// parameterized. This is specifically to support in-process testing scenarios -/// as environment variables and user home metadata are normally process global -/// state. See the OsEnv trait. -pub fn cargo_home_with_cwd_from(env: &dyn Env, cwd: &Path) -> io::Result { - match env.var_os("CARGO_HOME").filter(|h| !h.is_empty()) { - Some(home) => { - let home = PathBuf::from(home); - if home.is_absolute() { - Ok(home) - } else { - Ok(cwd.join(&home)) - } - } - _ => home_dir_from(env) - .map(|p| p.join(".cargo")) - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find cargo home dir")), - } + env::cargo_home_with_cwd_env(&env::OS_ENV, cwd) } /// Returns the storage directory used by rustup, often knowns as @@ -209,40 +139,11 @@ pub fn cargo_home_with_cwd_from(env: &dyn Env, cwd: &Path) -> io::Result io::Result { - rustup_home_from(&OS_ENV) -} - -/// Variant of cargo_home_with_cwd where the environment source is -/// parameterized. This is specifically to support in-process testing scenarios -/// as environment variables and user home metadata are normally process global -/// state. See the OsEnv trait. -pub fn rustup_home_from(env: &dyn Env) -> io::Result { - let cwd = env.current_dir()?; - rustup_home_with_cwd_from(env, &cwd) + env::rustup_home_with_env(&env::OS_ENV) } /// Returns the storage directory used by rustup within `cwd`. /// For more details, see [`rustup_home`](fn.rustup_home.html). pub fn rustup_home_with_cwd(cwd: &Path) -> io::Result { - rustup_home_with_cwd_from(&OS_ENV, cwd) -} - -/// Variant of cargo_home_with_cwd where the environment source is -/// parameterized. This is specifically to support in-process testing scenarios -/// as environment variables and user home metadata are normally process global -/// state. See the OsEnv trait. -pub fn rustup_home_with_cwd_from(env: &dyn Env, cwd: &Path) -> io::Result { - match env.var_os("RUSTUP_HOME").filter(|h| !h.is_empty()) { - Some(home) => { - let home = PathBuf::from(home); - if home.is_absolute() { - Ok(home) - } else { - Ok(cwd.join(&home)) - } - } - _ => home_dir_from(env) - .map(|d| d.join(".rustup")) - .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "could not find rustup home dir")), - } + env::rustup_home_with_cwd_env(&env::OS_ENV, cwd) } From 38c610aed4398b34a0130d84d7f2b3065e4ef9de Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 19 Sep 2022 15:12:36 -0400 Subject: [PATCH 75/84] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 639ceb930eb..d13b4cc859a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -- Add `_from` variants of functions to support in-process threaded tests for +- Add `_with_env` variants of functions to support in-process threaded tests for rustup. ## [0.5.3] - 2020-01-07 From eed5978f23dddb765fd5570d699c333747abee1d Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 19 Sep 2022 15:22:04 -0400 Subject: [PATCH 76/84] chore: Improve CI --- .github/codecov.yml | 21 ++++++ .github/workflows/check.yml | 107 ++++++++++++++++++++++++++++++ .github/workflows/nostd.yml | 24 +++++++ .github/workflows/rust.yml | 97 --------------------------- .github/workflows/safety.yml | 86 ++++++++++++++++++++++++ .github/workflows/scheduled.yml | 64 ++++++++++++++++++ .github/workflows/test.yml | 113 ++++++++++++++++++++++++++++++++ 7 files changed, 415 insertions(+), 97 deletions(-) create mode 100644 .github/codecov.yml create mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/nostd.yml delete mode 100644 .github/workflows/rust.yml create mode 100644 .github/workflows/safety.yml create mode 100644 .github/workflows/scheduled.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 00000000000..ff4f571d53f --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,21 @@ +# ref: https://docs.codecov.com/docs/codecovyml-reference +coverage: + # Hold ourselves to a high bar + range: 85..100 + round: down + precision: 1 + status: + # ref: https://docs.codecov.com/docs/commit-status + project: + default: + # Avoid false negatives + threshold: 1% + +# Test files aren't important for coverage +ignore: + - "tests" + +# Make comments less noisy +comment: + layout: "files" + require_changes: yes diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 00000000000..704f241eee2 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,107 @@ +on: + push: + branches: [main] + pull_request: +name: check +jobs: + fmt: + runs-on: ubuntu-latest + name: stable / fmt + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: rustfmt + - name: cargo fmt --check + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --check + clippy: + runs-on: ubuntu-latest + name: ${{ matrix.toolchain }} / clippy + strategy: + fail-fast: false + matrix: + toolchain: [stable, beta] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install ${{ matrix.toolchain }} + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.toolchain }} + default: true + components: clippy + - name: cargo clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + doc: + runs-on: ubuntu-latest + name: nightly / doc + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install nightly + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + default: true + - name: cargo doc + uses: actions-rs/cargo@v1 + with: + command: doc + args: --no-deps --all-features + env: + RUSTDOCFLAGS: --cfg docsrs + hack: + runs-on: ubuntu-latest + name: ubuntu / stable / features + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + - name: cargo install cargo-hack + uses: taiki-e/install-action@cargo-hack + - name: cargo hack + uses: actions-rs/cargo@v1 + with: + command: hack + args: --feature-powerset check --lib --tests + msrv: + runs-on: ubuntu-latest + # we use a matrix here just because env can't be used in job names + # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability + strategy: + matrix: + msrv: [1.36.0] + name: ubuntu / ${{ matrix.msrv }} + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install ${{ matrix.toolchain }} + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.msrv }} + default: true + - name: cargo +${{ matrix.msrv }} check + uses: actions-rs/cargo@v1 + with: + command: check diff --git a/.github/workflows/nostd.yml b/.github/workflows/nostd.yml new file mode 100644 index 00000000000..409ae73a297 --- /dev/null +++ b/.github/workflows/nostd.yml @@ -0,0 +1,24 @@ +on: + push: + branches: [main] + pull_request: +name: no-std +jobs: + nostd: + runs-on: ubuntu-latest + name: ${{ matrix.target }} + strategy: + matrix: + target: [thumbv7m-none-eabi, aarch64-unknown-none] + steps: + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + target: ${{ matrix.target }} + - uses: actions/checkout@v3 + - name: cargo check + uses: actions-rs/cargo@v1 + with: + command: check + args: --target ${{ matrix.target }} --no-default-features diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index d578054cb1d..00000000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,97 +0,0 @@ -# XXX: Miri cannot emulate the Windows syscalls. So it's pointless to run it. - -name: Rust -on: - # Trigger the workflow on push or pull request, - # but only for the master branch - push: - branches: - - master - pull_request: - branches: - - master - # Also trigger on page_build, as well as release created events - page_build: - release: - types: # This configuration does not affect the page_build event above - - created - -jobs: - test: - name: Test - runs-on: ${{ matrix.os }} - strategy: - matrix: - build: [linux, macos, win32, win64] - include: - - build: linux - os: ubuntu-latest - rust: 1.36.0 - - build: macos - os: macos-latest - rust: 1.36.0 - - build: win32 - os: windows-latest - rust: 1.36.0-i686-msvc - - build: win64 - os: windows-latest - rust: 1.36.0-x86_64-msvc - steps: - - uses: actions/checkout@v1 - - name: Cache CARGO_HOME - uses: actions/cache@v1 - with: - path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} - restore-keys: ${{ runner.os }}-cargo-home - - run: | - rustup update --no-self-update ${{ matrix.rust }} - rustup default ${{ matrix.rust }} - - run: | - rustup -V - rustc -Vv - cargo -V - - if: runner.os == 'Linux' - shell: bash - run: | - rustup component add rustfmt - cargo fmt -- --check - - run: cargo build --verbose - - run: cargo test --verbose - # FIXME: Use `cargo install` directly when Rust 1.41.0 is out - - name: Before cache - shell: bash - run: | - case ${{ runner.os }} in - Linux ) OS=linux;; - Windows ) OS=windows;; - macOS ) OS=osx;; - esac - curl -sSL "https://github.com/lzutao/cargo-cache/releases/download/0.3.3/cargo-cache-0.3.3-${OS}.tar.gz" | tar -xzf - -C ~/.cargo/bin - cargo cache --autoclean - - clippy: - name: Clippy - runs-on: windows-latest - steps: - - uses: actions/checkout@v1 - - name: Cache CARGO_HOME - uses: actions/cache@v1 - with: - path: ~/.cargo - key: ${{ runner.os }}-cargo-home-${{ hashFiles('Cargo.toml') }}-${{ hashFiles('.github/workflows/rust.yml') }} - restore-keys: ${{ runner.os }}-cargo-home - - run: | - rustup update --no-self-update nightly - rustup default nightly - - run: | - rustup -V - rustc -Vv - cargo -V - - run: rustup component add clippy - - run: cargo clippy --all --all-targets - - name: Before cache - shell: bash - run: | - cargo install --debug --bin cargo-cache -- cargo-cache - cargo cache --autoclean diff --git a/.github/workflows/safety.yml b/.github/workflows/safety.yml new file mode 100644 index 00000000000..86fc9eeae81 --- /dev/null +++ b/.github/workflows/safety.yml @@ -0,0 +1,86 @@ +on: + push: + branches: [main] + pull_request: +name: safety +jobs: + sanitizers: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install nightly + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + default: true + - run: | + # to get the symbolizer for debug symbol resolution + sudo apt install llvm + # to fix buggy leak analyzer: + # https://github.com/japaric/rust-san#unrealiable-leaksanitizer + sed -i '/\[features\]/i [profile.dev]' Cargo.toml + sed -i '/profile.dev/a opt-level = 1' Cargo.toml + cat Cargo.toml + name: Enable debug symbols + - name: cargo test -Zsanitizer=address + uses: actions-rs/cargo@v1 + with: + command: test + # only --lib --tests b/c of https://github.com/rust-lang/rust/issues/53945 + args: --lib --tests --all-features --target x86_64-unknown-linux-gnu + env: + ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=0" + RUSTFLAGS: "-Z sanitizer=address" + - name: cargo test -Zsanitizer=leak + if: always() + uses: actions-rs/cargo@v1 + with: + command: test + args: --all-features --target x86_64-unknown-linux-gnu + env: + LSAN_OPTIONS: "suppressions=lsan-suppressions.txt" + RUSTFLAGS: "-Z sanitizer=leak" + miri: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - run: | + echo "NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)" >> $GITHUB_ENV + - name: Install ${{ env.NIGHTLY }} + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ env.NIGHTLY }} + default: true + components: miri + - name: cargo miri test + uses: actions-rs/cargo@v1 + with: + command: miri + args: test + env: + MIRIFLAGS: "-Zmiri-tag-raw-pointers" + loom: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + - name: cargo test --test loom + uses: actions-rs/cargo@v1 + with: + command: test + args: --release --test loom + env: + LOOM_MAX_PREEMPTIONS: 2 + RUSTFLAGS: "--cfg loom" diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml new file mode 100644 index 00000000000..a5f53110bf1 --- /dev/null +++ b/.github/workflows/scheduled.yml @@ -0,0 +1,64 @@ +on: + push: + branches: [main] + pull_request: + schedule: + - cron: '7 7 * * *' +name: rolling +jobs: + # https://twitter.com/mycoliza/status/1571295690063753218 + nightly: + runs-on: ubuntu-latest + name: ubuntu / nightly + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install nightly + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + default: true + - name: cargo generate-lockfile + if: hashFiles('Cargo.lock') == '' + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + - name: cargo test --locked + uses: actions-rs/cargo@v1 + with: + command: test + args: --locked --all-features --all-targets + # https://twitter.com/alcuadrado/status/1571291687837732873 + update: + runs-on: ubuntu-latest + name: ubuntu / beta / updated + # There's no point running this if no Cargo.lock was checked in in the + # first place, since we'd just redo what happened in the regular test job. + # Unfortunately, hashFiles only works in if on steps, so we reepeat it. + # if: hashFiles('Cargo.lock') != '' + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install beta + if: hashFiles('Cargo.lock') != '' + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: beta + default: true + - name: cargo update + if: hashFiles('Cargo.lock') != '' + uses: actions-rs/cargo@v1 + with: + command: update + - name: cargo test + if: hashFiles('Cargo.lock') != '' + uses: actions-rs/cargo@v1 + with: + command: test + args: --locked --all-features --all-targets + env: + RUSTFLAGS: -D deprecated diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000000..83645f88ff7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,113 @@ +on: + push: + branches: [main] + pull_request: +name: test +jobs: + required: + runs-on: ubuntu-latest + name: ubuntu / ${{ matrix.toolchain }} + strategy: + matrix: + toolchain: [stable, beta] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install ${{ matrix.toolchain }} + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: ${{ matrix.toolchain }} + default: true + - name: cargo generate-lockfile + if: hashFiles('Cargo.lock') == '' + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + # https://twitter.com/jonhoo/status/1571290371124260865 + - name: cargo test --locked + uses: actions-rs/cargo@v1 + with: + command: test + args: --locked --all-features --all-targets + minimal: + runs-on: ubuntu-latest + name: ubuntu / stable / minimal-versions + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + - name: Install nightly for -Zminimal-versions + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + - name: cargo update -Zminimal-versions + uses: actions-rs/cargo@v1 + with: + command: update + toolchain: nightly + args: -Zminimal-versions + - name: cargo test + uses: actions-rs/cargo@v1 + with: + command: test + args: --locked --all-features --all-targets + os-check: + runs-on: ${{ matrix.os }} + name: ${{ matrix.os }} / stable + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + - name: cargo generate-lockfile + if: hashFiles('Cargo.lock') == '' + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + - name: cargo test + uses: actions-rs/cargo@v1 + with: + command: test + args: --locked --all-features --all-targets + coverage: + runs-on: ubuntu-latest + name: ubuntu / stable / coverage + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install stable + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + components: llvm-tools-preview + - name: cargo install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + - name: cargo generate-lockfile + if: hashFiles('Cargo.lock') == '' + uses: actions-rs/cargo@v1 + with: + command: generate-lockfile + - name: cargo llvm-cov + run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info + - name: Upload to codecov.io + uses: codecov/codecov-action@v2 + with: + fail_ci_if_error: true From 6d79d9538b4ab346261b4dc9101209e5b2ad96c1 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 19 Sep 2022 15:26:05 -0400 Subject: [PATCH 77/84] remove unwanted ci tests --- .github/workflows/nostd.yml | 24 ---------- .github/workflows/safety.yml | 86 ------------------------------------ 2 files changed, 110 deletions(-) delete mode 100644 .github/workflows/nostd.yml delete mode 100644 .github/workflows/safety.yml diff --git a/.github/workflows/nostd.yml b/.github/workflows/nostd.yml deleted file mode 100644 index 409ae73a297..00000000000 --- a/.github/workflows/nostd.yml +++ /dev/null @@ -1,24 +0,0 @@ -on: - push: - branches: [main] - pull_request: -name: no-std -jobs: - nostd: - runs-on: ubuntu-latest - name: ${{ matrix.target }} - strategy: - matrix: - target: [thumbv7m-none-eabi, aarch64-unknown-none] - steps: - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - target: ${{ matrix.target }} - - uses: actions/checkout@v3 - - name: cargo check - uses: actions-rs/cargo@v1 - with: - command: check - args: --target ${{ matrix.target }} --no-default-features diff --git a/.github/workflows/safety.yml b/.github/workflows/safety.yml deleted file mode 100644 index 86fc9eeae81..00000000000 --- a/.github/workflows/safety.yml +++ /dev/null @@ -1,86 +0,0 @@ -on: - push: - branches: [main] - pull_request: -name: safety -jobs: - sanitizers: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install nightly - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - default: true - - run: | - # to get the symbolizer for debug symbol resolution - sudo apt install llvm - # to fix buggy leak analyzer: - # https://github.com/japaric/rust-san#unrealiable-leaksanitizer - sed -i '/\[features\]/i [profile.dev]' Cargo.toml - sed -i '/profile.dev/a opt-level = 1' Cargo.toml - cat Cargo.toml - name: Enable debug symbols - - name: cargo test -Zsanitizer=address - uses: actions-rs/cargo@v1 - with: - command: test - # only --lib --tests b/c of https://github.com/rust-lang/rust/issues/53945 - args: --lib --tests --all-features --target x86_64-unknown-linux-gnu - env: - ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=0" - RUSTFLAGS: "-Z sanitizer=address" - - name: cargo test -Zsanitizer=leak - if: always() - uses: actions-rs/cargo@v1 - with: - command: test - args: --all-features --target x86_64-unknown-linux-gnu - env: - LSAN_OPTIONS: "suppressions=lsan-suppressions.txt" - RUSTFLAGS: "-Z sanitizer=leak" - miri: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - run: | - echo "NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)" >> $GITHUB_ENV - - name: Install ${{ env.NIGHTLY }} - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ env.NIGHTLY }} - default: true - components: miri - - name: cargo miri test - uses: actions-rs/cargo@v1 - with: - command: miri - args: test - env: - MIRIFLAGS: "-Zmiri-tag-raw-pointers" - loom: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - - name: cargo test --test loom - uses: actions-rs/cargo@v1 - with: - command: test - args: --release --test loom - env: - LOOM_MAX_PREEMPTIONS: 2 - RUSTFLAGS: "--cfg loom" From 0f6aad657b8977a3bb9e79f80dd6ef717453e6a7 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 19 Sep 2022 15:31:50 -0400 Subject: [PATCH 78/84] remove code cov --- .github/codecov.yml | 21 --------------------- .github/workflows/test.yml | 26 -------------------------- 2 files changed, 47 deletions(-) delete mode 100644 .github/codecov.yml diff --git a/.github/codecov.yml b/.github/codecov.yml deleted file mode 100644 index ff4f571d53f..00000000000 --- a/.github/codecov.yml +++ /dev/null @@ -1,21 +0,0 @@ -# ref: https://docs.codecov.com/docs/codecovyml-reference -coverage: - # Hold ourselves to a high bar - range: 85..100 - round: down - precision: 1 - status: - # ref: https://docs.codecov.com/docs/commit-status - project: - default: - # Avoid false negatives - threshold: 1% - -# Test files aren't important for coverage -ignore: - - "tests" - -# Make comments less noisy -comment: - layout: "files" - require_changes: yes diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 83645f88ff7..af346295a6a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,29 +85,3 @@ jobs: with: command: test args: --locked --all-features --all-targets - coverage: - runs-on: ubuntu-latest - name: ubuntu / stable / coverage - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - components: llvm-tools-preview - - name: cargo install cargo-llvm-cov - uses: taiki-e/install-action@cargo-llvm-cov - - name: cargo generate-lockfile - if: hashFiles('Cargo.lock') == '' - uses: actions-rs/cargo@v1 - with: - command: generate-lockfile - - name: cargo llvm-cov - run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info - - name: Upload to codecov.io - uses: codecov/codecov-action@v2 - with: - fail_ci_if_error: true From e697b7b15ad2f4f4a529d7f09073a9b49f6fb562 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 10 Oct 2022 09:28:25 -0400 Subject: [PATCH 79/84] chore: Prepare `v0.5.4` --- CHANGELOG.md | 7 ++++++- Cargo.toml | 2 +- src/lib.rs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d13b4cc859a..7674667c991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [0.5.4] - 2022-10-10 - Add `_with_env` variants of functions to support in-process threaded tests for rustup. @@ -36,6 +38,9 @@ Use Rust 1.36.0 as minimum Rust version. ### Removed - Remove support for `multirust` folder used in old version of `rustup`. -[Unreleased]: https://github.com/brson/home/compare/v0.5.0...HEAD +[Unreleased]: https://github.com/brson/home/compare/v0.5.4...HEAD +[0.5.4]: https://github.com/brson/home/compare/v0.5.3...v0.5.4 +[0.5.3]: https://github.com/brson/home/compare/v0.5.2...v0.5.3 +[0.5.2]: https://github.com/brson/home/compare/v0.5.1...v0.5.2 [0.5.1]: https://github.com/brson/home/compare/v0.5.0...v0.5.1 [0.5.0]: https://github.com/brson/home/compare/0.4.2...v0.5.0 diff --git a/Cargo.toml b/Cargo.toml index f7c8296901c..052b6193215 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "home" -version = "0.5.3" # also update `html_root_url` in `src/lib.rs` +version = "0.5.4" # also update `html_root_url` in `src/lib.rs` authors = [ "Brian Anderson " ] documentation = "https://docs.rs/home" edition = "2018" diff --git a/src/lib.rs b/src/lib.rs index ee3931aba1b..ad254ca3bb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,7 @@ //! //! [discussion]: https://github.com/rust-lang/rust/pull/46799#issuecomment-361156935 -#![doc(html_root_url = "https://docs.rs/home/0.5.3")] +#![doc(html_root_url = "https://docs.rs/home/0.5.4")] #![deny(rust_2018_idioms)] pub mod env; From dbb8dada1932f1f9d4cb61f8b52b5c0114098544 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 12 Dec 2022 13:46:41 -0500 Subject: [PATCH 80/84] Add crate --- {.github => crates/home/.github}/workflows/check.yml | 0 {.github => crates/home/.github}/workflows/scheduled.yml | 0 {.github => crates/home/.github}/workflows/test.yml | 0 .gitignore => crates/home/.gitignore | 0 .rustfmt.toml => crates/home/.rustfmt.toml | 0 CHANGELOG.md => crates/home/CHANGELOG.md | 0 Cargo.toml => crates/home/Cargo.toml | 0 LICENSE-APACHE => crates/home/LICENSE-APACHE | 0 LICENSE-MIT => crates/home/LICENSE-MIT | 0 README.md => crates/home/README.md | 0 {src => crates/home/src}/env.rs | 0 {src => crates/home/src}/lib.rs | 0 {src => crates/home/src}/windows.rs | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename {.github => crates/home/.github}/workflows/check.yml (100%) rename {.github => crates/home/.github}/workflows/scheduled.yml (100%) rename {.github => crates/home/.github}/workflows/test.yml (100%) rename .gitignore => crates/home/.gitignore (100%) rename .rustfmt.toml => crates/home/.rustfmt.toml (100%) rename CHANGELOG.md => crates/home/CHANGELOG.md (100%) rename Cargo.toml => crates/home/Cargo.toml (100%) rename LICENSE-APACHE => crates/home/LICENSE-APACHE (100%) rename LICENSE-MIT => crates/home/LICENSE-MIT (100%) rename README.md => crates/home/README.md (100%) rename {src => crates/home/src}/env.rs (100%) rename {src => crates/home/src}/lib.rs (100%) rename {src => crates/home/src}/windows.rs (100%) diff --git a/.github/workflows/check.yml b/crates/home/.github/workflows/check.yml similarity index 100% rename from .github/workflows/check.yml rename to crates/home/.github/workflows/check.yml diff --git a/.github/workflows/scheduled.yml b/crates/home/.github/workflows/scheduled.yml similarity index 100% rename from .github/workflows/scheduled.yml rename to crates/home/.github/workflows/scheduled.yml diff --git a/.github/workflows/test.yml b/crates/home/.github/workflows/test.yml similarity index 100% rename from .github/workflows/test.yml rename to crates/home/.github/workflows/test.yml diff --git a/.gitignore b/crates/home/.gitignore similarity index 100% rename from .gitignore rename to crates/home/.gitignore diff --git a/.rustfmt.toml b/crates/home/.rustfmt.toml similarity index 100% rename from .rustfmt.toml rename to crates/home/.rustfmt.toml diff --git a/CHANGELOG.md b/crates/home/CHANGELOG.md similarity index 100% rename from CHANGELOG.md rename to crates/home/CHANGELOG.md diff --git a/Cargo.toml b/crates/home/Cargo.toml similarity index 100% rename from Cargo.toml rename to crates/home/Cargo.toml diff --git a/LICENSE-APACHE b/crates/home/LICENSE-APACHE similarity index 100% rename from LICENSE-APACHE rename to crates/home/LICENSE-APACHE diff --git a/LICENSE-MIT b/crates/home/LICENSE-MIT similarity index 100% rename from LICENSE-MIT rename to crates/home/LICENSE-MIT diff --git a/README.md b/crates/home/README.md similarity index 100% rename from README.md rename to crates/home/README.md diff --git a/src/env.rs b/crates/home/src/env.rs similarity index 100% rename from src/env.rs rename to crates/home/src/env.rs diff --git a/src/lib.rs b/crates/home/src/lib.rs similarity index 100% rename from src/lib.rs rename to crates/home/src/lib.rs diff --git a/src/windows.rs b/crates/home/src/windows.rs similarity index 100% rename from src/windows.rs rename to crates/home/src/windows.rs From 98a3d4e385039f82239537df43443683cc46307e Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 12 Dec 2022 13:49:46 -0500 Subject: [PATCH 81/84] Add home crate to CI --- .github/workflows/main.yml | 1 + Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cd08bebddd5..d16d04223c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,6 +99,7 @@ jobs: CARGO_TARGET_DIR: target - run: cargo test -p cargo-platform - run: cargo test -p cargo-util + - run: cargo test -p home - run: cargo test --manifest-path crates/mdman/Cargo.toml - run: cargo build --manifest-path crates/credential/cargo-credential-1password/Cargo.toml - run: cargo build --manifest-path crates/credential/cargo-credential-gnome-secret/Cargo.toml diff --git a/Cargo.toml b/Cargo.toml index d3352269b62..de48b4aaf08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ git2 = "0.15.0" git2-curl = "0.16.0" glob = "0.3.0" hex = "0.4" -home = "0.5" +home = { path = "crates/home", version = "0.5" } http-auth = { version = "0.1.6", default-features = false } humantime = "2.0.0" indexmap = "1" From ac9da4b1932ac4e150baf0117103a57edace125e Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 12 Dec 2022 13:52:23 -0500 Subject: [PATCH 82/84] home: Remove github ci, link license, remove others --- crates/home/.github/workflows/check.yml | 107 ----------- crates/home/.github/workflows/scheduled.yml | 64 ------- crates/home/.github/workflows/test.yml | 87 --------- crates/home/.gitignore | 2 - crates/home/.rustfmt.toml | 4 - crates/home/LICENSE-APACHE | 202 +------------------- crates/home/LICENSE-MIT | 22 +-- crates/home/src/windows.rs | 8 +- 8 files changed, 9 insertions(+), 487 deletions(-) delete mode 100644 crates/home/.github/workflows/check.yml delete mode 100644 crates/home/.github/workflows/scheduled.yml delete mode 100644 crates/home/.github/workflows/test.yml delete mode 100644 crates/home/.gitignore delete mode 100644 crates/home/.rustfmt.toml mode change 100644 => 120000 crates/home/LICENSE-APACHE mode change 100644 => 120000 crates/home/LICENSE-MIT diff --git a/crates/home/.github/workflows/check.yml b/crates/home/.github/workflows/check.yml deleted file mode 100644 index 704f241eee2..00000000000 --- a/crates/home/.github/workflows/check.yml +++ /dev/null @@ -1,107 +0,0 @@ -on: - push: - branches: [main] - pull_request: -name: check -jobs: - fmt: - runs-on: ubuntu-latest - name: stable / fmt - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - components: rustfmt - - name: cargo fmt --check - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --check - clippy: - runs-on: ubuntu-latest - name: ${{ matrix.toolchain }} / clippy - strategy: - fail-fast: false - matrix: - toolchain: [stable, beta] - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install ${{ matrix.toolchain }} - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.toolchain }} - default: true - components: clippy - - name: cargo clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - doc: - runs-on: ubuntu-latest - name: nightly / doc - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install nightly - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - default: true - - name: cargo doc - uses: actions-rs/cargo@v1 - with: - command: doc - args: --no-deps --all-features - env: - RUSTDOCFLAGS: --cfg docsrs - hack: - runs-on: ubuntu-latest - name: ubuntu / stable / features - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - - name: cargo install cargo-hack - uses: taiki-e/install-action@cargo-hack - - name: cargo hack - uses: actions-rs/cargo@v1 - with: - command: hack - args: --feature-powerset check --lib --tests - msrv: - runs-on: ubuntu-latest - # we use a matrix here just because env can't be used in job names - # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability - strategy: - matrix: - msrv: [1.36.0] - name: ubuntu / ${{ matrix.msrv }} - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install ${{ matrix.toolchain }} - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.msrv }} - default: true - - name: cargo +${{ matrix.msrv }} check - uses: actions-rs/cargo@v1 - with: - command: check diff --git a/crates/home/.github/workflows/scheduled.yml b/crates/home/.github/workflows/scheduled.yml deleted file mode 100644 index a5f53110bf1..00000000000 --- a/crates/home/.github/workflows/scheduled.yml +++ /dev/null @@ -1,64 +0,0 @@ -on: - push: - branches: [main] - pull_request: - schedule: - - cron: '7 7 * * *' -name: rolling -jobs: - # https://twitter.com/mycoliza/status/1571295690063753218 - nightly: - runs-on: ubuntu-latest - name: ubuntu / nightly - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install nightly - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - default: true - - name: cargo generate-lockfile - if: hashFiles('Cargo.lock') == '' - uses: actions-rs/cargo@v1 - with: - command: generate-lockfile - - name: cargo test --locked - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked --all-features --all-targets - # https://twitter.com/alcuadrado/status/1571291687837732873 - update: - runs-on: ubuntu-latest - name: ubuntu / beta / updated - # There's no point running this if no Cargo.lock was checked in in the - # first place, since we'd just redo what happened in the regular test job. - # Unfortunately, hashFiles only works in if on steps, so we reepeat it. - # if: hashFiles('Cargo.lock') != '' - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install beta - if: hashFiles('Cargo.lock') != '' - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: beta - default: true - - name: cargo update - if: hashFiles('Cargo.lock') != '' - uses: actions-rs/cargo@v1 - with: - command: update - - name: cargo test - if: hashFiles('Cargo.lock') != '' - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked --all-features --all-targets - env: - RUSTFLAGS: -D deprecated diff --git a/crates/home/.github/workflows/test.yml b/crates/home/.github/workflows/test.yml deleted file mode 100644 index af346295a6a..00000000000 --- a/crates/home/.github/workflows/test.yml +++ /dev/null @@ -1,87 +0,0 @@ -on: - push: - branches: [main] - pull_request: -name: test -jobs: - required: - runs-on: ubuntu-latest - name: ubuntu / ${{ matrix.toolchain }} - strategy: - matrix: - toolchain: [stable, beta] - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install ${{ matrix.toolchain }} - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: ${{ matrix.toolchain }} - default: true - - name: cargo generate-lockfile - if: hashFiles('Cargo.lock') == '' - uses: actions-rs/cargo@v1 - with: - command: generate-lockfile - # https://twitter.com/jonhoo/status/1571290371124260865 - - name: cargo test --locked - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked --all-features --all-targets - minimal: - runs-on: ubuntu-latest - name: ubuntu / stable / minimal-versions - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - - name: Install nightly for -Zminimal-versions - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - - name: cargo update -Zminimal-versions - uses: actions-rs/cargo@v1 - with: - command: update - toolchain: nightly - args: -Zminimal-versions - - name: cargo test - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked --all-features --all-targets - os-check: - runs-on: ${{ matrix.os }} - name: ${{ matrix.os }} / stable - strategy: - fail-fast: false - matrix: - os: [macos-latest, windows-latest] - steps: - - uses: actions/checkout@v3 - with: - submodules: true - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - - name: cargo generate-lockfile - if: hashFiles('Cargo.lock') == '' - uses: actions-rs/cargo@v1 - with: - command: generate-lockfile - - name: cargo test - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked --all-features --all-targets diff --git a/crates/home/.gitignore b/crates/home/.gitignore deleted file mode 100644 index 2c96eb1b651..00000000000 --- a/crates/home/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -Cargo.lock diff --git a/crates/home/.rustfmt.toml b/crates/home/.rustfmt.toml deleted file mode 100644 index 17120d6f6c4..00000000000 --- a/crates/home/.rustfmt.toml +++ /dev/null @@ -1,4 +0,0 @@ -max_width = 120 -edition = "2018" -merge_derives = false -use_field_init_shorthand = true diff --git a/crates/home/LICENSE-APACHE b/crates/home/LICENSE-APACHE deleted file mode 100644 index c3164555677..00000000000 --- a/crates/home/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright 2019 Brian Anderson - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/crates/home/LICENSE-APACHE b/crates/home/LICENSE-APACHE new file mode 120000 index 00000000000..1cd601d0a3a --- /dev/null +++ b/crates/home/LICENSE-APACHE @@ -0,0 +1 @@ +../../LICENSE-APACHE \ No newline at end of file diff --git a/crates/home/LICENSE-MIT b/crates/home/LICENSE-MIT deleted file mode 100644 index f613bcb1f3c..00000000000 --- a/crates/home/LICENSE-MIT +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Brian Anderson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/crates/home/LICENSE-MIT b/crates/home/LICENSE-MIT new file mode 120000 index 00000000000..b2cfbdc7b0b --- /dev/null +++ b/crates/home/LICENSE-MIT @@ -0,0 +1 @@ +../../LICENSE-MIT \ No newline at end of file diff --git a/crates/home/src/windows.rs b/crates/home/src/windows.rs index 30a535df5ce..4e0cd8ec513 100644 --- a/crates/home/src/windows.rs +++ b/crates/home/src/windows.rs @@ -19,7 +19,13 @@ pub fn home_dir_inner() -> Option { fn home_dir_crt() -> Option { unsafe { let mut path: Vec = Vec::with_capacity(MAX_PATH); - match SHGetFolderPathW(ptr::null_mut(), CSIDL_PROFILE, ptr::null_mut(), 0, path.as_mut_ptr()) { + match SHGetFolderPathW( + ptr::null_mut(), + CSIDL_PROFILE, + ptr::null_mut(), + 0, + path.as_mut_ptr(), + ) { S_OK => { let len = wcslen(path.as_ptr()); path.set_len(len); From faa9b31dffc530578302e3fc8b0946923de5b218 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Mon, 12 Dec 2022 14:02:07 -0500 Subject: [PATCH 83/84] Remove home crate path dep --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index de48b4aaf08..d3352269b62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ git2 = "0.15.0" git2-curl = "0.16.0" glob = "0.3.0" hex = "0.4" -home = { path = "crates/home", version = "0.5" } +home = "0.5" http-auth = { version = "0.1.6", default-features = false } humantime = "2.0.0" indexmap = "1" From 18a06cc809cd0c7dc2a7297ad4a2b4b98b829d22 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Tue, 13 Dec 2022 15:40:26 -0500 Subject: [PATCH 84/84] fix ci to test local home crate --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d16d04223c7..f9b09ff6868 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -99,7 +99,7 @@ jobs: CARGO_TARGET_DIR: target - run: cargo test -p cargo-platform - run: cargo test -p cargo-util - - run: cargo test -p home + - run: cargo test --manifest-path crates/home/Cargo.toml - run: cargo test --manifest-path crates/mdman/Cargo.toml - run: cargo build --manifest-path crates/credential/cargo-credential-1password/Cargo.toml - run: cargo build --manifest-path crates/credential/cargo-credential-gnome-secret/Cargo.toml