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