diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e783256061..2124ae6677 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -5,6 +5,12 @@ == DFX +=== feat: Introduce DFX_CACHE_ROOT environment variable + +A new environment variable, `DFX_CACHE_ROOT`, has been introduced to allow setting the cache root directory to a different location than the configuration root directory. Previously `DFX_CONFIG_ROOT` was repurposed for this which only allowed one location to be set for both the cache and configuration root directories. + +This is a breaking change since setting `DFX_CONFIG_ROOT` will no longer set the cache root directory to that location. + === fix: Error if nonzero cycles are passed without a wallet proxy Previously, `dfx canister call --with-cycles 1` would silently ignore the `--with-cycles` argument as the DFX principal has no way to pass cycles and the call must be forwarded through the wallet. Now it will error instead of silently ignoring it. To forward a call through the wallet, use `--wallet $(dfx identity get-wallet)`, or `--wallet $(dfx identity --network ic get-wallet)` for mainnet. diff --git a/check-binaries.nix b/check-binaries.nix index eac4566f7c..8da9da7373 100644 --- a/check-binaries.nix +++ b/check-binaries.nix @@ -15,7 +15,7 @@ pkgs.runCommand "check-binaries" { ++ lib.optional stdenv.isLinux [ glibc.bin patchelf ]; } '' mkdir -p $out - export DFX_CONFIG_ROOT="$out" + export DFX_CACHE_ROOT="$out" cp ${dfx.standalone}/bin/dfx dfx ${pkgs.lib.optionalString pkgs.stdenv.isLinux '' diff --git a/e2e/tests-dfx/dfx_install.bash b/e2e/tests-dfx/dfx_install.bash index f4394f4bad..081408200b 100644 --- a/e2e/tests-dfx/dfx_install.bash +++ b/e2e/tests-dfx/dfx_install.bash @@ -15,7 +15,7 @@ teardown() { @test "dfx cache show does not install the dfx version into the cache" { [ "$USE_IC_REF" ] && skip "skipped for ic-ref" - test -z "$(ls -A "$DFX_CONFIG_ROOT")" + test -z "$(ls -A "$DFX_CACHE_ROOT")" assert_command dfx cache show @@ -23,8 +23,8 @@ teardown() { test ! -e "$(dfx cache show)" # it does create the empty versions directory though - test -d "$DFX_CONFIG_ROOT/.cache/dfinity/versions" - test -z "$(ls -A "$DFX_CONFIG_ROOT/.cache/dfinity/versions"``)" + test -d "$DFX_CACHE_ROOT/.cache/dfinity/versions" + test -z "$(ls -A "$DFX_CACHE_ROOT/.cache/dfinity/versions"``)" } @test "non-forced install populates an empty cache" { diff --git a/e2e/tests-dfx/mode_reinstall.bash b/e2e/tests-dfx/mode_reinstall.bash index b49fadd036..a2841d15a3 100644 --- a/e2e/tests-dfx/mode_reinstall.bash +++ b/e2e/tests-dfx/mode_reinstall.bash @@ -5,6 +5,7 @@ load ../utils/_ setup() { # We want to work from a temporary directory, different for every test. x=$(mktemp -d -t dfx-e2e-XXXXXXXX) + export DFX_CACHE_ROOT="$x" export DFX_CONFIG_ROOT="$x" cd "$x" || exit export RUST_BACKTRACE=1 @@ -14,6 +15,7 @@ setup() { teardown() { dfx_stop + rm -rf "$DFX_CACHE_ROOT" rm -rf "$DFX_CONFIG_ROOT" } diff --git a/e2e/tests-dfx/upgrade_check.bash b/e2e/tests-dfx/upgrade_check.bash index b1c43542ac..9faa947534 100644 --- a/e2e/tests-dfx/upgrade_check.bash +++ b/e2e/tests-dfx/upgrade_check.bash @@ -5,6 +5,7 @@ load ../utils/_ setup() { # We want to work from a temporary directory, different for every test. x=$(mktemp -d -t dfx-e2e-XXXXXXXX) + export DFX_CACHE_ROOT="$x" export DFX_CONFIG_ROOT="$x" cd "$x" || exit export RUST_BACKTRACE=1 @@ -14,6 +15,7 @@ setup() { teardown() { dfx_stop + rm -rf "$DFX_CACHE_ROOT" rm -rf "$DFX_CONFIG_ROOT" } diff --git a/e2e/tests-dfx/usage_env.bash b/e2e/tests-dfx/usage_env.bash index 536eb1efb7..8c66493671 100644 --- a/e2e/tests-dfx/usage_env.bash +++ b/e2e/tests-dfx/usage_env.bash @@ -21,15 +21,16 @@ teardown() { #cache # create a new project to install dfx cache - assert_command_fail ls "$DFX_CONFIG_ROOT/.cache/dfinity/versions" + assert_command_fail ls "$DFX_CACHE_ROOT/.cache/dfinity/versions" dfx new hello - assert_command ls "$DFX_CONFIG_ROOT/.cache/dfinity/versions" + assert_command ls "$DFX_CACHE_ROOT/.cache/dfinity/versions" assert_command_fail ls "$HOME/.cache/dfinity/versions" rm -rf hello ( # use subshell to retain $DFX_CONFIG_ROOT for teardown # remove configured variable, should use $HOME now + unset DFX_CACHE_ROOT unset DFX_CONFIG_ROOT dfx identity new --disable-encryption bob diff --git a/e2e/utils/_.bash b/e2e/utils/_.bash index 2fc9a27c5c..cfbf087925 100644 --- a/e2e/utils/_.bash +++ b/e2e/utils/_.bash @@ -15,12 +15,14 @@ standard_setup() { export DFX_E2E_TEMP_DIR="$x" mkdir "$x/working-dir" + mkdir "$x/cache-root" mkdir "$x/config-root" mkdir "$x/home-dir" cd "$x/working-dir" || exit export HOME="$x/home-dir" + export DFX_CACHE_ROOT="$x/cache-root" export DFX_CONFIG_ROOT="$x/config-root" export RUST_BACKTRACE=1 } diff --git a/src/dfx/src/config/cache.rs b/src/dfx/src/config/cache.rs index 478ccd084e..273e1a5d24 100644 --- a/src/dfx/src/config/cache.rs +++ b/src/dfx/src/config/cache.rs @@ -67,10 +67,10 @@ impl Cache for DiskBasedCache { } pub fn get_cache_root() -> DfxResult { - let config_root = std::env::var("DFX_CONFIG_ROOT").ok(); + let cache_root = std::env::var("DFX_CACHE_ROOT").ok(); let home = std::env::var("HOME").map_err(|_| DfxError::new(CacheError::CannotFindHomeDirectory()))?; - let root = config_root.unwrap_or(home); + let root = cache_root.unwrap_or(home); let p = PathBuf::from(root).join(".cache").join("dfinity"); if !p.exists() { if let Err(_e) = std::fs::create_dir_all(&p) { diff --git a/src/dfx/src/lib/environment.rs b/src/dfx/src/lib/environment.rs index 92af026a99..f64d31ae85 100644 --- a/src/dfx/src/lib/environment.rs +++ b/src/dfx/src/lib/environment.rs @@ -486,9 +486,9 @@ mod tests { #[test] fn test_passwords() { - let cfg_root = TempDir::new().unwrap(); - let old_var = env::var_os("DFX_CONFIG_ROOT"); - env::set_var("DFX_CONFIG_ROOT", cfg_root.path()); + let cache_root = TempDir::new().unwrap(); + let old_var = env::var_os("DFX_CACHE_ROOT"); + env::set_var("DFX_CACHE_ROOT", cache_root.path()); let log = Logger::root( FullFormat::new(PlainSyncDecorator::new(io::stderr())) .build() @@ -503,9 +503,9 @@ mod tests { assert_eq!(user, "default"); assert_eq!(pass, "hunter2:"); if let Some(old_var) = old_var { - env::set_var("DFX_CONFIG_ROOT", old_var); + env::set_var("DFX_CACHE_ROOT", old_var); } else { - env::remove_var("DFX_CONFIG_ROOT"); + env::remove_var("DFX_CACHE_ROOT"); } } }