Skip to content

Commit dab915e

Browse files
committed
bug fix (untested)
1 parent 0dbb7e5 commit dab915e

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/dfx/src/lib/models/canister.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -583,15 +583,25 @@ impl CanisterPool {
583583
let source_ids = &self.imports.borrow().nodes;
584584
let start: Vec<_> =
585585
real_canisters_to_build.iter().map(|name| MotokoImport::Canister(name.clone())).collect(); // `clone` is inefficient.
586-
let start = start.into_iter().map(|node| *source_ids.get(&node).unwrap());
587-
// // Transform the graph of file dependencies to graph of canister dependencies.
588-
// // For this do DFS for each of `real_canisters_to_build`.
586+
let start: Vec<_> = start.into_iter().map(|node| *source_ids.get(&node).unwrap()).collect();
587+
// Transform the graph of file dependencies to graph of canister dependencies.
588+
// For this do DFS for each of `real_canisters_to_build`.
589589
let mut dest_graph: DiGraph<CanisterId, ()> = DiGraph::new();
590590
let mut dest_id_set = HashMap::new();
591-
for start_node in start {
591+
for start_node in start.into_iter() {
592+
// Initialize "mirrors" of the parent node of source graph in dest graph:
593+
let parent = source_graph.node_weight(start_node).unwrap();
594+
let parent_name = match parent {
595+
MotokoImport::Canister(name) => name,
596+
_ => {
597+
panic!("programming error");
598+
}
599+
};
600+
let parent_canister = self.get_first_canister_with_name(&parent_name).unwrap().canister_id();
601+
let _ = *dest_id_set.entry(start_node).or_insert_with(|| dest_graph.add_node(parent_canister));
602+
592603
let bfs = Bfs::new(&source_graph, start_node);
593604
let mut filtered_bfs = BfsFiltered::new(bfs);
594-
let mut nodes_map = HashMap::new(); // from source graph to dest graph
595605
filtered_bfs.traverse(
596606
source_graph,
597607
|&s| {
@@ -623,12 +633,7 @@ impl CanisterPool {
623633
let child_canister = self.get_first_canister_with_name(&child_name).unwrap().canister_id();
624634

625635
let dest_parent_id = *dest_id_set.entry(source_parent_id).or_insert_with(|| dest_graph.add_node(parent_canister));
626-
nodes_map.insert(source_parent_id, dest_parent_id);
627636
let dest_child_id = *dest_id_set.entry(source_child_id).or_insert_with(|| dest_graph.add_node(child_canister));
628-
nodes_map.insert(source_child_id, dest_child_id);
629-
nodes_map.entry(source_parent_id).or_insert_with(
630-
|| dest_graph.add_node(*dest_graph.node_weight(source_parent_id).unwrap()) // FIXME: `unwrap()`?
631-
);
632637
dest_graph.add_edge(dest_parent_id, dest_child_id, ());
633638
}
634639
);

0 commit comments

Comments
 (0)