Skip to content

Commit

Permalink
Ignore features that reference unresolved crates (#67)
Browse files Browse the repository at this point in the history
* Ignore features that referenced unresolved crates

* Update CHANGELOG
  • Loading branch information
Jake-Shadle committed Jan 20, 2024
1 parent a15d521 commit ab54878
Show file tree
Hide file tree
Showing 6 changed files with 596 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [Unreleased] - ReleaseDate
### Fixed
- [PR#67](https://github.com/EmbarkStudios/krates/pull/67) resolved [#66](https://github.com/EmbarkStudios/krates/issues/66) by ignore features that reference crates that aren't resolved, instead of panicing, as there should only be one case where that occurs.

## [0.16.0] - 2024-01-19
### Fixed
- [PR#65](https://github.com/EmbarkStudios/krates/pull/65) resolved [#64](https://github.com/EmbarkStudios/krates/issues/64) by adding support for the newly stabilized (currently nightly only) package id format.
Expand Down
7 changes: 3 additions & 4 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,9 @@ impl Builder {
let Some(ndep) = rnode.deps.iter().find(|rdep| {
dep_names_match(krate_name, &rdep.name) || krate_name == rdep.pkg.name()
}) else {
unreachable!(
"unable to find dependency {krate_name} for {pid} {:#?}",
rnode.deps
);
// We can have a feature that points to a crate that isn't resolved by cargo due to it being
// a dev-only dependency
continue;
};

let rdep_node = get_rnode(&ndep.pkg);
Expand Down
17 changes: 17 additions & 0 deletions tests/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ fn handles_cyclic_features() {
assert_features!(md, "features-galore", ["cycle", "midi", "subfeatcycle"]);
}

/// Ensures we handle features that enable dev only dependencies
/// <https://github.com/EmbarkStudios/krates/issues/66>
#[test]
fn handles_dev_only_features() {
let mut cmd = krates::Cmd::new();
cmd.manifest_path("tests/features/Cargo.toml")
.no_default_features();

let mut builder = krates::Builder::new();
builder.include_targets([("x86_64-pc-windows-msvc", vec![])]);
builder.ignore_kind(krates::DepKind::Dev, krates::Scope::All);

let md: krates::Krates<util::JustId> = builder.build(cmd, krates::NoneFilter).unwrap();

insta::assert_snapshot!(krates::petgraph::dot::Dot::new(md.graph()).to_string());
}

/// Ensures that features only brought in by eg dev-dependencies are not used if
/// dev-dependencies are ignored
/// <https://github.com/EmbarkStudios/krates/issues/60>
Expand Down

0 comments on commit ab54878

Please sign in to comment.