Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customizing the installation location #2917

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions avm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Loading