Skip to content

Commit fceda1d

Browse files
committed
misc
1 parent 8078ced commit fceda1d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/dfx/src/lib/builders/motoko.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use dfx_core::config::cache::Cache;
1616
use dfx_core::config::model::dfinity::{MetadataVisibility, Profile};
1717
use dfx_core::fs::metadata;
1818
use fn_error_context::context;
19+
use petgraph::visit::Bfs;
1920
use slog::{info, o, trace, warn, Logger};
2021
use std::collections::BTreeMap;
2122
use std::convert::TryFrom;
@@ -45,7 +46,7 @@ impl MotokoBuilder {
4546
// TODO: Rename this function.
4647
#[context("Failed to find imports for canister at '{}'.", info.get_main_path().display())]
4748
fn get_imports(cache: &dyn Cache, info: &MotokoCanisterInfo, imports: &mut ImportsTracker) -> DfxResult<()> {
48-
#[context("Failed recursive dependency detection at {}.", file.display())] // FIXME
49+
#[context("Failed recursive dependency detection at {}.", file.display())]
4950
fn get_imports_recursive (
5051
cache: &dyn Cache,
5152
file: &Path,
@@ -94,7 +95,7 @@ impl CanisterBuilder for MotokoBuilder {
9495
info: &CanisterInfo,
9596
) -> DfxResult<Vec<CanisterId>> {
9697
let motoko_info = info.as_info::<MotokoCanisterInfo>()?;
97-
get_imports(self.cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut())?; // TODO: slow operation
98+
get_imports(self.cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut())?;
9899

99100
Ok(pool.imports.borrow().nodes
100101
.iter()
@@ -145,7 +146,7 @@ impl CanisterBuilder for MotokoBuilder {
145146
std::fs::create_dir_all(idl_dir_path)
146147
.with_context(|| format!("Failed to create {}.", idl_dir_path.to_string_lossy()))?;
147148

148-
get_imports(cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut())?; // TODO: repeated slow operation
149+
get_imports(cache.as_ref(), &motoko_info, &mut *pool.imports.borrow_mut())?;
149150

150151
// If the management canister is being imported, emit the candid file.
151152
if pool.imports.borrow().nodes.contains_key(&MotokoImport::Ic("aaaaa-aa".to_string()))
@@ -172,11 +173,12 @@ impl CanisterBuilder for MotokoBuilder {
172173
// Check that one of the dependencies is newer than the target:
173174
if let Ok(wasm_file_metadata) = metadata(output_wasm_path) {
174175
let wasm_file_time = wasm_file_metadata.modified()?;
175-
let imports = pool.imports.borrow();
176-
let mut import_iter = imports.nodes.iter();
176+
let mut imports = pool.imports.borrow_mut();
177+
let start = imports.graph.add_node(MotokoImport::Relative(motoko_info.get_main_path().to_path_buf())); // Start with oput canister.
178+
let mut import_iter = Bfs::new(&imports.graph, start);
177179
loop {
178-
if let Some(import) = import_iter.next() {
179-
let imported_file = match import.0 {
180+
if let Some(import) = import_iter.next(&imports.graph) {
181+
let imported_file = match &imports.graph[import] {
180182
MotokoImport::Canister(canister_name) => {
181183
if let Some(canister) = pool.get_first_canister_with_name(canister_name.as_str()) {
182184
let main_file = canister.get_info().get_main_file();
@@ -214,7 +216,7 @@ impl CanisterBuilder for MotokoBuilder {
214216
} else {
215217
Path::new(path.as_str()).to_owned()
216218
};
217-
let path2 = pre_path.to_string_lossy() + ".mo"; // TODO: Is `lossy` OK?
219+
let path2 = pre_path.to_str().unwrap().to_owned() + ".mo";
218220
let path2 = path2.to_string();
219221
let path2 = Path::new(&path2);
220222
if path2.exists() { // TODO: Is it correct order of two variants?
@@ -240,7 +242,7 @@ impl CanisterBuilder for MotokoBuilder {
240242
};
241243
};
242244
} else {
243-
// trace!(log, "Canister {} already compiled", canister_info.get_name()); // TODO
245+
// println!("Canister {} already compiled.", canister_info.get_name()); // TODO
244246
return Ok(BuildOutput { // duplicate code
245247
canister_id: canister_info
246248
.get_canister_id()

0 commit comments

Comments
 (0)