Skip to content

Commit

Permalink
trace log when generating type instead of eprintln
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshang committed Nov 18, 2024
1 parent fc14680 commit 3494fc7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/dfx/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn exec(env: &dyn Environment, opts: GenerateOpts) -> DfxResult {
}

for canister in canister_pool_load.canisters_to_build(&generate_config) {
canister.generate(&canister_pool_load, &generate_config)?;
canister.generate(log, &canister_pool_load, &generate_config)?;
}

Ok(())
Expand Down
15 changes: 9 additions & 6 deletions src/dfx/src/lib/builders/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use dfx_core::network::provider::get_network_context;
use dfx_core::util;
use fn_error_context::context;
use handlebars::Handlebars;
use slog::{trace, Logger};
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::ffi::OsStr;
Expand Down Expand Up @@ -94,6 +95,7 @@ pub trait CanisterBuilder {
/// Generate type declarations for the canister
fn generate(
&self,
logger: &Logger,
pool: &CanisterPool,
info: &CanisterInfo,
config: &BuildConfig,
Expand Down Expand Up @@ -137,8 +139,9 @@ pub trait CanisterBuilder {
return Ok(());
}

eprintln!(
"Generating type declarations for canister {}:",
trace!(
logger,
"Generating type declarations for canister {}",
&info.get_name()
);

Expand Down Expand Up @@ -172,7 +175,7 @@ pub trait CanisterBuilder {
output_did_ts_path.to_string_lossy()
)
})?;
eprintln!(" {}", &output_did_ts_path.display());
trace!(logger, " {}", &output_did_ts_path.display());

compile_handlebars_files("ts", info, generate_output_dir)?;
}
Expand All @@ -191,7 +194,7 @@ pub trait CanisterBuilder {
output_did_js_path.to_string_lossy()
)
})?;
eprintln!(" {}", &output_did_js_path.display());
trace!(logger, " {}", &output_did_js_path.display());

compile_handlebars_files("js", info, generate_output_dir)?;
}
Expand All @@ -206,7 +209,7 @@ pub trait CanisterBuilder {
std::fs::write(&output_mo_path, content).with_context(|| {
format!("Failed to write to {}.", output_mo_path.to_string_lossy())
})?;
eprintln!(" {}", &output_mo_path.display());
trace!(logger, " {}", &output_mo_path.display());
}

// Candid
Expand All @@ -216,7 +219,7 @@ pub trait CanisterBuilder {
.with_extension("did");
dfx_core::fs::copy(&did_from_build, &output_did_path)?;
dfx_core::fs::set_permissions_readwrite(&output_did_path)?;
eprintln!(" {}", &output_did_path.display());
trace!(logger, " {}", &output_did_path.display());
}

Ok(())
Expand Down
10 changes: 8 additions & 2 deletions src/dfx/src/lib/models/canister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ impl Canister {
}

#[context("Failed while trying to generate type declarations for '{}'.", self.info.get_name())]
pub fn generate(&self, pool: &CanisterPool, build_config: &BuildConfig) -> DfxResult {
self.builder.generate(pool, &self.info, build_config)
pub fn generate(
&self,
logger: &Logger,
pool: &CanisterPool,
build_config: &BuildConfig,
) -> DfxResult {
self.builder
.generate(logger, pool, &self.info, build_config)
}

#[context("Failed to post-process wasm of canister '{}'.", self.info.get_name())]
Expand Down

0 comments on commit 3494fc7

Please sign in to comment.