@@ -4,7 +4,7 @@ use std::{
4
4
sync:: mpsc:: Receiver ,
5
5
} ;
6
6
7
- use anyhow:: { anyhow, Context , Error , Result } ;
7
+ use anyhow:: { anyhow, Error , Result } ;
8
8
use objdiff_core:: {
9
9
diff:: { diff_objs, DiffObjConfig , ObjDiff } ,
10
10
obj:: { read, ObjInfo } ,
@@ -189,81 +189,118 @@ fn run_build(
189
189
None
190
190
} ;
191
191
192
- let mut total = 3 ;
192
+ let mut total = 1 ;
193
193
if config. build_target && target_path_rel. is_some ( ) {
194
194
total += 1 ;
195
195
}
196
196
if config. build_base && base_path_rel. is_some ( ) {
197
197
total += 1 ;
198
198
}
199
- let first_status = match target_path_rel {
199
+ if target_path_rel. is_some ( ) {
200
+ total += 1 ;
201
+ }
202
+ if base_path_rel. is_some ( ) {
203
+ total += 1 ;
204
+ }
205
+
206
+ let mut step_idx = 0 ;
207
+ let mut first_status = match target_path_rel {
200
208
Some ( target_path_rel) if config. build_target => {
201
209
update_status (
202
210
context,
203
211
format ! ( "Building target {}" , target_path_rel. display( ) ) ,
204
- 0 ,
212
+ step_idx ,
205
213
total,
206
214
& cancel,
207
215
) ?;
216
+ step_idx += 1 ;
208
217
run_make ( & config. build_config , target_path_rel)
209
218
}
210
219
_ => BuildStatus :: default ( ) ,
211
220
} ;
212
221
213
- let second_status = match base_path_rel {
222
+ let mut second_status = match base_path_rel {
214
223
Some ( base_path_rel) if config. build_base => {
215
224
update_status (
216
225
context,
217
226
format ! ( "Building base {}" , base_path_rel. display( ) ) ,
218
- 0 ,
227
+ step_idx ,
219
228
total,
220
229
& cancel,
221
230
) ?;
231
+ step_idx += 1 ;
222
232
run_make ( & config. build_config , base_path_rel)
223
233
}
224
234
_ => BuildStatus :: default ( ) ,
225
235
} ;
226
236
227
237
let time = OffsetDateTime :: now_utc ( ) ;
228
238
229
- let first_obj =
230
- match & obj_config. target_path {
231
- Some ( target_path) if first_status. success => {
232
- update_status (
233
- context,
234
- format ! ( "Loading target {}" , target_path_rel. unwrap( ) . display( ) ) ,
235
- 2 ,
236
- total,
237
- & cancel,
238
- ) ?;
239
- Some ( read:: read ( target_path, & config. diff_obj_config ) . with_context ( || {
240
- format ! ( "Failed to read object '{}'" , target_path. display( ) )
241
- } ) ?)
239
+ let first_obj = match & obj_config. target_path {
240
+ Some ( target_path) if first_status. success => {
241
+ update_status (
242
+ context,
243
+ format ! ( "Loading target {}" , target_path_rel. unwrap( ) . display( ) ) ,
244
+ step_idx,
245
+ total,
246
+ & cancel,
247
+ ) ?;
248
+ step_idx += 1 ;
249
+ match read:: read ( target_path, & config. diff_obj_config ) {
250
+ Ok ( obj) => Some ( obj) ,
251
+ Err ( e) => {
252
+ first_status = BuildStatus {
253
+ success : false ,
254
+ stdout : format ! ( "Loading object '{}'" , target_path. display( ) ) ,
255
+ stderr : format ! ( "{:#}" , e) ,
256
+ ..Default :: default ( )
257
+ } ;
258
+ None
259
+ }
242
260
}
243
- _ => None ,
244
- } ;
261
+ }
262
+ Some ( _) => {
263
+ step_idx += 1 ;
264
+ None
265
+ }
266
+ _ => None ,
267
+ } ;
245
268
246
269
let second_obj = match & obj_config. base_path {
247
270
Some ( base_path) if second_status. success => {
248
271
update_status (
249
272
context,
250
273
format ! ( "Loading base {}" , base_path_rel. unwrap( ) . display( ) ) ,
251
- 3 ,
274
+ step_idx ,
252
275
total,
253
276
& cancel,
254
277
) ?;
255
- Some (
256
- read:: read ( base_path, & config. diff_obj_config )
257
- . with_context ( || format ! ( "Failed to read object '{}'" , base_path. display( ) ) ) ?,
258
- )
278
+ step_idx += 1 ;
279
+ match read:: read ( base_path, & config. diff_obj_config ) {
280
+ Ok ( obj) => Some ( obj) ,
281
+ Err ( e) => {
282
+ second_status = BuildStatus {
283
+ success : false ,
284
+ stdout : format ! ( "Loading object '{}'" , base_path. display( ) ) ,
285
+ stderr : format ! ( "{:#}" , e) ,
286
+ ..Default :: default ( )
287
+ } ;
288
+ None
289
+ }
290
+ }
291
+ }
292
+ Some ( _) => {
293
+ step_idx += 1 ;
294
+ None
259
295
}
260
296
_ => None ,
261
297
} ;
262
298
263
- update_status ( context, "Performing diff" . to_string ( ) , 4 , total, & cancel) ?;
299
+ update_status ( context, "Performing diff" . to_string ( ) , step_idx, total, & cancel) ?;
300
+ step_idx += 1 ;
264
301
let result = diff_objs ( & config. diff_obj_config , first_obj. as_ref ( ) , second_obj. as_ref ( ) , None ) ?;
265
302
266
- update_status ( context, "Complete" . to_string ( ) , total , total, & cancel) ?;
303
+ update_status ( context, "Complete" . to_string ( ) , step_idx , total, & cancel) ?;
267
304
Ok ( Box :: new ( ObjDiffResult {
268
305
first_status,
269
306
second_status,
@@ -274,7 +311,7 @@ fn run_build(
274
311
}
275
312
276
313
pub fn start_build ( ctx : & egui:: Context , config : ObjDiffConfig ) -> JobState {
277
- start_job ( ctx, "Object diff " , Job :: ObjDiff , move |context, cancel| {
314
+ start_job ( ctx, "Build " , Job :: ObjDiff , move |context, cancel| {
278
315
run_build ( & context, cancel, config) . map ( |result| JobResult :: ObjDiff ( Some ( result) ) )
279
316
} )
280
317
}
0 commit comments