Skip to content

Commit

Permalink
Merge pull request #61 from ehuss/more-fields
Browse files Browse the repository at this point in the history
Add some more fields.
  • Loading branch information
oli-obk authored Jan 11, 2019
2 parents 5b08e8e + 028e865 commit 8897b2d
Show file tree
Hide file tree
Showing 28 changed files with 674 additions and 17 deletions.
25 changes: 24 additions & 1 deletion src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use serde::{Deserialize, Deserializer};
use semver::VersionReq;
use std::fmt;

#[derive(PartialEq, Clone, Debug, Copy, Serialize, Deserialize)]
/// Dependencies can come in three kinds
Expand Down Expand Up @@ -51,8 +52,30 @@ pub struct Dependency {
/// The list of features enabled for this dependency.
pub features: Vec<String>,
/// The target this dependency is specific to.
target: Option<String>,
///
/// Use the [`Display`] trait to access the contents.
///
/// [`Display`]: https://doc.rust-lang.org/std/fmt/trait.Display.html
pub target: Option<Platform>,
/// If the dependency is renamed, this is the new name for the dependency
/// as a string. None if it is not renamed.
pub rename: Option<String>,
/// The URL of the index of the registry where this dependency is from.
///
/// If None, the dependency is from crates.io.
pub registry: Option<String>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
}

/// A target platform.
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(transparent)]
pub struct Platform(String);

impl fmt::Display for Platform {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ pub struct Node {
#[derive(Clone, Serialize, Deserialize, Debug)]
/// A dependency in a node
pub struct NodeDep {
/// Crate name. If the crate was renamed, it's the new name.
/// The name of the dependency's library target.
/// If the crate was renamed, it is the new name.
pub name: String,
/// Package ID (opaque unique identifier)
pub pkg: PackageId,
Expand Down Expand Up @@ -311,6 +312,8 @@ pub struct Package {
/// ```
#[serde(default)]
pub metadata: serde_json::Value,
/// The name of a native library the package is linking to.
pub links: Option<String>,
#[doc(hidden)]
#[serde(skip)]
__do_not_match_exhaustively: (),
Expand Down
49 changes: 49 additions & 0 deletions tests/all/Cargo.lock

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

50 changes: 50 additions & 0 deletions tests/all/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[package]
name = "all"
version = "0.1.0"
authors = ["Jane Doe <user@example.com>"]
edition = "2018"
license = "MIT/Apache-2.0"
license-file = "LICENSE"
description = "Package description."
categories = ["command-line-utilities"]
keywords = ["cli"]
readme = "README.md"
repository = "https://github.com/oli-obk/cargo_metadata/"
links = "foo"

[package.metadata.docs.rs]
all-features = true
default-target = "x86_64-unknown-linux-gnu"
rustc-args = [ "--example-rustc-arg" ]

[dependencies]
path-dep = { path = "path-dep" }
namedep = { path = "namedep" }
bitflags = { version = "1.0", optional = true }
featdep = { path = "featdep", features = ["i128"], default-features = false }
newname = { path = "oldname", package = "oldname" }

[dev-dependencies]
devdep = { path = "devdep" }

[build-dependencies]
bdep = { path = "bdep" }

[target.'cfg(windows)'.dependencies]
windep = { path = "windep" }

[features]
default = ["feat1", "bitflags"]
feat1 = []
feat2 = []

[lib]
crate-type = ["rlib", "cdylib", "dylib", "staticlib"]

[[bin]]
name = "otherbin"
edition = '2015'

[[bin]]
name = "reqfeat"
required-features = ["feat2"]
6 changes: 6 additions & 0 deletions tests/all/bdep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "bdep"
version = "0.1.0"
edition = "2018"

[dependencies]
Empty file added tests/all/bdep/src/lib.rs
Empty file.
Empty file added tests/all/benches/b1.rs
Empty file.
1 change: 1 addition & 0 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
6 changes: 6 additions & 0 deletions tests/all/devdep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "devdep"
version = "0.1.0"
edition = "2018"

[dependencies]
Empty file added tests/all/devdep/src/lib.rs
Empty file.
Empty file added tests/all/examples/ex1.rs
Empty file.
9 changes: 9 additions & 0 deletions tests/all/featdep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "featdep"
version = "0.1.0"
edition = "2018"

[dependencies]

[features]
i128 = []
Empty file added tests/all/featdep/src/lib.rs
Empty file.
9 changes: 9 additions & 0 deletions tests/all/namedep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "namedep"
version = "0.1.0"
edition = "2018"

[dependencies]

[lib]
name = "different_name"
Empty file added tests/all/namedep/src/lib.rs
Empty file.
6 changes: 6 additions & 0 deletions tests/all/oldname/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "oldname"
version = "0.1.0"
edition = "2018"

[dependencies]
Empty file added tests/all/oldname/src/lib.rs
Empty file.
6 changes: 6 additions & 0 deletions tests/all/path-dep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "path-dep"
version = "0.1.0"
edition = "2018"

[dependencies]
Empty file added tests/all/path-dep/src/lib.rs
Empty file.
1 change: 1 addition & 0 deletions tests/all/src/bin/otherbin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
1 change: 1 addition & 0 deletions tests/all/src/bin/reqfeat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn main() {}
Empty file added tests/all/src/lib.rs
Empty file.
3 changes: 3 additions & 0 deletions tests/all/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
Empty file added tests/all/tests/t1.rs
Empty file.
6 changes: 6 additions & 0 deletions tests/all/windep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "windep"
version = "0.1.0"
edition = "2018"

[dependencies]
Empty file added tests/all/windep/src/lib.rs
Empty file.
32 changes: 17 additions & 15 deletions tests/selftest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ fn metadata() {
Path::new(&metadata.target_directory)
);

assert_eq!(metadata.packages[0].name, "cargo_metadata");
assert_eq!(metadata.packages[0].targets.len(), 2);
let this = &metadata.packages[0];
assert_eq!(this.name, "cargo_metadata");
assert_eq!(this.targets.len(), 3);

assert_eq!(metadata.packages[0].targets[0].name, "cargo_metadata");
assert_eq!(metadata.packages[0].targets[0].kind[0], "lib");
assert_eq!(metadata.packages[0].targets[0].crate_types[0], "lib");
let lib = this.targets.iter().find(|t| t.name == "cargo_metadata").unwrap();
assert_eq!(lib.kind[0], "lib");
assert_eq!(lib.crate_types[0], "lib");

assert_eq!(metadata.packages[0].targets[1].name, "selftest");
assert_eq!(metadata.packages[0].targets[1].kind[0], "test");
assert_eq!(metadata.packages[0].targets[1].crate_types[0], "bin");
let selftest = this.targets.iter().find(|t| t.name == "selftest").unwrap();
assert_eq!(selftest.name, "selftest");
assert_eq!(selftest.kind[0], "test");
assert_eq!(selftest.crate_types[0], "bin");

let package_metadata = &metadata.packages[0].metadata.as_object()
.expect("package.metadata must be a table.");
Expand Down Expand Up @@ -113,15 +115,15 @@ fn metadata_deps() {
let this = &metadata[this_id];

assert_eq!(this.name, "cargo_metadata");
assert_eq!(this.targets.len(), 2);

assert_eq!(this.targets[0].name, "cargo_metadata");
assert_eq!(this.targets[0].kind[0], "lib");
assert_eq!(this.targets[0].crate_types[0], "lib");
let lib = this.targets.iter().find(|t| t.name == "cargo_metadata").unwrap();
assert_eq!(lib.kind[0], "lib");
assert_eq!(lib.crate_types[0], "lib");

assert_eq!(this.targets[1].name, "selftest");
assert_eq!(this.targets[1].kind[0], "test");
assert_eq!(this.targets[1].crate_types[0], "bin");
let selftest = this.targets.iter().find(|t| t.name == "selftest").unwrap();
assert_eq!(selftest.name, "selftest");
assert_eq!(selftest.kind[0], "test");
assert_eq!(selftest.crate_types[0], "bin");

let dependencies = &this.dependencies;

Expand Down
Loading

0 comments on commit 8897b2d

Please sign in to comment.