@@ -168,78 +168,81 @@ impl CanisterBuilder for MotokoBuilder {
168
168
} ;
169
169
}
170
170
171
- let wasm_file_metadata = metadata ( output_wasm_path) ?;
172
- let wasm_file_time = wasm_file_metadata. modified ( ) ?;
173
- let mut import_iter = imports. iter ( ) ;
174
- loop {
175
- if let Some ( import) = import_iter. next ( ) {
176
- let imported_file = match import {
177
- MotokoImport :: Canister ( canister_name) => {
178
- if let Some ( canister) = pool. get_first_canister_with_name ( canister_name) {
179
- let main_file = canister. get_info ( ) . get_main_file ( ) ;
180
- if let Some ( main_file) = main_file {
181
- Some ( main_file. to_owned ( ) )
171
+ // Check that one of the dependencies is newer than the target:
172
+ if let Ok ( wasm_file_metadata) = metadata ( output_wasm_path) {
173
+ let wasm_file_time = wasm_file_metadata. modified ( ) ?;
174
+ let mut import_iter = imports. iter ( ) ;
175
+ loop {
176
+ if let Some ( import) = import_iter. next ( ) {
177
+ let imported_file = match import {
178
+ MotokoImport :: Canister ( canister_name) => {
179
+ if let Some ( canister) = pool. get_first_canister_with_name ( canister_name) {
180
+ let main_file = canister. get_info ( ) . get_main_file ( ) ;
181
+ if let Some ( main_file) = main_file {
182
+ Some ( main_file. to_owned ( ) )
183
+ } else {
184
+ None
185
+ }
182
186
} else {
183
187
None
184
188
}
185
- } else {
186
- None
187
189
}
188
- }
189
- MotokoImport :: Ic ( canister_id) => {
190
- if let Some ( canister_name) = rev_id_map. get ( canister_id) {
191
- if let Some ( canister) = pool. get_first_canister_with_name ( canister_name) {
192
- if let Some ( main_file) = canister. get_info ( ) . get_main_file ( ) {
193
- Some ( main_file. to_owned ( ) )
190
+ MotokoImport :: Ic ( canister_id) => {
191
+ if let Some ( canister_name) = rev_id_map. get ( canister_id) {
192
+ if let Some ( canister) = pool. get_first_canister_with_name ( canister_name) {
193
+ if let Some ( main_file) = canister. get_info ( ) . get_main_file ( ) {
194
+ Some ( main_file. to_owned ( ) )
195
+ } else {
196
+ None
197
+ }
194
198
} else {
195
199
None
196
200
}
197
201
} else {
198
202
None
199
203
}
200
- } else {
201
- None
202
204
}
203
- }
204
- MotokoImport :: Lib ( path) => {
205
- let i = path. find ( '/' ) ;
206
- let pre_path = if let Some ( i) = i {
207
- let expanded = Path :: new (
208
- package_arguments_map. get ( & path[ ..i] ) . ok_or_else ( || anyhow ! ( "nonexisting package" ) ) ?
209
- ) . join ( Path :: new ( "src" ) ) ;
210
- expanded. join ( & path[ i+1 ..] )
211
- } else {
212
- Path :: new ( path) . to_owned ( )
213
- } ;
214
- let path2 = pre_path. to_string_lossy ( ) + ".mo" ; // TODO: Is `lossy` OK?
215
- let path2 = path2. to_string ( ) ;
216
- let path2 = Path :: new ( & path2) ;
217
- if path2. exists ( ) { // TODO: Is it correct order of two variants?
218
- Some ( Path :: new ( path2) . to_owned ( ) )
219
- } else {
220
- let path3 = pre_path. join ( Path :: new ( "lib.mo" ) ) ;
221
- if path3. exists ( ) {
222
- Some ( path3. to_owned ( ) )
205
+ MotokoImport :: Lib ( path) => {
206
+ let i = path. find ( '/' ) ;
207
+ let pre_path = if let Some ( i) = i {
208
+ let expanded = Path :: new (
209
+ package_arguments_map. get ( & path[ ..i] ) . ok_or_else ( || anyhow ! ( "nonexisting package" ) ) ?
210
+ ) ;
211
+ expanded. join ( & path[ i+1 ..] )
212
+ } else {
213
+ Path :: new ( path) . to_owned ( )
214
+ } ;
215
+ let path2 = pre_path. to_string_lossy ( ) + ".mo" ; // TODO: Is `lossy` OK?
216
+ let path2 = path2. to_string ( ) ;
217
+ let path2 = Path :: new ( & path2) ;
218
+ if path2. exists ( ) { // TODO: Is it correct order of two variants?
219
+ Some ( Path :: new ( path2) . to_owned ( ) )
223
220
} else {
224
- bail ! ( "source file has been deleted" ) ;
221
+ let path3 = pre_path. join ( Path :: new ( "lib.mo" ) ) ;
222
+ println ! ( "path3: {}" , & path3. to_string_lossy( ) ) ; // FIXME
223
+ if path3. exists ( ) {
224
+ Some ( path3. to_owned ( ) )
225
+ } else {
226
+ bail ! ( "source file has been deleted" ) ;
227
+ }
225
228
}
226
229
}
227
- }
228
- MotokoImport :: Relative ( path) => {
229
- Some ( Path :: new ( path) . to_owned ( ) )
230
- }
231
- } ;
232
- if let Some ( imported_file) = imported_file {
233
- let imported_file_metadata = metadata ( imported_file. as_ref ( ) ) ?;
234
- let imported_file_time = imported_file_metadata. modified ( ) ?;
235
- if imported_file_time > wasm_file_time {
236
- break ;
230
+ MotokoImport :: Relative ( path) => {
231
+ Some ( Path :: new ( path) . to_owned ( ) )
232
+ }
237
233
} ;
238
- } ;
239
- } else {
240
- bail ! ( "already compiled" ) ; // FIXME: Ensure that `dfx` command doesn't return false because of this.
234
+ if let Some ( imported_file) = imported_file {
235
+ let imported_file_metadata = metadata ( imported_file. as_ref ( ) ) ?;
236
+ let imported_file_time = imported_file_metadata. modified ( ) ?;
237
+ if imported_file_time > wasm_file_time {
238
+ break ;
239
+ } ;
240
+ } ;
241
+ } else {
242
+ bail ! ( "already compiled" ) ; // FIXME: Ensure that `dfx` command doesn't return false because of this.
243
+ }
241
244
}
242
- }
245
+ } ;
243
246
244
247
let moc_arguments = match motoko_info. get_args ( ) {
245
248
Some ( args) => [
0 commit comments