mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 22:30:03 +00:00
Use install.root
in $CARGO_HOME/config.toml
(#884)
Fixed #859 * Impl `cargo_config` * Use `install.root` in `$CARGO_HOME/.cargo/config.toml` before fallback to `cargo_home`. * Improve logging in `get_cargo_roots_path` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
3e830c9fad
commit
58b7044e98
3 changed files with 182 additions and 10 deletions
|
@ -4,23 +4,33 @@ use std::{
|
|||
};
|
||||
|
||||
use binstalk::home::cargo_home;
|
||||
use binstalk_manifests::cargo_config::Config;
|
||||
use tracing::debug;
|
||||
|
||||
pub fn get_cargo_roots_path(cargo_roots: Option<PathBuf>) -> Option<PathBuf> {
|
||||
if let Some(p) = cargo_roots {
|
||||
return Some(p);
|
||||
}
|
||||
|
||||
// Environmental variables
|
||||
if let Some(p) = var_os("CARGO_INSTALL_ROOT") {
|
||||
Some(p)
|
||||
} else if let Some(p) = var_os("CARGO_INSTALL_ROOT") {
|
||||
// Environmental variables
|
||||
let p = PathBuf::from(p);
|
||||
debug!("using CARGO_INSTALL_ROOT ({})", p.display());
|
||||
return Some(p);
|
||||
}
|
||||
|
||||
if let Ok(p) = cargo_home() {
|
||||
debug!("using ({}) as cargo home", p.display());
|
||||
Some(p)
|
||||
} else if let Ok(cargo_home) = cargo_home() {
|
||||
let config_path = cargo_home.join("config.toml");
|
||||
if let Some(root) = Config::load_from_path(&config_path)
|
||||
.ok()
|
||||
.and_then(|config| config.install.root)
|
||||
{
|
||||
debug!(
|
||||
"using `install.root` {} from config {}",
|
||||
root.display(),
|
||||
config_path.display()
|
||||
);
|
||||
Some(root)
|
||||
} else {
|
||||
debug!("using ({}) as cargo home", cargo_home.display());
|
||||
Some(cargo_home)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue