Skip to content

Commit a75c90f

Browse files
chore: Update dfx generate output (#4097)
1 parent ca9a3f4 commit a75c90f

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

src/dfx/src/commands/generate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,17 @@ pub fn exec(env: &dyn Environment, opts: GenerateOpts) -> DfxResult {
6969
.unwrap_or(false)
7070
{
7171
let canister_pool_build = CanisterPool::load(&env, true, &build_dependees)?;
72-
slog::info!(log, "Building canisters before generate for Motoko");
72+
let spinner = env.new_spinner("Building Motoko canisters before generation...".into());
7373
let runtime = Runtime::new().expect("Unable to create a runtime");
7474
runtime.block_on(canister_pool_build.build_or_fail(&env, log, &build_config))?;
75+
spinner.finish_and_clear();
7576
}
7677

78+
let spinner = env.new_spinner("Generating type declarations...".into());
7779
for canister in canister_pool_load.canisters_to_build(&generate_config) {
7880
canister.generate(&env, log, &canister_pool_load, &generate_config)?;
7981
}
82+
spinner.finish_and_clear();
8083

8184
Ok(())
8285
}

src/dfx/src/lib/builders/mod.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use dfx_core::network::provider::get_network_context;
1212
use dfx_core::util;
1313
use fn_error_context::context;
1414
use handlebars::Handlebars;
15-
use slog::{trace, Logger};
15+
use slog::{info, trace, Logger};
1616
use std::borrow::Cow;
1717
use std::collections::BTreeMap;
1818
use std::ffi::OsStr;
@@ -115,7 +115,7 @@ pub trait CanisterBuilder {
115115
.with_context(|| {
116116
format!(
117117
"Failed to canonicalize output dir {}.",
118-
generate_output_dir.to_string_lossy()
118+
generate_output_dir.display()
119119
)
120120
})?;
121121
if !generate_output_dir.starts_with(info.get_workspace_root()) {
@@ -125,10 +125,7 @@ pub trait CanisterBuilder {
125125
);
126126
}
127127
std::fs::remove_dir_all(&generate_output_dir).with_context(|| {
128-
format!(
129-
"Failed to remove dir: {}",
130-
generate_output_dir.to_string_lossy()
131-
)
128+
format!("Failed to remove dir: {}", generate_output_dir.display())
132129
})?;
133130
}
134131

@@ -139,29 +136,24 @@ pub trait CanisterBuilder {
139136
.context("`bindings` must not be None")?;
140137

141138
if bindings.is_empty() {
142-
eprintln!("`{}.declarations.bindings` in dfx.json was set to be an empty list, so no type declarations will be generated.", &info.get_name());
139+
info!(logger, "`{}.declarations.bindings` in dfx.json was set to be an empty list, so no type declarations will be generated.", &info.get_name());
143140
return Ok(());
144141
}
145142

146-
trace!(
147-
logger,
148-
"Generating type declarations for canister {}",
149-
&info.get_name()
150-
);
151-
152-
std::fs::create_dir_all(generate_output_dir).with_context(|| {
143+
let spinner = env.new_spinner(
153144
format!(
154-
"Failed to create dir: {}",
155-
generate_output_dir.to_string_lossy()
145+
"Generating type declarations for canister {}",
146+
&info.get_name()
156147
)
157-
})?;
148+
.into(),
149+
);
150+
151+
std::fs::create_dir_all(generate_output_dir)
152+
.with_context(|| format!("Failed to create dir: {}", generate_output_dir.display()))?;
158153

159154
let did_from_build = self.get_candid_path(env, pool, info, config)?;
160155
if !did_from_build.exists() {
161-
bail!(
162-
"Candid file: {} doesn't exist.",
163-
did_from_build.to_string_lossy()
164-
);
156+
bail!("Candid file: {} doesn't exist.", did_from_build.display());
165157
}
166158

167159
let (env, ty) = CandidSource::File(did_from_build.as_path()).load()?;
@@ -192,12 +184,8 @@ pub trait CanisterBuilder {
192184
.with_extension("did.js");
193185
let content =
194186
ensure_trailing_newline(candid_parser::bindings::javascript::compile(&env, &ty));
195-
std::fs::write(&output_did_js_path, content).with_context(|| {
196-
format!(
197-
"Failed to write to {}.",
198-
output_did_js_path.to_string_lossy()
199-
)
200-
})?;
187+
std::fs::write(&output_did_js_path, content)
188+
.with_context(|| format!("Failed to write to {}.", output_did_js_path.display()))?;
201189
trace!(logger, " {}", &output_did_js_path.display());
202190

203191
compile_handlebars_files("js", info, generate_output_dir)?;
@@ -210,9 +198,8 @@ pub trait CanisterBuilder {
210198
.with_extension("mo");
211199
let content =
212200
ensure_trailing_newline(candid_parser::bindings::motoko::compile(&env, &ty));
213-
std::fs::write(&output_mo_path, content).with_context(|| {
214-
format!("Failed to write to {}.", output_mo_path.to_string_lossy())
215-
})?;
201+
std::fs::write(&output_mo_path, content)
202+
.with_context(|| format!("Failed to write to {}.", output_mo_path.display()))?;
216203
trace!(logger, " {}", &output_mo_path.display());
217204
}
218205

@@ -226,6 +213,14 @@ pub trait CanisterBuilder {
226213
trace!(logger, " {}", &output_did_path.display());
227214
}
228215

216+
spinner.finish_and_clear();
217+
info!(
218+
logger,
219+
"Generated type declarations for canister {} to {}",
220+
&info.get_name(),
221+
generate_output_dir.display()
222+
);
223+
229224
Ok(())
230225
}
231226

0 commit comments

Comments
 (0)