Skip to content

objdiff-cli diff: Accept any kind of unit path #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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