Skip to content

Commit f79b3fc

Browse files
adamspofford-dfinityrikonor
authored andcommitted
chore: clean up dfx canister create output (#4080)
* change canister creation to spinners * keep spinners and logs from interfering with each other * Spinner for wallet creation
1 parent 3319c39 commit f79b3fc

File tree

31 files changed

+365
-183
lines changed

31 files changed

+365
-183
lines changed

Cargo.lock

Lines changed: 22 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clippy.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
too-many-arguments-threshold = 16
1+
too-many-arguments-threshold = 16
2+
3+
[[disallowed-types]]
4+
path = "indicatif::ProgressBar"
5+
reason = "use env.new_spinner() for log compatibility"

e2e/tests-dfx/deploy.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ teardown() {
182182
dfx_start
183183
dfx canister create --all --no-wallet
184184
assert_command dfx deploy
185-
assert_not_contains "Creating a wallet canister"
185+
assert_not_contains "Created a wallet canister"
186186
assert_command dfx identity get-wallet
187-
assert_contains "Creating a wallet canister"
187+
assert_contains "Created a wallet canister"
188188
}
189189

190190
@test "can deploy gzip wasm" {

src/dfx-core/src/config/cache.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
#[cfg(windows)]
22
use crate::config::directories::project_dirs;
33
use crate::error::cache::{
4-
DeleteCacheError, EnsureCacheVersionsDirError, GetBinaryCommandPathError, GetCacheRootError,
5-
GetVersionFromCachePathError, IsCacheInstalledError, ListCacheVersionsError,
4+
DeleteCacheError, EnsureCacheVersionsDirError, GetCacheRootError, GetVersionFromCachePathError,
5+
IsCacheInstalledError, ListCacheVersionsError,
66
};
77
#[cfg(not(windows))]
88
use crate::foundation::get_user_home;
99
use crate::fs::composite::ensure_dir_exists;
1010
use semver::Version;
1111
use std::path::{Path, PathBuf};
1212

13-
pub trait Cache {
14-
fn version_str(&self) -> String;
15-
fn is_installed(&self) -> Result<bool, IsCacheInstalledError>;
16-
fn delete(&self) -> Result<(), DeleteCacheError>;
17-
fn get_binary_command_path(
18-
&self,
19-
binary_name: &str,
20-
) -> Result<PathBuf, GetBinaryCommandPathError>;
21-
fn get_binary_command(
22-
&self,
23-
binary_name: &str,
24-
) -> Result<std::process::Command, GetBinaryCommandPathError>;
25-
}
26-
2713
pub fn get_cache_root() -> Result<PathBuf, GetCacheRootError> {
2814
let cache_root = std::env::var_os("DFX_CACHE_ROOT");
2915
// dirs-next is not used for *nix to preserve existing paths

src/dfx/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ic-utils.workspace = true
7474
ic-wasm = "0.8.0"
7575
icrc-ledger-types = "0.1.5"
7676
idl2json = "0.10.1"
77-
indicatif = "0.16.0"
77+
indicatif = "0.17.0"
7878
itertools.workspace = true
7979
json-patch = "1.0.0"
8080
keyring.workspace = true

src/dfx/src/actors/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub fn start_btc_adapter_actor(
4444
shutdown_controller: Addr<ShutdownController>,
4545
btc_adapter_pid_file_path: PathBuf,
4646
) -> DfxResult<Recipient<BtcAdapterReadySubscribe>> {
47-
let btc_adapter_path = env.get_cache().get_binary_command_path("ic-btc-adapter")?;
47+
let btc_adapter_path = env
48+
.get_cache()
49+
.get_binary_command_path(env, "ic-btc-adapter")?;
4850

4951
let actor_config = btc_adapter::Config {
5052
btc_adapter_path,
@@ -69,7 +71,7 @@ pub fn start_canister_http_adapter_actor(
6971
) -> DfxResult<Recipient<CanisterHttpAdapterReadySubscribe>> {
7072
let adapter_path = env
7173
.get_cache()
72-
.get_binary_command_path("ic-https-outcalls-adapter")?;
74+
.get_binary_command_path(env, "ic-https-outcalls-adapter")?;
7375

7476
let actor_config = canister_http_adapter::Config {
7577
adapter_path,
@@ -133,8 +135,8 @@ pub fn start_replica_actor(
133135
canister_http_adapter_ready_subscribe: Option<Recipient<CanisterHttpAdapterReadySubscribe>>,
134136
) -> DfxResult<Addr<Replica>> {
135137
// get binary path
136-
let replica_path = env.get_cache().get_binary_command_path("replica")?;
137-
let ic_starter_path = env.get_cache().get_binary_command_path("ic-starter")?;
138+
let replica_path = env.get_cache().get_binary_command_path(env, "replica")?;
139+
let ic_starter_path = env.get_cache().get_binary_command_path(env, "ic-starter")?;
138140

139141
setup_replica_env(local_server_descriptor, &replica_config)?;
140142
let replica_pid_path = local_server_descriptor.replica_pid_path();
@@ -169,7 +171,7 @@ pub fn start_pocketic_proxy_actor(
169171
pocketic_proxy_pid_path: PathBuf,
170172
pocketic_proxy_port_path: PathBuf,
171173
) -> DfxResult<Addr<PocketIcProxy>> {
172-
let pocketic_proxy_path = env.get_cache().get_binary_command_path("pocket-ic")?;
174+
let pocketic_proxy_path = env.get_cache().get_binary_command_path(env, "pocket-ic")?;
173175
let actor_config = pocketic_proxy::Config {
174176
logger: Some(env.get_logger().clone()),
175177
port_ready_subscribe,
@@ -190,7 +192,7 @@ pub fn start_pocketic_actor(
190192
shutdown_controller: Addr<ShutdownController>,
191193
pocketic_port_path: PathBuf,
192194
) -> DfxResult<Addr<PocketIc>> {
193-
let pocketic_path = env.get_cache().get_binary_command_path("pocket-ic")?;
195+
let pocketic_path = env.get_cache().get_binary_command_path(env, "pocket-ic")?;
194196

195197
// Touch the port file. This ensures it is empty prior to
196198
// handing it over to PocketIC. If we read the file and it has

src/dfx/src/commands/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::cache::DiskBasedCache;
1+
use crate::config::cache::VersionCache;
22
use crate::lib::agent::create_anonymous_agent_environment;
33
use crate::lib::builders::BuildConfig;
44
use crate::lib::environment::Environment;
@@ -44,7 +44,7 @@ pub fn exec(env: &dyn Environment, opts: CanisterBuildOpts) -> DfxResult {
4444

4545
// Check the cache. This will only install the cache if there isn't one installed
4646
// already.
47-
DiskBasedCache::install(&env.get_cache().version_str())?;
47+
VersionCache::install(&env, &env.get_cache().version_str())?;
4848

4949
let build_mode_check = opts.check;
5050

@@ -90,7 +90,7 @@ pub fn exec(env: &dyn Environment, opts: CanisterBuildOpts) -> DfxResult {
9090
.with_build_mode_check(build_mode_check)
9191
.with_canisters_to_build(canisters_to_build)
9292
.with_env_file(env_file);
93-
runtime.block_on(canister_pool.build_or_fail(logger, &build_config))?;
93+
runtime.block_on(canister_pool.build_or_fail(&env, logger, &build_config))?;
9494

9595
Ok(())
9696
}

src/dfx/src/commands/cache/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::cache::DiskBasedCache;
1+
use crate::config::cache::VersionCache;
22
use crate::lib::environment::Environment;
33
use crate::lib::error::{DfxError, DfxResult};
44
use clap::Parser;
@@ -9,6 +9,6 @@ use clap::Parser;
99
pub struct CacheInstall {}
1010

1111
pub fn exec(env: &dyn Environment, _opts: CacheInstall) -> DfxResult {
12-
DiskBasedCache::force_install(&env.get_cache().version_str()).map_err(DfxError::from)?;
12+
VersionCache::force_install(env, &env.get_cache().version_str()).map_err(DfxError::from)?;
1313
Ok(())
1414
}

src/dfx/src/commands/extension/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::commands::DfxCommand;
2-
use crate::config::cache::DiskBasedCache;
2+
use crate::config::cache::VersionCache;
33
use crate::lib::environment::Environment;
44
use crate::lib::error::{DfxError, DfxResult};
55
use anyhow::bail;
@@ -30,7 +30,7 @@ pub struct InstallOpts {
3030
pub fn exec(env: &dyn Environment, opts: InstallOpts) -> DfxResult<()> {
3131
// creating an `extensions` directory in an otherwise empty cache directory would
3232
// cause the cache to be considered "installed" and later commands would fail
33-
DiskBasedCache::install(&env.get_cache().version_str())?;
33+
VersionCache::install(env, &env.get_cache().version_str())?;
3434
let spinner = env.new_spinner(format!("Installing extension: {}", opts.name).into());
3535
let mgr = env.get_extension_manager();
3636
let effective_extension_name = opts.install_as.clone().unwrap_or_else(|| opts.name.clone());

src/dfx/src/commands/generate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::config::cache::DiskBasedCache;
1+
use crate::config::cache::VersionCache;
22
use crate::lib::agent::create_anonymous_agent_environment;
33
use crate::lib::builders::BuildConfig;
44
use crate::lib::environment::Environment;
@@ -28,7 +28,7 @@ pub fn exec(env: &dyn Environment, opts: GenerateOpts) -> DfxResult {
2828

2929
// Check the cache. This will only install the cache if there isn't one installed
3030
// already.
31-
DiskBasedCache::install(&env.get_cache().version_str())?;
31+
VersionCache::install(&env, &env.get_cache().version_str())?;
3232

3333
// Option can be None which means generate types for all canisters
3434
let canisters_to_load = config
@@ -73,11 +73,11 @@ pub fn exec(env: &dyn Environment, opts: GenerateOpts) -> DfxResult {
7373
let canister_pool_build = CanisterPool::load(&env, true, &build_dependees)?;
7474
slog::info!(log, "Building canisters before generate for Motoko");
7575
let runtime = Runtime::new().expect("Unable to create a runtime");
76-
runtime.block_on(canister_pool_build.build_or_fail(log, &build_config))?;
76+
runtime.block_on(canister_pool_build.build_or_fail(&env, log, &build_config))?;
7777
}
7878

7979
for canister in canister_pool_load.canisters_to_build(&generate_config) {
80-
canister.generate(log, &canister_pool_load, &generate_config)?;
80+
canister.generate(&env, log, &canister_pool_load, &generate_config)?;
8181
}
8282

8383
Ok(())

0 commit comments

Comments
 (0)