From 90e2073b4333a7cca1068d4885200abfb28e95df Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 22 Oct 2021 12:31:11 -0700 Subject: [PATCH 1/3] Add `doc` field to `Target`. Added in https://github.com/rust-lang/cargo/pull/8869 --- src/lib.rs | 6 ++++++ tests/all/Cargo.toml | 1 + tests/test_samples.rs | 19 +++++++++++-------- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4240a549..52205e85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -428,6 +428,12 @@ pub struct Target { #[serde(default = "default_true")] #[cfg_attr(feature = "builder", builder(default = "true"))] pub test: bool, + /// Whether or not this target is documented by `cargo doc`. + /// + /// This is always `true` if running with a version of Cargo older than 1.50. + #[serde(default = "default_true")] + #[cfg_attr(feature = "builder", builder(default = "true"))] + pub doc: bool, } fn default_true() -> bool { diff --git a/tests/all/Cargo.toml b/tests/all/Cargo.toml index 6cdd4de8..6a161866 100644 --- a/tests/all/Cargo.toml +++ b/tests/all/Cargo.toml @@ -47,6 +47,7 @@ crate-type = ["rlib", "cdylib", "dylib", "staticlib"] [[bin]] name = "otherbin" edition = '2015' +doc = false [[bin]] name = "reqfeat" diff --git a/tests/test_samples.rs b/tests/test_samples.rs index 76d49836..c57b812f 100644 --- a/tests/test_samples.rs +++ b/tests/test_samples.rs @@ -95,6 +95,7 @@ fn old_minimal() { assert_eq!(target.edition, "2015"); assert_eq!(target.doctest, true); assert_eq!(target.test, true); + assert_eq!(target.doc, true); assert_eq!(pkg.features.len(), 0); assert_eq!(pkg.manifest_path, "/foo/Cargo.toml"); assert_eq!(pkg.categories.len(), 0); @@ -155,10 +156,10 @@ struct TestObject { #[test] fn all_the_fields() { - // All the fields currently generated as of 1.49. This tries to exercise as + // All the fields currently generated as of 1.51. This tries to exercise as // much as possible. let ver = cargo_version(); - let minimum = semver::Version::parse("1.49.0").unwrap(); + let minimum = semver::Version::parse("1.51.0").unwrap(); if ver < minimum { // edition added in 1.30 // rename added in 1.31 @@ -169,6 +170,7 @@ fn all_the_fields() { // test added in 1.47 // homepage added in 1.49 // documentation added in 1.49 + // doc added in 1.50 // path added in 1.51 eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver); return; @@ -222,12 +224,10 @@ fn all_the_fields() { assert_eq!(path_dep.source, None); assert_eq!(path_dep.kind, DependencyKind::Normal); assert_eq!(path_dep.req, semver::VersionReq::parse("*").unwrap()); - if ver >= semver::Version::parse("1.51.0").unwrap() { - assert_eq!( - path_dep.path.as_ref().map(|p| p.ends_with("path-dep")), - Some(true), - ); - } + assert_eq!( + path_dep.path.as_ref().map(|p| p.ends_with("path-dep")), + Some(true), + ); all.dependencies .iter() @@ -292,15 +292,18 @@ fn all_the_fields() { assert_eq!(lib.edition, "2018"); assert_eq!(lib.doctest, true); assert_eq!(lib.test, true); + assert_eq!(lib.doc, true); let main = get_file_name!("main.rs"); assert_eq!(main.crate_types, vec!["bin"]); assert_eq!(main.kind, vec!["bin"]); assert_eq!(main.doctest, false); assert_eq!(main.test, true); + assert_eq!(main.doc, true); let otherbin = get_file_name!("otherbin.rs"); assert_eq!(otherbin.edition, "2015"); + assert_eq!(otherbin.doc, false); let reqfeat = get_file_name!("reqfeat.rs"); assert_eq!(reqfeat.required_features, vec!["feat2"]); From 409729edac4d129332a35f887f61e491622d9f05 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 22 Oct 2021 12:40:45 -0700 Subject: [PATCH 2/3] Add `default_run` field to `Package`. Added in https://github.com/rust-lang/cargo/pull/9550 --- src/lib.rs | 4 ++++ tests/all/Cargo.toml | 1 + tests/test_samples.rs | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 52205e85..653224c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -345,6 +345,10 @@ pub struct Package { /// /// This is always `None` if running with a version of Cargo older than 1.39. pub publish: Option>, + /// The default binary to run by `cargo run`. + /// + /// This is always `None` if running with a version of Cargo older than 1.55. + pub default_run: Option, } impl Package { diff --git a/tests/all/Cargo.toml b/tests/all/Cargo.toml index 6a161866..db2d82ff 100644 --- a/tests/all/Cargo.toml +++ b/tests/all/Cargo.toml @@ -14,6 +14,7 @@ homepage = "https://github.com/oli-obk/cargo_metadata/" documentation = "https://docs.rs/cargo_metadata/" links = "foo" publish = false +default-run = "otherbin" [package.metadata.docs.rs] all-features = true diff --git a/tests/test_samples.rs b/tests/test_samples.rs index c57b812f..cbf4d22e 100644 --- a/tests/test_samples.rs +++ b/tests/test_samples.rs @@ -73,6 +73,7 @@ fn old_minimal() { assert_eq!(pkg.description, None); assert_eq!(pkg.license, None); assert_eq!(pkg.license_file, None); + assert_eq!(pkg.default_run, None); assert_eq!(pkg.dependencies.len(), 1); let dep = &pkg.dependencies[0]; assert_eq!(dep.name, "somedep"); @@ -156,10 +157,10 @@ struct TestObject { #[test] fn all_the_fields() { - // All the fields currently generated as of 1.51. This tries to exercise as + // All the fields currently generated as of 1.55. This tries to exercise as // much as possible. let ver = cargo_version(); - let minimum = semver::Version::parse("1.51.0").unwrap(); + let minimum = semver::Version::parse("1.55.0").unwrap(); if ver < minimum { // edition added in 1.30 // rename added in 1.31 @@ -172,6 +173,7 @@ fn all_the_fields() { // documentation added in 1.49 // doc added in 1.50 // path added in 1.51 + // default_run added in 1.55 eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver); return; } @@ -202,6 +204,7 @@ fn all_the_fields() { assert!(all.license_file().unwrap().ends_with("tests/all/LICENSE")); assert_eq!(all.publish, Some(vec![])); assert_eq!(all.links, Some("foo".to_string())); + assert_eq!(all.default_run, Some("otherbin".to_string())); assert_eq!(all.dependencies.len(), 8); let bitflags = all From 1ca3f6cb855dc893a02ad00c285c3e9878b4dfe2 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Fri, 22 Oct 2021 12:58:35 -0700 Subject: [PATCH 3/3] Add `rust_version` field to `Package`. Added in https://github.com/rust-lang/cargo/pull/9967 --- src/lib.rs | 6 +++++- tests/all/Cargo.toml | 1 + tests/test_samples.rs | 12 ++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 653224c4..6e111efe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ use std::process::Command; use std::str::from_utf8; pub use camino; -pub use semver::Version; +pub use semver::{Version, VersionReq}; pub use dependency::{Dependency, DependencyKind}; use diagnostic::Diagnostic; @@ -349,6 +349,10 @@ pub struct Package { /// /// This is always `None` if running with a version of Cargo older than 1.55. pub default_run: Option, + /// The minimum supported Rust version of this package. + /// + /// This is always `None` if running with a version of Cargo older than 1.58. + pub rust_version: Option, } impl Package { diff --git a/tests/all/Cargo.toml b/tests/all/Cargo.toml index db2d82ff..435dfaf4 100644 --- a/tests/all/Cargo.toml +++ b/tests/all/Cargo.toml @@ -15,6 +15,7 @@ documentation = "https://docs.rs/cargo_metadata/" links = "foo" publish = false default-run = "otherbin" +rust-version = "1.56" [package.metadata.docs.rs] all-features = true diff --git a/tests/test_samples.rs b/tests/test_samples.rs index cbf4d22e..c5d9c3ce 100644 --- a/tests/test_samples.rs +++ b/tests/test_samples.rs @@ -74,6 +74,7 @@ fn old_minimal() { assert_eq!(pkg.license, None); assert_eq!(pkg.license_file, None); assert_eq!(pkg.default_run, None); + assert_eq!(pkg.rust_version, None); assert_eq!(pkg.dependencies.len(), 1); let dep = &pkg.dependencies[0]; assert_eq!(dep.name, "somedep"); @@ -157,10 +158,10 @@ struct TestObject { #[test] fn all_the_fields() { - // All the fields currently generated as of 1.55. This tries to exercise as + // All the fields currently generated as of 1.58. This tries to exercise as // much as possible. let ver = cargo_version(); - let minimum = semver::Version::parse("1.55.0").unwrap(); + let minimum = semver::Version::parse("1.56.0").unwrap(); if ver < minimum { // edition added in 1.30 // rename added in 1.31 @@ -174,6 +175,7 @@ fn all_the_fields() { // doc added in 1.50 // path added in 1.51 // default_run added in 1.55 + // rust_version added in 1.58 eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver); return; } @@ -205,6 +207,12 @@ fn all_the_fields() { assert_eq!(all.publish, Some(vec![])); assert_eq!(all.links, Some("foo".to_string())); assert_eq!(all.default_run, Some("otherbin".to_string())); + if ver >= semver::Version::parse("1.58.0").unwrap() { + assert_eq!( + all.rust_version, + Some(semver::VersionReq::parse("1.56").unwrap()) + ); + } assert_eq!(all.dependencies.len(), 8); let bitflags = all