From aac820e062bdf460cd7053d7907d98967231c012 Mon Sep 17 00:00:00 2001 From: zeroc Date: Sat, 20 Apr 2024 02:25:40 +0800 Subject: [PATCH 1/2] Support customizing the installation location using AVM_HOME env variable --- avm/src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/avm/src/lib.rs b/avm/src/lib.rs index 32881f9c81..882c6819eb 100644 --- a/avm/src/lib.rs +++ b/avm/src/lib.rs @@ -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 = 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") } From 70b0288d21b77df3b40777acc1010af77d648114 Mon Sep 17 00:00:00 2001 From: zeroc Date: Sat, 20 Apr 2024 02:43:42 +0800 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 291d9f83a9..5177b565a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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