@@ -10,16 +10,15 @@ use anyhow::{Context, Error, Result};
10
10
use crate :: {
11
11
app:: AppConfig ,
12
12
diff:: diff_objs,
13
- elf,
14
13
jobs:: { queue_job, update_status, Job , JobResult , JobState , Status } ,
15
- obj:: ObjInfo ,
14
+ obj:: { elf , ObjInfo } ,
16
15
} ;
17
16
18
17
pub struct BuildStatus {
19
18
pub success : bool ,
20
19
pub log : String ,
21
20
}
22
- pub struct BuildResult {
21
+ pub struct ObjDiffResult {
23
22
pub first_status : BuildStatus ,
24
23
pub second_status : BuildStatus ,
25
24
pub first_obj : Option < ObjInfo > ,
@@ -78,58 +77,61 @@ fn run_build(
78
77
cancel : Receiver < ( ) > ,
79
78
obj_path : String ,
80
79
config : Arc < RwLock < AppConfig > > ,
81
- ) -> Result < Box < BuildResult > > {
80
+ ) -> Result < Box < ObjDiffResult > > {
82
81
let config = config. read ( ) . map_err ( |_| Error :: msg ( "Failed to lock app config" ) ) ?. clone ( ) ;
83
82
let project_dir =
84
83
config. project_dir . as_ref ( ) . ok_or_else ( || Error :: msg ( "Missing project dir" ) ) ?;
85
- let mut asm_path = config
86
- . build_asm_dir
84
+ let mut target_path = config
85
+ . target_obj_dir
87
86
. as_ref ( )
88
- . ok_or_else ( || Error :: msg ( "Missing build asm dir" ) ) ?
87
+ . ok_or_else ( || Error :: msg ( "Missing target obj dir" ) ) ?
89
88
. to_owned ( ) ;
90
- asm_path. push ( & obj_path) ;
91
- let mut src_path = config
92
- . build_src_dir
93
- . as_ref ( )
94
- . ok_or_else ( || Error :: msg ( "Missing build src dir" ) ) ?
95
- . to_owned ( ) ;
96
- src_path. push ( & obj_path) ;
97
- let asm_path_rel =
98
- asm_path. strip_prefix ( project_dir) . context ( "Failed to create relative asm obj path" ) ?;
99
- let src_path_rel =
100
- src_path. strip_prefix ( project_dir) . context ( "Failed to create relative src obj path" ) ?;
89
+ target_path. push ( & obj_path) ;
90
+ let mut base_path =
91
+ config. base_obj_dir . as_ref ( ) . ok_or_else ( || Error :: msg ( "Missing base obj dir" ) ) ?. to_owned ( ) ;
92
+ base_path. push ( & obj_path) ;
93
+ let target_path_rel = target_path
94
+ . strip_prefix ( project_dir)
95
+ . context ( "Failed to create relative target obj path" ) ?;
96
+ let base_path_rel =
97
+ base_path. strip_prefix ( project_dir) . context ( "Failed to create relative base obj path" ) ?;
101
98
102
- update_status ( status, format ! ( "Building asm {}" , obj_path) , 0 , 5 , & cancel) ?;
103
- let first_status = run_make ( project_dir, asm_path_rel, & config) ;
99
+ let total = if config. build_target { 5 } else { 4 } ;
100
+ let first_status = if config. build_target {
101
+ update_status ( status, format ! ( "Building target {}" , obj_path) , 0 , total, & cancel) ?;
102
+ run_make ( project_dir, target_path_rel, & config)
103
+ } else {
104
+ BuildStatus { success : true , log : String :: new ( ) }
105
+ } ;
104
106
105
- update_status ( status, format ! ( "Building src {}" , obj_path) , 1 , 5 , & cancel) ?;
106
- let second_status = run_make ( project_dir, src_path_rel , & config) ;
107
+ update_status ( status, format ! ( "Building base {}" , obj_path) , 1 , total , & cancel) ?;
108
+ let second_status = run_make ( project_dir, base_path_rel , & config) ;
107
109
108
110
let mut first_obj = if first_status. success {
109
- update_status ( status, format ! ( "Loading asm {}" , obj_path) , 2 , 5 , & cancel) ?;
110
- Some ( elf:: read ( & asm_path ) ?)
111
+ update_status ( status, format ! ( "Loading target {}" , obj_path) , 2 , total , & cancel) ?;
112
+ Some ( elf:: read ( & target_path ) ?)
111
113
} else {
112
114
None
113
115
} ;
114
116
115
117
let mut second_obj = if second_status. success {
116
- update_status ( status, format ! ( "Loading src {}" , obj_path) , 3 , 5 , & cancel) ?;
117
- Some ( elf:: read ( & src_path ) ?)
118
+ update_status ( status, format ! ( "Loading base {}" , obj_path) , 3 , total , & cancel) ?;
119
+ Some ( elf:: read ( & base_path ) ?)
118
120
} else {
119
121
None
120
122
} ;
121
123
122
124
if let ( Some ( first_obj) , Some ( second_obj) ) = ( & mut first_obj, & mut second_obj) {
123
- update_status ( status, "Performing diff" . to_string ( ) , 4 , 5 , & cancel) ?;
125
+ update_status ( status, "Performing diff" . to_string ( ) , 4 , total , & cancel) ?;
124
126
diff_objs ( first_obj, second_obj) ?;
125
127
}
126
128
127
- update_status ( status, "Complete" . to_string ( ) , 5 , 5 , & cancel) ?;
128
- Ok ( Box :: new ( BuildResult { first_status, second_status, first_obj, second_obj } ) )
129
+ update_status ( status, "Complete" . to_string ( ) , total , total , & cancel) ?;
130
+ Ok ( Box :: new ( ObjDiffResult { first_status, second_status, first_obj, second_obj } ) )
129
131
}
130
132
131
133
pub fn queue_build ( obj_path : String , config : Arc < RwLock < AppConfig > > ) -> JobState {
132
- queue_job ( Job :: Build , move |status, cancel| {
133
- run_build ( status, cancel, obj_path, config) . map ( JobResult :: Build )
134
+ queue_job ( Job :: ObjDiff , move |status, cancel| {
135
+ run_build ( status, cancel, obj_path, config) . map ( JobResult :: ObjDiff )
134
136
} )
135
137
}
0 commit comments