Skip to content

Commit 5259828

Browse files
committed
Option to skip building target obj
1 parent 4bab96e commit 5259828

File tree

10 files changed

+108
-136
lines changed

10 files changed

+108
-136
lines changed

src/app.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use notify::{RecursiveMode, Watcher};
1515

1616
use crate::{
1717
jobs::{
18-
build::{queue_build, BuildResult, BuildStatus},
18+
objdiff::{queue_build, BuildStatus, ObjDiffResult},
1919
Job, JobResult, JobState,
2020
},
2121
views::{
@@ -44,7 +44,7 @@ pub struct ViewState {
4444
#[serde(skip)]
4545
pub jobs: Vec<JobState>,
4646
#[serde(skip)]
47-
pub build: Option<Box<BuildResult>>,
47+
pub build: Option<Box<ObjDiffResult>>,
4848
#[serde(skip)]
4949
pub highlighted_symbol: Option<String>,
5050
#[serde(skip)]
@@ -68,9 +68,10 @@ pub struct AppConfig {
6868
pub selected_wsl_distro: Option<String>,
6969
// Split obj
7070
pub project_dir: Option<PathBuf>,
71-
pub build_asm_dir: Option<PathBuf>,
72-
pub build_src_dir: Option<PathBuf>,
73-
pub build_obj: Option<String>,
71+
pub target_obj_dir: Option<PathBuf>,
72+
pub base_obj_dir: Option<PathBuf>,
73+
pub obj_path: Option<String>,
74+
pub build_target: bool,
7475
// Whole binary
7576
pub left_obj: Option<PathBuf>,
7677
pub right_obj: Option<PathBuf>,
@@ -237,11 +238,11 @@ impl eframe::App for App {
237238
log::error!("{:?}", err);
238239
}
239240
}
240-
JobResult::Build(state) => {
241+
JobResult::ObjDiff(state) => {
241242
self.view_state.build = Some(state);
242243
}
243244
JobResult::BinDiff(state) => {
244-
self.view_state.build = Some(Box::new(BuildResult {
245+
self.view_state.build = Some(Box::new(ObjDiffResult {
245246
first_status: BuildStatus {
246247
success: true,
247248
log: "".to_string(),
@@ -287,13 +288,13 @@ impl eframe::App for App {
287288
}
288289
}
289290

290-
if let Some(build_obj) = &config.build_obj {
291+
if let Some(build_obj) = &config.obj_path {
291292
if self.modified.load(Ordering::Relaxed) {
292293
if !self
293294
.view_state
294295
.jobs
295296
.iter()
296-
.any(|j| j.job_type == Job::Build && j.handle.is_some())
297+
.any(|j| j.job_type == Job::ObjDiff && j.handle.is_some())
297298
{
298299
self.view_state
299300
.jobs

src/jobs/bindiff.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use anyhow::{Error, Result};
55
use crate::{
66
app::AppConfig,
77
diff::diff_objs,
8-
elf,
98
jobs::{queue_job, update_status, Job, JobResult, JobState, Status},
10-
obj::ObjInfo,
9+
obj::{elf, ObjInfo},
1110
};
1211

1312
pub struct BinDiffResult {
@@ -21,15 +20,15 @@ fn run_build(
2120
config: Arc<RwLock<AppConfig>>,
2221
) -> Result<Box<BinDiffResult>> {
2322
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
24-
let left_path = config.left_obj.as_ref().ok_or_else(|| Error::msg("Missing left obj path"))?;
25-
let right_path =
26-
config.right_obj.as_ref().ok_or_else(|| Error::msg("Missing right obj path"))?;
23+
let target_path =
24+
config.left_obj.as_ref().ok_or_else(|| Error::msg("Missing target obj path"))?;
25+
let base_path = config.right_obj.as_ref().ok_or_else(|| Error::msg("Missing base obj path"))?;
2726

28-
update_status(status, "Loading left obj".to_string(), 0, 3, &cancel)?;
29-
let mut left_obj = elf::read(left_path)?;
27+
update_status(status, "Loading target obj".to_string(), 0, 3, &cancel)?;
28+
let mut left_obj = elf::read(target_path)?;
3029

31-
update_status(status, "Loading right obj".to_string(), 1, 3, &cancel)?;
32-
let mut right_obj = elf::read(right_path)?;
30+
update_status(status, "Loading base obj".to_string(), 1, 3, &cancel)?;
31+
let mut right_obj = elf::read(base_path)?;
3332

3433
update_status(status, "Performing diff".to_string(), 2, 3, &cancel)?;
3534
diff_objs(&mut left_obj, &mut right_obj)?;

src/jobs/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ use std::{
99

1010
use anyhow::Result;
1111

12-
use crate::jobs::{bindiff::BinDiffResult, build::BuildResult};
12+
use crate::jobs::{bindiff::BinDiffResult, objdiff::ObjDiffResult};
1313

1414
pub mod bindiff;
15-
pub mod build;
15+
pub mod objdiff;
1616

1717
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
1818
pub enum Job {
19-
Build,
19+
ObjDiff,
2020
BinDiff,
2121
}
2222
pub static JOB_ID: AtomicUsize = AtomicUsize::new(0);
@@ -38,7 +38,7 @@ pub struct JobStatus {
3838
}
3939
pub enum JobResult {
4040
None,
41-
Build(Box<BuildResult>),
41+
ObjDiff(Box<ObjDiffResult>),
4242
BinDiff(Box<BinDiffResult>),
4343
}
4444

src/jobs/build.rs renamed to src/jobs/objdiff.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ use anyhow::{Context, Error, Result};
1010
use crate::{
1111
app::AppConfig,
1212
diff::diff_objs,
13-
elf,
1413
jobs::{queue_job, update_status, Job, JobResult, JobState, Status},
15-
obj::ObjInfo,
14+
obj::{elf, ObjInfo},
1615
};
1716

1817
pub struct BuildStatus {
1918
pub success: bool,
2019
pub log: String,
2120
}
22-
pub struct BuildResult {
21+
pub struct ObjDiffResult {
2322
pub first_status: BuildStatus,
2423
pub second_status: BuildStatus,
2524
pub first_obj: Option<ObjInfo>,
@@ -78,58 +77,61 @@ fn run_build(
7877
cancel: Receiver<()>,
7978
obj_path: String,
8079
config: Arc<RwLock<AppConfig>>,
81-
) -> Result<Box<BuildResult>> {
80+
) -> Result<Box<ObjDiffResult>> {
8281
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
8382
let project_dir =
8483
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
8786
.as_ref()
88-
.ok_or_else(|| Error::msg("Missing build asm dir"))?
87+
.ok_or_else(|| Error::msg("Missing target obj dir"))?
8988
.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")?;
10198

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+
};
104106

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);
107109

108110
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)?)
111113
} else {
112114
None
113115
};
114116

115117
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)?)
118120
} else {
119121
None
120122
};
121123

122124
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)?;
124126
diff_objs(first_obj, second_obj)?;
125127
}
126128

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 }))
129131
}
130132

131133
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)
134136
})
135137
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ pub use app::App;
55
mod app;
66
mod diff;
77
mod editops;
8-
mod elf;
98
mod jobs;
109
mod obj;
1110
mod views;
File renamed without changes.

src/obj.rs renamed to src/obj/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pub mod elf;
12
pub mod mips;
23
pub mod ppc;
34

@@ -142,9 +143,3 @@ pub struct ObjReloc {
142143
pub target: ObjSymbol,
143144
pub target_section: Option<String>,
144145
}
145-
// #[derive(Debug, Clone)]
146-
// pub struct ObjInsDiff {
147-
// pub kind: ObjInsDiffKind,
148-
// pub left: Option<ObjIns>,
149-
// pub right: Option<ObjIns>,
150-
// }

src/views/config.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use anyhow::{Context, Result};
77

88
use crate::{
99
app::{AppConfig, DiffKind, ViewState},
10-
jobs::{bindiff::queue_bindiff, build::queue_build},
10+
jobs::{bindiff::queue_bindiff, objdiff::queue_build},
1111
};
1212

1313
#[cfg(windows)]
@@ -50,12 +50,13 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
5050
available_wsl_distros,
5151
selected_wsl_distro,
5252
project_dir,
53-
project_dir_change,
54-
build_asm_dir,
55-
build_src_dir,
56-
build_obj,
53+
target_obj_dir,
54+
base_obj_dir,
55+
obj_path,
56+
build_target,
5757
left_obj,
5858
right_obj,
59+
project_dir_change,
5960
} = &mut *config_guard;
6061

6162
ui.heading("Build config");
@@ -92,9 +93,9 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
9293
if let Some(path) = rfd::FileDialog::new().pick_folder() {
9394
*project_dir = Some(path);
9495
*project_dir_change = true;
95-
*build_asm_dir = None;
96-
*build_src_dir = None;
97-
*build_obj = None;
96+
*target_obj_dir = None;
97+
*base_obj_dir = None;
98+
*obj_path = None;
9899
}
99100
}
100101
if let Some(dir) = project_dir {
@@ -104,58 +105,59 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
104105
ui.separator();
105106

106107
if let Some(project_dir) = project_dir {
107-
if ui.button("Select asm build dir").clicked() {
108+
if ui.button("Select target build dir").clicked() {
108109
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder()
109110
{
110-
*build_asm_dir = Some(path);
111-
*build_obj = None;
111+
*target_obj_dir = Some(path);
112+
*obj_path = None;
112113
}
113114
}
114-
if let Some(dir) = build_asm_dir {
115+
if let Some(dir) = target_obj_dir {
115116
ui.label(dir.to_string_lossy());
116117
}
118+
ui.checkbox(build_target, "Build target");
117119

118120
ui.separator();
119121

120-
if ui.button("Select src build dir").clicked() {
122+
if ui.button("Select base build dir").clicked() {
121123
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder()
122124
{
123-
*build_src_dir = Some(path);
124-
*build_obj = None;
125+
*base_obj_dir = Some(path);
126+
*obj_path = None;
125127
}
126128
}
127-
if let Some(dir) = build_src_dir {
129+
if let Some(dir) = base_obj_dir {
128130
ui.label(dir.to_string_lossy());
129131
}
130132

131133
ui.separator();
132134
}
133135

134-
if let Some(build_src_dir) = build_src_dir {
136+
if let Some(base_dir) = base_obj_dir {
135137
if ui.button("Select obj").clicked() {
136138
if let Some(path) = rfd::FileDialog::new()
137-
.set_directory(&build_src_dir)
139+
.set_directory(&base_dir)
138140
.add_filter("Object file", &["o", "elf"])
139141
.pick_file()
140142
{
141143
let mut new_build_obj: Option<String> = None;
142-
if let Ok(obj_path) = path.strip_prefix(&build_src_dir) {
144+
if let Ok(obj_path) = path.strip_prefix(&base_dir) {
143145
new_build_obj = Some(obj_path.display().to_string());
144-
} else if let Some(build_asm_dir) = build_asm_dir {
146+
} else if let Some(build_asm_dir) = target_obj_dir {
145147
if let Ok(obj_path) = path.strip_prefix(&build_asm_dir) {
146148
new_build_obj = Some(obj_path.display().to_string());
147149
}
148150
}
149151
if let Some(new_build_obj) = new_build_obj {
150-
*build_obj = Some(new_build_obj.clone());
152+
*obj_path = Some(new_build_obj.clone());
151153
view_state.jobs.push(queue_build(new_build_obj, config.clone()));
152154
}
153155
}
154156
}
155-
if let Some(build_obj) = build_obj {
156-
ui.label(&*build_obj);
157+
if let Some(obj) = obj_path {
158+
ui.label(&*obj);
157159
if ui.button("Build").clicked() {
158-
view_state.jobs.push(queue_build(build_obj.clone(), config.clone()));
160+
view_state.jobs.push(queue_build(obj.clone(), config.clone()));
159161
}
160162
}
161163

src/views/function_diff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
324324
Color32::WHITE,
325325
demangled.as_ref().unwrap_or(selected_symbol),
326326
);
327-
ui.label("Diff asm:");
327+
ui.label("Diff target:");
328328
ui.separator();
329329
});
330330
});
@@ -342,7 +342,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
342342
);
343343
}
344344
}
345-
ui.label("Diff src:");
345+
ui.label("Diff base:");
346346
ui.separator();
347347
});
348348
});

0 commit comments

Comments
 (0)