Skip to content

Commit

Permalink
Fix handling of proc macro deps with multiple kinds (#2211)
Browse files Browse the repository at this point in the history
A proc macro dependency may have multiple kinds such as build
and normal. Due to a bug in filtering predicate, such dependencies
are considered only as build dependency.

This PR fixes the bug and adds a regression test.

Issue: #2210

---------

Co-authored-by: UebelAndre <[email protected]>
  • Loading branch information
ulan and UebelAndre authored Oct 25, 2023
1 parent 535af8b commit 9455b71
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 1 deletion.
26 changes: 25 additions & 1 deletion crate_universe/src/metadata/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl DependencySet {
// Do not track workspace members as dependencies. Users are expected to maintain those connections
.filter(|dep| !is_workspace_member(dep, metadata))
.filter(|dep| is_proc_macro_package(&metadata[&dep.pkg]))
.filter(|dep| !is_build_dependency(dep))
.filter(|dep| is_normal_dependency(dep) || is_dev_dependency(dep))
.partition(|dep| is_dev_dependency(dep));

(
Expand Down Expand Up @@ -604,6 +604,30 @@ mod test {
);
}

#[test]
fn multi_kind_proc_macro_dep() {
let metadata = metadata::multi_kind_proc_macro_dep();

let node = find_metadata_node("multi-kind-proc-macro-dep", &metadata);
let dependencies = DependencySet::new_for_node(node, &metadata);

let lib_deps: Vec<_> = dependencies
.proc_macro_deps
.get_iter(None)
.unwrap()
.map(|dep| dep.target_name.clone())
.collect();
assert_eq!(lib_deps, vec!["paste"]);

let build_deps: Vec<_> = dependencies
.build_proc_macro_deps
.get_iter(None)
.unwrap()
.map(|dep| dep.target_name.clone())
.collect();
assert_eq!(build_deps, vec!["paste"]);
}

#[test]
fn optional_deps_disabled() {
let metadata = metadata::optional_deps_disabled();
Expand Down
8 changes: 8 additions & 0 deletions crate_universe/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ pub mod metadata {
.unwrap()
}

pub fn multi_kind_proc_macro_dep() -> cargo_metadata::Metadata {
serde_json::from_str(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/metadata/multi_kind_proc_macro_dep/metadata.json"
)))
.unwrap()
}

pub fn no_deps() -> cargo_metadata::Metadata {
serde_json::from_str(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "multi-kind-proc-macro-dep"
version = "0.1.0"
edition = "2018"

# Required to satisfy cargo but no `lib.rs` is expected to
# exist within test data.
[lib]
path = "lib.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
paste = "=1.0.14"

[build-dependencies]
paste = "=1.0.14"

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

0 comments on commit 9455b71

Please sign in to comment.