Skip to content

Commit

Permalink
Remove dependency on home
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 21, 2024
1 parent 9897df5 commit e27e58f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/.cspell/project-dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mcdc
microkernel
MSYSTEM
nextest
normpath
notcovered
profdata
profraw
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
uses: taiki-e/github-actions/.github/workflows/msrv.yml@main
with:
event_name: ${{ github.event_name }}
# MSRV is 1.74 on Windows due to normpath.
target: x86_64-unknown-linux-gnu
release-dry-run:
uses: taiki-e/github-actions/.github/workflows/release-dry-run.yml@main
tidy:
Expand Down
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pkg-fmt = "tgz"
[dependencies]
anyhow = "1.0.47"
camino = "1.0.5"
cargo-config2 = "0.1.29"
cargo-config2 = "0.1.31"
duct = "0.13.1"
fs-err = "3"
glob = "0.3"
Expand All @@ -43,9 +43,6 @@ tar = "0.4.40"
termcolor = "1.1.2"
walkdir = "2.2.3"

[target.'cfg(windows)'.dependencies]
home = "0.5"

[dev-dependencies]
easy-ext = "1"
rustversion = "1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ cargo-llvm-cov --json | some-program
cargo +stable install cargo-llvm-cov --locked
```

Currently, installing cargo-llvm-cov requires rustc 1.73+.
Currently, installing cargo-llvm-cov requires rustc 1.73+ for non-Windows and rustc 1.74+ for Windows.

cargo-llvm-cov is usually runnable with Cargo versions older than the Rust version
required for installation (e.g., `cargo +1.60 llvm-cov`). Currently, to run
Expand Down
46 changes: 2 additions & 44 deletions src/env.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT

pub(crate) use std::env::*;
use std::{
ffi::OsString,
path::{Path, PathBuf},
};
use std::ffi::OsString;

use anyhow::Result;
pub(crate) use cargo_config2::{cargo_home_with_cwd, home_dir, rustup_home_with_cwd};

pub(crate) fn var(key: &str) -> Result<Option<String>> {
match std::env::var(key) {
Expand All @@ -20,43 +18,3 @@ pub(crate) fn var(key: &str) -> Result<Option<String>> {
pub(crate) fn var_os(key: &str) -> Option<OsString> {
std::env::var_os(key).filter(|v| !v.is_empty())
}

// Use the home crate only on Windows which std::env::home_dir is not correct.
// https://github.com/rust-lang/cargo/blob/0.80.0/crates/home/src/lib.rs#L65-L72
#[cfg(windows)]
pub(crate) use home::home_dir;
#[cfg(not(windows))]
pub(crate) fn home_dir() -> Option<PathBuf> {
#[allow(deprecated)]
std::env::home_dir()
}

// Follow the cargo's behavior.
// https://github.com/rust-lang/cargo/blob/0.80.0/crates/home/src/lib.rs#L77-L86
// https://github.com/rust-lang/cargo/blob/0.80.0/crates/home/src/lib.rs#L114-L123
// https://github.com/rust-lang/cargo/blob/0.80.0/crates/home/src/env.rs#L63-L77
// https://github.com/rust-lang/cargo/blob/0.80.0/crates/home/src/env.rs#L92-L106
pub(crate) fn cargo_home_with_cwd(cwd: &Path) -> Option<PathBuf> {
match var_os("CARGO_HOME").map(PathBuf::from) {
Some(home) => {
if home.is_absolute() {
Some(home)
} else {
Some(cwd.join(home))
}
}
_ => Some(home_dir()?.join(".cargo")),
}
}
pub(crate) fn rustup_home_with_cwd(cwd: &Path) -> Option<PathBuf> {
match var_os("RUSTUP_HOME").map(PathBuf::from) {
Some(home) => {
if home.is_absolute() {
Some(home)
} else {
Some(cwd.join(home))
}
}
_ => Some(home_dir()?.join(".rustup")),
}
}

0 comments on commit e27e58f

Please sign in to comment.