@@ -549,18 +549,31 @@ impl CanisterPool {
549
549
id_set. insert ( canister_id, graph. add_node ( canister_id) ) ;
550
550
}
551
551
552
- // Add all the edges.
553
- for canister in & real_canisters_to_build {
554
- let canister_id = canister. canister_id ( ) ;
555
- let canister_info = & canister. info ;
556
- let deps = canister. builder . get_dependencies ( self , canister_info) ?;
557
- if let Some ( node_ix) = id_set. get ( & canister_id) {
558
- for d in deps {
559
- if let Some ( dep_ix) = id_set. get ( & d) {
560
- graph. add_edge ( * node_ix, * dep_ix, ( ) ) ;
552
+ // Traverse the graph of dependencies starting from `real_canisters_to_build` set.
553
+ let mut current_canisters_to_build =
554
+ HashMap :: from_iter ( real_canisters_to_build. iter ( ) . map ( |c| ( c. canister_id ( ) , ( ) ) ) ) ;
555
+ loop {
556
+ let mut current_canisters_to_build2 = HashMap :: new ( ) ;
557
+ for canister in & self . canisters {
558
+ if !current_canisters_to_build. contains_key ( & canister. canister_id ( ) ) {
559
+ break ;
560
+ }
561
+ let canister_id = canister. canister_id ( ) ;
562
+ let canister_info = & canister. info ;
563
+ let deps = canister. builder . get_dependencies ( self , canister_info) ?;
564
+ if let Some ( node_ix) = id_set. get ( & canister_id) {
565
+ for d in deps {
566
+ if let Some ( dep_ix) = id_set. get ( & d) {
567
+ graph. add_edge ( * node_ix, * dep_ix, ( ) ) ;
568
+ current_canisters_to_build2. insert ( * graph. node_weight ( * dep_ix) . unwrap ( ) , ( ) ) ;
569
+ }
561
570
}
562
571
}
563
572
}
573
+ if current_canisters_to_build2. is_empty ( ) { // passed to the end of the graph
574
+ break ;
575
+ }
576
+ current_canisters_to_build = current_canisters_to_build2;
564
577
}
565
578
566
579
// Verify the graph has no cycles.
0 commit comments