@@ -51,9 +51,11 @@ fn get_imports(cache: &dyn Cache, info: &MotokoCanisterInfo, imports: &mut Impor
51
51
file : & Path ,
52
52
imports : & mut ImportsTracker ,
53
53
) -> DfxResult {
54
- if imports. nodes . contains_key ( & MotokoImport :: Relative ( file. to_path_buf ( ) ) ) {
54
+ let parent = MotokoImport :: Relative ( file. to_path_buf ( ) ) ;
55
+ if imports. nodes . contains_key ( & parent) {
55
56
return Ok ( ( ) ) ;
56
57
}
58
+ imports. nodes . insert ( parent. clone ( ) , ( ) ) ;
57
59
58
60
let mut command = cache. get_binary_command ( "moc" ) ?;
59
61
let command = command. arg ( "--print-deps" ) . arg ( file) ;
@@ -63,23 +65,17 @@ fn get_imports(cache: &dyn Cache, info: &MotokoCanisterInfo, imports: &mut Impor
63
65
let output = String :: from_utf8_lossy ( & output. stdout ) ;
64
66
65
67
for line in output. lines ( ) {
66
- let import = MotokoImport :: try_from ( line) . context ( "Failed to create MotokoImport." ) ?;
67
- match & import {
68
+ let child = MotokoImport :: try_from ( line) . context ( "Failed to create MotokoImport." ) ?;
69
+ // TODO: The code seems screwed: Why recompile onluy on `Relative`?
70
+ match & child {
68
71
MotokoImport :: Relative ( path) => {
69
- if !imports. nodes . contains_key ( & import) { // Don't look up already looked up dependencies
70
- imports. nodes . insert ( & import, ( ) ) ;
71
- get_imports_recursive ( cache, path. as_path ( ) , imports) ?;
72
- }
73
- }
74
- _ => {
75
- let parent = MotokoImport :: Relative ( file. to_path_buf ( ) ) ;
76
- // imports.insert(parent);
77
-
78
- let parent_node = imports. graph . add_node ( parent) ;
79
- let child_node = imports. graph . add_node ( import) ;
80
- imports. graph . add_edge ( parent_node, child_node, ( ) ) ;
72
+ get_imports_recursive ( cache, path. as_path ( ) , imports) ?;
81
73
}
74
+ _ => { }
82
75
}
76
+ let parent_node = imports. graph . add_node ( parent. clone ( ) ) ;
77
+ let child_node = imports. graph . add_node ( child) ;
78
+ imports. graph . add_edge ( parent_node, child_node, ( ) ) ;
83
79
}
84
80
85
81
Ok ( ( ) )
0 commit comments