mirror of https://github.com/encounter/objdiff.git
Compare commits
4 Commits
e68629c339
...
d9e7dacb6d
Author | SHA1 | Date |
---|---|---|
Luke Street | d9e7dacb6d | |
Luke Street | 04b4fdcd21 | |
Luke Street | 803eaafee6 | |
Luke Street | e1dc84698f |
|
@ -2525,7 +2525,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "objdiff"
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"byteorder",
|
||||
|
@ -2539,6 +2539,7 @@ dependencies = [
|
|||
"egui",
|
||||
"egui_extras",
|
||||
"exec",
|
||||
"filetime",
|
||||
"flagset",
|
||||
"globset",
|
||||
"log",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "objdiff"
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
edition = "2021"
|
||||
rust-version = "1.70"
|
||||
authors = ["Luke Street <luke@street.dev>"]
|
||||
|
@ -32,6 +32,7 @@ dirs = "5.0.1"
|
|||
eframe = { version = "0.23.0", features = ["persistence"] }
|
||||
egui = "0.23.0"
|
||||
egui_extras = "0.23.0"
|
||||
filetime = "0.2.22"
|
||||
flagset = "0.4.4"
|
||||
globset = { version = "0.4.13", features = ["serde1"] }
|
||||
log = "0.4.20"
|
||||
|
|
133
src/app.rs
133
src/app.rs
|
@ -1,5 +1,6 @@
|
|||
use std::{
|
||||
default::Default,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
sync::{
|
||||
|
@ -9,16 +10,18 @@ use std::{
|
|||
time::Duration,
|
||||
};
|
||||
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
use filetime::FileTime;
|
||||
use globset::{Glob, GlobSet};
|
||||
use notify::{RecursiveMode, Watcher};
|
||||
use time::UtcOffset;
|
||||
|
||||
use crate::{
|
||||
app_config::{deserialize_config, AppConfigVersion},
|
||||
config::{
|
||||
build_globset, load_project_config, ProjectObject, ProjectObjectNode, CONFIG_FILENAMES,
|
||||
config::{build_globset, load_project_config, ProjectObject, ProjectObjectNode},
|
||||
jobs::{
|
||||
objdiff::{start_build, ObjDiffConfig},
|
||||
Job, JobQueue, JobResult, JobStatus,
|
||||
},
|
||||
jobs::{objdiff::start_build, Job, JobQueue, JobResult, JobStatus},
|
||||
views::{
|
||||
appearance::{appearance_window, Appearance},
|
||||
config::{config_ui, project_window, ConfigViewState, DEFAULT_WATCH_PATTERNS},
|
||||
|
@ -51,6 +54,12 @@ pub struct ObjectConfig {
|
|||
pub complete: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct ProjectConfigInfo {
|
||||
pub path: PathBuf,
|
||||
pub timestamp: FileTime,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bool_true() -> bool { true }
|
||||
|
||||
|
@ -77,6 +86,8 @@ pub struct AppConfig {
|
|||
pub base_obj_dir: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub selected_obj: Option<ObjectConfig>,
|
||||
#[serde(default = "bool_true")]
|
||||
pub build_base: bool,
|
||||
#[serde(default)]
|
||||
pub build_target: bool,
|
||||
#[serde(default = "bool_true")]
|
||||
|
@ -101,7 +112,9 @@ pub struct AppConfig {
|
|||
#[serde(skip)]
|
||||
pub queue_build: bool,
|
||||
#[serde(skip)]
|
||||
pub project_config_loaded: bool,
|
||||
pub queue_reload: bool,
|
||||
#[serde(skip)]
|
||||
pub project_config_info: Option<ProjectConfigInfo>,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
|
@ -114,6 +127,7 @@ impl Default for AppConfig {
|
|||
target_obj_dir: None,
|
||||
base_obj_dir: None,
|
||||
selected_obj: None,
|
||||
build_base: true,
|
||||
build_target: false,
|
||||
rebuild_on_changes: true,
|
||||
auto_update_check: true,
|
||||
|
@ -125,7 +139,8 @@ impl Default for AppConfig {
|
|||
config_change: false,
|
||||
obj_change: false,
|
||||
queue_build: false,
|
||||
project_config_loaded: false,
|
||||
queue_reload: false,
|
||||
project_config_info: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,7 +163,7 @@ impl AppConfig {
|
|||
self.config_change = true;
|
||||
self.obj_change = true;
|
||||
self.queue_build = false;
|
||||
self.project_config_loaded = false;
|
||||
self.project_config_info = None;
|
||||
}
|
||||
|
||||
pub fn set_target_obj_dir(&mut self, path: PathBuf) {
|
||||
|
@ -180,7 +195,6 @@ pub struct App {
|
|||
view_state: ViewState,
|
||||
config: AppConfigRef,
|
||||
modified: Arc<AtomicBool>,
|
||||
config_modified: Arc<AtomicBool>,
|
||||
watcher: Option<notify::RecommendedWatcher>,
|
||||
relaunch_path: Rc<Mutex<Option<PathBuf>>>,
|
||||
should_relaunch: bool,
|
||||
|
@ -286,8 +300,10 @@ impl App {
|
|||
};
|
||||
let config = &mut *config;
|
||||
|
||||
if self.config_modified.swap(false, Ordering::Relaxed) {
|
||||
config.config_change = true;
|
||||
if let Some(info) = &config.project_config_info {
|
||||
if file_modified(&info.path, info.timestamp) {
|
||||
config.config_change = true;
|
||||
}
|
||||
}
|
||||
|
||||
if config.config_change {
|
||||
|
@ -305,21 +321,14 @@ impl App {
|
|||
drop(self.watcher.take());
|
||||
|
||||
if let Some(project_dir) = &config.project_dir {
|
||||
if !config.watch_patterns.is_empty() {
|
||||
match build_globset(&config.watch_patterns)
|
||||
.map_err(anyhow::Error::new)
|
||||
.and_then(|globset| {
|
||||
create_watcher(
|
||||
self.modified.clone(),
|
||||
self.config_modified.clone(),
|
||||
project_dir,
|
||||
globset,
|
||||
)
|
||||
match build_globset(&config.watch_patterns).map_err(anyhow::Error::new).and_then(
|
||||
|globset| {
|
||||
create_watcher(self.modified.clone(), project_dir, globset)
|
||||
.map_err(anyhow::Error::new)
|
||||
}) {
|
||||
Ok(watcher) => self.watcher = Some(watcher),
|
||||
Err(e) => log::error!("Failed to create watcher: {e}"),
|
||||
}
|
||||
},
|
||||
) {
|
||||
Ok(watcher) => self.watcher = Some(watcher),
|
||||
Err(e) => log::error!("Failed to create watcher: {e}"),
|
||||
}
|
||||
config.watcher_change = false;
|
||||
}
|
||||
|
@ -337,11 +346,32 @@ impl App {
|
|||
config.queue_build = true;
|
||||
}
|
||||
|
||||
if let Some(result) = &diff_state.build {
|
||||
if let Some(obj) = &result.first_obj {
|
||||
if file_modified(&obj.path, obj.timestamp) {
|
||||
config.queue_reload = true;
|
||||
}
|
||||
}
|
||||
if let Some(obj) = &result.second_obj {
|
||||
if file_modified(&obj.path, obj.timestamp) {
|
||||
config.queue_reload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't clear `queue_build` if a build is running. A file may have been modified during
|
||||
// the build, so we'll start another build after the current one finishes.
|
||||
if config.queue_build && config.selected_obj.is_some() && !jobs.is_running(Job::ObjDiff) {
|
||||
jobs.push(start_build(self.config.clone()));
|
||||
jobs.push(start_build(ObjDiffConfig::from_config(config)));
|
||||
config.queue_build = false;
|
||||
config.queue_reload = false;
|
||||
} else if config.queue_reload && !jobs.is_running(Job::ObjDiff) {
|
||||
let mut diff_config = ObjDiffConfig::from_config(config);
|
||||
// Don't build, just reload the current files
|
||||
diff_config.build_base = false;
|
||||
diff_config.build_target = false;
|
||||
jobs.push(start_build(diff_config));
|
||||
config.queue_reload = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -373,15 +403,23 @@ impl eframe::App for App {
|
|||
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||
egui::menu::bar(ui, |ui| {
|
||||
ui.menu_button("File", |ui| {
|
||||
if ui.button("Project…").clicked() {
|
||||
*show_project_config = !*show_project_config;
|
||||
ui.close_menu();
|
||||
}
|
||||
let recent_projects = if let Ok(guard) = config.read() {
|
||||
guard.recent_projects.clone()
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
if recent_projects.is_empty() {
|
||||
ui.add_enabled(false, egui::Button::new("Recent Projects…"));
|
||||
ui.add_enabled(false, egui::Button::new("Recent projects…"));
|
||||
} else {
|
||||
ui.menu_button("Recent Projects…", |ui| {
|
||||
if ui.button("Clear").clicked() {
|
||||
config.write().unwrap().recent_projects.clear();
|
||||
};
|
||||
ui.separator();
|
||||
for path in recent_projects {
|
||||
if ui.button(format!("{}", path.display())).clicked() {
|
||||
config.write().unwrap().set_project_dir(path);
|
||||
|
@ -404,6 +442,29 @@ impl eframe::App for App {
|
|||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
ui.menu_button("Diff Options", |ui| {
|
||||
let mut config = config.write().unwrap();
|
||||
let response = ui
|
||||
.checkbox(&mut config.rebuild_on_changes, "Rebuild on changes")
|
||||
.on_hover_text("Automatically re-run the build & diff when files change.");
|
||||
if response.changed() {
|
||||
config.watcher_change = true;
|
||||
};
|
||||
ui.add_enabled(
|
||||
!diff_state.symbol_state.disable_reverse_fn_order,
|
||||
egui::Checkbox::new(
|
||||
&mut diff_state.symbol_state.reverse_fn_order,
|
||||
"Reverse function order (-inline deferred)",
|
||||
),
|
||||
)
|
||||
.on_disabled_hover_text(
|
||||
"Option disabled because it's set by the project configuration file.",
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut diff_state.symbol_state.show_hidden_symbols,
|
||||
"Show hidden symbols",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -455,16 +516,9 @@ impl eframe::App for App {
|
|||
|
||||
fn create_watcher(
|
||||
modified: Arc<AtomicBool>,
|
||||
config_modified: Arc<AtomicBool>,
|
||||
project_dir: &Path,
|
||||
patterns: GlobSet,
|
||||
) -> notify::Result<notify::RecommendedWatcher> {
|
||||
let mut config_patterns = GlobSetBuilder::new();
|
||||
for filename in CONFIG_FILENAMES {
|
||||
config_patterns.add(Glob::new(filename).unwrap());
|
||||
}
|
||||
let config_patterns = config_patterns.build().unwrap();
|
||||
|
||||
let base_dir = project_dir.to_owned();
|
||||
let mut watcher =
|
||||
notify::recommended_watcher(move |res: notify::Result<notify::Event>| match res {
|
||||
|
@ -479,9 +533,7 @@ fn create_watcher(
|
|||
let Ok(path) = path.strip_prefix(&base_dir) else {
|
||||
continue;
|
||||
};
|
||||
if config_patterns.is_match(path) {
|
||||
config_modified.store(true, Ordering::Relaxed);
|
||||
} else if patterns.is_match(path) {
|
||||
if patterns.is_match(path) {
|
||||
modified.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
|
@ -492,3 +544,12 @@ fn create_watcher(
|
|||
watcher.watch(project_dir, RecursiveMode::Recursive)?;
|
||||
Ok(watcher)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn file_modified(path: &Path, last_ts: FileTime) -> bool {
|
||||
if let Ok(metadata) = fs::metadata(path) {
|
||||
FileTime::from_last_modification_time(&metadata) != last_ts
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,54 @@
|
|||
use std::{
|
||||
fs::File,
|
||||
io::Read,
|
||||
path::{Component, Path, PathBuf},
|
||||
};
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::{bail, Result};
|
||||
use filetime::FileTime;
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
|
||||
use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS};
|
||||
use crate::{
|
||||
app::{AppConfig, ProjectConfigInfo},
|
||||
views::config::DEFAULT_WATCH_PATTERNS,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
fn bool_true() -> bool { true }
|
||||
|
||||
#[derive(Default, Clone, serde::Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct ProjectConfig {
|
||||
#[serde(default)]
|
||||
pub min_version: Option<String>,
|
||||
#[serde(default)]
|
||||
pub custom_make: Option<String>,
|
||||
#[serde(default)]
|
||||
pub target_dir: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub base_dir: Option<PathBuf>,
|
||||
#[serde(default = "bool_true")]
|
||||
pub build_base: bool,
|
||||
#[serde(default)]
|
||||
pub build_target: bool,
|
||||
#[serde(default)]
|
||||
pub watch_patterns: Option<Vec<Glob>>,
|
||||
#[serde(alias = "units")]
|
||||
#[serde(default, alias = "units")]
|
||||
pub objects: Vec<ProjectObject>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, serde::Deserialize)]
|
||||
pub struct ProjectObject {
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub path: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub target_path: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub base_path: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub reverse_fn_order: Option<bool>,
|
||||
#[serde(default)]
|
||||
pub complete: Option<bool>,
|
||||
}
|
||||
|
||||
|
@ -120,7 +141,7 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
|
|||
let Some(project_dir) = &config.project_dir else {
|
||||
return Ok(());
|
||||
};
|
||||
if let Some(result) = try_project_config(project_dir) {
|
||||
if let Some((result, info)) = try_project_config(project_dir) {
|
||||
let project_config = result?;
|
||||
if let Some(min_version) = &project_config.min_version {
|
||||
let version_str = env!("CARGO_PKG_VERSION");
|
||||
|
@ -133,6 +154,7 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
|
|||
config.custom_make = project_config.custom_make;
|
||||
config.target_obj_dir = project_config.target_dir.map(|p| project_dir.join(p));
|
||||
config.base_obj_dir = project_config.base_dir.map(|p| project_dir.join(p));
|
||||
config.build_base = project_config.build_base;
|
||||
config.build_target = project_config.build_target;
|
||||
config.watch_patterns = project_config.watch_patterns.unwrap_or_else(|| {
|
||||
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
|
||||
|
@ -141,34 +163,39 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
|
|||
config.objects = project_config.objects;
|
||||
config.object_nodes =
|
||||
build_nodes(&config.objects, project_dir, &config.target_obj_dir, &config.base_obj_dir);
|
||||
config.project_config_loaded = true;
|
||||
config.project_config_info = Some(info);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn try_project_config(dir: &Path) -> Option<Result<ProjectConfig>> {
|
||||
fn try_project_config(dir: &Path) -> Option<(Result<ProjectConfig>, ProjectConfigInfo)> {
|
||||
for filename in CONFIG_FILENAMES.iter() {
|
||||
let config_path = dir.join(filename);
|
||||
if config_path.is_file() {
|
||||
return match filename.contains("json") {
|
||||
true => Some(read_json_config(&config_path)),
|
||||
false => Some(read_yml_config(&config_path)),
|
||||
let Ok(mut file) = File::open(&config_path) else {
|
||||
continue;
|
||||
};
|
||||
let metadata = file.metadata();
|
||||
if let Ok(metadata) = metadata {
|
||||
if !metadata.is_file() {
|
||||
continue;
|
||||
}
|
||||
let ts = FileTime::from_last_modification_time(&metadata);
|
||||
let config = match filename.contains("json") {
|
||||
true => read_json_config(&mut file),
|
||||
false => read_yml_config(&mut file),
|
||||
};
|
||||
return Some((config, ProjectConfigInfo { path: config_path, timestamp: ts }));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn read_yml_config(config_path: &Path) -> Result<ProjectConfig> {
|
||||
let mut reader = File::open(config_path)
|
||||
.with_context(|| format!("Failed to open config file '{}'", config_path.display()))?;
|
||||
Ok(serde_yaml::from_reader(&mut reader)?)
|
||||
fn read_yml_config<R: Read>(reader: &mut R) -> Result<ProjectConfig> {
|
||||
Ok(serde_yaml::from_reader(reader)?)
|
||||
}
|
||||
|
||||
fn read_json_config(config_path: &Path) -> Result<ProjectConfig> {
|
||||
let mut reader = File::open(config_path)
|
||||
.with_context(|| format!("Failed to open config file '{}'", config_path.display()))?;
|
||||
Ok(serde_json::from_reader(&mut reader)?)
|
||||
fn read_json_config<R: Read>(reader: &mut R) -> Result<ProjectConfig> {
|
||||
Ok(serde_json::from_reader(reader)?)
|
||||
}
|
||||
|
||||
pub fn build_globset(vec: &[Glob]) -> std::result::Result<GlobSet, globset::Error> {
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
use std::{path::Path, process::Command, str::from_utf8, sync::mpsc::Receiver};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
str::from_utf8,
|
||||
sync::mpsc::Receiver,
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Context, Error, Result};
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use crate::{
|
||||
app::{AppConfig, AppConfigRef},
|
||||
app::{AppConfig, ObjectConfig},
|
||||
diff::diff_objs,
|
||||
jobs::{start_job, update_status, Job, JobResult, JobState, JobStatusRef},
|
||||
obj::{elf, ObjInfo},
|
||||
|
@ -15,6 +20,28 @@ pub struct BuildStatus {
|
|||
pub log: String,
|
||||
}
|
||||
|
||||
pub struct ObjDiffConfig {
|
||||
pub build_base: bool,
|
||||
pub build_target: bool,
|
||||
pub custom_make: Option<String>,
|
||||
pub project_dir: Option<PathBuf>,
|
||||
pub selected_obj: Option<ObjectConfig>,
|
||||
pub selected_wsl_distro: Option<String>,
|
||||
}
|
||||
|
||||
impl ObjDiffConfig {
|
||||
pub(crate) fn from_config(config: &AppConfig) -> Self {
|
||||
ObjDiffConfig {
|
||||
build_base: config.build_base,
|
||||
build_target: config.build_target,
|
||||
custom_make: config.custom_make.clone(),
|
||||
project_dir: config.project_dir.clone(),
|
||||
selected_obj: config.selected_obj.clone(),
|
||||
selected_wsl_distro: config.selected_wsl_distro.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ObjDiffResult {
|
||||
pub first_status: BuildStatus,
|
||||
pub second_status: BuildStatus,
|
||||
|
@ -23,7 +50,7 @@ pub struct ObjDiffResult {
|
|||
pub time: OffsetDateTime,
|
||||
}
|
||||
|
||||
fn run_make(cwd: &Path, arg: &Path, config: &AppConfig) -> BuildStatus {
|
||||
fn run_make(cwd: &Path, arg: &Path, config: &ObjDiffConfig) -> BuildStatus {
|
||||
match (|| -> Result<BuildStatus> {
|
||||
let make = config.custom_make.as_deref().unwrap_or("make");
|
||||
#[cfg(not(windows))]
|
||||
|
@ -73,9 +100,8 @@ fn run_make(cwd: &Path, arg: &Path, config: &AppConfig) -> BuildStatus {
|
|||
fn run_build(
|
||||
status: &JobStatusRef,
|
||||
cancel: Receiver<()>,
|
||||
config: AppConfigRef,
|
||||
config: ObjDiffConfig,
|
||||
) -> Result<Box<ObjDiffResult>> {
|
||||
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
|
||||
let obj_config = config.selected_obj.as_ref().ok_or_else(|| Error::msg("Missing obj path"))?;
|
||||
let project_dir =
|
||||
config.project_dir.as_ref().ok_or_else(|| Error::msg("Missing project dir"))?;
|
||||
|
@ -106,7 +132,7 @@ fn run_build(
|
|||
if config.build_target && target_path_rel.is_some() {
|
||||
total += 1;
|
||||
}
|
||||
if base_path_rel.is_some() {
|
||||
if config.build_base && base_path_rel.is_some() {
|
||||
total += 1;
|
||||
}
|
||||
let first_status = match target_path_rel {
|
||||
|
@ -123,17 +149,18 @@ fn run_build(
|
|||
_ => BuildStatus { success: true, log: String::new() },
|
||||
};
|
||||
|
||||
let second_status = if let Some(base_path_rel) = base_path_rel {
|
||||
update_status(
|
||||
status,
|
||||
format!("Building base {}", base_path_rel.display()),
|
||||
1,
|
||||
total,
|
||||
&cancel,
|
||||
)?;
|
||||
run_make(project_dir, base_path_rel, &config)
|
||||
} else {
|
||||
BuildStatus { success: true, log: String::new() }
|
||||
let second_status = match base_path_rel {
|
||||
Some(base_path_rel) if config.build_base => {
|
||||
update_status(
|
||||
status,
|
||||
format!("Building base {}", base_path_rel.display()),
|
||||
0,
|
||||
total,
|
||||
&cancel,
|
||||
)?;
|
||||
run_make(project_dir, base_path_rel, &config)
|
||||
}
|
||||
_ => BuildStatus { success: true, log: String::new() },
|
||||
};
|
||||
|
||||
let time = OffsetDateTime::now_utc();
|
||||
|
@ -179,7 +206,7 @@ fn run_build(
|
|||
Ok(Box::new(ObjDiffResult { first_status, second_status, first_obj, second_obj, time }))
|
||||
}
|
||||
|
||||
pub fn start_build(config: AppConfigRef) -> JobState {
|
||||
pub fn start_build(config: ObjDiffConfig) -> JobState {
|
||||
start_job("Object diff", Job::ObjDiff, move |status, cancel| {
|
||||
run_build(status, cancel, config).map(|result| JobResult::ObjDiff(Some(result)))
|
||||
})
|
||||
|
|
|
@ -3,10 +3,11 @@ use std::{collections::BTreeMap, fs, io::Cursor, path::Path};
|
|||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
use cwdemangle::demangle;
|
||||
use filetime::FileTime;
|
||||
use flagset::Flags;
|
||||
use object::{
|
||||
elf, Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget,
|
||||
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolSection,
|
||||
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolScope, SymbolSection,
|
||||
};
|
||||
|
||||
use crate::obj::{
|
||||
|
@ -42,6 +43,9 @@ fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> R
|
|||
if symbol.is_weak() {
|
||||
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Weak);
|
||||
}
|
||||
if symbol.scope() == SymbolScope::Linkage {
|
||||
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Hidden);
|
||||
}
|
||||
let section_address = if let Some(section) =
|
||||
symbol.section_index().and_then(|idx| obj_file.section_by_index(idx).ok())
|
||||
{
|
||||
|
@ -301,9 +305,10 @@ fn line_info(obj_file: &File<'_>) -> Result<Option<BTreeMap<u32, u32>>> {
|
|||
}
|
||||
|
||||
pub fn read(obj_path: &Path) -> Result<ObjInfo> {
|
||||
let data = {
|
||||
let (data, timestamp) = {
|
||||
let file = fs::File::open(obj_path)?;
|
||||
unsafe { memmap2::Mmap::map(&file) }?
|
||||
let timestamp = FileTime::from_last_modification_time(&file.metadata()?);
|
||||
(unsafe { memmap2::Mmap::map(&file) }?, timestamp)
|
||||
};
|
||||
let obj_file = File::parse(&*data)?;
|
||||
let architecture = match obj_file.architecture() {
|
||||
|
@ -319,6 +324,7 @@ pub fn read(obj_path: &Path) -> Result<ObjInfo> {
|
|||
let mut result = ObjInfo {
|
||||
architecture,
|
||||
path: obj_path.to_owned(),
|
||||
timestamp,
|
||||
sections: filter_sections(&obj_file)?,
|
||||
common: common_symbols(&obj_file)?,
|
||||
line_info: line_info(&obj_file)?,
|
||||
|
|
|
@ -4,6 +4,7 @@ pub mod ppc;
|
|||
|
||||
use std::{collections::BTreeMap, path::PathBuf};
|
||||
|
||||
use filetime::FileTime;
|
||||
use flagset::{flags, FlagSet};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||
|
@ -18,6 +19,7 @@ flags! {
|
|||
Local,
|
||||
Weak,
|
||||
Common,
|
||||
Hidden,
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
|
@ -143,6 +145,7 @@ pub enum ObjArchitecture {
|
|||
pub struct ObjInfo {
|
||||
pub architecture: ObjArchitecture,
|
||||
pub path: PathBuf,
|
||||
pub timestamp: FileTime,
|
||||
pub sections: Vec<ObjSection>,
|
||||
pub common: Vec<ObjSymbol>,
|
||||
pub line_info: Option<BTreeMap<u32, u32>>,
|
||||
|
|
|
@ -616,7 +616,7 @@ fn split_obj_config_ui(
|
|||
ui.label(job);
|
||||
},
|
||||
appearance,
|
||||
!config.project_config_loaded,
|
||||
config.project_config_info.is_none(),
|
||||
);
|
||||
if response.clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder() {
|
||||
|
@ -666,13 +666,36 @@ fn split_obj_config_ui(
|
|||
ui.label(job);
|
||||
},
|
||||
appearance,
|
||||
!config.project_config_loaded,
|
||||
config.project_config_info.is_none(),
|
||||
);
|
||||
if response.clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder() {
|
||||
config.set_base_obj_dir(path);
|
||||
}
|
||||
}
|
||||
ui.checkbox(&mut config.build_base, "Build base objects").on_hover_ui(|ui| {
|
||||
let mut job = LayoutJob::default();
|
||||
job.append(
|
||||
"Tells the build system to produce the base object.\n",
|
||||
0.0,
|
||||
text_format.clone(),
|
||||
);
|
||||
job.append("For example, this would call ", 0.0, text_format.clone());
|
||||
job.append("make path/to/base.o", 0.0, code_format.clone());
|
||||
job.append(".\n\n", 0.0, text_format.clone());
|
||||
job.append(
|
||||
"This can be disabled if you're running the build system\n",
|
||||
0.0,
|
||||
text_format.clone(),
|
||||
);
|
||||
job.append(
|
||||
"externally, and just want objdiff to reload the files\n",
|
||||
0.0,
|
||||
text_format.clone(),
|
||||
);
|
||||
job.append("when they change.", 0.0, text_format.clone());
|
||||
ui.label(job);
|
||||
});
|
||||
ui.separator();
|
||||
}
|
||||
|
||||
|
|
|
@ -163,7 +163,11 @@ fn write_ins(
|
|||
} else {
|
||||
Color32::TRANSPARENT
|
||||
});
|
||||
if ui.add(Label::new(op_label).sense(Sense::click())).clicked() {
|
||||
if ui
|
||||
.add(Label::new(op_label).sense(Sense::click()))
|
||||
.context_menu(|ui| ins_context_menu(ui, ins))
|
||||
.clicked()
|
||||
{
|
||||
if highlighted_op {
|
||||
ins_view_state.highlight = HighlightKind::None;
|
||||
} else {
|
||||
|
@ -262,7 +266,11 @@ fn write_ins(
|
|||
write_text(")", base_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
writing_offset = new_writing_offset;
|
||||
if ui.add(Label::new(job).sense(Sense::click())).clicked() {
|
||||
if ui
|
||||
.add(Label::new(job).sense(Sense::click()))
|
||||
.context_menu(|ui| ins_context_menu(ui, ins))
|
||||
.clicked()
|
||||
{
|
||||
if highlighted_arg {
|
||||
ins_view_state.highlight = HighlightKind::None;
|
||||
} else if matches!(arg, ObjInsArg::Reloc | ObjInsArg::RelocWithBase) {
|
||||
|
@ -444,7 +452,11 @@ fn asm_row_ui(
|
|||
},
|
||||
..Default::default()
|
||||
});
|
||||
if ui.add(Label::new(job).sense(Sense::click())).clicked() {
|
||||
if ui
|
||||
.add(Label::new(job).sense(Sense::click()))
|
||||
.context_menu(|ui| ins_context_menu(ui, ins))
|
||||
.clicked()
|
||||
{
|
||||
if addr_highlight {
|
||||
ins_view_state.highlight = HighlightKind::None;
|
||||
} else {
|
||||
|
|
|
@ -47,6 +47,7 @@ pub struct SymbolViewState {
|
|||
pub selected_symbol: Option<SymbolReference>,
|
||||
pub reverse_fn_order: bool,
|
||||
pub disable_reverse_fn_order: bool,
|
||||
pub show_hidden_symbols: bool,
|
||||
}
|
||||
|
||||
impl DiffViewState {
|
||||
|
@ -136,6 +137,9 @@ fn symbol_ui(
|
|||
state: &mut SymbolViewState,
|
||||
appearance: &Appearance,
|
||||
) -> Option<View> {
|
||||
if symbol.flags.0.contains(ObjSymbolFlags::Hidden) && !state.show_hidden_symbols {
|
||||
return None;
|
||||
}
|
||||
let mut ret = None;
|
||||
let mut job = LayoutJob::default();
|
||||
let name: &str =
|
||||
|
@ -155,6 +159,9 @@ fn symbol_ui(
|
|||
if symbol.flags.0.contains(ObjSymbolFlags::Weak) {
|
||||
write_text("w", appearance.text_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
if symbol.flags.0.contains(ObjSymbolFlags::Hidden) {
|
||||
write_text("h", appearance.deemphasized_text_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
write_text("] ", appearance.text_color, &mut job, appearance.code_font.clone());
|
||||
if let Some(match_percent) = symbol.match_percent {
|
||||
write_text("(", appearance.text_color, &mut job, appearance.code_font.clone());
|
||||
|
@ -336,13 +343,9 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
|
|||
}
|
||||
});
|
||||
|
||||
ui.add_enabled(
|
||||
!symbol_state.disable_reverse_fn_order,
|
||||
egui::Checkbox::new(
|
||||
&mut symbol_state.reverse_fn_order,
|
||||
"Reverse function order (-inline deferred)",
|
||||
),
|
||||
);
|
||||
if ui.add_enabled(!state.build_running, egui::Button::new("Build")).clicked() {
|
||||
state.queue_build = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue