@@ -4,7 +4,7 @@ use std::{
44 sync:: mpsc:: Receiver ,
55} ;
66
7- use anyhow:: { anyhow, Context , Error , Result } ;
7+ use anyhow:: { anyhow, Error , Result } ;
88use objdiff_core:: {
99 diff:: { diff_objs, DiffObjConfig , ObjDiff } ,
1010 obj:: { read, ObjInfo } ,
@@ -189,81 +189,118 @@ fn run_build(
189189 None
190190 } ;
191191
192- let mut total = 3 ;
192+ let mut total = 1 ;
193193 if config. build_target && target_path_rel. is_some ( ) {
194194 total += 1 ;
195195 }
196196 if config. build_base && base_path_rel. is_some ( ) {
197197 total += 1 ;
198198 }
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 {
200208 Some ( target_path_rel) if config. build_target => {
201209 update_status (
202210 context,
203211 format ! ( "Building target {}" , target_path_rel. display( ) ) ,
204- 0 ,
212+ step_idx ,
205213 total,
206214 & cancel,
207215 ) ?;
216+ step_idx += 1 ;
208217 run_make ( & config. build_config , target_path_rel)
209218 }
210219 _ => BuildStatus :: default ( ) ,
211220 } ;
212221
213- let second_status = match base_path_rel {
222+ let mut second_status = match base_path_rel {
214223 Some ( base_path_rel) if config. build_base => {
215224 update_status (
216225 context,
217226 format ! ( "Building base {}" , base_path_rel. display( ) ) ,
218- 0 ,
227+ step_idx ,
219228 total,
220229 & cancel,
221230 ) ?;
231+ step_idx += 1 ;
222232 run_make ( & config. build_config , base_path_rel)
223233 }
224234 _ => BuildStatus :: default ( ) ,
225235 } ;
226236
227237 let time = OffsetDateTime :: now_utc ( ) ;
228238
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+ }
242260 }
243- _ => None ,
244- } ;
261+ }
262+ Some ( _) => {
263+ step_idx += 1 ;
264+ None
265+ }
266+ _ => None ,
267+ } ;
245268
246269 let second_obj = match & obj_config. base_path {
247270 Some ( base_path) if second_status. success => {
248271 update_status (
249272 context,
250273 format ! ( "Loading base {}" , base_path_rel. unwrap( ) . display( ) ) ,
251- 3 ,
274+ step_idx ,
252275 total,
253276 & cancel,
254277 ) ?;
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
259295 }
260296 _ => None ,
261297 } ;
262298
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 ;
264301 let result = diff_objs ( & config. diff_obj_config , first_obj. as_ref ( ) , second_obj. as_ref ( ) , None ) ?;
265302
266- update_status ( context, "Complete" . to_string ( ) , total , total, & cancel) ?;
303+ update_status ( context, "Complete" . to_string ( ) , step_idx , total, & cancel) ?;
267304 Ok ( Box :: new ( ObjDiffResult {
268305 first_status,
269306 second_status,
@@ -274,7 +311,7 @@ fn run_build(
274311}
275312
276313pub 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| {
278315 run_build ( & context, cancel, config) . map ( |result| JobResult :: ObjDiff ( Some ( result) ) )
279316 } )
280317}
0 commit comments