Skip to content

Commit

Permalink
objdiff-cli diff: Accept any kind of unit path (#48)
Browse files Browse the repository at this point in the history
* objdiff-cli diff: Accept any kind of unit path

* Appease clippy

* Call `resolve_paths` in slightly fewer cases
  • Loading branch information
ribbanya authored Mar 2, 2024
1 parent 3b1249e commit 023dd7a
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions objdiff-cli/src/cmd/diff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io::stdout, path::PathBuf};
use std::{fs, io::stdout, path::PathBuf, str::FromStr};

use anyhow::{bail, Context, Result};
use argp::FromArgs;
Expand Down Expand Up @@ -74,12 +74,34 @@ pub fn run(args: Args) -> Result<()> {
)
};
if let Some(u) = u {
let Some(object) =
project_config.objects.iter_mut().find(|obj| obj.name() == u)
else {
let unit_path =
PathBuf::from_str(u).ok().and_then(|p| fs::canonicalize(p).ok());

let Some(object) = project_config.objects.iter_mut().find_map(|obj| {
if obj.name.as_deref() == Some(u) {
resolve_paths(obj);
return Some(obj);
}

let Some(up) = unit_path.as_deref() else {
return None;
};

resolve_paths(obj);

if [&obj.base_path, &obj.target_path]
.into_iter()
.filter_map(|p| p.as_ref().and_then(|p| p.canonicalize().ok()))
.any(|p| p == up)
{
return Some(obj);
}

None
}) else {
bail!("Unit not found: {}", u)
};
resolve_paths(object);

object
} else {
let mut idx = None;
Expand All @@ -92,7 +114,7 @@ pub fn run(args: Args) -> Result<()> {
.as_deref()
.map(|o| obj::elf::has_function(o, &args.symbol))
.transpose()?
.unwrap_or_default()
.unwrap_or(false)
{
idx = Some(i);
count += 1;
Expand Down

0 comments on commit 023dd7a

Please sign in to comment.