@@ -53,12 +53,12 @@ fn get_imports(cache: &dyn Cache, info: &MotokoCanisterInfo, imports: &mut Impor
53
53
imports : & mut ImportsTracker ,
54
54
pool : & CanisterPool ,
55
55
) -> DfxResult {
56
- println ! ( "CanisterInfo: {:#?}" , file) ;
57
56
let parent = MotokoImport :: Relative ( file. to_path_buf ( ) ) ;
58
57
if imports. nodes . contains_key ( & parent) {
59
58
return Ok ( ( ) ) ;
60
59
}
61
- imports. nodes . insert ( parent. clone ( ) , ( ) ) ;
60
+ let parent_node_index = * imports. nodes . entry ( parent. clone ( ) ) . or_insert_with ( || imports. graph . add_node ( parent. clone ( ) ) ) ;
61
+ imports. nodes . insert ( parent. clone ( ) , parent_node_index) ;
62
62
if let MotokoImport :: Relative ( path) = & parent {
63
63
println ! ( "INSERTED: {}" , path. display( ) ) ; // FIXME
64
64
}
@@ -86,18 +86,21 @@ fn get_imports(cache: &dyn Cache, info: &MotokoCanisterInfo, imports: &mut Impor
86
86
}
87
87
_ => { }
88
88
}
89
- let parent_node = imports. graph . add_node ( parent. clone ( ) ) ;
90
- if let MotokoImport :: Relative ( child) = & child {
91
- println ! ( "INSERTED CHILD: {}" , child. display( ) ) ; // FIXME
92
- }
93
- let child_node = imports. graph . add_node ( child) ;
94
- imports. graph . add_edge ( parent_node, child_node, ( ) ) ;
89
+ let parent_node_index = * imports. nodes . entry ( parent. clone ( ) ) . or_insert_with ( || imports. graph . add_node ( parent. clone ( ) ) ) ;
90
+ let child_node_index = * imports. nodes . entry ( child. clone ( ) ) . or_insert_with ( || imports. graph . add_node ( child. clone ( ) ) ) ;
91
+ // if let MotokoImport::Relative(parent) = &parent {
92
+ // println!("INSERTED PARENT: {} ({:?})", parent.display(), parent_node); // FIXME
93
+ // }
94
+ // let child_node = imports.graph.add_node(child.clone());
95
+ // if let MotokoImport::Relative(child) = &child {
96
+ // println!("INSERTED CHILD: {} ({:?})", child.display(), child_node); // FIXME
97
+ // }
98
+ imports. graph . add_edge ( parent_node_index, child_node_index, ( ) ) ;
95
99
}
96
100
97
101
Ok ( ( ) )
98
102
}
99
103
100
- println ! ( "CanisterInfo2: {:#?}" , info. get_main_path( ) ) ;
101
104
get_imports_recursive ( cache, info. get_main_path ( ) , imports, pool) ?;
102
105
103
106
Ok ( ( ) )
@@ -136,7 +139,6 @@ impl CanisterBuilder for MotokoBuilder {
136
139
config : & BuildConfig ,
137
140
) -> DfxResult < BuildOutput > {
138
141
let motoko_info = canister_info. as_info :: < MotokoCanisterInfo > ( ) ?;
139
- println ! ( "motoko_info: {}" , motoko_info. get_main_path( ) . display( ) ) ;
140
142
let profile = config. profile ;
141
143
let input_path = motoko_info. get_main_path ( ) ;
142
144
let output_wasm_path = motoko_info. get_output_wasm_path ( ) ;
@@ -193,10 +195,20 @@ impl CanisterBuilder for MotokoBuilder {
193
195
if let Ok ( wasm_file_metadata) = metadata ( output_wasm_path) {
194
196
let wasm_file_time = wasm_file_metadata. modified ( ) ?;
195
197
let mut imports = pool. imports . borrow_mut ( ) ;
196
- let start = imports. graph . add_node ( MotokoImport :: Relative ( motoko_info. get_main_path ( ) . to_path_buf ( ) ) ) ; // Start with oput canister.
198
+ println ! ( "START: {}" , motoko_info. get_main_path( ) . to_path_buf( ) . display( ) ) ; // FIXME
199
+ // let start = imports.graph.add_node(MotokoImport::Relative(motoko_info.get_main_path().to_path_buf())); // Start with oput canister.
200
+ let start = if let Some ( node_index) = imports. nodes . get ( & MotokoImport :: Relative ( motoko_info. get_main_path ( ) . to_path_buf ( ) ) ) {
201
+ * node_index
202
+ } else {
203
+ let node = MotokoImport :: Relative ( motoko_info. get_main_path ( ) . to_path_buf ( ) ) ;
204
+ let node_index = imports. graph . add_node ( node. clone ( ) ) ;
205
+ imports. nodes . insert ( node, node_index) ;
206
+ node_index
207
+ } ;
197
208
let mut import_iter = Bfs :: new ( & imports. graph , start) ;
198
209
loop {
199
210
if let Some ( import) = import_iter. next ( & imports. graph ) {
211
+ println ! ( "NodeIndex {:?}" , import) ;
200
212
let imported_file = match & imports. graph [ import] {
201
213
MotokoImport :: Canister ( canister_name) => { // duplicate code
202
214
if let Some ( canister) = pool. get_first_canister_with_name ( canister_name. as_str ( ) ) {
0 commit comments