diff --git a/crate_universe/src/metadata/dependency.rs b/crate_universe/src/metadata/dependency.rs index fcc058bffd..77b197e3cc 100644 --- a/crate_universe/src/metadata/dependency.rs +++ b/crate_universe/src/metadata/dependency.rs @@ -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)); ( @@ -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(); diff --git a/crate_universe/src/test.rs b/crate_universe/src/test.rs index e97e20b654..cdb38ce5f7 100644 --- a/crate_universe/src/test.rs +++ b/crate_universe/src/test.rs @@ -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"), diff --git a/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/Cargo.lock b/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/Cargo.lock new file mode 100644 index 0000000000..df2652de8a --- /dev/null +++ b/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "multi-kind-proc-macro-dep" +version = "0.1.0" +dependencies = [ + "paste", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" diff --git a/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/Cargo.toml b/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/Cargo.toml new file mode 100644 index 0000000000..dc5ede1169 --- /dev/null +++ b/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/Cargo.toml @@ -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" diff --git a/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/metadata.json b/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/metadata.json new file mode 100644 index 0000000000..0c95a7469b --- /dev/null +++ b/crate_universe/test_data/metadata/multi_kind_proc_macro_dep/metadata.json @@ -0,0 +1,297 @@ +{ + "packages": [ + { + "name": "multi-kind-proc-macro-dep", + "version": "0.1.0", + "id": "multi-kind-proc-macro-dep 0.1.0 (path+file://{TMP_DIR}/multi_kind_proc_macro_dep)", + "license": null, + "license_file": null, + "description": null, + "source": null, + "dependencies": [ + { + "name": "paste", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "req": "=1.0.14", + "kind": null, + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": null + }, + { + "name": "paste", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "req": "=1.0.14", + "kind": "build", + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": null + } + ], + "targets": [ + { + "kind": [ + "lib" + ], + "crate_types": [ + "lib" + ], + "name": "multi-kind-proc-macro-dep", + "src_path": "{TMP_DIR}/multi_kind_proc_macro_dep/lib.rs", + "edition": "2018", + "doc": true, + "doctest": true, + "test": true + } + ], + "features": {}, + "manifest_path": "{TMP_DIR}/multi_kind_proc_macro_dep/Cargo.toml", + "metadata": null, + "publish": null, + "authors": [], + "categories": [], + "keywords": [], + "readme": null, + "repository": null, + "homepage": null, + "documentation": null, + "edition": "2018", + "links": null, + "default_run": null, + "rust_version": null + }, + { + "name": "paste", + "version": "1.0.14", + "id": "paste 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "license": "MIT OR Apache-2.0", + "license_file": null, + "description": "Macros for all your token pasting needs", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "dependencies": [ + { + "name": "paste-test-suite", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "req": "^0", + "kind": "dev", + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": null + }, + { + "name": "rustversion", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "req": "^1.0", + "kind": "dev", + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [], + "target": null, + "registry": null + }, + { + "name": "trybuild", + "source": "registry+https://github.com/rust-lang/crates.io-index", + "req": "^1.0.49", + "kind": "dev", + "rename": null, + "optional": false, + "uses_default_features": true, + "features": [ + "diff" + ], + "target": null, + "registry": null + } + ], + "targets": [ + { + "kind": [ + "proc-macro" + ], + "crate_types": [ + "proc-macro" + ], + "name": "paste", + "src_path": "{CARGO_HOME}/registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/src/lib.rs", + "edition": "2018", + "doc": true, + "doctest": true, + "test": true + }, + { + "kind": [ + "test" + ], + "crate_types": [ + "bin" + ], + "name": "test_doc", + "src_path": "{CARGO_HOME}/registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/tests/test_doc.rs", + "edition": "2018", + "doc": false, + "doctest": false, + "test": true + }, + { + "kind": [ + "test" + ], + "crate_types": [ + "bin" + ], + "name": "test_item", + "src_path": "{CARGO_HOME}/registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/tests/test_item.rs", + "edition": "2018", + "doc": false, + "doctest": false, + "test": true + }, + { + "kind": [ + "test" + ], + "crate_types": [ + "bin" + ], + "name": "test_attr", + "src_path": "{CARGO_HOME}/registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/tests/test_attr.rs", + "edition": "2018", + "doc": false, + "doctest": false, + "test": true + }, + { + "kind": [ + "test" + ], + "crate_types": [ + "bin" + ], + "name": "test_expr", + "src_path": "{CARGO_HOME}registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/tests/test_expr.rs", + "edition": "2018", + "doc": false, + "doctest": false, + "test": true + }, + { + "kind": [ + "test" + ], + "crate_types": [ + "bin" + ], + "name": "compiletest", + "src_path": "{CARGO_HOME}/registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/tests/compiletest.rs", + "edition": "2018", + "doc": false, + "doctest": false, + "test": true + }, + { + "kind": [ + "custom-build" + ], + "crate_types": [ + "bin" + ], + "name": "build-script-build", + "src_path": "{CARGO_HOME}/registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/build.rs", + "edition": "2018", + "doc": false, + "doctest": false, + "test": false + } + ], + "features": {}, + "manifest_path": "{CARGO_HOME}/registry/src/index.crates.io-6f17d22bba15001f/paste-1.0.14/Cargo.toml", + "metadata": { + "docs": { + "rs": { + "rustdoc-args": [ + "--generate-link-to-definition" + ], + "targets": [ + "x86_64-unknown-linux-gnu" + ] + } + } + }, + "publish": null, + "authors": [ + "David Tolnay " + ], + "categories": [ + "development-tools", + "no-std", + "no-std::no-alloc" + ], + "keywords": [ + "macros" + ], + "readme": "README.md", + "repository": "https://github.com/dtolnay/paste", + "homepage": null, + "documentation": null, + "edition": "2018", + "links": null, + "default_run": null, + "rust_version": "1.31" + } + ], + "workspace_members": [ + "multi-kind-proc-macro-dep 0.1.0 (path+file://{TMP_DIR}/multi_kind_proc_macro_dep)" + ], + "workspace_default_members": [ + "multi-kind-proc-macro-dep 0.1.0 (path+file://{TMP_DIR}/multi_kind_proc_macro_dep)" + ], + "resolve": { + "nodes": [ + { + "id": "multi-kind-proc-macro-dep 0.1.0 (path+file://{TMP_DIR}/multi_kind_proc_macro_dep)", + "dependencies": [ + "paste 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" + ], + "deps": [ + { + "name": "paste", + "pkg": "paste 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "dep_kinds": [ + { + "kind": null, + "target": null + }, + { + "kind": "build", + "target": null + } + ] + } + ], + "features": [] + }, + { + "id": "paste 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", + "dependencies": [], + "deps": [], + "features": [] + } + ], + "root": "multi-kind-proc-macro-dep 0.1.0 (path+file://{TMP_DIR}/multi_kind_proc_macro_dep)" + }, + "target_directory": "{TMP_DIR}/multi_kind_proc_macro_dep/target", + "version": 1, + "workspace_root": "{TMP_DIR}/multi_kind_proc_macro_dep", + "metadata": null +} \ No newline at end of file