use std::{
env::var_os,
path::{Path, PathBuf},
};
use binstalk_manifests::cargo_config::Config;
use tracing::debug;
pub fn get_cargo_roots_path(
cargo_roots: Option<PathBuf>,
cargo_home: PathBuf,
config: &mut Config,
) -> Option<PathBuf> {
if let Some(p) = cargo_roots {
Some(p)
} else if let Some(p) = var_os("CARGO_INSTALL_ROOT") {
let p = PathBuf::from(p);
debug!("using CARGO_INSTALL_ROOT ({})", p.display());
Some(p)
} else if let Some(root) = config.install.take().and_then(|install| install.root) {
debug!("using `install.root` {} from cargo config", root.display());
Some(root)
} else {
debug!("using ({}) as cargo home", cargo_home.display());
Some(cargo_home)
}
}
pub fn get_install_path(
install_path: Option<PathBuf>,
cargo_roots: Option<impl AsRef<Path>>,
) -> (Option<PathBuf>, bool) {
if let Some(p) = install_path {
return (Some(p), true);
}
if let Some(p) = cargo_roots {
return (Some(p.as_ref().join("bin")), false);
}
let dir = dirs::executable_dir();
if let Some(d) = &dir {
debug!("Fallback to {}", d.display());
}
(dir, true)
}