@@ -556,7 +556,7 @@ impl CanisterPool {
556
556
/// Build only dependencies relevant for `canisters_to_build`.
557
557
#[ context( "Failed to build dependencies graph for canister pool." ) ]
558
558
fn build_dependencies_graph ( & self , canisters_to_build : Option < Vec < String > > ) -> DfxResult < DiGraph < CanisterId , ( ) > > {
559
- let mut graph: DiGraph < CanisterId , ( ) > = DiGraph :: new ( ) ;
559
+ let mut graph: DiGraph < CanisterId , ( ) > = DiGraph :: new ( ) ; // TODO: hack: we below transform DiGraph<MotokoImport> to DiGraph<CanisterId>
560
560
let mut id_set: BTreeMap < CanisterId , NodeIndex < u32 > > = BTreeMap :: new ( ) ;
561
561
562
562
// TODO: Can be done faster by not using `collect` and/or `clone`?
@@ -593,43 +593,54 @@ impl CanisterPool {
593
593
// }
594
594
595
595
// Traverse, creating the graph of dependencies starting from `real_canisters_to_build` set.
596
- let mut current_canisters_to_build =
597
- HashMap :: from_iter ( real_canisters_to_build. iter ( ) . map ( |c| ( c. canister_id ( ) , ( ) ) ) ) ;
598
- for canister_id in current_canisters_to_build. keys ( ) {
599
- id_set. entry ( * canister_id) . or_insert_with ( || graph. add_node ( * canister_id) ) ;
600
- // id_set.insert(*canister_id, graph.add_node(*canister_id)); // TODO: Use this, instead.
601
- }
602
- loop {
603
- let mut current_canisters_to_build2 = HashMap :: new ( ) ;
604
- // println!("self.canisters.len(): {}", self.canisters.len());
596
+ // let mut current_canisters_to_build =
597
+ // HashMap::from_iter(real_canisters_to_build.iter().map(|c| (c.canister_id(), ())));
598
+ // for canister_id in current_canisters_to_build.keys() {
599
+ // id_set.entry(*canister_id).or_insert_with(|| graph.add_node(*canister_id));
600
+ // // id_set.insert(*canister_id, graph.add_node(*canister_id)); // TODO: Use this, instead.
601
+ // }
602
+ // loop {
603
+ // let mut current_canisters_to_build2 = HashMap::new();
604
+ // // println!("self.canisters.len(): {}", self.canisters.len());
605
605
for canister in & self . canisters { // a little inefficient
606
- // FIXME: Remove:
607
- if !current_canisters_to_build. contains_key ( & canister. canister_id ( ) ) {
608
- continue ;
609
- }
606
+ // if !current_canisters_to_build.contains_key(&canister.canister_id()) {
607
+ // continue;
608
+ // }
610
609
let canister_id = canister. canister_id ( ) ;
611
610
let canister_info = & canister. info ;
612
611
// FIXME: Is `unwrap()` in the next operator correct?
613
612
let deps: Vec < CanisterId > = canister. builder . get_dependencies ( self , canister_info) ?
614
613
. into_iter ( ) . filter ( |d| * d != canister_info. get_canister_id ( ) . unwrap ( ) ) . collect ( ) ; // TODO: This is a hack.
615
614
// println!("PARENT: {}, DEPS: {:?}", canister.get_info().get_canister_id()?.to_text(), deps.iter().map(|c| c.to_text()).collect::<Vec<_>>()); // FIXME
616
- let node_ix = * id_set. entry ( canister_id) . or_insert_with ( || graph. add_node ( canister_id) ) ;
617
- for d in deps {
618
- let dep_ix = * id_set. entry ( d) . or_insert_with ( || graph. add_node ( d) ) ;
619
- graph. add_edge ( node_ix, dep_ix, ( ) ) ;
620
- current_canisters_to_build2. insert ( d, ( ) ) ;
621
- println ! ( "canister_id={} -> d={}" , canister_id, d) ;
622
- }
615
+ // let node_ix = *id_set.entry(canister_id).or_insert_with(|| graph.add_node(canister_id));
616
+ // for d in deps {
617
+ // let dep_ix = *id_set.entry(d).or_insert_with(|| graph.add_node(d));
618
+ // graph.add_edge(node_ix, dep_ix, ());
619
+ // current_canisters_to_build2.insert(d, ());
620
+ // println!("canister_id={} -> d={}", canister_id, d);
621
+ // }
623
622
}
624
- println ! ( "NEXT CYCLE" ) ; // FIXME: Remove.
625
- if current_canisters_to_build2. is_empty ( ) { // passed to the end of the graph
626
- break ;
627
- }
628
- current_canisters_to_build = current_canisters_to_build2;
629
- }
623
+ // println!("NEXT CYCLE"); // FIXME: Remove.
624
+ // if current_canisters_to_build2.is_empty() { // passed to the end of the graph
625
+ // break;
626
+ // }
627
+ // current_canisters_to_build = current_canisters_to_build2;
628
+ // }
630
629
631
- println ! ( "id_set: {:?}" , id_set. keys( ) ) ; // FIXME: Remove.
632
- Ok ( graph)
630
+ // Ok(graph)
631
+ Ok ( self . imports . borrow ( ) . graph . filter_map (
632
+ |node_index, node_weight| {
633
+ // B::from(node_weight)
634
+ match node_weight {
635
+ // TODO: `get_first_canister_with_name` is a hack
636
+ MotokoImport :: Canister ( name) => Some ( self . get_first_canister_with_name ( & name) . unwrap ( ) . canister_id ( ) ) ,
637
+ _ => None ,
638
+ }
639
+ } ,
640
+ |edge_index, edge_weight| {
641
+ Some ( ( ) )
642
+ }
643
+ ) )
633
644
}
634
645
635
646
#[ context( "Failed step_prebuild_all." ) ]
0 commit comments