avm: Support customizing the installation location (#2917)

This commit is contained in:
zeroc 2024-04-20 19:36:19 +08:00 committed by GitHub
parent 7515c919f8
commit b53bb35cf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -12,6 +12,8 @@ The minor version will be incremented upon a breaking change and the patch versi
### Features
- avm: Support customizing the installation location using `AVM_HOME` environment variable ([#2917](https://github.com/coral-xyz/anchor/pull/2917))
### Fixes
### Breaking

View File

@ -10,26 +10,30 @@ use std::io::Write;
use std::path::PathBuf;
use std::process::Stdio;
/// Storage directory for AVM, ~/.avm
/// Storage directory for AVM, customizable by setting the $AVM_HOME, defaults to ~/.avm
pub static AVM_HOME: Lazy<PathBuf> = Lazy::new(|| {
cfg_if::cfg_if! {
if #[cfg(test)] {
let dir = tempfile::tempdir().expect("Could not create temporary directory");
dir.path().join(".avm")
} else {
let mut user_home = dirs::home_dir().expect("Could not find home directory");
user_home.push(".avm");
user_home
if let Ok(avm_home) = std::env::var("AVM_HOME") {
PathBuf::from(avm_home)
} else {
let mut user_home = dirs::home_dir().expect("Could not find home directory");
user_home.push(".avm");
user_home
}
}
}
});
/// Path to the current version file ~/.avm/.version
/// Path to the current version file $AVM_HOME/.version
fn current_version_file_path() -> PathBuf {
AVM_HOME.join(".version")
}
/// Path to the current version file ~/.avm/bin
/// Path to the current version file $AVM_HOME/bin
fn get_bin_dir_path() -> PathBuf {
AVM_HOME.join("bin")
}