@@ -24,7 +24,7 @@ use petgraph::graph::{DiGraph, NodeIndex};
24
24
use rand:: { thread_rng, RngCore } ;
25
25
use slog:: { error, info, trace, warn, Logger } ;
26
26
use std:: cell:: RefCell ;
27
- use std:: collections:: { BTreeMap , HashSet } ;
27
+ use std:: collections:: { BTreeMap , HashMap , HashSet } ;
28
28
use std:: convert:: TryFrom ;
29
29
use std:: ffi:: OsStr ;
30
30
use std:: io:: Read ;
@@ -528,18 +528,29 @@ impl CanisterPool {
528
528
}
529
529
530
530
#[ context( "Failed to build dependencies graph for canister pool." ) ]
531
- fn build_dependencies_graph ( & self ) -> DfxResult < DiGraph < CanisterId , ( ) > > {
531
+ fn build_dependencies_graph ( & self , canisters_to_build : Option < Vec < String > > ) -> DfxResult < DiGraph < CanisterId , ( ) > > {
532
+ println ! ( "build_dependencies_graph" ) ; // FIXME: Remove.
532
533
let mut graph: DiGraph < CanisterId , ( ) > = DiGraph :: new ( ) ;
533
534
let mut id_set: BTreeMap < CanisterId , NodeIndex < u32 > > = BTreeMap :: new ( ) ;
534
535
536
+ // TODO: Can be done faster by not using `collect` and/or `clone`?
537
+ let real_canisters_to_build = if let Some ( canisters_to_build) = canisters_to_build {
538
+ let canisters_to_build_map: HashMap < & str , ( ) > = canisters_to_build. iter ( ) . map ( |e| ( e. as_str ( ) , ( ) ) ) . collect ( ) ;
539
+ self . canisters . iter ( )
540
+ . filter ( |c| canisters_to_build_map. contains_key ( c. get_name ( ) ) )
541
+ . map ( |c| c. clone ( ) ) . collect :: < Vec < _ > > ( )
542
+ } else {
543
+ self . canisters . iter ( ) . map ( |c| c. clone ( ) ) . collect :: < Vec < _ > > ( )
544
+ } ;
545
+
535
546
// Add all the canisters as nodes.
536
547
for canister in & self . canisters {
537
548
let canister_id = canister. info . get_canister_id ( ) ?;
538
549
id_set. insert ( canister_id, graph. add_node ( canister_id) ) ;
539
550
}
540
551
541
552
// Add all the edges.
542
- for canister in & self . canisters {
553
+ for canister in & real_canisters_to_build {
543
554
let canister_id = canister. canister_id ( ) ;
544
555
let canister_info = & canister. info ;
545
556
let deps = canister. builder . get_dependencies ( self , canister_info) ?;
@@ -692,7 +703,7 @@ impl CanisterPool {
692
703
. map_err ( |e| DfxError :: new ( BuildError :: PreBuildAllStepFailed ( Box :: new ( e) ) ) ) ?;
693
704
694
705
trace ! ( log, "Building dependencies graph." ) ;
695
- let graph = self . build_dependencies_graph ( ) ? ;
706
+ let graph = self . build_dependencies_graph ( build_config . canisters_to_build . clone ( ) ) ? ; // TODO: Can `clone` be eliminated?
696
707
let nodes = petgraph:: algo:: toposort ( & graph, None ) . map_err ( |cycle| {
697
708
let message = match graph. node_weight ( cycle. node_id ( ) ) {
698
709
Some ( canister_id) => match self . get_canister_info ( canister_id) {
0 commit comments