Skip to content

Commit 774c64c

Browse files
committed
Auto merge of #8869 - ayazhafiz:e/metadata-doc, r=ehuss
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
2 parents 41c0f48 + 600e231 commit 774c64c

File tree

13 files changed

+65
-0
lines changed

13 files changed

+65
-0
lines changed

src/cargo/core/manifest.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ struct SerializedTarget<'a> {
259259
edition: &'a str,
260260
#[serde(rename = "required-features", skip_serializing_if = "Option::is_none")]
261261
required_features: Option<Vec<&'a str>>,
262+
/// Whether docs should be built for the target via `cargo doc`
263+
/// See https://doc.rust-lang.org/cargo/commands/cargo-doc.html#target-selection
264+
doc: bool,
262265
doctest: bool,
263266
/// Whether tests should be run for the target (`test` field in `Cargo.toml`)
264267
test: bool,
@@ -281,6 +284,7 @@ impl ser::Serialize for Target {
281284
required_features: self
282285
.required_features()
283286
.map(|rf| rf.iter().map(|s| &**s).collect()),
287+
doc: self.documented(),
284288
doctest: self.doctested() && self.doctestable(),
285289
test: self.tested(),
286290
}

src/doc/man/cargo-metadata.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ The output has the following format:
127127
This property is not included if no required features are set.
128128
*/
129129
"required-features": ["feat1"],
130+
/* Whether the target should be documented by `cargo doc`. */
131+
"doc": true,
130132
/* Whether or not this target has doc tests enabled, and
131133
the target is compatible with doc testing.
132134
*/

src/doc/man/generated_txt/cargo-metadata.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ OUTPUT FORMAT
122122
This property is not included if no required features are set.
123123
*/
124124
"required-features": ["feat1"],
125+
/* Whether the target should be documented by `cargo doc`. */
126+
"doc": true,
125127
/* Whether or not this target has doc tests enabled, and
126128
the target is compatible with doc testing.
127129
*/

src/doc/src/commands/cargo-metadata.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ The output has the following format:
127127
This property is not included if no required features are set.
128128
*/
129129
"required-features": ["feat1"],
130+
/* Whether the target should be documented by `cargo doc`. */
131+
"doc": true,
130132
/* Whether or not this target has doc tests enabled, and
131133
the target is compatible with doc testing.
132134
*/

src/etc/man/cargo-metadata.1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ The output has the following format:
124124
This property is not included if no required features are set.
125125
*/
126126
"required\-features": ["feat1"],
127+
/* Whether the target should be documented by `cargo doc`. */
128+
"doc": true,
127129
/* Whether or not this target has doc tests enabled, and
128130
the target is compatible with doc testing.
129131
*/

tests/testsuite/bench.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,6 +1741,7 @@ fn json_artifact_includes_executable_for_benchmark() {
17411741
"target": {
17421742
"crate_types": [ "bin" ],
17431743
"kind": [ "bench" ],
1744+
"doc": false,
17441745
"doctest": false,
17451746
"edition": "2015",
17461747
"name": "benchmark",

tests/testsuite/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,7 @@ fn compiler_json_error_format() {
31443144
"target":{
31453145
"kind":["custom-build"],
31463146
"crate_types":["bin"],
3147+
"doc": false,
31473148
"doctest": false,
31483149
"edition": "2015",
31493150
"name":"build-script-build",
@@ -3169,6 +3170,7 @@ fn compiler_json_error_format() {
31693170
"target":{
31703171
"kind":["lib"],
31713172
"crate_types":["lib"],
3173+
"doc": true,
31723174
"doctest": true,
31733175
"edition": "2015",
31743176
"name":"bar",
@@ -3193,6 +3195,7 @@ fn compiler_json_error_format() {
31933195
"target":{
31943196
"kind":["lib"],
31953197
"crate_types":["lib"],
3198+
"doc": true,
31963199
"doctest": true,
31973200
"edition": "2015",
31983201
"name":"bar",
@@ -3222,6 +3225,7 @@ fn compiler_json_error_format() {
32223225
"target":{
32233226
"kind":["bin"],
32243227
"crate_types":["bin"],
3228+
"doc": true,
32253229
"doctest": false,
32263230
"edition": "2015",
32273231
"name":"foo",
@@ -3237,6 +3241,7 @@ fn compiler_json_error_format() {
32373241
"target":{
32383242
"kind":["bin"],
32393243
"crate_types":["bin"],
3244+
"doc": true,
32403245
"doctest": false,
32413246
"edition": "2015",
32423247
"name":"foo",
@@ -3306,6 +3311,7 @@ fn message_format_json_forward_stderr() {
33063311
"target":{
33073312
"kind":["bin"],
33083313
"crate_types":["bin"],
3314+
"doc": true,
33093315
"doctest": false,
33103316
"edition": "2015",
33113317
"name":"foo",
@@ -3321,6 +3327,7 @@ fn message_format_json_forward_stderr() {
33213327
"target":{
33223328
"kind":["bin"],
33233329
"crate_types":["bin"],
3330+
"doc": true,
33243331
"doctest": false,
33253332
"edition": "2015",
33263333
"name":"foo",

tests/testsuite/metabuild.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ fn metabuild_json_artifact() {
697697
"crate_types": [
698698
"bin"
699699
],
700+
"doc": false,
700701
"doctest": false,
701702
"edition": "2018",
702703
"kind": [
@@ -747,6 +748,7 @@ fn metabuild_failed_build_json() {
747748
"crate_types": [
748749
"bin"
749750
],
751+
"doc": false,
750752
"doctest": false,
751753
"edition": "2018",
752754
"kind": [

tests/testsuite/metadata.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ fn cargo_metadata_simple() {
4545
"crate_types": [
4646
"bin"
4747
],
48+
"doc": true,
4849
"doctest": false,
4950
"test": true,
5051
"edition": "2015",
@@ -141,6 +142,7 @@ crate-type = ["lib", "staticlib"]
141142
"lib",
142143
"staticlib"
143144
],
145+
"doc": true,
144146
"doctest": true,
145147
"test": true,
146148
"edition": "2015",
@@ -225,6 +227,7 @@ optional_feat = []
225227
"crate_types": [
226228
"lib"
227229
],
230+
"doc": true,
228231
"doctest": true,
229232
"test": true,
230233
"edition": "2015",
@@ -340,6 +343,7 @@ fn cargo_metadata_with_deps_and_version() {
340343
"crate_types": [
341344
"lib"
342345
],
346+
"doc": true,
343347
"doctest": true,
344348
"test": true,
345349
"edition": "2015",
@@ -378,6 +382,7 @@ fn cargo_metadata_with_deps_and_version() {
378382
"crate_types": [
379383
"lib"
380384
],
385+
"doc": true,
381386
"doctest": true,
382387
"test": true,
383388
"edition": "2015",
@@ -441,6 +446,7 @@ fn cargo_metadata_with_deps_and_version() {
441446
"crate_types": [
442447
"bin"
443448
],
449+
"doc": true,
444450
"doctest": false,
445451
"test": true,
446452
"edition": "2015",
@@ -479,6 +485,7 @@ fn cargo_metadata_with_deps_and_version() {
479485
"crate_types": [
480486
"lib"
481487
],
488+
"doc": true,
482489
"doctest": true,
483490
"test": true,
484491
"edition": "2015",
@@ -615,6 +622,7 @@ name = "ex"
615622
{
616623
"kind": [ "lib" ],
617624
"crate_types": [ "lib" ],
625+
"doc": true,
618626
"doctest": true,
619627
"test": true,
620628
"edition": "2015",
@@ -624,6 +632,7 @@ name = "ex"
624632
{
625633
"kind": [ "example" ],
626634
"crate_types": [ "bin" ],
635+
"doc": false,
627636
"doctest": false,
628637
"test": false,
629638
"edition": "2015",
@@ -706,6 +715,7 @@ crate-type = ["rlib", "dylib"]
706715
{
707716
"kind": [ "lib" ],
708717
"crate_types": [ "lib" ],
718+
"doc": true,
709719
"doctest": true,
710720
"test": true,
711721
"edition": "2015",
@@ -715,6 +725,7 @@ crate-type = ["rlib", "dylib"]
715725
{
716726
"kind": [ "example" ],
717727
"crate_types": [ "rlib", "dylib" ],
728+
"doc": false,
718729
"doctest": false,
719730
"test": false,
720731
"edition": "2015",
@@ -804,6 +815,7 @@ fn workspace_metadata() {
804815
{
805816
"kind": [ "lib" ],
806817
"crate_types": [ "lib" ],
818+
"doc": true,
807819
"doctest": true,
808820
"test": true,
809821
"edition": "2015",
@@ -840,6 +852,7 @@ fn workspace_metadata() {
840852
{
841853
"kind": [ "lib" ],
842854
"crate_types": [ "lib" ],
855+
"doc": true,
843856
"doctest": true,
844857
"test": true,
845858
"edition": "2015",
@@ -931,6 +944,7 @@ fn workspace_metadata_no_deps() {
931944
{
932945
"kind": [ "lib" ],
933946
"crate_types": [ "lib" ],
947+
"doc": true,
934948
"doctest": true,
935949
"test": true,
936950
"edition": "2015",
@@ -967,6 +981,7 @@ fn workspace_metadata_no_deps() {
967981
{
968982
"kind": [ "lib" ],
969983
"crate_types": ["lib"],
984+
"doc": true,
970985
"doctest": true,
971986
"test": true,
972987
"edition": "2015",
@@ -1028,6 +1043,7 @@ const MANIFEST_OUTPUT: &str = r#"
10281043
"targets":[{
10291044
"kind":["bin"],
10301045
"crate_types":["bin"],
1046+
"doc": true,
10311047
"doctest": false,
10321048
"test": true,
10331049
"edition": "2015",
@@ -1217,6 +1233,7 @@ fn package_metadata() {
12171233
{
12181234
"kind": [ "lib" ],
12191235
"crate_types": [ "lib" ],
1236+
"doc": true,
12201237
"doctest": true,
12211238
"test": true,
12221239
"edition": "2015",
@@ -1293,6 +1310,7 @@ fn package_publish() {
12931310
{
12941311
"kind": [ "lib" ],
12951312
"crate_types": [ "lib" ],
1313+
"doc": true,
12961314
"doctest": true,
12971315
"test": true,
12981316
"edition": "2015",
@@ -1370,6 +1388,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
13701388
"crate_types": [
13711389
"lib"
13721390
],
1391+
"doc": true,
13731392
"doctest": true,
13741393
"test": true,
13751394
"edition": "2015",
@@ -1455,6 +1474,7 @@ fn package_edition_2018() {
14551474
"crate_types": [
14561475
"lib"
14571476
],
1477+
"doc": true,
14581478
"doctest": true,
14591479
"test": true,
14601480
"edition": "2018",
@@ -1544,6 +1564,7 @@ fn target_edition_2018() {
15441564
"crate_types": [
15451565
"lib"
15461566
],
1567+
"doc": true,
15471568
"doctest": true,
15481569
"test": true,
15491570
"edition": "2018",
@@ -1557,6 +1578,7 @@ fn target_edition_2018() {
15571578
"crate_types": [
15581579
"bin"
15591580
],
1581+
"doc": true,
15601582
"doctest": false,
15611583
"test": true,
15621584
"edition": "2015",
@@ -1647,6 +1669,7 @@ fn rename_dependency() {
16471669
"crate_types": [
16481670
"lib"
16491671
],
1672+
"doc": true,
16501673
"doctest": true,
16511674
"test": true,
16521675
"edition": "2015",
@@ -1685,6 +1708,7 @@ fn rename_dependency() {
16851708
"crate_types": [
16861709
"lib"
16871710
],
1711+
"doc": true,
16881712
"doctest": true,
16891713
"test": true,
16901714
"edition": "2015",
@@ -1748,6 +1772,7 @@ fn rename_dependency() {
17481772
"crate_types": [
17491773
"lib"
17501774
],
1775+
"doc": true,
17511776
"doctest": true,
17521777
"test": true,
17531778
"edition": "2015",
@@ -1867,6 +1892,7 @@ fn metadata_links() {
18671892
"crate_types": [
18681893
"lib"
18691894
],
1895+
"doc": true,
18701896
"doctest": true,
18711897
"test": true,
18721898
"edition": "2015",
@@ -1880,6 +1906,7 @@ fn metadata_links() {
18801906
"crate_types": [
18811907
"bin"
18821908
],
1909+
"doc": false,
18831910
"doctest": false,
18841911
"test": false,
18851912
"edition": "2015",
@@ -1973,6 +2000,7 @@ fn deps_with_bin_only() {
19732000
"name": "foo",
19742001
"src_path": "[..]/foo/src/lib.rs",
19752002
"edition": "2015",
2003+
"doc": true,
19762004
"doctest": true,
19772005
"test": true
19782006
}
@@ -2076,6 +2104,7 @@ fn filter_platform() {
20762104
"src_path": "[..]/alt-dep-0.0.1/src/lib.rs",
20772105
"edition": "2015",
20782106
"test": true,
2107+
"doc": true,
20792108
"doctest": true
20802109
}
20812110
],
@@ -2117,6 +2146,7 @@ fn filter_platform() {
21172146
"src_path": "[..]/cfg-dep-0.0.1/src/lib.rs",
21182147
"edition": "2015",
21192148
"test": true,
2149+
"doc": true,
21202150
"doctest": true
21212151
}
21222152
],
@@ -2158,6 +2188,7 @@ fn filter_platform() {
21582188
"src_path": "[..]/host-dep-0.0.1/src/lib.rs",
21592189
"edition": "2015",
21602190
"test": true,
2191+
"doc": true,
21612192
"doctest": true
21622193
}
21632194
],
@@ -2199,6 +2230,7 @@ fn filter_platform() {
21992230
"src_path": "[..]/normal-dep-0.0.1/src/lib.rs",
22002231
"edition": "2015",
22012232
"test": true,
2233+
"doc": true,
22022234
"doctest": true
22032235
}
22042236
],
@@ -2289,6 +2321,7 @@ fn filter_platform() {
22892321
"src_path": "[..]/foo/src/lib.rs",
22902322
"edition": "2015",
22912323
"test": true,
2324+
"doc": true,
22922325
"doctest": true
22932326
}
22942327
],

0 commit comments

Comments
 (0)