Skip to content

Commit

Permalink
Merge pull request #353 from pacak/cmd
Browse files Browse the repository at this point in the history
Update cargo_metadata :-/
  • Loading branch information
pacak authored Dec 20, 2024
2 parents 382e197 + 4552b77 commit a92705b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ anyhow = "1"
ar = { version = "0.9", optional = true }
bpaf = { version = "0.9.15", features = ["bpaf_derive", "autocomplete"] }
capstone = { version = "0.12", optional = true }
cargo_metadata = "0.18.1"
cargo_metadata = "0.19.1"
line-span = "0.1"
nom = "7"
object = { version = "0.36", optional = true }
Expand Down
33 changes: 19 additions & 14 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,20 @@ impl TryFrom<&'_ cargo_metadata::Target> for Focus {
type Error = anyhow::Error;

fn try_from(target: &cargo_metadata::Target) -> Result<Self, Self::Error> {
match target.kind.first().map(|s| &**s) {
Some("lib" | "rlib" | "cdylib") => Ok(Focus::Lib),
Some("test") => Ok(Focus::Test(target.name.clone())),
Some("bench") => Ok(Focus::Bench(target.name.clone())),
Some("example") => Ok(Focus::Example(target.name.clone())),
Some("bin") => Ok(Focus::Bin(target.name.clone())),
_ => anyhow::bail!("Unknown target kind: {:?}", target.kind),
use cargo_metadata::TargetKind as T;
let kind = target
.kind
.first()
.ok_or_else(|| anyhow::anyhow!("No target kinds in target"))?;
let name = target.name.clone();
match kind {
T::Lib | T::RLib | T::CDyLib => Ok(Focus::Lib),
T::Test => Ok(Focus::Test(name)),
T::Bench => Ok(Focus::Bench(name)),
T::Example => Ok(Focus::Example(name)),
T::Bin => Ok(Focus::Bin(name)),
// don't bother with handling remaining cases since struct is #[non_exhaustive]
_ => anyhow::bail!("Unsupported target kind {kind:?}"),
}
}
}
Expand Down Expand Up @@ -497,13 +504,11 @@ impl Focus {
#[must_use]
pub fn matches_artifact(&self, artifact: &Artifact) -> bool {
let (kind, name) = self.as_parts();
let somewhat_matches = kind == "lib"
&& artifact
.target
.kind
.iter()
.any(|i| ["rlib", "cdylib"].contains(&i.as_str()));
let kind_matches = artifact.target.kind == [kind];
let somewhat_matches =
kind == "lib" && artifact.target.is_rlib() || artifact.target.is_cdylib();
let kind = <cargo_metadata::TargetKind as std::str::FromStr>::from_str(kind)
.expect("cargo_metadata made me do it");
let kind_matches = artifact.target.kind.contains(&kind);
(somewhat_matches || kind_matches)
&& name.map_or(true, |name| artifact.target.name == *name)
}
Expand Down

0 comments on commit a92705b

Please sign in to comment.