@@ -583,15 +583,25 @@ impl CanisterPool {
583
583
let source_ids = & self . imports . borrow ( ) . nodes ;
584
584
let start: Vec < _ > =
585
585
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`.
589
589
let mut dest_graph: DiGraph < CanisterId , ( ) > = DiGraph :: new ( ) ;
590
590
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
+
592
603
let bfs = Bfs :: new ( & source_graph, start_node) ;
593
604
let mut filtered_bfs = BfsFiltered :: new ( bfs) ;
594
- let mut nodes_map = HashMap :: new ( ) ; // from source graph to dest graph
595
605
filtered_bfs. traverse (
596
606
source_graph,
597
607
|& s| {
@@ -623,12 +633,7 @@ impl CanisterPool {
623
633
let child_canister = self . get_first_canister_with_name ( & child_name) . unwrap ( ) . canister_id ( ) ;
624
634
625
635
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) ;
627
636
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
- ) ;
632
637
dest_graph. add_edge ( dest_parent_id, dest_child_id, ( ) ) ;
633
638
}
634
639
) ;
0 commit comments