Skip to content

Commit 023dd7a

Browse files
authored
objdiff-cli diff: Accept any kind of unit path (#48)
* objdiff-cli diff: Accept any kind of unit path * Appease clippy * Call `resolve_paths` in slightly fewer cases
1 parent 3b1249e commit 023dd7a

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

objdiff-cli/src/cmd/diff.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{io::stdout, path::PathBuf};
1+
use std::{fs, io::stdout, path::PathBuf, str::FromStr};
22

33
use anyhow::{bail, Context, Result};
44
use argp::FromArgs;
@@ -74,12 +74,34 @@ pub fn run(args: Args) -> Result<()> {
7474
)
7575
};
7676
if let Some(u) = u {
77-
let Some(object) =
78-
project_config.objects.iter_mut().find(|obj| obj.name() == u)
79-
else {
77+
let unit_path =
78+
PathBuf::from_str(u).ok().and_then(|p| fs::canonicalize(p).ok());
79+
80+
let Some(object) = project_config.objects.iter_mut().find_map(|obj| {
81+
if obj.name.as_deref() == Some(u) {
82+
resolve_paths(obj);
83+
return Some(obj);
84+
}
85+
86+
let Some(up) = unit_path.as_deref() else {
87+
return None;
88+
};
89+
90+
resolve_paths(obj);
91+
92+
if [&obj.base_path, &obj.target_path]
93+
.into_iter()
94+
.filter_map(|p| p.as_ref().and_then(|p| p.canonicalize().ok()))
95+
.any(|p| p == up)
96+
{
97+
return Some(obj);
98+
}
99+
100+
None
101+
}) else {
80102
bail!("Unit not found: {}", u)
81103
};
82-
resolve_paths(object);
104+
83105
object
84106
} else {
85107
let mut idx = None;
@@ -92,7 +114,7 @@ pub fn run(args: Args) -> Result<()> {
92114
.as_deref()
93115
.map(|o| obj::elf::has_function(o, &args.symbol))
94116
.transpose()?
95-
.unwrap_or_default()
117+
.unwrap_or(false)
96118
{
97119
idx = Some(i);
98120
count += 1;

0 commit comments

Comments
 (0)