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

Add kind/platform info to cargo metadata #7132

Merged
merged 3 commits into from
Nov 14, 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
28 changes: 24 additions & 4 deletions src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::core::compiler::{CompileKind, CompileTarget, TargetInfo};
use crate::core::resolver::{Resolve, ResolveOpts};
use crate::core::{Package, PackageId, Workspace};
use crate::core::{dependency, Dependency, Package, PackageId, Workspace};
use crate::ops::{self, Packages};
use crate::util::CargoResult;

use cargo_platform::Platform;
use serde::Serialize;
use std::collections::HashMap;
use std::path::PathBuf;
Expand Down Expand Up @@ -85,6 +85,22 @@ struct MetadataResolveNode {
struct Dep {
name: String,
pkg: PackageId,
dep_kinds: Vec<DepKindInfo>,
}

#[derive(Serialize)]
struct DepKindInfo {
kind: dependency::Kind,
target: Option<Platform>,
}

impl From<&Dependency> for DepKindInfo {
fn from(dep: &Dependency) -> DepKindInfo {
DepKindInfo {
kind: dep.kind(),
target: dep.platform().cloned(),
}
}
}

/// Builds the resolve graph as it will be displayed to the user.
Expand Down Expand Up @@ -167,12 +183,16 @@ fn build_resolve_graph_r(
}),
None => true,
})
.filter_map(|(dep_id, _deps)| {
.filter_map(|(dep_id, deps)| {
package_map
.get(&dep_id)
.and_then(|pkg| pkg.targets().iter().find(|t| t.is_lib()))
.and_then(|lib_target| resolve.extern_crate_name(pkg_id, dep_id, lib_target).ok())
.map(|name| Dep { name, pkg: dep_id })
.map(|name| Dep {
name,
pkg: dep_id,
dep_kinds: deps.iter().map(DepKindInfo::from).collect(),
})
})
.collect();
let dumb_deps: Vec<PackageId> = deps.iter().map(|dep| dep.pkg).collect();
Expand Down
30 changes: 22 additions & 8 deletions src/doc/man/cargo-metadata.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,14 @@ The output has the following format:
"workspace_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
/* The resolved dependency graph, with the concrete versions and features
selected. The set depends on the enabled features.
This is null if --no-deps is specified.
By default, this includes all dependencies for all target platforms.
The `--filter-platform` flag may be used to narrow to a specific
target triple.
*/
// The resolved dependency graph, with the concrete versions and features
// selected. The set depends on the enabled features.
//
// This is null if --no-deps is specified.
//
// By default, this includes all dependencies for all target platforms.
// The `--filter-platform` flag may be used to narrow to a specific
// target triple.
"resolve": {
/* Array of nodes within the dependency graph.
Each node is a package.
Expand All @@ -230,7 +231,20 @@ The output has the following format:
*/
"name": "bitflags",
/* The Package ID of the dependency. */
"pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
"pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
/* Array of dependency kinds. Added in Cargo 1.40. */
"dep_kinds": [
{
/* The dependency kind.
"dev", "build", or null for a normal dependency.
*/
"kind": null,
/* The target platform for the dependency.
null if not a target dependency.
*/
"target": "cfg(windows)"
}
]
}
],
/* Array of features enabled on this package. */
Expand Down
30 changes: 22 additions & 8 deletions src/doc/man/generated/cargo-metadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,14 @@ <h2 id="cargo_metadata_output_format">OUTPUT FORMAT</h2>
"workspace_members": [
"my-package 0.1.0 (path+file:///path/to/my-package)",
],
/* The resolved dependency graph, with the concrete versions and features
selected. The set depends on the enabled features.
This is null if --no-deps is specified.
By default, this includes all dependencies for all target platforms.
The `--filter-platform` flag may be used to narrow to a specific
target triple.
*/
// The resolved dependency graph, with the concrete versions and features
// selected. The set depends on the enabled features.
//
// This is null if --no-deps is specified.
//
// By default, this includes all dependencies for all target platforms.
// The `--filter-platform` flag may be used to narrow to a specific
// target triple.
"resolve": {
/* Array of nodes within the dependency graph.
Each node is a package.
Expand All @@ -237,7 +238,20 @@ <h2 id="cargo_metadata_output_format">OUTPUT FORMAT</h2>
*/
"name": "bitflags",
/* The Package ID of the dependency. */
"pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)"
"pkg": "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
/* Array of dependency kinds. Added in Cargo 1.40. */
"dep_kinds": [
{
/* The dependency kind.
"dev", "build", or null for a normal dependency.
*/
"kind": null,
/* The target platform for the dependency.
null if not a target dependency.
*/
"target": "cfg(windows)"
}
]
}
],
/* Array of features enabled on this package. */
Expand Down
30 changes: 22 additions & 8 deletions src/etc/man/cargo-metadata.1
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,14 @@ The output has the following format:
"workspace_members": [
"my\-package 0.1.0 (path+file:///path/to/my\-package)",
],
/* The resolved dependency graph, with the concrete versions and features
selected. The set depends on the enabled features.
This is null if \-\-no\-deps is specified.
By default, this includes all dependencies for all target platforms.
The `\-\-filter\-platform` flag may be used to narrow to a specific
target triple.
*/
// The resolved dependency graph, with the concrete versions and features
// selected. The set depends on the enabled features.
//
// This is null if \-\-no\-deps is specified.
//
// By default, this includes all dependencies for all target platforms.
// The `\-\-filter\-platform` flag may be used to narrow to a specific
// target triple.
"resolve": {
/* Array of nodes within the dependency graph.
Each node is a package.
Expand All @@ -251,7 +252,20 @@ The output has the following format:
*/
"name": "bitflags",
/* The Package ID of the dependency. */
"pkg": "bitflags 1.0.4 (registry+https://github.com/rust\-lang/crates.io\-index)"
"pkg": "bitflags 1.0.4 (registry+https://github.com/rust\-lang/crates.io\-index)",
/* Array of dependency kinds. Added in Cargo 1.40. */
"dep_kinds": [
{
/* The dependency kind.
"dev", "build", or null for a normal dependency.
*/
"kind": null,
/* The target platform for the dependency.
null if not a target dependency.
*/
"target": "cfg(windows)"
}
]
}
],
/* Array of features enabled on this package. */
Expand Down
Loading