Skip to content

Commit 5a0c31d

Browse files
committed
Auto merge of #6953 - vlad20012:add-doctest-field-to-metadata, r=alexcrichton
Add `doctest` field into metadata Some tools can support rust doctests (e.g. highlighting or launching). So it should be possible to find out if doctests are enabled for a target or not. This commit adds `doctest` field to `cargo metadata` output. Related to intellij-rust/intellij-rust#3852
2 parents c4fcfb7 + b6a8b0f commit 5a0c31d

File tree

8 files changed

+47
-0
lines changed

8 files changed

+47
-0
lines changed

src/cargo/core/manifest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ struct SerializedTarget<'a> {
287287
edition: &'a str,
288288
#[serde(rename = "required-features", skip_serializing_if = "Option::is_none")]
289289
required_features: Option<Vec<&'a str>>,
290+
doctest: bool,
290291
}
291292

292293
impl ser::Serialize for Target {
@@ -307,6 +308,7 @@ impl ser::Serialize for Target {
307308
.required_features
308309
.as_ref()
309310
.map(|rf| rf.iter().map(|s| &**s).collect()),
311+
doctest: self.doctest && self.doctestable(),
310312
}
311313
.serialize(s)
312314
}

tests/testsuite/bench.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ fn json_artifact_includes_executable_for_benchmark() {
16201620
"target": {
16211621
"crate_types": [ "bin" ],
16221622
"kind": [ "bench" ],
1623+
"doctest": false,
16231624
"edition": "2015",
16241625
"name": "benchmark",
16251626
"src_path": "[..]/foo/benches/benchmark.rs"

tests/testsuite/build.rs

+10
Original file line numberDiff line numberDiff line change
@@ -3052,6 +3052,7 @@ fn compiler_json_error_format() {
30523052
"target":{
30533053
"kind":["custom-build"],
30543054
"crate_types":["bin"],
3055+
"doctest": false,
30553056
"edition": "2015",
30563057
"name":"build-script-build",
30573058
"src_path":"[..]build.rs"
@@ -3075,6 +3076,7 @@ fn compiler_json_error_format() {
30753076
"target":{
30763077
"kind":["lib"],
30773078
"crate_types":["lib"],
3079+
"doctest": true,
30783080
"edition": "2015",
30793081
"name":"bar",
30803082
"src_path":"[..]lib.rs"
@@ -3097,6 +3099,7 @@ fn compiler_json_error_format() {
30973099
"target":{
30983100
"kind":["lib"],
30993101
"crate_types":["lib"],
3102+
"doctest": true,
31003103
"edition": "2015",
31013104
"name":"bar",
31023105
"src_path":"[..]lib.rs"
@@ -3123,6 +3126,7 @@ fn compiler_json_error_format() {
31233126
"target":{
31243127
"kind":["bin"],
31253128
"crate_types":["bin"],
3129+
"doctest": false,
31263130
"edition": "2015",
31273131
"name":"foo",
31283132
"src_path":"[..]main.rs"
@@ -3136,6 +3140,7 @@ fn compiler_json_error_format() {
31363140
"target":{
31373141
"kind":["bin"],
31383142
"crate_types":["bin"],
3143+
"doctest": false,
31393144
"edition": "2015",
31403145
"name":"foo",
31413146
"src_path":"[..]main.rs"
@@ -3167,6 +3172,7 @@ fn compiler_json_error_format() {
31673172
"target":{
31683173
"kind":["custom-build"],
31693174
"crate_types":["bin"],
3175+
"doctest": false,
31703176
"edition": "2015",
31713177
"name":"build-script-build",
31723178
"src_path":"[..]build.rs"
@@ -3199,6 +3205,7 @@ fn compiler_json_error_format() {
31993205
"target":{
32003206
"kind":["lib"],
32013207
"crate_types":["lib"],
3208+
"doctest": true,
32023209
"edition": "2015",
32033210
"name":"bar",
32043211
"src_path":"[..]lib.rs"
@@ -3225,6 +3232,7 @@ fn compiler_json_error_format() {
32253232
"target":{
32263233
"kind":["bin"],
32273234
"crate_types":["bin"],
3235+
"doctest": false,
32283236
"edition": "2015",
32293237
"name":"foo",
32303238
"src_path":"[..]main.rs"
@@ -3280,6 +3288,7 @@ fn message_format_json_forward_stderr() {
32803288
"target":{
32813289
"kind":["bin"],
32823290
"crate_types":["bin"],
3291+
"doctest": false,
32833292
"edition": "2015",
32843293
"name":"foo",
32853294
"src_path":"[..]"
@@ -3293,6 +3302,7 @@ fn message_format_json_forward_stderr() {
32933302
"target":{
32943303
"kind":["bin"],
32953304
"crate_types":["bin"],
3305+
"doctest": false,
32963306
"edition": "2015",
32973307
"name":"foo",
32983308
"src_path":"[..]"

tests/testsuite/metabuild.rs

+2
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ fn metabuild_json_artifact() {
695695
"crate_types": [
696696
"bin"
697697
],
698+
"doctest": false,
698699
"edition": "2018",
699700
"kind": [
700701
"custom-build"
@@ -742,6 +743,7 @@ fn metabuild_failed_build_json() {
742743
"crate_types": [
743744
"bin"
744745
],
746+
"doctest": false,
745747
"edition": "2018",
746748
"kind": [
747749
"custom-build"

tests/testsuite/metadata.rs

+26
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ fn cargo_metadata_simple() {
3939
"crate_types": [
4040
"bin"
4141
],
42+
"doctest": false,
4243
"edition": "2015",
4344
"name": "foo",
4445
"src_path": "[..]/foo/src/foo.rs"
@@ -129,6 +130,7 @@ crate-type = ["lib", "staticlib"]
129130
"lib",
130131
"staticlib"
131132
],
133+
"doctest": true,
132134
"edition": "2015",
133135
"name": "foo",
134136
"src_path": "[..]/foo/src/lib.rs"
@@ -207,6 +209,7 @@ optional_feat = []
207209
"crate_types": [
208210
"lib"
209211
],
212+
"doctest": true,
210213
"edition": "2015",
211214
"name": "foo",
212215
"src_path": "[..]/foo/src/lib.rs"
@@ -302,6 +305,7 @@ fn cargo_metadata_with_deps_and_version() {
302305
"crate_types": [
303306
"lib"
304307
],
308+
"doctest": true,
305309
"edition": "2015",
306310
"kind": [
307311
"lib"
@@ -360,6 +364,7 @@ fn cargo_metadata_with_deps_and_version() {
360364
"crate_types": [
361365
"bin"
362366
],
367+
"doctest": false,
363368
"edition": "2015",
364369
"kind": [
365370
"bin"
@@ -393,6 +398,7 @@ fn cargo_metadata_with_deps_and_version() {
393398
"crate_types": [
394399
"lib"
395400
],
401+
"doctest": true,
396402
"edition": "2015",
397403
"kind": [
398404
"lib"
@@ -439,6 +445,7 @@ fn cargo_metadata_with_deps_and_version() {
439445
"crate_types": [
440446
"lib"
441447
],
448+
"doctest": true,
442449
"edition": "2015",
443450
"kind": [
444451
"lib"
@@ -552,13 +559,15 @@ name = "ex"
552559
{
553560
"kind": [ "lib" ],
554561
"crate_types": [ "lib" ],
562+
"doctest": true,
555563
"edition": "2015",
556564
"name": "foo",
557565
"src_path": "[..]/foo/src/lib.rs"
558566
},
559567
{
560568
"kind": [ "example" ],
561569
"crate_types": [ "bin" ],
570+
"doctest": false,
562571
"edition": "2015",
563572
"name": "ex",
564573
"src_path": "[..]/foo/examples/ex.rs"
@@ -635,13 +644,15 @@ crate-type = ["rlib", "dylib"]
635644
{
636645
"kind": [ "lib" ],
637646
"crate_types": [ "lib" ],
647+
"doctest": true,
638648
"edition": "2015",
639649
"name": "foo",
640650
"src_path": "[..]/foo/src/lib.rs"
641651
},
642652
{
643653
"kind": [ "example" ],
644654
"crate_types": [ "rlib", "dylib" ],
655+
"doctest": false,
645656
"edition": "2015",
646657
"name": "ex",
647658
"src_path": "[..]/foo/examples/ex.rs"
@@ -717,6 +728,7 @@ fn workspace_metadata() {
717728
{
718729
"kind": [ "lib" ],
719730
"crate_types": [ "lib" ],
731+
"doctest": true,
720732
"edition": "2015",
721733
"name": "bar",
722734
"src_path": "[..]bar/src/lib.rs"
@@ -748,6 +760,7 @@ fn workspace_metadata() {
748760
{
749761
"kind": [ "lib" ],
750762
"crate_types": [ "lib" ],
763+
"doctest": true,
751764
"edition": "2015",
752765
"name": "baz",
753766
"src_path": "[..]baz/src/lib.rs"
@@ -827,6 +840,7 @@ fn workspace_metadata_no_deps() {
827840
{
828841
"kind": [ "lib" ],
829842
"crate_types": [ "lib" ],
843+
"doctest": true,
830844
"edition": "2015",
831845
"name": "bar",
832846
"src_path": "[..]bar/src/lib.rs"
@@ -858,6 +872,7 @@ fn workspace_metadata_no_deps() {
858872
{
859873
"kind": [ "lib" ],
860874
"crate_types": ["lib"],
875+
"doctest": true,
861876
"edition": "2015",
862877
"name": "baz",
863878
"src_path": "[..]baz/src/lib.rs"
@@ -915,6 +930,7 @@ const MANIFEST_OUTPUT: &str = r#"
915930
"targets":[{
916931
"kind":["bin"],
917932
"crate_types":["bin"],
933+
"doctest": false,
918934
"edition": "2015",
919935
"name":"foo",
920936
"src_path":"[..]/foo/src/foo.rs"
@@ -1093,6 +1109,7 @@ fn package_metadata() {
10931109
{
10941110
"kind": [ "lib" ],
10951111
"crate_types": [ "lib" ],
1112+
"doctest": true,
10961113
"edition": "2015",
10971114
"name": "foo",
10981115
"src_path": "[..]foo/src/lib.rs"
@@ -1167,6 +1184,7 @@ fn cargo_metadata_path_to_cargo_toml_project() {
11671184
"crate_types": [
11681185
"lib"
11691186
],
1187+
"doctest": true,
11701188
"edition": "2015",
11711189
"kind": [
11721190
"lib"
@@ -1246,6 +1264,7 @@ fn package_edition_2018() {
12461264
"crate_types": [
12471265
"lib"
12481266
],
1267+
"doctest": true,
12491268
"edition": "2018",
12501269
"kind": [
12511270
"lib"
@@ -1329,6 +1348,7 @@ fn target_edition_2018() {
13291348
"crate_types": [
13301349
"lib"
13311350
],
1351+
"doctest": true,
13321352
"edition": "2018",
13331353
"kind": [
13341354
"lib"
@@ -1340,6 +1360,7 @@ fn target_edition_2018() {
13401360
"crate_types": [
13411361
"bin"
13421362
],
1363+
"doctest": false,
13431364
"edition": "2015",
13441365
"kind": [
13451366
"bin"
@@ -1449,6 +1470,7 @@ fn rename_dependency() {
14491470
"crate_types": [
14501471
"lib"
14511472
],
1473+
"doctest": true,
14521474
"edition": "2015",
14531475
"kind": [
14541476
"lib"
@@ -1482,6 +1504,7 @@ fn rename_dependency() {
14821504
"crate_types": [
14831505
"lib"
14841506
],
1507+
"doctest": true,
14851508
"edition": "2015",
14861509
"kind": [
14871510
"lib"
@@ -1515,6 +1538,7 @@ fn rename_dependency() {
15151538
"crate_types": [
15161539
"lib"
15171540
],
1541+
"doctest": true,
15181542
"edition": "2015",
15191543
"kind": [
15201544
"lib"
@@ -1616,6 +1640,7 @@ fn metadata_links() {
16161640
"crate_types": [
16171641
"lib"
16181642
],
1643+
"doctest": true,
16191644
"edition": "2015",
16201645
"kind": [
16211646
"lib"
@@ -1627,6 +1652,7 @@ fn metadata_links() {
16271652
"crate_types": [
16281653
"bin"
16291654
],
1655+
"doctest": false,
16301656
"edition": "2015",
16311657
"kind": [
16321658
"custom-build"

tests/testsuite/read_manifest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static MANIFEST_OUTPUT: &'static str = r#"
2222
"targets":[{
2323
"kind":["bin"],
2424
"crate_types":["bin"],
25+
"doctest": false,
2526
"edition": "2015",
2627
"name":"foo",
2728
"src_path":"[..]/foo/src/foo.rs"

tests/testsuite/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3362,6 +3362,7 @@ fn json_artifact_includes_test_flag() {
33623362
"target":{
33633363
"kind":["lib"],
33643364
"crate_types":["lib"],
3365+
"doctest": true,
33653366
"edition": "2015",
33663367
"name":"foo",
33673368
"src_path":"[..]lib.rs"
@@ -3395,6 +3396,7 @@ fn json_artifact_includes_executable_for_library_tests() {
33953396
"target": {
33963397
"crate_types": [ "lib" ],
33973398
"kind": [ "lib" ],
3399+
"doctest": true,
33983400
"edition": "2015",
33993401
"name": "foo",
34003402
"src_path": "[..]/foo/src/lib.rs"
@@ -3428,6 +3430,7 @@ fn json_artifact_includes_executable_for_integration_tests() {
34283430
"target": {
34293431
"crate_types": [ "bin" ],
34303432
"kind": [ "test" ],
3433+
"doctest": false,
34313434
"edition": "2015",
34323435
"name": "integration_test",
34333436
"src_path": "[..]/foo/tests/integration_test.rs"

tests/testsuite/update.rs

+2
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ fn update_precise_first_run() {
456456
"crate_types": [
457457
"lib"
458458
],
459+
"doctest": true,
459460
"edition": "2015",
460461
"kind": [
461462
"lib"
@@ -502,6 +503,7 @@ fn update_precise_first_run() {
502503
"crate_types": [
503504
"lib"
504505
],
506+
"doctest": true,
505507
"edition": "2015",
506508
"kind": [
507509
"lib"

0 commit comments

Comments
 (0)