Skip to content

Commit 708383d

Browse files
committed
Auto merge of #12859 - epage:doc-open, r=weihanglo
feat(doc): Print the generated docs links I've wanted something like this myself. I dislike using `--open` because I tend to move up to re-run my `cargo doc` run but then have to edit it to remove `--open`. Also makes it annoying when opening docs when `cargo doc` is wrapped by a tool like `make`. This was previously attempted in #5592: - Unlike the request in #5562, this aligns with #5592 in always printing rather than using a flag as this seems generally useful - Unlike #5592, this prints as an alternative to "Opening" to keep things light - Unlike #5592, this prints afterwards as the link is only valid then Fixes #5562
2 parents 307486e + 293f225 commit 708383d

14 files changed

+140
-16
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ fn substitute_macros(input: &str) -> String {
237237
("[WAITING]", " Waiting"),
238238
("[PUBLISHED]", " Published"),
239239
("[BLOCKING]", " Blocking"),
240+
("[GENERATED]", " Generated"),
240241
];
241242
let mut result = input.to_owned();
242243
for &(pat, subst) in &macros {

src/cargo/ops/cargo_doc.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,23 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
3434
let cfg: Option<PathAndArgs> = ws.config().get("doc.browser")?;
3535
cfg.map(|path_args| (path_args.path.resolve_program(ws.config()), path_args.args))
3636
};
37-
3837
let mut shell = ws.config().shell();
3938
shell.status("Opening", path.display())?;
4039
open_docs(&path, &mut shell, config_browser, ws.config())?;
4140
}
41+
} else {
42+
for name in &compilation.root_crate_names {
43+
for kind in &options.compile_opts.build_config.requested_kinds {
44+
let path = compilation.root_output[&kind]
45+
.with_file_name("doc")
46+
.join(&name)
47+
.join("index.html");
48+
if path.exists() {
49+
let mut shell = ws.config().shell();
50+
shell.status("Generated", path.display())?;
51+
}
52+
}
53+
}
4254
}
4355

4456
Ok(())

tests/testsuite/artifact_dep.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,7 @@ fn doc_lib_true() {
21522152
[DOCUMENTING] bar v0.0.1 ([CWD]/bar)
21532153
[DOCUMENTING] foo v0.0.1 ([CWD])
21542154
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2155+
[GENERATED] [CWD]/target/doc/foo/index.html
21552156
",
21562157
)
21572158
.run();
@@ -2227,6 +2228,7 @@ fn rustdoc_works_on_libs_with_artifacts_and_lib_false() {
22272228
[COMPILING] bar v0.5.0 ([CWD]/bar)
22282229
[DOCUMENTING] foo v0.0.1 ([CWD])
22292230
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
2231+
[GENERATED] [CWD]/target/doc/foo/index.html
22302232
",
22312233
)
22322234
.run();

tests/testsuite/build_script.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@ fn testing_and_such() {
14711471
[DOCUMENTING] foo v0.5.0 ([CWD])
14721472
[RUNNING] `rustdoc [..]`
14731473
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1474+
[GENERATED] [CWD]/target/doc/foo/index.html
14741475
",
14751476
)
14761477
.run();

tests/testsuite/check_cfg.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ fn build_script_doc() {
312312
[RUNNING] `[..]/build-script-build`
313313
[DOCUMENTING] foo [..]
314314
[RUNNING] `rustdoc [..] src/main.rs [..]
315-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
315+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
316+
[GENERATED] [CWD]/target/doc/foo/index.html
317+
",
316318
)
317319
.masquerade_as_nightly_cargo(&["check-cfg"])
318320
.run();

tests/testsuite/collisions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ fn collision_doc_multiple_versions() {
202202
[DOCUMENTING] bar v2.0.0
203203
[FINISHED] [..]
204204
[DOCUMENTING] foo v0.1.0 [..]
205+
[GENERATED] [CWD]/target/doc/foo/index.html
205206
",
206207
)
207208
.run();
@@ -384,6 +385,7 @@ fn collision_doc_profile_split() {
384385
[DOCUMENTING] pm v0.1.0 [..]
385386
[DOCUMENTING] foo v0.1.0 [..]
386387
[FINISHED] [..]
388+
[GENERATED] [CWD]/target/doc/foo/index.html
387389
",
388390
)
389391
.run();
@@ -430,6 +432,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
430432
[CHECKING] bar v1.0.0
431433
[DOCUMENTING] foo v0.1.0 [..]
432434
[FINISHED] [..]
435+
[GENERATED] [CWD]/target/doc/foo/index.html
433436
",
434437
)
435438
.run();
@@ -478,6 +481,7 @@ fn collision_doc_target() {
478481
[CHECKING] bar v1.0.0
479482
[DOCUMENTING] foo v0.1.0 [..]
480483
[FINISHED] [..]
484+
[GENERATED] [CWD]/target/[..]/doc/foo/index.html
481485
",
482486
)
483487
.run();
@@ -545,6 +549,8 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
545549
[DOCUMENTING] foo-macro v1.0.0 [..]
546550
[DOCUMENTING] abc v1.0.0 [..]
547551
[FINISHED] [..]
552+
[GENERATED] [CWD]/target/doc/abc/index.html
553+
[GENERATED] [CWD]/target/doc/foo_macro/index.html
548554
")
549555
.run();
550556
}

tests/testsuite/doc.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn simple() {
3131
[..] foo v0.0.1 ([CWD])
3232
[..] foo v0.0.1 ([CWD])
3333
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
34+
[GENERATED] [CWD]/target/doc/foo/index.html
3435
",
3536
)
3637
.run();
@@ -69,6 +70,7 @@ fn doc_twice() {
6970
"\
7071
[DOCUMENTING] foo v0.0.1 ([CWD])
7172
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
73+
[GENERATED] [CWD]/target/doc/foo/index.html
7274
",
7375
)
7476
.run();
@@ -103,6 +105,7 @@ fn doc_deps() {
103105
[..] bar v0.0.1 ([CWD]/bar)
104106
[DOCUMENTING] foo v0.0.1 ([CWD])
105107
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
108+
[GENERATED] [CWD]/target/doc/foo/index.html
106109
",
107110
)
108111
.run();
@@ -151,6 +154,7 @@ fn doc_no_deps() {
151154
[CHECKING] bar v0.0.1 ([CWD]/bar)
152155
[DOCUMENTING] foo v0.0.1 ([CWD])
153156
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
157+
[GENERATED] [CWD]/target/doc/foo/index.html
154158
",
155159
)
156160
.run();
@@ -284,6 +288,8 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
284288
[DOCUMENTING] bar v0.1.0 ([ROOT]/foo/bar)
285289
[DOCUMENTING] foo v0.1.0 ([ROOT]/foo/foo)
286290
[FINISHED] [..]
291+
[GENERATED] [CWD]/target/doc/foo_lib/index.html
292+
[GENERATED] [CWD]/target/doc/foo_lib/index.html
287293
",
288294
)
289295
.run();
@@ -398,6 +404,7 @@ fn doc_lib_bin_same_name_documents_lib() {
398404
"\
399405
[DOCUMENTING] foo v0.0.1 ([CWD])
400406
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
407+
[GENERATED] [CWD]/target/doc/foo/index.html
401408
",
402409
)
403410
.run();
@@ -433,6 +440,7 @@ fn doc_lib_bin_same_name_documents_lib_when_requested() {
433440
"\
434441
[DOCUMENTING] foo v0.0.1 ([CWD])
435442
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
443+
[GENERATED] [CWD]/target/doc/foo/index.html
436444
",
437445
)
438446
.run();
@@ -478,6 +486,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
478486
[CHECKING] foo v0.0.1 ([CWD])
479487
[DOCUMENTING] foo v0.0.1 ([CWD])
480488
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
489+
[GENERATED] [CWD]/target/doc/foo/index.html
481490
",
482491
)
483492
.run();
@@ -523,6 +532,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
523532
[CHECKING] foo v0.0.1 ([CWD])
524533
[DOCUMENTING] foo v0.0.1 ([CWD])
525534
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
535+
[GENERATED] [CWD]/target/doc/foo/index.html
526536
",
527537
)
528538
.run();
@@ -567,7 +577,9 @@ fn doc_lib_bin_example_same_name_documents_named_example_when_requested() {
567577
"\
568578
[CHECKING] foo v0.0.1 ([CWD])
569579
[DOCUMENTING] foo v0.0.1 ([CWD])
570-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
580+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
581+
[GENERATED] [CWD]/target/doc/ex1/index.html
582+
",
571583
)
572584
.run();
573585

@@ -620,7 +632,10 @@ fn doc_lib_bin_example_same_name_documents_examples_when_requested() {
620632
"\
621633
[CHECKING] foo v0.0.1 ([CWD])
622634
[DOCUMENTING] foo v0.0.1 ([CWD])
623-
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
635+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
636+
[GENERATED] [CWD]/target/doc/ex1/index.html
637+
[GENERATED] [CWD]/target/doc/ex2/index.html
638+
",
624639
)
625640
.run();
626641

@@ -677,6 +692,7 @@ fn doc_dash_p() {
677692
[..] b v0.0.1 ([CWD]/b)
678693
[DOCUMENTING] a v0.0.1 ([CWD]/a)
679694
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
695+
[GENERATED] [CWD]/target/doc/a/index.html
680696
",
681697
)
682698
.run();
@@ -704,6 +720,7 @@ fn doc_all_exclude() {
704720
"\
705721
[DOCUMENTING] bar v0.1.0 ([..])
706722
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
723+
[GENERATED] [CWD]/target/doc/bar/index.html
707724
",
708725
)
709726
.run();
@@ -731,6 +748,7 @@ fn doc_all_exclude_glob() {
731748
"\
732749
[DOCUMENTING] bar v0.1.0 ([..])
733750
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
751+
[GENERATED] [CWD]/target/doc/bar/index.html
734752
",
735753
)
736754
.run();
@@ -918,6 +936,7 @@ fn doc_release() {
918936
[DOCUMENTING] foo v0.0.1 ([..])
919937
[RUNNING] `rustdoc [..] src/lib.rs [..]`
920938
[FINISHED] release [optimized] target(s) in [..]
939+
[GENERATED] [CWD]/target/doc/foo/index.html
921940
",
922941
)
923942
.run();
@@ -1006,6 +1025,7 @@ fn features() {
10061025
[DOCUMENTING] bar v0.0.1 [..]
10071026
[DOCUMENTING] foo v0.0.1 [..]
10081027
[FINISHED] [..]
1028+
[GENERATED] [CWD]/target/doc/foo/index.html
10091029
",
10101030
)
10111031
.run();
@@ -1020,6 +1040,7 @@ fn features() {
10201040
[DOCUMENTING] bar v0.0.1 [..]
10211041
[DOCUMENTING] foo v0.0.1 [..]
10221042
[FINISHED] [..]
1043+
[GENERATED] [CWD]/target/doc/foo/index.html
10231044
",
10241045
)
10251046
.run();
@@ -1032,6 +1053,7 @@ fn features() {
10321053
[DOCUMENTING] bar v0.0.1 [..]
10331054
[DOCUMENTING] foo v0.0.1 [..]
10341055
[FINISHED] [..]
1056+
[GENERATED] [CWD]/target/doc/foo/index.html
10351057
",
10361058
)
10371059
.run();
@@ -1202,6 +1224,7 @@ fn doc_virtual_manifest_one_project() {
12021224
"\
12031225
[DOCUMENTING] bar v0.1.0 ([..])
12041226
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1227+
[GENERATED] [CWD]/target/doc/bar/index.html
12051228
",
12061229
)
12071230
.run();
@@ -1229,6 +1252,7 @@ fn doc_virtual_manifest_glob() {
12291252
"\
12301253
[DOCUMENTING] baz v0.1.0 ([..])
12311254
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1255+
[GENERATED] [CWD]/target/doc/baz/index.html
12321256
",
12331257
)
12341258
.run();
@@ -1277,6 +1301,7 @@ the same path; see <https://github.com/rust-lang/cargo/issues/6313>.
12771301
[CHECKING] bar v0.1.0
12781302
[DOCUMENTING] bar v0.1.0 [..]
12791303
[FINISHED] [..]
1304+
[GENERATED] [CWD]/target/doc/bar/index.html
12801305
",
12811306
)
12821307
.run();
@@ -1639,6 +1664,7 @@ fn doc_cap_lints() {
16391664
[CHECKING] a v0.5.0 ([..])
16401665
[DOCUMENTING] foo v0.0.1 ([..])
16411666
[FINISHED] dev [..]
1667+
[GENERATED] [CWD]/target/doc/foo/index.html
16421668
",
16431669
)
16441670
.run();
@@ -1903,6 +1929,7 @@ fn bin_private_items() {
19031929
"\
19041930
[DOCUMENTING] foo v0.0.1 ([CWD])
19051931
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1932+
[GENERATED] [CWD]/target/doc/foo/index.html
19061933
",
19071934
)
19081935
.run();
@@ -1963,6 +1990,7 @@ fn bin_private_items_deps() {
19631990
[CHECKING] bar v0.0.1 ([..])
19641991
[DOCUMENTING] foo v0.0.1 ([CWD])
19651992
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1993+
[GENERATED] [CWD]/target/doc/foo/index.html
19661994
",
19671995
)
19681996
.run();
@@ -1997,6 +2025,7 @@ fn crate_versions() {
19972025
[DOCUMENTING] foo v1.2.4 [..]
19982026
[RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..]--crate-version 1.2.4`
19992027
[FINISHED] [..]
2028+
[GENERATED] [CWD]/target/doc/foo/index.html
20002029
",
20012030
)
20022031
.run();
@@ -2406,7 +2435,8 @@ fn doc_fingerprint_unusual_behavior() {
24062435
p.cargo("doc")
24072436
.with_stderr(
24082437
"[DOCUMENTING] foo [..]\n\
2409-
[FINISHED] [..]",
2438+
[FINISHED] [..]\n\
2439+
[GENERATED] [CWD]/target/doc/foo/index.html",
24102440
)
24112441
.run();
24122442
// This will delete somefile, but not .hidden.
@@ -2425,7 +2455,8 @@ fn doc_fingerprint_unusual_behavior() {
24252455
.masquerade_as_nightly_cargo(&["skip-rustdoc-fingerprint"])
24262456
.with_stderr(
24272457
"[DOCUMENTING] foo [..]\n\
2428-
[FINISHED] [..]",
2458+
[FINISHED] [..]\n\
2459+
[GENERATED] [CWD]/target/doc/foo/index.html",
24292460
)
24302461
.run();
24312462
// Should not have deleted anything.
@@ -2467,6 +2498,8 @@ fn lib_before_bin() {
24672498
[RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..]
24682499
[RUNNING] `rustdoc --crate-type bin --crate-name somebin src/bin/somebin.rs [..]
24692500
[FINISHED] [..]
2501+
[GENERATED] [CWD]/target/doc/foo/index.html
2502+
[GENERATED] [CWD]/target/doc/somebin/index.html
24702503
",
24712504
)
24722505
.run();
@@ -2517,6 +2550,7 @@ fn doc_lib_false() {
25172550
[CHECKING] foo v0.1.0 [..]
25182551
[DOCUMENTING] foo v0.1.0 [..]
25192552
[FINISHED] [..]
2553+
[GENERATED] [CWD]/target/doc/some_bin/index.html
25202554
",
25212555
)
25222556
.run();
@@ -2563,6 +2597,7 @@ fn doc_lib_false_dep() {
25632597
[CHECKING] bar v0.1.0 [..]
25642598
[DOCUMENTING] foo v0.1.0 [..]
25652599
[FINISHED] [..]
2600+
[GENERATED] [CWD]/target/doc/foo/index.html
25662601
",
25672602
)
25682603
.run();
@@ -2587,7 +2622,8 @@ fn link_to_private_item() {
25872622
p.cargo("doc")
25882623
.with_stderr(
25892624
"[DOCUMENTING] foo [..]\n\
2590-
[FINISHED] [..]",
2625+
[FINISHED] [..]\n\
2626+
[GENERATED] [CWD]/target/doc/foo/index.html",
25912627
)
25922628
.run();
25932629
}

0 commit comments

Comments
 (0)