mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-01 09:40:03 +00:00
Split crates and clean up structure of codebase (#294)
Co-authored-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
bf700f9012
commit
4b00f5f143
88 changed files with 2989 additions and 1423 deletions
39
crates/bin/src/install_path.rs
Normal file
39
crates/bin/src/install_path.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use binstall::helpers::statics::cargo_home;
|
||||
use log::debug;
|
||||
|
||||
/// Fetch install path from environment
|
||||
/// roughly follows <https://doc.rust-lang.org/cargo/commands/cargo-install.html#description>
|
||||
///
|
||||
/// Return (install_path, is_custom_install_path)
|
||||
pub fn get_install_path<P: AsRef<Path>>(install_path: Option<P>) -> (Option<Arc<Path>>, bool) {
|
||||
// Command line override first first
|
||||
if let Some(p) = install_path {
|
||||
return (Some(Arc::from(p.as_ref())), true);
|
||||
}
|
||||
|
||||
// Environmental variables
|
||||
if let Ok(p) = std::env::var("CARGO_INSTALL_ROOT") {
|
||||
debug!("using CARGO_INSTALL_ROOT ({p})");
|
||||
let b = PathBuf::from(p);
|
||||
return (Some(Arc::from(b.join("bin"))), true);
|
||||
}
|
||||
|
||||
if let Ok(p) = cargo_home() {
|
||||
debug!("using ({}) as cargo home", p.display());
|
||||
return (Some(p.join("bin").into()), false);
|
||||
}
|
||||
|
||||
// Local executable dir if no cargo is found
|
||||
let dir = dirs::executable_dir();
|
||||
|
||||
if let Some(d) = &dir {
|
||||
debug!("Fallback to {}", d.display());
|
||||
}
|
||||
|
||||
(dir.map(Arc::from), true)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue