Skip to content
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

cargo metadata: Don't show null deps. #6534

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
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
11 changes: 5 additions & 6 deletions src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ where
{
#[derive(Serialize)]
struct Dep {
name: Option<String>,
name: String,
pkg: PackageId,
}

Expand All @@ -123,13 +123,12 @@ where
dependencies: resolve.deps(id).map(|(pkg, _deps)| pkg).collect(),
deps: resolve
.deps(id)
.map(|(pkg, _deps)| {
let name = packages
.filter_map(|(pkg, _deps)| {
packages
.get(&pkg)
.and_then(|pkg| pkg.targets().iter().find(|t| t.is_lib()))
.and_then(|lib_target| resolve.extern_crate_name(id, pkg, lib_target).ok());

Dep { name, pkg }
.and_then(|lib_target| resolve.extern_crate_name(id, pkg, lib_target).ok())
.map(|name| Dep { name, pkg })
})
.collect(),
features: resolve.features_sorted(id),
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/cargo-metadata.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ The output has the following format:
*/
"deps": [
{
/* The name of the dependency.
/* The name of the dependency's library target.
If this is a renamed dependency, this is the new
name.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/doc/man/generated/cargo-metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ <h2 id="cargo_metadata_output_format">OUTPUT FORMAT</h2>
*/
"deps": [
{
/* The name of the dependency.
/* The name of the dependency's library target.
If this is a renamed dependency, this is the new
name.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/etc/man/cargo-metadata.1
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ The output has the following format:
*/
"deps": [
{
/* The name of the dependency.
/* The name of the dependency\(aqs library target.
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
If this is a renamed dependency, this is the new
name.
*/
Expand Down
29 changes: 29 additions & 0 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,3 +1669,32 @@ fn metadata_links() {
)
.run()
}

#[test]
fn deps_with_bin_only() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
bdep = { path = "bdep" }
"#,
)
.file("src/lib.rs", "")
.file("bdep/Cargo.toml", &basic_bin_manifest("bdep"))
.file("bdep/src/main.rs", "fn main() {}")
.build();

let output = p
.cargo("metadata")
.exec_with_output()
.expect("cargo metadata failed");
let stdout = std::str::from_utf8(&output.stdout).unwrap();
let meta: serde_json::Value = serde_json::from_str(stdout).expect("failed to parse json");
let nodes = &meta["resolve"]["nodes"];
assert!(nodes[0]["deps"].as_array().unwrap().is_empty());
assert!(nodes[1]["deps"].as_array().unwrap().is_empty());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have a test for this (I remember dealing with this problem explicitelly) already. Might be a good idea to put .unwrap on the name and run the test-suite.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried with an unwrap, but none of the tests failed.