Skip to content

Commit

Permalink
Auto merge of #8869 - ayazhafiz:e/metadata-doc, r=ehuss
Browse files Browse the repository at this point in the history
Publish target's "doc" setting when emitting metadata

Prior to this commit `cargo metadata` would not emit the value of a
target's "doc" setting, used by `cargo doc` to determine whether
documentation should be generated. However, this information is useful
for machine programs interested in such targets, and the information is
already made available on the internal representation of a target, so
this commit just exposes that during target serialization for emit.

cf deadlinks/cargo-deadlinks#99
  • Loading branch information
bors committed Nov 24, 2020
2 parents 41c0f48 + 600e231 commit 774c64c
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ struct SerializedTarget<'a> {
edition: &'a str,
#[serde(rename = "required-features", skip_serializing_if = "Option::is_none")]
required_features: Option<Vec<&'a str>>,
/// Whether docs should be built for the target via `cargo doc`
/// See https://doc.rust-lang.org/cargo/commands/cargo-doc.html#target-selection
doc: bool,
doctest: bool,
/// Whether tests should be run for the target (`test` field in `Cargo.toml`)
test: bool,
Expand All @@ -281,6 +284,7 @@ impl ser::Serialize for Target {
required_features: self
.required_features()
.map(|rf| rf.iter().map(|s| &**s).collect()),
doc: self.documented(),
doctest: self.doctested() && self.doctestable(),
test: self.tested(),
}
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The output has the following format:
This property is not included if no required features are set.
*/
"required-features": ["feat1"],
/* Whether the target should be documented by `cargo doc`. */
"doc": true,
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/generated_txt/cargo-metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ OUTPUT FORMAT
This property is not included if no required features are set.
*/
"required-features": ["feat1"],
/* Whether the target should be documented by `cargo doc`. */
"doc": true,
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/doc/src/commands/cargo-metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The output has the following format:
This property is not included if no required features are set.
*/
"required-features": ["feat1"],
/* Whether the target should be documented by `cargo doc`. */
"doc": true,
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/etc/man/cargo-metadata.1
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ The output has the following format:
This property is not included if no required features are set.
*/
"required\-features": ["feat1"],
/* Whether the target should be documented by `cargo doc`. */
"doc": true,
/* Whether or not this target has doc tests enabled, and
the target is compatible with doc testing.
*/
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,7 @@ fn json_artifact_includes_executable_for_benchmark() {
"target": {
"crate_types": [ "bin" ],
"kind": [ "bench" ],
"doc": false,
"doctest": false,
"edition": "2015",
"name": "benchmark",
Expand Down
7 changes: 7 additions & 0 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3144,6 +3144,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["custom-build"],
"crate_types":["bin"],
"doc": false,
"doctest": false,
"edition": "2015",
"name":"build-script-build",
Expand All @@ -3169,6 +3170,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["lib"],
"crate_types":["lib"],
"doc": true,
"doctest": true,
"edition": "2015",
"name":"bar",
Expand All @@ -3193,6 +3195,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["lib"],
"crate_types":["lib"],
"doc": true,
"doctest": true,
"edition": "2015",
"name":"bar",
Expand Down Expand Up @@ -3222,6 +3225,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"doc": true,
"doctest": false,
"edition": "2015",
"name":"foo",
Expand All @@ -3237,6 +3241,7 @@ fn compiler_json_error_format() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"doc": true,
"doctest": false,
"edition": "2015",
"name":"foo",
Expand Down Expand Up @@ -3306,6 +3311,7 @@ fn message_format_json_forward_stderr() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"doc": true,
"doctest": false,
"edition": "2015",
"name":"foo",
Expand All @@ -3321,6 +3327,7 @@ fn message_format_json_forward_stderr() {
"target":{
"kind":["bin"],
"crate_types":["bin"],
"doc": true,
"doctest": false,
"edition": "2015",
"name":"foo",
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/metabuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ fn metabuild_json_artifact() {
"crate_types": [
"bin"
],
"doc": false,
"doctest": false,
"edition": "2018",
"kind": [
Expand Down Expand Up @@ -747,6 +748,7 @@ fn metabuild_failed_build_json() {
"crate_types": [
"bin"
],
"doc": false,
"doctest": false,
"edition": "2018",
"kind": [
Expand Down
33 changes: 33 additions & 0 deletions tests/testsuite/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn cargo_metadata_simple() {
"crate_types": [
"bin"
],
"doc": true,
"doctest": false,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -141,6 +142,7 @@ crate-type = ["lib", "staticlib"]
"lib",
"staticlib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -225,6 +227,7 @@ optional_feat = []
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -340,6 +343,7 @@ fn cargo_metadata_with_deps_and_version() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -378,6 +382,7 @@ fn cargo_metadata_with_deps_and_version() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -441,6 +446,7 @@ fn cargo_metadata_with_deps_and_version() {
"crate_types": [
"bin"
],
"doc": true,
"doctest": false,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -479,6 +485,7 @@ fn cargo_metadata_with_deps_and_version() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -615,6 +622,7 @@ name = "ex"
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand All @@ -624,6 +632,7 @@ name = "ex"
{
"kind": [ "example" ],
"crate_types": [ "bin" ],
"doc": false,
"doctest": false,
"test": false,
"edition": "2015",
Expand Down Expand Up @@ -706,6 +715,7 @@ crate-type = ["rlib", "dylib"]
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand All @@ -715,6 +725,7 @@ crate-type = ["rlib", "dylib"]
{
"kind": [ "example" ],
"crate_types": [ "rlib", "dylib" ],
"doc": false,
"doctest": false,
"test": false,
"edition": "2015",
Expand Down Expand Up @@ -804,6 +815,7 @@ fn workspace_metadata() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -840,6 +852,7 @@ fn workspace_metadata() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -931,6 +944,7 @@ fn workspace_metadata_no_deps() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -967,6 +981,7 @@ fn workspace_metadata_no_deps() {
{
"kind": [ "lib" ],
"crate_types": ["lib"],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1028,6 +1043,7 @@ const MANIFEST_OUTPUT: &str = r#"
"targets":[{
"kind":["bin"],
"crate_types":["bin"],
"doc": true,
"doctest": false,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1217,6 +1233,7 @@ fn package_metadata() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1293,6 +1310,7 @@ fn package_publish() {
{
"kind": [ "lib" ],
"crate_types": [ "lib" ],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1370,6 +1388,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1455,6 +1474,7 @@ fn package_edition_2018() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2018",
Expand Down Expand Up @@ -1544,6 +1564,7 @@ fn target_edition_2018() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2018",
Expand All @@ -1557,6 +1578,7 @@ fn target_edition_2018() {
"crate_types": [
"bin"
],
"doc": true,
"doctest": false,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1647,6 +1669,7 @@ fn rename_dependency() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1685,6 +1708,7 @@ fn rename_dependency() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1748,6 +1772,7 @@ fn rename_dependency() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand Down Expand Up @@ -1867,6 +1892,7 @@ fn metadata_links() {
"crate_types": [
"lib"
],
"doc": true,
"doctest": true,
"test": true,
"edition": "2015",
Expand All @@ -1880,6 +1906,7 @@ fn metadata_links() {
"crate_types": [
"bin"
],
"doc": false,
"doctest": false,
"test": false,
"edition": "2015",
Expand Down Expand Up @@ -1973,6 +2000,7 @@ fn deps_with_bin_only() {
"name": "foo",
"src_path": "[..]/foo/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
}
Expand Down Expand Up @@ -2076,6 +2104,7 @@ fn filter_platform() {
"src_path": "[..]/alt-dep-0.0.1/src/lib.rs",
"edition": "2015",
"test": true,
"doc": true,
"doctest": true
}
],
Expand Down Expand Up @@ -2117,6 +2146,7 @@ fn filter_platform() {
"src_path": "[..]/cfg-dep-0.0.1/src/lib.rs",
"edition": "2015",
"test": true,
"doc": true,
"doctest": true
}
],
Expand Down Expand Up @@ -2158,6 +2188,7 @@ fn filter_platform() {
"src_path": "[..]/host-dep-0.0.1/src/lib.rs",
"edition": "2015",
"test": true,
"doc": true,
"doctest": true
}
],
Expand Down Expand Up @@ -2199,6 +2230,7 @@ fn filter_platform() {
"src_path": "[..]/normal-dep-0.0.1/src/lib.rs",
"edition": "2015",
"test": true,
"doc": true,
"doctest": true
}
],
Expand Down Expand Up @@ -2289,6 +2321,7 @@ fn filter_platform() {
"src_path": "[..]/foo/src/lib.rs",
"edition": "2015",
"test": true,
"doc": true,
"doctest": true
}
],
Expand Down
Loading

0 comments on commit 774c64c

Please sign in to comment.